Skip to contentSkip to conversation

boot/uboot: add option to install custom environment file

PATCH In review Heiko Thiery 2 participants 2 messages Aug 4, 2023 – Jul 12, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 boot/uboot: add option to install custom environment file

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 value of CONFIG_ENV_SOURCE_FILE must only contain the filename without the '.env' suffix.

Thus the buildroot option BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_FILE is added that needs the information about the target of the file in the buildroot environment.

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

These 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 <[email protected]>
Cc Yann E. MORIN <[email protected]>

---
v2: change to shell expansion instead of make shell expansion. With that
we make sure it is expanded right at the time the command is called.

 boot/uboot/Config.in | 10 ++++++++++
 boot/uboot/uboot.mk  | 19 +++++++++++++++++++
 2 files changed, 29 insertions(+)
boot/uboot/Config.in +10 -0
index 8b726eaa57..cbbf629ba6 100644
@@ -607,6 +607,16 @@ config BR2_TARGET_UBOOT_CUSTOM_DTS_PATH
 
 endif
 
+config BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_FILE
+	string "Custom environment file"
+	help
+	  Provide a custom u-boot environment file. This will be
+	  copied to the U-Boot source directory in the corresponding
+	  boardspecific folder and enabled via the U-Boot config
+	  option CONFIG_ENV_SOURCE_FILE. The target path will be
+	  determined based on the U-Boot configuration using
+	  CONFIG_SYS_VENDOR and CONFIG_SYS_BOARD.
+
 config BR2_TARGET_UBOOT_CUSTOM_MAKEOPTS
 	string "Custom make options"
 	help
boot/uboot/uboot.mk +19 -0
index b3d26b16fe..2007647e3b 100644
@@ -181,6 +181,24 @@ UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_ATF_FIRMWARE
 endif
 endif
 
+#
+# Prepare for custom environment
+#
+UBOOT_CUSTOM_ENVIRONMENT_FILE = $(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_FILE))
+UBOOT_ENV_FILE_NAME=$(patsubst %.env,%,$(notdir $(UBOOT_CUSTOM_ENVIRONMENT_FILE)))
+ifneq ($(UBOOT_CUSTOM_ENVIRONMENT_FILE),)
+define UBOOT_COPY_CUSTOM_ENVIRONMENT_FILE
+	sys_vendor=`BR2_PREFIX= utils/config --file $(@D)/.config -s CONFIG_SYS_VENDOR`; \
+	sys_board=`BR2_PREFIX= utils/config --file $(@D)/.config -s CONFIG_SYS_BOARD`; \
+	cp -f $(UBOOT_CUSTOM_ENVIRONMENT_FILE) $(@D)/board/$${sys_vendor}/$${sys_board}
+endef
+UBOOT_POST_CONFIGURE_HOOKS += UBOOT_COPY_CUSTOM_ENVIRONMENT_FILE
+
+define UBOOT_KCONFIG_CUSTOM_ENV_SOURCE
+	$(call KCONFIG_SET_OPT,CONFIG_ENV_SOURCE_FILE,"$(UBOOT_ENV_FILE_NAME)")
+endef
+endif  # UBOOT_CUSTOM_ENVIRONMENT_FILE != ""
+
 ifeq ($(BR2_TARGET_UBOOT_NEEDS_OPTEE_TEE),y)
 UBOOT_DEPENDENCIES += optee-os
 UBOOT_MAKE_OPTS += TEE=$(BINARIES_DIR)/tee.elf
@@ -497,6 +515,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)
Signature · 6 lines
2.30.2

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

Hi Heiko,

Thanks for reviving this old patch :-)

Quoted 6 lines · Heiko Thiery

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 value of CONFIG_ENV_SOURCE_FILE must only contain the filename without the '.env' suffix.

Quoted 6 lines

Thus the buildroot option BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_FILE is added that needs the information about the target of the file in the buildroot environment.

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

