THISAPP = flash-image
TARGET = $(DIR_INFO)/$(THISAPP)
-ifeq "$(MACHINE)" "i586"
- EFI = 1
-endif
-
DEVICE = $(shell losetup -f)
PART_BOOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p1
ifeq "$(EFI)" "1"
# FAT32
PART_TYPE = c
+ifeq "$(BUILD_ARCH)" "aarch64"
+ BOOTLOADER = grub
+endif
else
BOOTLOADER = grub
S_OFFSET = 8192
- # Logical
+ # Linux
PART_TYPE = L
endif
-GRUB_CFGS = /boot/grub/grub.cfg
+# /boot: 128MB - OFFSET
+# / : 1200 MB
+S_BOOT := $(shell echo $$(( 262144 - $(S_OFFSET) )))
+S_ROOT := 2477600
ifeq "$(EFI)" "1"
- S_EFI = 204800
- GRUB_CFGS += /boot/efi/EFI/ipfire/grub-efi/grub.cfg
+ S_EFI = 65536 # 32 MB
else
S_EFI = 0
endif
-# /boot: 128MB - OFFSET
-# / : 1200 MB
-S_BOOT := $(shell echo $$(( 262144 - $(S_OFFSET) )))
-S_ROOT := 2477600
-
PADDING = 100 # MB
ifeq "$(EFI)" "1"
- SFDISK_EFI = $(S_OFFSET),$(S_EFI),c,*\n
SFDISK = $(SFDISK_BOOT)$(SFDISK_EFI)$(SFDISK_ROOT)
else
- SFDISK_SWAP = ,0,0\n
- SFDISK = $(SFDISK_BOOT)$(SFDISK_SWAP)$(SFDISK_ROOT)
+ SFDISK = $(SFDISK_BOOT),0,0\n$(SFDISK_ROOT)
endif
-SFDISK_BOOT = $(shell echo $$(( $(S_OFFSET) + $(S_EFI) ))),$(S_BOOT),$(PART_TYPE)\n
-SFDISK_ROOT = $(shell echo $$(( $(S_OFFSET) + $(S_EFI) + $(S_BOOT) ))),$(S_ROOT),L\n
+SFDISK_BOOT = $(S_OFFSET),$(S_BOOT),$(PART_TYPE),*\n
+SFDISK_EFI = $(shell echo $$(( $(S_OFFSET) + $(S_BOOT) ))),$(S_EFI),U\n
+SFDISK_ROOT = $(shell echo $$(( $(S_OFFSET) + $(S_BOOT) + $(S_EFI) ))),$(S_ROOT),L\n
$(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
# Stop if $(MNThdd) is still mounted
# Write Partition table
echo -e "$(SFDISK)" | sfdisk -uS $(DEVICE)
- # Remove 2nd empty partition
-ifneq "$(EFI)" "1"
- -echo -e "d\n2\nw\n\q\n" | fdisk $(DEVICE)
-endif
-
kpartx -v -a $(DEVICE)
# Format them
$(MNThdd)/etc/grub.d/
# Create configuration
- for i in $(GRUB_CFGS); do \
- mkdir -pv $$(dirname $(MNThdd)$(GRUB_CFG)); \
- chroot $(MNThdd) grub-mkconfig -o $$i || exit 1; \
- done
+ mkdir -pv $(MNThdd)/boot/grub
+ chroot $(MNThdd) grub-mkconfig -o /boot/grub/grub.cfg
# Boot the first kernel by default
chroot $(MNThdd) grub-set-default 0
# Insert the UUID because grub-mkconfig often fails to
# detect that correctly
- sed -i $(addprefix $(MNThdd),$(GRUB_CFGS)) \
sed -i $(MNThdd)/boot/grub/grub.cfg \
-e "s/root=[A-Za-z0-9\/=-]*/root=UUID=$$(blkid -o value -s UUID $(PART_ROOT))/g"
+ifeq "$(BUILD_PLATFORM)" "x86"
# Install GRUB
grub-install --force --recheck --no-floppy --target=i386-pc \
--root-directory=$(MNThdd) $(DEVICE)
+endif
+
+ifeq "$(EFI)" "1"
+ # Install GRUB for EFI
+ grub-install --target=$(GRUB_ARCH)-efi --removable --no-nvram \
+ --boot-directory=$(MNThdd)/boot --efi-directory=$(MNThdd)/boot/efi
+endif
# restore orginal defaults
mv -f $(MNThdd)/etc/default/grub.backup $(MNThdd)/etc/default/grub
rm -f $(MNThdd)/etc/grub.d/11_linux_scon
-
-ifeq "$(EFI)" "1"
- mkdir -pv $(MNThdd)/boot/efi/EFI/boot
- cp -vf $(MNThdd)/boot/efi/EFI/ipfire/grub-efi/grub.efi \
- $(MNThdd)/boot/efi/EFI/boot/bootia32.efi
-endif
endif
# Set ramdisk mode to automatic