blob: c583120c1c4aea220389cbd3eedfb515a2fabdea [file] [log] [blame]
Joe Hershberger170ab112012-12-11 22:16:24 -06001/*
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 Hershberger25980902012-12-11 22:16:31 -060027#include <env_flags.h>
Joe Hershberger170ab112012-12-11 22:16:24 -060028#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 Hershbergere080d542012-12-11 22:16:30 -060038#ifdef CONFIG_SILENT_CONSOLE
39#define SILENT_CALLBACK "silent:silent,"
40#else
41#define SILENT_CALLBACK
42#endif
43
Joe Hershberger170ab112012-12-11 22:16:24 -060044/*
45 * This list of callback bindings is static, but may be overridden by defining
46 * a new association in the ".callbacks" environment variable.
47 */
48#define ENV_CALLBACK_LIST_STATIC ENV_CALLBACK_VAR ":callbacks," \
Joe Hershberger25980902012-12-11 22:16:31 -060049 ENV_FLAGS_VAR ":flags," \
Joe Hershberger32057712012-12-11 22:16:27 -060050 "baudrate:baudrate," \
Joe Hershbergera9f51c92012-12-11 22:16:26 -060051 "bootfile:bootfile," \
Joe Hershberger1cf0a8b2012-12-11 22:16:28 -060052 "loadaddr:loadaddr," \
Joe Hershbergere080d542012-12-11 22:16:30 -060053 SILENT_CALLBACK \
Joe Hershberger849d5d92012-12-11 22:16:29 -060054 "stdin:console,stdout:console,stderr:console," \
Joe Hershberger170ab112012-12-11 22:16:24 -060055 CONFIG_ENV_CALLBACK_LIST_STATIC
56
57struct env_clbk_tbl {
58 const char *name; /* Callback name */
59 int (*callback)(const char *name, const char *value, enum env_op op,
60 int flags);
61};
62
63struct env_clbk_tbl *find_env_callback(const char *);
64void env_callback_init(ENTRY *var_entry);
65
66/*
67 * Define a callback that can be associated with variables.
68 * when associated through the ".callbacks" environment variable, the callback
69 * will be executed any time the variable is inserted, overwritten, or deleted.
70 */
Scott Woodf8cfcf12012-12-20 11:51:05 +000071#ifdef CONFIG_SPL_BUILD
72#define U_BOOT_ENV_CALLBACK(name, callback) \
73 static inline void _u_boot_env_noop_##name(void) \
74 { \
75 (void)callback; \
76 }
77#else
Joe Hershberger170ab112012-12-11 22:16:24 -060078#define U_BOOT_ENV_CALLBACK(name, callback) \
79 ll_entry_declare(struct env_clbk_tbl, name, env_clbk, env_clbk) = \
80 {#name, callback}
Scott Woodf8cfcf12012-12-20 11:51:05 +000081#endif
Joe Hershberger170ab112012-12-11 22:16:24 -060082
83#endif /* __ENV_CALLBACK_H__ */