X-Git-Url: https://git.kernelconcepts.de/?a=blobdiff_plain;f=common%2Fenv_sf.c;h=e928f5752cc7c5dddaf13b329a8f1eb67b8b669e;hb=4c84f80f591808fae35b5f6b423a700aeea3d72b;hp=9f806fb090f54964566bc5bd4fef89068d0a4222;hpb=19d829fa60fc4e6df514a046142faaaf9fc8185d;p=karo-tx-uboot.git diff --git a/common/env_sf.c b/common/env_sf.c index 9f806fb090..e928f5752c 100644 --- a/common/env_sf.c +++ b/common/env_sf.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -47,8 +48,7 @@ static struct spi_flash *env_flash; int saveenv(void) { env_t env_new; - ssize_t len; - char *res, *saved_buffer = NULL, flag = OBSOLETE_FLAG; + char *saved_buffer = NULL, flag = OBSOLETE_FLAG; u32 saved_size, saved_offset, sector = 1; int ret; @@ -62,13 +62,9 @@ int saveenv(void) } } - 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); + ret = env_export(&env_new); + if (ret) + return ret; env_new.flags = ACTIVE_FLAG; if (gd->env_valid == 1) { @@ -192,15 +188,17 @@ void env_relocate_spec(void) tmp_env2->flags == ACTIVE_FLAG) { gd->env_valid = 2; } else if (tmp_env1->flags == tmp_env2->flags) { - gd->env_valid = 2; + gd->env_valid = 1; } else if (tmp_env1->flags == 0xFF) { + gd->env_valid = 1; + } else if (tmp_env2->flags == 0xFF) { gd->env_valid = 2; } else { /* * this differs from code in env_flash.c, but I think a sane * default path is desirable. */ - gd->env_valid = 2; + gd->env_valid = 1; } if (gd->env_valid == 1) @@ -225,10 +223,9 @@ out: int saveenv(void) { u32 saved_size, saved_offset, sector = 1; - char *res, *saved_buffer = NULL; + char *saved_buffer = NULL; int ret = 1; env_t env_new; - ssize_t len; if (!env_flash) { env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, @@ -260,13 +257,9 @@ int saveenv(void) sector++; } - 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); + ret = env_export(&env_new); + if (ret) goto done; - } - env_new.crc = crc32(0, env_new.data, ENV_SIZE); puts("Erasing SPI flash..."); ret = spi_flash_erase(env_flash, CONFIG_ENV_OFFSET, @@ -299,13 +292,16 @@ int saveenv(void) void env_relocate_spec(void) { - char buf[CONFIG_ENV_SIZE]; int ret; + char *buf = NULL; + buf = (char *)malloc(CONFIG_ENV_SIZE); env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); if (!env_flash) { set_default_env("!spi_flash_probe() failed"); + if (buf) + free(buf); return; } @@ -321,6 +317,8 @@ void env_relocate_spec(void) gd->env_valid = 1; out: spi_flash_free(env_flash); + if (buf) + free(buf); env_flash = NULL; } #endif