xref: /openbmc/u-boot/include/env_callback.h (revision 01c541e0)
1 /*
2  * (C) Copyright 2012
3  * Joe Hershberger, National Instruments, joe.hershberger@ni.com
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #ifndef __ENV_CALLBACK_H__
9 #define __ENV_CALLBACK_H__
10 
11 #include <env_flags.h>
12 #include <linker_lists.h>
13 #include <search.h>
14 
15 #define ENV_CALLBACK_VAR ".callbacks"
16 
17 /* Board configs can define additional static callback bindings */
18 #ifndef CONFIG_ENV_CALLBACK_LIST_STATIC
19 #define CONFIG_ENV_CALLBACK_LIST_STATIC
20 #endif
21 
22 #ifdef CONFIG_SILENT_CONSOLE
23 #define SILENT_CALLBACK "silent:silent,"
24 #else
25 #define SILENT_CALLBACK
26 #endif
27 
28 #ifdef CONFIG_SPLASHIMAGE_GUARD
29 #define SPLASHIMAGE_CALLBACK "splashimage:splashimage,"
30 #else
31 #define SPLASHIMAGE_CALLBACK
32 #endif
33 
34 #ifdef CONFIG_REGEX
35 #define ENV_DOT_ESCAPE "\\"
36 #define ETHADDR_WILDCARD "\\d?"
37 #else
38 #define ENV_DOT_ESCAPE
39 #define ETHADDR_WILDCARD
40 #endif
41 
42 #ifdef CONFIG_CMD_DNS
43 #define DNS_CALLBACK "dnsip:dnsip,"
44 #else
45 #define DNS_CALLBACK
46 #endif
47 
48 #ifdef CONFIG_NET
49 #define NET_CALLBACKS \
50 	"bootfile:bootfile," \
51 	"ipaddr:ipaddr," \
52 	"gatewayip:gatewayip," \
53 	"netmask:netmask," \
54 	"serverip:serverip," \
55 	"nvlan:nvlan," \
56 	"vlan:vlan," \
57 	DNS_CALLBACK \
58 	"eth" ETHADDR_WILDCARD "addr:ethaddr,"
59 #else
60 #define NET_CALLBACKS
61 #endif
62 
63 /*
64  * This list of callback bindings is static, but may be overridden by defining
65  * a new association in the ".callbacks" environment variable.
66  */
67 #define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \
68 	ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \
69 	"baudrate:baudrate," \
70 	NET_CALLBACKS \
71 	"loadaddr:loadaddr," \
72 	SILENT_CALLBACK \
73 	SPLASHIMAGE_CALLBACK \
74 	"stdin:console,stdout:console,stderr:console," \
75 	"serial#:serialno," \
76 	CONFIG_ENV_CALLBACK_LIST_STATIC
77 
78 struct env_clbk_tbl {
79 	const char *name;		/* Callback name */
80 	int (*callback)(const char *name, const char *value, enum env_op op,
81 		int flags);
82 };
83 
84 void env_callback_init(ENTRY *var_entry);
85 
86 /*
87  * Define a callback that can be associated with variables.
88  * when associated through the ".callbacks" environment variable, the callback
89  * will be executed any time the variable is inserted, overwritten, or deleted.
90  */
91 #ifdef CONFIG_SPL_BUILD
92 #define U_BOOT_ENV_CALLBACK(name, callback) \
93 	static inline __maybe_unused void _u_boot_env_noop_##name(void) \
94 	{ \
95 		(void)callback; \
96 	}
97 #else
98 #define U_BOOT_ENV_CALLBACK(name, callback) \
99 	ll_entry_declare(struct env_clbk_tbl, name, env_clbk) = \
100 	{#name, callback}
101 #endif
102 
103 #endif /* __ENV_CALLBACK_H__ */
104