]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - env/callback.c
1 // SPDX-License-Identifier: GPL-2.0+
4 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
9 #include <env_internal.h>
10 #include <asm/global_data.h>
13 * Look up a callback function pointer by name
15 static struct env_clbk_tbl
*find_env_callback(const char *name
)
17 struct env_clbk_tbl
*clbkp
;
19 int num_callbacks
= ll_entry_count(struct env_clbk_tbl
, env_clbk
);
24 /* look up the callback in the linker-list */
25 for (i
= 0, clbkp
= ll_entry_start(struct env_clbk_tbl
, env_clbk
);
28 if (strcmp(name
, clbkp
->name
) == 0)
35 static int first_call
= 1;
36 static const char *callback_list
;
39 * Look for a possible callback for a newly added variable
40 * This is called specifically when the variable did not exist in the hash
41 * previously, so the blanket update did not find this variable.
43 void env_callback_init(struct env_entry
*var_entry
)
45 const char *var_name
= var_entry
->key
;
46 char callback_name
[256] = "";
47 struct env_clbk_tbl
*clbkp
;
51 callback_list
= env_get(ENV_CALLBACK_VAR
);
55 var_entry
->callback
= NULL
;
57 /* look in the ".callbacks" var for a reference to this variable */
58 if (callback_list
!= NULL
)
59 ret
= env_attr_lookup(callback_list
, var_name
, callback_name
);
61 /* only if not found there, look in the static list */
63 ret
= env_attr_lookup(ENV_CALLBACK_LIST_STATIC
, var_name
,
66 /* if an association was found, set the callback pointer */
67 if (!ret
&& strlen(callback_name
)) {
68 clbkp
= find_env_callback(callback_name
);
70 var_entry
->callback
= clbkp
->callback
;
75 * Called on each existing env var prior to the blanket update since removing
76 * a callback association should remove its callback.
78 static int clear_callback(struct env_entry
*entry
)
80 entry
->callback
= NULL
;
86 * Call for each element in the list that associates variables to callbacks
88 static int set_callback(const char *name
, const char *value
, void *priv
)
90 struct env_entry e
, *ep
;
91 struct env_clbk_tbl
*clbkp
;
96 hsearch_r(e
, ENV_FIND
, &ep
, &env_htab
, 0);
98 /* does the env variable actually exist? */
100 /* the assocaition delares no callback, so remove the pointer */
101 if (value
== NULL
|| strlen(value
) == 0)
104 /* assign the requested callback */
105 clbkp
= find_env_callback(value
);
107 ep
->callback
= clbkp
->callback
;
114 static int on_callbacks(const char *name
, const char *value
, enum env_op op
,
117 /* remove all callbacks */
118 hwalk_r(&env_htab
, clear_callback
);
120 /* configure any static callback bindings */
121 env_attr_walk(ENV_CALLBACK_LIST_STATIC
, set_callback
, NULL
);
122 /* configure any dynamic callback bindings */
123 env_attr_walk(value
, set_callback
, NULL
);
127 U_BOOT_ENV_CALLBACK(callbacks
, on_callbacks
);