#define DEBUG_ENV 0 /* set to 1 to debug */
-#define debug_env(fmt, args...) \
+#define debug_env(fmt, args...) \
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
*/
#define DELIM "\0"
const FLASH char default_env[] = {
- ENV_BAUDRATE "=" "115200" DELIM
- ENV_BOOTDELAY "=" "3" DELIM
+ ENV_BAUDRATE "=" stringify(CONFIG_BAUDRATE) DELIM
+ ENV_BOOTDELAY "=" stringify(CONFIG_BOOTDELAY) DELIM
ENV_BOOTCMD "=" "pin ${pins};loadcpm3;go ${startaddress}" DELIM
ENV_CPM3_SYSFILE "=" CONFIG_CPM3_SYSFILE DELIM
ENV_PINALIAS "=" "0:PG5,1:PG4,2:PB4,3:PB5,4:PB6,5:PB7,"
"6:PG3,7:PG2,8:PG1,9:PG0,10:PE7" DELIM
- //ENV_STARTADDRESS "=" "0" DELIM
"pins" "=" "2,8 low 9 high 3 2" DELIM
DELIM
};
+#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;
switch (env_valid) {
case 2:
off += CONFIG_ENV_SIZE;
+ /* FALL TROUGH */
case 1:
ret = (char) eeprom_read_byte((const uint8_t *)off + index +
offsetof(env_t, data));
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);
* @param varvalue Value to set it to
* @return 0 if ok, 1 on error
*/
-static
+
int setenv(const MEMX char *varname, const char *varvalue)
{
int rc;
bool mode = 0;
command_ret_t rc = CMD_RET_SUCCESS;
- /* reset getopt() */
- optind = 0;
-
int opt;
while ((opt = getopt(argc, argv, PSTR("s"))) != -1) {
switch (opt) {
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;
}
/* print selected env vars */
while (optind < argc) {
- int rc = env_print(argv[optind], mode);
- if (rc < 0) {
- printf_P(PSTR("## Error: \"%s\" not defined\n"), argv[optind]);
+ int len = env_print(argv[optind], mode);
+ if (len < 0) {
rc = CMD_RET_FAILURE;
}
optind++;
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;
+}