X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/8b2c7c224f3ff45c5404501034bdc2e01612eef0..1e5609bf0dfb390b0d62651cbd979e0ee21184fe:/avr/env.c diff --git a/avr/env.c b/avr/env.c index 6bbd99c..add281c 100644 --- a/avr/env.c +++ b/avr/env.c @@ -18,13 +18,6 @@ debug_cond(DEBUG_ENV, fmt, ##args) -#define ENV_SIZE (CONFIG_ENV_SIZE - sizeof(uint16_t) -1) -#define ACTIVE_FLAG 1 -#define OBSOLETE_FLAG 0 - -#define ENVLIST_DELETE (1<<0) - - /* * Default Environment */ @@ -44,10 +37,17 @@ const FLASH char default_env[] = { }; +#define ENV_SIZE (CONFIG_ENV_SIZE - sizeof(uint16_t) - sizeof(uint8_t)) + +#define ENVLIST_DELETE (1<<0) + + /* EEPROM storage */ typedef struct environment_s { uint16_t crc; /* CRC16 over data bytes */ uint8_t flags; /* active/obsolete flags */ +#define ACTIVE_FLAG 1 +#define OBSOLETE_FLAG 0 char data[ENV_SIZE]; /* Environment data */ } env_t; @@ -139,7 +139,7 @@ static char *env_item_insert_name(char *pos, const char *name, int len) while (*end++ != 0) while (*end++ != 0); - if (end > env_list + ENV_SIZE) + if (end + len >= env_list + ENV_SIZE) return NULL; memmove(dstp, pos, end - pos); @@ -714,7 +714,7 @@ command_ret_t do_env_print(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, return CMD_RET_FAILURE; if (mode == 0) printf_P(PSTR("\nEnvironment size: %d/%d bytes\n"), - size, ENV_SIZE); + size, ENV_SIZE - 1); return CMD_RET_SUCCESS; } @@ -795,3 +795,91 @@ int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf) return found; } #endif + +cmd_tbl_t cmd_tbl_env[] = { +CMD_TBL_ITEM_COMPLETE( + printenv, CONFIG_SYS_MAXARGS, 1|CTBL_SUBCMDAUTO, do_env_print, + "print environment variables", + "[-s] [name ...]\n" + " Print value of environment variable(s) 'name'\n" + " If no names are given, print values of all environment variables\n" + " -s Print in setenv form", + var_complete +), +CMD_TBL_ITEM_COMPLETE( + setenv, CONFIG_SYS_MAXARGS, CTBL_SUBCMDAUTO, do_env_set, + "set environment variables", + "name value ...\n" + " - set environment variable 'name' to 'value ...'\n" + "setenv name\n" + " - delete environment variable 'name'", + var_complete +), +CMD_TBL_ITEM( + saveenv, 1, CTBL_SUBCMDAUTO, do_env_save, + "save environment variables to persistent storage", + "" +), +CMD_TBL_ITEM( + defaultenv, 1, CTBL_SUBCMDAUTO, do_env_default, + "set all environment variables to their default values", + "" +), + +CMD_TBL_ITEM_COMPLETE( + print, CONFIG_SYS_MAXARGS, 1, do_env_print, + "print environment variables", + "[-s] [name ...]\n" + " Print value of environment variable(s) 'name'\n" + " If no names are given, print values of all environment variables\n" + " -s Print in setenv form", + var_complete +), +CMD_TBL_ITEM_COMPLETE( + set, CONFIG_SYS_MAXARGS, 0, do_env_set, + "set environment variables", + "name value ...\n" + " - set environment variable 'name' to 'value ...'\n" + "setenv name\n" + " - delete environment variable 'name'", + var_complete +), +CMD_TBL_ITEM( + save, 1, 0, do_env_save, + "save environment variables to persistent storage", + "" +), +CMD_TBL_ITEM( + default, 1, 0, do_env_default, + "set all environment variables to their default values", + "" +), + +CMD_TBL_ITEM( + help, CONFIG_SYS_MAXARGS, CTBL_RPT, do_help, + "Print sub command description/usage", + "\n" + " - print brief description of all sub commands\n" + "env help command ...\n" + " - print detailed usage of sub cmd 'command'" +), + +/* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */ + {FSTR("?"), CONFIG_SYS_MAXARGS, 1, do_help, + NULL, +#ifdef CONFIG_SYS_LONGHELP + FSTR(""), +#endif /* CONFIG_SYS_LONGHELP */ + NULL, +#ifdef CONFIG_AUTO_COMPLETE + NULL, +#endif +}, +/* Mark end of table */ +CMD_TBL_END(cmd_tbl_env) +}; + +command_ret_t do_env(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED) +{ + return CMD_RET_USAGE; +}