Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Yann E. MORIN" <yann.morin.1998@free.fr>
To: Kory Maincent <kory.maincent@bootlin.com>
Cc: thomas.petazzoni@bootlin.com, buildroot@buildroot.org
Subject: Re: [Buildroot] [PATCH 4/8] fs/iso9660: add support to Grub EFI bootloader in the image
Date: Sat, 18 Sep 2021 14:19:55 +0200	[thread overview]
Message-ID: <20210918121955.GL1053080@scaer> (raw)
In-Reply-To: <20210914093457.1389174-5-kory.maincent@bootlin.com>

Köry, All,

On 2021-09-14 11:34 +0200, Kory Maincent spake thusly:
> Add support to boot the Grub bootloader from an EFI BIOS in the ISO9660
> image.
> For that we need to create EFI System Partition (ESP). The ESP is a vfat
> partition which contain the Grub2 binary at the /EFI/BOOT/ location.
> xorriso command will generate the iso image including the ESP.
> 
> We notice Grub can not read and mount the ESP, therefore we place the Grub
> configuration file in the ISO9660 partition. A Grub2 builtin configuration
> need to be used to tell Grub2 to search automatically its configuration
> file in the ISO9660 partition.

I am not sure I got that last sentence. Did you refer to using 'cd' or
'root=(cd0)' as explain in the config help?

Also see further review below...

> Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
> ---
>  fs/iso9660/Config.in  | 30 ++++++++++++++++++++++++------
>  fs/iso9660/iso9660.mk | 33 ++++++++++++++++++++++++++++++---
>  2 files changed, 54 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/iso9660/Config.in b/fs/iso9660/Config.in
> index 6f001c0640..4fc96db28c 100644
> --- a/fs/iso9660/Config.in
> +++ b/fs/iso9660/Config.in
> @@ -3,6 +3,7 @@ config BR2_TARGET_ROOTFS_ISO9660
>  	depends on (BR2_i386 || BR2_x86_64)
>  	depends on BR2_LINUX_KERNEL
>  	depends on BR2_TARGET_GRUB2_I386_PC || \
> +		BR2_TARGET_GRUB2_I386_EFI || BR2_TARGET_GRUB2_X86_64_EFI || \
>  		BR2_TARGET_SYSLINUX_ISOLINUX
>  	select BR2_LINUX_KERNEL_INSTALL_TARGET \
>  	       if (!BR2_TARGET_ROOTFS_ISO9660_INITRD && !BR2_TARGET_ROOTFS_INITRAMFS)
> @@ -27,22 +28,38 @@ choice
>  
>  config BR2_TARGET_ROOTFS_ISO9660_GRUB2
>  	bool "grub2"
> -	depends on BR2_TARGET_GRUB2_I386_PC
> +	depends on BR2_TARGET_GRUB2_I386_PC || BR2_TARGET_GRUB2_I386_EFI || \
> +		BR2_TARGET_GRUB2_X86_64_EFI
> +	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
> -	  BR2_TARGET_GRUB2_BUILTIN_MODULES and to use 'cd' as the boot
> -	  partition in BR2_TARGET_GRUB2_BOOT_PARTITION=.
> +	  BR2_TARGET_GRUB2_BUILTIN_MODULES_PC or
> +	  BR2_TARGET_GRUB2_BUILTIN_MODULES_EFI. Use 'cd' as the boot
> +	  partition in BR2_TARGET_GRUB2_BOOT_PARTITION= for GRUB on BIOS
> +	  or 'set root=(cd0)' in the configuration file passed to
> +	  BR2_TARGET_GRUB2_BUILTIN_CONFIG_EFI for GRUB on EFI.
>  
>  config BR2_TARGET_ROOTFS_ISO9660_ISOLINUX
>  	bool "isolinux"
>  	depends on BR2_TARGET_SYSLINUX_ISOLINUX
> +	select BR2_TARGET_ROOTFS_ISO9660_BIOS_BOOTLOADER
>  
>  endchoice
>  
> +config BR2_TARGET_ROOTFS_ISO9660_BIOS_BOOTLOADER
> +	bool
> +
> +config BR2_TARGET_ROOTFS_ISO9660_EFI_BOOTLOADER
> +	bool
> +
>  config BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU
>  	string "Boot menu config file"
> -	default "fs/iso9660/grub.cfg" if BR2_TARGET_ROOTFS_ISO9660_GRUB2
> +	default "fs/iso9660/grub.cfg" if BR2_TARGET_ROOTFS_ISO9660_GRUB2_PC || \
> +					BR2_TARGET_ROOTFS_ISO9660_GRUB2_EFI
>  	default "fs/iso9660/isolinux.cfg" if BR2_TARGET_ROOTFS_ISO9660_ISOLINUX
>  	help
>  	  Use this option to provide a custom bootloader configuration
> @@ -83,7 +100,8 @@ config BR2_TARGET_ROOTFS_ISO9660_HYBRID
>  
>  endif
>  
> -comment "iso image needs a Linux kernel and either grub2 i386-pc or isolinux to be built"
> +comment "iso image needs a Linux kernel and either grub2 or isolinux to be built"
>  	depends on BR2_i386 || BR2_x86_64
>  	depends on !BR2_LINUX_KERNEL || \
> -		!(BR2_TARGET_GRUB2_I386_PC || BR2_TARGET_SYSLINUX_ISOLINUX)
> +		!(BR2_TARGET_GRUB2_I386_PC || BR2_TARGET_GRUB2_I386_EFI || \
> +		BR2_TARGET_GRUB2_X86_64_EFI || BR2_TARGET_SYSLINUX_ISOLINUX)
> diff --git a/fs/iso9660/iso9660.mk b/fs/iso9660/iso9660.mk
> index f80b735858..4e4c5de1d0 100644
> --- a/fs/iso9660/iso9660.mk
> +++ b/fs/iso9660/iso9660.mk
> @@ -57,15 +57,31 @@ else
>  ROOTFS_ISO9660_TMP_TARGET_DIR = $(TARGET_DIR)
>  endif
>  
> -ifeq ($(BR2_TARGET_ROOTFS_ISO9660_GRUB2),y)
> +ifeq ($(BR2_TARGET_ROOTFS_ISO9660_GRUB2)$(BR2_TARGET_ROOTFS_ISO9660_BIOS_BOOTLOADER),yy)
>  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
> +	mkdir -p $(dir ROOTFS_ISO9660_BOOT_IMAGE)

