]> git.sur5r.net Git - u-boot/commitdiff
env: Drop the env_name_spec global
authorSimon Glass <sjg@chromium.org>
Thu, 3 Aug 2017 18:22:03 +0000 (12:22 -0600)
committerTom Rini <trini@konsulko.com>
Wed, 16 Aug 2017 00:50:28 +0000 (20:50 -0400)
Add a name to the driver and use that instead of the global variable
declared by each driver.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
17 files changed:
cmd/nvedit.c
env/dataflash.c
env/eeprom.c
env/env.c
env/ext4.c
env/fat.c
env/flash.c
env/mmc.c
env/nand.c
env/nowhere.c
env/nvram.c
env/onenand.c
env/remote.c
env/sata.c
env/sf.c
env/ubi.c
include/environment.h

index cd17db6409705a79d6102f45888a96e9770b50c4..75df997592e0553c5fa8e9f20d8da03cab583483 100644 (file)
@@ -706,7 +706,9 @@ ulong getenv_ulong(const char *name, int base, ulong default_val)
 static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc,
                       char * const argv[])
 {
-       printf("Saving Environment to %s...\n", env_name_spec);
+       struct env_driver *env = env_driver_lookup_default();
+
+       printf("Saving Environment to %s...\n", env->name);
 
        return saveenv() ? 1 : 0;
 }
index 8ab482b3b406fd1ef99e20dcea51df4d36cf2894..9421a6a5b236c598e900cfb66a542e11bf988a88 100644 (file)
@@ -16,8 +16,6 @@ DECLARE_GLOBAL_DATA_PTR;
 
 env_t *env_ptr;
 
