0021-x86-add-grub2-iso-support.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. From: nbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73>
  2. Date: Sun, 7 Oct 2012 23:01:52 +0000
  3. Subject: x86: add grub2 iso support
  4. diff --git a/Config.in b/Config.in
  5. index 5b4522e..54df7c8 100644
  6. --- a/Config.in
  7. +++ b/Config.in
  8. @@ -81,7 +81,7 @@ menu "Target Images"
  9. config TARGET_ROOTFS_ISO
  10. bool "iso"
  11. default n
  12. - depends TARGET_ROOTFS_INITRAMFS && TARGET_x86
  13. + depends on TARGET_x86_generic
  14. help
  15. Create some bootable ISO image
  16. diff --git a/target/linux/x86/base-files/lib/preinit/20_check_iso b/target/linux/x86/base-files/lib/preinit/20_check_iso
  17. new file mode 100644
  18. index 0000000..beff6eb
  19. --- /dev/null
  20. +++ b/target/linux/x86/base-files/lib/preinit/20_check_iso
  21. @@ -0,0 +1,5 @@
  22. +check_for_iso() {
  23. + grep -qE '/dev/root.*iso9660' /proc/mounts && ramoverlay
  24. +}
  25. +
  26. +boot_hook_add preinit_mount_root check_for_iso
  27. diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile
  28. index 13da511..8f0debd 100644
  29. --- a/target/linux/x86/image/Makefile
  30. +++ b/target/linux/x86/image/Makefile
  31. @@ -9,7 +9,8 @@ include $(INCLUDE_DIR)/image.mk
  32. export PATH=$(TARGET_PATH):/sbin
  33. -GRUB2_MODULES = biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial vga
  34. +GRUB2_MODULES = at_keyboard biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial vga
  35. +GRUB2_MODULES_ISO = at_keyboard biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial vga
  36. GRUB_TERMINALS =
  37. GRUB_SERIAL_CONFIG =
  38. GRUB_TERMINAL_CONFIG =
  39. @@ -51,7 +52,7 @@ ifneq ($(CONFIG_X86_GRUB_IMAGES),)
  40. define Image/cmdline/ext4
  41. root=$(ROOTPART) rootfstype=ext4 rootwait
  42. endef
  43. -
  44. +
  45. define Image/cmdline/jffs2-64k
  46. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
  47. endef
  48. @@ -165,7 +166,31 @@ define Image/Build/squashfs
  49. $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
  50. endef
  51. -define Image/Build/iso
  52. +ifdef CONFIG_X86_USE_GRUB2
  53. + define Image/Build/iso
  54. + $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
  55. + $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  56. + grub-mkimage \
  57. + -o $(KDIR)/grub2/eltorito.img \
  58. + -O i386-pc \
  59. + -c ./grub-early.cfg \
  60. + $(GRUB2_MODULES_ISO)
  61. + cat \
  62. + $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
  63. + $(KDIR)/grub2/eltorito.img \
  64. + > $(KDIR)/root.grub/boot/grub/eltorito.img
  65. + sed \
  66. + -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  67. + -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  68. + -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  69. + -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
  70. + ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
  71. + $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  72. + mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \
  73. + -o $(KDIR)/root.iso $(KDIR)/root.grub $(TARGET_DIR)
  74. + endef
  75. +else
  76. + define Image/Build/iso
  77. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
  78. $(CP) \
  79. $(KDIR)/stage2_eltorito \
  80. @@ -179,7 +204,8 @@ define Image/Build/iso
  81. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  82. mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table \
  83. -o $(KDIR)/root.iso $(KDIR)/root.grub
  84. -endef
  85. + endef
  86. +endif
  87. ifneq ($(CONFIG_X86_VDI_IMAGES),)
  88. define Image/Build/vdi
  89. diff --git a/target/linux/x86/image/grub-iso.cfg b/target/linux/x86/image/grub-iso.cfg
  90. new file mode 100644
  91. index 0000000..4d5d697
  92. --- /dev/null
  93. +++ b/target/linux/x86/image/grub-iso.cfg
  94. @@ -0,0 +1,10 @@
  95. +@SERIAL_CONFIG@
  96. +@TERMINAL_CONFIG@
  97. +
  98. +set default="0"
  99. +set timeout="@TIMEOUT@"
  100. +set root='(cd)'
  101. +
  102. +menuentry "OpenWrt" {
  103. + linux /boot/vmlinuz @CMDLINE@ noinitrd reboot=bios
  104. +}