[U-Boot] [PATCH v0 4/4] env: implement "env import -n var[, var...]"
Gerlando Falauto
gerlando.falauto at keymile.com
Wed Oct 26 18:37:52 CEST 2011
Implemented selective importing of variables in
env import
Signed-off-by: Gerlando Falauto <gerlando.falauto at keymile.com>
---
common/cmd_nvedit.c | 35 ++++++++++++++++++++++++++++++-----
1 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 07cd062..0984a53 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -831,15 +831,19 @@ sep_err:
* size: length of input data; if missing, proper '\0'
* termination is mandatory
*/
-static int do_env_import(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+#define MAX_NVARS 16
+static int do_env_import(cmd_tbl_t *cmdtp, int __flag, int argc,
+ char * const argv[])
{
char *cmd, *addr;
char sep = '\n';
int chk = 0;
int fmt = 0;
- int del = 0;
+ int flag = H_NOCLEAR;
size_t size;
-
+ char *vars[MAX_NVARS];
+ int nvars = 0;
+ char *s;
cmd = *argv;
while (--argc > 0 && **++argv == '-') {
@@ -863,7 +867,27 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
sep = '\n';
break;
case 'd':
- del = 1;
+ flag &= ~H_NOCLEAR;
+ break;
+ case 'f':
+ flag |= H_FORCE;
+ break;
+ case 'n':
+ s = *++argv;
+ argc--;
+ do {
+ if (nvars >= MAX_NVARS) {
+ printf("Cannot import more "
+ "than %d variables at a"
+ " time!", MAX_NVARS);
+ return 1;
+ }
+ vars[nvars++] = strsep(&s, ",");
+ debug("Considering variable %s\n",
+ vars[nvars-1]);
+ } while (s);
+ debug("Importing a total of %d variables\n",
+ nvars);
break;
default:
return cmd_usage(cmdtp);
@@ -914,7 +938,8 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
addr = (char *)ep->data;
}
- if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR) == 0) {
+ if (himport_ex(&env_htab, addr, size, sep, flag,
+ nvars, vars, NULL) == 0) {
error("Environment import failed: errno = %d\n", errno);
return 1;
}
--
1.7.1
More information about the U-Boot
mailing list