[OpenWrt-Devel] [PATCH 1/2] x86: fix bios mkimage during efi image generation

Alif M. Ahmad alive4ever at live.com
Sat Mar 3 20:40:21 EST 2018


Previously, grub-mkimage embeds full-featured grub.cfg inside core.img
during efi image generation phase (target/linux/install).

This causes grub to not passing kernel command line to the kernel, which
causes kernel panic when the generated gpt image is booted on bios mode
because the kernel doesn't find the root partition.

Fixing the problem involves using minimal grub-early.cfg to embed inside
grub's core.img to load the full-featured grub.cfg later.

grub-early.cfg contains one configuration line:

  configfile (hd0,gpt1)/boot/grub/grub.cfg

With this change, the generated gpt image should be bootable on both
bios and UEFI based systems.

Signed-off-by: Alif M. Ahmad <alive4ever at live.com>
---

Notes:
    This patch is based on Jow's staging repository instead of OpenWrt master branch.
    
    Hopefully, this would allow UEFI image generation for x86 targets, i.e. to get
    changes on Jow's staging repository merged into OpenWrt master branch

 target/linux/x86/image/Makefile | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile
index d5786fb2ad..c8dd94dc78 100644
--- a/target/linux/x86/image/Makefile
+++ b/target/linux/x86/image/Makefile
@@ -86,13 +86,17 @@ ifneq ($(CONFIG_GRUB_IMAGES)$(CONFIG_EFI_IMAGES),)
 		-e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
 		-e 's#set root.*#search --file /boot/grub/$(SIGNATURE).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 \
 		-O i386-pc \
 		-p '(hd0,gpt1)/boot/grub' \
-		-c $(KDIR)/root.grub/boot/grub/grub.cfg \
+		-c $(KDIR)/root.grub/boot/grub/grub-early.cfg \
 		$(GRUB2_MODULES_LEGACY)
 	$(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/
 
-- 
2.16.2
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list