]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
cmd: env: add env select command
authorPatrick Delaunay <patrick.delaunay@st.com>
Tue, 28 Jul 2020 09:51:21 +0000 (11:51 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 31 Jul 2020 14:13:00 +0000 (10:13 -0400)
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>
cmd/Kconfig
cmd/nvedit.c
env/env.c
include/env.h

index 498fd31b107d69b13ce3224c883fb25d63d1738e..d7136b0e7902eaa5c5976a56a1db502e129cbcd5 100644 (file)
@@ -610,6 +610,11 @@ config CMD_NVEDIT_LOAD
          Load all environment variables from the compiled-in persistent
          storage.
 
+config CMD_NVEDIT_SELECT
+       bool "env select"
+       help
+         Select the compiled-in persistent storage of environment variables.
+
 endmenu
 
 menu "Memory commands"
index f730e2e7546ebdce4cb6f9b7ed8da5bd282ea6fd..d188c6aa6b73a3d16463e0b01c253e4598f1b32e 100644 (file)
@@ -802,6 +802,15 @@ static int do_env_load(struct cmd_tbl *cmdtp, int flag, int argc,
        return env_reload() ? 1 : 0;
 }
 #endif
+
+#if defined(CONFIG_CMD_NVEDIT_SELECT)
+static int do_env_select(struct cmd_tbl *cmdtp, int flag, int argc,
+                        char *const argv[])
+{
+       return env_select(argv[1]) ? 1 : 0;
+}
+#endif
+
 #endif /* CONFIG_SPL_BUILD */
 
 int env_match(uchar *s1, int i2)
@@ -1367,6 +1376,9 @@ static struct cmd_tbl cmd_env_sub[] = {
 #if defined(CONFIG_CMD_ERASEENV)
        U_BOOT_CMD_MKENT(erase, 1, 0, do_env_erase, "", ""),
 #endif
+#endif
+#if defined(CONFIG_CMD_NVEDIT_SELECT)
+       U_BOOT_CMD_MKENT(select, 2, 0, do_env_select, "", ""),
 #endif
        U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
 #if defined(CONFIG_CMD_ENV_EXISTS)
@@ -1456,6 +1468,9 @@ static char env_help_text[] =
 #if defined(CONFIG_CMD_NVEDIT_LOAD)
        "env load - load environment\n"
 #endif
+#if defined(CONFIG_CMD_NVEDIT_SELECT)
+       "env select [target] - select environment target\n"
+#endif
 #if defined(CONFIG_CMD_NVEDIT_EFI)
        "env set -e [-nv][-bs][-rt][-at][-a][-i addr,size][-v] name [arg ...]\n"
        "    - set UEFI variable; unset if '-i' or 'arg' not specified\n"
index 785a2b8552ae7b1d5268c05cbaa82a563a5f6bd0..2af2fae23cd9f6ddda883930dbe43cf578853b51 100644 (file)
--- 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;
+}
index 68e0f4fa56b0839abc40c05058870f2773ee975c..665857f032c230e8784b6bca4d8c3b272cc3e58c 100644 (file)
@@ -286,6 +286,13 @@ int env_save(void);
  */
 int env_erase(void);
 
+/**
+ * env_select() - Select the environment storage
+ *
+ * @return 0 if OK, -ve on error
+ */
+int env_select(const char *name);
+
 /**
  * env_import() - Import from a binary representation into hash table
  *
@@ -349,5 +356,4 @@ int env_get_char(int index);
  * This is used for those unfortunate archs with crappy toolchains
  */
 void env_reloc(void);
-
 #endif