Joe Hershberger | 170ab11 | 2012-12-11 22:16:24 -0600 | [diff] [blame] | 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 | |
| 24 | #ifndef __ENV_CALLBACK_H__ |
| 25 | #define __ENV_CALLBACK_H__ |
| 26 | |
Joe Hershberger | 2598090 | 2012-12-11 22:16:31 -0600 | [diff] [blame] | 27 | #include <env_flags.h> |
Joe Hershberger | 170ab11 | 2012-12-11 22:16:24 -0600 | [diff] [blame] | 28 | #include <linker_lists.h> |
| 29 | #include <search.h> |
| 30 | |
| 31 | #define ENV_CALLBACK_VAR ".callbacks" |
| 32 | |
| 33 | /* Board configs can define additional static callback bindings */ |
| 34 | #ifndef CONFIG_ENV_CALLBACK_LIST_STATIC |
| 35 | #define CONFIG_ENV_CALLBACK_LIST_STATIC |
| 36 | #endif |
| 37 | |
Joe Hershberger | e080d54 | 2012-12-11 22:16:30 -0600 | [diff] [blame] | 38 | #ifdef CONFIG_SILENT_CONSOLE |
| 39 | #define SILENT_CALLBACK "silent:silent," |
| 40 | #else |
| 41 | #define SILENT_CALLBACK |
| 42 | #endif |
| 43 | |
Nikita Kiryanov | c088048 | 2013-02-24 21:28:43 +0000 | [diff] [blame] | 44 | #ifdef CONFIG_SPLASHIMAGE_GUARD |
| 45 | #define SPLASHIMAGE_CALLBACK "splashimage:splashimage," |
| 46 | #else |
| 47 | #define SPLASHIMAGE_CALLBACK |
| 48 | #endif |
| 49 | |
Joe Hershberger | 170ab11 | 2012-12-11 22:16:24 -0600 | [diff] [blame] | 50 | /* |
| 51 | * This list of callback bindings is static, but may be overridden by defining |
| 52 | * a new association in the ".callbacks" environment variable. |
| 53 | */ |
| 54 | #define ENV_CALLBACK_LIST_STATIC ENV_CALLBACK_VAR ":callbacks," \ |
Joe Hershberger | 2598090 | 2012-12-11 22:16:31 -0600 | [diff] [blame] | 55 | ENV_FLAGS_VAR ":flags," \ |
Joe Hershberger | 3205771 | 2012-12-11 22:16:27 -0600 | [diff] [blame] | 56 | "baudrate:baudrate," \ |
Joe Hershberger | a9f51c9 | 2012-12-11 22:16:26 -0600 | [diff] [blame] | 57 | "bootfile:bootfile," \ |
Joe Hershberger | 1cf0a8b | 2012-12-11 22:16:28 -0600 | [diff] [blame] | 58 | "loadaddr:loadaddr," \ |
Joe Hershberger | e080d54 | 2012-12-11 22:16:30 -0600 | [diff] [blame] | 59 | SILENT_CALLBACK \ |
Nikita Kiryanov | c088048 | 2013-02-24 21:28:43 +0000 | [diff] [blame] | 60 | SPLASHIMAGE_CALLBACK \ |
Joe Hershberger | 849d5d9 | 2012-12-11 22:16:29 -0600 | [diff] [blame] | 61 | "stdin:console,stdout:console,stderr:console," \ |
Joe Hershberger | 170ab11 | 2012-12-11 22:16:24 -0600 | [diff] [blame] | 62 | CONFIG_ENV_CALLBACK_LIST_STATIC |
| 63 | |
| 64 | struct env_clbk_tbl { |
| 65 | const char *name; /* Callback name */ |
| 66 | int (*callback)(const char *name, const char *value, enum env_op op, |
| 67 | int flags); |
| 68 | }; |
| 69 | |
Joe Hershberger | 170ab11 | 2012-12-11 22:16:24 -0600 | [diff] [blame] | 70 | void env_callback_init(ENTRY *var_entry); |
| 71 | |
| 72 | /* |
| 73 | * Define a callback that can be associated with variables. |
| 74 | * when associated through the ".callbacks" environment variable, the callback |
| 75 | * will be executed any time the variable is inserted, overwritten, or deleted. |
| 76 | */ |
Scott Wood | f8cfcf1 | 2012-12-20 11:51:05 +0000 | [diff] [blame] | 77 | #ifdef CONFIG_SPL_BUILD |
| 78 | #define U_BOOT_ENV_CALLBACK(name, callback) \ |
| 79 | static inline void _u_boot_env_noop_##name(void) \ |
| 80 | { \ |
| 81 | (void)callback; \ |
| 82 | } |
| 83 | #else |
Joe Hershberger | 170ab11 | 2012-12-11 22:16:24 -0600 | [diff] [blame] | 84 | #define U_BOOT_ENV_CALLBACK(name, callback) \ |
Albert ARIBAUD | ef123c5 | 2013-02-25 00:59:00 +0000 | [diff] [blame] | 85 | ll_entry_declare(struct env_clbk_tbl, name, env_clbk) = \ |
Joe Hershberger | 170ab11 | 2012-12-11 22:16:24 -0600 | [diff] [blame] | 86 | {#name, callback} |
Scott Wood | f8cfcf1 | 2012-12-20 11:51:05 +0000 | [diff] [blame] | 87 | #endif |
Joe Hershberger | 170ab11 | 2012-12-11 22:16:24 -0600 | [diff] [blame] | 88 | |
| 89 | #endif /* __ENV_CALLBACK_H__ */ |