env: Drop common init() functions
authorSimon Glass <sjg@chromium.org>
Thu, 3 Aug 2017 18:22:02 +0000 (12:22 -0600)
committerTom Rini <trini@konsulko.com>
Wed, 16 Aug 2017 00:50:27 +0000 (20:50 -0400)
Most of the init() implementations just use the default environment.
Adjust env_init_new() to do this automatically, and drop the redundant
code.

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

index 6d95d6409bd3c0d2d43810c8688a91fac0218c98..8ab482b3b406fd1ef99e20dcea51df4d36cf2894 100644 (file)
@@ -68,25 +68,9 @@ static int env_dataflash_save(void)
                                CONFIG_ENV_SIZE);
 }
 
-/*
- * Initialize environment use
- *
- * We are still running from ROM, so data use is limited.
- * Use a (moderately small) buffer on the stack
- */
-int env_dataflash_init(void)
-{
-       /* use default */
-       gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = ENV_VALID;
-
-       return 0;
-}
-
 U_BOOT_ENV_LOCATION(dataflash) = {
        .location       = ENVL_DATAFLASH,
        .get_char       = env_dataflash_get_char,
        .load           = env_dataflash_load,
        .save           = env_save_ptr(env_dataflash_save),
-       .init           = env_dataflash_init,
 };
index eb69f75f7b1bd9a1a32599f5437d2a0d4f4f5454..3cc412620acdc998de87cc50c450bddbe5181d01 100644 (file)
@@ -231,23 +231,9 @@ static int env_eeprom_save(void)
        return rc;
 }
 
-/*
- * Initialize Environment use
- *
- * We are still running from ROM, so data use is limited.
- * Use a (moderately small) buffer on the stack
- */
-static int env_eeprom_init(void)
-{
-       gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = ENV_VALID;
-       return 0;
-}
-
 U_BOOT_ENV_LOCATION(eeprom) = {
        .location       = ENVL_EEPROM,
        .get_char       = env_eeprom_get_char,
        .load           = env_eeprom_load,
        .save           = env_save_ptr(env_eeprom_save),
-       .init           = env_eeprom_init,
 };
