Skip to contentSkip to conversation

cmd: mmc: Add mmc reg read command for reading card registers

PATCH New Marek Vasut 3 participants 6 messages Jun 20, 2020 – Jun 24, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmd: mmc: Add mmc reg read command for reading card registers

Add extension to the 'mmc' command to read out the card registers. Currently, only the eMMC OCR/CID/CSD/EXTCSD/RCA/DSR register are supported. A register value can either be displayed or read into an environment variable.

---
 cmd/Kconfig |  8 +++++
 cmd/mmc.c   | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+)
cmd/Kconfig +8 -0
index 192b3b262f..a0cf03c911 100644
@@ -1104,6 +1104,14 @@ config CMD_BKOPS_ENABLE
 	  on a eMMC device. The feature is optionally available on eMMC devices
 	  conforming to standard >= 4.41.
 
+config CMD_MMC_REG
+	bool "Enable support for reading card registers in the mmc command"
+	depends on CMD_MMC
+	default y
+	help
+	  Enable the commands for reading card registers. This is useful
+	  mostly for debugging or extracting details from the card.
+
 config CMD_MMC_RPMB
 	bool "Enable support for RPMB in the mmc command"
 	depends on SUPPORT_EMMC_RPMB
cmd/mmc.c +94 -0

112 lines not on this page · raw message

Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/1 cmd: mmc: Add mmc reg read command for reading card registers

Hi

Quoted 51 lines · Marek Vasut

Add extension to the 'mmc' command to read out the card registers. Currently, only the eMMC OCR/CID/CSD/EXTCSD/RCA/DSR register are supported. A register value can either be displayed or read into an environment variable.

---
 cmd/Kconfig |  8 +++++
 cmd/mmc.c   | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+)
cmd/Kconfig +8 -0
index 192b3b262f..a0cf03c911 100644
@@ -1104,6 +1104,14 @@ config CMD_BKOPS_ENABLE
          on a eMMC device. The feature is optionally available on eMMC devices
          conforming to standard >= 4.41.
 
+config CMD_MMC_REG
+       bool "Enable support for reading card registers in the mmc command"
+       depends on CMD_MMC
+       default y
+       help
+         Enable the commands for reading card registers. This is useful
+         mostly for debugging or extracting details from the card.
+
 config CMD_MMC_RPMB
        bool "Enable support for RPMB in the mmc command"
        depends on SUPPORT_EMMC_RPMB
cmd/mmc.c +12 -0
index 1529a3e05d..55fbfe822e 100644
@@ -912,6 +912,93 @@ static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag,
 }
 #endif
 
