]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_nvedit.c
Merge branch 'uboot'
[karo-tx-uboot.git] / common / cmd_nvedit.c
index f4e306ceba9a3b67fa2319a6668ff35aa9410978..855808c3e4a4d58bc3437da32725a3b725face01 100644 (file)
@@ -25,6 +25,7 @@
  */
 
 #include <common.h>
+#include <cli.h>
 #include <command.h>
 #include <environment.h>
 #include <search.h>
@@ -408,7 +409,7 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                return 1;
 
        /* prompt for input */
-       len = readline(message);
+       len = cli_readline(message);
 
        if (size < len)
                console_buffer[size] = '\0';
@@ -591,7 +592,7 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
        else
                buffer[0] = '\0';
 
-       if (readline_into_buffer("edit: ", buffer, 0) < 0)
+       if (cli_readline_into_buffer("edit: ", buffer, 0) < 0)
                return 1;
 
        return setenv(argv[1], buffer);
@@ -949,11 +950,15 @@ sep_err:
 
 #ifdef CONFIG_CMD_IMPORTENV
 /*
- * env import [-d] [-t | -b | -c] addr [size]
+ * env import [-d] [-t [-r] | -b | -c] addr [size]
  *     -d:     delete existing environment before importing;
  *             otherwise overwrite / append to existion definitions
  *     -t:     assume text format; either "size" must be given or the
  *             text data must be '\0' terminated
+ *     -r:     handle CRLF like LF, that means exported variables with
+ *             a content which ends with \r won't get imported. Used
+ *             to import text files created with editors which are using CRLF
+ *             for line endings. Only effective in addition to -t.
  *     -b:     assume binary format ('\0' separated, "\0\0" terminated)
  *     -c:     assume checksum protected environment format
  *     addr:   memory address to read from
@@ -969,6 +974,7 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag,
        int     chk = 0;
        int     fmt = 0;
        int     del = 0;
+       int     crlf_is_lf = 0;
        size_t  size;
 
        cmd = *argv;
@@ -993,6 +999,9 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag,
                                        goto sep_err;
                                sep = '\n';
                                break;
+                       case 'r':               /* handle CRLF like LF */
+                               crlf_is_lf = 1;
+                               break;
                        case 'd':
                                del = 1;
                                break;
@@ -1008,6 +1017,9 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag,
        if (!fmt)
                printf("## Warning: defaulting to text format\n");
 
+       if (sep != '\n' && crlf_is_lf )
+               crlf_is_lf = 0;
+
        addr = simple_strtoul(argv[0], NULL, 16);
        ptr = map_sysmem(addr, 0);
 
@@ -1049,8 +1061,8 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag,
                ptr = (char *)ep->data;
        }
 
-       if (himport_r(&env_htab, ptr, size, sep, del ? 0 : H_NOCLEAR, 0,
-                     NULL) == 0) {
+       if (himport_r(&env_htab, ptr, size, sep, del ? 0 : H_NOCLEAR,
+                       crlf_is_lf, 0, NULL) == 0) {
                error("Environment import failed: errno = %d\n", errno);
                return 1;
        }
@@ -1179,7 +1191,7 @@ static char env_help_text[] =
 #endif
 #endif
 #if defined(CONFIG_CMD_IMPORTENV)
-       "env import [-d] [-t | -b | -c] addr [size] - import environment\n"
+       "env import [-d] [-t [-r] | -b | -c] addr [size] - import environment\n"
 #endif
        "env print [-a | name ...] - print environment\n"
 #if defined(CONFIG_CMD_RUN)