X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=common%2Fcmd_nvedit.c;h=eb89e9e60a669464f9d7ed669e0b5c047647931f;hb=daa989b47297c9f73426783599c286ef3a1f3f49;hp=1fcb4c96af3e0f41c46a04a84fe6f8020e8d738d;hpb=c1b7c70083fc8d0bb77db20dd47bb6c988f3dc67;p=people%2Fms%2Fu-boot.git diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 1fcb4c96af..eb89e9e60a 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -42,6 +42,9 @@ #include #include #include +#if defined(CONFIG_CMD_EDITENV) +#include +#endif #include #include #include @@ -52,15 +55,17 @@ DECLARE_GLOBAL_DATA_PTR; -#if !defined(CONFIG_ENV_IS_IN_NVRAM) && \ - !defined(CONFIG_ENV_IS_IN_EEPROM) && \ +#if !defined(CONFIG_ENV_IS_IN_EEPROM) && \ !defined(CONFIG_ENV_IS_IN_FLASH) && \ !defined(CONFIG_ENV_IS_IN_DATAFLASH) && \ + !defined(CONFIG_ENV_IS_IN_MG_DISK) && \ !defined(CONFIG_ENV_IS_IN_NAND) && \ + !defined(CONFIG_ENV_IS_IN_NVRAM) && \ !defined(CONFIG_ENV_IS_IN_ONENAND) && \ !defined(CONFIG_ENV_IS_IN_SPI_FLASH) && \ !defined(CONFIG_ENV_IS_NOWHERE) -# error Define one of CONFIG_ENV_IS_IN_{NVRAM|EEPROM|FLASH|DATAFLASH|ONENAND|SPI_FLASH|NOWHERE} +# error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\ +SPI_FLASH|MG_DISK|NVRAM|NOWHERE} #endif #define XMK_STR(x) #x @@ -75,61 +80,89 @@ DECLARE_GLOBAL_DATA_PTR; static const unsigned long baudrate_table[] = CONFIG_SYS_BAUDRATE_TABLE; #define N_BAUDRATES (sizeof(baudrate_table) / sizeof(baudrate_table[0])) +/* + * This variable is incremented on each do_setenv (), so it can + * be used via get_env_id() as an indication, if the environment + * has changed or not. So it is possible to reread an environment + * variable only if the environment was changed ... done so for + * example in NetInitLoop() + */ +static int env_id = 1; +int get_env_id (void) +{ + return env_id; +} /************************************************************************ * Command interface: print one or all environment variables */ -int do_printenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +/* + * state 0: finish printing this string and return (matched!) + * state 1: no matching to be done; print everything + * state 2: continue searching for matched name + */ +static int printenv(char *name, int state) { - int i, j, k, nxt; - int rcode = 0; - - if (argc == 1) { /* Print all env variables */ - for (i=0; env_get_char(i) != '\0'; i=nxt+1) { - for (nxt=i; env_get_char(nxt) != '\0'; ++nxt) - ; - for (k=i; k= 0) + state = 0; + + j = 0; + do { + buf[j++] = c = env_get_char(i++); + if (j == sizeof(buf) - 1) { + if (state <= 1) + puts(buf); + j = 0; } - } + } while (c != '\0'); - printf("\nEnvironment size: %d/%ld bytes\n", - i, (ulong)ENV_SIZE); + if (state <= 1) { + if (j) + puts(buf); + putc('\n'); + } - return 0; + if (ctrlc()) + return -1; } - for (i=1; ibi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0; - if (s) s = (*e) ? e+1 : e; - } -#ifdef CONFIG_NET_MULTI - eth_set_enetaddr(0, argv[2]); -#endif + if (strcmp(argv[1],"ethaddr") == 0) return 0; - } if (strcmp(argv[1],"ipaddr") == 0) { char *s = argv[2]; /* always use only one arg */ @@ -391,7 +403,7 @@ int _do_setenv (int flag, int argc, char *argv[]) int setenv (char *varname, char *varvalue) { char *argv[4] = { "setenv", varname, varvalue, NULL }; - if (varvalue == NULL) + if ((varvalue == NULL) || (varvalue[0] == '\0')) return _do_setenv (0, 2, argv); else return _do_setenv (0, 3, argv); @@ -493,6 +505,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, @@ -546,7 +586,7 @@ int getenv_r (char *name, char *buf, unsigned len) return (-1); } -#if defined(CONFIG_CMD_ENV) && !defined(CONFIG_ENV_IS_NOWHERE) +#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) int do_saveenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { @@ -560,7 +600,7 @@ int do_saveenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) U_BOOT_CMD( saveenv, 1, 0, do_saveenv, "save environment variables to persistent storage", - NULL + "" ); #endif @@ -588,12 +628,21 @@ 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", "\n - print values of all environment variables\n" "printenv name ...\n" - " - print value of environment variable 'name'\n" + " - print value of environment variable 'name'" ); U_BOOT_CMD( @@ -602,7 +651,7 @@ U_BOOT_CMD( "name value ...\n" " - set environment variable 'name' to 'value ...'\n" "setenv name\n" - " - delete environment variable 'name'\n" + " - delete environment variable 'name'" ); #if defined(CONFIG_CMD_ASKENV) @@ -618,7 +667,7 @@ U_BOOT_CMD( " - get environment variable 'name' from stdin (max 'size' chars)\n" "askenv name [message] size\n" " - display 'message' string and get environment variable 'name'" - "from stdin (max 'size' chars)\n" + "from stdin (max 'size' chars)" ); #endif @@ -628,6 +677,6 @@ U_BOOT_CMD( run, CONFIG_SYS_MAXARGS, 1, do_run, "run commands in an environment variable", "var [...]\n" - " - run the commands in the environment variable(s) 'var'\n" + " - run the commands in the environment variable(s) 'var'" ); #endif