Linux MultiMedia Card development
 help / color / mirror / Atom feed
* [PATCH] mmc-utils: Add basic erase error check
@ 2022-12-12  9:21 Christian Löhle
  2022-12-12 13:44 ` Avri Altman
  0 siblings, 1 reply; 12+ messages in thread
From: Christian Löhle @ 2022-12-12  9:21 UTC (permalink / raw)
  To: ulf.hansson@linaro.org, adrian.hunter@intel.com,
	linux-mmc@vger.kernel.org

Check for erase specific R1 errors so e.g. an OOR erase is not
reported as successful when it never executed.

There could be checks for more error bits but R1_ERASE_SEQ_ERROR
on CMD38 should catch all that are reported by hardware anyway.

Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
---
 mmc_cmds.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/mmc_cmds.c b/mmc_cmds.c
index e6d3273..c00fe5e 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -54,6 +54,7 @@
 #define WPTYPE_PWRON 2
 #define WPTYPE_PERM 3
 
+#define ERASE_R1_ERR_MASK (R1_ERASE_SEQ_ERROR | R1_ERASE_PARAM | R1_ERASE_RESET)
 
 int read_extcsd(int fd, __u8 *ext_csd)
 {
@@ -2668,6 +2669,23 @@ static int erase(int dev_fd, __u32 argin, __u32 start, __u32 end)
 	if (ret)
 		perror("Erase multi-cmd ioctl");
 
+	/* Does not work for SPI cards */
+	if (multi_cmd->cmds[0].response[0] & ERASE_R1_ERR_MASK) {
+		fprintf(stderr, "Erase start response: %08x\n",
+				multi_cmd->cmds[0].response[0]);
+		ret = -EIO;
+	}
+	if (multi_cmd->cmds[1].response[0] & ERASE_R1_ERR_MASK) {
+		fprintf(stderr, "Erase end response: %08x\n",
+				multi_cmd->cmds[1].response[0]);
+		ret = -EIO;
+	}
+	if (multi_cmd->cmds[2].response[0] & ERASE_R1_ERR_MASK) {
+		fprintf(stderr, "Erase response: %08x\n",
+				multi_cmd->cmds[2].response[0]);
+		ret = -EIO;
+	}
+
 	free(multi_cmd);
 	return ret;
 }
-- 
2.37.3


Hyperstone GmbH | Reichenaustr. 39a  | 78467 Konstanz
Managing Director: Dr. Jan Peter Berns.
Commercial register of local courts: Freiburg HRB381782


^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [PATCH] mmc-utils: Add basic erase error check
@ 2023-01-16 10:49 Christian Löhle
  2023-01-16 11:10 ` Avri Altman
  0 siblings, 1 reply; 12+ messages in thread
From: Christian Löhle @ 2023-01-16 10:49 UTC (permalink / raw)
  To: Avri Altman, linux-mmc@vger.kernel.org; +Cc: ulf.hansson@linaro.org

Check for erase specific R1 errors so e.g. an OOR erase is not
reported as successful when it never executed.

There could be checks for more error bits but R1_ERASE_SEQ_ERROR
on CMD38 should catch all that are reported by hardware anyway.

Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
---
-v2: Remove unneeded error bit checking
 mmc_cmds.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/mmc_cmds.c b/mmc_cmds.c
index e6d3273..97fdb59 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -54,7 +54,6 @@
 #define WPTYPE_PWRON 2
 #define WPTYPE_PERM 3
 
-
 int read_extcsd(int fd, __u8 *ext_csd)
 {
 	int ret = 0;
@@ -2668,6 +2667,18 @@ static int erase(int dev_fd, __u32 argin, __u32 start, __u32 end)
 	if (ret)
 		perror("Erase multi-cmd ioctl");
 
+	/* Does not work for SPI cards */
+	if (multi_cmd->cmds[0].response[0] & R1_ERASE_PARAM) {
+		fprintf(stderr, "Erase start response: 0x%08x\n",
+				multi_cmd->cmds[0].response[0]);
+		ret = -EIO;
+	}
+	if (multi_cmd->cmds[2].response[0] & R1_ERASE_SEQ_ERROR) {
+		fprintf(stderr, "Erase response: 0x%08x\n",
+				multi_cmd->cmds[2].response[0]);
+		ret = -EIO;
+	}
+
 	free(multi_cmd);
 	return ret;
 }
-- 
2.37.3


Hyperstone GmbH | Reichenaustr. 39a  | 78467 Konstanz
Managing Director: Dr. Jan Peter Berns.
Commercial register of local courts: Freiburg HRB381782


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-01-16 11:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-12  9:21 [PATCH] mmc-utils: Add basic erase error check Christian Löhle
2022-12-12 13:44 ` Avri Altman
2022-12-12 14:00   ` Christian Löhle
2022-12-12 14:08     ` Christian Löhle
2022-12-13 14:00       ` Avri Altman
2022-12-13 15:26         ` Christian Löhle
2022-12-14  8:15           ` Avri Altman
2022-12-15 18:14             ` Christian Löhle
2022-12-16  6:11               ` Avri Altman
2023-01-02 12:01                 ` Avri Altman
  -- strict thread matches above, loose matches on Subject: below --
2023-01-16 10:49 Christian Löhle
2023-01-16 11:10 ` Avri Altman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox