diff options
Diffstat (limited to 'common/env_nvram.c')
-rw-r--r-- | common/env_nvram.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/common/env_nvram.c b/common/env_nvram.c index eab0e7b..ff74a6c 100644 --- a/common/env_nvram.c +++ b/common/env_nvram.c @@ -60,6 +60,10 @@ env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR; char *env_name_spec = "NVRAM"; #ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE +static char env_buf[CONFIG_ENV_SIZE]; +#endif + +#ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE uchar env_get_char_spec(int index) { uchar c; @@ -72,36 +76,38 @@ uchar env_get_char_spec(int index) void env_relocate_spec(void) { - char buf[CONFIG_ENV_SIZE]; + char *buf; #if defined(CONFIG_SYS_NVRAM_ACCESS_ROUTINE) + buf = env_buf; nvram_read(buf, CONFIG_ENV_ADDR, CONFIG_ENV_SIZE); #else - memcpy(buf, (void *)CONFIG_ENV_ADDR, CONFIG_ENV_SIZE); + buf = (void *)CONFIG_ENV_ADDR; #endif env_import(buf, 1); } int saveenv(void) { - env_t env_new; +#ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE + env_t *env_new = (env_t *)env_buf; +#else + env_t *env_new = (env_t *)CONFIG_ENV_ADDR; +#endif ssize_t len; char *res; int rcode = 0; - res = (char *)&env_new.data; + res = (char *)env_new->data; len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; } - env_new.crc = crc32(0, env_new.data, ENV_SIZE); + env_new->crc = crc32(0, env_new->data, ENV_SIZE); #ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE - nvram_write(CONFIG_ENV_ADDR, &env_new, CONFIG_ENV_SIZE); -#else - if (memcpy((char *)CONFIG_ENV_ADDR, &env_new, CONFIG_ENV_SIZE) == NULL) - rcode = 1; + nvram_write(CONFIG_ENV_ADDR, env_new, CONFIG_ENV_SIZE); #endif return rcode; } @@ -115,7 +121,7 @@ int env_init(void) { #if defined(CONFIG_SYS_NVRAM_ACCESS_ROUTINE) ulong crc; - uchar data[ENV_SIZE]; + uchar *data = env_buf; nvram_read(&crc, CONFIG_ENV_ADDR, sizeof(ulong)); nvram_read(data, CONFIG_ENV_ADDR + sizeof(ulong), ENV_SIZE); |