[U-Boot] [PATCH v3 4/5] env: Allow environment files to use the C preprocessor

Simon Glass sjg at chromium.org
Sat Oct 26 07:01:34 CEST 2013


In many cases environment variables need access to the U-Boot CONFIG
variables to select different options. Enable this so that the environment
scripts can be as useful as the ones currently in the board config files.

Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v3:
- Define __UBOOT_CONFIG__ when collecting environment files

Changes in v2:
- Add separate patch to enable C preprocessor for environment files
- Enable var+=value form to simplify composing variables in multiple steps

 Makefile                     |  4 +++-
 README                       | 18 +++++++++++++++++-
 tools/scripts/env2string.awk |  6 ++++++
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index a9b4b9e..8c96310 100644
--- a/Makefile
+++ b/Makefile
@@ -745,7 +745,9 @@ ENV_FILE := $(if $(wildcard $(ENV_FILE_BOARD)),$(ENV_FILE_BOARD),$(ENV_FILE_COMM
 $(obj)include/generated/environment.in: $(obj)include/generated/autoconf.mk.base \
 		$(wildcard $(ENV_FILE))
 	if [ -f "$(ENV_FILE)" ]; then \
-		cat $(ENV_FILE) >$@ ; \
+		$(CPP) -P $(CFLAGS) -x assembler-with-cpp -D__ASSEMBLY__ \
+			-D__UBOOT_CONFIG__ -include $(obj)include/config.h \
+			$(ENV_FILE) -o $@; \
 	else \
 		echo -n >$@ ; \
 	fi
diff --git a/README b/README
index 3146a2d..7428b0c 100644
--- a/README
+++ b/README
@@ -4574,11 +4574,25 @@ and has an equals sign immediately afterwards. Spaces before the = are not
 permitted. It is a good idea to indent your scripts so that only the 'var='
 appears at the start of a line.
 
+To add additional text to a variable you can use var+=value. This text is
+merged into the variable during the make process and made available as a
+single value to U-Boot.
+
 For example, for snapper9260 you would create a text file called
 board/bluewater/env/snapper9260.env containing the environment text.
 
+This file can include C-style comments. Blank lines and multi-line
+variables are supported, and you can use normal C preprocessor directives
+and CONFIG defines from your board config also.
+
 >>>
+stdout=serial
+#ifdef CONFIG_LCD
+stdout+=,lcd
+#endif
 bootcmd=
+	/* U-Boot script for booting */
+
 	if [ -z ${tftpserverip} ]; then
 		echo "Use 'setenv tftpserverip a.b.c.d' to set IP address."
 	fi
@@ -4587,7 +4601,9 @@ bootcmd=
 	tftpboot ${tftpserverip}:
 	bootm
 failed=
-	echo boot failed - please check your image
+	/* Print a message when boot fails */
+	echo CONFIG_SYS_BOARD boot failed - please check your image
+	echo Load address is CONFIG_SYS_LOAD_ADDR
 <<<
 
 The resulting environment can be exported and importing using the
diff --git a/tools/scripts/env2string.awk b/tools/scripts/env2string.awk
index 2a86494..f2b6d1a 100644
--- a/tools/scripts/env2string.awk
+++ b/tools/scripts/env2string.awk
@@ -28,6 +28,12 @@ BEGIN {
 		}
 		var = arr[1]
 		env = arr[2]
+
+		# Deal with +=
+		if (match(var, "(.*)[+]$", var_arr)) {
+			var = var_arr[1]
+			env = vars[var] env
+		}
 	} else {
 		# Change newline to \n
 		env = env "\\n" $0;
-- 
1.8.4.1



More information about the U-Boot mailing list