#include <search.h>
#include <errno.h>
#include <malloc.h>
+#include <mapmem.h>
#include <watchdog.h>
#include <linux/stddef.h>
#include <asm/byteorder.h>
* Set a new environment variable,
* or replace or delete an existing one.
*/
-static int _do_env_set(int flag, int argc, char * const argv[])
+static int _do_env_set(int flag, int argc, char * const argv[], int env_flag)
{
int i, len;
char *name, *value, *s;
ENTRY e, *ep;
- int env_flag = H_INTERACTIVE;
debug("Initial value for argc=%d\n", argc);
while (argc > 1 && **(argv + 1) == '-') {
return 1;
if (varvalue == NULL || varvalue[0] == '\0')
- return _do_env_set(0, 2, (char * const *)argv);
+ return _do_env_set(0, 2, (char * const *)argv, H_PROGRAMMATIC);
else
- return _do_env_set(0, 3, (char * const *)argv);
+ return _do_env_set(0, 3, (char * const *)argv, H_PROGRAMMATIC);
}
/**
if (argc < 2)
return CMD_RET_USAGE;
- return _do_env_set(flag, argc, argv);
+ return _do_env_set(flag, argc, argv, H_INTERACTIVE);
}
/*
}
/* Continue calling setenv code */
- return _do_env_set(flag, len, local_args);
+ return _do_env_set(flag, len, local_args, H_INTERACTIVE);
}
#endif
#if defined(CONFIG_CMD_ENV_CALLBACK)
-static int print_static_binding(const char *var_name, const char *callback_name)
+static int print_static_binding(const char *var_name, const char *callback_name,
+ void *priv)
{
printf("\t%-20s %-20s\n", var_name, callback_name);
puts("Static callback bindings:\n");
printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
printf("\t%-20s %-20s\n", "-------------", "-------------");
- env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding);
+ env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding, NULL);
puts("\n");
/* walk through each variable and print the callback if it has one */
#endif
#if defined(CONFIG_CMD_ENV_FLAGS)
-static int print_static_flags(const char *var_name, const char *flags)
+static int print_static_flags(const char *var_name, const char *flags,
+ void *priv)
{
enum env_flags_vartype type = env_flags_parse_vartype(flags);
enum env_flags_varaccess access = env_flags_parse_varaccess(flags);
"Variable Access");
printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
"---------------");
- env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags);
+ env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags, NULL);
puts("\n");
/* walk through each variable and print the flags if non-default */
if (argc < 2)
return CMD_RET_USAGE;
+ /* before import into hashtable */
+ if (!(gd->flags & GD_FLG_ENV_READY))
+ return 1;
+
/* Set read buffer to initial value or empty sting */
init_val = getenv(argv[1]);
if (init_val)
if (cli_readline_into_buffer("edit: ", buffer, 0) < 0)
return 1;
- return setenv(argv[1], buffer);
+ if (buffer[0] == '\0') {
+ const char * const _argv[3] = { "setenv", argv[1], NULL };
+
+ return _do_env_set(0, 2, (char * const *)_argv, H_INTERACTIVE);
+ } else {
+ const char * const _argv[4] = { "setenv", argv[1], buffer,
+ NULL };
+
+ return _do_env_set(0, 3, (char * const *)_argv, H_INTERACTIVE);
+ }
}
#endif /* CONFIG_CMD_EDITENV */
#endif /* CONFIG_SPL_BUILD */
#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
int chk = 0;
int fmt = 0;
int del = 0;
+ int crlf_is_lf = 0;
size_t size;
cmd = *argv;
goto sep_err;
sep = '\n';
break;
+ case 'r': /* handle CRLF like LF */
+ crlf_is_lf = 1;
+ break;
case 'd':
del = 1;
break;
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);
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;
}
#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)