diff options
author | Alexander Holler <holler@ahsoftware.de> | 2014-07-14 17:49:55 +0200 |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2014-07-22 07:44:26 -0400 |
commit | ecd1446fe1df00d7f7b9de286dba309d93b51870 (patch) | |
tree | 4379b5361d1ac07d36b56a6fadf4cae1cb6b3d64 /common/cmd_nvedit.c | |
parent | 8973601c38c63726e344fd1eb416f05ae18aec91 (diff) | |
download | u-boot-ecd1446fe1df00d7f7b9de286dba309d93b51870.tar.gz |
Add option -r to env import to allow import of text files with CRLF as line endings
When this option is enabled, CRLF is treated like LF when importing environments
from text files, which means CRs ('\r') in front of LFs ('\n') are just ignored.
Drawback of enabling this option is that (maybe exported) variables which have
a trailing CR in their content will get imported without that CR. But this
drawback is very unlikely and the big advantage of letting Windows user create
a *working* uEnv.txt too is likely more welcome.
Signed-off-by: Alexander Holler <holler@ahsoftware.de>
Diffstat (limited to 'common/cmd_nvedit.c')
-rw-r--r-- | common/cmd_nvedit.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index e6c33956e7..855808c3e4 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -950,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 @@ -970,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; @@ -994,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; @@ -1009,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); @@ -1050,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; } @@ -1180,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) |