From patchwork Wed Feb 12 18:30:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Delaunay X-Patchwork-Id: 236266 List-Id: U-Boot discussion From: patrick.delaunay at st.com (Patrick Delaunay) Date: Wed, 12 Feb 2020 19:30:20 +0100 Subject: [PATCH 09/10] env: ext4: add support of command env erase In-Reply-To: <20200212183021.4844-1-patrick.delaunay@st.com> References: <20200212183021.4844-1-patrick.delaunay@st.com> Message-ID: <20200212183021.4844-10-patrick.delaunay@st.com> 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 --- env/ext4.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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 };