Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] uboot: allow taking the entire default environment from a text file
@ 2024-06-17 16:00 Luca Ceresoli via buildroot
  2024-06-28 13:20 ` Kory Maincent via buildroot
  2024-07-12  9:23 ` Arnout Vandecappelle via buildroot
  0 siblings, 2 replies; 6+ messages in thread
From: Luca Ceresoli via buildroot @ 2024-06-17 16:00 UTC (permalink / raw)
  To: buildroot; +Cc: Köry Maincent, Luca Ceresoli, Thomas Petazzoni

By default U-Boot builds a default environment from its own configuration
and a board-specific set of variables. However it also allows to bypass
this entirely and define the entire default environment from a text file.

Expose this feature to Buildroot. This allows to have a file e.g. in
board/.../uboot.env which contains an easy to maintain text file with the
wanted default environment, without patching the U-Boot source code.

Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
 boot/uboot/Config.in | 29 +++++++++++++++++++++++++++++
 boot/uboot/uboot.mk  |  9 +++++++++
 2 files changed, 38 insertions(+)

diff --git a/boot/uboot/Config.in b/boot/uboot/Config.in
index f37040a28a97..a3bf3e009c52 100644
--- a/boot/uboot/Config.in
+++ b/boot/uboot/Config.in
@@ -136,6 +136,35 @@ config BR2_TARGET_UBOOT_CONFIG_FRAGMENT_FILES
 	  that will be merged to the main U-Boot configuration file.
 endif
 
+config BR2_TARGET_UBOOT_USE_DEFAULT_ENV_FILE
+	bool "Generate default environment from text file"
+	select BR2_TARGET_UBOOT_NEEDS_XXD
+	help
+	  Define the entire U-Boot default environment from a file,
+	  disabling all the logic to generate it from the U-Boot source
+	  code and other configuration values.
+
+	  Based on the USE_DEFAULT_ENV_FILE and DEFAULT_ENV_FILE U-Boot
+	  configuration variables.
+
+	  Requires U-Boot >= v2018.05.
+
+config BR2_TARGET_UBOOT_DEFAULT_ENV_FILE
+	string "Text file with default environment"
+	depends on BR2_TARGET_UBOOT_USE_DEFAULT_ENV_FILE
+	help
+	  Text file containing the variables to be used as the default
+	  environment in U-Boot.
+
+	  From the U-Boot documentation:
+
+	    The format is the same as accepted by the mkenvimage tool, with
+	    lines containing key=value pairs. Blank lines and lines
+	    beginning with '#' are ignored.
+
+	  For more info see:
+	  https://docs.u-boot.org/en/latest/usage/environment.html#external-environment-file
+
 config BR2_TARGET_UBOOT_NEEDS_DTC
 	bool "U-Boot needs dtc"
 	select BR2_PACKAGE_HOST_DTC
diff --git a/boot/uboot/uboot.mk b/boot/uboot/uboot.mk
index 19f4cdb557e6..3b3d3a13e711 100644
--- a/boot/uboot/uboot.mk
+++ b/boot/uboot/uboot.mk
@@ -390,6 +390,14 @@ UBOOT_KCONFIG_EDITORS = menuconfig xconfig gconfig nconfig
 # override again. In addition, host-ccache is not ready at kconfig
 # time, so use HOSTCC_NOCCACHE.
 UBOOT_KCONFIG_OPTS = $(UBOOT_MAKE_OPTS) HOSTCC="$(HOSTCC_NOCCACHE)" HOSTLDFLAGS=""
+
+ifeq ($(BR2_TARGET_UBOOT_USE_DEFAULT_ENV_FILE),y)
+UBOOT_DEFAULT_ENV_FILE = $(call qstrip,$(BR2_TARGET_UBOOT_DEFAULT_ENV_FILE))
+define UBOOT_KCONFIG_DEFAULT_ENV_FILE
+	$(call KCONFIG_SET_OPT,CONFIG_USE_DEFAULT_ENV_FILE,y)
+	$(call KCONFIG_SET_OPT,CONFIG_DEFAULT_ENV_FILE,"$(shell readlink -f $(UBOOT_DEFAULT_ENV_FILE))")
+endef
+endif
 endif # BR2_TARGET_UBOOT_BUILD_SYSTEM_LEGACY
 
 UBOOT_CUSTOM_DTS_PATH = $(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_DTS_PATH))
@@ -530,6 +538,7 @@ define UBOOT_KCONFIG_FIXUP_CMDS
 	$(UBOOT_ZYNQMP_KCONFIG_PMUFW)
 	$(UBOOT_ZYNQMP_KCONFIG_PM_CFG)
 	$(UBOOT_ZYNQMP_KCONFIG_PSU_INIT)
+	$(UBOOT_KCONFIG_DEFAULT_ENV_FILE)
 endef
 
 ifeq ($(BR2_TARGET_UBOOT)$(BR_BUILDING),yy)

---
base-commit: 7bfea9372f1842279a8f57b5fc4428bbae822e91
change-id: 20240617-uboot-default-env-46688521fbae

Best regards,
-- 
Luca Ceresoli <luca.ceresoli@bootlin.com>

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-07-16 12:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-17 16:00 [Buildroot] [PATCH] uboot: allow taking the entire default environment from a text file Luca Ceresoli via buildroot
2024-06-28 13:20 ` Kory Maincent via buildroot
2024-07-12  9:23 ` Arnout Vandecappelle via buildroot
2024-07-15 13:51   ` Luca Ceresoli via buildroot
2024-07-15 14:49     ` Arnout Vandecappelle via buildroot
2024-07-16 12:40       ` Luca Ceresoli via buildroot

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