summaryrefslogtreecommitdiff
path: root/common/cmd_nvedit.c
diff options
context:
space:
mode:
authorPeter Tyser <ptyser@xes-inc.com>2009-10-25 15:12:56 -0500
committerWolfgang Denk <wd@denx.de>2009-10-27 20:58:25 +0100
commit246c69225c7b962d5c93e92282b78ca9fc5fefee (patch)
treee894adbd050ceed629228469c0066076b9f2d79a /common/cmd_nvedit.c
parentb0fa8e50632a628766db23f5c884ec63f1469552 (diff)
downloadu-boot-imx-246c69225c7b962d5c93e92282b78ca9fc5fefee.zip
u-boot-imx-246c69225c7b962d5c93e92282b78ca9fc5fefee.tar.gz
u-boot-imx-246c69225c7b962d5c93e92282b78ca9fc5fefee.tar.bz2
Add 'editenv' command
The editenv command can be used to edit an environment variable. Editing an environment variable is useful when one wants to tweak an existing variable, for example fix a typo or change the baudrate in the 'bootargs' environment variable. Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Diffstat (limited to 'common/cmd_nvedit.c')
-rw-r--r--common/cmd_nvedit.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 725e573..eb89e9e 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -42,6 +42,9 @@
#include <common.h>
#include <command.h>
#include <environment.h>
+#if defined(CONFIG_CMD_EDITENV)
+#include <malloc.h>
+#endif
#include <watchdog.h>
#include <serial.h>
#include <linux/stddef.h>
@@ -503,6 +506,34 @@ int do_askenv ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
#endif
/************************************************************************
+ * Interactively edit an environment variable
+ */
+#if defined(CONFIG_CMD_EDITENV)
+int do_editenv(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ char buffer[CONFIG_SYS_CBSIZE];
+ char *init_val;
+ int len;
+
+ if (argc < 2) {
+ cmd_usage(cmdtp);
+ return 1;
+ }
+
+ /* Set read buffer to initial value or empty sting */
+ init_val = getenv(argv[1]);
+ if (init_val)
+ len = sprintf(buffer, "%s", init_val);
+ else
+ buffer[0] = '\0';
+
+ readline_into_buffer("edit: ", buffer);
+
+ return setenv(argv[1], buffer);
+}
+#endif /* CONFIG_CMD_EDITENV */
+
+/************************************************************************
* Look up variable from environment,
* return address of storage for that variable,
* or NULL if not found
@@ -597,6 +628,15 @@ int envmatch (uchar *s1, int i2)
/**************************************************/
+#if defined(CONFIG_CMD_EDITENV)
+U_BOOT_CMD(
+ editenv, 2, 0, do_editenv,
+ "edit environment variable",
+ "name\n"
+ " - edit environment variable 'name'"
+);
+#endif
+
U_BOOT_CMD(
printenv, CONFIG_SYS_MAXARGS, 1, do_printenv,
"print environment variables",