* lsprop patch for little endian
@ 2008-05-09 0:14 Benjamin Herrenschmidt
0 siblings, 0 replies; only message in thread
From: Benjamin Herrenschmidt @ 2008-05-09 0:14 UTC (permalink / raw)
To: linuxppc-dev list
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 {
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-05-09 0:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-09 0:14 lsprop patch for little endian Benjamin Herrenschmidt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).