[RESEND,09/10] env: ext4: add support of command env erase
diff mbox series

Message ID 20200212184501.5911-10-patrick.delaunay@st.com
State New
Delegated to: Joe Hershberger
Headers show
Series
  • env: ext4: add test for env in ext4
Related show

Commit Message

Patrick Delaunay Feb. 12, 2020, 6:45 p.m. UTC
Add support of opts erase for env in ext4,
this opts is used by command 'env erase'.

This command only fill the env file (CONFIG_ENV_EXT4_FILE)
with 0, the CRC and the saved environment becomes invalid.

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

 env/ext4.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/env/ext4.c b/env/ext4.c
index 49ed06659f..aec2a33fad 100644
--- a/env/ext4.c
+++ b/env/ext4.c
@@ -43,7 +43,7 @@  __weak const char *env_ext4_get_dev_part(void)
 	return (const char *)CONFIG_ENV_EXT4_DEVICE_AND_PART;
 }
 
-#if defined(CONFIG_CMD_SAVEENV)
+#if defined(CONFIG_CMD_SAVEENV) || defined(CONFIG_CMD_ERASEENV)
 static int env_ext4_save_buffer(env_t *env_new)
 {
 	struct blk_desc *dev_desc = NULL;
@@ -102,6 +102,25 @@  static int env_ext4_save(void)
 }
 #endif /* CONFIG_CMD_SAVEENV */
 
+#if defined(CONFIG_CMD_ERASEENV)
+static int env_ext4_erase(void)
+{
+	env_t	env_new;
+	int err;
+
+	memset(&env_new, 0, sizeof(env_t));
+
+	err = env_ext4_save_buffer(&env_new);
+	if (err)
+		return err;
+
+	gd->env_valid = ENV_INVALID;
+	puts("done\n");
+
+	return 0;
+}
+#endif
+
 static int env_ext4_load(void)
 {
 	ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
@@ -161,4 +180,7 @@  U_BOOT_ENV_LOCATION(ext4) = {
 #ifdef CONFIG_CMD_SAVEENV
 	.save		= env_save_ptr(env_ext4_save),
 #endif
+#if defined(CONFIG_CMD_ERASEENV)
+	.erase		= env_ext4_erase,
+#endif
 };