mmc-utils: Add General command CMD56 read support
PATCH 1/1 mmc-utils: Add General command CMD56 read support
From: Bean Huo <[email protected]>
Micron eMMC offers an additional set of commands that go beyond the JEDEC Device Health Report. These additional DEVICE HEALTH commands are implemented using the generic CMD56 command and they return a significant amount of useful information about the status of the NAND device. Such as bad block counters, block erase counters ,etc. For more information, refer to TN-FC-32: e·MMC Device Health Report.
Since the CMD56 is specified in JEDEC, to make CMD56 universal used and let more users of mmc-utils get the benefit for this. I add CMD56 read, and let the user to input the CMD56 argument, also, here I didn't add data parsing, just print raw data, since it is vendor-specific.
--- mmc.c | 7 +++++++ mmc.h | 2 ++ mmc_cmds.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ mmc_cmds.h | 1 + 4 files changed, 62 insertions(+)
mmc.c +7 -0
@@ -237,6 +237,13 @@ static struct Command commands[] = { "secure-trim1 | secure-trim2 | trim \n", NULL }, + { do_general_cmd_read,-2 , +"gen_cmd read" ,"<arg> <device>\n" +"Send GEN_CMD (CMD56) with specific <arg> to <device> to read vendor\n" +"specific data. <arg> must be 32 bits length hex number prefixed with 0x/0X.\n\n" +"NOTE!: Because this option is only used to read, the bit0 in <arg> must be 1" , +NULL + }, { 0, 0, 0, 0 } };
mmc.h +2 -0
@@ -41,6 +41,8 @@[1] Discard Enable [0] Identify Write Blocks for Erase (or TRIM Enable) R1b */ +#define MMC_GEN_CMD 56/* adtc [31:1] stuff bits. +[0]: RD/WR1 R1 */ #define R1_OUT_OF_RANGE (1 << 31)/* er, c */ #define R1_ADDRESS_ERROR (1 << 30)/* erx, c */
mmc_cmds.c +52 -0
55 lines not on this page · raw message
mmc_cmds.h +1 -0
@@ -46,3 +46,4 @@ int do_read_scr(int argc, char **argv);int do_read_cid (int argc,char **argv);int do_read_csd (int argc,char **argv);int do_erase (int nargs,char **argv); +int do_general_cmd_read (int nargs,char **argv);
Signature · 1 line
2.34.1
Quoted 91 lines
From: Bean Huo <[email protected]>
Micron eMMC offers an additional set of commands that go beyond the JEDEC Device Health Report. These additional DEVICE HEALTH commands are implemented using the generic CMD56 command and they return a significant amount of useful information about the status of the NAND device. Such as bad block counters, block erase counters ,etc. For more information, refer to TN-FC- 32: e·MMC Device Health Report.
Since the CMD56 is specified in JEDEC, to make CMD56 universal used and let more users of mmc-utils get the benefit for this. I add CMD56 read, and let the user to input the CMD56 argument, also, here I didn't add data parsing, just print raw data, since it is vendor-specific.
Signed-off-by Bean Huo <[email protected]>--- mmc.c | 7 +++++++ mmc.h | 2 ++ mmc_cmds.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ mmc_cmds.h | 1 + 4 files changed, 62 insertions(+)mmc.c +3
-0@@ -237,6 +237,13 @@ static struct Command commands[] = {"secure-trim1 | secure-trim2 | trim \n" ,NULL }, + { do_general_cmd_read, -2, +"gen_cmd read" ,"<arg> <device>\n" + "Send GEN_CMD (CMD56) with specific <arg> to <device> to readvendor\n"
+ "specific data. <arg> must be 32 bits length hex number prefixed with
0x/0X.\n\n"
+ "NOTE!: Because this option is only used to read, the bit0 in <arg>
must be 1",mmc.c +2
-0+NULL + }, { 0, 0, 0, 0 } };mmc.h +2
-0@@ -41,6 +41,8 @@[1] Discard Enable [0] Identify Write Blocks for Erase (or TRIM Enable) R1b */ +#define MMC_GEN_CMD 56/* adtc [31:1] stuff bits. +[0]: RD/WR1 R1 */ #define R1_OUT_OF_RANGE (1 << 31)/* er, c */ #define R1_ADDRESS_ERROR (1 << 30)/* erx, c */ mmc_cmds.c +24
-0@@ -2981,3 +2981,55 @@ out:return ret;#endif } + +int do_general_cmd_read (int nargs,char **argv) { +int dev_fd; +__u8 buf[512 ]; +__u32 arg; +char *device; +char *endptr; +int ret = -EINVAL , i; +struct mmc_ioc_cmd idata; + +if (nargs !=3 ) { +fprintf (stderr,"Usage: gen_cmd read <arg> </path/to/mmcblkX>\n" ); +exit (1 ); + } + + device = argv[2 ]; + dev_fd =open (device,O_RDWR ); +if (dev_fd <0 ) { +perror ("device open failed" ); +exit (1 ); + } + arg =strtol (argv[1 ], &endptr,16 ); +if (errno !=0 || *endptr !='\0' || !arg&0x1 ) { + fprintf(stderr, "Wrong ARG, it should be Hex number and bit0 must be1\n");
mmc_cmds.c
Quoted 2 lines
mmc_cmds.c +2
-0+ goto out; + }
One line space
mmc_cmds.c out: · line 3014
Quoted 4 lines
mmc_cmds.c +4
-0+memset (&idata,0 ,sizeof (idata)); + idata.write_flag =0 ; + idata.opcode =MMC_GEN_CMD ; + idata.arg = arg;
Practically arg is not needed, because bits[1..31] are meaningless. Maybe just set: idata.arg = 1;
Thanks,
Avri
Quoted 9 lines · Avri Altman
Quoted 4 lines
+
memset(&idata, 0, sizeof(idata));
+ idata.write_flag = 0;
+ idata.opcode =MMC_GEN_CMD;
+ idata.arg = arg;Practically arg is not needed, because bits[1..31] are meaningless. Maybe just set: idata.arg = 1;
Thanks,
Avri
Thanks for your review.
you are right arg is not needed according to eMMC spec. But as I mentioned in the commit message, for the universal use. we need it for the vendor-specific arg. I will change it that its arg will be 1 by default if the user doesn't specific arg.
Kind regards,
Bean
Quoted 8 lines · Avri Altman
Quoted 7 lines
mmc_cmds.c out: · line 3014
Quoted 4 lines
mmc_cmds.c +4
-0+memset (&idata,0 ,sizeof (idata)); + idata.write_flag =0 ; + idata.opcode =MMC_GEN_CMD ; + idata.arg = arg;Practically arg is not needed, because bits[1..31] are meaningless. Maybe just set: idata.arg = 1;
Quoted 8 lines
Quoted 2 lines
Thanks,
AvriThanks for your review.
you are right arg is not needed according to eMMC spec. But as I mentioned in the commit message, for the universal use. we need it for the vendor- specific arg. I will change it that its arg will be 1 by default if the user doesn't specific arg.
Ack.
Thanks,
Avri
Quoted 5 lines
Kind regards,
Bean
Rossler, Jakob (Nokia - DE/Ulm)
Tested-byBest regards
Jakob
-----Original Message-----
From: Avri Altman <[email protected]>
Sent: Monday, April 11, 2022 12:05 PM
To: Bean Huo <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Rossler, Jakob (Nokia - DE/Ulm) <[email protected]>; [email protected]; Bean Huo <[email protected]>
Subject: RE: [PATCH v1] mmc-utils: Add General command CMD56 read support
Quoted 8 lines · Avri Altman
Quoted 7 lines
mmc_cmds.c out: · line 3014
Quoted 4 lines
mmc_cmds.c +4
-0+memset (&idata,0 ,sizeof (idata)); + idata.write_flag =0 ; + idata.opcode =MMC_GEN_CMD ; + idata.arg = arg;Practically arg is not needed, because bits[1..31] are meaningless. Maybe just set: idata.arg = 1;
Quoted 8 lines
Quoted 2 lines
Thanks,
AvriThanks for your review.
you are right arg is not needed according to eMMC spec. But as I mentioned in the commit message, for the universal use. we need it for the vendor- specific arg. I will change it that its arg will be 1 by default if the user doesn't specific arg.
Ack.
Thanks,
Avri
Quoted 5 lines
Kind regards,
Bean