From patchwork Tue Feb 9 10:48:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1438258 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector1 header.b=AvpyX2vD; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DZflT5zmBz9sVX for ; Tue, 9 Feb 2021 21:49:09 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D7CB282A1E; Tue, 9 Feb 2021 11:49:02 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com 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=foss.st.com header.i=@foss.st.com header.b="AvpyX2vD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B669882A23; Tue, 9 Feb 2021 11:49:00 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (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 7928882A17 for ; Tue, 9 Feb 2021 11:48:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.delaunay@foss.st.com Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 119AeqaK032143; Tue, 9 Feb 2021 11:48:56 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=nioCG45t5o2xQpmyJ0ku9g5OqDi7ZF/lDUPhE7GbvTw=; b=AvpyX2vDNqQAt5614mEYna3tREO0kLzgessuDVpNjwCMfO8OV7RFADZ1ZNCqX6MljUVH L3e6bnbhNupRco6pi1NiGyF8t1sAojU8zQGTfadSeh3iJnQC+JsKpw8YOBv4KrVtVmJO XsNK4dkj26ESCgkBMWmrvJ0ePjIJhXNxVm6SPI/koeN2mJK6cu9oZIZv82yQmE/K3gdP fsKOljRGAU1TTq8UBbpeuC+Q9Kfs++Ner7j2/sXxfg8VBCXUf84LEVkXLHD0PpnNmBdv vzE45+3/3p01qEciXfakH0eL7NmezFEyo5IJVAZBc+8xzV5H8QORm0vA7zzCBK+mszi6 Fg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 36hr2c7ywk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Feb 2021 11:48:56 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4EFB6100034; Tue, 9 Feb 2021 11:48:56 +0100 (CET) Received: from Webmail-eu.st.com (gpxdag2node6.st.com [10.75.127.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 4296E226F66; Tue, 9 Feb 2021 11:48:56 +0100 (CET) Received: from localhost (10.75.127.122) by GPXDAG2NODE6.st.com (10.75.127.70) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 9 Feb 2021 11:48:55 +0100 From: Patrick Delaunay To: CC: Patrick Delaunay , Joe Hershberger , Wolfgang Denk , U-Boot STM32 Subject: [PATCH 1/3] env: add ENV_ERASE_PTR macro Date: Tue, 9 Feb 2021 11:48:50 +0100 Message-ID: <20210209114849.1.I4101043ff86264c22da77700b28bf231d66e49cb@changeid> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210209104852.1293-1-patrick.delaunay@foss.st.com> References: <20210209104852.1293-1-patrick.delaunay@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.122] X-ClientProxiedBy: GPXDAG1NODE5.st.com (10.75.127.66) To GPXDAG2NODE6.st.com (10.75.127.70) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369, 18.0.737 definitions=2021-02-09_03:2021-02-09, 2021-02-09 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Add ENV_ERASE_PTR macro to handle erase opts and remove the associated ifdef. This patch is a extension of previous commit 82b2f4135719 ("env_internal.h: add alternative ENV_SAVE_PTR macro"). Signed-off-by: Patrick Delaunay --- env/ext4.c | 3 +-- env/mmc.c | 6 +----- include/env_internal.h | 1 + 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/env/ext4.c b/env/ext4.c index e666f7b945..caa3e05a57 100644 --- a/env/ext4.c +++ b/env/ext4.c @@ -187,6 +187,5 @@ U_BOOT_ENV_LOCATION(ext4) = { ENV_NAME("EXT4") .load = env_ext4_load, .save = ENV_SAVE_PTR(env_ext4_save), - .erase = CONFIG_IS_ENABLED(CMD_ERASEENV) ? env_ext4_erase : - NULL, + .erase = ENV_ERASE_PTR(env_ext4_erase), }; diff --git a/env/mmc.c b/env/mmc.c index ee376c3e0c..d959ba6d80 100644 --- a/env/mmc.c +++ b/env/mmc.c @@ -232,7 +232,6 @@ fini: return ret; } -#if defined(CONFIG_CMD_ERASEENV) static inline int erase_env(struct mmc *mmc, unsigned long size, unsigned long offset) { @@ -278,7 +277,6 @@ static int env_mmc_erase(void) return ret; } -#endif /* CONFIG_CMD_ERASEENV */ #endif /* CONFIG_CMD_SAVEENV && !CONFIG_SPL_BUILD */ static inline int read_env(struct mmc *mmc, unsigned long size, @@ -393,8 +391,6 @@ U_BOOT_ENV_LOCATION(mmc) = { .load = env_mmc_load, #ifndef CONFIG_SPL_BUILD .save = env_save_ptr(env_mmc_save), -#if defined(CONFIG_CMD_ERASEENV) - .erase = env_mmc_erase, -#endif + .erase = ENV_ERASE_PTR(env_mmc_erase) #endif }; diff --git a/include/env_internal.h b/include/env_internal.h index 708c833a55..b7bddcb00d 100644 --- a/include/env_internal.h +++ b/include/env_internal.h @@ -211,6 +211,7 @@ struct env_driver { #endif #define ENV_SAVE_PTR(x) (CONFIG_IS_ENABLED(SAVEENV) ? (x) : NULL) +#define ENV_ERASE_PTR(x) (CONFIG_IS_ENABLED(CMD_ERASEENV) ? (x) : NULL) extern struct hsearch_data env_htab; From patchwork Tue Feb 9 10:48:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1438261 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector1 header.b=D8EsOMW7; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DZfm31JxKz9sBJ for ; Tue, 9 Feb 2021 21:49:38 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5CDB582A2D; Tue, 9 Feb 2021 11:49:16 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com 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=foss.st.com header.i=@foss.st.com header.b="D8EsOMW7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A3F2982A27; Tue, 9 Feb 2021 11:49:04 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (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 4437682A1D for ; Tue, 9 Feb 2021 11:48:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.delaunay@foss.st.com Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 119AeosX032103; Tue, 9 Feb 2021 11:48:57 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=N8vFbKowdDHAEPj7Jy5LDHioKzbpzKWO5cJhK4T9gCw=; b=D8EsOMW75MuclRSWCfz8bF0UTRg5/PnPhWsjyRNTnEsF/UkkbRgfq3VDIMHjXqyzDZN5 HCq1FYLxpH+aB3ft9bT15qXPud3S2rcWdlbY4QJ5k1Sm+eMfc0rMsU8X7a6q2IZ14010 YLpHAd+eSdS6GY17CveSRqyMQHjkuLcJJMb2HZlSRhCTry/JAlCMHgn/LfiUkH2PmCpC uCKwV4eziwBTwwZpMaEt93Og0+bEA0aYbZZVecxeLDQg2yxA9LZjrx5WN0ExN8Ah5GUa DJxhTZAbJlWKlGvfRF2Kf0WJfzGjndfT/nPuwGCO6mbINc63z4/+08eogOzwppoBZJNv IA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 36hr2c7ywn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Feb 2021 11:48:57 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3555310002A; Tue, 9 Feb 2021 11:48:57 +0100 (CET) Received: from Webmail-eu.st.com (gpxdag2node6.st.com [10.75.127.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 28067226F66; Tue, 9 Feb 2021 11:48:57 +0100 (CET) Received: from localhost (10.75.127.122) by GPXDAG2NODE6.st.com (10.75.127.70) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 9 Feb 2021 11:48:56 +0100 From: Patrick Delaunay To: CC: Patrick Delaunay , Joe Hershberger , Wolfgang Denk , U-Boot STM32 Subject: [PATCH 2/3] env: sf: update the use of macro ENV_SAVE_PTR Date: Tue, 9 Feb 2021 11:48:51 +0100 Message-ID: <20210209114849.2.I108ef0bb214bf9eabfb9a39438381a9be6ba4b6a@changeid> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210209104852.1293-1-patrick.delaunay@foss.st.com> References: <20210209104852.1293-1-patrick.delaunay@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.122] X-ClientProxiedBy: GPXDAG3NODE5.st.com (10.75.127.72) To GPXDAG2NODE6.st.com (10.75.127.70) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369, 18.0.737 definitions=2021-02-09_03:2021-02-09, 2021-02-09 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Remove CONFIG_IS_ENABLED(SAVEENV) as it is already tested in the ENV_SAVE_PTR macro. Signed-off-by: Patrick Delaunay --- env/sf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/env/sf.c b/env/sf.c index 42d762714e..3f2fbbec12 100644 --- a/env/sf.c +++ b/env/sf.c @@ -405,6 +405,6 @@ U_BOOT_ENV_LOCATION(sf) = { .location = ENVL_SPI_FLASH, ENV_NAME("SPIFlash") .load = env_sf_load, - .save = CONFIG_IS_ENABLED(SAVEENV) ? ENV_SAVE_PTR(env_sf_save) : NULL, + .save = ENV_SAVE_PTR(env_sf_save), .init = env_sf_init, }; From patchwork Tue Feb 9 10:48:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1438260 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector1 header.b=SzQpP0TA; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DZfls3vRYz9sVX for ; Tue, 9 Feb 2021 21:49:29 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3540F82A31; Tue, 9 Feb 2021 11:49:13 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com 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=foss.st.com header.i=@foss.st.com header.b="SzQpP0TA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DB3C382A21; Tue, 9 Feb 2021 11:49:04 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (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 DDAC082A17 for ; Tue, 9 Feb 2021 11:49:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.delaunay@foss.st.com Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 119AgY1d023243; Tue, 9 Feb 2021 11:48:59 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=kytvhHJywrKId5CwbCNRI4KX3TTb/rqRWTTrXaXpa7Q=; b=SzQpP0TAK7vf1qAcde3FNldAey04UToUqv2tMGL+dLfLxqkd2Cg7U5uti+ovUbGQDvaI t/x9sQwms3Qo88D+CjLOVteJo8kkIELTCXCqlfdbPCOw3H7LJmY4PXuK1/Jcyk3I3mQF 1bYeUiUKzOqOjk+DHxSpsZhfNV9nvAPv1geNrGnXnXnrEgxh4EVELEflzGMepqMSBDhm XDjHx5ukgaw52i2nd/zS9/Zt358Cti9HgC/kGyyDNZgSqFkkC7QNVDMSer8eBekcMNKf Jn6iKbIR/U8QVvFLdQOvyA4/tl/6xFhVbHASUma+xBY4RNwuzlajqDk2O2T4gqN9fXUH HQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 36hraur3cd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Feb 2021 11:48:59 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2B21A10002A; Tue, 9 Feb 2021 11:48:58 +0100 (CET) Received: from Webmail-eu.st.com (gpxdag2node6.st.com [10.75.127.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 2108C226F68; Tue, 9 Feb 2021 11:48:58 +0100 (CET) Received: from localhost (10.75.127.120) by GPXDAG2NODE6.st.com (10.75.127.70) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 9 Feb 2021 11:48:57 +0100 From: Patrick Delaunay To: CC: Patrick Delaunay , Joe Hershberger , Wolfgang Denk , U-Boot STM32 Subject: [PATCH 3/3] env: sf: add support of command env erase Date: Tue, 9 Feb 2021 11:48:52 +0100 Message-ID: <20210209114849.3.I10fb7cded95e008428ff08f4f1e6f785cefc4d0f@changeid> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210209104852.1293-1-patrick.delaunay@foss.st.com> References: <20210209104852.1293-1-patrick.delaunay@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.120] X-ClientProxiedBy: GPXDAG2NODE4.st.com (10.75.127.68) To GPXDAG2NODE6.st.com (10.75.127.70) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369, 18.0.737 definitions=2021-02-09_03:2021-02-09, 2021-02-09 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Add support of opts erase for env in SPI flash; this opts is used by command 'env erase'. This command only fills the env offset by 0x0 (bit flip to 0) and the saved environment becomes invalid (with bad CRC). It doesn't erase the sector here to avoid issue when the sector is larger than the env (i.e. embedded when CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE). The needed sector erase will be managed in the next "env save" command, using the opt ".save", before to update the environment in SPI flash. Signed-off-by: Patrick Delaunay --- env/sf.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/env/sf.c b/env/sf.c index 3f2fbbec12..6b61a4b8de 100644 --- a/env/sf.c +++ b/env/sf.c @@ -27,9 +27,18 @@ #define INITENV #endif +#define OFFSET_INVALID (~(u32)0) + #ifdef CONFIG_ENV_OFFSET_REDUND +#define ENV_OFFSET_REDUND CONFIG_ENV_OFFSET_REDUND + static ulong env_offset = CONFIG_ENV_OFFSET; static ulong env_new_offset = CONFIG_ENV_OFFSET_REDUND; + +#else + +#define ENV_OFFSET_REDUND OFFSET_INVALID + #endif /* CONFIG_ENV_OFFSET_REDUND */ DECLARE_GLOBAL_DATA_PTR; @@ -279,6 +288,30 @@ out: } #endif +static int env_sf_erase(void) +{ + int ret; + env_t env; + + ret = setup_flash_device(); + if (ret) + return ret; + + memset(&env, 0, sizeof(env_t)); + ret = spi_flash_write(env_flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, &env); + if (ret) + goto done; + + if (ENV_OFFSET_REDUND != OFFSET_INVALID) + ret = spi_flash_write(env_flash, ENV_OFFSET_REDUND, CONFIG_ENV_SIZE, &env); + +done: + spi_flash_free(env_flash); + env_flash = NULL; + + return ret; +} + #if CONFIG_ENV_ADDR != 0x0 __weak void *env_sf_get_env_addr(void) { @@ -406,5 +439,6 @@ U_BOOT_ENV_LOCATION(sf) = { ENV_NAME("SPIFlash") .load = env_sf_load, .save = ENV_SAVE_PTR(env_sf_save), + .erase = ENV_ERASE_PTR(env_sf_erase), .init = env_sf_init, };