diff options
Diffstat (limited to 'commands/mmc.c')
-rw-r--r-- | commands/mmc.c | 124 |
1 files changed, 105 insertions, 19 deletions
diff --git a/commands/mmc.c b/commands/mmc.c index c696e7b881..fa01b89cdf 100644 --- a/commands/mmc.c +++ b/commands/mmc.c @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: GPL-2.0-only + #include <command.h> #include <mci.h> #include <stdio.h> @@ -63,23 +65,6 @@ static int mmc_partitioning_complete(struct mci *mci) return ret; } -static u8 *mci_get_ext_csd(struct mci *mci) -{ - u8 *ext_csd; - int ret; - - ext_csd = xmalloc(512); - - ret = mci_send_ext_csd(mci, ext_csd); - if (ret) { - printf("Failure to read EXT_CSD register\n"); - free(ext_csd); - return ERR_PTR(-EIO); - } - - return ext_csd; -} - /* enh_area [-c] /dev/mmcX */ static int do_mmc_enh_area(int argc, char *argv[]) { @@ -93,6 +78,7 @@ static int do_mmc_enh_area(int argc, char *argv[]) while ((opt = getopt(argc, argv, "c")) > 0) { switch (opt) { case 'c': + printf("Use -c to complete the partitioning is deprecated, use separate partition_complete command instead\n"); set_completed = 1; break; } @@ -145,6 +131,95 @@ error: return COMMAND_ERROR; } +static int do_mmc_write_reliability(int argc, char *argv[]) +{ + const char *devpath; + struct mci *mci; + u8 *ext_csd; + + if (argc - optind != 1) { + printf("Usage: mmc write_reliability /dev/mmcX\n"); + return COMMAND_ERROR_USAGE; + } + + devpath = argv[optind]; + + mci = mci_get_device_by_devpath(devpath); + if (!mci) { + printf("Failure to open %s as mci device\n", devpath); + return COMMAND_ERROR; + } + + ext_csd = mci_get_ext_csd(mci); + if (IS_ERR(ext_csd)) + return COMMAND_ERROR; + + if (ext_csd[EXT_CSD_PARTITION_SETTING_COMPLETED]) { + printf("Partitioning already finalized\n"); + goto error; + } + + if (!(ext_csd[EXT_CSD_WR_REL_PARAM] & EXT_CSD_EN_REL_WR)) { + printf("Device doesn't support the enhanced definition of reliable write\n"); + goto error; + } + + if (!(ext_csd[EXT_CSD_WR_REL_PARAM] & EXT_CSD_HS_CTRL_REL)) { + printf("Device doesn't support WR_REL_SET writes\n"); + goto error; + } + + /* + * Host has one opportunity to write all of the bits. Separate writes to + * individual bits are not permitted so set all bits for now. + */ + if ((ext_csd[EXT_CSD_WR_REL_SET] & 0x1f) != 0x1f) { + int ret; + + ret = mci_switch(mci, EXT_CSD_WR_REL_SET, 0x1f); + if (ret) { + printf("Failure to write to EXT_CSD_WR_REL_SET\n"); + goto error; + } + } + + free(ext_csd); + + return COMMAND_SUCCESS; + +error: + free(ext_csd); + return COMMAND_ERROR; +} + +static int do_mmc_partition_complete(int argc, char *argv[]) +{ + const char *devpath; + struct mci *mci; + int ret; + + if (argc - optind != 1) { + printf("Usage: mmc partition_complete /dev/mmcX\n"); + return COMMAND_ERROR_USAGE; + } + + devpath = argv[optind]; + + mci = mci_get_device_by_devpath(devpath); + if (!mci) { + printf("Failure to open %s as mci device\n", devpath); + return COMMAND_ERROR_USAGE; + } + + ret = mmc_partitioning_complete(mci); + if (ret) + return COMMAND_ERROR; + + printf("Now power cycle the device to let it reconfigure itself.\n"); + + return COMMAND_SUCCESS; +} + static struct { const char *cmd; int (*func)(int argc, char *argv[]); @@ -152,6 +227,12 @@ static struct { { .cmd = "enh_area", .func = do_mmc_enh_area, + }, { + .cmd = "write_reliability", + .func = do_mmc_write_reliability, + }, { + .cmd = "partition_complete", + .func = do_mmc_partition_complete, } }; @@ -186,11 +267,16 @@ BAREBOX_CMD_HELP_TEXT("") BAREBOX_CMD_HELP_TEXT("The subcommand enh_area creates an enhanced area of") BAREBOX_CMD_HELP_TEXT("maximal size.") BAREBOX_CMD_HELP_TEXT("Note, with -c this is an irreversible action.") -BAREBOX_CMD_HELP_OPT("-c", "complete partitioning") +BAREBOX_CMD_HELP_OPT("-c", "complete partitioning (deprecated)") +BAREBOX_CMD_HELP_TEXT("") +BAREBOX_CMD_HELP_TEXT("The subcommand write_reliability enable write reliability") +BAREBOX_CMD_HELP_TEXT("") +BAREBOX_CMD_HELP_TEXT("The subcommand partition_complete set PARTITION_SETTING_COMPLETED (irreversible action)") BAREBOX_CMD_HELP_END BAREBOX_CMD_START(mmc) .cmd = do_mmc, - BAREBOX_CMD_OPTS("enh_area [-c] /dev/mmcX") + BAREBOX_CMD_OPTS("partition_complete|write_reliability|enh_area [-c] /dev/mmcX") + BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP) BAREBOX_CMD_HELP(cmd_mmc_help) BAREBOX_CMD_END |