From a08f08ec675261a7d7c141f818a613a304e85be8 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Fri, 16 Dec 2022 11:16:25 -0500 Subject: [PATCH] mmc-utils: Add a command to write extcsd registers There is a command to read the extcsd and some commands to configure particular features, but no generic write extcsd command. Such a command may be useful for not-yet-supported features and manufacturer-specific registers. Signed-off-by: Philippe Reynes [ rebased onto latest master and updated commit message ] Signed-off-by: Sean Anderson Link: https://lore.kernel.org/r/20221216161625.2924013-1-sean.anderson@seco.com Signed-off-by: Ulf Hansson --- mmc.c | 5 +++++ mmc_cmds.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/mmc.c b/mmc.c index adcd814..b9aa478 100644 --- a/mmc.c +++ b/mmc.c @@ -58,6 +58,11 @@ static struct Command commands[] = { "Print extcsd data from .", NULL }, + { do_write_extcsd, 3, + "extcsd write", " \n" + "Write at offset to 's extcsd.", + NULL + }, { do_writeprotect_boot_get, -1, "writeprotect boot get", "\n" "Print the boot partitions write protect status for .", diff --git a/mmc_cmds.c b/mmc_cmds.c index e6d3273..33b9e43 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -1982,6 +1982,38 @@ out_free: return ret; } +int do_write_extcsd(int nargs, char **argv) +{ + int fd, ret; + int offset, value; + char *device; + + if (nargs != 4) { + fprintf(stderr, "Usage: mmc extcsd write \n"); + exit(1); + } + + offset = strtol(argv[1], NULL, 0); + value = strtol(argv[2], NULL, 0); + device = argv[3]; + + fd = open(device, O_RDWR); + if (fd < 0) { + perror("open"); + exit(1); + } + + ret = write_extcsd_value(fd, offset, value, 0); + if (ret) { + fprintf(stderr, + "Could not write 0x%02x to EXT_CSD[%d] in %s\n", + value, offset, device); + exit(1); + } + + return ret; +} + int do_sanitize(int nargs, char **argv) { int fd, ret;