+#if CONFIG_IS_ENABLED(CMD_MMC_REG)
+static int do_mmc_reg(struct cmd_tbl *cmdtp, int flag,
+                        int argc, char *const argv[])
+{
+       ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
+       struct mmc *mmc;
+       int i, ret;
+       u32 off;
+
+       if (argc < 3 || argc > 5)
+               return CMD_RET_USAGE;
+

cmd/mmc.c static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag, · line 936

Quoted 10 lines
cmd/mmc.c +10 -0
+       mmc = find_mmc_device(curr_device);
+       if (!mmc) {
+               printf("no mmc device at slot %x\n", curr_device);
+               return CMD_RET_FAILURE;
+       }
+
+       if (IS_SD(mmc)) {
+               printf("SD registers are not supported\n");
+               return CMD_RET_FAILURE;
+       } else {

else is not needed

Quoted 27 lines
cmd/mmc.c +27 -0
+               off = simple_strtoul(argv[3], NULL, 10);
+               if (!strcmp(argv[2], "cid")) {
+                       if (off > 1)
+                               return CMD_RET_USAGE;
+                       printf("CID[%i]: 0x%08x\n", off, mmc->cid[off]);
+                       if (argv[4])
+                               env_set_hex(argv[4], mmc->cid[off]);
+                       return CMD_RET_SUCCESS;
+               }
+               if (!strcmp(argv[2], "csd")) {
+                       if (off > 3)
+                               return CMD_RET_USAGE;
+                       printf("CSD[%i]: 0x%08x\n", off, mmc->csd[off]);
+                       if (argv[4])
+                               env_set_hex(argv[4], mmc->csd[off]);
+                       return CMD_RET_SUCCESS;
+               }
+               if (!strcmp(argv[2], "dsr")) {
+                       printf("DSR: 0x%08x\n", mmc->dsr);
+                       if (argv[4])
+                               env_set_hex(argv[4], mmc->dsr);
+                       return CMD_RET_SUCCESS;
+               }
+               if (!strcmp(argv[2], "ocr")) {
+                       printf("OCR: 0x%08x\n", mmc->ocr);
+                       if (argv[4])
+                               env_set_hex(argv[4], mmc->ocr);

cmd/mmc.c static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag, · line 973

Quoted 10 lines
cmd/mmc.c +10 -0
+                       return CMD_RET_SUCCESS;
+               }
+               if (!strcmp(argv[2], "rca")) {
+                       printf("RCA: 0x%08x\n", mmc->rca);
+                       if (argv[4])
+                               env_set_hex(argv[4], mmc->rca);
+                       return CMD_RET_SUCCESS;
+               }
+               if (!strcmp(argv[2], "extcsd") &&
+                   mmc->version >= MMC_VERSION_4_41) {

Can you factorize all the conditions?
string, function

Even use strcmp("extcsd", arg

Michael

Quoted 55 lines
cmd/mmc.c +35 -1
+                       ret = mmc_send_ext_csd(mmc, ext_csd);
+                       if (ret)
+                               return ret;
+                       if (!strcmp(argv[3], "all")) {
+                               /* Dump the entire register */
+                               printf("EXT_CSD:");
+                               for (i = 0; i < MMC_MAX_BLOCK_LEN; i++) {
+                                       if (!(i % 10))
+                                               printf("\n%03i: ", i);
+                                       printf(" %02x", ext_csd[i]);
+                               }
+                               printf("\n");
+                               return CMD_RET_SUCCESS;
+                       }
+                       off = simple_strtoul(argv[3], NULL, 10);
+                       if (off > 512)
+                               return CMD_RET_USAGE;
+                       printf("EXT_CSD[%i]: 0x%02x\n", off, ext_csd[off]);
+                       if (argv[4])
+                               env_set_hex(argv[4], ext_csd[off]);
+                       return CMD_RET_SUCCESS;
+               }
+       }
+
+       return CMD_RET_FAILURE;
+}
+#endif
+
 static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
                          int argc, char * const argv[])
 {
@@ -963,6 +1050,9 @@ static struct cmd_tbl cmd_mmc[] = {
 #ifdef CONFIG_CMD_BKOPS_ENABLE
        U_BOOT_CMD_MKENT(bkops-enable, 2, 0, do_mmc_bkops_enable, "", ""),
 #endif
+#if CONFIG_IS_ENABLED(CMD_MMC_REG)
+       U_BOOT_CMD_MKENT(reg, 5, 0, do_mmc_reg, "", ""),
+#endif
 };
 
 static int do_mmcops(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -1037,6 +1127,10 @@ U_BOOT_CMD(
 #ifdef CONFIG_CMD_BKOPS_ENABLE
        "mmc bkops-enable <dev> - enable background operations handshake on device\n"
        "   WARNING: This is a write-once setting.\n"
+#endif
+#if CONFIG_IS_ENABLED(CMD_MMC_REG)
+       "mmc reg read <reg> <offset> [env] - read card register <reg> offset <offset>\n"
+       "   (optionally into [env] variable)\n"
 #endif
        );
 
--

2.27.0

Signature · 4 lines
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
#2 lore raw

PATCH 1/1 cmd: mmc: Add mmc reg read command for reading card registers

Hi

Quoted 106 lines · Michael Nazzareno Trimarchi

Hi

Quoted 51 lines · Marek Vasut

Add extension to the 'mmc' command to read out the card registers. Currently, only the eMMC OCR/CID/CSD/EXTCSD/RCA/DSR register are supported. A register value can either be displayed or read into an environment variable.

---
 cmd/Kconfig |  8 +++++
 cmd/mmc.c   | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+)
cmd/Kconfig +8 -0
index 192b3b262f..a0cf03c911 100644
@@ -1104,6 +1104,14 @@ config CMD_BKOPS_ENABLE
          on a eMMC device. The feature is optionally available on eMMC devices
          conforming to standard >= 4.41.
 
+config CMD_MMC_REG
+       bool "Enable support for reading card registers in the mmc command"
+       depends on CMD_MMC
+       default y
+       help
+         Enable the commands for reading card registers. This is useful
+         mostly for debugging or extracting details from the card.
+
 config CMD_MMC_RPMB
        bool "Enable support for RPMB in the mmc command"
        depends on SUPPORT_EMMC_RPMB
cmd/mmc.c +12 -0
index 1529a3e05d..55fbfe822e 100644
@@ -912,6 +912,93 @@ static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag,
 }
 #endif
 
