[Buildroot] [PATCHv5] package/mender-grubenv: fix grub module checks

Adam Duskett aduskett at gmail.com
Wed Dec 1 17:29:37 UTC 2021


Hello;

Thank you for the help Yann! I really appreciate your time!

On Tue, Nov 30, 2021 at 1:55 PM Yann E. MORIN <yann.morin.1998 at free.fr> wrote:
>
> From: Adam Duskett <aduskett at gmail.com>
>
> Commit b68810e70cbd (boot/grub2: add support to build multiple Grub2
> configurations in the same build) broke mender-grubenv by splititng up
> BR2_TARGET_GRUB2_BUILTIN_MODULES into two separate symbols, one for
> legacy boot, and one for EFI boot.
>
> This causes a systematic build failure now, as the legacy variable
> BR2_TARGET_GRUB2_BUILTIN_MODULES is now always empty (during build).
>
> We fix that by suplicating the missing modules check: one for EFI and
> one for legacy boot.
>
> The EFI check is tricky: idneed, there can be more than one EFI platform
> enabled simlutaneouslyl indeed, on x86_64 we can have bothe ehte 32-bit
> and 64-bit EFI platforms enabled. So the check is inverted, and we check
> that no platform is not enabled (yeah, double negation). For consistency,
> we do the same for the legacy b oot, even though in that case there can
> only ever be only one enabled at once at most.
>
> Finally, the install commands are split into two macros, that are also
> defined conditionally under the same conditions as the checks are done.
>
> Signed-off-by: Adam Duskett <aduskett at gmail.com>
> [yann.morin.1998 at free.fr:
>   - drop superfluous check on empty modules lists
>   - move EFI and legacy commands under same condition as checks
> ]
> Signed-off-by: Yann E. MORIN <yann.morin.1998 at free.fr>
> ---
> changes v1 -> v2:
>   - Change ifeq ($(BR2_TARGET_GRUB2_X86_64_EFI),y) to
>     ifneq ($(BR2_TARGET_GRUB2_BUILTIN_MODULES_EFI),) to cover all grub2
> efi
>     scenarios. (Thomas)
>
>   - Change BR2_TARGET_GRUB2_BUILTIN_MODULES to
>     BR2_TARGET_GRUB2_BUILTIN_MODULES_PC (thomas)
>
> Changes v2 -> v3:
>   - Check for both MODULES_EFI and MODULES_PC (Thomas)
>
> Changes v3 -> v4:
>   - Add qstrips to needed variables (Thomas)
>   - Check for empty module lists (Thomas)
>   - Split up MENDER_GRUBENV_INSTALL_IMAGES_CMDS to work with pc and efi
>     at the
>     same time.
>
> Changes v4 -> v5 (Yann):
>   - drop superfluous check on empty modules lists
>   - move EFI and legacy commands under same condition as checks
> ---
>  package/mender-grubenv/mender-grubenv.mk | 56 ++++++++++++++++--------
>  1 file changed, 37 insertions(+), 19 deletions(-)
>
> diff --git a/package/mender-grubenv/mender-grubenv.mk b/package/mender-grubenv/mender-grubenv.mk
> index 07df25512c..a910f55cb4 100644
> --- a/package/mender-grubenv/mender-grubenv.mk
> +++ b/package/mender-grubenv/mender-grubenv.mk
> @@ -31,14 +31,44 @@ MENDER_GRUBENV_DEFINES = \
>  # These grub modules must be built in for the grub scripts to work properly.
>  # Without them, the system will not boot.
>  MENDER_GRUBENV_MANDATORY_MODULES=loadenv hashsum echo halt gcry_sha256 test regexp
> -MENDER_GRUBENV_MODULES_MISSING = \
> -       $(filter-out $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_MODULES)),\
> +
> +# grub2 does not provide a syntetic EFI option, so check all of them
> +ifneq ($(BR2_TARGET_GRUB2_I386_EFI)$(BR2_TARGET_GRUB2_X86_64_EFI)$(BR2_TARGET_GRUB2_ARM_EFI)$(BR2_TARGET_GRUB2_ARM64_EFI),)
> +MENDER_GRUBENV_MODULES_MISSING_EFI = \
> +       $(filter-out $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_MODULES_EFI)),\
>                 $(MENDER_GRUBENV_MANDATORY_MODULES))
>
> +define MENDER_GRUBENV_INSTALL_EFI_CFG
> +       mkdir -p $(BINARIES_DIR)/efi-part/EFI/BOOT
> +       cp -dpfr $(TARGET_DIR)/boot/EFI/BOOT/grub.cfg \
> +               $(TARGET_DIR)/boot/EFI/BOOT/mender_grubenv* \
> +               $(BINARIES_DIR)/efi-part/EFI/BOOT
> +endef
> +endif
> +
> +# grub2 does not provide a syntetic legacy boot option, so check all of them
> +ifneq ($(BR2_TARGET_GRUB2_I386_PC)$(BR2_TARGET_GRUB2_ARM_UBOOT),)
> +MENDER_GRUBENV_MODULES_MISSING_PC = \
> +       $(filter-out $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_MODULES_PC)),\
> +               $(MENDER_GRUBENV_MANDATORY_MODULES))
> +
> +define MENDER_GRUBENV_INSTALL_I386_CFG
> +       mkdir -p $(BINARIES_DIR)/boot-part/grub
> +       cp -dpfr $(TARGET_DIR)/boot/grub/grub.cfg \
> +               $(TARGET_DIR)/boot/grub/mender_grubenv* \
> +               $(BINARIES_DIR)/boot-part/grub
> +endef
> +endif
> +
>  ifeq ($(BR2_PACKAGE_MENDER_GRUBENV)$(BR_BUILDING),yy)
> -ifneq ($(MENDER_GRUBENV_MODULES_MISSING),)
> -$(error The following missing grub2 modules must be enabled for mender-grubenv \
> -       to work: $(MENDER_GRUBENV_MODULES_MISSING))
> +ifneq ($(MENDER_GRUBENV_MODULES_MISSING_EFI),)
> +$(error The following missing grub2 efi modules must be enabled for mender-grubenv \
> +       to work: $(MENDER_GRUBENV_MODULES_MISSING_EFI))
> +endif
> +
> +ifneq ($(MENDER_GRUBENV_MODULES_MISSING_PC),)
> +$(error The following missing grub2 pc modules must be enabled for mender-grubenv \
> +       to work: $(MENDER_GRUBENV_MODULES_MISSING_PC))
>  endif
>  endif
>
> @@ -54,21 +84,9 @@ define MENDER_GRUBENV_INSTALL_TARGET_CMDS
>         $(MENDER_GRUBENV_MAKE_ENV) $(MAKE) DESTDIR=$(TARGET_DIR) -C $(@D) install
>  endef
>
> -# Overwrite the default grub2 config files with the ones in this package.
> -ifeq ($(BR2_TARGET_GRUB2_I386_PC)$(BR2_TARGET_GRUB2_ARM_UBOOT),y)
>  define MENDER_GRUBENV_INSTALL_IMAGES_CMDS
> -       mkdir -p $(BINARIES_DIR)/boot-part/grub
> -       cp -dpfr $(TARGET_DIR)/boot/grub/grub.cfg \
> -               $(TARGET_DIR)/boot/grub/mender_grubenv* \
> -               $(BINARIES_DIR)/boot-part/grub
> +       $(MENDER_GRUBENV_INSTALL_I386_CFG)
> +       $(MENDER_GRUBENV_INSTALL_EFI_CFG)
>  endef
> -else
> -define MENDER_GRUBENV_INSTALL_IMAGES_CMDS
> -       mkdir -p $(BINARIES_DIR)/efi-part/EFI/BOOT
> -       cp -dpfr $(TARGET_DIR)/boot/EFI/BOOT/grub.cfg \
> -               $(TARGET_DIR)/boot/EFI/BOOT/mender_grubenv* \
> -               $(BINARIES_DIR)/efi-part/EFI/BOOT
> -endef
> -endif
>
Bleh, unfortunately, this fails if multiple grubs are selected thanks
to the following lines in the .mk file:

ifeq ($(BR2_TARGET_GRUB2_I386_PC)$(BR2_TARGET_GRUB2_ARM_UBOOT),y)
MENDER_GRUBENV_ENV_DIR = /boot/grub
else
MENDER_GRUBENV_ENV_DIR = /boot/EFI/BOOT
endif

This fails with the following error:
mkdir -p output/images/boot-part/grub
cp -dpfr output/target/boot/grub/grub.cfg
output/target/boot/grub/mender_grubenv* output/images/boot-part/grub
mkdir -p output/images/efi-part/EFI/BOOT
cp -dpfr output/target/boot/EFI/BOOT/grub.cfg
output/target/boot/EFI/BOOT/mender_grubenv*
output/images/efi-part/EFI/BOOT
cp: cannot stat 'output/target/boot/EFI/BOOT/grub.cfg': No such file
or directory
cp: cannot stat 'output/target/boot/EFI/BOOT/mender_grubenv*': No such
file or directory

What would you suggest?

Adam
>  $(eval $(generic-package))
> --
> 2.25.1
>



More information about the buildroot mailing list