summaryrefslogtreecommitdiff
path: root/env/mmc.c
diff options
context:
space:
mode:
authorFrank Wunderlich <frank-w@public-files.de>2019-06-29 11:36:20 +0200
committerTom Rini <trini@konsulko.com>2019-07-18 11:31:26 -0400
commit3485392506decf3896b7f742c1300cbdf8b31f83 (patch)
tree5b5a8d5403cd4b18da66c27bdf6dfd286a4913cc /env/mmc.c
parentcd121bdb6df3fe8dfe45ff1e34f46f86b8f060c0 (diff)
downloadu-boot-3485392506decf3896b7f742c1300cbdf8b31f83.tar.gz
u-boot-3485392506decf3896b7f742c1300cbdf8b31f83.tar.bz2
u-boot-3485392506decf3896b7f742c1300cbdf8b31f83.zip
env: mmc: add erase-function
this adds erase environment for mmc storage squashed fixes: - add CONFIG_CMD_ERASEENV - env: erase redundant offset if defined - changes mentioned by Simon - fix whitespaces around errmsg Suggested-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Signed-off-by: Frank Wunderlich <frank-w@public-files.de> Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Diffstat (limited to 'env/mmc.c')
-rw-r--r--env/mmc.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/env/mmc.c b/env/mmc.c
index c3cf35d01b..b7b833f423 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -242,6 +242,54 @@ fini:
fini_mmc_for_env(mmc);
return ret;
}
+
+#if defined(CONFIG_CMD_ERASEENV)
+static inline int erase_env(struct mmc *mmc, unsigned long size,
+ unsigned long offset)
+{
+ uint blk_start, blk_cnt, n;
+ struct blk_desc *desc = mmc_get_blk_desc(mmc);
+
+ blk_start = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
+ blk_cnt = ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len;
+
+ n = blk_derase(desc, blk_start, blk_cnt);
+ printf("%d blocks erased: %s\n", n, (n == blk_cnt) ? "OK" : "ERROR");
+
+ return (n == blk_cnt) ? 0 : 1;
+}
+
+static int env_mmc_erase(void)
+{
+ int dev = mmc_get_env_dev();
+ struct mmc *mmc = find_mmc_device(dev);
+ int ret, copy = 0;
+ u32 offset;
+ const char *errmsg;
+
+ errmsg = init_mmc_for_env(mmc);
+ if (errmsg) {
+ printf("%s\n", errmsg);
+ return 1;
+ }
+
+ if (mmc_get_env_addr(mmc, copy, &offset))
+ return CMD_RET_FAILURE;
+
+ ret = erase_env(mmc, CONFIG_ENV_SIZE, offset);
+
+#ifdef CONFIG_ENV_OFFSET_REDUND
+ copy = 1;
+
+ if (mmc_get_env_addr(mmc, copy, &offset))
+ return CMD_RET_FAILURE;
+
+ ret |= erase_env(mmc, CONFIG_ENV_SIZE, offset);
+#endif
+
+ return ret;
+}
+#endif /* CONFIG_CMD_ERASEENV */
#endif /* CONFIG_CMD_SAVEENV && !CONFIG_SPL_BUILD */
static inline int read_env(struct mmc *mmc, unsigned long size,
@@ -351,5 +399,8 @@ 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
#endif
};