public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: "Stefan Roese" <sr@denx.de>, "Marek Behún" <marek.behun@nic.cz>
Cc: u-boot@lists.denx.de
Subject: [PATCH u-boot-marvell 1/8] env: sf: Allow to use env_sf_init_addr() at any stage
Date: Wed,  2 Mar 2022 12:47:51 +0100	[thread overview]
Message-ID: <20220302114758.21787-2-pali@kernel.org> (raw)
In-Reply-To: <20220302114758.21787-1-pali@kernel.org>

In some cases it makes sense to use env_sf_init_addr() also in SPL mode.
Allow it for boards by providing custom implementation of weak function
env_sf_get_env_addr(). When this function returns NULL it signals that
address is invalid, like config option CONFIG_ENV_ADDR.

There is no change in default behavior or in config options.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 env/sf.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/env/sf.c b/env/sf.c
index 6a4bb756f006..d2c07cd71687 100644
--- a/env/sf.c
+++ b/env/sf.c
@@ -24,10 +24,6 @@
 #include <dm/device-internal.h>
 #include <u-boot/crc.h>
 
-#ifndef CONFIG_SPL_BUILD
-#define INITENV
-#endif
-
 #define	OFFSET_INVALID		(~(u32)0)
 
 #ifdef CONFIG_ENV_OFFSET_REDUND
@@ -322,14 +318,15 @@ done:
 	return ret;
 }
 
-#if CONFIG_ENV_ADDR != 0x0
 __weak void *env_sf_get_env_addr(void)
 {
+#ifndef CONFIG_SPL_BUILD
 	return (void *)CONFIG_ENV_ADDR;
-}
+#else
+	return NULL;
 #endif
+}
 
-#if defined(INITENV) && (CONFIG_ENV_ADDR != 0x0)
 /*
  * check if Environment on CONFIG_ENV_ADDR is valid.
  */
@@ -337,6 +334,9 @@ static int env_sf_init_addr(void)
 {
 	env_t *env_ptr = (env_t *)env_sf_get_env_addr();
 
+	if (!env_ptr)
+		return -ENOENT;
+
 	if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
 		gd->env_addr = (ulong)&(env_ptr->data);
 		gd->env_valid = ENV_VALID;
@@ -346,7 +346,6 @@ static int env_sf_init_addr(void)
 
 	return 0;
 }
-#endif
 
 #if defined(CONFIG_ENV_SPI_EARLY)
 /*
@@ -432,9 +431,10 @@ out:
 
 static int env_sf_init(void)
 {
-#if defined(INITENV) && (CONFIG_ENV_ADDR != 0x0)
-	return env_sf_init_addr();
-#elif defined(CONFIG_ENV_SPI_EARLY)
+	int ret = env_sf_init_addr();
+	if (ret != -ENOENT)
+		return ret;
+#ifdef CONFIG_ENV_SPI_EARLY
 	return env_sf_init_early();
 #endif
 	/*
-- 
2.20.1


  reply	other threads:[~2022-03-02 11:50 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02 11:47 [PATCH u-boot-marvell 0/8] Turris Omnia: Add support for configuring mSATA and WWAN slots via env variables Pali Rohár
2022-03-02 11:47 ` Pali Rohár [this message]
2022-03-02 11:47 ` [PATCH u-boot-marvell 2/8] arm: mvebu: turris_omnia: Provide env_sf_get_env_addr() function Pali Rohár
2022-03-02 12:37   ` Marek Behún
2022-04-22 11:49     ` Pali Rohár
2022-04-22 12:21       ` Marek Behún
2022-03-02 11:47 ` [PATCH u-boot-marvell 3/8] arm: mvebu: turris_omnia: Enable ENV support in SPL Pali Rohár
2022-03-02 11:47 ` [PATCH u-boot-marvell 4/8] arm: mvebu: turris_omnia: Define only one serdes map variable Pali Rohár
2022-03-02 11:47 ` [PATCH u-boot-marvell 5/8] arm: mvebu: turris_omnia: Allow to configure mSATA slot via env variable Pali Rohár
2022-03-02 12:36   ` Marek Behún
2022-03-02 11:47 ` [PATCH u-boot-marvell 6/8] arm: mvebu: turris_omnia: Extract code for disabling sata/pcie Pali Rohár
2022-03-02 12:38   ` Marek Behún
2022-04-22  9:20     ` Pali Rohár
2022-04-22  9:23       ` Stefan Roese
2022-03-02 11:47 ` [PATCH u-boot-marvell 7/8] arm: mvebu: turris_omnia: Signal error when sata/pcie DT mode Pali Rohár
2022-03-02 11:47 ` [PATCH u-boot-marvell 8/8] arm: mvebu: turris_omnia: Add support for USB3.0 mode in WWAN MiniPCIe slot Pali Rohár
2022-03-02 12:46   ` Marek Behún
2022-04-22 11:47     ` Pali Rohár
2022-04-22 12:20       ` Marek Behún
2022-05-01 14:57 ` [PATCH u-boot-marvell 0/8] Turris Omnia: Add support for configuring mSATA and WWAN slots via env variables Pali Rohár
2022-05-02 15:39 ` Stefan Roese

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=20220302114758.21787-2-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=marek.behun@nic.cz \
    --cc=sr@denx.de \
    --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