Skip to contentSkip to conversation

commands: Add MMC ext. CSD register tool

PATCH Superseded Daniel Schultz 3 participants 8 messages Aug 24, 2015 – Aug 25, 2015

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 commands: Add MMC ext. CSD register tool

This tools can read/write to the extended CSD register of MMC devices.

---
 commands/Kconfig  |   16 +
 commands/Makefile |    1 +
 commands/extcsd.c | 2105 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 2122 insertions(+)
 create mode 100644 commands/extcsd.c
commands/Kconfig +16 -0
index 133dcbf..293d685 100644
@@ -242,6 +242,22 @@ config CMD_VERSION
 
 	  barebox 2014.05.0-00142-gb289373 #177 Mon May 12 20:35:55 CEST 2014
 
+config CMD_EXTCSD
+	tristate
+	prompt "read/write eMMC ext. CSD register"
+	depends on MCI
+	help
+	  Read or write the extended CSD register of a MMC device.
+
+	  Usage: extcsd dev [-r | -i index [-r | -v value -y]]
+
+	  Options:
+		  -i      field index of the register
+		  -r      print the register as raw data
+		  -v      value which will be written
+		  -y      don't request when writing to one time programmable fields
+		  __CAUTION__: this could damage the device!
+
 # end Information commands
 endmenu
 
commands/Makefile +1 -0
index 3d594c3..f2b1820 100644
@@ -114,3 +114,4 @@ obj-$(CONFIG_CMD_STATE)		+= state.o
 obj-$(CONFIG_CMD_DHCP)		+= dhcp.o
 obj-$(CONFIG_CMD_DHRYSTONE)	+= dhrystone.o
 obj-$(CONFIG_CMD_SPD_DECODE)	+= spd_decode.o
+obj-$(CONFIG_CMD_EXTCSD)	+= extcsd.o
commands/extcsd.c new file +2105 -0

2,105 lines not on this page · raw message

Signature · 7 lines
1.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 2/3 drivers: mci: Make two functions public

There is no possibility to read/write to the extended CSD register of MMC devices from a command. To avoid duplicated driver code, two driver functions have to be public.

---
 drivers/mci/mci-core.c | 4 ++--
 include/mci.h          | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/mci/mci-core.c +2 -2
index bd5cae2..c22f932 100644
@@ -370,7 +370,7 @@ static int mmc_send_op_cond(struct mci *mci)
  * Note: Only cards newer than Version 1.1 (Physical Layer Spec) support
  * this command
  */
