Skip to contentSkip to conversation

package/uboot-tools: add option to build env bin

PATCH New Matt Weber 2 participants 3 messages May 8, 2020 – May 10, 2020

lore
Share & tools
lore

Matt Weber

author
#0 lore raw

PATCH 1/1 package/uboot-tools: add option to build env bin

Add an option to allow the creation of a u-boot environment binary from a set of provided source file(s) when the defconfig being built does not offer the option via the u-boot package.

This feature requires environment source files unlike the u-boot package equivalent that can build the default environment based on the specific u-boot source tree and configuration.

---

I did not add conditions to force the user to use the u-boot pkg option if that is available. Seemed unnecessary as this would still work in that case.

---
 package/uboot-tools/Config.in.host | 54 ++++++++++++++++++++++++++++--
 package/uboot-tools/uboot-tools.mk | 13 +++++++
 2 files changed, 65 insertions(+), 2 deletions(-)
package/uboot-tools/Config.in.host +52 -2
index 52a4c2ec30..fccd40e4e4 100644
@@ -37,6 +37,56 @@ config BR2_PACKAGE_HOST_UBOOT_TOOLS_FIT_SIGNATURE_SUPPORT
 	  public key is stored in a non-volatile place, any image can
 	  be verified in this way.
 
-endif
+endif # BR2_PACKAGE_HOST_UBOOT_TOOLS_FIT_SUPPORT
 
-endif
+config BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE
+	bool "Environment image"
+	help
+	  Generate a valid binary environment image from a text file
+	  describing the key=value pairs of the environment.
+
+	  This option can be useful to build enviornment configurations
+	  as part of a Linux / rootfs only defconfig instead of using
+	  post scripts. This supports a hardware use case of a single
+	  bootloader only defconfig but multiple Linux / rootfs
+	  defconfigs with different boot environments.
+
+	  The environment image will be called uboot-env.bin.
+
+if BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE
+
+config BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE
+	string "Source files for environment"
+	help
+	  Text files describing the environment. Files should have
+	  lines of the form var=value, one per line. Blank lines and
+	  lines starting with a # are ignored.
+
+	  Multiple source files are concatenated in the order listed.
+
+	  Unlike the U-Boot package, the source files must be provided
+	  as there is no uboot configured to define the compiled-in env.
+
+config BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SIZE
+	string "Size of environment"
+	help
+	  Size of envronment, can be prefixed with 0x for hexadecimal
+	  values.
+
+config BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_REDUNDANT
+	bool "Environment has two copies"
+	help
+	  Some platforms define in their U-Boot configuration that the
+	  U-Boot environment should be duplicated in two locations (for
+	  extra safety). Check your U-Boot configuration for the
+	  CONFIG_ENV_ADDR_REDUND and CONFIG_ENV_SIZE_REDUND settings to
+	  see if this is the case for your platform.
+
+	  If it is the case, then you should enable this option to
+	  ensure that the U-Boot environment image generated by
+	  Buildroot is compatible with the "redundant environment"
+	  mechanism of U-Boot.
+
+endif # BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE
+
+endif # BR2_PACKAGE_HOST_UBOOT_TOOLS
package/uboot-tools/uboot-tools.mk +13 -0
index 55d1123bc8..de665e8fbf 100644
@@ -112,10 +112,23 @@ define HOST_UBOOT_TOOLS_BUILD_CMDS
 	$(BR2_MAKE1) -C $(@D) $(HOST_UBOOT_TOOLS_MAKE_OPTS) tools-only
 endef
 
+ifneq ($(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE),)
+UBOOT_TOOLS_GENERATE_ENV_FILE = $(call qstrip,$(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE))
+define UBOOT_TOOLS_GENERATE_ENV_IMAGE
+	cat $(UBOOT_TOOLS_GENERATE_ENV_FILE) > $(@D)/buildroot-env.txt
+	$(HOST_DIR)/bin/mkenvimage -s $(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SIZE) \
+		$(if $(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_REDUNDANT),-r) \
+		$(if $(filter "BIG",$(BR2_ENDIAN)),-b) \
+		-o $(BINARIES_DIR)/uboot-env.bin \
+		$(@D)/buildroot-env.txt
+endef
+endif
+
 define HOST_UBOOT_TOOLS_INSTALL_CMDS
 	$(INSTALL) -m 0755 -D $(@D)/tools/mkimage $(HOST_DIR)/bin/mkimage
 	$(INSTALL) -m 0755 -D $(@D)/tools/mkenvimage $(HOST_DIR)/bin/mkenvimage
 	$(INSTALL) -m 0755 -D $(@D)/tools/dumpimage $(HOST_DIR)/bin/dumpimage
+	$(UBOOT_TOOLS_GENERATE_ENV_IMAGE)
 endef
 
 $(eval $(generic-package))
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 package/uboot-tools: add option to build env bin

Hello Matt,

Quoted 3 lines · On Fri, 8 May 2020 13:13:04 -0500 Matt Weber…

Add an option to allow the creation of a u-boot environment binary from a set of provided source file(s) when the defconfig being built does not offer the option via the u-boot package.

I don't understand why we need this, when we already have BR2_TARGET_UBOOT_ENVIMAGE and related options in U-Boot.

I don't see how the logic behind BR2_TARGET_UBOOT_ENVIMAGE depends on the defconfig being built.

Could you clarify ?

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

PATCH 1/1 package/uboot-tools: add option to build env bin

Thomas,

Quoted 10 lines · Thomas Petazzoni

Hello Matt,

Quoted 3 lines · On Fri, 8 May 2020 13:13:04 -0500 Matt Weber…

Add an option to allow the creation of a u-boot environment binary from a set of provided source file(s) when the defconfig being built does not offer the option via the u-boot package.

Quoted 5 lines

I don't understand why we need this, when we already have BR2_TARGET_UBOOT_ENVIMAGE and related options in U-Boot.

I don't see how the logic behind BR2_TARGET_UBOOT_ENVIMAGE depends on the defconfig being built.

The use case is when a defconfig doesn't select the u-boot package (thus there isn't any uboot cfg / source code and the BR2_TARGET_UBOOT_ENVIMAGE's dependencies on a uboot package build
isn't met to allow creating the env file). Maybe we should move the
creation of this env file (BR2_TARGET_UBOOT_ENVIMAGE) to uboot-tools by default and when the uboot package is also built, evaluate if the source files list is empty to generate a image from the uboot package's compiled-in env defaults (ie. uses the uboot's scripts/get_default_envs.sh).

Matt