[U-Boot] [PATCH v3 2/2] env: mmc: add erase-function

Frank Wunderlich frank-w at public-files.de
Fri Apr 12 09:37:05 UTC 2019


Signed-off-by: Frank Wunderlich <frank-w at public-files.de>
---
 env/mmc.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/env/mmc.c b/env/mmc.c
index c3cf35d01b..f387a53970 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -242,6 +242,33 @@ fini:
 	fini_mmc_for_env(mmc);
 	return ret;
 }
+
+static int env_mmc_erase(void)
+{
+	int dev = mmc_get_env_dev();
+	struct mmc *mmc = find_mmc_device(dev);
+	int	n, blk, cnt;
+
+	if (!mmc)
+		return CMD_RET_FAILURE;
+
+	blk = CONFIG_ENV_OFFSET / mmc->read_bl_len;
+	cnt = CONFIG_ENV_SIZE / mmc->read_bl_len;
+
+	printf("\nMMC erase env: dev # %d, block # %d (0x%x), count %d (0x%x)\n",
+	       dev, blk, blk * mmc->read_bl_len,
+	       cnt, cnt * mmc->read_bl_len);
+
+	if (mmc_getwp(mmc) == 1) {
+		printf("Error: card is write protected!\n");
+		return CMD_RET_FAILURE;
+	}
+	n = blk_derase(mmc_get_blk_desc(mmc), blk, cnt);
+	printf("%d blocks erased: %s\n", n, (n == cnt) ? "OK" : "ERROR");
+
+	return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
+}
+
 #endif /* CONFIG_CMD_SAVEENV && !CONFIG_SPL_BUILD */

 static inline int read_env(struct mmc *mmc, unsigned long size,
@@ -351,5 +378,6 @@ U_BOOT_ENV_LOCATION(mmc) = {
 	.load		= env_mmc_load,
 #ifndef CONFIG_SPL_BUILD
 	.save		= env_save_ptr(env_mmc_save),
+	.erase		= env_mmc_erase,
 #endif
 };
--
2.17.1



More information about the U-Boot mailing list