[Buildroot] [RFC v2] boot/uboot: add option to install custom environment file

Heiko Thiery heiko.thiery at gmail.com
Thu Aug 3 12:10:04 UTC 2023


U-Boot has the capability to set the environment variables via a text file.
The text file has to be located in the U-Boot board source directory and
selected via the CONFIG_ENV_SOURCE_FILE option. The CONFIG_ENV_SOURCE_FILE
must only contain the filename without the '.env' suffix.

Thus the buildroot option BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT is added
that needs the information about the source of the file in the buildroot
environment (BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_SOURCE).

Since the environment file must be located in the U-Boot board source
directory. This directory is <SRC>/board/<VENDOR>/<BOARDNAME>.

Thes information about vendor name and board name are available in the
U-Boot .config file and can be extracted from there to determine the
destination directoy.

Cc: Michael Walle <michael at walle.cc>
Signed-off-by: Heiko Thiery <heiko.thiery at gmail.com>
---
v2: Drop the BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_TARGET option and
    determine the value from the applied u-boot defconfig (.config).
	Adopt the commit message according these changes.


 boot/uboot/Config.in | 16 ++++++++++++++++
 boot/uboot/uboot.mk  | 21 +++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/boot/uboot/Config.in b/boot/uboot/Config.in
index 8b726eaa57..894a0bd3b2 100644
--- a/boot/uboot/Config.in
+++ b/boot/uboot/Config.in
@@ -607,6 +607,22 @@ config BR2_TARGET_UBOOT_CUSTOM_DTS_PATH
 
 endif
 
+config BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT
+	bool "custom environment"
+	help
+	  Provide a custom u-boot environment file. This will be
+	  copied to the U-Boot source path and enabled via the
+	  U-Boot config option CONFIG_ENV_SOURCE_FILE. The target
+	  path will be determined based on the U-Boot configuration.
+
+if BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT
+config BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_SOURCE
+	string "Custom environment source file"
+	help
+	  Path to U-Boot custom environment file.
+
+endif
+
 config BR2_TARGET_UBOOT_CUSTOM_MAKEOPTS
 	string "Custom make options"
 	help
diff --git a/boot/uboot/uboot.mk b/boot/uboot/uboot.mk
index b3d26b16fe..35e26ade2d 100644
--- a/boot/uboot/uboot.mk
+++ b/boot/uboot/uboot.mk
@@ -181,6 +181,26 @@ UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_ATF_FIRMWARE
 endif
 endif
 
+#
+# Prepare for custom environment
+#
+ifeq ($(BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT),y)
+ifeq ($(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_SOURCE)),)
+$(error No custom environment source file specified, check your BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_SOURCE setting)
+endif
+
+define UBOOT_COPY_CUSTOM_ENVIRONMENT_FILE
+	cp -f $(BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_SOURCE) $(@D)/board/$(shell grep CONFIG_SYS_VENDOR $(@D)/.config | sed 's/.*=//' | sed 's/"//g')/$(shell grep CONFIG_SYS_BOARD $(@D)/.config | sed 's/.*=//' | sed 's/"//g')/
+endef
+UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_CUSTOM_ENVIRONMENT_FILE
+
+
+UBOOT_ENV_FILE_NAME=$(subst .env,,$(notdir $(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_SOURCE))))
+define UBOOT_KCONFIG_CUSTOM_ENV_SOURCE
+	$(call KCONFIG_SET_OPT,CONFIG_ENV_SOURCE_FILE,"$(UBOOT_ENV_FILE_NAME)")
+endef
+endif
+
 ifeq ($(BR2_TARGET_UBOOT_NEEDS_OPTEE_TEE),y)
 UBOOT_DEPENDENCIES += optee-os
 UBOOT_MAKE_OPTS += TEE=$(BINARIES_DIR)/tee.elf
@@ -497,6 +517,7 @@ define UBOOT_KCONFIG_FIXUP_CMDS
 	$(UBOOT_ZYNQMP_KCONFIG_PMUFW)
 	$(UBOOT_ZYNQMP_KCONFIG_PM_CFG)
 	$(UBOOT_ZYNQMP_KCONFIG_PSU_INIT)
+	$(UBOOT_KCONFIG_CUSTOM_ENV_SOURCE)
 endef
 
 ifeq ($(BR2_TARGET_UBOOT)$(BR_BUILDING),yy)
-- 
2.30.2




More information about the buildroot mailing list