This looks really dubious. The CWD is always Buidroot's top directory,
so this would create boot/grub/ in Buildroot's tree. Weird...

>  	$(INSTALL) -D -m 0644 $(BINARIES_DIR)/grub-eltorito.img \
>  		$(ROOTFS_ISO9660_TMP_TARGET_DIR)/boot/grub/grub-eltorito.img

... as this directory should normally be created with this "install -D".

>  endef
> +else 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
> +	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
> +	$(HOST_DIR)/sbin/mkfs.vfat $(ROOTFS_ISO9660_EFI_PARTITION_PATH)

We probably want to use --invariant with BR2_REPRODUCIBLE...

> +	$(HOST_DIR)/bin/mcopy -i $(ROOTFS_ISO9660_EFI_PARTITION_PATH) -s \
> +		$(ROOTFS_ISO9660_EFI_PARTITION_CONTENT)/* ::/

We may also need at least -m (Preserve the file modification time), and
maybe also -p (Preserves the attributes of the copied files), again with
BR2_REPRODUCIBLE (or always).

> +endef
>  else ifeq ($(BR2_TARGET_ROOTFS_ISO9660_ISOLINUX),y)
>  ROOTFS_ISO9660_DEPENDENCIES += syslinux
>  ROOTFS_ISO9660_BOOTLOADER_CONFIG_PATH = \
> @@ -128,9 +144,20 @@ ROOTFS_ISO9660_PRE_GEN_HOOKS += ROOTFS_ISO9660_DISABLE_EXTERNAL_INITRD
>  
>  endif # ROOTFS_ISO9660_USE_INITRD
>  
> +ifeq ($(BR2_TARGET_ROOTFS_ISO9660_BIOS_BOOTLOADER),y)
> +ROOTFS_ISO9660_XORRISO_BOOTLOADER_OPTS = \
> +	-J -R -b $(ROOTFS_ISO9660_BOOT_IMAGE) \
> +	$(ROOTFS_ISO9660_XORRISO_BOOTLOADER_COMMON_OPTS) \
> +	-boot-load-size 4 -boot-info-table -no-emul-boot

No need to introduce another variable, just use the existing one (notice
I have renamed it when applying previous patches) (I also tend to prefer
cionstant options first, then configurable ones last, unless order is
important), and for multi-line assignments, put one "option" per line:

    ROOTFS_ISO9660_OPTS += \
        -J \
        -R \
        -boot-load-size 4 \
        -boot-info-table \
        -no-emul-boot \
        -b $(ROOTFS_ISO9660_BOOT_IMAGE)

ROOTFS_ISO9660_XORRISO_BOOTLOADER_COMMON_OPTS is never set, and indeed
you removed it in patch 5. Just do not introduce it to begin with, I
guess? ;-)

> +else ifeq ($(BR2_TARGET_ROOTFS_ISO9660_EFI_BOOTLOADER),y)
> +ROOTFS_ISO9660_XORRISO_BOOTLOADER_OPTS = \
> +	--efi-boot $(ROOTFS_ISO9660_EFI_PARTITION) \
> +	-no-emul-boot

Ditto.

> +endif
> +
>  define ROOTFS_ISO9660_CMD
> -	$(HOST_DIR)/bin/xorriso -as mkisofs -J -R -b $(ROOTFS_ISO9660_BOOT_IMAGE) \
> -		-no-emul-boot -boot-load-size 4 -boot-info-table \
> +	$(HOST_DIR)/bin/xorriso -as mkisofs \
> +		$(ROOTFS_ISO9660_XORRISO_BOOTLOADER_OPTS) \
>  		$(ROOTFS_ISO9660_XORRISO_OPTS) \
>  		-o $@ $(ROOTFS_ISO9660_TMP_TARGET_DIR)
>  endef
> -- 
> 2.25.1
> 
> _______________________________________________
> buildroot mailing list
> buildroot@lists.buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@lists.buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  reply	other threads:[~2021-09-18 12:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-14  9:34 [Buildroot] [PATCH 0/8] Add support for ISO9660 image compatible with Legacy and EFI BIOS Kory Maincent
2021-09-14  9:34 ` [Buildroot] [PATCH 1/8] boot/grub2: add support to build multiple Grub2 configurations in the same build Kory Maincent
2021-09-17 21:24   ` Yann E. MORIN
2021-09-18  8:50     ` Thomas Petazzoni
2021-09-18  9:54       ` Yann E. MORIN
2021-09-14  9:34 ` [Buildroot] [PATCH 2/8] package/xorriso: build host variant with zlib support Kory Maincent
2021-09-17 19:52   ` Yann E. MORIN
2021-09-14  9:34 ` [Buildroot] [PATCH 3/8] fs/iso9660: switch from cdrkit to xorriso to build ISO9660 images Kory Maincent
2021-09-17 20:17   ` Yann E. MORIN
2021-09-14  9:34 ` [Buildroot] [PATCH 4/8] fs/iso9660: add support to Grub EFI bootloader in the image Kory Maincent
2021-09-18 12:19   ` Yann E. MORIN [this message]
2021-09-14  9:34 ` [Buildroot] [PATCH 5/8] fs/iso9660: add support for hybrid image using Grub bootloader on BIOS and EFI Kory Maincent
2021-09-14  9:34 ` [Buildroot] [PATCH 6/8] support/testing/infra/emulator.py: update encoding when calling qemu Kory Maincent
2021-09-14  9:34 ` [Buildroot] [PATCH 7/8] package/edk2-images: new package Kory Maincent
2021-09-17 13:43   ` D. Olsson via buildroot
2021-09-17 14:14     ` Thomas Petazzoni
2021-09-17 19:24       ` Yann E. MORIN
2021-09-14  9:34 ` [Buildroot] [PATCH 8/8] support/testing/tests/fs/test_iso9660.py: add support to test using EFI BIOS Kory Maincent

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210918121955.GL1053080@scaer \
    --to=yann.morin.1998@free.fr \
    --cc=buildroot@buildroot.org \
    --cc=kory.maincent@bootlin.com \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox