environment.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. .. SPDX-License-Identifier: GPL-2.0+
  2. Environment implementation
  3. ==========================
  4. See :doc:`../usage/environment` for usage information.
  5. Callback functions for environment variables
  6. --------------------------------------------
  7. For some environment variables, the behavior of u-boot needs to change
  8. when their values are changed. This functionality allows functions to
  9. be associated with arbitrary variables. On creation, overwrite, or
  10. deletion, the callback will provide the opportunity for some side
  11. effect to happen or for the change to be rejected.
  12. The callbacks are named and associated with a function using the
  13. U_BOOT_ENV_CALLBACK macro in your board or driver code.
  14. These callbacks are associated with variables in one of two ways. The
  15. static list can be added to by defining CFG_ENV_CALLBACK_LIST_STATIC
  16. in the board configuration to a string that defines a list of
  17. associations. The list must be in the following format::
  18. entry = variable_name[:callback_name]
  19. list = entry[,list]
  20. If the callback name is not specified, then the callback is deleted.
  21. Spaces are also allowed anywhere in the list.
  22. Callbacks can also be associated by defining the ".callbacks" variable
  23. with the same list format above. Any association in ".callbacks" will
  24. override any association in the static list. You can define
  25. CONFIG_ENV_CALLBACK_LIST_DEFAULT to a list (string) to define the
  26. ".callbacks" environment variable in the default or embedded environment.
  27. If CONFIG_REGEX is defined, the variable_name above is evaluated as a
  28. regular expression. This allows multiple variables to be connected to
  29. the same callback without explicitly listing them all out.
  30. The signature of the callback functions is::
  31. int callback(const char *name, const char *value, enum env_op op, int flags)
  32. * name - changed environment variable
  33. * value - new value of the environment variable
  34. * op - operation (create, overwrite, or delete)
  35. * flags - attributes of the environment variable change, see flags H_* in
  36. include/search.h
  37. The return value is 0 if the variable change is accepted and 1 otherwise.