All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] env: sf: add support of command env erase
@ 2021-02-09 10:48 Patrick Delaunay
  2021-02-09 10:48 ` [PATCH 1/3] env: add ENV_ERASE_PTR macro Patrick Delaunay
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Patrick Delaunay @ 2021-02-09 10:48 UTC (permalink / raw)
  To: u-boot


Hi,

I add support of env erase command for SPI flash backend (sf).

To erase the environment, this patch only invalidate the content at
CONFIG_ENV_OFFSET and at CONFIG_ENV_OFFSET_REDUND (force a bad CRC).

The 2 first patchs of the serie are preliminary and clenaup steps.

Patrick



Patrick Delaunay (3):
  env: add ENV_ERASE_PTR macro
  env: sf: update the use of macro ENV_SAVE_PTR
  env: sf: add support of command env erase

 env/ext4.c             |  3 +--
 env/mmc.c              |  6 +-----
 env/sf.c               | 36 +++++++++++++++++++++++++++++++++++-
 include/env_internal.h |  1 +
 4 files changed, 38 insertions(+), 8 deletions(-)

-- 
2.17.1

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

* [PATCH 1/3] env: add ENV_ERASE_PTR macro
  2021-02-09 10:48 [PATCH 0/3] env: sf: add support of command env erase Patrick Delaunay
@ 2021-02-09 10:48 ` Patrick Delaunay
  2021-04-18 12:45   ` Tom Rini
  2021-02-09 10:48 ` [PATCH 2/3] env: sf: update the use of macro ENV_SAVE_PTR Patrick Delaunay
  2021-02-09 10:48 ` [PATCH 3/3] env: sf: add support of command env erase Patrick Delaunay
  2 siblings, 1 reply; 7+ messages in thread
From: Patrick Delaunay @ 2021-02-09 10:48 UTC (permalink / raw)
  To: u-boot

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 <patrick.delaunay@foss.st.com>
---

 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;
 
-- 
2.17.1

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

* [PATCH 2/3] env: sf: update the use of macro ENV_SAVE_PTR
  2021-02-09 10:48 [PATCH 0/3] env: sf: add support of command env erase Patrick Delaunay
  2021-02-09 10:48 ` [PATCH 1/3] env: add ENV_ERASE_PTR macro Patrick Delaunay
@ 2021-02-09 10:48 ` Patrick Delaunay
  2021-04-18 12:45   ` Tom Rini
  2021-02-09 10:48 ` [PATCH 3/3] env: sf: add support of command env erase Patrick Delaunay
  2 siblings, 1 reply; 7+ messages in thread
From: Patrick Delaunay @ 2021-02-09 10:48 UTC (permalink / raw)
  To: u-boot

Remove CONFIG_IS_ENABLED(SAVEENV) as it is already tested in
the ENV_SAVE_PTR macro.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---

 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,
 };
-- 
2.17.1

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

* [PATCH 3/3] env: sf: add support of command env erase
  2021-02-09 10:48 [PATCH 0/3] env: sf: add support of command env erase Patrick Delaunay
  2021-02-09 10:48 ` [PATCH 1/3] env: add ENV_ERASE_PTR macro Patrick Delaunay
  2021-02-09 10:48 ` [PATCH 2/3] env: sf: update the use of macro ENV_SAVE_PTR Patrick Delaunay
@ 2021-02-09 10:48 ` Patrick Delaunay
  2021-04-18 12:45   ` Tom Rini
  2 siblings, 1 reply; 7+ messages in thread
From: Patrick Delaunay @ 2021-02-09 10:48 UTC (permalink / raw)
  To: u-boot

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 <patrick.delaunay@foss.st.com>
---

 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,
 };
-- 
2.17.1

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

* [PATCH 1/3] env: add ENV_ERASE_PTR macro
  2021-02-09 10:48 ` [PATCH 1/3] env: add ENV_ERASE_PTR macro Patrick Delaunay
@ 2021-04-18 12:45   ` Tom Rini
  0 siblings, 0 replies; 7+ messages in thread
From: Tom Rini @ 2021-04-18 12:45 UTC (permalink / raw)
  To: u-boot

On Tue, Feb 09, 2021 at 11:48:50AM +0100, Patrick Delaunay wrote:

> 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 <patrick.delaunay@foss.st.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210418/3a4b2153/attachment.sig>

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

* [PATCH 2/3] env: sf: update the use of macro ENV_SAVE_PTR
  2021-02-09 10:48 ` [PATCH 2/3] env: sf: update the use of macro ENV_SAVE_PTR Patrick Delaunay
@ 2021-04-18 12:45   ` Tom Rini
  0 siblings, 0 replies; 7+ messages in thread
From: Tom Rini @ 2021-04-18 12:45 UTC (permalink / raw)
  To: u-boot

On Tue, Feb 09, 2021 at 11:48:51AM +0100, Patrick Delaunay wrote:

> Remove CONFIG_IS_ENABLED(SAVEENV) as it is already tested in
> the ENV_SAVE_PTR macro.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210418/5453a948/attachment.sig>

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

* [PATCH 3/3] env: sf: add support of command env erase
  2021-02-09 10:48 ` [PATCH 3/3] env: sf: add support of command env erase Patrick Delaunay
@ 2021-04-18 12:45   ` Tom Rini
  0 siblings, 0 replies; 7+ messages in thread
From: Tom Rini @ 2021-04-18 12:45 UTC (permalink / raw)
  To: u-boot

On Tue, Feb 09, 2021 at 11:48:52AM +0100, Patrick Delaunay wrote:

> 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 <patrick.delaunay@foss.st.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210418/cfa5a54b/attachment.sig>

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

end of thread, other threads:[~2021-04-18 12:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-09 10:48 [PATCH 0/3] env: sf: add support of command env erase Patrick Delaunay
2021-02-09 10:48 ` [PATCH 1/3] env: add ENV_ERASE_PTR macro Patrick Delaunay
2021-04-18 12:45   ` Tom Rini
2021-02-09 10:48 ` [PATCH 2/3] env: sf: update the use of macro ENV_SAVE_PTR Patrick Delaunay
2021-04-18 12:45   ` Tom Rini
2021-02-09 10:48 ` [PATCH 3/3] env: sf: add support of command env erase Patrick Delaunay
2021-04-18 12:45   ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.