All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 24/34] env: Drop common init() functions
Date: Sun, 23 Jul 2017 21:19:59 -0600	[thread overview]
Message-ID: <20170724032009.43994-25-sjg@chromium.org> (raw)
In-Reply-To: <20170724032009.43994-1-sjg@chromium.org>

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>
---

Changes in v2: None

 env/dataflash.c       | 16 ----------------
 env/eeprom.c          | 14 --------------
 env/env.c             | 14 +++++++++-----
 env/ext4.c            | 10 ----------
 env/fat.c             | 10 ----------
 env/mmc.c             | 10 ----------
 env/nowhere.c         | 19 -------------------
 env/onenand.c         | 10 ----------
 env/remote.c          |  4 +---
 env/sata.c            | 10 ----------
 env/sf.c              | 10 ----------
 env/ubi.c             | 10 ----------
 include/environment.h |  3 ++-
 13 files changed, 12 insertions(+), 128 deletions(-)

diff --git a/env/dataflash.c b/env/dataflash.c
index 6d95d6409b..8ab482b3b4 100644
--- a/env/dataflash.c
+++ b/env/dataflash.c
@@ -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,
 };
diff --git a/env/eeprom.c b/env/eeprom.c
index eb69f75f7b..3cc412620a 100644
--- a/env/eeprom.c
+++ b/env/eeprom.c
@@ -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,
 };
diff --git a/env/env.c b/env/env.c
index 608ab7bb39..73547002d1 100644
--- 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 = -ENOSYS;
 
 	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 = ENV_VALID;
+
+		return 0;
+	} else if (ret) {
 		debug("%s: Environment failed to init (err=%d)\n", __func__,
 		      ret);
 		return ret;
diff --git a/env/ext4.c b/env/ext4.c
index aa69219021..25a5cbecdd 100644
--- a/env/ext4.c
+++ b/env/ext4.c
@@ -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,
 };
diff --git a/env/fat.c b/env/fat.c
index f7abfdb952..bd31b2904d 100644
--- 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,
 };
diff --git a/env/mmc.c b/env/mmc.c
index 2bdeeb7dc6..2dd0382bfb 100644
--- 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)
 {
@@ -361,5 +352,4 @@ U_BOOT_ENV_LOCATION(mmc) = {
 #ifndef CONFIG_SPL_BUILD
 	.save		= env_save_ptr(env_mmc_save),
 #endif
-	.init		= env_mmc_init,
 };
diff --git a/env/nowhere.c b/env/nowhere.c
index 6a67ab09ff..1d2ae85a57 100644
--- a/env/nowhere.c
+++ b/env/nowhere.c
@@ -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,
 };
diff --git a/env/onenand.c b/env/onenand.c
index f72aa4b036..cb1ab53216 100644
--- a/env/onenand.c
+++ b/env/onenand.c
@@ -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,
 };
diff --git a/env/remote.c b/env/remote.c
index 0324cba099..c5dce5b966 100644
--- a/env/remote.c
+++ b/env/remote.c
@@ -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
diff --git a/env/sata.c b/env/sata.c
index 6f9099873d..a5ff54c287 100644
--- a/env/sata.c
+++ b/env/sata.c
@@ -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,
 };
diff --git a/env/sf.c b/env/sf.c
index 82babaab67..a07641b7d4 100644
--- 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,
 };
diff --git a/env/ubi.c b/env/ubi.c
index 82a9c3bd03..773fcf0ed2 100644
--- 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 unsigned char env_flags;
@@ -217,5 +208,4 @@ U_BOOT_ENV_LOCATION(ubi) = {
 	.location	= ENVL_UBI,
 	.load		= env_ubi_load,
 	.save		= env_save_ptr(env_ubi_save),
-	.init		= env_ubi_init,
 };
diff --git a/include/environment.h b/include/environment.h
index c3a75c8a66..87727f2b29 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -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);
 };
