env_callback.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #define ETHADDR_WILDCARD "\\d?"
  30. #else
  31. #define ENV_DOT_ESCAPE
  32. #define ETHADDR_WILDCARD
  33. #endif
  34. #ifdef CONFIG_CMD_DNS
  35. #define DNS_CALLBACK "dnsip:dnsip,"
  36. #else
  37. #define DNS_CALLBACK
  38. #endif
  39. #ifdef CONFIG_NET
  40. #define NET_CALLBACKS \
  41. "bootfile:bootfile," \
  42. "ipaddr:ipaddr," \
  43. "gatewayip:gatewayip," \
  44. "netmask:netmask," \
  45. "serverip:serverip," \
  46. "nvlan:nvlan," \
  47. "vlan:vlan," \
  48. DNS_CALLBACK \
  49. "eth" ETHADDR_WILDCARD "addr:ethaddr,"
  50. #else
  51. #define NET_CALLBACKS
  52. #endif
  53. /*
  54. * This list of callback bindings is static, but may be overridden by defining
  55. * a new association in the ".callbacks" environment variable.
  56. */
  57. #define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \
  58. ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \
  59. "baudrate:baudrate," \
  60. NET_CALLBACKS \
  61. "loadaddr:loadaddr," \
  62. SILENT_CALLBACK \
  63. SPLASHIMAGE_CALLBACK \
  64. "stdin:console,stdout:console,stderr:console," \
  65. "serial#:serialno," \
  66. CONFIG_ENV_CALLBACK_LIST_STATIC
  67. struct env_clbk_tbl {
  68. const char *name; /* Callback name */
  69. int (*callback)(const char *name, const char *value, enum env_op op,
  70. int flags);
  71. };
  72. void env_callback_init(ENTRY *var_entry);
  73. /*
  74. * Define a callback that can be associated with variables.
  75. * when associated through the ".callbacks" environment variable, the callback
  76. * will be executed any time the variable is inserted, overwritten, or deleted.
  77. */
  78. #ifdef CONFIG_SPL_BUILD
  79. #define U_BOOT_ENV_CALLBACK(name, callback) \
  80. static inline __maybe_unused void _u_boot_env_noop_##name(void) \
  81. { \
  82. (void)callback; \
  83. }
  84. #else
  85. #define U_BOOT_ENV_CALLBACK(name, callback) \
  86. ll_entry_declare(struct env_clbk_tbl, name, env_clbk) = \
  87. {#name, callback}
  88. #endif
  89. #endif /* __ENV_CALLBACK_H__ */