package/mender-grubenv: fix grub module checks

Commit b68810e70c (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 change 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 supplicating the missing modules to check: one for EFI and
one for legacy boot.

The EFI check is tricky: Indeed, there can be more than one EFI platform
enabled simultaneously; indeed, on x86_64, we can have both the 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 boot, even though in that case, there can
only ever be only one enabled at once at most.

Furthermore, mender-grubenv does not support multiple installations of
grub concurrently; it can only be installed for either legacy or EFI,
not both at the same time: /etc/mender-grubenv.cfg, its configuration
file, can only contain settings for one or the other, not both.

So we add a new check to Config.in to support only one grub installation
type at a time.

Signed-off-by: Adam Duskett <aduskett@gmail.com>
[yann.morin.1998@free.fr:
  - drop superfluous check on empty modules lists
  - move EFI and legacy commands under same condition as checks
  - variables were renamed
  - misc eye-candy
]
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Cc: Köry Maincent <kory.maincent@bootlin.com>
This commit is contained in:
Adam Duskett 2021-12-03 10:51:06 -08:00 committed by Yann E. MORIN
parent 8be79fbc53
commit 4d5b209384
2 changed files with 40 additions and 20 deletions

View File

@ -3,6 +3,7 @@ config BR2_PACKAGE_MENDER_GRUBENV
depends on BR2_TARGET_GRUB2_ARCH_SUPPORTS
depends on BR2_PACKAGE_MENDER # runtime
depends on BR2_TARGET_GRUB2
depends on !(BR2_TARGET_GRUB2_HAS_LEGACY_BOOT && BR2_TARGET_GRUB2_HAS_EFI_BOOT)
help
Contains the boot scripts and tools used by Mender to
integrate with the GRUB bootloader.
@ -34,3 +35,7 @@ comment "mender-grubenv needs a grub2 bootloader"
depends on BR2_TARGET_GRUB2_ARCH_SUPPORTS
depends on BR2_PACKAGE_MENDER
depends on !BR2_TARGET_GRUB2
comment "mender-grubenv does not support both legacy and EFI grub2 bootloaders at the same time"
depends on BR2_PACKAGE_MENDER
depends on BR2_TARGET_GRUB2_HAS_LEGACY_BOOT && BR2_TARGET_GRUB2_HAS_EFI_BOOT

View File

@ -13,7 +13,7 @@ MENDER_GRUBENV_LICENSE_FILES = LICENSE
MENDER_GRUBENV_DEPENDENCIES = grub2
MENDER_GRUBENV_INSTALL_IMAGES = YES
ifeq ($(BR2_TARGET_GRUB2_I386_PC)$(BR2_TARGET_GRUB2_ARM_UBOOT),y)
ifeq ($(BR2_TARGET_GRUB_LEGACY),y)
MENDER_GRUBENV_ENV_DIR = /boot/grub
else
MENDER_GRUBENV_ENV_DIR = /boot/EFI/BOOT
@ -31,14 +31,41 @@ 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)),\
ifeq ($(BR2_TARGET_GRUB2_HAS_LEGACY_BOOT),y)
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)$(MENDER_GRUBENV_ENV_DIR)/grub.cfg \
$(TARGET_DIR)$(MENDER_GRUBENV_ENV_DIR)/mender_grubenv* \
$(BINARIES_DIR)/boot-part/grub
endef
endif # BR2_TARGET_GRUB2_HAS_LEGACY_BOOT
ifeq ($(BR2_TARGET_GRUB2_HAS_EFI_BOOT),y)
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)$(MENDER_GRUBENV_ENV_DIR)/grub.cfg \
$(TARGET_DIR)$(MENDER_GRUBENV_ENV_DIR)/mender_grubenv* \
$(BINARIES_DIR)/efi-part/EFI/BOOT
endef
endif # BR2_TARGET_GRUB2_HAS_EFI_BOOT
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 +81,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
$(eval $(generic-package))