-- 
2.14.0.rc0.284.gd933b75aa4-goog

  parent reply	other threads:[~2017-07-24  3:19 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-24  3:19 [U-Boot] [PATCH v2 00/34] env: Move environment code to use location drivers Simon Glass
2017-07-24  3:19 ` [U-Boot] [PATCH v2 01/34] configs: Resync with savedefconfig Simon Glass
2017-07-24  3:19 ` [U-Boot] [PATCH v2 02/34] Makefile: Rename 'env' target to 'environ' Simon Glass
2017-07-26 16:13   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 03/34] Move environment files from common/ to env/ Simon Glass
2017-07-26 16:13   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 04/34] Convert CONFIG_ENV_IS_IN_MMC et al to Kconfig Simon Glass
2017-07-26  1:36   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 05/34] env: Move help from README " Simon Glass
2017-07-26  1:36   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 06/34] Convert CONFIG_ENV_IS_IN_FLASH " Simon Glass
2017-07-26  1:36   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 07/34] Convert CONFIG_ENV_IS_IN_NVRAM " Simon Glass
2017-07-26  1:36   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 08/34] Convert CONFIG_ENV_IS_IN_EEPROM " Simon Glass
2017-07-26  1:36   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 09/34] Convert CONFIG_ENV_IS_IN_DATAFLASH " Simon Glass
2017-07-26  1:36   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 10/34] Convert CONFIG_ENV_IS_IN_SPI_FLASH " Simon Glass
2017-07-26  1:36   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 11/34] Convert CONFIG_ENV_IS_IN_REMOTE " Simon Glass
2017-07-26  1:36   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 12/34] Convert CONFIG_ENV_IS_IN_FAT " Simon Glass
2017-07-26  1:36   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 13/34] Convert CONFIG_ENV_IS_IN_ONENAND " Simon Glass
2017-07-26  1:36   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 14/34] env: common: Make env_get_addr/get_char_memory() static Simon Glass
2017-07-26 16:13   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 15/34] env: common: Drop env_get_addr() Simon Glass
2017-07-26 16:13   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 16/34] env: common: Factor out the common env_valid check Simon Glass
2017-07-26 16:13   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 17/34] env: common: Drop env_get_char_init() Simon Glass
2017-07-26 16:14   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 18/34] env: common: Drop env_get_char_memory() Simon Glass
2017-07-26 16:14   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 19/34] env: Add an enum for environment state Simon Glass
2017-07-26 16:14   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 20/34] env: Rename nand env_location to nand_env_location Simon Glass
2017-07-26 16:14   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 21/34] env: Create a location driver for each location Simon Glass
2017-07-26 16:02   ` Tom Rini
2017-07-24  3:19 ` [U-Boot] [PATCH v2 22/34] env: Add a new implementation of environment access Simon Glass
2017-07-26 16:04   ` Tom Rini
2017-07-26 16:32     ` Simon Glass
2017-07-26 17:23       ` Tom Rini
2017-07-26 18:02         ` Simon Glass
2017-07-26 20:13           ` Tom Rini
2017-08-01  9:49             ` Simon Glass
2017-07-24  3:19 ` [U-Boot] [PATCH v2 23/34] env: Switch over to use environment location drivers Simon Glass
2017-07-26 16:14   ` Tom Rini
2017-07-24  3:19 ` Simon Glass [this message]
2017-07-26 16:14   ` [U-Boot] [PATCH v2 24/34] env: Drop common init() functions Tom Rini
2017-07-24  3:20 ` [U-Boot] [PATCH v2 25/34] env: Drop the env_name_spec global Simon Glass
2017-07-26 16:14   ` Tom Rini
2017-07-24  3:20 ` [U-Boot] [PATCH v2 26/34] env: Drop unused env_ptr variables Simon Glass
2017-07-26 16:14   ` Tom Rini
2017-07-24  3:20 ` [U-Boot] [PATCH v2 27/34] env: Drop env_init_new() Simon Glass
2017-07-26 16:14   ` Tom Rini
2017-07-24  3:20 ` [U-Boot] [PATCH v2 28/34] env: Drop env_get_char_spec() Simon Glass
2017-07-26 16:15   ` Tom Rini
2017-07-24  3:20 ` [U-Boot] [PATCH v2 29/34] env: Drop env_relocate_spec() in favour of env_load() Simon Glass
2017-07-26 16:15   ` Tom Rini
2017-07-24  3:20 ` [U-Boot] [PATCH v2 30/34] env: Drop saveenv() in favour of env_save() Simon Glass
2017-07-26 16:15   ` Tom Rini
2017-07-24  3:20 ` [U-Boot] [PATCH v2 31/34] env: Rename setenv() and friends to env_set() Simon Glass
2017-07-26 16:11   ` Tom Rini
2017-07-26 16:28     ` Simon Glass
2017-07-26 17:29       ` Tom Rini
2017-07-26 17:43         ` Tom Rini
2017-07-26 18:34           ` Simon Glass
2017-07-26 20:14             ` Tom Rini
2017-07-24  3:20 ` [U-Boot] [PATCH v2 32/34] env: Rename getenv() and friends to env_get() Simon Glass
2017-07-26 16:12   ` Tom Rini
2017-07-24  3:20 ` [U-Boot] [PATCH v2 33/34] env: Adjust the get_char() method to return an int Simon Glass
2017-07-26 16:15   ` Tom Rini
2017-07-24  3:20 ` [U-Boot] [PATCH v2 34/34] env: Adjust the load() method to return an error Simon Glass
2017-07-26 16:15   ` Tom Rini
2017-07-25 17:49 ` [U-Boot] [PATCH v2 00/34] env: Move environment code to use location drivers Tom Rini
2017-07-25 21:40   ` Simon Glass
2017-07-25 21:47     ` Tom Rini
2017-07-26  4:51 ` Masahiro Yamada
2017-07-28  3:40   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170724032009.43994-25-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.