[U-Boot] [PATCH] cmd: nvedit: Add filtering during env import
Alex Kiernan
alex.kiernan at gmail.com
Tue Mar 27 08:43:26 UTC 2018
When importing variables allow size to be elided using '-' and then
support a list of variables which restricts what will be picked during
the import.
Signed-off-by: Alex Kiernan <alex.kiernan at gmail.com>
---
cmd/nvedit.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 4cb25b8..486bb24 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -972,7 +972,7 @@ sep_err:
#ifdef CONFIG_CMD_IMPORTENV
/*
- * env import [-d] [-t [-r] | -b | -c] addr [size]
+ * env import [-d] [-t [-r] | -b | -c] addr [size] [var ...]
* -d: delete existing environment before importing;
* otherwise overwrite / append to existing definitions
* -t: assume text format; either "size" must be given or the
@@ -985,7 +985,10 @@ sep_err:
* -c: assume checksum protected environment format
* addr: memory address to read from
* size: length of input data; if missing, proper '\0'
- * termination is mandatory
+ * termination is mandatory. If not required and passing
+ * variables to import use '-'
+ * var...: List of variable names that get imported. Without arguments,
+ * all variables are imported
*/
static int do_env_import(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
@@ -1043,11 +1046,20 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag,
crlf_is_lf = 0;
addr = simple_strtoul(argv[0], NULL, 16);
+ --argc;
+ ++argv;
ptr = map_sysmem(addr, 0);
- if (argc == 2) {
- size = simple_strtoul(argv[1], NULL, 16);
- } else if (argc == 1 && chk) {
+ if (argc >= 1 && !strcmp(argv[0], "-")) {
+ --argc;
+ ++argv;
+ }
+
+ if (argc >= 1) {
+ size = simple_strtoul(argv[0], NULL, 16);
+ --argc;
+ ++argv;
+ } else if (argc == 0 && chk) {
puts("## Error: external checksum format must pass size\n");
return CMD_RET_FAILURE;
} else {
@@ -1084,7 +1096,7 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag,
}
if (himport_r(&env_htab, ptr, size, sep, del ? 0 : H_NOCLEAR,
- crlf_is_lf, 0, NULL) == 0) {
+ crlf_is_lf, argc, argc ? argv : NULL) == 0) {
pr_err("Environment import failed: errno = %d\n", errno);
return 1;
}
@@ -1213,7 +1225,7 @@ static char env_help_text[] =
#endif
#endif
#if defined(CONFIG_CMD_IMPORTENV)
- "env import [-d] [-t [-r] | -b | -c] addr [size] - import environment\n"
+ "env import [-d] [-t [-r] | -b | -c] addr [size] [var ...] - import environment\n"
#endif
"env print [-a | name ...] - print environment\n"
#if defined(CONFIG_CMD_RUN)
--
2.7.4
More information about the U-Boot
mailing list