From: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/4] env_sf: factor out prepare_flash_device
Date: Mon, 28 Nov 2016 11:01:14 +0100 [thread overview]
Message-ID: <20161128100117.5237-2-andreas.fenkart@digitalstrom.com> (raw)
In-Reply-To: <20161128100117.5237-1-andreas.fenkart@digitalstrom.com>
copy&paste code found in single/double buffered code path
Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
---
common/env_sf.c | 47 ++++++++++++++++++-----------------------------
1 file changed, 18 insertions(+), 29 deletions(-)
diff --git a/common/env_sf.c b/common/env_sf.c
index c53200f..5126762 100644
--- a/common/env_sf.c
+++ b/common/env_sf.c
@@ -45,13 +45,8 @@ 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;
@@ -76,6 +71,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 +251,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) {
--
2.10.1
next prev parent reply other threads:[~2016-11-28 10:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-28 10:01 [U-Boot] [PATCH 0/4] env_sf: minor cleanup Andreas Fenkart
2016-11-28 10:01 ` Andreas Fenkart [this message]
2016-11-30 0:34 ` [U-Boot] [PATCH 1/4] env_sf: factor out prepare_flash_device Simon Glass
2016-12-02 20:03 ` [U-Boot] [U-Boot,1/4] " Tom Rini
2016-11-28 10:01 ` [U-Boot] [PATCH 2/4] enf_sf: reuse setup_flash_device instead of open coding it Andreas Fenkart
2016-11-28 10:01 ` [U-Boot] [PATCH 3/4] env_sf: re-order error handling in single-buffer env_relocate_spec Andreas Fenkart
2016-11-30 0:34 ` Simon Glass
2016-11-28 10:01 ` [U-Boot] [PATCH 4/4] env_sf: use DIV_ROUND_UP to calculate number of sectors to erase Andreas Fenkart
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=20161128100117.5237-2-andreas.fenkart@digitalstrom.com \
--to=andreas.fenkart@digitalstrom.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox