All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: "Tom Rini" <trini@konsulko.com>, "Simon Glass" <sjg@chromium.org>,
	"Bin Meng" <bmeng.cn@gmail.com>,
	"Joe Hershberger" <joe.hershberger@ni.com>,
	"Marek Behún" <marek.behun@nic.cz>,
	"Pali Rohár" <pali@kernel.org>
Subject: [PATCH v4 4/5] env: Allow environment files to use the C preprocessor
Date: Sun, 19 Sep 2021 12:59:49 -0600	[thread overview]
Message-ID: <20210919125937.v4.4.Ie78bfbfca0d01d9cba501e127f446ec48e1f7afe@changeid> (raw)
In-Reply-To: <20210919185950.3813952-1-sjg@chromium.org>

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.

Also support += to allow variables to be appended to. This is needed when
using the preprocessor.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v4:
- Add documentation in rST format instead of README

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                  | 7 ++++++-
 doc/usage/environment.rst | 8 ++++++++
 scripts/env2string.awk    | 6 ++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 9e44af2ccb1..6315de93506 100644
--- a/Makefile
+++ b/Makefile
@@ -1813,7 +1813,12 @@ ENV_FILE := $(if $(wildcard $(ENV_FILE_BOARD)),$(ENV_FILE_BOARD),$(ENV_FILE_COMM
 quiet_cmd_gen_envp = ENVP    $@
       cmd_gen_envp = \
 	if [ -f "$(ENV_FILE)" ]; then \
-		cat $(ENV_FILE) >$@; \
+		$(CPP) -P $(CFLAGS) -x assembler-with-cpp -D__ASSEMBLY__ \
+			-D__UBOOT_CONFIG__ \
+			-I . -I include \
+			-I $(srctree)/include -include include/config.h \
+			-I$(srctree)/arch/$(ARCH)/include \
+			$(ENV_FILE) -o $@; \
 	else \
 		echo -n >$@ ; \
 	fi
diff --git a/doc/usage/environment.rst b/doc/usage/environment.rst
index 81130d17f85..5df55cdfa8f 100644
--- a/doc/usage/environment.rst
+++ b/doc/usage/environment.rst
@@ -31,6 +31,14 @@ 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.
+
+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.
+
 For example, for snapper9260 you would create a text file called
 `board/bluewater/env/snapper9260.env` containing the environment text.
 
diff --git a/scripts/env2string.awk b/scripts/env2string.awk
index f442d3b7c44..9851925d877 100644
--- a/scripts/env2string.awk
+++ b/scripts/env2string.awk
@@ -29,6 +29,12 @@ NF {
 		}
 		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;
-- 
2.33.0.464.g1972c5931b-goog


  parent reply	other threads:[~2021-09-19 19:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-19 18:59 [PATCH v4 0/5] env: Allow environment in text files Simon Glass
2021-09-19 18:59 ` [PATCH v4 1/5] sandbox: Drop distro_boot Simon Glass
2021-09-19 18:59 ` [PATCH v4 2/5] doc: Move environment documentation to rST Simon Glass
2021-09-20 12:18   ` Wolfgang Denk
2021-09-19 18:59 ` [PATCH v4 3/5] env: Allow U-Boot scripts to be placed in a .env file Simon Glass
2021-09-20 12:30   ` Wolfgang Denk
2021-09-19 18:59 ` Simon Glass [this message]
2021-09-20 12:35   ` [PATCH v4 4/5] env: Allow environment files to use the C preprocessor Wolfgang Denk
2021-09-19 18:59 ` [PATCH v4 5/5] sandbox: Use a text-based environment Simon Glass

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=20210919125937.v4.4.Ie78bfbfca0d01d9cba501e127f446ec48e1f7afe@changeid \
    --to=sjg@chromium.org \
    --cc=bmeng.cn@gmail.com \
    --cc=joe.hershberger@ni.com \
    --cc=marek.behun@nic.cz \
    --cc=pali@kernel.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.