Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Heiko Thiery <heiko.thiery@gmail.com>
To: buildroot@buildroot.org
Cc: Heiko Thiery <heiko.thiery@gmail.com>,
	Michael Walle <michael@walle.cc>,
	"Yann E . MORIN" <yann.morin.1998@free.fr>
Subject: [Buildroot] [PATCH] boot/uboot: add option to install custom environment file
Date: Fri,  4 Aug 2023 10:24:35 +0200	[thread overview]
Message-ID: <20230804082434.288173-1-heiko.thiery@gmail.com> (raw)

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

                 reply	other threads:[~2023-08-04  8:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230804082434.288173-1-heiko.thiery@gmail.com \
    --to=heiko.thiery@gmail.com \
    --cc=buildroot@buildroot.org \
    --cc=michael@walle.cc \
    --cc=yann.morin.1998@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox