1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <common.h>
25#include <environment.h>
26
27#if defined(CONFIG_NEEDS_MANUAL_RELOC)
28DECLARE_GLOBAL_DATA_PTR;
29#endif
30
31
32
33
34static struct env_clbk_tbl *find_env_callback(const char *name)
35{
36 struct env_clbk_tbl *clbkp;
37 int i;
38 int num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
39
40 if (name == NULL)
41 return NULL;
42
43
44 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
45 i < num_callbacks;
46 i++, clbkp++) {
47 if (strcmp(name, clbkp->name) == 0)
48 return clbkp;
49 }
50
51 return NULL;
52}
53
54
55
56
57
58
59void env_callback_init(ENTRY *var_entry)
60{
61 const char *var_name = var_entry->key;
62 const char *callback_list = getenv(ENV_CALLBACK_VAR);
63 char callback_name[256] = "";
64 struct env_clbk_tbl *clbkp;
65 int ret = 1;
66
67
68 if (callback_list != NULL)
69 ret = env_attr_lookup(callback_list, var_name, callback_name);
70
71
72 if (ret)
73 ret = env_attr_lookup(ENV_CALLBACK_LIST_STATIC, var_name,
74 callback_name);
75
76
77 if (!ret && strlen(callback_name)) {
78 clbkp = find_env_callback(callback_name);
79 if (clbkp != NULL)
80#if defined(CONFIG_NEEDS_MANUAL_RELOC)
81 var_entry->callback = clbkp->callback + gd->reloc_off;
82#else
83 var_entry->callback = clbkp->callback;
84#endif
85 }
86}
87
88
89
90
91
92static int clear_callback(ENTRY *entry)
93{
94 entry->callback = NULL;
95
96 return 0;
97}
98
99
100
101
102static int set_callback(const char *name, const char *value)
103{
104 ENTRY e, *ep;
105 struct env_clbk_tbl *clbkp;
106
107 e.key = name;
108 e.data = NULL;
109 hsearch_r(e, FIND, &ep, &env_htab, 0);
110
111
112 if (ep != NULL) {
113
114 if (value == NULL || strlen(value) == 0)
115 ep->callback = NULL;
116 else {
117
118 clbkp = find_env_callback(value);
119 if (clbkp != NULL)
120#if defined(CONFIG_NEEDS_MANUAL_RELOC)
121 ep->callback = clbkp->callback + gd->reloc_off;
122#else
123 ep->callback = clbkp->callback;
124#endif
125 }
126 }
127
128 return 0;
129}
130
131static int on_callbacks(const char *name, const char *value, enum env_op op,
132 int flags)
133{
134
135 hwalk_r(&env_htab, clear_callback);
136
137
138 env_attr_walk(ENV_CALLBACK_LIST_STATIC, set_callback);
139
140 env_attr_walk(value, set_callback);
141
142 return 0;
143}
144U_BOOT_ENV_CALLBACK(callbacks, on_callbacks);
145