+#if CONFIG_IS_ENABLED(CMD_MMC_REG)
+static int do_mmc_reg(struct cmd_tbl *cmdtp, int flag,
+                        int argc, char *const argv[])
+{
+       ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
+       struct mmc *mmc;
+       int i, ret;
+       u32 off;
+
+       if (argc < 3 || argc > 5)
+               return CMD_RET_USAGE;
+

cmd/mmc.c static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag, · line 936

Quoted 10 lines
cmd/mmc.c +10 -0
+       mmc = find_mmc_device(curr_device);
+       if (!mmc) {
+               printf("no mmc device at slot %x\n", curr_device);
+               return CMD_RET_FAILURE;
+       }
+
+       if (IS_SD(mmc)) {
+               printf("SD registers are not supported\n");
+               return CMD_RET_FAILURE;
+       } else {

else is not needed

Quoted 27 lines
cmd/mmc.c +27 -0
+               off = simple_strtoul(argv[3], NULL, 10);
+               if (!strcmp(argv[2], "cid")) {
+                       if (off > 1)
+                               return CMD_RET_USAGE;
+                       printf("CID[%i]: 0x%08x\n", off, mmc->cid[off]);
+                       if (argv[4])
+                               env_set_hex(argv[4], mmc->cid[off]);
+                       return CMD_RET_SUCCESS;
+               }
+               if (!strcmp(argv[2], "csd")) {
+                       if (off > 3)
+                               return CMD_RET_USAGE;
+                       printf("CSD[%i]: 0x%08x\n", off, mmc->csd[off]);
+                       if (argv[4])
+                               env_set_hex(argv[4], mmc->csd[off]);
+                       return CMD_RET_SUCCESS;
+               }
+               if (!strcmp(argv[2], "dsr")) {
+                       printf("DSR: 0x%08x\n", mmc->dsr);
+                       if (argv[4])
+                               env_set_hex(argv[4], mmc->dsr);
+                       return CMD_RET_SUCCESS;
+               }
+               if (!strcmp(argv[2], "ocr")) {
+                       printf("OCR: 0x%08x\n", mmc->ocr);
+                       if (argv[4])
+                               env_set_hex(argv[4], mmc->ocr);

cmd/mmc.c static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag, · line 973

Quoted 10 lines
cmd/mmc.c +10 -0
+                       return CMD_RET_SUCCESS;
+               }
+               if (!strcmp(argv[2], "rca")) {
+                       printf("RCA: 0x%08x\n", mmc->rca);
+                       if (argv[4])
+                               env_set_hex(argv[4], mmc->rca);
+                       return CMD_RET_SUCCESS;
+               }
+               if (!strcmp(argv[2], "extcsd") &&
+                   mmc->version >= MMC_VERSION_4_41) {
Quoted 4 lines

Can you factorize all the conditions?
string, function

Even use strcmp("extcsd", arg

Sorry for the last comment, I was a bit sleeping

Michael

Quoted 61 lines

Michael

Quoted 53 lines
cmd/mmc.c +35 -1
+                       ret = mmc_send_ext_csd(mmc, ext_csd);
+                       if (ret)
+                               return ret;
+                       if (!strcmp(argv[3], "all")) {
+                               /* Dump the entire register */
+                               printf("EXT_CSD:");
+                               for (i = 0; i < MMC_MAX_BLOCK_LEN; i++) {
+                                       if (!(i % 10))
+                                               printf("\n%03i: ", i);
+                                       printf(" %02x", ext_csd[i]);
+                               }
+                               printf("\n");
+                               return CMD_RET_SUCCESS;
+                       }
+                       off = simple_strtoul(argv[3], NULL, 10);
+                       if (off > 512)
+                               return CMD_RET_USAGE;
+                       printf("EXT_CSD[%i]: 0x%02x\n", off, ext_csd[off]);
+                       if (argv[4])
+                               env_set_hex(argv[4], ext_csd[off]);
+                       return CMD_RET_SUCCESS;
+               }
+       }
+
+       return CMD_RET_FAILURE;
+}
+#endif
+
 static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
                          int argc, char * const argv[])
 {
@@ -963,6 +1050,9 @@ static struct cmd_tbl cmd_mmc[] = {
 #ifdef CONFIG_CMD_BKOPS_ENABLE
        U_BOOT_CMD_MKENT(bkops-enable, 2, 0, do_mmc_bkops_enable, "", ""),
 #endif
+#if CONFIG_IS_ENABLED(CMD_MMC_REG)
+       U_BOOT_CMD_MKENT(reg, 5, 0, do_mmc_reg, "", ""),
+#endif
 };
 
 static int do_mmcops(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -1037,6 +1127,10 @@ U_BOOT_CMD(
 #ifdef CONFIG_CMD_BKOPS_ENABLE
        "mmc bkops-enable <dev> - enable background operations handshake on device\n"
        "   WARNING: This is a write-once setting.\n"
+#endif
+#if CONFIG_IS_ENABLED(CMD_MMC_REG)
+       "mmc reg read <reg> <offset> [env] - read card register <reg> offset <offset>\n"
+       "   (optionally into [env] variable)\n"
 #endif
        );
 
--
Quoted 2 lines

2.27.0

--

Quoted 4 lines
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |

--

| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
#3 lore raw

PATCH 1/1 cmd: mmc: Add mmc reg read command for reading card registers

In reply to Marek Vasut

Hi Marek,

Quoted 2 lines

Subject: [PATCH] cmd: mmc: Add mmc reg read command for reading card registers

This patch breaks ci build.

+u-boot.imx exceeds file size limit:

+  limit:  0x5fc00 bytes
+  actual: 0x60c00 bytes
+  excess: 0x1000 bytes

+make[1]: *** [Makefile:1204: u-boot.imx] Error 1
+make[1]: *** Deleting file 'u-boot.imx'
+make: *** [Makefile:167: sub-make] Error 2

Regards,
Peng.

Quoted 153 lines

Add extension to the 'mmc' command to read out the card registers. Currently, only the eMMC OCR/CID/CSD/EXTCSD/RCA/DSR register are supported. A register value can either be displayed or read into an environment variable.

---
 cmd/Kconfig |  8 +++++
 cmd/mmc.c   | 94
+++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+)
cmd/Kconfig +0 -0
index 192b3b262f..a0cf03c911 100644
@@ -1104,6 +1104,14 @@ config CMD_BKOPS_ENABLE
 	  on a eMMC device. The feature is optionally available on eMMC

devices

cmd/Kconfig +8 -0
 	  conforming to standard >= 4.41.
 
+config CMD_MMC_REG
+	bool "Enable support for reading card registers in the mmc command"
+	depends on CMD_MMC
+	default y
+	help
+	  Enable the commands for reading card registers. This is useful
+	  mostly for debugging or extracting details from the card.
+
 config CMD_MMC_RPMB
 	bool "Enable support for RPMB in the mmc command"
 	depends on SUPPORT_EMMC_RPMB
cmd/mmc.c +87 -0
index 1529a3e05d..55fbfe822e 100644
@@ -912,6 +912,93 @@ static int do_mmc_bkops_enable(struct cmd_tbl
 *cmdtp, int flag,  }  #endif
 
+#if CONFIG_IS_ENABLED(CMD_MMC_REG)
+static int do_mmc_reg(struct cmd_tbl *cmdtp, int flag,
+			 int argc, char *const argv[])
+{
+	ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
+	struct mmc *mmc;
+	int i, ret;
+	u32 off;
+
+	if (argc < 3 || argc > 5)
+		return CMD_RET_USAGE;
+
+	mmc = find_mmc_device(curr_device);
+	if (!mmc) {
+		printf("no mmc device at slot %x\n", curr_device);
+		return CMD_RET_FAILURE;
+	}
+
+	if (IS_SD(mmc)) {
+		printf("SD registers are not supported\n");
+		return CMD_RET_FAILURE;
+	} else {
+		off = simple_strtoul(argv[3], NULL, 10);
+		if (!strcmp(argv[2], "cid")) {
+			if (off > 1)
+				return CMD_RET_USAGE;
+			printf("CID[%i]: 0x%08x\n", off, mmc->cid[off]);
+			if (argv[4])
+				env_set_hex(argv[4], mmc->cid[off]);
+			return CMD_RET_SUCCESS;
+		}
+		if (!strcmp(argv[2], "csd")) {
+			if (off > 3)
+				return CMD_RET_USAGE;
+			printf("CSD[%i]: 0x%08x\n", off, mmc->csd[off]);
+			if (argv[4])
+				env_set_hex(argv[4], mmc->csd[off]);
+			return CMD_RET_SUCCESS;
+		}
+		if (!strcmp(argv[2], "dsr")) {
+			printf("DSR: 0x%08x\n", mmc->dsr);
+			if (argv[4])
+				env_set_hex(argv[4], mmc->dsr);
+			return CMD_RET_SUCCESS;
+		}
+		if (!strcmp(argv[2], "ocr")) {
+			printf("OCR: 0x%08x\n", mmc->ocr);
+			if (argv[4])
+				env_set_hex(argv[4], mmc->ocr);
+			return CMD_RET_SUCCESS;
+		}
+		if (!strcmp(argv[2], "rca")) {
+			printf("RCA: 0x%08x\n", mmc->rca);
+			if (argv[4])
+				env_set_hex(argv[4], mmc->rca);
+			return CMD_RET_SUCCESS;
+		}
+		if (!strcmp(argv[2], "extcsd") &&
+		    mmc->version >= MMC_VERSION_4_41) {
+			ret = mmc_send_ext_csd(mmc, ext_csd);
+			if (ret)
+				return ret;
+			if (!strcmp(argv[3], "all")) {
+				/* Dump the entire register */
+				printf("EXT_CSD:");
+				for (i = 0; i < MMC_MAX_BLOCK_LEN; i++) {
+					if (!(i % 10))
+						printf("\n%03i: ", i);
+					printf(" %02x", ext_csd[i]);
+				}
+				printf("\n");
+				return CMD_RET_SUCCESS;
+			}
+			off = simple_strtoul(argv[3], NULL, 10);
+			if (off > 512)
+				return CMD_RET_USAGE;
+			printf("EXT_CSD[%i]: 0x%02x\n", off, ext_csd[off]);
+			if (argv[4])
+				env_set_hex(argv[4], ext_csd[off]);
+			return CMD_RET_SUCCESS;
+		}
+	}
+
+	return CMD_RET_FAILURE;
+}
+#endif
+
 static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
 			  int argc, char * const argv[])
 {
@@ -963,6 +1050,9 @@ static struct cmd_tbl cmd_mmc[] = {  #ifdef

CONFIG_CMD_BKOPS_ENABLE
U_BOOT_CMD_MKENT(bkops-enable, 2, 0, do_mmc_bkops_enable, "",
""), #endif

cmd/mmc.c +3 -0
+#if CONFIG_IS_ENABLED(CMD_MMC_REG)
+	U_BOOT_CMD_MKENT(reg, 5, 0, do_mmc_reg, "", ""), #endif
 };
 
 static int do_mmcops(struct cmd_tbl *cmdtp, int flag, int argc, @@ -1037,6
+1127,10 @@ U_BOOT_CMD(  #ifdef CONFIG_CMD_BKOPS_ENABLE
 	"mmc bkops-enable <dev> - enable background operations handshake

on device\n"

cmd/mmc.c +3 -0
 	"   WARNING: This is a write-once setting.\n"
+#endif
+#if CONFIG_IS_ENABLED(CMD_MMC_REG)
+	"mmc reg read <reg> <offset> [env] - read card register <reg> offset

<offset>\n"

cmd/mmc.c +1 -1
+	"   (optionally into [env] variable)\n"
 #endif
 	);
 
--

2.27.0

#4 lore raw

PATCH 1/1 cmd: mmc: Add mmc reg read command for reading card registers

Quoted 1 line · Peng Fan

Hi Marek,

Hi,

Review

Quoted 12 lines
Quoted 2 lines

Subject: [PATCH] cmd: mmc: Add mmc reg read command for reading card registers

This patch breaks ci build.

(quoted diff) +7 -0
+u-boot.imx exceeds file size limit:
+  limit:  0x5fc00 bytes
+  actual: 0x60c00 bytes
+  excess: 0x1000 bytes
+make[1]: *** [Makefile:1204: u-boot.imx] Error 1
+make[1]: *** Deleting file 'u-boot.imx'
+make: *** [Makefile:167: sub-make] Error 2

On which board ?

#5 lore raw

PATCH 1/1 cmd: mmc: Add mmc reg read command for reading card registers

Quoted 13 lines

Subject: Re: [PATCH] cmd: mmc: Add mmc reg read command for reading card registers

Quoted 1 line · Peng Fan

Hi Marek,

Hi,

Quoted 5 lines
Quoted 2 lines

Subject: [PATCH] cmd: mmc: Add mmc reg read command for reading card registers

This patch breaks ci build.

Quoted 9 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+u-boot.imx exceeds file size limit:
+  limit:  0x5fc00 bytes
+  actual: 0x60c00 bytes
+  excess: 0x1000 bytes
+make[1]: *** [Makefile:1204: u-boot.imx] Error 1
+make[1]: *** Deleting file 'u-boot.imx'
+make: *** [Makefile:167: sub-make] Error 2

On which board ?

arm: + tbs2910
Regards,
Peng.