More recently, Luca has posted a patch [1] that achieves the same purpose but
using a different U-Boot config (why they have two configs doing essentially the same thing, I don't know...). Luca's version is a bit more elegant I think because it doesn't need this special directory.

Could you test that patch, change it if needed, and resend it? Luca hadn't
noticed that you had already sent a patch with the same purpose, by taking over his patch you can recover some of the credit :-)

Quoted 23 lines

These 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 <[email protected]>
Cc Yann E. MORIN <[email protected]>

---
v2: change to shell expansion instead of make shell expansion. With that
we make sure it is expanded right at the time the command is called.

  boot/uboot/Config.in | 10 ++++++++++
  boot/uboot/uboot.mk  | 19 +++++++++++++++++++
  2 files changed, 29 insertions(+)
boot/uboot/Config.in +0 -0
index 8b726eaa57..cbbf629ba6 100644
@@ -607,6 +607,16 @@ config BR2_TARGET_UBOOT_CUSTOM_DTS_PATH
 
  endif

boot/uboot/Config.in config BR2_TARGET_UBOOT_CUSTOM_DTS_PATH · line 618

Quoted 10 lines
boot/uboot/Config.in +9 -0
 
+config BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_FILE
+	string "Custom environment file"
+	help
+	  Provide a custom u-boot environment file. This will be
+	  copied to the U-Boot source directory in the corresponding
+	  boardspecific folder and enabled via the U-Boot config
+	  option CONFIG_ENV_SOURCE_FILE. The target path will be
+	  determined based on the U-Boot configuration using
+	  CONFIG_SYS_VENDOR and CONFIG_SYS_BOARD.

The help text should indicate the minimum U-Boot version that has this feature.

Regards,
Arnout

Quoted 34 lines
boot/uboot/Config.in +1 -0
+
  config BR2_TARGET_UBOOT_CUSTOM_MAKEOPTS
  	string "Custom make options"
  	help
boot/uboot/uboot.mk +18 -0
index b3d26b16fe..2007647e3b 100644
@@ -181,6 +181,24 @@ UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_ATF_FIRMWARE
  endif
  endif
 
+#
+# Prepare for custom environment
+#
+UBOOT_CUSTOM_ENVIRONMENT_FILE = $(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_FILE))
+UBOOT_ENV_FILE_NAME=$(patsubst %.env,%,$(notdir $(UBOOT_CUSTOM_ENVIRONMENT_FILE)))
+ifneq ($(UBOOT_CUSTOM_ENVIRONMENT_FILE),)
+define UBOOT_COPY_CUSTOM_ENVIRONMENT_FILE
+	sys_vendor=`BR2_PREFIX= utils/config --file $(@D)/.config -s CONFIG_SYS_VENDOR`; \
+	sys_board=`BR2_PREFIX= utils/config --file $(@D)/.config -s CONFIG_SYS_BOARD`; \
+	cp -f $(UBOOT_CUSTOM_ENVIRONMENT_FILE) $(@D)/board/$${sys_vendor}/$${sys_board}
+endef
+UBOOT_POST_CONFIGURE_HOOKS += UBOOT_COPY_CUSTOM_ENVIRONMENT_FILE
+
+define UBOOT_KCONFIG_CUSTOM_ENV_SOURCE
+	$(call KCONFIG_SET_OPT,CONFIG_ENV_SOURCE_FILE,"$(UBOOT_ENV_FILE_NAME)")
+endef
+endif  # UBOOT_CUSTOM_ENVIRONMENT_FILE != ""
+
  ifeq ($(BR2_TARGET_UBOOT_NEEDS_OPTEE_TEE),y)
  UBOOT_DEPENDENCIES += optee-os
  UBOOT_MAKE_OPTS += TEE=$(BINARIES_DIR)/tee.elf

boot/uboot/uboot.mk define UBOOT_KCONFIG_FIXUP_CMDS · line 521

Quoted 7 lines
boot/uboot/uboot.mk +1 -0
@@ -497,6 +515,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)

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot