summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorJuergen Borleis <jbe@pengutronix.de>2014-07-31 12:39:03 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-08-01 08:24:00 +0200
commite805b7dcb02bf7d8087a13175b02758ed60c5e23 (patch)
tree717f4f9d63c41da8d9e1b244b1136871088bb2d4 /commands
parent72ce27f8e02524170a922d2f6a6c73c5e4b5b5cd (diff)
downloadbarebox-e805b7dcb02bf7d8087a13175b02758ed60c5e23.tar.gz
barebox-e805b7dcb02bf7d8087a13175b02758ed60c5e23.tar.xz
saveenv: provide a zeroed/empty/ignore environment
If an external environment storage should be used in very rare and special cases, the intentional behaviour should be to ignore the external environment and always fall back to the built-in environment. By storing an empty "to be ignored" environment into the external environment a confusing error message about invalid CRC sums will go away and still the built-in environment is used. With this new option we can force the intentional behaviour. Signed-off-by: Juergen Borleis <jbe@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/saveenv.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/commands/saveenv.c b/commands/saveenv.c
index 178b783a0c..31d6951e62 100644
--- a/commands/saveenv.c
+++ b/commands/saveenv.c
@@ -18,26 +18,39 @@
#include <common.h>
#include <command.h>
#include <errno.h>
+#include <getopt.h>
#include <fs.h>
#include <fcntl.h>
#include <envfs.h>
static int do_saveenv(int argc, char *argv[])
{
- int ret;
+ int ret, opt;
+ unsigned envfs_flags = 0;
char *filename, *dirname;
printf("saving environment\n");
- if (argc < 3)
+ while ((opt = getopt(argc, argv, "z")) > 0) {
+ switch (opt) {
+ case 'z':
+ envfs_flags |= ENVFS_FLAGS_FORCE_BUILT_IN;
+ break;
+ }
+ }
+
+ /* destination and source are given? */
+ if (argc == optind + 2)
+ dirname = argv[optind + 1];
+ else
dirname = "/env";
+
+ /* destination only given? */
+ if (argc == optind + 1)
+ filename = argv[optind];
else
- dirname = argv[2];
- if (argc < 2)
filename = default_environment_path_get();
- else
- filename = argv[1];
- ret = envfs_save(filename, dirname, 0);
+ ret = envfs_save(filename, dirname, envfs_flags);
return ret;
}
@@ -49,13 +62,14 @@ BAREBOX_CMD_HELP_TEXT("ENVFS is usually a block in flash but can be any other fi
BAREBOX_CMD_HELP_TEXT("omitted, DIRECTORY defaults to /env and ENVFS defaults to")
BAREBOX_CMD_HELP_TEXT("/dev/env0. Note that envfs can only handle files, directories are being")
BAREBOX_CMD_HELP_TEXT("skipped silently.")
+BAREBOX_CMD_HELP_OPT ("-z", "force the built-in default environment at startup")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(saveenv)
.cmd = do_saveenv,
BAREBOX_CMD_DESC("save environment to persistent storage")
- BAREBOX_CMD_OPTS("[ENVFS [DIRECTORY]]")
+ BAREBOX_CMD_OPTS("[-z] [ENVFS [DIRECTORY]]")
BAREBOX_CMD_GROUP(CMD_GRP_ENV)
BAREBOX_CMD_HELP(cmd_saveenv_help)
BAREBOX_CMD_END