summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAndreas Fenkart <afenkart@gmail.com>2017-04-08 09:59:31 (GMT)
committerJagan Teki <jagan@openedev.com>2017-05-03 05:47:10 (GMT)
commitafa81a7750d63be9cb9eeb99a26c73bc93f4e1d9 (patch)
treeeefee7f37e0abb62b92dc70ea4318aae05c02c7e /common
parentac6991fb5fc1a694b29f4ebd5e07baebf818d7cc (diff)
downloadu-boot-afa81a7750d63be9cb9eeb99a26c73bc93f4e1d9.tar.xz
env_sf: factor out prepare_flash_device
copy&paste code found in single/double buffered code path Signed-off-by: Andreas Fenkart <afenkart@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Jagan Teki <jagan@openedev.com> Tested-by: Jagan Teki <jagan@openedev.com>
Diffstat (limited to 'common')
-rw-r--r--common/env_sf.c48
1 files changed, 19 insertions, 29 deletions
diff --git a/common/env_sf.c b/common/env_sf.c
index 27b4d12..8af590a 100644
--- a/common/env_sf.c
+++ b/common/env_sf.c
@@ -45,15 +45,11 @@ char *env_name_spec = "SPI Flash";
static struct spi_flash *env_flash;
-#if defined(CONFIG_ENV_OFFSET_REDUND)
-int saveenv(void)
+static int setup_flash_device(void)
{
- env_t env_new;
- char *saved_buffer = NULL, flag = OBSOLETE_FLAG;
- u32 saved_size, saved_offset, sector = 1;
- int ret;
#ifdef CONFIG_DM_SPI_FLASH
struct udevice *new;
+ int ret;
/* speed and mode will be read from DT */
ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
@@ -76,6 +72,20 @@ int saveenv(void)
}
}
#endif
+ return 0;
+}
+
+#if defined(CONFIG_ENV_OFFSET_REDUND)
+int saveenv(void)
+{
+ env_t env_new;
+ char *saved_buffer = NULL, flag = OBSOLETE_FLAG;
+ u32 saved_size, saved_offset, sector = 1;
+ int ret;
+
+ ret = setup_flash_device();
+ if (ret)
+ return ret;
ret = env_export(&env_new);
if (ret)
@@ -242,30 +252,10 @@ int saveenv(void)
char *saved_buffer = NULL;
int ret = 1;
env_t env_new;
-#ifdef CONFIG_DM_SPI_FLASH
- struct udevice *new;
- /* speed and mode will be read from DT */
- ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
- 0, 0, &new);
- if (ret) {
- set_default_env("!spi_flash_probe_bus_cs() failed");
- return 1;
- }
-
- env_flash = dev_get_uclass_priv(new);
-#else
-
- if (!env_flash) {
- env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS,
- CONFIG_ENV_SPI_CS,
- CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
- if (!env_flash) {
- set_default_env("!spi_flash_probe() failed");
- return 1;
- }
- }
-#endif
+ ret = setup_flash_device();
+ if (ret)
+ return ret;
/* Is the sector larger than the env (i.e. embedded) */
if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {