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;