Files
u-boot/doc/develop/environment.rst
James Hilliard 5e41a5deb4 env: migrate static flags list to Kconfig
Environment callbacks can already be configured from Kconfig with
CONFIG_ENV_CALLBACK_LIST_STATIC, but static environment flags still
require board headers to define CFG_ENV_FLAGS_LIST_STATIC.

Add CONFIG_ENV_FLAGS_LIST_STATIC and use it as the only board-provided
static environment flags list. Convert the remaining default-config users
from CFG_ENV_FLAGS_LIST_STATIC to defconfig settings and drop the legacy
header macro from ENV_FLAGS_LIST_STATIC.

Move the environment flags format documentation out of README and into
the developer environment documentation. Include the format in the
Kconfig help as well.

This lets boards configure writeable-list policy and type validation
from defconfig without adding a config header solely for env flags.

This preserves the behavior of default configs. Header-only cases that
were inactive in upstream defconfigs are not converted into defconfig
entries: iot2050 can add its list when enabling ENV_WRITEABLE_LIST, and
smegw01 can add mmcdev:dw support if the unlocked SYS_BOOT_LOCKED=n
configuration is needed.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Reviewed-by: Walter Schweizer <walter.schweizer@siemens.com>
2026-05-25 13:44:40 -06:00

92 lines
3.2 KiB
ReStructuredText

.. SPDX-License-Identifier: GPL-2.0+
Environment implementation
==========================
See :doc:`../usage/environment` for usage information.
Callback functions for environment variables
--------------------------------------------
For some environment variables, the behavior of u-boot needs to change
when their values are changed. This functionality allows functions to
be associated with arbitrary variables. On creation, overwrite, or
deletion, the callback will provide the opportunity for some side
effect to happen or for the change to be rejected.
The callbacks are named and associated with a function using the
U_BOOT_ENV_CALLBACK macro in your board or driver code.
These callbacks are associated with variables in one of two ways. The
static list can be added to by defining CONFIG_ENV_CALLBACK_LIST_STATIC
in the board defconfig via menuconfig to a string that defines a list of
associations. The list must be in the following format::
entry = variable_name[:callback_name]
list = entry[,list]
If the callback name is not specified, then the callback is deleted.
Spaces are also allowed anywhere in the list.
Callbacks can also be associated by defining the ".callbacks" variable
with the same list format above. Any association in ".callbacks" will
override any association in the static list. You can define
CONFIG_ENV_CALLBACK_LIST_DEFAULT to a list (string) to define the
".callbacks" environment variable in the default or embedded environment.
If CONFIG_REGEX is defined, the variable_name above is evaluated as a
regular expression. This allows multiple variables to be connected to
the same callback without explicitly listing them all out.
The signature of the callback functions is::
int callback(const char *name, const char *value, enum env_op op, int flags)
* name - changed environment variable
* value - new value of the environment variable
* op - operation (create, overwrite, or delete)
* flags - attributes of the environment variable change, see flags H_* in
include/search.h
The return value is 0 if the variable change is accepted and 1 otherwise.
Flags for environment variables
-------------------------------
Environment flags validate the values given to environment variables and
restrict how environment variables can be changed.
The static list is configured with CONFIG_ENV_FLAGS_LIST_STATIC. The list
must be in the following format::
type_attribute = [s|d|x|b|i|m]
access_attribute = [a|r|o|c|w]
attributes = type_attribute[access_attribute]
entry = variable_name[:attributes]
list = entry[,list]
The type attributes are:
* s - String (default)
* d - Decimal
* x - Hexadecimal
* b - Boolean ([1yYtT|0nNfF])
* i - IP address, if networking is enabled
* m - MAC address, if networking is enabled
The access attributes are:
* a - Any (default)
* r - Read-only
* o - Write-once
* c - Change-default
* w - Writeable, if CONFIG_ENV_WRITEABLE_LIST is enabled
CONFIG_ENV_FLAGS_LIST_DEFAULT defines the ``.flags`` variable in the
default or embedded environment. Any association in ``.flags`` overrides
an association in the static list.
If CONFIG_REGEX is defined, the variable name is evaluated as a regular
expression. This allows multiple variables to define the same flags without
explicitly listing them all.