env_callback.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * (C) Copyright 2012
  3. * Joe Hershberger, National Instruments, joe.hershberger@ni.com
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #ifndef __ENV_CALLBACK_H__
  8. #define __ENV_CALLBACK_H__
  9. #include <env_flags.h>
  10. #include <linker_lists.h>
  11. #include <search.h>
  12. #define ENV_CALLBACK_VAR ".callbacks"
  13. /* Board configs can define additional static callback bindings */
  14. #ifndef CONFIG_ENV_CALLBACK_LIST_STATIC
  15. #define CONFIG_ENV_CALLBACK_LIST_STATIC
  16. #endif
  17. #ifdef CONFIG_SILENT_CONSOLE
  18. #define SILENT_CALLBACK "silent:silent,"
  19. #else
  20. #define SILENT_CALLBACK
  21. #endif
  22. #ifdef CONFIG_SPLASHIMAGE_GUARD
  23. #define SPLASHIMAGE_CALLBACK "splashimage:splashimage,"
  24. #else
  25. #define SPLASHIMAGE_CALLBACK
  26. #endif
  27. #ifdef CONFIG_REGEX
  28. #define ENV_DOT_ESCAPE "\\"
  29. #else
  30. #define ENV_DOT_ESCAPE
  31. #endif
  32. /*
  33. * This list of callback bindings is static, but may be overridden by defining
  34. * a new association in the ".callbacks" environment variable.
  35. */
  36. #define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \
  37. ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \
  38. "baudrate:baudrate," \
  39. "bootfile:bootfile," \
  40. "loadaddr:loadaddr," \
  41. SILENT_CALLBACK \
  42. SPLASHIMAGE_CALLBACK \
  43. "stdin:console,stdout:console,stderr:console," \
  44. CONFIG_ENV_CALLBACK_LIST_STATIC
  45. struct env_clbk_tbl {
  46. const char *name; /* Callback name */
  47. int (*callback)(const char *name, const char *value, enum env_op op,
  48. int flags);
  49. };
  50. void env_callback_init(ENTRY *var_entry);
  51. /*
  52. * Define a callback that can be associated with variables.
  53. * when associated through the ".callbacks" environment variable, the callback
  54. * will be executed any time the variable is inserted, overwritten, or deleted.
  55. */
  56. #ifdef CONFIG_SPL_BUILD
  57. #define U_BOOT_ENV_CALLBACK(name, callback) \
  58. static inline __maybe_unused void _u_boot_env_noop_##name(void) \
  59. { \
  60. (void)callback; \
  61. }
  62. #else
  63. #define U_BOOT_ENV_CALLBACK(name, callback) \
  64. ll_entry_declare(struct env_clbk_tbl, name, env_clbk) = \
  65. {#name, callback}
  66. #endif
  67. #endif /* __ENV_CALLBACK_H__ */