[PATCH] mmc-utils: Add basic erase error check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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




[Index of Archives]     [Linux Memonry Technology]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux