DECLARE_GLOBAL_DATA_PTR;
-char *env_name_spec = "SPI Flash";
-
static struct spi_flash *env_flash;
static int setup_flash_device(void)
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);
-}
-#endif
-
-static int env_sf_init(void)
-{
- /* SPI flash isn't usable before relocation */
- gd->env_addr = (ulong)&default_environment[0];
- gd->env_valid = ENV_VALID;
- return 0;
+ return ret;
}
+#endif
U_BOOT_ENV_LOCATION(sf) = {
.location = ENVL_SPI_FLASH,
+ ENV_NAME("SPI Flash")
.load = env_sf_load,
#ifdef CMD_SAVEENV
.save = env_save_ptr(env_sf_save),
#endif
- .init = env_sf_init,
};