Message ID | 1336574901-26579-2-git-send-email-saugata.das@stericsson.com |
---|---|
State | New |
Headers | show |
On 5/9/2012 8:18 PM, Saugata Das wrote: > From: Saugata Das<saugata.das@linaro.org> > > In this patch, we add utility to disable emulation mode in the eMMC-4.5. > This is done to increase the data sector size to 4KB. > > Signed-off-by: Saugata Das<saugata.das@linaro.org> > --- > mmc.c | 6 ++++++ > mmc.h | 2 ++ > mmc_cmds.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > mmc_cmds.h | 1 + > 4 files changed, 51 insertions(+), 0 deletions(-) > > diff --git a/mmc.c b/mmc.c > index c27fc24..43b95aa 100644 > --- a/mmc.c > +++ b/mmc.c > @@ -65,6 +65,12 @@ static struct Command commands[] = { > "Set the eMMC writeprotect status of<device>.", > NULL > }, > + { do_disable_emulation, -1, can we add good name? which emulation we are disabling? It's 512B emulation mode, we are disabling. > + "disable emulation", "<device>\n" > + "Set the eMMC data sector size to 4KB by disabling emulation<device>.", > + NULL > + }, > + > { 0, 0, 0, 0 } > }; > > diff --git a/mmc.h b/mmc.h > index 3af36f1..a2050fa 100644 > --- a/mmc.h > +++ b/mmc.h > @@ -35,6 +35,8 @@ > #define EXT_CSD_PART_SWITCH_TIME 199 > #define EXT_CSD_BOOT_CFG 179 > #define EXT_CSD_BOOT_WP 173 > +#define EXT_CSD_NATIVE_SECTOR_SIZE 63 /* R */ > +#define EXT_CSD_NATIVE_SECTOR 62 /* R/W */ Can we name this as EXT_CSD_USE_NATIVE_SECTOR? > > /* > * EXT_CSD field definitions > diff --git a/mmc_cmds.c b/mmc_cmds.c > index 4562cef..2713ccd 100644 > --- a/mmc_cmds.c > +++ b/mmc_cmds.c > @@ -168,6 +168,48 @@ int do_writeprotect_set(int nargs, char **argv) > return ret; > } > > + > +int do_disable_emulation(int nargs, char **argv) > +{ > + __u8 ext_csd[512], native_sector_size; > + int fd, ret; > + char *device; > + > + CHECK(nargs != 2, "Usage: mmc</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); > + } > + > + native_sector_size = ext_csd[EXT_CSD_NATIVE_SECTOR_SIZE]; > + > + if (native_sector_size) { > + ret = write_extcsd_value(fd, EXT_CSD_NATIVE_SECTOR, 1); Just curious, how are we going to power cycle the device after setting the USE_NATIVE_SECTOR? because DATA_SECTOR_SIZE won't be changed to 4K until we explicitly power cycle after setting this field. > + > + if (ret) { > + fprintf(stderr, "Could not write 0x%02x to " > + "EXT_CSD[%d] in %s\n", > + 1, EXT_CSD_BOOT_WP, device); > + exit(1); > + } > + } else { > + printf("MMC does not support 4KB native sector\n"); > + } > + > + return ret; > +} > + > + > int do_read_extcsd(int nargs, char **argv) > { > __u8 ext_csd[512], ext_csd_rev, reg; > diff --git a/mmc_cmds.h b/mmc_cmds.h > index 66e9acb..dd107d5 100644 > --- a/mmc_cmds.h > +++ b/mmc_cmds.h > @@ -19,3 +19,4 @@ 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_emulation(int nargs, char **argv);
On 5/9/2012 8:18 PM, Saugata Das wrote: > From: Saugata Das<saugata.das@linaro.org> > > In this patch, we add utility to disable emulation mode in the eMMC-4.5. > This is done to increase the data sector size to 4KB. > > Signed-off-by: Saugata Das<saugata.das@linaro.org> > --- > mmc.c | 6 ++++++ > mmc.h | 2 ++ > mmc_cmds.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > mmc_cmds.h | 1 + > 4 files changed, 51 insertions(+), 0 deletions(-) > > diff --git a/mmc.c b/mmc.c > index c27fc24..43b95aa 100644 > --- a/mmc.c > +++ b/mmc.c > @@ -65,6 +65,12 @@ static struct Command commands[] = { > "Set the eMMC writeprotect status of<device>.", > NULL > }, > + { do_disable_emulation, -1, > + "disable emulation", "<device>\n" > + "Set the eMMC data sector size to 4KB by disabling emulation<device>.", > + NULL > + }, > + > { 0, 0, 0, 0 } > }; > > diff --git a/mmc.h b/mmc.h > index 3af36f1..a2050fa 100644 > --- a/mmc.h > +++ b/mmc.h > @@ -35,6 +35,8 @@ > #define EXT_CSD_PART_SWITCH_TIME 199 > #define EXT_CSD_BOOT_CFG 179 > #define EXT_CSD_BOOT_WP 173 > +#define EXT_CSD_NATIVE_SECTOR_SIZE 63 /* R */ > +#define EXT_CSD_NATIVE_SECTOR 62 /* R/W */ > > /* > * EXT_CSD field definitions > diff --git a/mmc_cmds.c b/mmc_cmds.c > index 4562cef..2713ccd 100644 > --- a/mmc_cmds.c > +++ b/mmc_cmds.c > @@ -168,6 +168,48 @@ int do_writeprotect_set(int nargs, char **argv) > return ret; > } > > + > +int do_disable_emulation(int nargs, char **argv) > +{ > + __u8 ext_csd[512], native_sector_size; > + int fd, ret; > + char *device; > + > + CHECK(nargs != 2, "Usage: mmc</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); > + } > + > + native_sector_size = ext_csd[EXT_CSD_NATIVE_SECTOR_SIZE]; > + > + if (native_sector_size) { Before setting the use_native_sector field, can you also check if NATIVE_SECTOR_SIZE and DATA_SECTOR_SIZE fields are different. If they are same then there is no need to set the USE_NATIVE_SECTOR size field. > + ret = write_extcsd_value(fd, EXT_CSD_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); > + } > + } else { > + printf("MMC does not support 4KB native sector\n"); > + } > + > + return ret; > +} > + > + > int do_read_extcsd(int nargs, char **argv) > { > __u8 ext_csd[512], ext_csd_rev, reg; > diff --git a/mmc_cmds.h b/mmc_cmds.h > index 66e9acb..dd107d5 100644 > --- a/mmc_cmds.h > +++ b/mmc_cmds.h > @@ -19,3 +19,4 @@ 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_emulation(int nargs, char **argv);
On 14 May 2012 16:20, Subhash Jadavani <subhashj@codeaurora.org> wrote: > On 5/9/2012 8:18 PM, Saugata Das wrote: >> >> From: Saugata Das<saugata.das@linaro.org> >> >> In this patch, we add utility to disable emulation mode in the eMMC-4.5. >> This is done to increase the data sector size to 4KB. >> >> Signed-off-by: Saugata Das<saugata.das@linaro.org> >> --- >> mmc.c | 6 ++++++ >> mmc.h | 2 ++ >> mmc_cmds.c | 42 ++++++++++++++++++++++++++++++++++++++++++ >> mmc_cmds.h | 1 + >> 4 files changed, 51 insertions(+), 0 deletions(-) >> >> diff --git a/mmc.c b/mmc.c >> index c27fc24..43b95aa 100644 >> --- a/mmc.c >> +++ b/mmc.c >> @@ -65,6 +65,12 @@ static struct Command commands[] = { >> "Set the eMMC writeprotect status of<device>.", >> NULL >> }, >> + { do_disable_emulation, -1, >> + "disable emulation", "<device>\n" >> + "Set the eMMC data sector size to 4KB by disabling >> emulation<device>.", >> + NULL >> + }, >> + >> { 0, 0, 0, 0 } >> }; >> >> diff --git a/mmc.h b/mmc.h >> index 3af36f1..a2050fa 100644 >> --- a/mmc.h >> +++ b/mmc.h >> @@ -35,6 +35,8 @@ >> #define EXT_CSD_PART_SWITCH_TIME 199 >> #define EXT_CSD_BOOT_CFG 179 >> #define EXT_CSD_BOOT_WP 173 >> +#define EXT_CSD_NATIVE_SECTOR_SIZE 63 /* R */ >> +#define EXT_CSD_NATIVE_SECTOR 62 /* R/W */ >> >> /* >> * EXT_CSD field definitions >> diff --git a/mmc_cmds.c b/mmc_cmds.c >> index 4562cef..2713ccd 100644 >> --- a/mmc_cmds.c >> +++ b/mmc_cmds.c >> @@ -168,6 +168,48 @@ int do_writeprotect_set(int nargs, char **argv) >> return ret; >> } >> >> + >> +int do_disable_emulation(int nargs, char **argv) >> +{ >> + __u8 ext_csd[512], native_sector_size; >> + int fd, ret; >> + char *device; >> + >> + CHECK(nargs != 2, "Usage: mmc</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); >> + } >> + >> + native_sector_size = ext_csd[EXT_CSD_NATIVE_SECTOR_SIZE]; >> + >> + if (native_sector_size) { > > Before setting the use_native_sector field, can you also check if > NATIVE_SECTOR_SIZE and DATA_SECTOR_SIZE fields are different. If they are > same then there is no need to set the USE_NATIVE_SECTOR size field. > Ok > >> + ret = write_extcsd_value(fd, EXT_CSD_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); >> + } >> + } else { >> + printf("MMC does not support 4KB native sector\n"); >> + } >> + >> + return ret; >> +} >> + >> + >> int do_read_extcsd(int nargs, char **argv) >> { >> __u8 ext_csd[512], ext_csd_rev, reg; >> diff --git a/mmc_cmds.h b/mmc_cmds.h >> index 66e9acb..dd107d5 100644 >> --- a/mmc_cmds.h >> +++ b/mmc_cmds.h >> @@ -19,3 +19,4 @@ 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_emulation(int nargs, char **argv); > >
On 14 May 2012 16:09, Subhash Jadavani <subhashj@codeaurora.org> wrote: > On 5/9/2012 8:18 PM, Saugata Das wrote: >> >> From: Saugata Das<saugata.das@linaro.org> >> >> In this patch, we add utility to disable emulation mode in the eMMC-4.5. >> This is done to increase the data sector size to 4KB. >> >> Signed-off-by: Saugata Das<saugata.das@linaro.org> >> --- >> mmc.c | 6 ++++++ >> mmc.h | 2 ++ >> mmc_cmds.c | 42 ++++++++++++++++++++++++++++++++++++++++++ >> mmc_cmds.h | 1 + >> 4 files changed, 51 insertions(+), 0 deletions(-) >> >> diff --git a/mmc.c b/mmc.c >> index c27fc24..43b95aa 100644 >> --- a/mmc.c >> +++ b/mmc.c >> @@ -65,6 +65,12 @@ static struct Command commands[] = { >> "Set the eMMC writeprotect status of<device>.", >> NULL >> }, >> + { do_disable_emulation, -1, > > can we add good name? which emulation we are disabling? It's 512B emulation > mode, we are disabling. > Ok >> + "disable emulation", "<device>\n" >> + "Set the eMMC data sector size to 4KB by disabling >> emulation<device>.", >> + NULL >> + }, >> + >> { 0, 0, 0, 0 } >> }; >> >> diff --git a/mmc.h b/mmc.h >> index 3af36f1..a2050fa 100644 >> --- a/mmc.h >> +++ b/mmc.h >> @@ -35,6 +35,8 @@ >> #define EXT_CSD_PART_SWITCH_TIME 199 >> #define EXT_CSD_BOOT_CFG 179 >> #define EXT_CSD_BOOT_WP 173 >> +#define EXT_CSD_NATIVE_SECTOR_SIZE 63 /* R */ >> +#define EXT_CSD_NATIVE_SECTOR 62 /* R/W */ > > Can we name this as EXT_CSD_USE_NATIVE_SECTOR? > Ok >> >> /* >> * EXT_CSD field definitions >> diff --git a/mmc_cmds.c b/mmc_cmds.c >> index 4562cef..2713ccd 100644 >> --- a/mmc_cmds.c >> +++ b/mmc_cmds.c >> @@ -168,6 +168,48 @@ int do_writeprotect_set(int nargs, char **argv) >> return ret; >> } >> >> + >> +int do_disable_emulation(int nargs, char **argv) >> +{ >> + __u8 ext_csd[512], native_sector_size; >> + int fd, ret; >> + char *device; >> + >> + CHECK(nargs != 2, "Usage: mmc</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); >> + } >> + >> + native_sector_size = ext_csd[EXT_CSD_NATIVE_SECTOR_SIZE]; >> + >> + if (native_sector_size) { >> + ret = write_extcsd_value(fd, EXT_CSD_NATIVE_SECTOR, 1); > > Just curious, how are we going to power cycle the device after setting the > USE_NATIVE_SECTOR? because DATA_SECTOR_SIZE won't be changed to 4K until we > explicitly power cycle after setting this field. > I will add a "printf" instructing the user to power cycle the eMMC at the end of the switch. >> + >> + if (ret) { >> + fprintf(stderr, "Could not write 0x%02x to " >> + "EXT_CSD[%d] in %s\n", >> + 1, EXT_CSD_BOOT_WP, device); >> + exit(1); >> + } >> + } else { >> + printf("MMC does not support 4KB native sector\n"); >> + } >> + >> + return ret; >> +} >> + >> + >> int do_read_extcsd(int nargs, char **argv) >> { >> __u8 ext_csd[512], ext_csd_rev, reg; >> diff --git a/mmc_cmds.h b/mmc_cmds.h >> index 66e9acb..dd107d5 100644 >> --- a/mmc_cmds.h >> +++ b/mmc_cmds.h >> @@ -19,3 +19,4 @@ 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_emulation(int nargs, char **argv); > >
diff --git a/mmc.c b/mmc.c index c27fc24..43b95aa 100644 --- a/mmc.c +++ b/mmc.c @@ -65,6 +65,12 @@ static struct Command commands[] = { "Set the eMMC writeprotect status of <device>.", NULL }, + { do_disable_emulation, -1, + "disable emulation", "<device>\n" + "Set the eMMC data sector size to 4KB by disabling emulation <device>.", + NULL + }, + { 0, 0, 0, 0 } }; diff --git a/mmc.h b/mmc.h index 3af36f1..a2050fa 100644 --- a/mmc.h +++ b/mmc.h @@ -35,6 +35,8 @@ #define EXT_CSD_PART_SWITCH_TIME 199 #define EXT_CSD_BOOT_CFG 179 #define EXT_CSD_BOOT_WP 173 +#define EXT_CSD_NATIVE_SECTOR_SIZE 63 /* R */ +#define EXT_CSD_NATIVE_SECTOR 62 /* R/W */ /* * EXT_CSD field definitions diff --git a/mmc_cmds.c b/mmc_cmds.c index 4562cef..2713ccd 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -168,6 +168,48 @@ int do_writeprotect_set(int nargs, char **argv) return ret; } + +int do_disable_emulation(int nargs, char **argv) +{ + __u8 ext_csd[512], native_sector_size; + int fd, ret; + char *device; + + CHECK(nargs != 2, "Usage: mmc </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); + } + + native_sector_size = ext_csd[EXT_CSD_NATIVE_SECTOR_SIZE]; + + if (native_sector_size) { + ret = write_extcsd_value(fd, EXT_CSD_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); + } + } else { + printf("MMC does not support 4KB native sector\n"); + } + + return ret; +} + + int do_read_extcsd(int nargs, char **argv) { __u8 ext_csd[512], ext_csd_rev, reg; diff --git a/mmc_cmds.h b/mmc_cmds.h index 66e9acb..dd107d5 100644 --- a/mmc_cmds.h +++ b/mmc_cmds.h @@ -19,3 +19,4 @@ 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_emulation(int nargs, char **argv);