diff mbox series

[RESEND,08/10] env: ext4: introduce new function env_ext4_save_buffer

Message ID 20200212184501.5911-9-patrick.delaunay@st.com
State New
Headers show
Series env: ext4: add test for env in ext4 | expand

Commit Message

Patrick Delaunay Feb. 12, 2020, 6:44 p.m. UTC
Split the function env_ext4_save to prepare the erase support

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

 env/ext4.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/env/ext4.c b/env/ext4.c
index aa77261649..49ed06659f 100644
--- a/env/ext4.c
+++ b/env/ext4.c
@@ -43,10 +43,9 @@  __weak const char *env_ext4_get_dev_part(void)
 	return (const char *)CONFIG_ENV_EXT4_DEVICE_AND_PART;
 }
 
-#ifdef CONFIG_CMD_SAVEENV
-static int env_ext4_save(void)
+#if defined(CONFIG_CMD_SAVEENV)
+static int env_ext4_save_buffer(env_t *env_new)
 {
-	env_t	env_new;
 	struct blk_desc *dev_desc = NULL;
 	disk_partition_t info;
 	int dev, part;
@@ -54,10 +53,6 @@  static int env_ext4_save(void)
 	const char *ifname = env_ext4_get_intf();
 	const char *dev_and_part = env_ext4_get_dev_part();
 
-	err = env_export(&env_new);
-	if (err)
-		return err;
-
 	part = blk_get_device_part_str(ifname, dev_and_part,
 				       &dev_desc, &info, 1);
 	if (part < 0)
@@ -72,7 +67,7 @@  static int env_ext4_save(void)
 		return 1;
 	}
 
-	err = ext4fs_write(CONFIG_ENV_EXT4_FILE, (void *)&env_new,
+	err = ext4fs_write(CONFIG_ENV_EXT4_FILE, (void *)env_new,
 			   sizeof(env_t), FILETYPE_REG);
 	ext4fs_close();
 
@@ -81,9 +76,28 @@  static int env_ext4_save(void)
 			CONFIG_ENV_EXT4_FILE, ifname, dev, part);
 		return 1;
 	}
-	gd->env_valid = ENV_VALID;
 
+	return 0;
+}
+#endif
+
+#ifdef CONFIG_CMD_SAVEENV
+static int env_ext4_save(void)
+{
+	env_t	env_new;
+	int err;
+
+	err = env_export(&env_new);
+	if (err)
+		return err;
+
+	err = env_ext4_save_buffer(&env_new);
+	if (err)
+		return err;
+
+	gd->env_valid = ENV_VALID;
 	puts("done\n");
+
 	return 0;
 }
 #endif /* CONFIG_CMD_SAVEENV */