All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 0/1] fix messy code to be printed
@ 2021-02-08  2:26 Xingyu Wu
  2021-02-08  2:26 ` [PATCH V2 1/1] mmc-utils: fix messy code printed Xingyu Wu
  0 siblings, 1 reply; 4+ messages in thread
From: Xingyu Wu @ 2021-02-08  2:26 UTC (permalink / raw)
  To: chris, jwerner, gwendal, linux-mmc; +Cc: wuxy20, Xingyu Wu

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

Version V2 change:
Add the recipient: linux-mmc@vger.kernel.org 

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

 mmc_cmds.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH V2 1/1] mmc-utils: fix messy code printed
  2021-02-08  2:26 [PATCH V2 0/1] fix messy code to be printed Xingyu Wu
@ 2021-02-08  2:26 ` Xingyu Wu
  2021-03-30 13:00   ` Ulf Hansson
  0 siblings, 1 reply; 4+ messages in thread
From: Xingyu Wu @ 2021-02-08  2:26 UTC (permalink / raw)
  To: chris, jwerner, gwendal, linux-mmc; +Cc: wuxy20, 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.

Signed-off-by: Xingyu Wu <wuxy20@gmail.com>
---
 mmc_cmds.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/mmc_cmds.c b/mmc_cmds.c
index fb37189..d090a24 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V2 1/1] mmc-utils: fix messy code printed
  2021-02-08  2:26 ` [PATCH V2 1/1] mmc-utils: fix messy code printed Xingyu Wu
@ 2021-03-30 13:00   ` Ulf Hansson
  2021-03-30 13:56     ` Avri Altman
  0 siblings, 1 reply; 4+ messages in thread
From: Ulf Hansson @ 2021-03-30 13:00 UTC (permalink / raw)
  To: Avri Altman; +Cc: Xingyu Wu, jwerner, Gwendal Grignou, linux-mmc, wuxy20

+ Avri

On Mon, 8 Feb 2021 at 03:30, Xingyu Wu <wuxy20@gmail.com> wrote:
>
> 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.
>
> Signed-off-by: Xingyu Wu <wuxy20@gmail.com>

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

Kind regards
Uffe

> ---
>  mmc_cmds.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index fb37189..d090a24 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH V2 1/1] mmc-utils: fix messy code printed
  2021-03-30 13:00   ` Ulf Hansson
@ 2021-03-30 13:56     ` Avri Altman
  0 siblings, 0 replies; 4+ messages in thread
From: Avri Altman @ 2021-03-30 13:56 UTC (permalink / raw)
  To: Ulf Hansson, Xingyu Wu; +Cc: jwerner, Gwendal Grignou, linux-mmc, wuxy20

> + Avri
> 
> On Mon, 8 Feb 2021 at 03:30, Xingyu Wu <wuxy20@gmail.com> wrote:
> >
> > 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.
> >
> > Signed-off-by: Xingyu Wu <wuxy20@gmail.com>
> 
> Avri, can you please have a look at this and provide comments or your ack?
> 
> Kind regards
> Uffe
> 
> > ---
> >  mmc_cmds.c | 13 +++++++++++--
> >  1 file changed, 11 insertions(+), 2 deletions(-)
> >
> > diff --git a/mmc_cmds.c b/mmc_cmds.c
> > index fb37189..d090a24 100644
> > --- a/mmc_cmds.c
> > +++ b/mmc_cmds.c
> > @@ -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) {
int i;
please don't mix declaration and code

> > -               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] */

> > +               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
> > +               }
> > +               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
> >

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-30 13:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-08  2:26 [PATCH V2 0/1] fix messy code to be printed Xingyu Wu
2021-02-08  2:26 ` [PATCH V2 1/1] mmc-utils: fix messy code printed Xingyu Wu
2021-03-30 13:00   ` Ulf Hansson
2021-03-30 13:56     ` Avri Altman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.