diff mbox series

[06/11] env: add env_driver to env_driver functions' arguments

Message ID 0a56db0dbb1b0eec0151842b800ad73d7ddbfc15.1513975247.git-series.quentin.schulz@free-electrons.com
State New
Headers show
Series Introduce variables whitelisting in environment | expand

Commit Message

Quentin Schulz Dec. 22, 2017, 9:13 p.m. UTC
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(-)
diff mbox series

Patch

diff --git a/env/eeprom.c b/env/eeprom.c
index 584379e..b0ffce4 100644
--- a/env/eeprom.c
+++ b/env/eeprom.c
@@ -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;
diff --git a/env/env.c b/env/env.c
index 43a62b8..7c98083 100644
--- a/env/env.c
+++ b/env/env.c
@@ -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 */
diff --git a/env/ext4.c b/env/ext4.c
index 6520221..77c0389 100644
--- a/env/ext4.c
+++ b/env/ext4.c
@@ -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;
diff --git a/env/fat.c b/env/fat.c
index 51c4ced..05b5971 100644
--- a/env/fat.c
+++ b/env/fat.c
@@ -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;
diff --git a/env/flash.c b/env/flash.c
index bac10ff..45e58b4 100644
--- a/env/flash.c
+++ b/env/flash.c
@@ -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)) {
diff --git a/env/mmc.c b/env/mmc.c
index 885e000..64d1404 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -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);
diff --git a/env/nand.c b/env/nand.c
index 8058b55..6ed3c26 100644
--- a/env/nand.c
+++ b/env/nand.c
@@ -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;
diff --git a/env/nowhere.c b/env/nowhere.c
index 7a37909..fb6ea9e 100644
--- a/env/nowhere.c
+++ b/env/nowhere.c
@@ -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;
diff --git a/env/nvram.c b/env/nvram.c
index c8b3475..aad341d 100644
--- a/env/nvram.c
+++ b/env/nvram.c
@@ -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;
diff --git a/env/onenand.c b/env/onenand.c
index 2e3045c..e633ebe 100644
--- a/env/onenand.c
+++ b/env/onenand.c
@@ -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;
diff --git a/env/remote.c b/env/remote.c
index c013fdd..b004964 100644
--- a/env/remote.c
+++ b/env/remote.c
@@ -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);
diff --git a/env/sata.c b/env/sata.c
index a770297..93289be 100644
--- a/env/sata.c
+++ b/env/sata.c
@@ -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;
diff --git a/env/sf.c b/env/sf.c
index e51b1ae..e811cde 100644
--- a/env/sf.c
+++ b/env/sf.c
@@ -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;
diff --git a/env/ubi.c b/env/ubi.c
index 1c4653d..a649999 100644
--- a/env/ubi.c
+++ b/env/ubi.c
@@ -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);
 
diff --git a/include/environment.h b/include/environment.h
index 33e47ba..34a0d5e 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -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