[Buildroot] [PATCH v3 2/7] boot/grub2: add support to build multiple Grub2 configurations in the same build
Köry Maincent
kory.maincent at bootlin.com
Fri Oct 8 08:20:33 UTC 2021
On Thu, 7 Oct 2021 18:29:31 +0200
"Yann E. MORIN" <yann.morin.1998 at free.fr> wrote:
> Köry, All,
>
> On 2021-10-07 14:43 +0200, Köry Maincent spake thusly:
> > On Thu, 7 Oct 2021 11:53:26 +0200
> > "Yann E. MORIN" <yann.morin.1998 at free.fr> wrote:
> [--SNIP--]
> > > By using --with-platform=none in the main CONF_OPTS, we should be able
> > > to disable building any of the "images", and just build the tools.
> > >
> > > Totally untested, of course...
> > As I said if we do that we won't have all the Grub modules in the target
> > directory. I think these modules are quiet important, an user that wants to
> > use grub-mkimage will surely use them for example.
>
> OK, I had a hard time understanding what you meant... But indeed,
> BR2_TARGET_GRUB2_INSTALL_TOOLS *also* wants to install the modules in
> target/
Sorry I was maybe not clear enough.
I was speaking about all the .mod and .module files installed in the
/target/lib/grub/$(GRUB2_TUPLES-$(tuple)) directory when calling the "make
install" command. If we use none as platform they are not generated, therefore
installed.
Here is the list of installed file if I add "make install" in the foreach
loop: https://termbin.com/8b4w
Here is the list of installed file in the case of none
platform: https://termbin.com/x45h
>
> In this case, this should not be too complex either; we just need a
> post-image hook that copies all modules into TARGET_DIR, like:
Yes it could works, but the installation of the module is not really proper, see
below.
>
> diff --git a/boot/grub2/grub2.mk b/boot/grub2/grub2.mk
> index e01ebb2edb..0bb10d765d 100644
> --- a/boot/grub2/grub2.mk
> +++ b/boot/grub2/grub2.mk
> @@ -50,11 +50,6 @@ GRUB2_IGNORE_CVES += CVE-2019-14865
> # version available in Buildroot.
> GRUB2_IGNORE_CVES += CVE-2020-15705
>
> -ifeq ($(BR2_TARGET_GRUB2_INSTALL_TOOLS),y)
> -GRUB2_INSTALL_TARGET = YES
> -else
> -GRUB2_INSTALL_TARGET = NO
> -endif
> GRUB2_CPE_ID_VENDOR = gnu
>
> GRUB2_BUILTIN_MODULES_PC = $(call
> qstrip,$(BR2_TARGET_GRUB2_BUILTIN_MODULES_PC)) @@ -127,6 +122,9 @@
> GRUB2_TUPLES-$(BR2_TARGET_GRUB2_ARM64_EFI) += arm64-efi HOST_GRUB2_CONF_ENV =
> \ CPP="$(HOSTCC) -E"
>
> +# Main build: only build tools
> +GRUB2_CONF_OPTS = --with-platform=none --blabla...
> +
> GRUB2_CONF_ENV = \
> CPP="$(TARGET_CC) -E" \
> TARGET_CC="$(TARGET_CC)" \
> @@ -147,7 +145,7 @@ HOST_GRUB2_CONF_OPTS = \
> --enable-libzfs=no \
> --disable-werror
>
> -define GRUB2_CONFIGURE_CMDS
> +define GRUB2_CONFIGURE_CMDS_PTF
> $(foreach tuple, $(GRUB2_TUPLES-y), \
> mkdir -p $(@D)/build-$(tuple) ; \
> cd $(@D)/build-$(tuple) ; \
> @@ -169,14 +167,16 @@ define GRUB2_CONFIGURE_CMDS
> --disable-werror
> )
> endef
> +GRUB2_POST_CONFIGURE_HOOKS += GRUB2_CONFIGURE_CMDS_PTF
>
> -define GRUB2_BUILD_CMDS
> +define GRUB2_BUILD_CMDS_PTF
> $(foreach tuple, $(GRUB2_TUPLES-y), \
> $(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/build-$(tuple)
> )
> endef
> +GRUB2_POST_BUILD_HOOKS += GRUB2_BUILD_CMDS_PTF
>
> -define GRUB2_INSTALL_IMAGES_CMDS
> +define GRUB2_INSTALL_IMAGES_CMDS_PTF
> $(foreach tuple, $(GRUB2_TUPLES-y), \
> mkdir -p $(dir $(GRUB2_IMAGE_$(tuple))) ; \
> $(HOST_DIR)/usr/bin/grub-mkimage \
> @@ -194,6 +194,23 @@ define GRUB2_INSTALL_IMAGES_CMDS
> ) \
> )
> endef
> +GRUB2_POST_INSTALL_IMAGES_HOOKS += GRUB2_INSTALL_IMAGES_CMDS_PTF
>
> -$(eval $(generic-package))
> +ifeq ($(BR2_TARGET_GRUB2_INSTALL_TOOLS),y)
> +GRUB2_INSTALL_TARGET = YES
> +define GRUB2_INSTALL_MODS_IN_TARGET
> + mkdir -p $(TARGET_DIR)/boot
> + $(foreach tuple, $(GRUB2_TUPLES-y), \
> + cp -a $(GRUB2_IMAGE_$(tuple)) $(TARGET_DIR)/boot/
Here you copy only the image generated, not the modules. It should more be like
that:
$(foreach tuple, $(GRUB2_TUPLES-y), \
mkdir -p $(TARGET_DIR)/usr/lib/$(tuple) \
cp -a $(@D)/build-$(tuple)/grub-core/{*.mod,*.module} \
$(TARGET_DIR)/usr/lib/$(tuple)
We might also need *.img file because cdboot.img is needed to create CDROM
drive image.
Or we also could "make install" each platform in a temporary folder then copy
the content of tmp-folder-$(tuple)/usr/lib/$(tuple) in the $(TARGET_DIR) but I
am not sure it is better than just "make install" directly in the $(TARGET_DIR).
> + )
> +endef
> +# **YES** this is a post-install-image hook that installs in target/
> +# **AND** we need it to be registered **LAST**, after all the per-tuple
> +# image-install hooks
> +GRUB2_POST_INSTALL_IMAGES_HOOKS += GRUB2_INSTALL_MODS_IN_TARGET
> +else
> +GRUB2_INSTALL_TARGET = NO
> +endif
> +
> +$(eval $(autotools-package))
> $(eval $(host-autotools-package))
>
>
> NOTE: yes, I know that $(GRUB2_IMAGE_$(tuple)) is not exactly what we
> need to copy, and that it will need some additional tweaking.
>
> But then, maybe installing all the per-tuple to target/ might just
> work in the end. That would not be nice, but as Thomas already said,
> grub2 is already not nice anyway...
Yeah, not sure what is the better solution.
> Also, I just noticed that we copy the cdboot.img from the host dir! Are
> the modules all there?
You may have copy a wrong code because it won't install cdboot.img in the
$(TARGET_DIR) with the code below.
Regards,
Köry
More information about the buildroot
mailing list