Skip to content
Snippets Groups Projects
Commit 054ea170 authored by Mike Frysinger's avatar Mike Frysinger Committed by Wolfgang Denk
Browse files

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

Signed-off-by: default avatarMike Frysinger <vapier@gentoo.org>
parent 9504a551
No related branches found
No related tags found
No related merge requests found
...@@ -258,6 +258,7 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ...@@ -258,6 +258,7 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
ulong addr1, addr2, count, ngood; ulong addr1, addr2, count, ngood;
int size; int size;
int rcode = 0; int rcode = 0;
const char *type;
if (argc != 4) if (argc != 4)
return CMD_RET_USAGE; return CMD_RET_USAGE;
...@@ -266,6 +267,7 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ...@@ -266,6 +267,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) if ((size = cmd_get_data_size(argv[0], 4)) < 0)
return 1; return 1;
type = size == 4 ? "word" : size == 2 ? "halfword" : "byte";
addr1 = simple_strtoul(argv[1], NULL, 16); addr1 = simple_strtoul(argv[1], NULL, 16);
addr1 += base_address; addr1 += base_address;
...@@ -292,39 +294,25 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ...@@ -292,39 +294,25 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
ngood = 0; ngood = 0;
while (count-- > 0) { while (count-- > 0) {
ulong word1, word2;
if (size == 4) { if (size == 4) {
ulong word1 = *(ulong *)addr1; word1 = *(ulong *)addr1;
ulong word2 = *(ulong *)addr2; word2 = *(ulong *)addr2;
if (word1 != word2) { } else if (size == 2) {
printf("word at 0x%08lx (0x%08lx) " word1 = *(ushort *)addr1;
"!= word at 0x%08lx (0x%08lx)\n", word2 = *(ushort *)addr2;
addr1, word1, addr2, word2); } else {
rcode = 1; word1 = *(u_char *)addr1;
break; word2 = *(u_char *)addr2;
}
}
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;
}
} }
else { if (word1 != word2) {
u_char byte1 = *(u_char *)addr1; printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
u_char byte2 = *(u_char *)addr2; type, addr1, size, word1,
if (byte1 != byte2) { type, addr2, size, word2);
printf("byte at 0x%08lx (0x%02x) " rcode = 1;
"!= byte at 0x%08lx (0x%02x)\n", break;
addr1, byte1, addr2, byte2);
rcode = 1;
break;
}
} }
ngood++; ngood++;
addr1 += size; addr1 += size;
addr2 += size; addr2 += size;
...@@ -334,9 +322,7 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ...@@ -334,9 +322,7 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
WATCHDOG_RESET(); WATCHDOG_RESET();
} }
printf("Total of %ld %s%s were the same\n", printf("Total of %ld %s(s) were the same\n", ngood, type);
ngood, size == 4 ? "word" : size == 2 ? "halfword" : "byte",
ngood == 1 ? "" : "s");
return rcode; return rcode;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment