[U-Boot-Users] [PATCH] Fix itest endianess problem
ito at mlb.co.jp
ito at mlb.co.jp
Tue Apr 4 08:39:41 CEST 2006
Hello
Command 'itest' has 2 bugs.
1. It does not work on big endian machine.
and itest.b may cause unaligned access.
2. itest.l does not work on mips CPU.
on mips,
result of (1 << 32) -1 is 0.
(gcc 3.3.4 binutil 2.14.90.0.6 )
I think, In C language, shifting more than 32bit is undefined.
Please consider to merge
Patch is attched.
--------
Hiroshi Ito
Media Lab. Inc.,
URL http://www.mlb.co.jp ( Sorry, Japanese only. )
TEL +81-3-5294-7255 FAX +81-3-5294-7256
-------------- next part --------------
diff --git a/common/cmd_itest.c b/common/cmd_itest.c
index 8ad134f..20dada9 100644
--- a/common/cmd_itest.c
+++ b/common/cmd_itest.c
@@ -70,17 +70,37 @@ extern int cmd_get_data_size(char* arg,
static long evalexp(char *s, int w)
{
- long l, *p;
-
+ long l;
+ void *p;
+ switch (w) {
+ case 1:
/* if the parameter starts with a * then assume is a pointer to the value we want */
- if (s[0] == '*') {
- p = (long *)simple_strtoul(&s[1], NULL, 16);
- l = *p;
- } else {
- l = simple_strtoul(s, NULL, 16);
+ if (s[0] == '*') {
+ p = (void *)simple_strtoul(&s[1], NULL, 16);
+ l = *(unsigned char*)p;
+ } else {
+ l = simple_strtoul(s, NULL, 16) & 0xFF;
+ }
+ break;
+ case 2:
+ if (s[0] == '*') {
+ p = (void *)simple_strtoul(&s[1], NULL, 16);
+ l = *(unsigned short*)p;
+ } else {
+ l = simple_strtoul(s, NULL, 16) & 0xFFFF;
+ }
+ break;
+ case 4:
+ default:
+ if (s[0] == '*') {
+ p = (void *)simple_strtoul(&s[1], NULL, 16);
+ l = *(unsigned int*)p;
+ } else {
+ l = simple_strtoul(s, NULL, 16);
+ }
+ break;
}
-
- return (l & ((1 << (w * 8)) - 1));
+ return l;
}
static char * evalstr(char *s)
More information about the U-Boot
mailing list