x86: add grub2 iso support
[openwrt/svn-archive/archive.git] / target / linux / x86 / image / Makefile
index 26e34ff6d6ed1c4bc14d58caaea8d8215c88f180..17e300d5080be33483c7661e7bdf3cc298039c6a 100644 (file)
@@ -9,6 +9,8 @@ include $(INCLUDE_DIR)/image.mk
 
 export PATH=$(TARGET_PATH):/sbin
 
+GRUB2_MODULES = at_keyboard biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial vga
+GRUB2_MODULES_ISO = at_keyboard biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial vga
 GRUB_TERMINALS =
 GRUB_SERIAL_CONFIG =
 GRUB_TERMINAL_CONFIG =
@@ -26,7 +28,11 @@ ifneq ($(CONFIG_X86_GRUB_SERIAL),)
 endif
 
 ifneq ($(GRUB_TERMINALS),)
-  GRUB_TERMINAL_CONFIG := terminal --timeout=2 $(GRUB_TERMINALS)
+  ifneq ($(CONFIG_X86_USE_GRUB2),)
+    GRUB_TERMINAL_CONFIG := terminal_input $(GRUB_TERMINALS); terminal_output $(GRUB_TERMINALS)
+  else
+    GRUB_TERMINAL_CONFIG := terminal --timeout=2 $(GRUB_TERMINALS)
+  endif
 endif
 
 ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
@@ -40,7 +46,7 @@ ifneq ($(CONFIG_X86_GRUB_IMAGES),)
   define Image/cmdline/ext4
     root=$(ROOTPART) rootfstype=ext4 rootwait
   endef
-  
+
   define Image/cmdline/jffs2-64k
     block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
   endef
@@ -68,7 +74,7 @@ ifneq ($(CONFIG_X86_GRUB_IMAGES),)
                -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
                -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
                ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
-       PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_x86.sh \
+       PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_grub.sh \
                $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
                $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \
                $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1)
@@ -85,6 +91,35 @@ ifneq ($(CONFIG_X86_GRUB_IMAGES),)
                $(KDIR)/
   endef
 
+  define Image/Build/grub2
+       # left here because the image builder doesnt need these
+       $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
+       $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
+       grub-mkimage \
+               -o $(KDIR)/grub2/core.img \
+               -O i386-pc \
+               -c ./grub-early.cfg \
+               $(GRUB2_MODULES)
+       $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/
+       echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map
+       sed \
+               -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
+               -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
+               -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
+               -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
+               ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
+       PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_generic.sh \
+               $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
+               $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \
+               $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \
+               256
+       grub-bios-setup \
+               --device-map="$(KDIR)/grub2/device.map" \
+               -d "$(KDIR)/grub2" \
+               -r "hd0,msdos1" \
+               "$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img"
+       $(call Image/Build/grub/$(1))
+  endef
 endif
 
 ROOTDELAY=10
@@ -125,7 +160,31 @@ define Image/Build/squashfs
        $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
 endef
 
-define Image/Build/iso 
+ifdef CONFIG_X86_USE_GRUB2
+  define Image/Build/iso
+       $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
+       $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
+       grub-mkimage \
+               -o $(KDIR)/grub2/eltorito.img \
+               -O i386-pc \
+               -c ./grub-early.cfg \
+               $(GRUB2_MODULES_ISO)
+       cat \
+               $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
+               $(KDIR)/grub2/eltorito.img \
+               > $(KDIR)/root.grub/boot/grub/eltorito.img
+       sed \
+               -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
+               -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
+               -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
+               -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
+               ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
+       $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
+       mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \
+               -o $(KDIR)/root.iso $(KDIR)/root.grub $(TARGET_DIR)
+  endef
+else
+  define Image/Build/iso
        $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
        $(CP) \
                $(KDIR)/stage2_eltorito \
@@ -139,7 +198,8 @@ define Image/Build/iso
        $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz 
        mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table \
                -o $(KDIR)/root.iso $(KDIR)/root.grub 
-endef 
+  endef
+endif
 
 ifneq ($(CONFIG_X86_VDI_IMAGES),)
   define Image/Build/vdi
@@ -203,14 +263,14 @@ endef
 define Image/Prepare
        $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
        $(call Image/Prepare/bootscript)
-       $(call Image/Prepare/grub)
+       $(call Image/Prepare/$(if $(CONFIG_X86_USE_GRUB2),grub2,grub))
 endef
 
 define Image/Build
        $(call Image/Build/$(1))
        $(call Image/Build/bootscript,$(1))
   ifneq ($(1),iso)
-       $(call Image/Build/grub,$(1))
+       $(call Image/Build/$(if $(CONFIG_X86_USE_GRUB2),grub2,grub),$(1))
        $(call Image/Build/vdi,$(1))
        $(call Image/Build/vmdk,$(1))
   endif