On 1/2/23 08:06, Ulf Hansson wrote: > On Fri, 16 Dec 2022 at 17:16, Sean Anderson <sean.anderson@xxxxxxxx> wrote: >> >> 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. > > In a way this seems reasonable to me, while I am also a bit reluctant > to provide a too easy interface to allow the user to write any extcsd > value to the device. Note that, if these changes affect the behaviour > of the device, the kernel will not be aware of it. This is mainly to add an easy way to use vendor features, or to play around with unimplemented registers. For example, I wanted to determine the behavior of CD_PERM_WP_DIS (whether it persisted across power cycles, as the spec is unclear). With this command I was quickly able to set it and test things out. --Sean > Anyway, I will defer to Avri to make the call. >> >> Signed-off-by: Philippe Reynes <philippe.reynes@xxxxxxxxxxxx> >> [ rebased onto latest master and updated commit message ] >> Signed-off-by: Sean Anderson <sean.anderson@xxxxxxxx> > > Kind regards > Uffe > >> --- >> >> 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 <device>.", >> NULL >> }, >> + { do_write_extcsd, 3, >> + "extcsd write", "<offset> <value> <device>\n" >> + "Write <value> at offset <offset> to <device>'s extcsd.", >> + NULL >> + }, >> { do_writeprotect_boot_get, -1, >> "writeprotect boot get", "<device>\n" >> "Print the boot partitions write protect status for <device>.", >> 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 <offset> <value> </path/to/mmcblkX>\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; >> -- >> 2.35.1.1320.gc452695387.dirty >>