[U-Boot] [PATCH v2 4/5] env: Allow environment files to use the C preprocessor
Simon Glass
sjg at chromium.org
Mon Jun 24 22:46:04 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 v2:
- Add separate patch to enable C preprocessor for environment files
- Enable var+=value form to simplify composing variables in multiple steps
Makefile | 3 ++-
README | 17 ++++++++++++++++-
tools/scripts/env2string.awk | 6 ++++++
3 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 9dae750..89ac4c5 100644
--- a/Makefile
+++ b/Makefile
@@ -714,7 +714,8 @@ 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__ \
+ -include $(obj)include/config.h $(ENV_FILE) -o $@; \
else \
echo -n >$@ ; \
fi
diff --git a/README b/README
index 2c8a8c9..6711cd0 100644
--- a/README
+++ b/README
@@ -4376,12 +4376,25 @@ have a common environment for all vendor boards.
This is a plain text file where you can type your environment variables in
the form 'var=value'. Blank lines and multi-line variables are supported.
+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
@@ -4390,7 +4403,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 2d167c0..d647cf3 100644
--- a/tools/scripts/env2string.awk
+++ b/tools/scripts/env2string.awk
@@ -23,6 +23,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.3
More information about the U-Boot
mailing list