linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: linuxppc-dev list <linuxppc-dev@ozlabs.org>
Subject: lsprop patch for little endian
Date: Fri, 09 May 2008 10:14:58 +1000	[thread overview]
Message-ID: <1210292098.1421.93.camel@pasglop> (raw)

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 {

                 reply	other threads:[~2008-05-09  0:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1210292098.1421.93.camel@pasglop \
    --to=benh@kernel.crashing.org \
    --cc=linuxppc-dev@ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).