diff mbox series

[OpenWrt-Devel,2/2] x86: simplify efi image generation process

Message ID SG2PR0601MB194973EE845A1B329BCDA3EDE4DB0@SG2PR0601MB1949.apcprd06.prod.outlook.com
State Rejected
Delegated to: John Crispin
Headers show
Series [OpenWrt-Devel,1/2] x86: fix bios mkimage during efi image generation | expand

Commit Message

Alif M. Ahmad March 4, 2018, 1:41 a.m. UTC
Currently, efi image generation involves a hacky approach to find the
grub root partition, i.e. using $(SIGNATURE).cfg as additional
configuration file.

This commit simplify efi image generation by removing $(SIGNATURE).cfg
file and use single /boot/grub/grub.cfg for grub external configuration.

This commit also removes unnecessary grub-bios-setup during efi image
generation and only perform grub-bios-setup after the disk image has
been converted into gpt.

Signed-off-by: Alif M. Ahmad <alive4ever@live.com>
---
 target/linux/x86/image/Makefile | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)

Comments

Alif M. Ahmad March 26, 2018, 6:13 a.m. UTC | #1
Hi Jo,

Could you apply this patch on top of uefi related changes as well so
grub bootloader will have the same configuration for both uefi and bios
boot on the resulting gpt image.

On Sun, Mar 04, 2018 at 01:41:28AM +0000, Alif M. Ahmad wrote:
> Currently, efi image generation involves a hacky approach to find the
> grub root partition, i.e. using $(SIGNATURE).cfg as additional
> configuration file.
> 
> This commit simplify efi image generation by removing $(SIGNATURE).cfg
> file and use single /boot/grub/grub.cfg for grub external configuration.
> 
> This commit also removes unnecessary grub-bios-setup during efi image
> generation and only perform grub-bios-setup after the disk image has
> been converted into gpt.
> 
> Signed-off-by: Alif M. Ahmad <alive4ever@live.com>
> ---
>  target/linux/x86/image/Makefile | 23 +++++++----------------
>  1 file changed, 7 insertions(+), 16 deletions(-)
>
diff mbox series

Patch

diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile
index c8dd94dc78..2efb9dbbf9 100644
--- a/target/linux/x86/image/Makefile
+++ b/target/linux/x86/image/Makefile
@@ -84,13 +84,12 @@  ifneq ($(CONFIG_GRUB_IMAGES)$(CONFIG_EFI_IMAGES),)
 		-e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
 		-e 's#@CMDLINE@#$(strip $(call Image/cmdline/efi,$(1),$(EFI_SIGNATURE)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
 		-e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
-		-e 's#set root.*#search --file /boot/grub/$(SIGNATURE).cfg --set=root#g' \
+		-e 's#set root.*#search --file /boot/grub/grub.cfg --set=root#g' \
 		./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
 	sed \
 		-e 's/(hd0,msdos1)/(hd0,gpt1)/' ./grub-early.cfg > \
 			$(KDIR)/root.grub/boot/grub/grub-early.cfg
 
-	$(CP) $(KDIR)/root.grub/boot/grub/grub.cfg $(KDIR)/root.grub/boot/grub/$(SIGNATURE).cfg
 	grub-mkimage \
 		-d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
 		-o $(KDIR)/grub2/core.img \
@@ -104,20 +103,19 @@  ifneq ($(CONFIG_GRUB_IMAGES)$(CONFIG_EFI_IMAGES),)
 	rm -rf $(KDIR)/grub2.efi/ || true
 	$(INSTALL_DIR) $(KDIR)/grub2.efi/efi/boot/
 
-	# Generate the grub search root config (grub will search for the $(SIGNATURE).cfg file placed on the boot partition as grub does not support search of GPT UUID yet)
-	echo "search --file /boot/grub/$(SIGNATURE).cfg --set=root" > $(KDIR)/grub2.efi/efi/boot/grub.cfg
-	echo "configfile /boot/grub/grub.cfg" >> $(KDIR)/grub2.efi/efi/boot/grub.cfg
-
 	# Create the EFI grub binary
 	grub-mkimage-efi \
 		-d $(STAGING_DIR_HOST)/lib/grub/x86_64-efi \
 		-o $(KDIR)/grub2.efi/efi/boot/bootx64.efi \
 		-O x86_64-efi \
 		-p /efi/boot \
-		-c $(KDIR)/grub2.efi/efi/boot/grub.cfg \
+		-c $(KDIR)/root.grub/boot/grub/grub-early.cfg \
 		$(GRUB2_MODULES_EFI)
 
-	# Generate the EFI VFAT bootfs
+	# remove grub-early.cfg, since it has been embedded inside grub's core.img
+	rm -f $(KDIR)/root.grub/boot/grub/grub-early.cfg
+
+	# Generate EFI boot partition
 	rm $(KDIR)/kernel.efi || true
 	mkfs.fat -C $(KDIR)/kernel.efi -S 512 1024
 	mcopy -s -i "$(KDIR)/kernel.efi" $(KDIR)/grub2.efi/* ::/
@@ -130,13 +128,6 @@  ifneq ($(CONFIG_GRUB_IMAGES)$(CONFIG_EFI_IMAGES),)
 		$(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \
 		256
 
-	# Setup legacy bios for hybrid MBR (optional)
-	grub-bios-setup \
-		--device-map="$(KDIR)/grub2/device.map" \
-		-d "$(KDIR)/grub2" \
-		-r "hd0,msdos1" \
-		"$(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img"
-
 	# Convert the MBR partition to GPT and set EFI ROOTFS signature
 	dd if=/dev/zero of="$(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img" bs=512 count=33 conv=notrunc oflag=append
 	sgdisk -g "$(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img"
@@ -145,7 +136,7 @@  ifneq ($(CONFIG_GRUB_IMAGES)$(CONFIG_EFI_IMAGES),)
 	sgdisk -u 4:$(EFI_SIGNATURE) "$(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img"
 	sgdisk -h "$(BIN_DIR)/$(IMG_PREFIX)-uefi-gpt-$(1).img"
 
-	# Setup EFI grub
+	# Setup legacy bios boot support
 	grub-bios-setup-efi \
 		--device-map="$(KDIR)/grub2/device.map" \
 		-d "$(KDIR)/grub2" \