Skip to contentSkip to conversation

fix messy code to be printed

PATCH In review Xingyu Wu 3 participants 4 messages Feb 8, 2021 – Mar 30, 2021 MMC, SD and SDIO

lore
Share & tools
lore

Xingyu Wu

author
#0 lore raw

v2 cover fix messy code to be printed

Dear Sirs:
This patch fixes messy printing of firmware name, please help to review, thank you very much.

Version V2 change:
Add the recipient: [email protected]

Xingyu Wu (1):
mmc-utils: fix messy code printed

 mmc_cmds.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 1/1 mmc-utils: fix messy code printed

Some vendors of eMMC use different format to define the Firmware name. If the Firmware name uses character and if it exceeds the printable range of ASCII (0x20~0x7e), mmc-utils will print messy code. This change can fix the messy code issue, if the firmware name is not printable, print it out as hexadecimal, this change was verified on chromium project.

---
 mmc_cmds.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
mmc_cmds.c +11 -2
index fb37189..d090a24 100644
@@ -29,6 +29,7 @@
 #include <stdint.h>
 #include <assert.h>
 #include <linux/fs.h> /* for BLKGETSIZE */
+#include <ctype.h>
 
 #include "mmc.h"
 #include "mmc_cmds.h"
@@ -1758,8 +1759,16 @@ int do_read_extcsd(int nargs, char **argv)
 	}
 
 	if (ext_csd_rev >= 7) {
-		printf("eMMC Firmware Version: %s\n",
-			(char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]);
+		printf("eMMC Firmware Version:");
+		for (int i = 0; i < 8; i++) {
+			char c = ext_csd[EXT_CSD_FIRMWARE_VERSION + i];
+
+			if (isprint(c))
+				printf("%c", c);
+			else if (c != 0)
+				printf("\\x%02x", c);
+		}
+		printf("\n");
 		printf("eMMC Life Time Estimation A [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]: 0x%02x\n",
 			ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]);
 		printf("eMMC Life Time Estimation B [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n",
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH V2 1/1] mmc-utils: fix messy code printed

+ Avri

Quoted 10 lines · Xingyu Wu

Some vendors of eMMC use different format to define the Firmware name. If the Firmware name uses character and if it exceeds the printable range of ASCII (0x20~0x7e), mmc-utils will print messy code. This change can fix the messy code issue, if the firmware name is not printable, print it out as hexadecimal, this change was verified on chromium project.

Avri, can you please have a look at this and provide comments or your ack?

Kind regards
Uffe

Quoted 38 lines
---
 mmc_cmds.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
mmc_cmds.c +11 -3
index fb37189..d090a24 100644
@@ -29,6 +29,7 @@
 #include <stdint.h>
 #include <assert.h>
 #include <linux/fs.h> /* for BLKGETSIZE */
+#include <ctype.h>
 
 #include "mmc.h"
 #include "mmc_cmds.h"
@@ -1758,8 +1759,16 @@ int do_read_extcsd(int nargs, char **argv)
        }
 
        if (ext_csd_rev >= 7) {
-               printf("eMMC Firmware Version: %s\n",
-                       (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]);
+               printf("eMMC Firmware Version:");
+               for (int i = 0; i < 8; i++) {
+                       char c = ext_csd[EXT_CSD_FIRMWARE_VERSION + i];
+
+                       if (isprint(c))
+                               printf("%c", c);
+                       else if (c != 0)
+                               printf("\\x%02x", c);
+               }
+               printf("\n");
                printf("eMMC Life Time Estimation A [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]: 0x%02x\n",
                        ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]);
                printf("eMMC Life Time Estimation B [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n",
--

2.25.1

#3 lore raw

RE: [PATCH V2 1/1] mmc-utils: fix messy code printed

Quoted 33 lines

+ Avri

Quoted 10 lines · Xingyu Wu

Some vendors of eMMC use different format to define the Firmware name. If the Firmware name uses character and if it exceeds the printable range of ASCII (0x20~0x7e), mmc-utils will print messy code. This change can fix the messy code issue, if the firmware name is not printable, print it out as hexadecimal, this change was verified on chromium project.

Avri, can you please have a look at this and provide comments or your ack?

Kind regards
Uffe

Quoted 14 lines
---
 mmc_cmds.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
mmc_cmds.c +1 -0
index fb37189..d090a24 100644
@@ -29,6 +29,7 @@
 #include <stdint.h>
 #include <assert.h>
 #include <linux/fs.h> /* for BLKGETSIZE */
+#include <ctype.h>
 
Quoted 6 lines

mmc_cmds.c int do_read_extcsd(int nargs, char **argv) · line 1761

Quoted 6 lines
mmc_cmds.c +0 -0
 #include "mmc.h"
 #include "mmc_cmds.h"
@@ -1758,8 +1759,16 @@ int do_read_extcsd(int nargs, char **argv)
        }
 
        if (ext_csd_rev >= 7) {

int i;
please don't mix declaration and code

Quoted 3 lines

mmc_cmds.c int do_read_extcsd(int nargs, char **argv) · line 1762

Quoted 3 lines
mmc_cmds.c +1 -2
-               printf("eMMC Firmware Version: %s\n",
-                       (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]);
+               printf("eMMC Firmware Version:");

Maybe add a comment that will explain why 8 bytes: /* FIRMWARE_VERSION [261-254] */

Quoted 7 lines

mmc_cmds.c int do_read_extcsd(int nargs, char **argv) · line 1769

Quoted 7 lines
mmc_cmds.c +7 -0
+               for (int i = 0; i < 8; i++) {
+                       char c = ext_csd[EXT_CSD_FIRMWARE_VERSION + i];
+
+                       if (isprint(c))
+                               printf("%c", c);
+                       else if (c != 0)
+                               printf("\\x%02x", c);

else

	break;

also why do you need the \\x? %02x should work

Thanks,
Avri

Quoted 10 lines

mmc_cmds.c int do_read_extcsd(int nargs, char **argv)

Quoted 3 lines
mmc_cmds.c +2 -0
+               }
+               printf("\n");
                printf("eMMC Life Time Estimation A

[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]: 0x%02x\n",

mmc_cmds.c int do_read_extcsd(int nargs, char **argv) · line 1774

Quoted 2 lines
mmc_cmds.c +0 -0
                        ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]);
                printf("eMMC Life Time Estimation B

[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n",

Quoted 3 lines

--
2.25.1