aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Wunderlich2019-06-29 11:36:19 +0200
committerTom Rini2019-07-18 11:31:25 -0400
commitcd121bdb6df3fe8dfe45ff1e34f46f86b8f060c0 (patch)
tree32dd275494f021a9ea3b8f9ddcc1ed5855b6c900
parent4225f830c56d6a8f6e459bce8cec310a58a9df28 (diff)
env: register erase command
this patch adds basic changes for adding a erase-subcommand to env with this command the environment stored on non-volatile storage written by saveenv can be cleared. Signed-off-by: Frank Wunderlich <frank-w@public-files.de> squashed fixes - start message with "Erasing" - mark erase-function as optional - env: separate eraseenv from saveenv Suggested-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
-rw-r--r--cmd/Kconfig8
-rw-r--r--cmd/nvedit.c20
-rw-r--r--env/env.c30
-rw-r--r--include/environment.h17
4 files changed, 75 insertions, 0 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 67284d8a5f6..ec746fe8255 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -408,6 +408,14 @@ config CMD_SAVEENV
Save all environment variables into the compiled-in persistent
storage.
+config CMD_ERASEENV
+ bool "eraseenv"
+ default n
+ depends on CMD_SAVEENV
+ help
+ Erase environment variables from the compiled-in persistent
+ storage.
+
config CMD_ENV_EXISTS
bool "env exists"
default y
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 7e468ab39d6..46b1e60f0ad 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -767,6 +767,20 @@ U_BOOT_CMD(
"save environment variables to persistent storage",
""
);
+
+#if defined(CONFIG_CMD_ERASEENV)
+static int do_env_erase(cmd_tbl_t *cmdtp, int flag, int argc,
+ char * const argv[])
+{
+ return env_erase() ? 1 : 0;
+}
+
+U_BOOT_CMD(
+ eraseenv, 1, 0, do_env_erase,
+ "erase environment variables from persistent storage",
+ ""
+);
+#endif
#endif
#endif /* CONFIG_SPL_BUILD */
@@ -1316,6 +1330,9 @@ static cmd_tbl_t cmd_env_sub[] = {
#endif
#if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE)
U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
+#if defined(CONFIG_CMD_ERASEENV)
+ U_BOOT_CMD_MKENT(erase, 1, 0, do_env_erase, "", ""),
+#endif
#endif
U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
#if defined(CONFIG_CMD_ENV_EXISTS)
@@ -1396,6 +1413,9 @@ static char env_help_text[] =
#endif
#if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE)
"env save - save environment\n"
+#if defined(CONFIG_CMD_ERASEENV)
+ "env erase - erase environment\n"
+#endif
#endif
#if defined(CONFIG_CMD_NVEDIT_EFI)
"env set -e name [arg ...] - set UEFI variable; unset if 'arg' not specified\n"
diff --git a/env/env.c b/env/env.c
index 4b417b90a29..d3cbe2f9158 100644
--- a/env/env.c
+++ b/env/env.c
@@ -24,6 +24,8 @@ void env_fix_drivers(void)
entry->load += gd->reloc_off;
if (entry->save)
entry->save += gd->reloc_off;
+ if (entry->erase)
+ entry->erase += gd->reloc_off;
if (entry->init)
entry->init += gd->reloc_off;
}
@@ -254,6 +256,34 @@ int env_save(void)
return -ENODEV;
}
+int env_erase(void)
+{
+ struct env_driver *drv;
+
+ drv = env_driver_lookup(ENVOP_ERASE, gd->env_load_prio);
+ if (drv) {
+ int ret;
+
+ if (!drv->erase)
+ return -ENODEV;
+
+ if (!env_has_inited(drv->location))
+ return -ENODEV;
+
+ printf("Erasing Environment on %s... ", drv->name);
+ ret = drv->erase();
+ if (ret)
+ printf("Failed (%d)\n", ret);
+ else
+ printf("OK\n");
+
+ if (!ret)
+ return 0;
+ }
+
+ return -ENODEV;
+}
+
int env_init(void)
{
struct env_driver *drv;
diff --git a/include/environment.h b/include/environment.h
index cd966761416..de67cf4f0ea 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -200,6 +200,7 @@ enum env_operation {
ENVOP_INIT, /* we want to call the init function */
ENVOP_LOAD, /* we want to call the load function */
ENVOP_SAVE, /* we want to call the save function */
+ ENVOP_ERASE, /* we want to call the erase function */
};
struct env_driver {
@@ -226,6 +227,15 @@ struct env_driver {
int (*save)(void);
/**
+ * erase() - Erase the environment on storage
+ *
+ * This method is optional and required for 'eraseenv' to work.
+ *
+ * @return 0 if OK, -ve on error
+ */
+ int (*erase)(void);
+
+ /**
* init() - Set up the initial pre-relocation environment
*
* This method is optional.
@@ -304,6 +314,13 @@ int env_load(void);
int env_save(void);
/**
+ * env_erase() - Erase the environment on storage
+ *
+ * @return 0 if OK, -ve on error
+ */
+int env_erase(void);
+
+/**
* env_fix_drivers() - Updates envdriver as per relocation
*/
void env_fix_drivers(void);