summaryrefslogtreecommitdiff
path: root/common/cmd_nvedit.c
diff options
context:
space:
mode:
authorJoe Hershberger <joe.hershberger@ni.com>2015-05-20 14:27:21 -0500
committerTom Rini <trini@konsulko.com>2015-05-21 09:13:19 -0400
commit94b467b14ed908c89a0780256e89b375aa3cf3ef (patch)
tree071d2d605f83795ebf96cb86f51664b6c790a799 /common/cmd_nvedit.c
parentbdf1fe4e68b0d240f0ee666ea9d92d3f42f1a23f (diff)
env: Distinguish finer between source of env change
We already could tell the difference in the callback between an import and "other" which we called interactive. Now add further distinction between interactive (i.e. running env set / env edit / env ask / etc. from the U-Boot command line) and programmatic (i.e. when u-boot source calls any variant of setenv() ). Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/cmd_nvedit.c')
-rw-r--r--common/cmd_nvedit.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 6ca5a2e5a90..f4c2523f2fb 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -208,12 +208,11 @@ DONE:
* 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) == '-') {
@@ -291,9 +290,9 @@ int setenv(const char *varname, const char *varvalue)
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);
}
/**
@@ -347,7 +346,7 @@ static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (argc < 2)
return CMD_RET_USAGE;
- return _do_env_set(flag, argc, argv);
+ return _do_env_set(flag, argc, argv, H_INTERACTIVE);
}
/*
@@ -422,7 +421,7 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
/* Continue calling setenv code */
- return _do_env_set(flag, len, local_args);
+ return _do_env_set(flag, len, local_args, H_INTERACTIVE);
}
#endif
@@ -588,6 +587,10 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
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)
@@ -598,7 +601,16 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
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 */