-static int mci_send_ext_csd(struct mci *mci, char *ext_csd)
+int mci_send_ext_csd(struct mci *mci, char *ext_csd)
 {
 	struct mci_cmd cmd;
 	struct mci_data data;
@@ -394,7 +394,7 @@ static int mci_send_ext_csd(struct mci *mci, char *ext_csd)
  * @param value FIXME
  * @return Transaction status (0 on success)
  */
-static int mci_switch(struct mci *mci, unsigned set, unsigned index,
+int mci_switch(struct mci *mci, unsigned set, unsigned index,
 			unsigned value)
 {
 	struct mci_cmd cmd;
include/mci.h +3 -0
index c5ab5b3..a7bf8cd 100644
@@ -372,6 +372,9 @@ struct mci {
 int mci_register(struct mci_host*);
 void mci_of_parse(struct mci_host *host);
 int mci_detect_card(struct mci_host *);
+int mci_send_ext_csd(struct mci *mci, char *ext_csd);
+int mci_switch(struct mci *mci, unsigned set, unsigned index,
+			unsigned value);
 
 static inline int mmc_host_is_spi(struct mci_host *host)
 {
Signature · 7 lines
1.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

Re: [PATCH 2/3] drivers: mci: Make two functions public

Quoted 36 lines · Daniel Schultz

There is no possibility to read/write to the extended CSD register of MMC devices from a command. To avoid duplicated driver code, two driver functions have to be public.

---
 drivers/mci/mci-core.c | 4 ++--
 include/mci.h          | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/mci/mci-core.c +2 -2
index bd5cae2..c22f932 100644
@@ -370,7 +370,7 @@ static int mmc_send_op_cond(struct mci *mci)
  * Note: Only cards newer than Version 1.1 (Physical Layer Spec) support
  * this command
  */
-static int mci_send_ext_csd(struct mci *mci, char *ext_csd)
+int mci_send_ext_csd(struct mci *mci, char *ext_csd)
 {
 	struct mci_cmd cmd;
 	struct mci_data data;
@@ -394,7 +394,7 @@ static int mci_send_ext_csd(struct mci *mci, char *ext_csd)
  * @param value FIXME
  * @return Transaction status (0 on success)
  */
-static int mci_switch(struct mci *mci, unsigned set, unsigned index,
+int mci_switch(struct mci *mci, unsigned set, unsigned index,
 			unsigned value)
 {
 	struct mci_cmd cmd;
include/mci.h +0 -0
index c5ab5b3..a7bf8cd 100644

include/mci.h struct mci { · line 377

Quoted 6 lines
include/mci.h +3 -0
@@ -372,6 +372,9 @@ struct mci {
 int mci_register(struct mci_host*);
 void mci_of_parse(struct mci_host *host);
 int mci_detect_card(struct mci_host *);
+int mci_send_ext_csd(struct mci *mci, char *ext_csd);
+int mci_switch(struct mci *mci, unsigned set, unsigned index,
+			unsigned value);

Should be before 1/3.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH 3/3 include: mci: Add new ext. CSD field defines

In reply to Daniel Schultz

Added missing defines for the extended CSD register until standard 5.1.

---
 include/mci.h | 188 ++++++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 143 insertions(+), 45 deletions(-)
include/mci.h +143 -45
index a7bf8cd..dfeca46 100644
@@ -137,51 +137,149 @@
  * EXT_CSD fields
  */
 
-#define EXT_CSD_FLUSH_CACHE		32      /* W */
-#define EXT_CSD_CACHE_CTRL		33      /* R/W */
-#define EXT_CSD_POWER_OFF_NOTIFICATION	34	/* R/W */
-#define EXT_CSD_GP_SIZE_MULT		143	/* R/W */
-#define EXT_CSD_PARTITION_ATTRIBUTE	156	/* R/W */
-#define EXT_CSD_PARTITION_SUPPORT	160	/* RO */
-#define EXT_CSD_HPI_MGMT		161	/* R/W */
-#define EXT_CSD_RST_N_FUNCTION		162	/* R/W */
-#define EXT_CSD_SANITIZE_START		165     /* W */
-#define EXT_CSD_WR_REL_PARAM		166	/* RO */
-#define EXT_CSD_BOOT_WP			173	/* R/W */
-#define EXT_CSD_ERASE_GROUP_DEF		175	/* R/W */
-#define EXT_CSD_PART_CONFIG		179	/* R/W */
-#define EXT_CSD_ERASED_MEM_CONT		181	/* RO */
-#define EXT_CSD_BUS_WIDTH		183	/* R/W */
-#define EXT_CSD_HS_TIMING		185	/* R/W */
-#define EXT_CSD_POWER_CLASS		187	/* R/W */
-#define EXT_CSD_REV			192	/* RO */
-#define EXT_CSD_STRUCTURE		194	/* RO */
-#define EXT_CSD_CARD_TYPE		196	/* RO */
-#define EXT_CSD_OUT_OF_INTERRUPT_TIME	198	/* RO */
-#define EXT_CSD_PART_SWITCH_TIME        199     /* RO */
-#define EXT_CSD_PWR_CL_52_195		200	/* RO */
-#define EXT_CSD_PWR_CL_26_195		201	/* RO */
-#define EXT_CSD_PWR_CL_52_360		202	/* RO */
-#define EXT_CSD_PWR_CL_26_360		203	/* RO */
-#define EXT_CSD_SEC_CNT			212	/* RO, 4 bytes */
-#define EXT_CSD_S_A_TIMEOUT		217	/* RO */
-#define EXT_CSD_REL_WR_SEC_C		222	/* RO */
-#define EXT_CSD_HC_WP_GRP_SIZE		221	/* RO */
-#define EXT_CSD_ERASE_TIMEOUT_MULT	223	/* RO */
-#define EXT_CSD_HC_ERASE_GRP_SIZE	224	/* RO */
-#define EXT_CSD_BOOT_MULT		226	/* RO */
-#define EXT_CSD_SEC_TRIM_MULT		229	/* RO */
-#define EXT_CSD_SEC_ERASE_MULT		230	/* RO */
-#define EXT_CSD_SEC_FEATURE_SUPPORT	231	/* RO */
-#define EXT_CSD_TRIM_MULT		232	/* RO */
-#define EXT_CSD_PWR_CL_200_195		236	/* RO */
-#define EXT_CSD_PWR_CL_200_360		237	/* RO */
-#define EXT_CSD_PWR_CL_DDR_52_195	238	/* RO */
-#define EXT_CSD_PWR_CL_DDR_52_360	239	/* RO */
-#define EXT_CSD_POWER_OFF_LONG_TIME	247	/* RO */
-#define EXT_CSD_GENERIC_CMD6_TIME	248	/* RO */
-#define EXT_CSD_CACHE_SIZE		249	/* RO, 4 bytes */
-#define EXT_CSD_HPI_FEATURES		503	/* RO */
+#define EXT_CSD_FLUSH_CACHE			32      /* W */
+#define EXT_CSD_CACHE_CTRL			33      /* R/W */
+#define EXT_CSD_POWER_OFF_NOTIFICATION		34	/* R/W */
+#define EXT_CSD_GP_SIZE_MULT			143	/* R/W */
+#define EXT_CSD_PARTITION_ATTRIBUTE		156	/* R/W */
+#define EXT_CSD_PARTITION_SUPPORT		160	/* RO */
+#define EXT_CSD_HPI_MGMT			161	/* R/W */
+#define EXT_CSD_RST_N_FUNCTION			162	/* R/W */
+#define EXT_CSD_SANITIZE_START			165     /* W */
+#define EXT_CSD_WR_REL_PARAM			166	/* RO */
+#define EXT_CSD_BOOT_WP				173	/* R/W */
+#define EXT_CSD_ERASE_GROUP_DEF			175	/* R/W */
+#define EXT_CSD_PART_CONFIG			179	/* R/W */
+#define EXT_CSD_ERASED_MEM_CONT			181	/* RO */
+#define EXT_CSD_BUS_WIDTH			183	/* R/W */
+#define EXT_CSD_HS_TIMING			185	/* R/W */
+#define EXT_CSD_POWER_CLASS			187	/* R/W */
+#define EXT_CSD_REV				192	/* RO */
+#define EXT_CSD_STRUCTURE			194	/* RO */
+#define EXT_CSD_CARD_TYPE			196	/* RO */
+#define EXT_CSD_OUT_OF_INTERRUPT_TIME		198	/* RO */
+#define EXT_CSD_PWR_CL_52_195			200	/* RO */
+#define EXT_CSD_PWR_CL_26_195			201	/* RO */
+#define EXT_CSD_PWR_CL_52_360			202	/* RO */
+#define EXT_CSD_PWR_CL_26_360			203	/* RO */
+#define EXT_CSD_SEC_CNT				212	/* RO, 4 bytes */
+#define EXT_CSD_S_A_TIMEOUT			217	/* RO */
+#define EXT_CSD_REL_WR_SEC_C			222	/* RO */
+#define EXT_CSD_HC_WP_GRP_SIZE			221	/* RO */
+#define EXT_CSD_ERASE_TIMEOUT_MULT		223	/* RO */
+#define EXT_CSD_HC_ERASE_GRP_SIZE		224	/* RO */
+#define EXT_CSD_BOOT_MULT			226	/* RO */
+#define EXT_CSD_SEC_TRIM_MULT			229	/* RO */
+#define EXT_CSD_SEC_ERASE_MULT			230	/* RO */
+#define EXT_CSD_SEC_FEATURE_SUPPORT		231	/* RO */
+#define EXT_CSD_TRIM_MULT			232	/* RO */
+#define EXT_CSD_PWR_CL_200_195			236	/* RO */
+#define EXT_CSD_PWR_CL_200_360			237	/* RO */
+#define EXT_CSD_PWR_CL_DDR_52_195		238	/* RO */
+#define EXT_CSD_PWR_CL_DDR_52_360		239	/* RO */
+#define EXT_CSD_POWER_OFF_LONG_TIME		247	/* RO */
+#define EXT_CSD_GENERIC_CMD6_TIME		248	/* RO */
+#define EXT_CSD_CACHE_SIZE			249	/* RO, 4 bytes */
+#define EXT_CSD_HPI_FEATURES			503	/* RO */
+
+/* Added with the 5.1 standard */
+#define EXT_CSD_CMDQ_MODE_EN			15	/* RO */
+#define EXT_CSD_SECURE_REMOVAL_TYPE		16	/* R/W */
+#define EXT_CSD_PRODUCT_ST8_AWARENSS_ENABLEMENT	17	/* R/W */
+#define EXT_CSD_MAX_PRE_LOADING_DATA_SIZE	18	/* RO, 4 bytes */
+#define EXT_CSD_PRE_LOADING_DATA_SIZE		22	/* R/W, 4 bytes */
+#define EXT_CSD_FFU_STATUS			26	/* RO */
+#define EXT_CSD_MODE_OPERATION_CODES		29	/* W */
+#define EXT_CSD_MODE_CONFIG			30	/* R/W */
+#define EXT_CSD_BARRIER_CTRL			31	/* R/W */
+#define EXT_CSD_PACKED_FAILURE_INDEX		35	/* RO */
+#define EXT_CSD_PACKED_COMMAND_STATUS		36	/* RO */
+#define EXT_CSD_CONTEXT_CONF			37	/* R/W, 15 bytes */
+#define EXT_CSD_EXT_PARTITIONS_ATTRIBUTE	52	/* R/W, 2 bytes */
+#define EXT_CSD_EXCEPTION_EVENTS_STATUS		54	/* RO, 2 bytes */
+#define EXT_CSD_EXCEPTION_EVENTS_CTRL		56	/* R/W, 2 bytes */
+#define EXT_CSD_CLASS_6_CTRL			59	/* R/W */
+#define EXT_CSD_INI_TIMEOUT_EMU			60	/* RO */
+#define EXT_CSD_DATA_SECTOR_SIZE		61	/* RO */
+#define EXT_CSD_USE_NATIVE_SECTOR		62	/* RO */
+#define EXT_CSD_NATIVE_SECTOR_SIZE		63	/* RO */
+#define EXT_CSD_PROGRAM_CID_CSD_DDR_SUPPORT	130	/* R/W */
+#define EXT_CSD_PERIODIC_WAKEUP			131	/* R/W/ */
+#define EXT_CSD_TCASE_SUPPORT			132	/* R/W */
+#define EXT_CSD_PRODUCTION_STATE_AWARENESS	133	/* R/W */
+#define EXT_CSD_SEC_BAD_BLK_MGMNT		134	/* R/W */
+#define EXT_CSD_ENH_START_ADDR			136	/* R/W, 4 bytes */
+#define EXT_CSD_ENH_SIZE_MULT			140	/* R/W, 3 bytes */
+#define EXT_CSD_PARTITION_SETTING_COMPLETED	155	/* R/W */
+#define EXT_CSD_PARTITIONS_ATTRIBUTE		156	/* R/W */
+#define EXT_CSD_MAX_ENH_SIZE_MULT		157	/* RO, 3 bytes */
+#define EXT_CSD_PARTITIONING_SUPPORT		160	/* RO */
+#define EXT_CSD_BKOPS_EN			163	/* R/W */
+#define EXT_CSD_BKOPS_START			164	/* WO */
+#define EXT_CSD_WR_REL_SET			167	/* R/W */
+#define EXT_CSD_RPMB_SIZE_MULT			168	/* RO */
+#define EXT_CSD_FW_CONFIG			169	/* R/W */
+#define EXT_CSD_USER_WP				171	/* R/W */
+#define EXT_CSD_BOOT_WP_STATUS			174	/* RO */
+#define EXT_CSD_BOOT_BUS_CONDITIONS		177	/* R/W */
+#define EXT_CSD_BOOT_CONFIG_PROT		178	/* R/W */
+#define EXT_CSD_PARTITION_CONFIG		179	/* R/W */
+#define EXT_CSD_STROBE_SUPPORT			184	/* RO */
+#define EXT_CSD_CMD_SET_REV			189	/* R/W */
+#define EXT_CSD_CMD_SET				191	/* R/W */
+#define EXT_CSD_CSD_STRUCTURE			194	/* RO */
+#define EXT_CSD_DEVICE_TYPE			196	/* RO */
+#define EXT_CSD_DRIVER_STRENGTH			197	/* RO */
+#define EXT_CSD_PART_SWITCH_TIME		199	/* RO */
+#define EXT_CSD_PARTITION_SWITCH_TIME		199	/* RO */
+#define EXT_CSD_MIN_PERF_R_4_26			205	/* RO */
+#define EXT_CSD_MIN_PERF_W_4_26			206	/* RO */
+#define EXT_CSD_MIN_PERF_R_8_26_4_52		207	/* RO */
+#define EXT_CSD_MIN_PERF_W_8_26_4_52		208	/* RO */
+#define EXT_CSD_MIN_PERF_R_8_52			209	/* RO */
+#define EXT_CSD_MIN_PERF_W_8_52			210	/* RO */
+#define EXT_CSD_SECURE_WP_INFO			211	/* RO */
+#define EXT_CSD_SEC_COUNT			212	/* RO, 4 bytes */
+#define EXT_CSD_SLEEP_NOTIFICATION_TIME		216	/* RO */
+#define EXT_CSD_PRODUCTION_ST8_AWARENSS_TIMEOUT	218	/* RO */
+#define EXT_CSD_S_C_VCCQ			219	/* RO */
+#define EXT_CSD_S_C_VCC				220	/* RO */
+#define EXT_CSD_ACC_SIZE			225	/* RO */
+#define EXT_CSD_BOOT_SIZE_MULT			226	/* RO */
+#define EXT_CSD_BOOT_INFO			228	/* RO */
+#define EXT_CSD_MIN_PERF_DDR_R_8_52		234	/* RO */
+#define EXT_CSD_MIN_PERF_DDR_W_8_52		235	/* RO */
+#define EXT_CSD_CACHE_FLUSH_POLICY		240	/* RO */
+#define EXT_CSD_INI_TIMEOUT_AP			241	/* RO */
+#define EXT_CSD_CORRECTLY_PRG_SECTORS_NUM	242	/* RO, 4 bytes */
+#define EXT_CSD_BKOPS_STATUS			246	/* RO */
+#define EXT_CSD_FIRMWARE_VERSION		254	/* RO, 8 bytes */
+#define EXT_CSD_DEVICE_VERSION			262	/* RO, 2 bytes */
+#define EXT_CSD_OPTIMAL_TRIM_UNIT_SIZE		264	/* RO */
+#define EXT_CSD_OPTIMAL_WRITE_SIZE		265	/* RO */
+#define EXT_CSD_OPTIMAL_READ_SIZE		266	/* RO */
+#define EXT_CSD_PRE_EOL_INFO			267	/* RO */
+#define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A	268	/* RO */
+#define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B	269	/* RO */
+#define EXT_CSD_NMBR_OF_FW_SCTRS_CRRCTLY_PRGRMD	302	/* RO, 4 bytes */
+#define EXT_CSD_CMDQ_DEPTH			307	/* RO */
+#define EXT_CSD_CMDQ_SUPPORT			308	/* RO */
+#define EXT_CSD_BARRIER_SUPPORT			486	/* RO */
+#define EXT_CSD_FFU_ARG				487	/* RO, 4 bytes */
+#define EXT_CSD_OPERATION_CODES_TIMEOUT		491	/* RO */
+#define EXT_CSD_FFU_FEATURES			492	/* RO */
+#define EXT_CSD_SUPPORTED_MODES			493	/* RO */
+#define EXT_CSD_EXT_SUPPORT			494	/* RO */
+#define EXT_CSD_LARGE_UNIT_SIZE_M1		495	/* RO */
+#define EXT_CSD_CONTEXT_CAPABILITIES		496	/* RO */
+#define EXT_CSD_TAG_RES_SIZE			497	/* RO */
+#define EXT_CSD_TAG_UNIT_SIZE			498	/* RO */
+#define EXT_CSD_DATA_TAG_SUPPORT		499	/* RO */
+#define EXT_CSD_MAX_PACKED_WRITES		500	/* RO */
+#define EXT_CSD_MAX_PACKED_READS		501	/* RO */
+#define EXT_CSD_BKOPS_SUPPORT			502	/* RO */
+#define EXT_CSD_S_CMD_SET			504	/* RO */
+#define EXT_CSD_EXT_SECURITY_ERR		505	/* RO */
 
 /*
  * EXT_CSD field definitions
Signature · 7 lines
1.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

Re: [PATCH 3/3] include: mci: Add new ext. CSD field defines

Quoted 12 lines · Daniel Schultz

Added missing defines for the extended CSD register until standard 5.1.

---
 include/mci.h | 188 ++++++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 143 insertions(+), 45 deletions(-)
include/mci.h +0 -0
index a7bf8cd..dfeca46 100644

include/mci.h line 143

Quoted 7 lines
include/mci.h +0 -4
@@ -137,51 +137,149 @@
  * EXT_CSD fields
  */
 
-#define EXT_CSD_FLUSH_CACHE		32      /* W */
-#define EXT_CSD_CACHE_CTRL		33      /* R/W */
-#define EXT_CSD_POWER_OFF_NOTIFICATION	34	/* R/W */
-#define EXT_CSD_GP_SIZE_MULT		143	/* R/W */

Please do not change the whitespaces in existing defines. Better some whitespaces inconstistencies but a better to review patch.

Also you are using some of the defines in 1/3, so this patch should be before it, right?

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw
In reply to Daniel Schultz

Hi Daniel,

Nice command. Several comments inline, there is still some way to go to get this into shape.

commands/extcsd.c line 84

Quoted 11 lines · Daniel Schultz
commands/extcsd.c new file +11 -0
+
+static int print_field(u8 *reg, int index)
+{
+	int rev;
+	u32 val;
+	u32 tmp;
+	u64 tmp64;
+
+	rev = reg[EXT_CSD_REV];
+
+	if (rev >= 7)

Additional print_field_v7/v6/v5() functions will reduce the indentation level by one and help violating the 80 character limit less often.

commands/extcsd.c line 92

Quoted 8 lines
commands/extcsd.c new file +8 -0
+		switch (index) {
+		case EXT_CSD_CMDQ_MODE_EN:
+			print_field_caption(CMDQ_MODE_EN, RWE_P);
+			val = get_field_val(CMDQ_MODE_EN, 0, 0x1);
+			if (val)
+				printf("\tCommand queuing is enabled\n");
+			else
+				printf("\tCommand queuing is disabled\n");

Your printfs are very inefficient. You should use something like:

	if (val)
		str = "en";
	else
		str = "dis";
	printf("Command queuing is %sabled\n", str);

Same goes for many other printfs. This will result in much less similar strings in the binary.

Quoted 8 lines
commands/extcsd.c new file +8 -0
+			return 1;
+
+		case EXT_CSD_SECURE_REMOVAL_TYPE:
+			print_field_caption(SECURE_REMOVAL_TYPE, RWaR);
+			val = get_field_val(SECURE_REMOVAL_TYPE, 0, 0xF);
+			switch (val) {
+			case 0x0:
+				printf("\t[3-0] Supported Secure Removal Type: information removed by an erase of the physical memory\n");

commands/extcsd.c line 110

Quoted 10 lines
commands/extcsd.c new file +10 -0
+				break;
+			case 0x1:
+				printf("\t[3-0] Supported Secure Removal Type: information removed by an overwriting the addressed locations with a character followed by an erase\n");
+				break;
+			case 0x2:
+				printf("\t[3-0] Supported Secure Removal Type: information removed by an overwriting the addressed locations with a character, its complement, then a random character\n");
+				break;
+			case 0x3:
+				printf("\t[3-0] Supported Secure Removal Type: information removed using a vendor defined\n");
+				break;

This is *very* verbose. Could you write this a bit more compact, maybe

	case 0x0:
		str = "erase";
		break;
	case 0x1:
		str = "overwrite, then erase";
		break;
	case 0x2:
		str = "overwrite, complement, then random";
		break;
	case 0x3:
		str = "vendor defined";
		break;

	printf("[3-0] Supported Secure Removal Type: %s\n", str);

Background is that this information only makes sense when being somewhat familiar with the spec. Without knowing the spec at all even the more verbose printfs do not help, but when knowing the spec a more compact writing is enough to remember what is meant.

commands/extcsd.c line 1902

Quoted 13 lines
commands/extcsd.c new file +13 -0
+
+static void print_register_raw(u8 *reg, int index)
+{
+	int i;
+
+	if (index == 0)
+		for (i = 0; i < EXT_CSD_BLOCKSIZE; i++) {
+			if (i % 8 == 0)
+				printf("%u:", i);
+			printf(" %#02x", reg[i]);
+			if (i % 8 == 7)
+				printf("\n");
+		}
	memory_display(reg, 0, EXT_CSD_BLOCKSIZE, 1, 0);

Should do it here.

Quoted 7 lines
commands/extcsd.c new file +7 -0
+static int do_extcsd(int argc, char *argv[])
+{
+	struct device_d		*dev;
+	struct mci		*mci;
+	struct mci_host		*host;
+	u8			*dst;
+	int			retval = 0;

commands/extcsd.c line 2013

Quoted 10 lines
commands/extcsd.c new file +10 -0
+	int			opt;
+	char			*devname;
+	int			index = 0;
+	int			value = 0;
+	int			write_operation = 0;
+	int			always_write = 0;
+	int			print_as_raw = 0;
+
+	if (argv[1] == NULL)
+		return COMMAND_ERROR_USAGE;

argc contains the number of arguments. When argc is 1 then argv[1] is undefined. It may or may not be NULL in this case. You want to use if (argc < 2) here.

commands/extcsd.c line 2015

Quoted 2 lines
commands/extcsd.c new file +2 -0
+
+	devname = argv[1];

You should use argv[optind] after parsing the arguments for the devname. With this not only "extcsd <devname> [OPTIONS]" works but also "extcsd [OPTIONS] <devname>". Don't forget to check if there actually is argv[optind] by

	if (optind == argc)
		return COMMAND_ERROR_USAGE;
Quoted 20 lines
commands/extcsd.c new file +20 -0
+	if (!strncmp(devname, "/dev/", 5))
+		devname += 5;
+
+	while ((opt = getopt(argc, argv, "i:v:yr")) > 0)
+		switch (opt) {
+		case 'i':
+			index = simple_strtoul(optarg, NULL, 0);
+			break;
+		case 'v':
+			value = simple_strtoul(optarg, NULL, 0);
+			write_operation = 1;
+			break;
+		case 'y':
+			always_write = 1;
+			break;
+		case 'r':
+			print_as_raw = 1;
+			break;
+		}
+

commands/extcsd.c line 2045

Quoted 10 lines
commands/extcsd.c new file +10 -0
+	dev = get_device_by_name(devname);
+	if (dev == NULL) {
+		retval = -ENODEV;
+		goto error;
+	}
+	mci = container_of(dev, struct mci, dev);
+	if (mci == NULL) {
+		retval = -ENOENT;
+		goto error;
+	}

Unfortunately this doesn't work properly. It works when the argument really is a mmc devices, but it doesn't detect when the argument is some other type of device. This code will happily use container_of on something that is not a MMC device and probably crash barebox. What you have to do is:

- add a struct list_head member to struct mci and put all mci devices to a list during registration
- create a struct mci *mci_get_device_by_name(const char *name) function and use it here.

commands/extcsd.c line 2051

Quoted 6 lines
commands/extcsd.c new file +6 -0
+	host = mci->host;
+	if (host == NULL) {
+		retval = -ENOENT;
+		goto error;
+	}
+	dst = xmalloc(sizeof(*dst) * EXT_CSD_BLOCKSIZE);

xmalloc(EXT_CSD_BLOCKSIZE) is enough here.

commands/extcsd.c line 2055

Quoted 4 lines
commands/extcsd.c new file +4 -0
+	if (dst == NULL) {
+		retval = -ENOMEM;
+		goto error;
+	}

xmalloc never fails. You don't need to check the return value.

Quoted 25 lines
commands/extcsd.c new file +25 -0
+
+	retval = mci_send_ext_csd(mci, dst);
+	if (retval != 0)
+		goto error_with_mem;
+
+	if (dst[EXT_CSD_REV] < 3) {
+		printf("MMC version 4.2 or lower are not supported");
+		retval = 1;
+		goto error_with_mem;
+	}
+
+	if (write_operation)
+		if (!print_field(dst, index)) {
+			printf("No field with this index found. Abort write operation!\n");
+		} else {
+			write_field(mci, dst, index, value, always_write);
+			printf("\nValue written!\n\n");
+			retval = mci_send_ext_csd(mci, dst);
+			if (retval != 0)
+				goto error_with_mem;
+			print_field(dst, index);
+		}
+	else
+		if (print_as_raw)
+			print_register_raw(dst, index);

commands/extcsd.c line 2090

Quoted 10 lines
commands/extcsd.c new file +10 -0
+		else
+			print_register_readable(dst, index);
+
+error_with_mem:
+	free(dst);
+error:
+	return retval;
+}
+
+BAREBOX_CMD_HELP_START(extcsd)

Better rename this to mmc-extcsd so that the context of this command is clear.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw
Quoted 10 lines · Sascha Hauer

Your printfs are very inefficient. You should use something like:

        if (val)
                str = "en";
        else
                str = "dis";
        printf("Command queuing is %sabled\n", str);

Same goes for many other printfs. This will result in much less similar strings in the binary.

or like this:
printf("Command queuing is %sabled\n", val ? "en" : "dis");

Signature · 10 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw
In reply to Daniel Schultz
Quoted 1 line · Daniel Schultz

This tools can read/write to the extended CSD register of MMC devices.

Is this enough to use the "Enhanced User Data Area" and partitioning features of recent eMMCs? I seem to remember that the standard requires setting the ERASE_GROUP_DEF field on every boot.

Regards,
Jan

Signature · 10 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox