public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] env: env_sf: don't set .init op if not needed
@ 2020-11-01 13:38 Michael Walle
  2020-11-02  7:00 ` Heiko Schocher
  0 siblings, 1 reply; 14+ messages in thread
From: Michael Walle @ 2020-11-01 13:38 UTC (permalink / raw)
  To: u-boot

Commit 92765f45bb95 ("env: Access Environment in SPI flashes before
relocation") at least breaks the Kontron sl28 board. I guess it also
breaks others which use a (late) SPI environment.

Unfortunately, we cannot set the .init op and fall back to the same
behavior as it would be unset. Thus guard the .init op by #if's.

Fixes: 92765f45bb95 ("env: Access Environment in SPI flashes before relocation")
Signed-off-by: Michael Walle <michael@walle.cc>
---
 env/sf.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/env/sf.c b/env/sf.c
index 2eb2de1a4e..18d44a7ddc 100644
--- a/env/sf.c
+++ b/env/sf.c
@@ -385,7 +385,7 @@ out:
 }
 #endif
 
-static int env_sf_init(void)
+static int __maybe_unused env_sf_init(void)
 {
 #if defined(INITENV) && (CONFIG_ENV_ADDR != 0x0)
 	return env_sf_init_addr();
@@ -393,8 +393,13 @@ static int env_sf_init(void)
 	return env_sf_init_early();
 #endif
 	/*
-	 * we must return with 0 if there is nothing done,
-	 * else env_set_inited() get not called in env_init()
+	 * We shouldn't end up here. Unfortunately, there is no
+	 * way to return a value which yields the same behavior
+	 * as if the .init op wouldn't be set at all. See
+	 * env_init(); env_set_inited() is only called if we
+	 * return 0, but the default environment is only loaded
+	 * if -ENOENT is returned. Therefore, we need the ugly
+	 * ifdeferry for the .init op.
 	 */
 	return 0;
 }
@@ -404,5 +409,7 @@ U_BOOT_ENV_LOCATION(sf) = {
 	ENV_NAME("SPIFlash")
 	.load		= env_sf_load,
 	.save		= CONFIG_IS_ENABLED(SAVEENV) ? ENV_SAVE_PTR(env_sf_save) : NULL,
+#if (defined(INITENV) && (CONFIG_ENV_ADDR != 0x0)) || defined(CONFIG_ENV_SPI_EARLY)
 	.init		= env_sf_init,
+#endif
 };
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-11-08 13:25 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-01 13:38 [PATCH] env: env_sf: don't set .init op if not needed Michael Walle
2020-11-02  7:00 ` Heiko Schocher
2020-11-02 12:51   ` Wolfgang Denk
2020-11-03  5:15     ` Heiko Schocher
2020-11-03  7:52       ` Wolfgang Denk
2020-11-03  9:42         ` Rasmus Villemoes
2020-11-05 16:40           ` Wolfgang Denk
2020-11-06  7:46             ` Rasmus Villemoes
2020-11-06 20:45               ` Tom Rini
2020-11-08 13:25                 ` Wolfgang Denk
2020-11-08 13:22               ` Wolfgang Denk
2020-11-02 20:15   ` Michael Walle
2020-11-03  4:40     ` Heiko Schocher
2020-11-03 12:30       ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox