[RFC RFT PATCH] env: spl: filter the variables in default environment of SPL or TPL

Patrick Delaunay patrick.delaunay at st.com
Wed Mar 18 15:36:02 CET 2020

Use a new option CONFIG_SPL_ENV_VARS to filter the variables included
in the default environment used in SPL (and TPL).

That allows to reduce the size of default_environment[].

If the new configuration flags CONFIG_SPL_ENV_VARS is
- "" the default environment is empty (default)
- list of variables (comma separated) to keept in SPL/TPL
  (it searches ^<var>= in u-boot-initial-env)
- "*" the variables are not filtered

Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>

I propose this patch to reduce the SPL/TPL size when they support the
U-Boot environment.

But I need feedback, review and test (mainly for first boot when
environment in storage device is empty) to:
- confirm this patch can be acceptable
- confirm my assumptions on the list of variable used in SPL:
  empty by default in this first version.

This patch adds a filter on the environment variables present
in default environment of U-Boot, so SPL/TPL only include the required

I assumed the SPL/TPL environment can be empty by default (I filter all
the variables) because I think the environment is only needed when it is
loaded from external storage device; on cold boot and before to save env,
the content of default environment it is not necessary (To be confirmed).

For example, with falcon mode SPL need the environment to have the bootcmd
(load address , the file name to load and the the bootargs) only after
a first boot and after a correct 'env save' in U-Boot.

But I can update the default value for CONFIG_SPL_ENV_VARS to add
some generic variable to solve any raised issues:

PS: the current behavior (no filter) is kept when

I propose this patch after remarks on previous patch v4


It is a preliminary step for v5 of this serie.


 Makefile              | 32 ++++++++++++++++++++++++++++++--
 env/Kconfig           | 11 +++++++++++
 include/env_default.h |  4 ++++
 3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index fa687f13a5..425709ed02 100644
--- a/Makefile
+++ b/Makefile
@@ -1843,6 +1843,34 @@ $(timestamp_h): $(srctree)/Makefile FORCE
 $(defaultenv_h): $(CONFIG_DEFAULT_ENV_FILE:"%"=%) FORCE
 	$(call filechk,defaultenv.h)
+# ---------------------------------------------------------------------------
+# the SPL default environment is filtered by CONFIG_SPL_ENV_VARS
+spl_defaultenv_h := include/generated/spl_defaultenv_autogenerated.h
+quiet_cmd_gensplenv = GENENV $@
+ifeq ($(CONFIG_SPL_ENV_VARS),"*")
+cmd_gensplenv = cp $< $@
+ifeq ($(CONFIG_SPL_ENV_VARS),"")
+cmd_gensplenv = echo '\0'  > $@
+# use grep to filter SPL env with patern "^\(var1\|var2\)=",
+# with $CONFIG_SPL_ENV_VARS = "var1,var2"
+cmd_gensplenv = grep "^\($(subst $(comma),\|,$(CONFIG_SPL_ENV_VARS:"%"=%))\)=" $< > $@
+u-boot-spl-initial-env: u-boot-initial-env FORCE
+	$(call cmd,gensplenv)
+$(spl_defaultenv_h): u-boot-spl-initial-env
+	$(call filechk,defaultenv.h)
+spl_prepare: prepare $(spl_defaultenv_h)
+PHONY += spl_prepare
 # ---------------------------------------------------------------------------
 quiet_cmd_cpp_lds = LDS     $@
 cmd_cpp_lds = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) \
@@ -1855,7 +1883,7 @@ spl/u-boot-spl.bin: spl/u-boot-spl
-spl/u-boot-spl: tools prepare \
+spl/u-boot-spl: tools prepare spl_prepare \
 	$(Q)$(MAKE) obj=spl -f $(srctree)/scripts/Makefile.spl all
@@ -1872,7 +1900,7 @@ spl/u-boot-spl.sfp: spl/u-boot-spl
 spl/boot.bin: spl/u-boot-spl
-tpl/u-boot-tpl.bin: tools prepare \
+tpl/u-boot-tpl.bin: tools prepare spl_prepare \
 	$(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all
diff --git a/env/Kconfig b/env/Kconfig
index 0d6f559b39..ff7a8c1d6c 100644
--- a/env/Kconfig
+++ b/env/Kconfig
@@ -588,7 +588,18 @@ config ENV_VARS_UBOOT_RUNTIME_CONFIG
 	  run-time determined information about the hardware to the
 	  environment.  These will be named board_name, board_rev.
+config SPL_ENV_VARS
+	string "list of variables keept in SPL/TPL default environment"
+	default ""
+	help
+		List of variables, coma separated, included in the default
+		environment in SPL and TPL.
+		It is used to reduce the size impact of environment in SPL/TPL
+		None variable are included when the option is empty "".
+		The filtre is deactivated when option is "*".
 	bool "SPL Environment is not stored"
 	default y if ENV_IS_NOWHERE
diff --git a/include/env_default.h b/include/env_default.h
index 56a8bae39a..9ea6136803 100644
--- a/include/env_default.h
+++ b/include/env_default.h
@@ -21,6 +21,9 @@ static char default_environment[] = {
 const uchar default_environment[] = {
+#include "generated/spl_defaultenv_autogenerated.h"
@@ -114,6 +117,7 @@ const uchar default_environment[] = {
 #include "generated/defaultenv_autogenerated.h"

More information about the U-Boot mailing list