cmd_mem: replace custom PRINTF() with debug()
PATCH 1/3 cmd_mem: replace custom PRINTF() with debug()
--- common/cmd_mem.c | 12 +++--------- 1 files changed, 3 insertions(+), 9 deletions(-)
common/cmd_mem.c +3 -9
@@ -35,12 +35,6 @@#include <watchdog.h> #include <asm/io.h> -#ifdef CMD_MEM_DEBUG -#define PRINTF(fmt,args...) printf (fmt ,##args) -#else -#define PRINTF(fmt,args...) -#endif -static int mod_mem (cmd_tbl_t *,int ,int ,int ,char *const []);/* Display values from last command.
@@ -681,7 +675,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#if defined(CONFIG_SYS_ALT_MEMTEST )printf ("Testing %08x ... %08x:\n" , (uint )start, (uint )end); -PRINTF ("%s:%d: start 0x%p end 0x%p\n" , +debug ("%s:%d: start 0x%p end 0x%p\n" , __FUNCTION__, __LINE__, start, end);for (;;) {
@@ -698,7 +692,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) }printf ("Iteration: %6d\r" , iterations); -PRINTF ("\n" ); +debug ("\n" ); iterations++;/*
@@ -789,7 +783,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) pattern = (vu_long )0xaaaaaaaa ; anti_pattern = (vu_long )0x55555555 ; -PRINTF ("%s:%d: length = 0x%.8lx\n" , +debug ("%s:%d: length = 0x%.8lx\n" , __FUNCTION__, __LINE__, len);/*
Signature · 1 line
1.7.7.3
PATCH 2/3 cmd_mem: cmp: unify size code paths
Not only does the source code get simpler, but it also shrinks the compiled object code too.
While we're here, tweak the summary message to avoid the plural issue. It isn't that big of a deal, and it's currently wrong anyways in the single (1 byte) case:
Total of 1 byte were the same
Grammar wise, that should be "was" rather than "were". The new output people should be able to easily figure out:
Total of 1 byte(s) were the same
Total of 10 byte(s) were the same
--- common/cmd_mem.c | 52 +++++++++++++++++++--------------------------------- 1 files changed, 19 insertions(+), 33 deletions(-)
common/cmd_mem.c +19 -33
@@ -263,6 +263,7 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])ulong addr1, addr2, count, ngood;int size;int rcode =0 ; +const char *type;if (argc !=4 )return cmd_usage (cmdtp);
@@ -271,6 +272,7 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])*/ if ((size =cmd_get_data_size (argv[0 ],4 )) <0 )return 1 ; + type = size ==4 ?"word" : size ==2 ?"halfword" :"byte" ; addr1 =simple_strtoul (argv[1 ],NULL ,16 ); addr1 += base_address;
@@ -297,39 +299,25 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ngood =0 ;while (count-- >0 ) { +ulong word1, word2;if (size ==4 ) { -ulong word1 = *(ulong *)addr1; -ulong word2 = *(ulong *)addr2; -if (word1 != word2) { -printf ("word at 0x%08lx (0x%08lx) " -"!= word at 0x%08lx (0x%08lx)\n" , - addr1, word1, addr2, word2); - rcode =1 ; -break ; - } - } -else if (size ==2 ) { -ushort hword1 = *(ushort *)addr1; -ushort hword2 = *(ushort *)addr2; -if (hword1 != hword2) { -printf ("halfword at 0x%08lx (0x%04x) " -"!= halfword at 0x%08lx (0x%04x)\n" , - addr1, hword1, addr2, hword2); - rcode =1 ; -break ; - } + word1 = *(ulong *)addr1; + word2 = *(ulong *)addr2; + }else if (size ==2 ) { + word1 = *(ushort *)addr1; + word2 = *(ushort *)addr2; + }else { + word1 = *(u_char *)addr1; + word2 = *(u_char *)addr2; } -else { -u_char byte1 = *(u_char *)addr1; -u_char byte2 = *(u_char *)addr2; -if (byte1 != byte2) { -printf ("byte at 0x%08lx (0x%02x) " -"!= byte at 0x%08lx (0x%02x)\n" , - addr1, byte1, addr2, byte2); - rcode =1 ; -break ; - } +if (word1 != word2) { +printf ("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n" , + type, addr1, size, word1, + type, addr2, size, word2); + rcode =1 ; +break ; } + ngood++; addr1 += size; addr2 += size;
@@ -339,9 +327,7 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])WATCHDOG_RESET (); } -printf ("Total of %ld %s%s were the same\n" , - ngood, size ==4 ?"word" : size ==2 ?"halfword" :"byte" , - ngood ==1 ?"" :"s" ); +printf ("Total of %ld %s(s) were the same\n" , ngood, type);return rcode; }
Signature · 1 line
1.7.7.3
Wolfgang Denk
AppliedPATCH 2/3 cmd_mem: cmp: unify size code paths
Dear Mike Frysinger,
Quoted 12 lines · In message <[email protected]> you wrote:
Not only does the source code get simpler, but it also shrinks the compiled object code too.
While we're here, tweak the summary message to avoid the plural issue. It isn't that big of a deal, and it's currently wrong anyways in the single (1 byte) case:
Total of 1 byte were the same
Grammar wise, that should be "was" rather than "were". The new output people should be able to easily figure out:
Total of 1 byte(s) were the same
Total of 10 byte(s) were the same
Quoted 4 lines
Signed-off-by Mike Frysinger <[email protected]>--- common/cmd_mem.c | 52 +++++++++++++++++++--------------------------------- 1 files changed, 19 insertions(+), 33 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de They're usually so busy thinking about what happens next that the only time they ever find out what is happening now is when they come to look back on it. - Terry Pratchett, _Wyrd Sisters_
PATCH 3/3 cmd_mem: cmp: convert while() to for() loop
In reply to Mike FrysingerSimplify the code slightly by using a for() loop since this is basically what we're already doing -- incrementing "ngood" to the value in "count".
--- common/cmd_mem.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)
common/cmd_mem.c +2 -5
@@ -296,9 +296,7 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) }#endif - ngood =0 ; - -while (count-- >0 ) { +for (ngood =0 ; ngood < count; ++ngood) {ulong word1, word2;if (size ==4 ) { word1 = *(ulong *)addr1;
@@ -318,12 +316,11 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])break ; } - ngood++; addr1 += size; addr2 += size;/* reset watchdog from time to time */ -if ((count % (64 <<10 )) ==0 ) +if ((ngood % (64 <<10 )) ==0 )WATCHDOG_RESET (); }
Signature · 1 line
1.7.7.3
Wolfgang Denk
AppliedPATCH 3/3 cmd_mem: cmp: convert while() to for() loop
Dear Mike Frysinger,
Quoted 8 lines · In message <[email protected]> you wrote:
Simplify the code slightly by using a
for()loop since this is basically what we're already doing -- incrementing "ngood" to the value in "count".Signed-off-by Mike Frysinger <[email protected]>--- common/cmd_mem.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de A quarrel is quickly settled when deserted by one party; there is no battle unless there be two. - Seneca
Wolfgang Denk
AppliedPATCH 1/3 cmd_mem: replace custom PRINTF() with debug()
In reply to Mike FrysingerDear Mike Frysinger,
Quoted 4 lines · In message <[email protected]> you wrote:
Signed-off-by Mike Frysinger <[email protected]>--- common/cmd_mem.c | 12 +++--------- 1 files changed, 3 insertions(+), 9 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de The more complex the mind, the greater the need for the simplicity of play. -- Kirk, "Shore Leave", stardate 3025.8