env: sf: remove the static env_flash variable
As the the SPI flash is probed and is released in each ENV sf function the env_flash no more need to be static. This patch move this device handle as local variable of each function and simplify the associated code (env_flash is never == NULL when setup_flash_device is called). Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
This commit is contained in:
parent
c2d00364c1
commit
ecf1544232
|
@ -44,9 +44,7 @@ static ulong env_new_offset = CONFIG_ENV_OFFSET_REDUND;
|
||||||
|
|
||||||
DECLARE_GLOBAL_DATA_PTR;
|
DECLARE_GLOBAL_DATA_PTR;
|
||||||
|
|
||||||
static struct spi_flash *env_flash;
|
static int setup_flash_device(struct spi_flash **env_flash)
|
||||||
|
|
||||||
static int setup_flash_device(void)
|
|
||||||
{
|
{
|
||||||
#if CONFIG_IS_ENABLED(DM_SPI_FLASH)
|
#if CONFIG_IS_ENABLED(DM_SPI_FLASH)
|
||||||
struct udevice *new;
|
struct udevice *new;
|
||||||
|
@ -61,14 +59,11 @@ static int setup_flash_device(void)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
env_flash = dev_get_uclass_priv(new);
|
*env_flash = dev_get_uclass_priv(new);
|
||||||
#else
|
#else
|
||||||
if (env_flash)
|
*env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
|
||||||
spi_flash_free(env_flash);
|
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);
|
env_set_default("spi_flash_probe() failed", 0);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -84,8 +79,9 @@ static int env_sf_save(void)
|
||||||
u32 saved_size = 0, saved_offset = 0, sector;
|
u32 saved_size = 0, saved_offset = 0, sector;
|
||||||
u32 sect_size = CONFIG_ENV_SECT_SIZE;
|
u32 sect_size = CONFIG_ENV_SECT_SIZE;
|
||||||
int ret;
|
int ret;
|
||||||
|
struct spi_flash *env_flash;
|
||||||
|
|
||||||
ret = setup_flash_device();
|
ret = setup_flash_device(&env_flash);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
@ -155,7 +151,6 @@ static int env_sf_save(void)
|
||||||
|
|
||||||
done:
|
done:
|
||||||
spi_flash_free(env_flash);
|
spi_flash_free(env_flash);
|
||||||
env_flash = NULL;
|
|
||||||
|
|
||||||
if (saved_buffer)
|
if (saved_buffer)
|
||||||
free(saved_buffer);
|
free(saved_buffer);
|
||||||
|
@ -168,6 +163,7 @@ static int env_sf_load(void)
|
||||||
int ret;
|
int ret;
|
||||||
int read1_fail, read2_fail;
|
int read1_fail, read2_fail;
|
||||||
env_t *tmp_env1, *tmp_env2;
|
env_t *tmp_env1, *tmp_env2;
|
||||||
|
struct spi_flash *env_flash;
|
||||||
|
|
||||||
tmp_env1 = (env_t *)memalign(ARCH_DMA_MINALIGN,
|
tmp_env1 = (env_t *)memalign(ARCH_DMA_MINALIGN,
|
||||||
CONFIG_ENV_SIZE);
|
CONFIG_ENV_SIZE);
|
||||||
|
@ -179,7 +175,7 @@ static int env_sf_load(void)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = setup_flash_device();
|
ret = setup_flash_device(&env_flash);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -192,7 +188,6 @@ static int env_sf_load(void)
|
||||||
read2_fail, H_EXTERNAL);
|
read2_fail, H_EXTERNAL);
|
||||||
|
|
||||||
spi_flash_free(env_flash);
|
spi_flash_free(env_flash);
|
||||||
env_flash = NULL;
|
|
||||||
out:
|
out:
|
||||||
free(tmp_env1);
|
free(tmp_env1);
|
||||||
free(tmp_env2);
|
free(tmp_env2);
|
||||||
|
@ -207,8 +202,9 @@ static int env_sf_save(void)
|
||||||
char *saved_buffer = NULL;
|
char *saved_buffer = NULL;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
env_t env_new;
|
env_t env_new;
|
||||||
|
struct spi_flash *env_flash;
|
||||||
|
|
||||||
ret = setup_flash_device();
|
ret = setup_flash_device(&env_flash);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
@ -259,7 +255,6 @@ static int env_sf_save(void)
|
||||||
|
|
||||||
done:
|
done:
|
||||||
spi_flash_free(env_flash);
|
spi_flash_free(env_flash);
|
||||||
env_flash = NULL;
|
|
||||||
|
|
||||||
if (saved_buffer)
|
if (saved_buffer)
|
||||||
free(saved_buffer);
|
free(saved_buffer);
|
||||||
|
@ -271,6 +266,7 @@ static int env_sf_load(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
|
struct spi_flash *env_flash;
|
||||||
|
|
||||||
buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE);
|
buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
|
@ -278,7 +274,7 @@ static int env_sf_load(void)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = setup_flash_device();
|
ret = setup_flash_device(&env_flash);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -295,7 +291,6 @@ static int env_sf_load(void)
|
||||||
|
|
||||||
err_read:
|
err_read:
|
||||||
spi_flash_free(env_flash);
|
spi_flash_free(env_flash);
|
||||||
env_flash = NULL;
|
|
||||||
out:
|
out:
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
|
@ -307,8 +302,9 @@ static int env_sf_erase(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
env_t env;
|
env_t env;
|
||||||
|
struct spi_flash *env_flash;
|
||||||
|
|
||||||
ret = setup_flash_device();
|
ret = setup_flash_device(&env_flash);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
@ -322,7 +318,6 @@ static int env_sf_erase(void)
|
||||||
|
|
||||||
done:
|
done:
|
||||||
spi_flash_free(env_flash);
|
spi_flash_free(env_flash);
|
||||||
env_flash = NULL;
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -367,6 +362,7 @@ static int env_sf_init_early(void)
|
||||||
int crc1_ok;
|
int crc1_ok;
|
||||||
env_t *tmp_env2 = NULL;
|
env_t *tmp_env2 = NULL;
|
||||||
env_t *tmp_env1;
|
env_t *tmp_env1;
|
||||||
|
struct spi_flash *env_flash;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if malloc is not ready yet, we cannot use
|
* if malloc is not ready yet, we cannot use
|
||||||
|
@ -384,7 +380,7 @@ static int env_sf_init_early(void)
|
||||||
if (!tmp_env1 || !tmp_env2)
|
if (!tmp_env1 || !tmp_env2)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = setup_flash_device();
|
ret = setup_flash_device(&env_flash);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -420,12 +416,11 @@ static int env_sf_init_early(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
spi_flash_free(env_flash);
|
spi_flash_free(env_flash);
|
||||||
env_flash = NULL;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
err_read:
|
err_read:
|
||||||
spi_flash_free(env_flash);
|
spi_flash_free(env_flash);
|
||||||
env_flash = NULL;
|
|
||||||
free(tmp_env1);
|
free(tmp_env1);
|
||||||
if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT))
|
if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT))
|
||||||
free(tmp_env2);
|
free(tmp_env2);
|
||||||
|
|
Loading…
Reference in New Issue