All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frank Wunderlich <frank-w@public-files.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 2/4] env: mmc: add erase-function
Date: Sun, 28 Apr 2019 10:51:26 +0200	[thread overview]
Message-ID: <20190428085128.8479-3-frank-w@public-files.de> (raw)
In-Reply-To: <20190428085128.8479-1-frank-w@public-files.de>

this adds erase environment for mmc storage

Signed-off-by: Frank Wunderlich <frank-w@public-files.de>

squashed fixes:
 - fix bogus indent
 - add CONFIG_CMD_ERASEENV

Suggested-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
---
 env/mmc.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/env/mmc.c b/env/mmc.c
index c3cf35d01b..9ae9b1a66a 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -242,6 +242,34 @@ fini:
 	fini_mmc_for_env(mmc);
 	return ret;
 }
+
+#if defined(CONFIG_CMD_ERASEENV)
+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_ERASEENV */
 #endif /* CONFIG_CMD_SAVEENV && !CONFIG_SPL_BUILD */

 static inline int read_env(struct mmc *mmc, unsigned long size,
@@ -351,5 +379,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
 };
--
2.17.1

  parent reply	other threads:[~2019-04-28  8:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-28  8:51 [U-Boot] [PATCH v4 0/4] add command env erase Frank Wunderlich
2019-04-28  8:51 ` [U-Boot] [PATCH v4 1/4] env: register erase command Frank Wunderlich
2019-06-24 19:26   ` Simon Goldschmidt
2019-04-28  8:51 ` Frank Wunderlich [this message]
2019-06-24 19:40   ` [U-Boot] [PATCH v4 2/4] env: mmc: add erase-function Simon Goldschmidt
2019-06-24 20:08     ` Frank Wunderlich
2019-06-24 20:19       ` Simon Goldschmidt
2019-04-28  8:51 ` [U-Boot] [PATCH v4 3/4] env: add option to use redundant offset Frank Wunderlich
2019-04-28  8:51 ` [U-Boot] [PATCH v4 4/4] [RFC] env: call env_erase twice if CONFIG_ENV_OFFSET_REDUND is set Frank Wunderlich
2019-05-20 18:34 ` [U-Boot] [PATCH v4 0/4] add command env erase Frank Wunderlich
2019-06-24 10:30   ` Frank Wunderlich
2019-06-24 18:16     ` Tom Rini
2019-06-24 19:25     ` Simon Goldschmidt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190428085128.8479-3-frank-w@public-files.de \
    --to=frank-w@public-files.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.