env: Allow U-Boot scripts to be placed in a .env file

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/<vendor>
directory, typically called <board>.env and controlled by the
CONFIG_ENV_SOURCE_FILE option.

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 <sjg@chromium.org>
Reviewed-by: Marek Behún <marek.behun@nic.cz>
Tested-by: Marek Behún <marek.behun@nic.cz>
This commit is contained in:
Simon Glass
2021-10-21 21:08:46 -06:00
committed by Tom Rini
parent ea754aa565
commit 86b9c3e4e4
10 changed files with 372 additions and 2 deletions

View File

@@ -15,7 +15,86 @@ environment is erased by accident, a default environment is provided.
Some configuration options can be set using Environment Variables.
List of environment variables (most likely not complete):
Text-based Environment
----------------------
The default environment for a board is created using a `.env` environment file
using a simple text format. The base filename for this is defined by
`CONFIG_ENV_SOURCE_FILE`, or `CONFIG_SYS_BOARD` if that is empty.
The file must be in the board directory and have a .env extension, so
assuming that there is a board vendor, the resulting filename is therefore::
board/<vendor>/<board>/<CONFIG_ENV_SOURCE_FILE>.env
or::
board/<vendor>/<board>/<CONFIG_SYS_BOARD>.env
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.
The conversion script looks for a line that starts in column 1 with a string
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. Variables can contain `+` characters but in the unlikely
event that you want to have a variable name ending in plus, put a backslash
before the `+` so that the script knows you are not adding to an existing
variable but assigning to a new one::
maximum\+=value
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/snapper9260.env` containing the environment text.
Example::
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
usb start; setenv autoload n; bootp;
tftpboot ${tftpserverip}:
bootm
failed=
/* Print a message when boot fails */
echo CONFIG_SYS_BOARD boot failed - please check your image
echo Load address is CONFIG_SYS_LOAD_ADDR
If CONFIG_ENV_SOURCE_FILE is empty and the default filename is not present, then
the old-style C environment is used instead. See below.
Old-style C environment
-----------------------
Traditionally, the default environment is created in `include/env_default.h`,
and can be augmented by various `CONFIG` defines. See that file for details. In
particular you can define `CONFIG_EXTRA_ENV_SETTINGS` in your board file
to add environment variables.
Board maintainers are encouraged to migrate to the text-based environment as it
is easier to maintain. The distro-board script still requires the old-style
environment but work is underway to address this.
List of environment variables
-----------------------------
This is most-likely not complete:
baudrate
see CONFIG_BAUDRATE

View File

@@ -10,6 +10,7 @@ Use U-Boot
netconsole
partitions
cmdline
environment
Shell commands
--------------