Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] boot/uboot: add option to install custom environment file
@ 2023-08-04  8:24 Heiko Thiery
  0 siblings, 0 replies; only message in thread
From: Heiko Thiery @ 2023-08-04  8:24 UTC (permalink / raw)
  To: buildroot; +Cc: Heiko Thiery, Michael Walle, Yann E . MORIN

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 <michael@walle.cc>
Cc: Yann E. MORIN <yann.morin.1998@free.fr>
Signed-off-by: Heiko Thiery <heiko.thiery@gmail.com>
---
 boot/uboot/Config.in | 10 ++++++++++
 boot/uboot/uboot.mk  | 19 +++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/boot/uboot/Config.in b/boot/uboot/Config.in
index 8b726eaa57..cbbf629ba6 100644
--- a/boot/uboot/Config.in
+++ b/boot/uboot/Config.in
@@ -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
diff --git a/boot/uboot/uboot.mk b/boot/uboot/uboot.mk
index b3d26b16fe..847cc7648a 100644
--- a/boot/uboot/uboot.mk
+++ b/boot/uboot/uboot.mk
@@ -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=$(shell BR2_PREFIX= utils/config --file $(@D)/.config -s CONFIG_SYS_VENDOR); \
+	sys_board=$(shell 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)
-- 
2.30.2

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-04  8:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-04  8:24 [Buildroot] [PATCH] boot/uboot: add option to install custom environment file Heiko Thiery

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox