@@ -61,7 +61,7 @@ static int eeprom_bus_write(unsigned dev_addr, unsigned offset,
return rcode;
}
-static int env_eeprom_get_char(int index)
+static int env_eeprom_get_char(struct env_driver *drv, int index)
{
uchar c;
unsigned int off = CONFIG_ENV_OFFSET;
@@ -76,7 +76,7 @@ static int env_eeprom_get_char(int index)
return c;
}
-static int env_eeprom_load(void)
+static int env_eeprom_load(struct env_driver *drv)
{
char buf_env[CONFIG_ENV_SIZE];
unsigned int off = CONFIG_ENV_OFFSET;
@@ -186,7 +186,7 @@ static int env_eeprom_load(void)
return 0;
}
-static int env_eeprom_save(void)
+static int env_eeprom_save(struct env_driver *drv)
{
env_t env_new;
int rc;
@@ -153,7 +153,7 @@ int env_get_char(int index)
if (!(gd->env_has_init & BIT(drv->location)))
continue;
- ret = drv->get_char(index);
+ ret = drv->get_char(drv, index);
if (!ret)
return 0;
@@ -181,7 +181,7 @@ int env_load(void)
continue;
printf("Loading Environment from %s... ", drv->name);
- ret = drv->load();
+ ret = drv->load(drv);
printf("%s\n", ret ? "Failed" : "OK");
if (!ret)
break;
@@ -205,7 +205,7 @@ int env_load(void)
printf("Overriding env variables with ones from %s env...",
__func__, drv->name);
- ret = drv->load();
+ ret = drv->load(drv);
printf("%s\n", ret ? "Failed" : "OK");
if (!ret) {
found = true;
@@ -241,7 +241,7 @@ int env_save(void)
continue;
printf("Saving Environment to %s... ", drv->name);
- ret = drv->save();
+ ret = drv->save(drv);
printf("%s\n", ret ? "Failed" : "OK");
#ifdef CONFIG_ENV_VAR_WHITELIST
/* When whitelisting, we want to save to all media available */
@@ -34,7 +34,7 @@
DECLARE_GLOBAL_DATA_PTR;
#ifdef CONFIG_CMD_SAVEENV
-static int env_ext4_save(void)
+static int env_ext4_save(struct env_driver *drv)
{
env_t env_new;
struct blk_desc *dev_desc = NULL;
@@ -75,7 +75,7 @@ static int env_ext4_save(void)
}
#endif /* CONFIG_CMD_SAVEENV */
-static int env_ext4_load(void)
+static int env_ext4_load(struct env_driver *drv)
{
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
struct blk_desc *dev_desc = NULL;
@@ -34,7 +34,7 @@
DECLARE_GLOBAL_DATA_PTR;
#ifdef CMD_SAVEENV
-static int env_fat_save(void)
+static int env_fat_save(struct env_driver *drv)
{
env_t env_new;
struct blk_desc *dev_desc = NULL;
@@ -73,7 +73,7 @@ static int env_fat_save(void)
#endif /* CMD_SAVEENV */
#ifdef LOADENV
-static int env_fat_load(void)
+static int env_fat_load(struct env_driver *drv)
{
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
struct blk_desc *dev_desc = NULL;
@@ -71,7 +71,7 @@ static ulong __maybe_unused end_addr_new =
#ifdef CONFIG_ENV_ADDR_REDUND
#ifdef INITENV
-static int env_flash_init(void)
+static int env_flash_init(struct env_driver *drv)
{
int crc1_ok = 0, crc2_ok = 0;
@@ -117,7 +117,7 @@ static int env_flash_init(void)
#endif
#ifdef CMD_SAVEENV
-static int env_flash_save(void)
+static int env_flash_save(struct env_driver *drv)
{
env_t env_new;
char *saved_data = NULL;
@@ -222,7 +222,7 @@ done:
#else /* ! CONFIG_ENV_ADDR_REDUND */
#ifdef INITENV
-static int env_flash_init(void)
+static int env_flash_init(struct env_driver *drv)
{
if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
gd->env_addr = (ulong)&(env_ptr->data);
@@ -237,7 +237,7 @@ static int env_flash_init(void)
#endif
#ifdef CMD_SAVEENV
-static int env_flash_save(void)
+static int env_flash_save(struct env_driver *drv)
{
env_t env_new;
int rc = 1;
@@ -308,7 +308,7 @@ done:
#endif /* CONFIG_ENV_ADDR_REDUND */
#ifdef LOADENV
-static int env_flash_load(void)
+static int env_flash_load(struct env_driver *drv)
{
#ifdef CONFIG_ENV_ADDR_REDUND
if (gd->env_addr != (ulong)&(flash_addr->data)) {
@@ -143,7 +143,7 @@ static inline int write_env(struct mmc *mmc, unsigned long size,
return (n == blk_cnt) ? 0 : -1;
}
-static int env_mmc_save(void)
+static int env_mmc_save(struct env_driver *drv)
{
ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
int dev = mmc_get_env_dev();
@@ -206,7 +206,7 @@ static inline int read_env(struct mmc *mmc, unsigned long size,
}
#ifdef CONFIG_ENV_OFFSET_REDUND
-static int env_mmc_load(void)
+static int env_mmc_load(struct env_driver *drv)
{
#if !defined(ENV_IS_EMBEDDED)
struct mmc *mmc;
@@ -268,7 +268,7 @@ err:
return ret;
}
#else /* ! CONFIG_ENV_OFFSET_REDUND */
-static int env_mmc_load(void)
+static int env_mmc_load(struct env_driver *drv)
{
#if !defined(ENV_IS_EMBEDDED)
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
@@ -62,7 +62,7 @@ DECLARE_GLOBAL_DATA_PTR;
* This way the SPL loads not only the U-Boot image from NAND but
* also the environment.
*/
-static int env_nand_init(void)
+static int env_nand_init(struct env_driver *drv)
{
#if defined(ENV_IS_EMBEDDED) || defined(CONFIG_NAND_ENV_DST)
int crc1_ok = 0, crc2_ok = 0;
@@ -183,7 +183,7 @@ static int erase_and_write_env(const struct nand_env_location *location,
return ret;
}
-static int env_nand_save(void)
+static int env_nand_save(struct env_driver *drv)
{
int ret = 0;
ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
@@ -315,7 +315,7 @@ int get_nand_env_oob(struct mtd_info *mtd, unsigned long *result)
#endif
#ifdef CONFIG_ENV_OFFSET_REDUND
-static int env_nand_load(void)
+static int env_nand_load(struct env_driver *drv)
{
#if defined(ENV_IS_EMBEDDED)
return 0;
@@ -368,7 +368,7 @@ done:
* device i.e., nand_dev_desc + 0. This is also the behaviour using
* the new NAND code.
*/
-static int env_nand_load(void)
+static int env_nand_load(struct env_driver *drv)
{
#if !defined(ENV_IS_EMBEDDED)
int ret;
@@ -15,7 +15,7 @@
DECLARE_GLOBAL_DATA_PTR;
-static int env_nowhere_load(void)
+static int env_nowhere_load(struct env_driver *drv)
{
return !env_import((char *)default_environment, 0);
}
@@ -24,7 +24,7 @@ static int env_nowhere_load(void)
* Because we only ever have the default environment available we must mark
* it as invalid.
*/
-static int env_nowhere_init(void)
+static int env_nowhere_init(struct env_driver *drv)
{
gd->env_addr = (ulong)&default_environment[0];
gd->env_valid = ENV_VALID;
@@ -41,7 +41,7 @@ env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
#endif
#ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE
-static int env_nvram_get_char(int index)
+static int env_nvram_get_char(struct env_driver *drv, int index)
{
uchar c;
@@ -51,7 +51,7 @@ static int env_nvram_get_char(int index)
}
#endif
-static int env_nvram_load(void)
+static int env_nvram_load(struct env_driver *drv)
{
char buf[CONFIG_ENV_SIZE];
@@ -65,7 +65,7 @@ static int env_nvram_load(void)
return 0;
}
-static int env_nvram_save(void)
+static int env_nvram_save(struct env_driver *drv)
{
env_t env_new;
int rcode = 0;
@@ -88,7 +88,7 @@ static int env_nvram_save(void)
*
* We are still running from ROM, so data use is limited
*/
-static int env_nvram_init(void)
+static int env_nvram_init(struct env_driver *drv)
{
#if defined(CONFIG_SYS_NVRAM_ACCESS_ROUTINE)
ulong crc;
@@ -26,7 +26,7 @@
DECLARE_GLOBAL_DATA_PTR;
-static int env_onenand_load(void)
+static int env_onenand_load(struct env_driver *drv)
{
struct mtd_info *mtd = &onenand_mtd;
#ifdef CONFIG_ENV_ADDR_FLEX
@@ -63,7 +63,7 @@ static int env_onenand_load(void)
return rc ? 0 : -EIO;
}
-static int env_onenand_save(void)
+static int env_onenand_save(struct env_driver *drv)
{
env_t env_new;
int ret;
@@ -23,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR;
#define CONFIG_ENV_OFFSET 0
#endif
-static int env_remote_init(void)
+static int env_remote_init(struct env_driver *drv)
{
if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
gd->env_addr = (ulong)&(env_ptr->data);
@@ -35,7 +35,7 @@ static int env_remote_init(void)
}
#ifdef CONFIG_CMD_SAVEENV
-static int env_remote_save(void)
+static int env_remote_save(struct env_driver *drv)
{
#ifdef CONFIG_SRIO_PCIE_BOOT_SLAVE
printf("Can not support the 'saveenv' when boot from SRIO or PCIE!\n");
@@ -46,7 +46,7 @@ static int env_remote_save(void)
}
#endif /* CONFIG_CMD_SAVEENV */
-static int env_remote_load(void)
+static int env_remote_load(struct env_driver *drv)
{
#ifndef ENV_IS_EMBEDDED
env_import((char *)env_ptr, 1);
@@ -45,7 +45,7 @@ static inline int write_env(struct blk_desc *sata, unsigned long size,
return (n == blk_cnt) ? 0 : -1;
}
-static int env_sata_save(void)
+static int env_sata_save(struct env_driver *drv)
{
ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
struct blk_desc *sata = NULL;
@@ -91,7 +91,7 @@ static inline int read_env(struct blk_desc *sata, unsigned long size,
return (n == blk_cnt) ? 0 : -1;
}
-static void env_sata_load(void)
+static void env_sata_load(struct env_driver *drv)
{
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
struct blk_desc *sata = NULL;
@@ -82,7 +82,7 @@ static int setup_flash_device(void)
#if defined(CONFIG_ENV_OFFSET_REDUND)
#ifdef CMD_SAVEENV
-static int env_sf_save(void)
+static int env_sf_save(struct env_driver *drv)
{
env_t env_new;
char *saved_buffer = NULL, flag = OBSOLETE_FLAG;
@@ -162,7 +162,7 @@ static int env_sf_save(void)
}
#endif /* CMD_SAVEENV */
-static int env_sf_load(void)
+static int env_sf_load(struct env_driver *drv)
{
int ret;
int crc1_ok = 0, crc2_ok = 0;
@@ -251,7 +251,7 @@ out:
}
#else
#ifdef CMD_SAVEENV
-static int env_sf_save(void)
+static int env_sf_save(struct env_driver *drv)
{
u32 saved_size, saved_offset, sector;
char *saved_buffer = NULL;
@@ -312,7 +312,7 @@ static int env_sf_save(void)
}
#endif /* CMD_SAVEENV */
-static int env_sf_load(void)
+static int env_sf_load(struct env_driver *drv)
{
int ret;
char *buf = NULL;
@@ -20,7 +20,7 @@ DECLARE_GLOBAL_DATA_PTR;
#ifdef CONFIG_CMD_SAVEENV
#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
-static int env_ubi_save(void)
+static int env_ubi_save(struct env_driver *drv)
{
ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
int ret;
@@ -62,7 +62,7 @@ static int env_ubi_save(void)
return 0;
}
#else /* ! CONFIG_SYS_REDUNDAND_ENVIRONMENT */
-static int env_ubi_save(void)
+static int env_ubi_save(struct env_driver *drv)
{
ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
int ret;
@@ -91,7 +91,7 @@ static int env_ubi_save(void)
#endif /* CONFIG_CMD_SAVEENV */
#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
-static int env_ubi_load(void)
+static int env_ubi_load(struct env_driver *drv)
{
ALLOC_CACHE_ALIGN_BUFFER(char, env1_buf, CONFIG_ENV_SIZE);
ALLOC_CACHE_ALIGN_BUFFER(char, env2_buf, CONFIG_ENV_SIZE);
@@ -135,7 +135,7 @@ static int env_ubi_load(void)
return 0;
}
#else /* ! CONFIG_SYS_REDUNDAND_ENVIRONMENT */
-static int env_ubi_load(void)
+static int env_ubi_load(struct env_driver *drv)
{
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
@@ -222,6 +222,8 @@ enum env_operation {
ENVO_SAVE,
};
+struct env_driver;
+
struct env_driver {
const char *name;
enum env_location location;
@@ -232,10 +234,11 @@ struct env_driver {
* This method is optional. If not provided, a default implementation
* will read from gd->env_addr.
*
+ * @drv: the driver whose get_char function is about to be called
* @index: Index of character to read (0=first)
* @return character read, or -ve on error
*/
- int (*get_char)(int index);
+ int (*get_char)(struct env_driver *drv, int index);
/**
* load() - Load the environment from storage
@@ -243,28 +246,31 @@ struct env_driver {
* This method is optional. If not provided, no environment will be
* loaded.
*
+ * @drv: the driver whose load function is about to be called
* @return 0 if OK, -ve on error
*/
- int (*load)(void);
+ int (*load)(struct env_driver *drv);
/**
* save() - Save the environment to storage
*
* This method is required for 'saveenv' to work.
*
+ * @drv: the driver whose save function is about to be called
* @return 0 if OK, -ve on error
*/
- int (*save)(void);
+ int (*save)(struct env_driver *drv);
/**
* init() - Set up the initial pre-relocation environment
*
* This method is optional.
*
+ * @drv: the driver whose init function is about to be called
* @return 0 if OK, -ENOENT if no initial environment could be found,
* other -ve on error
*/
- int (*init)(void);
+ int (*init)(struct env_driver *drv);
};
#ifdef CONFIG_ENV_VAR_WHITELIST
Might be interesting to get some infos about the driver (e.g. its location) when inside one of its functions. Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com> --- env/eeprom.c | 6 +++--- env/env.c | 8 ++++---- env/ext4.c | 4 ++-- env/fat.c | 4 ++-- env/flash.c | 10 +++++----- env/mmc.c | 6 +++--- env/nand.c | 8 ++++---- env/nowhere.c | 4 ++-- env/nvram.c | 8 ++++---- env/onenand.c | 4 ++-- env/remote.c | 6 +++--- env/sata.c | 4 ++-- env/sf.c | 8 ++++---- env/ubi.c | 8 ++++---- include/environment.h | 14 ++++++++++---- 15 files changed, 54 insertions(+), 48 deletions(-)