boot/uboot: add option to install custom environment file
RFC 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 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.
---
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(+)
boot/uboot/Config.in +16 -0
@@ -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
boot/uboot/uboot.mk +21 -0
@@ -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)
Signature · 6 lines
2.30.2 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Heiko, All,
On 2023-08-03 14:10 +0200, Heiko Thiery spake thusly:
Quoted 12 lines
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_FILEoption. TheCONFIG_ENV_SOURCE_FILEmust only contain the filename without the '.env' suffix.Thus the buildroot option
BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENTis 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>.
Quoted 7 lines
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 <[email protected]>Signed-off-by Heiko Thiery <[email protected]>---
[--SNIP--]
Quoted 13 lines
boot/uboot/Config.in +5
-0@@ -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
boot/uboot/Config.in config BR2_TARGET_UBOOT_CUSTOM_DTS_PATH · line 624
Quoted 10 lines
boot/uboot/Config.in +10
-0+ 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
We don't really need a boolean option to guard a single string option. I know we tend to do that a lot, but I find that to be an anti-pattern.
In this case, the empty string is as good as saying "no" to the boolean option, so we can just live with the sting option, and then (see below)...
(of course, if the empty string _has_ a special meaning, then we'd need a boolean, but that's usually not the case in such situations).
Quoted 8 lines
boot/uboot/Config.in +0
-0config BR2_TARGET_UBOOT_CUSTOM_MAKEOPTS string "Custom make options" helpboot/uboot/uboot.mk +0
-0
boot/uboot/uboot.mk UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_ATF_FIRMWARE · line 190
Quoted 10 lines
boot/uboot/uboot.mk +7
-0@@ -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
... we don't need to check the sanity of the settings: empty means don't use a custom env file, set means use that file as custom env file.
boot/uboot/uboot.mk UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_ATF_FIRMWARE · line 193
Quoted 2 lines
boot/uboot/uboot.mk +2
-0+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')/
Please split this line into easier-to-parse construct, see below...
boot/uboot/uboot.mk UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_ATF_FIRMWARE · line 195
Quoted 2 lines
boot/uboot/uboot.mk +2
-0+endef +UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_CUSTOM_ENVIRONMENT_FILE
Is it a pre-build or a post-configure hook? I would think it should be a post-configure one...
boot/uboot/uboot.mk UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_ATF_FIRMWARE · line 198
Quoted 3 lines
boot/uboot/uboot.mk +3
-0+ + +UBOOT_ENV_FILE_NAME=$(subst .env,,$(notdir $(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_SOURCE))))
$(patsubst %.env,%,$(notdir $(UBOOT_CUSTOM_ENVIRONMENT_SOURCE)))
boot/uboot/uboot.mk UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_ATF_FIRMWARE · line 202
Quoted 4 lines
boot/uboot/uboot.mk +4
-0+define UBOOT_KCONFIG_CUSTOM_ENV_SOURCE + $(call KCONFIG_SET_OPT,CONFIG_ENV_SOURCE_FILE,"$(UBOOT_ENV_FILE_NAME)") +endef +endif
So, the .mk code would look like;
UBOOT_CUSTOM_ENVIRONMENT_SOURCE = $(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_SOURCE)))
UBOOT_ENV_FILE_NAME=$(patsubst %.env,%,$(notdir $(UBOOT_CUSTOM_ENVIRONMENT_SOURCE)))
ifneq ($(UBOOT_CUSTOM_ENVIRONMENT_SOURCE),)
define UBOOT_COPY_CUSTOM_ENVIRONMENT_FILE
sys_config=$( ./utils/config --file $(@D)/.config -s CONFIG_SYS_VENDOR ); \
sys_board=$( ./utils/config --file $(@D)/.config -s CONFIG_SYS_BOARD ); \
cp -f $(UBOOT_CUSTOM_ENVIRONMENT_SOURCE) $(@D)/board/$${sys_config}/$${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_SOURCE != ""Regards,
Yann E. MORIN.
Quoted 19 lines
boot/uboot/uboot.mk +2
-0+ 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)Signature · 6 lines
2.30.2 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------' _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Hi Yann,
Am Do., 3. Aug. 2023 um 21:41 Uhr schrieb Yann E. MORIN <[email protected]>:
Quoted 51 lines
Heiko, All,
On 2023-08-03 14:10 +0200, Heiko Thiery spake thusly:
Quoted 12 lines
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_FILEoption. TheCONFIG_ENV_SOURCE_FILEmust only contain the filename without the '.env' suffix.Thus the buildroot option
BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENTis 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>.
Quoted 7 lines
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 <[email protected]>Signed-off-by Heiko Thiery <[email protected]>---
[--SNIP--]
Quoted 13 lines
boot/uboot/Config.in +5
-0@@ -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 theboot/uboot/Config.in config BR2_TARGET_UBOOT_CUSTOM_DTS_PATH · line 624
Quoted 10 lines
boot/uboot/Config.in +10
-0+ 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. + +endifWe don't really need a boolean option to guard a single string option. I know we tend to do that a lot, but I find that to be an anti-pattern.
Quoted 5 lines
In this case, the empty string is as good as saying "no" to the boolean option, so we can just live with the sting option, and then (see below)...
(of course, if the empty string _has_ a special meaning, then we'd need a boolean, but that's usually not the case in such situations).
Ok, makes sense. Previously I had 2 config options for source and destination and removed the destination in v2.
Quoted 11 lines
Quoted 11 lines
boot/uboot/Config.in +0
-0config BR2_TARGET_UBOOT_CUSTOM_MAKEOPTS string "Custom make options" helpboot/uboot/uboot.mk +0
-0@@ -181,6 +181,26 @@ UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_ATF_FIRMWARE endif endif
Quoted 10 lines
boot/uboot/uboot.mk UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_ATF_FIRMWARE · line 190
Quoted 7 lines
boot/uboot/uboot.mk +7
-0+# +# 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... we don't need to check the sanity of the settings: empty means don't use a custom env file, set means use that file as custom env file.
Ok
Quoted 11 lines
boot/uboot/uboot.mk UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_ATF_FIRMWARE · line 193
Quoted 3 lines
boot/uboot/uboot.mk +2
-0+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')/Please split this line into easier-to-parse construct, see below...
boot/uboot/uboot.mk UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_ATF_FIRMWARE · line 195
Quoted 2 lines
boot/uboot/uboot.mk +2
-0+endef +UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_CUSTOM_ENVIRONMENT_FILEIs it a pre-build or a post-configure hook? I would think it should be a post-configure one...
I wanted to do it like the other steps, copy the files to the source folder before building.
- UBOOT_COPY_ATF_FIRMWARE
- UBOOT_COPY_IMX_FW_FILES
Quoted 14 lines
boot/uboot/uboot.mk UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_ATF_FIRMWARE · line 198
Quoted 4 lines
boot/uboot/uboot.mk +3
-0+ + +UBOOT_ENV_FILE_NAME=$(subst .env,,$(notdir $(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_SOURCE))))$(patsubst %.env,%,$(notdir $(UBOOT_CUSTOM_ENVIRONMENT_SOURCE)))
boot/uboot/uboot.mk UBOOT_PRE_BUILD_HOOKS += UBOOT_COPY_ATF_FIRMWARE · line 202
Quoted 4 lines
boot/uboot/uboot.mk +4
-0+define UBOOT_KCONFIG_CUSTOM_ENV_SOURCE + $(call KCONFIG_SET_OPT,CONFIG_ENV_SOURCE_FILE,"$(UBOOT_ENV_FILE_NAME)") +endef +endifSo, the .mk code would look like;
Quoted 5 lines
UBOOT_CUSTOM_ENVIRONMENT_SOURCE = $(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_ENVIRONMENT_SOURCE)))
UBOOT_ENV_FILE_NAME=$(patsubst %.env,%,$(notdir $(UBOOT_CUSTOM_ENVIRONMENT_SOURCE)))
ifneq ($(UBOOT_CUSTOM_ENVIRONMENT_SOURCE),)
define UBOOT_COPY_CUSTOM_ENVIRONMENT_FILE
sys_config=$( ./utils/config --file $(@D)/.config -s CONFIG_SYS_VENDOR ); \Creating a subshell to get the output of uitls/config does not work that way. I have to do $(shell ...). But with that it works ;-)
Quoted 10 lines
sys_board=$( ./utils/config --file $(@D)/.config -s CONFIG_SYS_BOARD ); \
cp -f $(UBOOT_CUSTOM_ENVIRONMENT_SOURCE) $(@D)/board/$${sys_config}/$${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_SOURCE != ""Quoted 2 lines
Regards,
Yann E. MORIN.
Many thanks for your comments! I will retest and prepare a v3.
Signature · 5 lines
Heiko _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot