Commit 246c69225c7b962d5c93e92282b78ca9fc5fefee

Authored by Peter Tyser
Committed by Wolfgang Denk
1 parent b0fa8e5063

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>

Showing 4 changed files with 43 additions and 0 deletions Side-by-side Diff

... ... @@ -620,6 +620,7 @@
620 620 CONFIG_CMD_DS4510_RST * ds4510 I2C rst command
621 621 CONFIG_CMD_DTT * Digital Therm and Thermostat
622 622 CONFIG_CMD_ECHO echo arguments
  623 + CONFIG_CMD_EDITENV edit env variable
623 624 CONFIG_CMD_EEPROM * EEPROM read/write support
624 625 CONFIG_CMD_ELF * bootelf, bootvx
625 626 CONFIG_CMD_SAVEENV saveenv
... ... @@ -42,6 +42,9 @@
42 42 #include <common.h>
43 43 #include <command.h>
44 44 #include <environment.h>
  45 +#if defined(CONFIG_CMD_EDITENV)
  46 +#include <malloc.h>
  47 +#endif
45 48 #include <watchdog.h>
46 49 #include <serial.h>
47 50 #include <linux/stddef.h>
... ... @@ -503,6 +506,34 @@
503 506 #endif
504 507  
505 508 /************************************************************************
  509 + * Interactively edit an environment variable
  510 + */
  511 +#if defined(CONFIG_CMD_EDITENV)
  512 +int do_editenv(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  513 +{
  514 + char buffer[CONFIG_SYS_CBSIZE];
  515 + char *init_val;
  516 + int len;
  517 +
  518 + if (argc < 2) {
  519 + cmd_usage(cmdtp);
  520 + return 1;
  521 + }
  522 +
  523 + /* Set read buffer to initial value or empty sting */
  524 + init_val = getenv(argv[1]);
  525 + if (init_val)
  526 + len = sprintf(buffer, "%s", init_val);
  527 + else
  528 + buffer[0] = '\0';
  529 +
  530 + readline_into_buffer("edit: ", buffer);
  531 +
  532 + return setenv(argv[1], buffer);
  533 +}
  534 +#endif /* CONFIG_CMD_EDITENV */
  535 +
  536 +/************************************************************************
506 537 * Look up variable from environment,
507 538 * return address of storage for that variable,
508 539 * or NULL if not found
... ... @@ -596,6 +627,15 @@
596 627  
597 628  
598 629 /**************************************************/
  630 +
  631 +#if defined(CONFIG_CMD_EDITENV)
  632 +U_BOOT_CMD(
  633 + editenv, 2, 0, do_editenv,
  634 + "edit environment variable",
  635 + "name\n"
  636 + " - edit environment variable 'name'"
  637 +);
  638 +#endif
599 639  
600 640 U_BOOT_CMD(
601 641 printenv, CONFIG_SYS_MAXARGS, 1, do_printenv,
include/config_cmd_all.h
... ... @@ -30,6 +30,7 @@
30 30 #define CONFIG_CMD_DOC /* Disk-On-Chip Support */
31 31 #define CONFIG_CMD_DTT /* Digital Therm and Thermostat */
32 32 #define CONFIG_CMD_ECHO /* echo arguments */
  33 +#define CONFIG_CMD_EDITENV /* editenv */
33 34 #define CONFIG_CMD_EEPROM /* EEPROM read/write support */
34 35 #define CONFIG_CMD_ELF /* ELF (VxWorks) load/boot cmd */
35 36 #define CONFIG_CMD_SAVEENV /* saveenv */
include/config_cmd_default.h
... ... @@ -20,6 +20,7 @@
20 20 #define CONFIG_CMD_BOOTD /* bootd */
21 21 #define CONFIG_CMD_CONSOLE /* coninfo */
22 22 #define CONFIG_CMD_ECHO /* echo arguments */
  23 +#define CONFIG_CMD_EDITENV /* editenv */
23 24 #define CONFIG_CMD_FPGA /* FPGA configuration Support */
24 25 #define CONFIG_CMD_IMI /* iminfo */
25 26 #define CONFIG_CMD_ITEST /* Integer (and string) test */