mender-grubenv: new package
PATCH 1/1 mender-grubenv: new package
From: Adam Duskett <[email protected]>
Mender-grubenv contains the boot scripts and tools used by Mender to integrate with the Grub2 bootloader.
The user must select the following Grub modules for this package:
loadenv, hashsum, echo, halt, gcry_sha256, and test.
Because this patch also includes a grub version of fw_printenv and fw_setenv, package/mender/Config.in must be changed as well at the same time, because if both uboot-tools and this package are selected, during startup, mender calls the uboot-tools fw_printenv and fails to start.
Also included is an example mender_grubenv_defines which is needed during the compilation step. This file is set up to work with qemu based systems.
--- DEVELOPERS | 1 + package/Config.in | 1 + package/mender-grubenv/Config.in | 39 ++++++++++++++++ package/mender-grubenv/mender-grubenv.hash | 3 ++ package/mender-grubenv/mender-grubenv.mk | 44 +++++++++++++++++++ package/mender-grubenv/mender_grubenv_defines | 32 ++++++++++++++ package/mender/Config.in | 5 ++- 7 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 package/mender-grubenv/Config.in create mode 100644 package/mender-grubenv/mender-grubenv.hash create mode 100644 package/mender-grubenv/mender-grubenv.mk create mode 100644 package/mender-grubenv/mender_grubenv_defines
DEVELOPERS +1 -0
@@ -50,6 +50,7 @@ F: package/libselinux/ F: package/libsemanage/ F: package/libsepol/ F: package/libwebsockets/ +F: package/mender-grubenv/ F: package/nginx-naxsi/ F: package/openjdk/ F: package/openjdk-bin/
package/Config.in +1 -0
@@ -2168,6 +2168,7 @@ menu "System tools" source "package/libostree/Config.in" source "package/lxc/Config.in" source "package/mender/Config.in" + source "package/mender-grubenv/Config.in" source "package/monit/Config.in" source "package/ncdu/Config.in" source "package/numactl/Config.in"
package/mender-grubenv/Config.in new file +39 -0
@@ -0,0 +1,39 @@ +config BR2_PACKAGE_MENDER_GRUBENV + bool "mender-grubenv" + depends on BR2_TARGET_GRUB2_ARCH_SUPPORTS + depends on BR2_USE_WCHAR # grub2 + depends on BR2_PACKAGE_HOST_GO_HOST_ARCH_SUPPORTS + depends on BR2_TARGET_GRUB2 + help + Contains the boot scripts and tools used by Mender to + integrate with the GRUB bootloader. + + The following Grub modules must be selected for this package: + loadenv hashsum echo halt gcry_sha256 test + + https://github.com/mendersoftware/grub-mender-grubenv + +if BR2_PACKAGE_MENDER_GRUBENV + +config BR2_PACKAGE_MENDER_GRUBENV_DEFINES + string "path to grubenv defines" + default package/mender-grubenv/mender_grubenv_defines + help + Specify a path to the mender grubenv defines file. + The example file sets the following: + mender_rootfsa_part=2 + mender_rootfsb_part=3 + mender_kernel_root_base=/dev/vda + mender_grub_storage_device=hd0 + kernel_imagetype=bzImage + + WARNING: + Using the default mender_grubenv_defines file may cause your + system to not boot properly, as it has only been tested on + QEMU based systems! + +endif + +comment "mender-grubenv needs a grub2 bootloader and a toolchain w/ wchar" + depends on BR2_TARGET_GRUB2_ARCH_SUPPORTS + depends on !BR2_USE_WCHAR
package/mender-grubenv/mender-grubenv.hash new file +3 -0
@@ -0,0 +1,3 @@ +# Locally computed +sha256 e50cc18a844e3fd1edef7af9224733b0338a34d51f1186ee19803ef7af1a5065 1.3.0.tar.gz +sha256 98ed35b5a138f58164b5c0dbccd9d7f01ef4d84b9dba01e896f0a3241c50c0f7 LICENSE
package/mender-grubenv/mender-grubenv.mk new file +44 -0
44 lines not on this page · raw message
package/mender-grubenv/mender_grubenv_defines new file +32 -0
@@ -0,0 +1,32 @@ +################################################################################ +# Mandatory +################################################################################ +# Warning: This file is an example and should be customized to fit your needs! + +# Partition index of root filesystem A +mender_rootfsa_part=2 + +# Partition index of root filesystem B +mender_rootfsb_part=3 + +# Device file corresponding to the root filesystem partitions, without index. +mender_kernel_root_base=/dev/vda + +# Name of the storage device containing root filesystem partitions in GRUB +# format. +mender_grub_storage_device=hd0 + +# Type of kernel (bzImage or zImage) +kernel_imagetype=bzImage + +# Type of initrd image. +# Note: An initrd image is not strictly necessary, and the system will boot and +# update without a initrd image. +initrd_imagetype=initrd.img + +################################################################################ +# Mandatory on ARM +################################################################################ + +# Basename of DTB that should be loaded by the bootloader. +# kernel_devicetree=kernel.dtb
package/mender/Config.in +3 -2
@@ -3,8 +3,9 @@ config BR2_PACKAGE_MENDER depends on BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS depends on BR2_PACKAGE_HOST_GO_TARGET_CGO_LINKING_SUPPORTS depends on BR2_TOOLCHAIN_HAS_THREADS - select BR2_PACKAGE_UBOOT_TOOLS # runtime - select BR2_PACKAGE_UBOOT_TOOLS_FWPRINTENV # runtime + select BR2_PACKAGE_UBOOT_TOOLS if BR2_TARGET_UBOOT # runtime + select BR2_PACKAGE_UBOOT_TOOLS_FWPRINTENV if BR2_TARGET_UBOOT # runtime + select BR2_PACKAGE_MENDER_GRUBENV if BR2_TARGET_GRUB2 # runtime help Mender is an open source over-the-air (OTA) software updater for embedded Linux devices. Mender comprises a client
Signature · 1 line
2.20.1
PATCH 1/1 mender-grubenv: new package
On 19/03/2019 20:01, aduskett at gmail.com wrote:
[snip]
package/mender-grubenv/Config.in line 4
Quoted 4 lines
package/mender-grubenv/Config.in new file +4
-0+config BR2_PACKAGE_MENDER_GRUBENV + bool "mender-grubenv" + depends on BR2_TARGET_GRUB2_ARCH_SUPPORTS + depends on BR2_USE_WCHAR # grub2
These two are already handled by the dependency on grub2.
package/mender-grubenv/Config.in line 5
Quoted 1 line
package/mender-grubenv/Config.in new file +1
-0+ depends on BR2_PACKAGE_HOST_GO_HOST_ARCH_SUPPORTS
Why?
A dependency on mender itself might make sense as well.
package/mender-grubenv/Config.in line 12
Quoted 7 lines
package/mender-grubenv/Config.in new file +7
-0+ depends on BR2_TARGET_GRUB2 + help + Contains the boot scripts and tools used by Mender to + integrate with the GRUB bootloader. + + The following Grub modules must be selected for this package: + loadenv hashsum echo halt gcry_sha256 test
Do they have to be built-in? We install all grub modules, but there is a
limited list of builtin options (the ones that are needed to be able to find the rest of the modules).
Quoted 4 lines
package/mender-grubenv/Config.in new file +4
-0+ + https://github.com/mendersoftware/grub-mender-grubenv + +if BR2_PACKAGE_MENDER_GRUBENV
package/mender-grubenv/Config.in line 26
Quoted 10 lines
package/mender-grubenv/Config.in new file +10
-0+ +config BR2_PACKAGE_MENDER_GRUBENV_DEFINES + string "path to grubenv defines" + default package/mender-grubenv/mender_grubenv_defines + help + Specify a path to the mender grubenv defines file. + The example file sets the following: + mender_rootfsa_part=2 + mender_rootfsb_part=3 + mender_kernel_root_base=/dev/vda
That's a bit an unfortunate choice for the default, since it is very unlikely
to be correct. I think in practice /dev/mmcblk0p would be a more sensible default. Indeed, that doesn't work in qemu, but it will work on most systems that really use mender.
Quoted 28 lines
package/mender-grubenv/Config.in new file +13
-0+ mender_grub_storage_device=hd0 + kernel_imagetype=bzImage + + WARNING: + Using the default mender_grubenv_defines file may cause your + system to not boot properly, as it has only been tested on + QEMU based systems! + +endif + +comment "mender-grubenv needs a grub2 bootloader and a toolchain w/ wchar" + depends on BR2_TARGET_GRUB2_ARCH_SUPPORTS + depends on !BR2_USE_WCHARpackage/mender-grubenv/mender-grubenv.hash new file +3
-0@@ -0,0 +1,3 @@ +# Locally computed +sha256 e50cc18a844e3fd1edef7af9224733b0338a34d51f1186ee19803ef7af1a5065 1.3.0.tar.gz +sha256 98ed35b5a138f58164b5c0dbccd9d7f01ef4d84b9dba01e896f0a3241c50c0f7 LICENSEpackage/mender-grubenv/mender-grubenv.mk new file +0
-0
package/mender-grubenv/mender-grubenv.mk line 8
Quoted 8 lines
package/mender-grubenv/mender-grubenv.mk new file +8
-0@@ -0,0 +1,44 @@ +################################################################################ +# +# mender-grubenv +# +################################################################################ + +MENDER_GRUBENV_VERSION = 1.3.0 +MENDER_GRUBENV_SITE = https://github.com/mendersoftware/grub-mender-grubenv/archive
It's not an uploaded tarball so please use the github helper.
package/mender-grubenv/mender-grubenv.mk line 16
Quoted 8 lines
package/mender-grubenv/mender-grubenv.mk new file +8
-0+MENDER_GRUBENV_SOURCE = $(MENDER_GRUBENV_VERSION).tar.gz +MENDER_GRUBENV_LICENSE = Apache2.0 +MENDER_GRUBENV_LICENSE_FILES = LICENSE + +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/EFI/BOOT
This assumes that the efi partition will be mounted on /boot/efi. Will that be
the case?
It would be nice if this condition would be handled somehow from grub2.mk
itself, but I'm not sure if that would be useful in practice.
package/mender-grubenv/mender-grubenv.mk line 24
Quoted 8 lines
package/mender-grubenv/mender-grubenv.mk new file +8
-0+endif + +# These grub modules must be built 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 +MENDER_GRUBENV_MODULES_MISSING = \ + $(filter-out $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_MODULES)),\ + $(MENDER_GRUBENV_MANDATORY_MODULES))
If they really need to be built in, it's great to have this check.
package/mender-grubenv/mender-grubenv.mk line 29
Quoted 5 lines
package/mender-grubenv/mender-grubenv.mk new file +5
-0+ +ifeq ($(BR2_PACKAGE_MENDER_GRUBENV),y) +ifneq ($(MENDER_GRUBENV_MODULES_MISSING),) +$(error The following grub2 modules must be enabled for mender-grubenv to \ + work: $(MENDER_GRUBENV_MANDATORY_MODULES))
Would be more relevant to report the missing modules here.
package/mender-grubenv/mender-grubenv.mk line 35
Quoted 6 lines
package/mender-grubenv/mender-grubenv.mk new file +6
-0+endif +endif + +define MENDER_GRUBENV_BUILD_CMDS + cp -dpfr $(call qstrip,$(BR2_PACKAGE_MENDER_GRUBENV_DEFINES)) \ + $(@D)/mender_grubenv_defines
Small nit: this part seems more appropriate for the configure step.
package/mender-grubenv/mender-grubenv.mk line 36
Quoted 1 line
package/mender-grubenv/mender-grubenv.mk new file +1
-0+ $(TARGET_MAKE_ENV) ENV_DIR=$(MENDER_GRUBENV_ENV_DIR) $(MAKE) -C $(@D)
Small nit: since the same env is used again in the install step, it's better to
define a variable for it:
MENDER_GRUBENV_MAKE_ENV = \ $(TARGET_MAKE_ENV) \ ENV_DIR=$(MENDER_GRUBENV_ENV_DIR)
Also, I'd expect that TARGET_CONFIGURE_OPTS needs to be added to the
environment. Hm, it actually doesn't build anything so it's not strictly needed. But it's a good habit :-)
Quoted 36 lines
package/mender-grubenv/mender-grubenv.mk new file +8
-0+endef + +define MENDER_GRUBENV_INSTALL_TARGET_CMDS + $(TARGET_MAKE_ENV) ENV_DIR=$(MENDER_GRUBENV_ENV_DIR) $(MAKE) \ + DESTDIR=$(TARGET_DIR) -C $(@D) install +endef + +$(eval $(generic-package))package/mender-grubenv/mender_grubenv_defines new file +22
-0@@ -0,0 +1,32 @@ +################################################################################ +# Mandatory +################################################################################ +# Warning: This file is an example and should be customized to fit your needs! + +# Partition index of root filesystem A +mender_rootfsa_part=2 + +# Partition index of root filesystem B +mender_rootfsb_part=3 + +# Device file corresponding to the root filesystem partitions, without index. +mender_kernel_root_base=/dev/vda + +# Name of the storage device containing root filesystem partitions in GRUB +# format. +mender_grub_storage_device=hd0 + +# Type of kernel (bzImage or zImage) +kernel_imagetype=bzImage + +# Type of initrd image.
package/mender-grubenv/mender_grubenv_defines line 32
Quoted 10 lines
package/mender-grubenv/mender_grubenv_defines new file +10
-0+# Note: An initrd image is not strictly necessary, and the system will boot and +# update without a initrd image. +initrd_imagetype=initrd.img + +################################################################################ +# Mandatory on ARM +################################################################################ + +# Basename of DTB that should be loaded by the bootloader. +# kernel_devicetree=kernel.dtb
AFAICS, this is just a copy of the example, with the vda change and the
kernel.dtb commented out.
I don't think this is such a great idea...
I think it makes more sense to not provide our own, but instead copy the
example if BR2_PACKAGE_MENDER_GRUBENV_DEFINES is empty.
Also, it might make sense to automatically update some of the values while
copying. E.g. the kernel_imagetype can be derived from LINUX_IMAGE_NAME (but only if a kernel is actually built). But that would anyway be for a follow-up patch.
package/mender/Config.in config BR2_PACKAGE_MENDER · line 7
Quoted 12 lines
package/mender/Config.in +2
-2@@ -3,8 +3,9 @@ config BR2_PACKAGE_MENDER depends on BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS depends on BR2_PACKAGE_HOST_GO_TARGET_CGO_LINKING_SUPPORTS depends on BR2_TOOLCHAIN_HAS_THREADS - select BR2_PACKAGE_UBOOT_TOOLS # runtime - select BR2_PACKAGE_UBOOT_TOOLS_FWPRINTENV # runtime + select BR2_PACKAGE_UBOOT_TOOLS if BR2_TARGET_UBOOT # runtime + select BR2_PACKAGE_UBOOT_TOOLS_FWPRINTENV if BR2_TARGET_UBOOT # runtime
This is a bit meh, because uboot is not necessarily built as part of Buildroot.
But yeah, in that case the user can still select uboot tools manually.
This change really should be a separate patch though.
Regards,
Arnout
Quoted 5 lines
package/mender/Config.in +1
-0+ select BR2_PACKAGE_MENDER_GRUBENV if BR2_TARGET_GRUB2 # runtime help Mender is an open source over-the-air (OTA) software updater for embedded Linux devices. Mender comprises a client