diff mbox series

[2/2] mmc-utils: Allow for custom sanitize timeout

Message ID 2928ac054a574f8f82670f7aa67d01a8@hyperstone.com (mailing list archive)
State New, archived
Headers show
Series [1/2] mmc-utils: Refactor switch to allow custom timeout | expand

Commit Message

Christian Loehle Oct. 10, 2022, 2:10 p.m. UTC
Some cards with certain preconditioing require a much higher timeout when
sanitizing. Let the user set the maximum timeout.

Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
---
 mmc.c      |  2 +-
 mmc_cmds.c | 10 +++++++---
 2 files changed, 8 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/mmc.c b/mmc.c
index 6c56387..2344879 100644
--- a/mmc.c
+++ b/mmc.c
@@ -150,7 +150,7 @@  static struct Command commands[] = {
 	  NULL
 	},
 	{ do_sanitize, -1,
-	  "sanitize", "<device>\n"
+	  "sanitize", "[timeout_ms] <device>\n"
 		"Send Sanitize command to the <device>.\nThis will delete the unmapped memory region of the device.",
 	  NULL
 	},
diff --git a/mmc_cmds.c b/mmc_cmds.c
index 4278b8a..8546a3f 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -2007,12 +2007,16 @@  int do_sanitize(int nargs, char **argv)
 {
 	int fd, ret;
 	char *device;
+	unsigned int timeout = SWITCH_TIMEOUT_MS;
 
-	if (nargs != 2) {
-		fprintf(stderr, "Usage: mmc sanitize </path/to/mmcblkX>\n");
+	if (nargs != 2 && nargs != 3) {
+		fprintf(stderr, "Usage: mmc sanitize [timeout_in_ms] </path/to/mmcblkX>\n");
 		exit(1);
 	}
 
+	if (nargs == 3)
+		timeout = strtol(argv[2], NULL, 10);
+
 	device = argv[1];
 
 	fd = open(device, O_RDWR);
@@ -2021,7 +2025,7 @@  int do_sanitize(int nargs, char **argv)
 		exit(1);
 	}
 
-	ret = write_extcsd_value(fd, EXT_CSD_SANITIZE_START, 1);
+	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);