-char *env_name_spec = "dataflash";
-
 static unsigned char env_dataflash_get_char(int index)
 {
        uchar c;
@@ -70,6 +68,7 @@ static int env_dataflash_save(void)
 
 U_BOOT_ENV_LOCATION(dataflash) = {
        .location       = ENVL_DATAFLASH,
+       ENV_NAME("dataflash")
        .get_char       = env_dataflash_get_char,
        .load           = env_dataflash_load,
        .save           = env_save_ptr(env_dataflash_save),
index 3cc412620acdc998de87cc50c450bddbe5181d01..2c795b9236dc322eb7e364892563f321e5aa440a 100644 (file)
@@ -23,8 +23,6 @@ DECLARE_GLOBAL_DATA_PTR;
 
 env_t *env_ptr;
 
-char *env_name_spec = "EEPROM";
-
 static int eeprom_bus_read(unsigned dev_addr, unsigned offset,
                           uchar *buffer, unsigned cnt)
 {
@@ -233,6 +231,7 @@ static int env_eeprom_save(void)
 
 U_BOOT_ENV_LOCATION(eeprom) = {
        .location       = ENVL_EEPROM,
+       ENV_NAME("EEPROM")
        .get_char       = env_eeprom_get_char,
        .load           = env_eeprom_load,
        .save           = env_save_ptr(env_eeprom_save),
index 12cd4750df49b56c29d644f92e19bfe778d9f982..53a085c43198279cc13fa77e76b73959350a732e 100644 (file)
--- a/env/env.c
+++ b/env/env.c
@@ -54,7 +54,7 @@ static enum env_location env_get_default_location(void)
                return ENVL_UNKNOWN;
 }
 
-static struct env_driver *env_driver_lookup_default(void)
+struct env_driver *env_driver_lookup_default(void)
 {
        enum env_location loc = env_get_default_location();
        struct env_driver *drv;
index 25a5cbecdd0060d5b61e0c2ec77c77813da8163e..5acdf0eda0dbb6d368622565237a87721ef0fc37 100644 (file)
@@ -31,8 +31,6 @@
 #include <ext4fs.h>
 #include <mmc.h>
 
-char *env_name_spec = "EXT4";
-
 env_t *env_ptr;
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -121,6 +119,7 @@ err_env_relocate:
 
 U_BOOT_ENV_LOCATION(ext4) = {
        .location       = ENVL_EXT4,
+       ENV_NAME("EXT4")
        .load           = env_ext4_load,
        .save           = env_save_ptr(env_ext4_save),
 };
index 1ff3d9dc865fd397540936ccf2fe383e57995886..eda18dbf3d4723ddb59ce5e488447ef0636f7833 100644 (file)
--- a/env/fat.c
+++ b/env/fat.c
@@ -31,8 +31,6 @@
 # endif
 #endif
 
-char *env_name_spec = "FAT";
-
 env_t *env_ptr;
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -116,6 +114,7 @@ err_env_relocate:
 
 U_BOOT_ENV_LOCATION(fat) = {
        .location       = ENVL_FAT,
+       ENV_NAME("FAT")
 #ifdef LOADENV
        .load           = env_fat_load,
 #endif
index 6ec9b61883a4c3f2d9db70d7f9b9010bf1263ba6..2d72c51622ff5d7198e28cf476604b39588267d4 100644 (file)
@@ -45,8 +45,6 @@ DECLARE_GLOBAL_DATA_PTR;
 #define INITENV
 #endif
 
-char *env_name_spec = "Flash";
-
 #ifdef ENV_IS_EMBEDDED
 env_t *env_ptr = &environment;
 
@@ -359,6 +357,7 @@ static void env_flash_load(void)
 
 U_BOOT_ENV_LOCATION(flash) = {
        .location       = ENVL_FLASH,
+       ENV_NAME("Flash")
 #ifdef LOADENV
        .load           = env_flash_load,
 #endif
index 966f6206538510fbf2351157e5d912cee979967e..18da6dc58c88e90695f685e9ccd280f4218bb626 100644 (file)
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -23,8 +23,6 @@
 #error CONFIG_ENV_SIZE_REDUND should be the same as CONFIG_ENV_SIZE
 #endif
 
-char *env_name_spec = "MMC";
-
 #ifdef ENV_IS_EMBEDDED
 env_t *env_ptr = &environment;
 #else /* ! ENV_IS_EMBEDDED */
@@ -318,6 +316,7 @@ err:
 
 U_BOOT_ENV_LOCATION(mmc) = {
        .location       = ENVL_MMC,
+       ENV_NAME("MMC")
        .load           = env_mmc_load,
 #ifndef CONFIG_SPL_BUILD
        .save           = env_save_ptr(env_mmc_save),
index 596bdd3980eaea64a28363b697cd0a9346efc303..e74a8c674e2cc4958109830459051904bed9f4d6 100644 (file)
@@ -40,8 +40,6 @@
 #define CONFIG_ENV_RANGE       CONFIG_ENV_SIZE
 #endif
 
-char *env_name_spec = "NAND";
-
 #if defined(ENV_IS_EMBEDDED)
 env_t *env_ptr = &environment;
 #elif defined(CONFIG_NAND_ENV_DST)
@@ -398,6 +396,7 @@ static void env_nand_load(void)
 
 U_BOOT_ENV_LOCATION(nand) = {
        .location       = ENVL_NAND,
+       ENV_NAME("NAND")
        .load           = env_nand_load,
 #if defined(CMD_SAVEENV)
        .save           = env_save_ptr(env_nand_save),
index 1d2ae85a57e0317cc76a20b9a9b6da6b29620573..1a17d6978b90026525445fe9dbd6f55aaca47dd9 100644 (file)
@@ -19,4 +19,5 @@ env_t *env_ptr;
 
 U_BOOT_ENV_LOCATION(nowhere) = {
        .location       = ENVL_NOWHERE,
+       ENV_NAME("nowhere")
 };
index 09091b8eb7ec29b7d1eb828496fe0936e0678ff6..0f4b491fd3b688868d21fcae80a918565fcbda37 100644 (file)
@@ -41,8 +41,6 @@ env_t *env_ptr;
 env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
 #endif
 
-char *env_name_spec = "NVRAM";
-
 #ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE
 static uchar env_nvram_get_char(int index)
 {
@@ -115,6 +113,7 @@ static int env_nvram_init(void)
 
 U_BOOT_ENV_LOCATION(nvram) = {
        .location       = ENVL_NVRAM,
+       ENV_NAME("NVRAM")
 #ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE
        .get_char       = env_nvram_get_char,
 #endif
index cb1ab53216c319348e272315761ef0f18a97042e..319f553262db4945ef19ccc7642b0a82bbdbd75f 100644 (file)
@@ -21,8 +21,6 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/onenand.h>
 
-char *env_name_spec = "OneNAND";
-
 #define ONENAND_MAX_ENV_SIZE   CONFIG_ENV_SIZE
 #define ONENAND_ENV_SIZE(mtd)  (ONENAND_MAX_ENV_SIZE - ENV_HEADER_SIZE)
 
@@ -108,6 +106,7 @@ static int env_onenand_save(void)
 
 U_BOOT_ENV_LOCATION(onenand) = {
        .location       = ENVL_ONENAND,
+       ENV_NAME("OneNAND")
        .load           = env_onenand_load,
        .save           = env_save_ptr(env_onenand_save),
 };
index c5dce5b9662cb5af1647836745020b0560568561..0d8865bd67777bf8b5b7fe9df08a7f7cf6a45c26 100644 (file)
@@ -11,8 +11,6 @@
 #include <environment.h>
 #include <linux/stddef.h>
 
-char *env_name_spec = "Remote";
-
 #ifdef ENV_IS_EMBEDDED
 env_t *env_ptr = &environment;
 #else /* ! ENV_IS_EMBEDDED */
@@ -57,6 +55,7 @@ static void env_remote_load(void)
 
 U_BOOT_ENV_LOCATION(remote) = {
        .location       = ENVL_REMOTE,
+       ENV_NAME("Remote")
        .load           = env_remote_load,
        .save           = env_save_ptr(env_remote_save),
        .init           = env_remote_init,
index a5ff54c287956bb64ab2b7dcc3e84e54a1f08d41..16d8f939db6ccd3cdbaef5711d2812ac226dd4ce 100644 (file)
@@ -24,8 +24,6 @@
 #error CONFIG_ENV_OFFSET or CONFIG_ENV_SIZE not defined
 #endif
 
-char *env_name_spec = "SATA";
-
 DECLARE_GLOBAL_DATA_PTR;
 
 __weak int sata_get_env_dev(void)
@@ -119,6 +117,7 @@ static void env_sata_load(void)
 
 U_BOOT_ENV_LOCATION(sata) = {
        .location       = ENVL_ESATA,
+       ENV_NAME("SATA")
        .load           = env_sata_load,
        .save           = env_save_ptr(env_sata_save),
 };
index a07641b7d4973f5c35d9afec81f7a03a7447409d..07386c629ae22261dd32adf75911868f41374397 100644 (file)
--- a/env/sf.c
+++ b/env/sf.c
@@ -48,8 +48,6 @@ static ulong env_new_offset   = CONFIG_ENV_OFFSET_REDUND;
 
 DECLARE_GLOBAL_DATA_PTR;
 
-char *env_name_spec = "SPI Flash";
-
 static struct spi_flash *env_flash;
 
 static int setup_flash_device(void)
@@ -346,6 +344,7 @@ out:
 
 U_BOOT_ENV_LOCATION(sf) = {
        .location       = ENVL_SPI_FLASH,
+       ENV_NAME("SPI Flash")
        .load           = env_sf_load,
 #ifdef CMD_SAVEENV
        .save           = env_save_ptr(env_sf_save),
index 4811f97413821222f2e504e92d84f42c9b9dc270..4d5ae1343defe9bccf1f9b00fc0dfc83296b1868 100644 (file)
--- a/env/ubi.c
+++ b/env/ubi.c
@@ -16,8 +16,6 @@
 #include <ubi_uboot.h>
 #undef crc32
 
-char *env_name_spec = "UBI";
-
 env_t *env_ptr;
 
 DECLARE_GLOBAL_DATA_PTR;
index 7eaba72181e3d694df3879298740b18f28bbbbe9..584fd7216d2e05d25d29a391ac802b69cab9e0c4 100644 (file)
@@ -143,10 +143,6 @@ extern unsigned long nand_env_oob_offset;
 # define ENV_HEADER_SIZE       (sizeof(uint32_t))
 #endif
 
-#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
-extern char *env_name_spec;
-#endif
-
 #ifdef CONFIG_ENV_AES
 /* Make sure the payload is multiple of AES block size */
 #define ENV_SIZE ((CONFIG_ENV_SIZE - ENV_HEADER_SIZE) & ~(16 - 1))
@@ -224,6 +220,7 @@ enum env_location {
 };
 
 struct env_driver {
+       const char *name;
        enum env_location location;
 
        /**
@@ -269,6 +266,13 @@ struct env_driver {
 #define U_BOOT_ENV_LOCATION(__name)                                    \
        ll_entry_declare(struct env_driver, __name, env_driver)
 
+/* Declare the name of a location */
+#ifdef CONFIG_CMD_SAVEENV
+#define ENV_NAME(_name) .name = _name,
+#else
+#define ENV_NAME(_name)
+#endif
+
 #ifdef CONFIG_CMD_SAVEENV
 #define env_save_ptr(x) x
 #else
@@ -303,6 +307,13 @@ int env_export(env_t *env_out);
 int env_import_redund(const char *buf1, const char *buf2);
 #endif
 
+/**
+ * env_driver_lookup_default() - Look up the default environment driver
+ *
+ * @return pointer to driver, or NULL if none (which should not happen)
+ */
+struct env_driver *env_driver_lookup_default(void);
+
 #endif /* DO_DEPS_ONLY */
 
 #endif /* _ENVIRONMENT_H_ */