return c;
}
-static void env_dataflash_load(void)
+static int env_dataflash_load(void)
{
ulong crc, new = 0;
unsigned off;
env_import(buf, 1);
else
set_default_env("!bad CRC");
+
+ return 0;
}
#ifdef CONFIG_ENV_OFFSET_REDUND
return c;
}
-static void env_eeprom_load(void)
+static int env_eeprom_load(void)
{
char buf_env[CONFIG_ENV_SIZE];
unsigned int off = CONFIG_ENV_OFFSET;
off, (uchar *)buf_env, CONFIG_ENV_SIZE);
env_import(buf_env, 1);
+
+ return 0;
}
static int env_eeprom_save(void)
}
#endif /* CONFIG_CMD_SAVEENV */
-static void env_ext4_load(void)
+static int env_ext4_load(void)
{
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
struct blk_desc *dev_desc = NULL;
}
env_import(buf, 1);
- return;
+ return 0;
err_env_relocate:
set_default_env(NULL);
+
+ return -EIO;
}
U_BOOT_ENV_LOCATION(ext4) = {
#endif /* CMD_SAVEENV */
#ifdef LOADENV
-static void env_fat_load(void)
+static int env_fat_load(void)
{
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
struct blk_desc *dev_desc = NULL;
}
env_import(buf, 1);
- return;
+ return 0;
err_env_relocate:
set_default_env(NULL);
+
+ return -EIO;
}
#endif /* LOADENV */
#endif /* CONFIG_ENV_ADDR_REDUND */
#ifdef LOADENV
-static void env_flash_load(void)
+static int env_flash_load(void)
{
#ifdef CONFIG_ENV_ADDR_REDUND
if (gd->env_addr != (ulong)&(flash_addr->data)) {
#endif /* CONFIG_ENV_ADDR_REDUND */
env_import((char *)flash_addr, 1);
+
+ return 0;
}
#endif /* LOADENV */
}
#ifdef CONFIG_ENV_OFFSET_REDUND
-static void env_mmc_load(void)
+static int env_mmc_load(void)
{
#if !defined(ENV_IS_EMBEDDED)
struct mmc *mmc;
errmsg = init_mmc_for_env(mmc);
if (errmsg) {
- ret = 1;
+ ret = -EIO;
goto err;
}
if (mmc_get_env_addr(mmc, 0, &offset1) ||
mmc_get_env_addr(mmc, 1, &offset2)) {
- ret = 1;
+ ret = -EIO;
goto fini;
}
if (read1_fail && read2_fail) {
errmsg = "!bad CRC";
- ret = 1;
+ ret = -EIO;
goto fini;
} else if (!read1_fail && read2_fail) {
gd->env_valid = ENV_VALID;
err:
if (ret)
set_default_env(errmsg);
+
#endif
+ return ret;
}
#else /* ! CONFIG_ENV_OFFSET_REDUND */
-static void env_mmc_load(void)
+static int env_mmc_load(void)
{
#if !defined(ENV_IS_EMBEDDED)
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
errmsg = init_mmc_for_env(mmc);
if (errmsg) {
- ret = 1;
+ ret = -EIO;
goto err;
}
if (mmc_get_env_addr(mmc, 0, &offset)) {
- ret = 1;
+ ret = -EIO;
goto fini;
}
if (read_env(mmc, CONFIG_ENV_SIZE, offset, buf)) {
errmsg = "!read failed";
- ret = 1;
+ ret = -EIO;
goto fini;
}
if (ret)
set_default_env(errmsg);
#endif
+ return ret;
}
#endif /* CONFIG_ENV_OFFSET_REDUND */
}
if (oob_buf[0] == ENV_OOB_MARKER) {
- *result = oob_buf[1] * mtd->erasesize;
+ *result = ovoid ob_buf[1] * mtd->erasesize;
} else if (oob_buf[0] == ENV_OOB_MARKER_OLD) {
*result = oob_buf[1];
} else {
#endif
#ifdef CONFIG_ENV_OFFSET_REDUND
-static void env_nand_load(void)
+static int env_nand_load(void)
{
-#if !defined(ENV_IS_EMBEDDED)
+#if defined(ENV_IS_EMBEDDED)
+ return 0;
+#else
int read1_fail = 0, read2_fail = 0;
env_t *tmp_env1, *tmp_env2;
+ int ret = 0;
tmp_env1 = (env_t *)malloc(CONFIG_ENV_SIZE);
tmp_env2 = (env_t *)malloc(CONFIG_ENV_SIZE);
if (tmp_env1 == NULL || tmp_env2 == NULL) {
puts("Can't allocate buffers for environment\n");
set_default_env("!malloc() failed");
+ ret = -EIO;
goto done;
}
free(tmp_env1);
free(tmp_env2);
+ return ret;
#endif /* ! ENV_IS_EMBEDDED */
}
#else /* ! CONFIG_ENV_OFFSET_REDUND */
* device i.e., nand_dev_desc + 0. This is also the behaviour using
* the new NAND code.
*/
-static void env_nand_load(void)
+static int env_nand_load(void)
{
#if !defined(ENV_IS_EMBEDDED)
int ret;
ret = readenv(CONFIG_ENV_OFFSET, (u_char *)buf);
if (ret) {
set_default_env("!readenv() failed");
- return;
+ return -EIO;
}
env_import(buf, 1);
#endif /* ! ENV_IS_EMBEDDED */
+
+ return 0;
}
#endif /* CONFIG_ENV_OFFSET_REDUND */
}
#endif
-static void env_nvram_load(void)
+static int env_nvram_load(void)
{
char buf[CONFIG_ENV_SIZE];
memcpy(buf, (void *)CONFIG_ENV_ADDR, CONFIG_ENV_SIZE);
#endif
env_import(buf, 1);
+
+ return 0;
}
static int env_nvram_save(void)
DECLARE_GLOBAL_DATA_PTR;
-static void env_onenand_load(void)
+static int env_onenand_load(void)
{
struct mtd_info *mtd = &onenand_mtd;
#ifdef CONFIG_ENV_ADDR_FLEX
rc = env_import(buf, 1);
if (rc)
gd->env_valid = ENV_VALID;
+
+ return rc ? 0 : -EIO;
}
static int env_onenand_save(void)
}
#endif /* CONFIG_CMD_SAVEENV */
-static void env_remote_load(void)
+static int env_remote_load(void)
{
#ifndef ENV_IS_EMBEDDED
env_import((char *)env_ptr, 1);
#endif
+
+ return 0;
}
U_BOOT_ENV_LOCATION(remote) = {
int env_sata;
if (sata_initialize())
- return;
+ return -EIO;
env_sata = sata_get_env_dev();
sata = sata_get_dev(env_sata);
if (sata == NULL) {
- printf("Unknown SATA(%d) device for environment!\n",
- env_sata);
- return;
+ printf("Unknown SATA(%d) device for environment!\n", env_sata);
+ return -EIO;
}
- if (read_env(sata, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, buf))
- return set_default_env(NULL);
+ if (read_env(sata, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, buf)) {
+ set_default_env(NULL);
+ return -EIO;
+ }
env_import(buf, 1);
+
+ return 0;
}
U_BOOT_ENV_LOCATION(sata) = {
0, 0, &new);
if (ret) {
set_default_env("!spi_flash_probe_bus_cs() failed");
- return 1;
+ return ret;
}
env_flash = dev_get_uclass_priv(new);
CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
if (!env_flash) {
set_default_env("!spi_flash_probe() failed");
- return 1;
+ return -EIO;
}
}
#endif
ret = env_export(&env_new);
if (ret)
- return ret;
+ return -EIO;
env_new.flags = ACTIVE_FLAG;
if (gd->env_valid == ENV_VALID) {
saved_offset = env_new_offset + CONFIG_ENV_SIZE;
saved_buffer = memalign(ARCH_DMA_MINALIGN, saved_size);
if (!saved_buffer) {
- ret = 1;
+ ret = -ENOMEM;
goto done;
}
ret = spi_flash_read(env_flash, saved_offset,
}
#endif /* CMD_SAVEENV */
-static void env_sf_load(void)
+static int env_sf_load(void)
{
int ret;
int crc1_ok = 0, crc2_ok = 0;
CONFIG_ENV_SIZE);
if (!tmp_env1 || !tmp_env2) {
set_default_env("!malloc() failed");
+ ret = -EIO;
goto out;
}
if (!crc1_ok && !crc2_ok) {
set_default_env("!bad CRC");
+ ret = -EIO;
goto err_read;
} else if (crc1_ok && !crc2_ok) {
gd->env_valid = ENV_VALID;
out:
free(tmp_env1);
free(tmp_env2);
+
+ return ret;
}
#else
#ifdef CMD_SAVEENV
}
#endif /* CMD_SAVEENV */
-static void env_sf_load(void)
+static int env_sf_load(void)
{
int ret;
char *buf = NULL;
buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE);
if (!buf) {
set_default_env("!malloc() failed");
- return;
+ return -EIO;
}
ret = setup_flash_device();
env_flash = NULL;
out:
free(buf);
+
+ return ret;
}
#endif
#endif /* CONFIG_CMD_SAVEENV */
#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
-static void env_ubi_load(void)
+static int env_ubi_load(void)
{
ALLOC_CACHE_ALIGN_BUFFER(char, env1_buf, CONFIG_ENV_SIZE);
ALLOC_CACHE_ALIGN_BUFFER(char, env2_buf, CONFIG_ENV_SIZE);
printf("\n** Cannot find mtd partition \"%s\"\n",
CONFIG_ENV_UBI_PART);
set_default_env(NULL);
- return;
+ return -EIO;
}
if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, (void *)tmp_env1,
}
env_import_redund((char *)tmp_env1, (char *)tmp_env2);
+
+ return 0;
}
#else /* ! CONFIG_SYS_REDUNDAND_ENVIRONMENT */
-static void env_ubi_load(void)
+static int env_ubi_load(void)
{
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
printf("\n** Cannot find mtd partition \"%s\"\n",
CONFIG_ENV_UBI_PART);
set_default_env(NULL);
- return;
+ return -EIO;
}
if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, buf, CONFIG_ENV_SIZE)) {
printf("\n** Unable to read env from %s:%s **\n",
CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);
set_default_env(NULL);
- return;
+ return -EIO;
}
env_import(buf, 1);
+
+ return 0;
}
#endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */
*
* This method is optional. If not provided, no environment will be
* loaded.
+ *
+ * @return 0 if OK, -ve on error
*/
- void (*load)(void);
+ int (*load)(void);
/**
* save() - Save the environment to storage