From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3143BC433EF for ; Wed, 2 Mar 2022 11:50:18 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E7C4B83CC6; Wed, 2 Mar 2022 12:49:54 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="gVXiw0yF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D671C83C8F; Wed, 2 Mar 2022 12:49:44 +0100 (CET) Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id ABBB783C7F for ; Wed, 2 Mar 2022 12:49:35 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E548AB81F71; Wed, 2 Mar 2022 11:49:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 595D1C340E9; Wed, 2 Mar 2022 11:49:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646221773; bh=STQYuZY7dmL7apQwec6Ocs4Kne6prSePk7O9AdHrm58=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gVXiw0yFTV8OkqZ+UztstROL141x5VL10UOoiPTBiWpgksL1eX4EGUriVEQjWer70 qGHD/VhvhdQn6Nb1cmRIkEuUbQf/3O9kOGmREdjf9dSEdriZCzVSw0h9dpWPP38fkw LIF1ShuBtUeVjSN7RdKFFjmWCd89OiYYGMiEfPWR6hUETEjC4koU4BITXyMjAyEcQo FJm/eBXvdcx2iZ664S0ct59zblxH6adKVSMdIl5EMngVd/hOxUK0aNdIHpCAMSVHtq BdL+rG8Xt3aiOBD3qZZ6TWBy9Kw/JlPngAj32bYZ5cyN3nTIQFIvb6GCDYehQ8mf8n xBmUPYHAONOug== Received: by pali.im (Postfix) id A7B1195D; Wed, 2 Mar 2022 12:49:30 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Stefan Roese , =?UTF-8?q?Marek=20Beh=C3=BAn?= 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 Message-Id: <20220302114758.21787-2-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220302114758.21787-1-pali@kernel.org> References: <20220302114758.21787-1-pali@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean 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 --- 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 #include -#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