DECLARE_GLOBAL_DATA_PTR;
-static struct spi_flash *env_flash;
-
-static int setup_flash_device(void)
+static int setup_flash_device(struct spi_flash **env_flash)
{
#if CONFIG_IS_ENABLED(DM_SPI_FLASH)
struct udevice *new;
return ret;
}
- env_flash = dev_get_uclass_priv(new);
+ *env_flash = dev_get_uclass_priv(new);
#else
- if (env_flash)
- spi_flash_free(env_flash);
-
- 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) {
+ *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) {
env_set_default("spi_flash_probe() failed", 0);
return -EIO;
}
u32 saved_size = 0, saved_offset = 0, sector;
u32 sect_size = CONFIG_ENV_SECT_SIZE;
int ret;
+ struct spi_flash *env_flash;
- ret = setup_flash_device();
+ ret = setup_flash_device(&env_flash);
if (ret)
return ret;
done:
spi_flash_free(env_flash);
- env_flash = NULL;
if (saved_buffer)
free(saved_buffer);
int ret;
int read1_fail, read2_fail;
env_t *tmp_env1, *tmp_env2;
+ struct spi_flash *env_flash;
tmp_env1 = (env_t *)memalign(ARCH_DMA_MINALIGN,
CONFIG_ENV_SIZE);
goto out;
}
- ret = setup_flash_device();
+ ret = setup_flash_device(&env_flash);
if (ret)
goto out;
read2_fail, H_EXTERNAL);
spi_flash_free(env_flash);
- env_flash = NULL;
out:
free(tmp_env1);
free(tmp_env2);
char *saved_buffer = NULL;
int ret = 1;
env_t env_new;
+ struct spi_flash *env_flash;
- ret = setup_flash_device();
+ ret = setup_flash_device(&env_flash);
if (ret)
return ret;
done:
spi_flash_free(env_flash);
- env_flash = NULL;
if (saved_buffer)
free(saved_buffer);
{
int ret;
char *buf = NULL;
+ struct spi_flash *env_flash;
buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE);
if (!buf) {
return -EIO;
}
- ret = setup_flash_device();
+ ret = setup_flash_device(&env_flash);
if (ret)
goto out;
err_read:
spi_flash_free(env_flash);
- env_flash = NULL;
out:
free(buf);
{
int ret;
env_t env;
+ struct spi_flash *env_flash;
- ret = setup_flash_device();
+ ret = setup_flash_device(&env_flash);
if (ret)
return ret;
done:
spi_flash_free(env_flash);
- env_flash = NULL;
return ret;
}
int crc1_ok;
env_t *tmp_env2 = NULL;
env_t *tmp_env1;
+ struct spi_flash *env_flash;
/*
* if malloc is not ready yet, we cannot use
if (!tmp_env1 || !tmp_env2)
goto out;
- ret = setup_flash_device();
+ ret = setup_flash_device(&env_flash);
if (ret)
goto out;
}
spi_flash_free(env_flash);
- env_flash = NULL;
return 0;
err_read:
spi_flash_free(env_flash);
- env_flash = NULL;
+
free(tmp_env1);
if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT))
free(tmp_env2);