Implemented selective importing of variables in
env import

Signed-off-by: Gerlando Falauto <gerlando.fala...@keymile.com>
---
 common/cmd_nvedit.c |   31 ++++++++++++++++++++++++++-----
 1 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 8636004..757a088 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -804,15 +804,18 @@ 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 == '-') {
@@ -836,7 +839,24 @@ 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("No more than %d 
variables can be imported at a single time\n", 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);
@@ -887,7 +907,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

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to