Skip to content

Commit

Permalink
fs/iso9660: add support for hybrid image using Grub2 on BIOS and EFI
Browse files Browse the repository at this point in the history
Add support for building an hybrid ISO9660 image compatible with legacy
and UEFI BIOS. Note that this is not about an (iso)hybrid image, which
can boot from both a CDROM or a USB stick, but really about an image
being bootable from the legay BIOS or EFI; the two are orthognal.

The option -eltorito-alt-boot need to be used in the xorriso command
to generate the hybrid image. That option is a separator, meaning the
previous boot entry is done, and the following boot options define a new
boot entry.

The -no-emul-boot defines the type of the current boot image; that's why
it has to now be repeated in each of the BIOS and EFI options.

Finally, for symetry and consistency between the BIOS and EFI options,
we move the BIOS image option first.

Note: the BIOS boot image options have to be provided before the EFI
ones, or the system won't boot; the underlying reason is not known...

Signed-off-by: Kory Maincent <[email protected]>
[[email protected]:
  - note about hybrid vs. (iso)hybrid
  - explain -eltorito-alt-boot
  - explain duplication of -no-emul-boot
  - rename the variables
  - note about the BIOS-EFI ordering
]
Signed-off-by: Yann E. MORIN <[email protected]>
  • Loading branch information
kmaincent authored and yann-morin-1998 committed Sep 29, 2021
1 parent 3b16591 commit 5916cc5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
16 changes: 7 additions & 9 deletions fs/iso9660/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ choice
config BR2_TARGET_ROOTFS_ISO9660_GRUB2
bool "grub2"
depends on BR2_TARGET_GRUB2
select BR2_TARGET_ROOTFS_ISO9660_BIOS_BOOTLOADER \
if BR2_TARGET_GRUB2_I386_PC
select BR2_TARGET_ROOTFS_ISO9660_EFI_BOOTLOADER \
if (BR2_TARGET_GRUB2_I386_EFI || BR2_TARGET_GRUB2_X86_64_EFI)
help
Use Grub 2 as the bootloader for the ISO9660 image. Make
sure to enable the 'iso9660' module in
Expand All @@ -39,21 +43,15 @@ config BR2_TARGET_ROOTFS_ISO9660_GRUB2
config BR2_TARGET_ROOTFS_ISO9660_ISOLINUX
bool "isolinux"
depends on BR2_TARGET_SYSLINUX_ISOLINUX
select BR2_TARGET_ROOTFS_ISO9660_BIOS_BOOTLOADER

endchoice

choice
prompt "Boot payload"

config BR2_TARGET_ROOTFS_ISO9660_BIOS_BOOTLOADER
bool "legacy bios"
depends on BR2_TARGET_GRUB2_I386_PC || BR2_TARGET_ROOTFS_ISO9660_ISOLINUX
bool

config BR2_TARGET_ROOTFS_ISO9660_EFI_BOOTLOADER
bool "UEFI"
depends on BR2_TARGET_GRUB2_I386_EFI || BR2_TARGET_GRUB2_X86_64_EFI

endchoice
bool

config BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU
string "Boot menu config file"
Expand Down
45 changes: 28 additions & 17 deletions fs/iso9660/iso9660.mk
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,20 @@ ROOTFS_ISO9660_DEPENDENCIES += grub2
ROOTFS_ISO9660_BOOTLOADER_CONFIG_PATH = \
$(ROOTFS_ISO9660_TMP_TARGET_DIR)/boot/grub/grub.cfg
ROOTFS_ISO9660_BOOT_IMAGE = boot/grub/grub-eltorito.img
define ROOTFS_ISO9660_INSTALL_BOOTLOADER
define ROOTFS_ISO9660_INSTALL_BOOTLOADER_BIOS
$(INSTALL) -D -m 0644 $(BINARIES_DIR)/grub-eltorito.img \
$(ROOTFS_ISO9660_TMP_TARGET_DIR)/boot/grub/grub-eltorito.img
endef
else ifeq ($(BR2_TARGET_ROOTFS_ISO9660_GRUB2)$(BR2_TARGET_ROOTFS_ISO9660_EFI_BOOTLOADER),yy)
endif

