Skip to content

Commit

Permalink
env: Switch over to use environment location drivers
Browse files Browse the repository at this point in the history
Move over to use a the master implementation of the location drivers, with
each method calling out to the appropriate driver.

Signed-off-by: Simon Glass <[email protected]>
Reviewed-by: Tom Rini <[email protected]>
  • Loading branch information
sjg20 authored and trini committed Aug 16, 2017
1 parent c9d728d commit e5bce24
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 114 deletions.
16 changes: 8 additions & 8 deletions env/dataflash.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env_t *env_ptr;

char *env_name_spec = "dataflash";

uchar env_get_char_spec(int index)
static unsigned char env_dataflash_get_char(int index)
{
uchar c;

Expand All @@ -27,7 +27,7 @@ uchar env_get_char_spec(int index)
return c;
}

void env_relocate_spec(void)
static void env_dataflash_load(void)
{
ulong crc, new = 0;
unsigned off;
Expand All @@ -54,7 +54,7 @@ void env_relocate_spec(void)
#error No support for redundant environment on dataflash yet!
#endif

int saveenv(void)
static int env_dataflash_save(void)
{
env_t env_new;
int ret;
Expand All @@ -74,7 +74,7 @@ int saveenv(void)
* We are still running from ROM, so data use is limited.
* Use a (moderately small) buffer on the stack
*/
int env_init(void)
int env_dataflash_init(void)
{
/* use default */
gd->env_addr = (ulong)&default_environment[0];
Expand All @@ -85,8 +85,8 @@ int env_init(void)

U_BOOT_ENV_LOCATION(dataflash) = {
.location = ENVL_DATAFLASH,
.get_char = env_get_char_spec,
.load = env_relocate_spec,
.save = env_save_ptr(saveenv),
.init = env_init,
.get_char = env_dataflash_get_char,
.load = env_dataflash_load,
.save = env_save_ptr(env_dataflash_save),
.init = env_dataflash_init,
};
16 changes: 8 additions & 8 deletions env/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static int eeprom_bus_write(unsigned dev_addr, unsigned offset,
return rcode;
}

uchar env_get_char_spec(int index)
static uchar env_eeprom_get_char(int index)
{
uchar c;
unsigned int off = CONFIG_ENV_OFFSET;
Expand All @@ -80,7 +80,7 @@ uchar env_get_char_spec(int index)
return c;
}

void env_relocate_spec(void)
static void env_eeprom_load(void)
{
char buf_env[CONFIG_ENV_SIZE];
unsigned int off = CONFIG_ENV_OFFSET;
Expand Down Expand Up @@ -188,7 +188,7 @@ void env_relocate_spec(void)
env_import(buf_env, 1);
}

int saveenv(void)
static int env_eeprom_save(void)
{
env_t env_new;
int rc;
Expand Down Expand Up @@ -237,7 +237,7 @@ int saveenv(void)
* We are still running from ROM, so data use is limited.
* Use a (moderately small) buffer on the stack
*/
int env_init(void)
static int env_eeprom_init(void)
{
gd->env_addr = (ulong)&default_environment[0];
gd->env_valid = ENV_VALID;
Expand All @@ -246,8 +246,8 @@ int env_init(void)

U_BOOT_ENV_LOCATION(eeprom) = {
.location = ENVL_EEPROM,
.get_char = env_get_char_spec,
.load = env_relocate_spec,
.save = env_save_ptr(saveenv),
.init = env_init,
.get_char = env_eeprom_get_char,
.load = env_eeprom_load,
.save = env_save_ptr(env_eeprom_save),
.init = env_eeprom_init,
};
20 changes: 20 additions & 0 deletions env/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,23 @@ int env_init_new(void)

return 0;
}

unsigned char env_get_char_spec(int index)
{
return *(uchar *)(gd->env_addr + index);
}

void env_relocate_spec(void)
{
env_load();
}

int saveenv(void)
{
return env_save();
}

int env_init(void)
{
return env_init_new();
}
13 changes: 6 additions & 7 deletions env/ext4.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ env_t *env_ptr;

DECLARE_GLOBAL_DATA_PTR;

int env_init(void)
static int env_ext4_init(void)
{
/* use default */
gd->env_addr = (ulong)&default_environment[0];
Expand All @@ -47,7 +47,7 @@ int env_init(void)
}

#ifdef CONFIG_CMD_SAVEENV
int saveenv(void)
static int env_ext4_save(void)
{
env_t env_new;
struct blk_desc *dev_desc = NULL;
Expand Down Expand Up @@ -88,7 +88,7 @@ int saveenv(void)
}
#endif /* CONFIG_CMD_SAVEENV */

void env_relocate_spec(void)
static void env_ext4_load(void)
{
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
struct blk_desc *dev_desc = NULL;
Expand Down Expand Up @@ -130,8 +130,7 @@ void env_relocate_spec(void)

U_BOOT_ENV_LOCATION(ext4) = {
.location = ENVL_EXT4,
.get_char = env_get_char_spec,
.load = env_relocate_spec,
.save = env_save_ptr(saveenv),
.init = env_init,
.load = env_ext4_load,
.save = env_save_ptr(env_ext4_save),
.init = env_ext4_init,
};
13 changes: 6 additions & 7 deletions env/fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ env_t *env_ptr;

DECLARE_GLOBAL_DATA_PTR;

int env_init(void)
static int env_fat_init(void)
{
/* use default */
gd->env_addr = (ulong)&default_environment[0];
Expand All @@ -47,7 +47,7 @@ int env_init(void)
}

#ifdef CMD_SAVEENV
int saveenv(void)
static int env_fat_save(void)
{
env_t env_new;
struct blk_desc *dev_desc = NULL;
Expand Down Expand Up @@ -87,7 +87,7 @@ int saveenv(void)
#endif /* CMD_SAVEENV */

#ifdef LOADENV
void env_relocate_spec(void)
static void env_fat_load(void)
{
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
struct blk_desc *dev_desc = NULL;
Expand Down Expand Up @@ -125,12 +125,11 @@ void env_relocate_spec(void)

U_BOOT_ENV_LOCATION(fat) = {
.location = ENVL_FAT,
.get_char = env_get_char_spec,
#ifdef LOADENV
.load = env_relocate_spec,
.load = env_fat_load,
#endif
#ifdef CMD_SAVEENV
.save = env_save_ptr(saveenv),
.save = env_save_ptr(env_fat_save),
#endif
.init = env_init,
.init = env_fat_init,
};
34 changes: 18 additions & 16 deletions env/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,30 @@ char *env_name_spec = "Flash";
#ifdef ENV_IS_EMBEDDED
env_t *env_ptr = &environment;

static env_t *flash_addr = (env_t *)CONFIG_ENV_ADDR;
static __maybe_unused env_t *flash_addr = (env_t *)CONFIG_ENV_ADDR;

#else /* ! ENV_IS_EMBEDDED */

env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
static env_t *flash_addr = (env_t *)CONFIG_ENV_ADDR;
static __maybe_unused env_t *flash_addr = (env_t *)CONFIG_ENV_ADDR;
#endif /* ENV_IS_EMBEDDED */

#if defined(CMD_SAVEENV) || defined(CONFIG_ENV_ADDR_REDUND)
/* CONFIG_ENV_ADDR is supposed to be on sector boundary */
static ulong end_addr = CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1;
#endif
static ulong __maybe_unused end_addr =
CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1;

#ifdef CONFIG_ENV_ADDR_REDUND
static env_t *flash_addr_new = (env_t *)CONFIG_ENV_ADDR_REDUND;

static env_t __maybe_unused *flash_addr_new = (env_t *)CONFIG_ENV_ADDR_REDUND;

/* CONFIG_ENV_ADDR_REDUND is supposed to be on sector boundary */
static ulong end_addr_new = CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1;
static ulong __maybe_unused end_addr_new =
CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1;
#endif /* CONFIG_ENV_ADDR_REDUND */


#ifdef CONFIG_ENV_ADDR_REDUND
#ifdef INITENV
int env_init(void)
static int env_flash_init(void)
{
int crc1_ok = 0, crc2_ok = 0;

Expand Down Expand Up @@ -119,7 +119,7 @@ int env_init(void)
#endif

#ifdef CMD_SAVEENV
int saveenv(void)
static int env_flash_save(void)
{
env_t env_new;
char *saved_data = NULL;
Expand Down Expand Up @@ -224,7 +224,7 @@ int saveenv(void)
#else /* ! CONFIG_ENV_ADDR_REDUND */

#ifdef INITENV
int env_init(void)
static int env_flash_init(void)
{
if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
gd->env_addr = (ulong)&(env_ptr->data);
Expand All @@ -239,7 +239,7 @@ int env_init(void)
#endif

#ifdef CMD_SAVEENV
int saveenv(void)
static int env_flash_save(void)
{
env_t env_new;
int rc = 1;
Expand Down Expand Up @@ -309,7 +309,8 @@ int saveenv(void)

#endif /* CONFIG_ENV_ADDR_REDUND */

void env_relocate_spec(void)
#ifdef LOADENV
static void env_flash_load(void)
{
#ifdef CONFIG_ENV_ADDR_REDUND
if (gd->env_addr != (ulong)&(flash_addr->data)) {
Expand Down Expand Up @@ -354,16 +355,17 @@ void env_relocate_spec(void)

env_import((char *)flash_addr, 1);
}
#endif /* LOADENV */

U_BOOT_ENV_LOCATION(flash) = {
.location = ENVL_FLASH,
#ifdef LOADENV
.load = env_relocate_spec,
.load = env_flash_load,
#endif
#ifdef CMD_SAVEENV
.save = env_save_ptr(saveenv),
.save = env_save_ptr(env_flash_save),
#endif
#ifdef INITENV
.init = env_init,
.init = env_flash_init,
#endif
};
19 changes: 9 additions & 10 deletions env/mmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ __weak int mmc_get_env_dev(void)
return CONFIG_SYS_MMC_ENV_DEV;
}

int env_init(void)
static int env_mmc_init(void)
{
/* use default */
gd->env_addr = (ulong)&default_environment[0];
Expand Down Expand Up @@ -145,7 +145,7 @@ static void fini_mmc_for_env(struct mmc *mmc)
#endif
}

#ifdef CONFIG_CMD_SAVEENV
#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_SPL_BUILD)
static inline int write_env(struct mmc *mmc, unsigned long size,
unsigned long offset, const void *buffer)
{
Expand All @@ -160,7 +160,7 @@ static inline int write_env(struct mmc *mmc, unsigned long size,
return (n == blk_cnt) ? 0 : -1;
}

int saveenv(void)
static int env_mmc_save(void)
{
ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
int dev = mmc_get_env_dev();
Expand Down Expand Up @@ -207,7 +207,7 @@ int saveenv(void)
fini_mmc_for_env(mmc);
return ret;
}
#endif /* CONFIG_CMD_SAVEENV */
#endif /* CONFIG_CMD_SAVEENV && !CONFIG_SPL_BUILD */

static inline int read_env(struct mmc *mmc, unsigned long size,
unsigned long offset, const void *buffer)
Expand All @@ -224,7 +224,7 @@ static inline int read_env(struct mmc *mmc, unsigned long size,
}

#ifdef CONFIG_ENV_OFFSET_REDUND
void env_relocate_spec(void)
static void env_mmc_load(void)
{
#if !defined(ENV_IS_EMBEDDED)
struct mmc *mmc;
Expand Down Expand Up @@ -284,7 +284,7 @@ void env_relocate_spec(void)
#endif
}
#else /* ! CONFIG_ENV_OFFSET_REDUND */
void env_relocate_spec(void)
static void env_mmc_load(void)
{
#if !defined(ENV_IS_EMBEDDED)
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
Expand Down Expand Up @@ -327,10 +327,9 @@ void env_relocate_spec(void)

U_BOOT_ENV_LOCATION(mmc) = {
.location = ENVL_MMC,
.get_char = env_get_char_spec,
.load = env_relocate_spec,
.load = env_mmc_load,
#ifndef CONFIG_SPL_BUILD
.save = env_save_ptr(saveenv),
.save = env_save_ptr(env_mmc_save),
#endif
.init = env_init,
.init = env_mmc_init,
};
Loading

0 comments on commit e5bce24

Please sign in to comment.