!defined(CONFIG_ENV_IS_IN_DATAFLASH) && \
!defined(CONFIG_ENV_IS_IN_MG_DISK) && \
!defined(CONFIG_ENV_IS_IN_MMC) && \
+ !defined(CONFIG_ENV_IS_IN_FAT) && \
!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_IN_REMOTE) && \
!defined(CONFIG_ENV_IS_NOWHERE)
# error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\
-SPI_FLASH|MG_DISK|NVRAM|MMC} or CONFIG_ENV_IS_NOWHERE
+SPI_FLASH|MG_DISK|NVRAM|MMC|FAT|REMOTE} or CONFIG_ENV_IS_NOWHERE
#endif
#define XMK_STR(x) #x
}
#ifdef CONFIG_CMD_GREPENV
-static int do_env_grep (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
+ int argc, char * const argv[])
{
ENTRY *match;
unsigned char matched[env_htab.size / 8];
int rcode = 1, arg = 1, idx;
if (argc < 2)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
memset(matched, 0, env_htab.size / 8);
* Set a new environment variable,
* or replace or delete an existing one.
*/
-
-int _do_env_set (int flag, int argc, char * const argv[])
+int _do_env_set(int flag, int argc, char * const argv[])
{
bd_t *bd = gd->bd;
int i, len;
name = argv[1];
if (strchr(name, '=')) {
- printf("## Error: illegal character '=' in variable name \"%s\"\n", name);
+ printf("## Error: illegal character '=' in variable name"
+ "\"%s\"\n", name);
return 1;
}
*/
if (ep) { /* variable exists */
#ifndef CONFIG_ENV_OVERWRITE
- if ((strcmp(name, "serial#") == 0) ||
- ((strcmp(name, "ethaddr") == 0)
+ if (strcmp(name, "serial#") == 0 ||
+ (strcmp(name, "ethaddr") == 0
#if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)
- && (strcmp(ep->data, MK_STR(CONFIG_ETHADDR)) != 0)
+ && strcmp(ep->data, MK_STR(CONFIG_ETHADDR)) != 0
#endif /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */
- ) ) {
+ )) {
printf("Can't overwrite \"%s\"\n", name);
return 1;
}
baudrate);
return 1;
}
- printf ("## Switch baudrate to %d bps and press ENTER ...\n",
- baudrate);
+ printf("## Switch baudrate to %d bps and"
+ "press ENTER ...\n", baudrate);
udelay(50000);
gd->baudrate = baudrate;
#if defined(CONFIG_PPC) || defined(CONFIG_MCF52x2)
serial_setbrg();
udelay(50000);
- for (;;) {
- if (getc() == '\r')
- break;
- }
+ while (getc() != '\r')
+ ;
}
}
/* Delete only ? */
- if ((argc < 3) || argv[2] == NULL) {
+ if (argc < 3 || argv[2] == NULL) {
int rc = hdelete_r(name, &env_htab);
return !rc;
}
while ((*s++ = *v++) != '\0')
;
- *(s-1) = ' ';
+ *(s - 1) = ' ';
}
if (s != value)
*--s = '\0';
- e.key = name;
- e.data = value;
+ e.key = name;
+ e.data = value;
hsearch_r(e, ENTER, &ep, &env_htab);
free(value);
if (!ep) {
* Some variables should be updated when the corresponding
* entry in the environment is changed
*/
-
if (strcmp(name, "ipaddr") == 0) {
char *s = argv[2]; /* always use only one arg */
char *e;
for (addr = 0, i = 0; i < 4; ++i) {
ulong val = s ? simple_strtoul(s, &e, 10) : 0;
addr <<= 8;
- addr |= (val & 0xFF);
- if (s) s = (*e) ? e+1 : e;
+ addr |= val & 0xFF;
+ if (s)
+ s = *e ? e + 1 : e;
}
bd->bi_ip_addr = htonl(addr);
return 0;
{
const char * const argv[4] = { "setenv", varname, varvalue, NULL };
- if ((varvalue == NULL) || (varvalue[0] == '\0'))
+ if (varvalue == NULL || varvalue[0] == '\0')
return _do_env_set(0, 2, (char * const *)argv);
else
return _do_env_set(0, 3, (char * const *)argv);
int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
if (argc < 2)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
return _do_env_set(flag, argc, argv);
}
#if defined(CONFIG_CMD_ASKENV)
int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- extern char console_buffer[CONFIG_SYS_CBSIZE];
char message[CONFIG_SYS_CBSIZE];
int size = CONFIG_SYS_CBSIZE - 1;
int i, len, pos;
/* Check the syntax */
switch (argc) {
case 1:
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
case 2: /* env_ask envname */
sprintf(message, "Please enter '%s':", argv[1]);
if (pos)
message[pos++] = ' ';
- strcpy(message+pos, argv[i]);
+ strcpy(message + pos, argv[i]);
pos += strlen(argv[i]);
}
+
message[pos] = '\0';
size = simple_strtoul(argv[argc - 1], NULL, 10);
break;
char *init_val;
if (argc < 2)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
/* Set read buffer to initial value or empty sting */
init_val = getenv(argv[1]);
else
buffer[0] = '\0';
- readline_into_buffer("edit: ", buffer);
+ readline_into_buffer("edit: ", buffer, 0);
return setenv(argv[1], buffer);
}
*/
char *getenv(const char *name)
{
- if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
+ if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
ENTRY e, *ep;
WATCHDOG_RESET();
- e.key = name;
- e.data = NULL;
+ e.key = name;
+ e.data = NULL;
hsearch_r(e, FIND, &ep, &env_htab);
return ep ? ep->data : NULL;
}
/* restricted capabilities before import */
-
if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
return (char *)(gd->env_buf);
{
int i, nxt;
- for (i = 0; env_get_char(i) != '\0'; i = nxt+1) {
+ for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
int val, n;
for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
/* found; copy out */
for (n = 0; n < len; ++n, ++buf) {
- if ((*buf = env_get_char(val++)) == '\0')
+ *buf = env_get_char(val++);
+ if (*buf == '\0')
return n;
}
return n;
}
+
return -1;
}
}
#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
-
int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- extern char *env_name_spec;
-
printf("Saving Environment to %s...\n", env_name_spec);
return saveenv() ? 1 : 0;
"save environment variables to persistent storage",
""
);
-
#endif
*
* s1 is either a simple 'name', or a 'name=value' pair.
* i2 is the environment index for a 'name2=value2' pair.
- * If the names match, return the index for the value2, else NULL.
+ * If the names match, return the index for the value2, else -1.
*/
-
int envmatch(uchar *s1, int i2)
{
while (*s1 == env_get_char(i2++))
if (*s1++ == '=')
return i2;
+
if (*s1 == '\0' && env_get_char(i2-1) == '=')
return i2;
+
return -1;
}
-static int do_env_default(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_env_default(cmd_tbl_t *cmdtp, int flag,
+ int argc, char * const argv[])
{
- if ((argc != 2) || (strcmp(argv[1], "-f") != 0))
- return cmd_usage(cmdtp);
+ if (argc != 2 || strcmp(argv[1], "-f") != 0)
+ return CMD_RET_USAGE;
set_default_env("## Resetting to default environment\n");
return 0;
}
-static int do_env_delete(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
+ int argc, char * const argv[])
{
printf("Not implemented yet\n");
return 0;
*
* => env import -d -t ${backup_addr}
*/
-static int do_env_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_env_export(cmd_tbl_t *cmdtp, int flag,
+ int argc, char * const argv[])
{
char buf[32];
char *addr, *cmd, *res;
sep = '\n';
break;
default:
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
}
}
NXTARG: ;
}
if (argc < 1)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
addr = (char *)simple_strtoul(argv[0], NULL, 16);
if (sep) { /* export as text file */
len = hexport_r(&env_htab, sep, &addr, size, argc, argv);
if (len < 0) {
- error("Cannot export environment: errno = %d\n",
- errno);
+ error("Cannot export environment: errno = %d\n", errno);
return 1;
}
sprintf(buf, "%zX", (size_t)len);
len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, argc, argv);
if (len < 0) {
- error("Cannot export environment: errno = %d\n",
- errno);
+ error("Cannot export environment: errno = %d\n", errno);
return 1;
}
if (chk) {
- envp->crc = crc32(0, envp->data, ENV_SIZE);
+ envp->crc = crc32(0, envp->data, ENV_SIZE);
#ifdef CONFIG_ENV_ADDR_REDUND
envp->flags = ACTIVE_FLAG;
#endif
return 0;
sep_err:
- printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
- cmd);
+ printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd);
return 1;
}
#endif
* size: length of input data; if missing, proper '\0'
* termination is mandatory
*/
-static int do_env_import(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_env_import(cmd_tbl_t *cmdtp, int flag,
+ int argc, char * const argv[])
{
char *cmd, *addr;
char sep = '\n';
del = 1;
break;
default:
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
}
}
}
if (argc < 1)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
if (!fmt)
printf("## Warning: defaulting to text format\n");
printf("## Warning: Input data exceeds %d bytes"
" - truncated\n", MAX_ENV_SIZE);
}
- ++size;
+ size += 2;
printf("## Info: input data size = %zu = 0x%zX\n", size, size);
}
}
#endif
-#if defined(CONFIG_CMD_RUN)
-extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
-#endif
-
/*
* New command line interface: "env" command with subcommands
*/
cmd_tbl_t *cp;
if (argc < 2)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
/* drop initial "env" arg */
argc--;
if (cp)
return cp->cmd(cmdtp, flag, argc, argv);
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
}
U_BOOT_CMD(
#if defined(CONFIG_CMD_RUN)
"env run var [...] - run commands in an environment variable\n"
#endif
+#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
"env save - save environment\n"
+#endif
"env set [-f] name [arg ...]\n"
);