linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* libfdt: Consistently use big-endian property data in testcases
@ 2007-09-17  5:42 David Gibson
  2007-09-17 19:24 ` Jon Loeliger
  0 siblings, 1 reply; 2+ messages in thread
From: David Gibson @ 2007-09-17  5:42 UTC (permalink / raw)
  To: Jon Loeliger; +Cc: linuxppc-dev

Flat device trees always have integers in their structure stored as
big-endian.  From this point of view, property values are
bags-of-bytes and any endianness is up to users of the device tree to
determine.

The libfdt testcases which use properties with integer values,
currently use native endian format for the architecture on which the
testcases are run.  This works ok for now, since both the creation and
checking of the example device trees happen in the same endianness.

This will become a problem, however, for tests of dtc which we want to
add in the nearish future.  dtc always uses big-endian format for
'cell' format data in properties; as it needs to in order to produce
powerpc-usable device trees when hosted on a little-endian
architecture.

This patch, therefore, changes the libfdt testsuite to use big-endian
format always for integer format data, in order to interoperate sanely
with future dtc testcases.  This also means that the example trees
created by the testsuite should now be byte-for-byte identical
regardless of dtc and libfdt's host platform, which is arguably an
advantage.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>

Index: dtc/tests/testdata.h
===================================================================
--- dtc.orig/tests/testdata.h	2007-09-17 11:50:21.000000000 +1000
+++ dtc/tests/testdata.h	2007-09-17 15:41:10.000000000 +1000
@@ -1,5 +1,16 @@
-#define TEST_VALUE_1	0xdeadbeef
-#define TEST_VALUE_2	0xabcd1234
+#include <endian.h>
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define cell_to_fdt(x)	(x)
+#else
+/* We do this as a big hairy expression instead of using bswap_32()
+ * because we need it to work in asm as well as C. */
+#define cell_to_fdt(x)	((((x) >> 24) & 0xff) | (((x) >> 8) & 0xff00) \
+			 | (((x) << 8) & 0xff0000) | (((x) << 24) & 0xff000000))
+#endif
+
+#define TEST_VALUE_1	cell_to_fdt(0xdeadbeef)
+#define TEST_VALUE_2	cell_to_fdt(0xabcd1234)
 
 #define TEST_STRING_1	"hello world"
 


-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: libfdt: Consistently use big-endian property data in testcases
  2007-09-17  5:42 libfdt: Consistently use big-endian property data in testcases David Gibson
@ 2007-09-17 19:24 ` Jon Loeliger
  0 siblings, 0 replies; 2+ messages in thread
From: Jon Loeliger @ 2007-09-17 19:24 UTC (permalink / raw)
  To: David Gibson; +Cc: linuxppc-dev

So, like, the other day David Gibson mumbled:
> Flat device trees always have integers in their structure stored as
> big-endian.  From this point of view, property values are
> bags-of-bytes and any endianness is up to users of the device tree to
> determine.
> 
> The libfdt testcases which use properties with integer values,
> currently use native endian format for the architecture on which the
> testcases are run.  This works ok for now, since both the creation and
> checking of the example device trees happen in the same endianness.
> 
> This will become a problem, however, for tests of dtc which we want to
> add in the nearish future.  dtc always uses big-endian format for
> 'cell' format data in properties; as it needs to in order to produce
> powerpc-usable device trees when hosted on a little-endian
> architecture.
> 
> This patch, therefore, changes the libfdt testsuite to use big-endian
> format always for integer format data, in order to interoperate sanely
> with future dtc testcases.  This also means that the example trees
> created by the testsuite should now be byte-for-byte identical
> regardless of dtc and libfdt's host platform, which is arguably an
> advantage.
> 
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>

Applied.

jdl

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-09-17 19:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-17  5:42 libfdt: Consistently use big-endian property data in testcases David Gibson
2007-09-17 19:24 ` Jon Loeliger

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).