summaryrefslogtreecommitdiff
path: root/env
diff options
context:
space:
mode:
authorPatrick Delaunay <patrick.delaunay@st.com>2020-07-28 11:51:21 +0200
committerTom Rini <trini@konsulko.com>2020-07-31 10:13:00 -0400
commita97d22ebba2305f2d0aee714544c72c6a53026d9 (patch)
tree11c843faeaeb7a2bdd1e180e2e135b11cf5817da /env
parent0115dd3a6a144e9c974e00a9f3f41c5bb053236e (diff)
cmd: env: add env select command
Add the new command 'env select' to force the persistent storage of environment, saved in gd->env_load_prio. Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Diffstat (limited to 'env')
-rw-r--r--env/env.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/env/env.c b/env/env.c
index 785a2b8552..2af2fae23c 100644
--- a/env/env.c
+++ b/env/env.c
@@ -344,3 +344,45 @@ int env_init(void)
return ret;
}
+
+int env_select(const char *name)
+{
+ struct env_driver *drv;
+ const int n_ents = ll_entry_count(struct env_driver, env_driver);
+ struct env_driver *entry;
+ int prio;
+ bool found = false;
+
+ printf("Select Environment on %s: ", name);
+
+ /* search ENV driver by name */
+ drv = ll_entry_start(struct env_driver, env_driver);
+ for (entry = drv; entry != drv + n_ents; entry++) {
+ if (!strcmp(entry->name, name)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ printf("driver not found\n");
+ return -ENODEV;
+ }
+
+ /* search priority by driver */
+ for (prio = 0; (drv = env_driver_lookup(ENVOP_INIT, prio)); prio++) {
+ if (entry->location == env_get_location(ENVOP_LOAD, prio)) {
+ /* when priority change, reset the ENV flags */
+ if (gd->env_load_prio != prio) {
+ gd->env_load_prio = prio;
+ gd->env_valid = ENV_INVALID;
+ gd->flags &= ~GD_FLG_ENV_DEFAULT;
+ }
+ printf("OK\n");
+ return 0;
+ }
+ }
+ printf("priority not found\n");
+
+ return -ENODEV;
+}