ifeq ($(BR2_TARGET_ROOTFS_ISO9660_GRUB2)$(BR2_TARGET_ROOTFS_ISO9660_EFI_BOOTLOADER),yy)
ROOTFS_ISO9660_DEPENDENCIES += grub2 host-dosfstools host-mtools
ROOTFS_ISO9660_EFI_PARTITION = boot/fat.efi
ROOTFS_ISO9660_EFI_PARTITION_PATH = $(ROOTFS_ISO9660_TMP_TARGET_DIR)/$(ROOTFS_ISO9660_EFI_PARTITION)
ROOTFS_ISO9660_EFI_PARTITION_CONTENT = $(BINARIES_DIR)/efi-part
ROOTFS_ISO9660_BOOTLOADER_CONFIG_PATH = \
$(ROOTFS_ISO9660_TMP_TARGET_DIR)/boot/grub/grub.cfg
define ROOTFS_ISO9660_INSTALL_BOOTLOADER
define ROOTFS_ISO9660_INSTALL_BOOTLOADER_EFI
rm -rf $(ROOTFS_ISO9660_EFI_PARTITION_PATH)
mkdir -p $(dir $(ROOTFS_ISO9660_EFI_PARTITION_PATH))
dd if=/dev/zero of=$(ROOTFS_ISO9660_EFI_PARTITION_PATH) bs=1M count=1
Expand All @@ -90,12 +92,14 @@ define ROOTFS_ISO9660_INSTALL_BOOTLOADER
$(ROOTFS_ISO9660_EFI_PARTITION_CONTENT)/* ::/
$(ROOTFS_ISO9660_FIX_TIME) $(ROOTFS_ISO9660_EFI_PARTITION_PATH)
endef
else ifeq ($(BR2_TARGET_ROOTFS_ISO9660_ISOLINUX),y)
endif

ifeq ($(BR2_TARGET_ROOTFS_ISO9660_ISOLINUX),y)
ROOTFS_ISO9660_DEPENDENCIES += syslinux
ROOTFS_ISO9660_BOOTLOADER_CONFIG_PATH = \
$(ROOTFS_ISO9660_TMP_TARGET_DIR)/isolinux/isolinux.cfg
ROOTFS_ISO9660_BOOT_IMAGE = isolinux/isolinux.bin
define ROOTFS_ISO9660_INSTALL_BOOTLOADER
define ROOTFS_ISO9660_INSTALL_BOOTLOADER_BIOS
$(INSTALL) -D -m 0644 $(BINARIES_DIR)/syslinux/* \
$(ROOTFS_ISO9660_TMP_TARGET_DIR)/isolinux/
$(INSTALL) -D -m 0644 $(HOST_DIR)/share/syslinux/ldlinux.c32 \
Expand All @@ -108,7 +112,8 @@ define ROOTFS_ISO9660_PREPARATION
$(ROOTFS_ISO9660_BOOTLOADER_CONFIG_PATH)
$(SED) "s%__KERNEL_PATH__%/boot/$(LINUX_IMAGE_NAME)%" \
$(ROOTFS_ISO9660_BOOTLOADER_CONFIG_PATH)
$(ROOTFS_ISO9660_INSTALL_BOOTLOADER)
$(ROOTFS_ISO9660_INSTALL_BOOTLOADER_BIOS)
$(ROOTFS_ISO9660_INSTALL_BOOTLOADER_EFI)
endef

ROOTFS_ISO9660_PRE_GEN_HOOKS += ROOTFS_ISO9660_PREPARATION
Expand Down Expand Up @@ -152,21 +157,27 @@ ROOTFS_ISO9660_PRE_GEN_HOOKS += ROOTFS_ISO9660_DISABLE_EXTERNAL_INITRD

endif # ROOTFS_ISO9660_USE_INITRD

ROOTFS_ISO9660_OPTS += \
-J \
-R \
-no-emul-boot
ROOTFS_ISO9660_OPTS += -J -R

ifeq ($(BR2_TARGET_ROOTFS_ISO9660_BIOS_BOOTLOADER),y)
ROOTFS_ISO9660_OPTS += \
ROOTFS_ISO9660_OPTS_BIOS = \
-b $(ROOTFS_ISO9660_BOOT_IMAGE) \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-b $(ROOTFS_ISO9660_BOOT_IMAGE)
endif
-boot-info-table

ROOTFS_ISO9660_OPTS_EFI = \
--efi-boot $(ROOTFS_ISO9660_EFI_PARTITION) \
-no-emul-boot

ifeq ($(BR2_TARGET_ROOTFS_ISO9660_EFI_BOOTLOADER),y)
ifeq ($(BR2_TARGET_ROOTFS_ISO9660_BIOS_BOOTLOADER)$(BR2_TARGET_ROOTFS_ISO9660_EFI_BOOTLOADER),yy)
ROOTFS_ISO9660_OPTS += \
--efi-boot $(ROOTFS_ISO9660_EFI_PARTITION)
$(ROOTFS_ISO9660_OPTS_BIOS) \
-eltorito-alt-boot \
$(ROOTFS_ISO9660_OPTS_EFI)
else ifeq ($(BR2_TARGET_ROOTFS_ISO9660_BIOS_BOOTLOADER),y)
ROOTFS_ISO9660_OPTS += $(ROOTFS_ISO9660_OPTS_BIOS)
else ifeq ($(BR2_TARGET_ROOTFS_ISO9660_EFI_BOOTLOADER),y)
ROOTFS_ISO9660_OPTS += $(ROOTFS_ISO9660_OPTS_EFI)
endif

define ROOTFS_ISO9660_CMD
Expand Down

0 comments on commit 5916cc5

Please sign in to comment.