env_callback.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * (C) Copyright 2012
  3. * Joe Hershberger, National Instruments, joe.hershberger@ni.com
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef __ENV_CALLBACK_H__
  24. #define __ENV_CALLBACK_H__
  25. #include <env_flags.h>
  26. #include <linker_lists.h>
  27. #include <search.h>
  28. #define ENV_CALLBACK_VAR ".callbacks"
  29. /* Board configs can define additional static callback bindings */
  30. #ifndef CONFIG_ENV_CALLBACK_LIST_STATIC
  31. #define CONFIG_ENV_CALLBACK_LIST_STATIC
  32. #endif
  33. #ifdef CONFIG_SILENT_CONSOLE
  34. #define SILENT_CALLBACK "silent:silent,"
  35. #else
  36. #define SILENT_CALLBACK
  37. #endif
  38. #ifdef CONFIG_SPLASHIMAGE_GUARD
  39. #define SPLASHIMAGE_CALLBACK "splashimage:splashimage,"
  40. #else
  41. #define SPLASHIMAGE_CALLBACK
  42. #endif
  43. /*
  44. * This list of callback bindings is static, but may be overridden by defining
  45. * a new association in the ".callbacks" environment variable.
  46. */
  47. #define ENV_CALLBACK_LIST_STATIC ENV_CALLBACK_VAR ":callbacks," \
  48. ENV_FLAGS_VAR ":flags," \
  49. "baudrate:baudrate," \
  50. "bootfile:bootfile," \
  51. "loadaddr:loadaddr," \
  52. SILENT_CALLBACK \
  53. SPLASHIMAGE_CALLBACK \
  54. "stdin:console,stdout:console,stderr:console," \
  55. CONFIG_ENV_CALLBACK_LIST_STATIC
  56. struct env_clbk_tbl {
  57. const char *name; /* Callback name */
  58. int (*callback)(const char *name, const char *value, enum env_op op,
  59. int flags);
  60. };
  61. struct env_clbk_tbl *find_env_callback(const char *);
  62. void env_callback_init(ENTRY *var_entry);
  63. /*
  64. * Define a callback that can be associated with variables.
  65. * when associated through the ".callbacks" environment variable, the callback
  66. * will be executed any time the variable is inserted, overwritten, or deleted.
  67. */
  68. #ifdef CONFIG_SPL_BUILD
  69. #define U_BOOT_ENV_CALLBACK(name, callback) \
  70. static inline void _u_boot_env_noop_##name(void) \
  71. { \
  72. (void)callback; \
  73. }
  74. #else
  75. #define U_BOOT_ENV_CALLBACK(name, callback) \
  76. ll_entry_declare(struct env_clbk_tbl, name, env_clbk, env_clbk) = \
  77. {#name, callback}
  78. #endif
  79. #endif /* __ENV_CALLBACK_H__ */