lsprop patch for little endian
Benjamin Herrenschmidt
benh at kernel.crashing.org
Fri May 9 10:14:58 EST 2008
I'm not sure who packages that, I think it's in powerpc-utils, anyway,
here's a patch that makes it work on device-tree tarballs lsprop'ed from
a LE machine.
--- /home/benh/grabbag/powerpc-utils-1.1.3/lsprop.c 2007-05-11 14:21:23.000000000 +1000
+++ lsprop.c 2008-05-09 10:13:49.000000000 +1000
@@ -7,10 +7,22 @@
*/
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
+#include <endian.h>
+#include <byteswap.h>
+
+static inline unsigned int dt_swap_int(unsigned int data)
+{
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ return bswap_32(data);
+#else
+ return data;
+#endif
+}
int recurse;
int maxbytes = 128;
@@ -170,7 +182,7 @@
} else if ((n & 3) == 0) {
nw = n >> 2;
if (nw == 1) {
- i = *(int *)buf;
+ i = dt_swap_int(*(int *)buf);
printf(" %.8x", i);
if (i > -0x10000 && !(i >= 0 && i <= 9))
printf(" (%d)", i);
@@ -185,7 +197,7 @@
if (i != 0)
printf("\n\t\t");
for (j = 0; j < npl && i + j < nw; ++j)
- printf(" %.8x", ((unsigned int *)buf)[i+j]);
+ printf(" %.8x", dt_swap_int(((unsigned int *)buf)[i+j]));
}
}
} else {
More information about the Linuxppc-dev
mailing list