diff options
author | Saugata Das <saugata.das@linaro.org> | 2012-05-17 09:26:34 -0400 |
---|---|---|
committer | Chris Ball <cjb@laptop.org> | 2012-05-17 09:31:12 -0400 |
commit | b7e2599c67408c38e57e91d2426c077a4541dc8c (patch) | |
tree | 3b503b3ff1849966bbb2c4f7dd46f5591c8a1c3c | |
parent | 8ba4466a4ad458618282f8bdcc2706025856a9f2 (diff) | |
download | mmc-utils-b7e2599c67408c38e57e91d2426c077a4541dc8c.tar.gz |
Add support for disabling 512B emulation
In this patch, we add a utility to disable emulation mode in eMMC-4.5.
This is done to increase the data sector size to 4KB.
Signed-off-by: Saugata Das <saugata.das@linaro.org>
Reviewed-by: Subhash Jadavani <subhashj@codeaurora.org>
Reviewed-by: Namjae Jeon <linkinjeon@gmail.com>
Reviewed-by: Subhash Jadavani <subhashj@codeaurora.org>
Signed-off-by: Chris Ball <cjb@laptop.org>
-rw-r--r-- | mmc.c | 5 | ||||
-rw-r--r-- | mmc.h | 12 | ||||
-rw-r--r-- | mmc_cmds.c | 45 | ||||
-rw-r--r-- | mmc_cmds.h | 1 |
4 files changed, 61 insertions, 2 deletions
@@ -65,6 +65,11 @@ static struct Command commands[] = { "Set the eMMC writeprotect status of <device>.", NULL }, + { do_disable_512B_emulation, -1, + "disable 512B emulation", "<device>\n" + "Set the eMMC data sector size to 4KB by disabling emulation on <device>.", + NULL + }, { do_write_boot_en, -3, "bootpart enable", "<boot_partition> " "<send_ack> " "<device>\n" "Enable the boot partition for the <device>.\nTo receive acknowledgment of boot from the card set <send_ack>\nto 1, else set it to 0.", @@ -34,8 +34,18 @@ #define EXT_CSD_BOOT_INFO 228 /* R/W */ #define EXT_CSD_PART_SWITCH_TIME 199 #define EXT_CSD_BOOT_CFG 179 -#define EXT_CSD_BOOT_WP 173 #define EXT_CSD_PART_CONFIG 179 +#define EXT_CSD_BOOT_WP 173 +#define EXT_CSD_WR_REL_PARAM 166 +#define EXT_CSD_NATIVE_SECTOR_SIZE 63 /* R */ +#define EXT_CSD_USE_NATIVE_SECTOR 62 /* R/W */ +#define EXT_CSD_DATA_SECTOR_SIZE 61 /* R */ + +/* + * WR_REL_PARAM field definitions + */ +#define HS_CTRL_REL (1<<0) +#define EN_REL_WR (1<<2) /* * EXT_CSD field definitions @@ -170,6 +170,50 @@ int do_writeprotect_set(int nargs, char **argv) return ret; } +int do_disable_512B_emulation(int nargs, char **argv) +{ + __u8 ext_csd[512], native_sector_size, data_sector_size, wr_rel_param; + int fd, ret; + char *device; + + CHECK(nargs != 2, "Usage: mmc disable 512B emulation </path/to/mmcblkX>\n", exit(1)); + device = argv[1]; + + fd = open(device, O_RDWR); + if (fd < 0) { + perror("open"); + exit(1); + } + + ret = read_extcsd(fd, ext_csd); + if (ret) { + fprintf(stderr, "Could not read EXT_CSD from %s\n", device); + exit(1); + } + + wr_rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; + native_sector_size = ext_csd[EXT_CSD_NATIVE_SECTOR_SIZE]; + data_sector_size = ext_csd[EXT_CSD_DATA_SECTOR_SIZE]; + + if (native_sector_size && !data_sector_size && + (wr_rel_param & EN_REL_WR)) { + ret = write_extcsd_value(fd, EXT_CSD_USE_NATIVE_SECTOR, 1); + + if (ret) { + fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n", + 1, EXT_CSD_BOOT_WP, device); + exit(1); + } + printf("MMC disable 512B emulation successful. Now reset the device to switch to 4KB native sector mode.\n"); + } else if (native_sector_size && data_sector_size) { + printf("MMC 512B emulation mode is already disabled; doing nothing.\n"); + } else { + printf("MMC does not support disabling 512B emulation mode.\n"); + } + + return ret; +} + int do_write_boot_en(int nargs, char **argv) { __u8 ext_csd[512]; @@ -236,7 +280,6 @@ int do_write_boot_en(int nargs, char **argv) return ret; } - int do_read_extcsd(int nargs, char **argv) { __u8 ext_csd[512], ext_csd_rev, reg; @@ -19,4 +19,5 @@ int do_read_extcsd(int nargs, char **argv); int do_write_extcsd(int nargs, char **argv); int do_writeprotect_get(int nargs, char **argv); int do_writeprotect_set(int nargs, char **argv); +int do_disable_512B_emulation(int nargs, char **argv); int do_write_boot_en(int nargs, char **argv); |