Skip to contentSkip to conversation

mmc-utils: Allow for custom sanitize timeout

PATCH Applied Christian Löhle 2 participants 3 messages Oct 15, 2022 – Oct 24, 2022 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH v4 2/2 mmc-utils: Allow for custom sanitize timeout

Some cards with certain preconditioning require a higher timeout when sanitizing. Let the user set the maximum timeout.

---
-v4: Fix argument order in help text

 mmc.c      |  2 +-
 mmc_cmds.c | 10 +++++++---
 2 files changed, 8 insertions(+), 4 deletions(-)
mmc.c +1 -1
index 6c56387..4c09b79 100644
@@ -150,7 +150,7 @@ static struct Command commands[] = {
 	  NULL
 	},
 	{ do_sanitize, -1,
-	  "sanitize", "<device>\n"
+	  "sanitize", "<device> [timeout_ms]\n"
 		"Send Sanitize command to the <device>.\nThis will delete the unmapped memory region of the device.",
 	  NULL
 	},
mmc_cmds.c +7 -3
index 3337ded..9e0571f 100644
@@ -1986,12 +1986,16 @@ int do_sanitize(int nargs, char **argv)
 {
 	int fd, ret;
 	char *device;
+	unsigned int timeout = 0;
 
-	if (nargs != 2) {
-		fprintf(stderr, "Usage: mmc sanitize </path/to/mmcblkX>\n");
+	if (nargs != 2 && nargs != 3) {
+		fprintf(stderr, "Usage: mmc sanitize </path/to/mmcblkX> [timeout_in_ms]\n");
 		exit(1);
 	}
 
+	if (nargs == 3)
+		timeout = strtol(argv[2], NULL, 10);
+
 	device = argv[1];
 
 	fd = open(device, O_RDWR);
@@ -2000,7 +2004,7 @@ int do_sanitize(int nargs, char **argv)
 		exit(1);
 	}
 
-	ret = write_extcsd_value(fd, EXT_CSD_SANITIZE_START, 1, 0);
+	ret = write_extcsd_value(fd, EXT_CSD_SANITIZE_START, 1, timeout);
 	if (ret) {
 		fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
 			1, EXT_CSD_SANITIZE_START, device);
Signature · 5 lines
2.37.3

Hyperstone GmbH | Reichenaustr. 39a  | 78467 Konstanz
Managing Director: Dr. Jan Peter Berns.
Commercial register of local courts: Freiburg HRB381782
author Reviewed-by Avri Altman on v4 2/2
#1 lore raw
Quoted 3 lines

Some cards with certain preconditioning require a higher timeout when sanitizing. Let the user set the maximum > > timeout.

Forgot to add, my bad.

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

Applied
#2 lore raw
In reply to Christian Löhle
Quoted 5 lines · Christian Löhle

Some cards with certain preconditioning require a higher timeout when sanitizing. Let the user set the maximum timeout.

Applied to git.kernel.org/pub/scm//utils/mmc/mmc-utils.git master, thanks!

Kind regards
Uffe

Quoted 58 lines

---

(quoted diff) +0 -1
-v4: Fix argument order in help text
 mmc.c      |  2 +-
 mmc_cmds.c | 10 +++++++---
 2 files changed, 8 insertions(+), 4 deletions(-)
mmc.c +1 -1
index 6c56387..4c09b79 100644
@@ -150,7 +150,7 @@ static struct Command commands[] = {
          NULL
        },
        { do_sanitize, -1,
-         "sanitize", "<device>\n"
+         "sanitize", "<device> [timeout_ms]\n"
                "Send Sanitize command to the <device>.\nThis will delete the unmapped memory region of the device.",
          NULL
        },
mmc_cmds.c +7 -4
index 3337ded..9e0571f 100644
@@ -1986,12 +1986,16 @@ int do_sanitize(int nargs, char **argv)
 {
        int fd, ret;
        char *device;
+       unsigned int timeout = 0;
 
-       if (nargs != 2) {
-               fprintf(stderr, "Usage: mmc sanitize </path/to/mmcblkX>\n");
+       if (nargs != 2 && nargs != 3) {
+               fprintf(stderr, "Usage: mmc sanitize </path/to/mmcblkX> [timeout_in_ms]\n");
                exit(1);
        }
 
+       if (nargs == 3)
+               timeout = strtol(argv[2], NULL, 10);
+
        device = argv[1];
 
        fd = open(device, O_RDWR);
@@ -2000,7 +2004,7 @@ int do_sanitize(int nargs, char **argv)
                exit(1);
        }
 
-       ret = write_extcsd_value(fd, EXT_CSD_SANITIZE_START, 1, 0);
+       ret = write_extcsd_value(fd, EXT_CSD_SANITIZE_START, 1, timeout);
        if (ret) {
                fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
                        1, EXT_CSD_SANITIZE_START, device);
--

2.37.3

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