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>
This commit is contained in:
parent
72ce27f8e0
commit
e805b7dcb0
|
@ -18,26 +18,39 @@
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <command.h>
|
#include <command.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include <fs.h>
|
#include <fs.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <envfs.h>
|
#include <envfs.h>
|
||||||
|
|
||||||
static int do_saveenv(int argc, char *argv[])
|
static int do_saveenv(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret, opt;
|
||||||
|
unsigned envfs_flags = 0;
|
||||||
char *filename, *dirname;
|
char *filename, *dirname;
|
||||||
|
|
||||||
printf("saving environment\n");
|
printf("saving environment\n");
|
||||||
if (argc < 3)
|
while ((opt = getopt(argc, argv, "z")) > 0) {
|
||||||
dirname = "/env";
|
switch (opt) {
|
||||||
else
|
case 'z':
|
||||||
dirname = argv[2];
|
envfs_flags |= ENVFS_FLAGS_FORCE_BUILT_IN;
|
||||||
if (argc < 2)
|
break;
|
||||||
filename = default_environment_path_get();
|
}
|
||||||
else
|
}
|
||||||
filename = argv[1];
|
|
||||||
|
|
||||||
ret = envfs_save(filename, dirname, 0);
|
/* 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
|
||||||
|
filename = default_environment_path_get();
|
||||||
|
|
||||||
|
ret = envfs_save(filename, dirname, envfs_flags);
|
||||||
|
|
||||||
return ret;
|
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("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("/dev/env0. Note that envfs can only handle files, directories are being")
|
||||||
BAREBOX_CMD_HELP_TEXT("skipped silently.")
|
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_HELP_END
|
||||||
|
|
||||||
BAREBOX_CMD_START(saveenv)
|
BAREBOX_CMD_START(saveenv)
|
||||||
.cmd = do_saveenv,
|
.cmd = do_saveenv,
|
||||||
BAREBOX_CMD_DESC("save environment to persistent storage")
|
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_GROUP(CMD_GRP_ENV)
|
||||||
BAREBOX_CMD_HELP(cmd_saveenv_help)
|
BAREBOX_CMD_HELP(cmd_saveenv_help)
|
||||||
BAREBOX_CMD_END
|
BAREBOX_CMD_END
|
||||||
|
|
|
@ -109,6 +109,7 @@ static void usage(char *prgname)
|
||||||
"\n"
|
"\n"
|
||||||
"options:\n"
|
"options:\n"
|
||||||
" -s save (directory -> environment sector)\n"
|
" -s save (directory -> environment sector)\n"
|
||||||
|
" -z force the built-in default environment at startup\n"
|
||||||
" -l load (environment sector -> directory)\n"
|
" -l load (environment sector -> directory)\n"
|
||||||
" -p <size> pad output file to given size\n"
|
" -p <size> pad output file to given size\n"
|
||||||
" -v verbose\n",
|
" -v verbose\n",
|
||||||
|
@ -120,9 +121,10 @@ int main(int argc, char *argv[])
|
||||||
int opt;
|
int opt;
|
||||||
int save = 0, load = 0, pad = 0, err = 0, fd;
|
int save = 0, load = 0, pad = 0, err = 0, fd;
|
||||||
char *filename = NULL, *dirname = NULL;
|
char *filename = NULL, *dirname = NULL;
|
||||||
|
unsigned envfs_flags = 0;
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
|
|
||||||
while((opt = getopt(argc, argv, "slp:v")) != -1) {
|
while((opt = getopt(argc, argv, "slp:vz")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 's':
|
case 's':
|
||||||
save = 1;
|
save = 1;
|
||||||
|
@ -133,6 +135,10 @@ int main(int argc, char *argv[])
|
||||||
case 'p':
|
case 'p':
|
||||||
pad = strtoul(optarg, NULL, 0);
|
pad = strtoul(optarg, NULL, 0);
|
||||||
break;
|
break;
|
||||||
|
case 'z':
|
||||||
|
envfs_flags |= ENVFS_FLAGS_FORCE_BUILT_IN;
|
||||||
|
save = 1;
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose = 1;
|
verbose = 1;
|
||||||
break;
|
break;
|
||||||
|
@ -181,7 +187,7 @@ int main(int argc, char *argv[])
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("saving contents of %s to file %s\n", dirname, filename);
|
printf("saving contents of %s to file %s\n", dirname, filename);
|
||||||
|
|
||||||
err = envfs_save(filename, dirname, 0);
|
err = envfs_save(filename, dirname, envfs_flags);
|
||||||
|
|
||||||
if (verbose && err)
|
if (verbose && err)
|
||||||
printf("saving env failed: %d\n", err);
|
printf("saving env failed: %d\n", err);
|
||||||
|
|
Loading…
Reference in New Issue