typedef struct env_item_s {
-#define EF_N_EEP (1<<7)
-#define EF_V_EEP (1<<6)
-#define EF_DIRTY (1<<0)
+#define EF_N_EEP (1<<7) /* Variable name is in EEPROM */
+#define EF_V_EEP (1<<6) /* Variable value is in EEPROM */
+#define EF_DIRTY (1<<0) /* Variable is new or value changed */
uint8_t flags;
union {
uint16_t eep;
sizeof(env_item_t), comp_env_key_item);
}
-
+#if 0
env_item_t *envlist_insert(const char *key, env_item_t *e)
{
const size_t size = sizeof(env_item_t);
} else
return NULL;
}
-
+#endif
env_item_t *envlist_enter(env_item_t *e)
{
free(ep->name.ram);
entrycount--;
-printf_P(PSTR("*** envlist_delete memmove: 0x%.4x, 0x%.4x, %d\n"),
- (unsigned) ep, (unsigned) ep + size,
- (env_list - ep)*size + entrycount*size);
memmove(ep, ep + 1, (env_list - ep)*size + entrycount*size);
rc = 1;
}
-#if 1
+#if 0
dump_ram((uint8_t *) &env_list[0], entrycount * sizeof(env_item_t),
"=== env_list:");
dump_heap();
return rc;
}
-
char *getenv(const char *name)
{
env_item_t *ep;
ep = envlist_get(name, ENV_GET_VAL);
if (ep != NULL)
ret = ep->val.ram;
-
-#if 1
+#if 0
dump_ram((uint8_t *) &env_list[0], entrycount * sizeof(env_item_t),
"=== env_list:");
dump_heap();
env_item_print(&env_list[i]);
}
#endif
-
return ret;
}
+/* TODO: implement saveenv() */
int saveenv(void)
{
int rc = 0;
-
// rc = env_export(&env_new);
if (rc)
return rc;
-
// rc = eeprom_bus_write(CONFIG_SYS_DEF_EEPROM_ADDR,
// off, (uchar *)&env_new, CONFIG_ENV_SIZE);
-
return rc;
}
unsigned int len = CONFIG_ENV_SIZE - offsetof(env_t, data);
unsigned int i, src = 0;
char c = 0xff, c0 = c;
-
+#if 0
printf_P(PSTR("\n\n** set_default_env()\n"));
-
+#endif
while (len) {
memcpy_P(buf, default_env+src, sizeof(buf));
}
eeprom_update_block(buf, (char *) eep, i);
-/**/ printf_P(PSTR("eeprom_update_block: eep: 0x%.4x, i:%d\n"),
+#if 0
+ printf_P(PSTR("eeprom_update_block: eep: 0x%.4x, i:%d\n"),
(unsigned int) eep, i);
-/**/ dump_ram((uint8_t *) buf, i, "=== buf:");
-/**/ dump_eep((const uint8_t *) eep, i);
-
+ dump_ram((uint8_t *) buf, i, "=== buf:");
+ dump_eep((const uint8_t *) eep, i);
+#endif
if (c == 0 && c0 == 0)
len = 0;
if (len > sizeof(buf))
src += sizeof(buf);
eep += sizeof(buf);
}
-
-printf_P(PSTR("** crc adr: 0x%.4x, crc: 0x%.4x\n"),
- (unsigned int) (uint16_t *) CONFIG_ENV_OFFSET + offsetof(env_t,crc), crc);
-
- eeprom_update_word((uint16_t *) CONFIG_ENV_OFFSET + offsetof(env_t,crc), crc);
-
-/**/ dump_eep(0, 128);
+#if 0
+ dump_eep(0, 128);
+#endif
return 0;
}
}
-/*
+/**
+ * Set or delete environment variable
+ *
* Set a new environment variable,
* or replace or delete an existing one.
+ *
+ * @param flag (not used)
+ * @param argc
+ * @param argv[1] Environment variable to set or delete
+ * if no more args
+ * @param argv[2] ... Value to set it to
+ *
+ * @return 0 if ok, 1 on error
*/
static int _do_env_set(int flag, int argc, char * const argv[])
{
- int i, len;
- char *name, *value, *s;
+ int i, len;
+ char *name, *value, *s;
env_item_t e, *ep;
(void) flag;
return 0;
}
+/**
+ * Set an environment variable
+ *
+ * @param varname Environment variable to set
+ * @param varvalue Value to set it to
+ * @return 0 if ok, 1 on error
+ */
int setenv(const char *varname, const char *varvalue)
{
const char * const argv[3] = { NULL, varname, varvalue };
return setenv(varname, str);
}
+/**
+ * Get an environment variable as a hex value
+ *
+ * @param varname Environment variable to get
+ * @param default_val Return this, if variable does not exist
+ * @return hex value of variable or default_val
+ */
unsigned long getenv_hex(const char *varname, unsigned long default_val)
{
const char *s;