index d327f9cdfffdbb20b20889a5e6f9867f29ff0edf..12cd4750df49b56c29d644f92e19bfe778d9f982 100644 (file)
--- a/env/env.c
+++ b/env/env.c
@@ -128,14 +128,18 @@ int env_save(void)
 int env_init_new(void)
 {
        struct env_driver *drv = env_driver_lookup_default();
-       int ret;
+       int ret = -ENOENT;
 
        if (!drv)
                return -ENODEV;
-       if (!drv->init)
-               return -ENOSYS;
-       ret = drv->init();
-       if (ret) {
+       if (drv->init)
+               ret = drv->init();
+       if (ret == -ENOENT) {
+               gd->env_addr = (ulong)&default_environment[0];
+               gd->env_valid = 0;
+
+               return 0;
+       } else if (ret) {
                debug("%s: Environment failed to init (err=%d)\n", __func__,
                      ret);
                return ret;
index aa69219021c3aa45343e71a839fe1436d2c07389..25a5cbecdd0060d5b61e0c2ec77c77813da8163e 100644 (file)
@@ -37,15 +37,6 @@ env_t *env_ptr;
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static int env_ext4_init(void)
-{
-       /* use default */
-       gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = ENV_VALID;
-
-       return 0;
-}
-
 #ifdef CONFIG_CMD_SAVEENV
 static int env_ext4_save(void)
 {
@@ -132,5 +123,4 @@ U_BOOT_ENV_LOCATION(ext4) = {
        .location       = ENVL_EXT4,
        .load           = env_ext4_load,
        .save           = env_save_ptr(env_ext4_save),
-       .init           = env_ext4_init,
 };
index b959013a88feb20feefffc11e1050a706f72bbb2..1ff3d9dc865fd397540936ccf2fe383e57995886 100644 (file)
--- a/env/fat.c
+++ b/env/fat.c
@@ -37,15 +37,6 @@ env_t *env_ptr;
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static int env_fat_init(void)
-{
-       /* use default */
-       gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = ENV_VALID;
-
-       return 0;
-}
-
 #ifdef CMD_SAVEENV
 static int env_fat_save(void)
 {
@@ -131,5 +122,4 @@ U_BOOT_ENV_LOCATION(fat) = {
 #ifdef CMD_SAVEENV
        .save           = env_save_ptr(env_fat_save),
 #endif
-       .init           = env_fat_init,
 };
index d63feea2b823cb8f5215b4d4907d6e3d5ff0022a..966f6206538510fbf2351157e5d912cee979967e 100644 (file)
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -82,15 +82,6 @@ __weak int mmc_get_env_dev(void)
        return CONFIG_SYS_MMC_ENV_DEV;
 }
 
-static int env_mmc_init(void)
-{
-       /* use default */
-       gd->env_addr    = (ulong)&default_environment[0];
-       gd->env_valid   = ENV_VALID;
-
-       return 0;
-}
-
 #ifdef CONFIG_SYS_MMC_ENV_PART
 __weak uint mmc_get_env_part(struct mmc *mmc)
 {
@@ -331,5 +322,4 @@ U_BOOT_ENV_LOCATION(mmc) = {
 #ifndef CONFIG_SPL_BUILD
        .save           = env_save_ptr(env_mmc_save),
 #endif
-       .init           = env_mmc_init,
 };
index 6a67ab09ff624320bd55d1be96699e425f0a43c8..1d2ae85a57e0317cc76a20b9a9b6da6b29620573 100644 (file)
@@ -17,25 +17,6 @@ DECLARE_GLOBAL_DATA_PTR;
 
 env_t *env_ptr;
 
-static void env_nowhere_load(void)
-{
-}
-
-/*
- * Initialize Environment use
- *
- * We are still running from ROM, so data use is limited
- */
-static int env_nowhere_init(void)
-{
-       gd->env_addr    = (ulong)&default_environment[0];
-       gd->env_valid   = 0;
-
-       return 0;
-}
-
 U_BOOT_ENV_LOCATION(nowhere) = {
        .location       = ENVL_NOWHERE,
-       .load           = env_nowhere_load,
-       .init           = env_nowhere_init,
 };
index f72aa4b0365b03269a39fbe3f3c53c419ad3e69f..cb1ab53216c319348e272315761ef0f18a97042e 100644 (file)
@@ -106,18 +106,8 @@ static int env_onenand_save(void)
        return 0;
 }
 
-static int env_onenand_init(void)
-{
-       /* use default */
-       gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = ENV_VALID;
-
-       return 0;
-}
-
 U_BOOT_ENV_LOCATION(onenand) = {
        .location       = ENVL_ONENAND,
        .load           = env_onenand_load,
        .save           = env_save_ptr(env_onenand_save),
-       .init           = env_onenand_init,
 };
index 0324cba099b6703696d522d174e243681e316547..c5dce5b9662cb5af1647836745020b0560568561 100644 (file)
@@ -33,9 +33,7 @@ static int env_remote_init(void)
                return 0;
        }
 
-       gd->env_addr = (ulong)default_environment;
-       gd->env_valid = 0;
-       return 0;
+       return -ENOENT;
 }
 
 #ifdef CONFIG_CMD_SAVEENV
index 6f9099873d9a5afe1fe69886a77ef1a1de0cf10e..a5ff54c287956bb64ab2b7dcc3e84e54a1f08d41 100644 (file)
@@ -33,15 +33,6 @@ __weak int sata_get_env_dev(void)
        return CONFIG_SYS_SATA_ENV_DEV;
 }
 
-static int env_sata_init(void)
-{
-       /* use default */
-       gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = ENV_VALID;
-
-       return 0;
-}
-
 #ifdef CONFIG_CMD_SAVEENV
 static inline int write_env(struct blk_desc *sata, unsigned long size,
                            unsigned long offset, void *buffer)
@@ -130,5 +121,4 @@ U_BOOT_ENV_LOCATION(sata) = {
        .location       = ENVL_ESATA,
        .load           = env_sata_load,
        .save           = env_save_ptr(env_sata_save),
-       .init           = env_sata_init,
 };
index 82babaab67c466c4dd031bec052d3557e1406df9..a07641b7d4973f5c35d9afec81f7a03a7447409d 100644 (file)
--- a/env/sf.c
+++ b/env/sf.c
@@ -344,20 +344,10 @@ out:
 }
 #endif
 
-static int env_sf_init(void)
-{
-       /* SPI flash isn't usable before relocation */
-       gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = ENV_VALID;
-
-       return 0;
-}
-
 U_BOOT_ENV_LOCATION(sf) = {
        .location       = ENVL_SPI_FLASH,
        .load           = env_sf_load,
 #ifdef CMD_SAVEENV
        .save           = env_save_ptr(env_sf_save),
 #endif
-       .init           = env_sf_init,
 };
index 3b6344df7a365ac1f0c0c6d01bbd732149bbfb7e..4811f97413821222f2e504e92d84f42c9b9dc270 100644 (file)
--- a/env/ubi.c
+++ b/env/ubi.c
@@ -22,15 +22,6 @@ env_t *env_ptr;
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static int env_ubi_init(void)
-{
-       /* use default */
-       gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = ENV_VALID;
-
-       return 0;
-}
-
 #ifdef CONFIG_CMD_SAVEENV
 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
 static int env_ubi_save(void)
@@ -182,5 +173,4 @@ U_BOOT_ENV_LOCATION(ubi) = {
        .location       = ENVL_UBI,
        .load           = env_ubi_load,
        .save           = env_save_ptr(env_ubi_save),
-       .init           = env_ubi_init,
 };
index ff3f54263a61b1c2b3221da7a29f97bc76cc9341..7eaba72181e3d694df3879298740b18f28bbbbe9 100644 (file)
@@ -259,7 +259,8 @@ struct env_driver {
         *
         * This method is optional.
         *
-        * @return 0 if OK, -ve on error
+        * @return 0 if OK, -ENOENT if no initial environment could be found,
+        * other -ve on error
         */
        int (*init)(void);
 };