Re: [PATCH v7 3/7] env: Allow U-Boot scripts to be placed in a .env file

2021-10-18 Thread Wolfgang Denk
Dear Simon,

In message 
<20211015183321.v7.3.Ie78bfbfca0d01d9cba501e127f446ec48e1f7afe@changeid> you 
wrote:
>
> Add a feature that brings in a .env file associated with the board
> config, if present. To use it, create a file in a board//env
> directory called .env (or common.env if you want the same
> environment for all boards).

The cover letter does not mention a separate "env" directory - and
do we really need it?  I will almost always contain just a single
file - so env/.env is an just unnecessary complication.

> Also support += to allow variables to be appended to. This is needed when
> using the preprocessor.
...
> - Explain why variables starting with _ , and / are not supported
...
> - Move use of += to this patch
> - Explain that environment variables may not end in +

I feel all these restrictions should also be mentioned in the commit
message, not only in the code.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
Command, n.:
Statement presented by a human and accepted by a computer
in such a manner as to make the human feel as if he is in control.


[PATCH v7 3/7] env: Allow U-Boot scripts to be placed in a .env file

2021-10-15 Thread Simon Glass
At present U-Boot environment variables, and thus scripts, are defined
by CONFIG_EXTRA_ENV_SETTINGS. It is painful to add large amounts of text
to this file and dealing with quoting and newlines is harder than it
should be. It would be better if we could just type the script into a
text file and have it included by U-Boot.

Add a feature that brings in a .env file associated with the board
config, if present. To use it, create a file in a board//env
directory called .env (or common.env if you want the same
environment for all boards).

The environment variables should be of the form "var=value". Values can
extend to multiple lines. See the README under 'Environment Variables:'
for more information and an example.

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.
This uses the C preprocessor, means that comments can be included in the
environment using /* ... */

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

Signed-off-by: Simon Glass 
---

Changes in v7:
- Use 'env' basename instead of 'environment' for intermediate output files
- Show a message indicating the source text file being used
- Give an error if CONFIG_EXTRA_ENV_SETTINGS is also defined
- Use CONFIG_ENV_SOURCE_FILE instead of rules to specify the text-file name
- Make board.env the default name if CONFIG_ENV_SOURCE_FILE is empty
- Rewrite the documentation
- Drop the use of common.env
- Update awk script to output the whole CONFIG string, or just a comment

Changes in v6:
- Combine the two env2string.awk patches into one

Changes in v5:
- Explain how to include the common.env file
- Explain why variables starting with _ , and / are not supported
- Expand the definition of how to declare an environment variable
- Explain what happens to empty variables
- Update maintainer
- Move use of += to this patch
- Explain that environment variables may not end in +

Changes in v4:
- Move this from being part of configuring U-Boot to part of building it
- Don't put the environment in autoconf.mk as it is not needed
- Add documentation in rST format instead of README
- Drop mention of import/export
- Update awk script to ignore blank lines, as generated by clang
- Add documentation in rST format instead of README

Changes in v3:
- Adjust Makefile to generate the .inc and .h files in separate fules
- Add more detail in the README about the format of .env files
- Improve the comment about " in the awk script
- Correctly terminate environment files with \n
- Define __UBOOT_CONFIG__ when collecting environment files

Changes in v2:
- Move .env file from include/configs to board/
- Use awk script to process environment since it is much easier on the brain
- Add information and updated example script to README
- Add dependency rule so that the environment is rebuilt when it changes
- Add separate patch to enable C preprocessor for environment files
- Enable var+=value form to simplify composing variables in multiple steps

 MAINTAINERS   |  7 
 Makefile  | 66 -
 config.mk |  2 +
 doc/usage/environment.rst | 77 ++-
 env/Kconfig   | 18 +
 env/embedded.c|  1 +
 include/env_default.h | 11 ++
 scripts/env2string.awk| 63 
 8 files changed, 243 insertions(+), 2 deletions(-)
 create mode 100644 scripts/env2string.awk

diff --git a/MAINTAINERS b/MAINTAINERS
index 71f468c00a8..36846528368 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -738,6 +738,13 @@ F: test/env/
 F: tools/env*
 F: tools/mkenvimage.c
 
+ENVIRONMENT AS TEXT
+M: Simon Glass 
+R: Wolfgang Denk 
+S: Maintained
+F: doc/usage/environment.rst
+F: scripts/env2string.awk
+
 FPGA
 M: Michal Simek 
 S: Maintained
diff --git a/Makefile b/Makefile
index f911f703443..ba99a644b63 100644
--- a/Makefile
+++ b/Makefile
@@ -513,6 +513,7 @@ version_h := include/generated/version_autogenerated.h
 timestamp_h := include/generated/timestamp_autogenerated.h
 defaultenv_h := include/generated/defaultenv_autogenerated.h
 dt_h := include/generated/dt.h
+env_h := include/generated/environment.h
 
 no-dot-config-targets := clean clobber mrproper distclean \
 help %docs check% coccicheck \
@@ -1785,6 +1786,69 @@ quiet_cmd_sym ?= SYM $@
 u-boot.sym: u-boot FORCE
$(call if_changed,sym)
 
+# Environment processing
+# ---
+
+# Directory where we expect the .env file, if it exists
+ENV_DIR := $(srctree)/board/$(BOARDDIR)
+
+# Basename of .env file, stripping quotes
+ENV_SOURCE_FILE := $(CONFIG_ENV_SOURCE_FILE:"%"=%)
+
+# Filename of .env file
+ENV_FILE_CFG := $(ENV_DIR)/$(ENV_SOURCE_FILE).env