[Crosstoolchain-logs] [device-tree-compiler] 60/357: libfdt: Fix libfdt for little endian hosts

Hector Oron zumbi at moszumanska.debian.org
Thu Dec 8 17:05:48 UTC 2016


This is an automated email from the git hooks/post-receive script.

zumbi pushed a commit to branch upstream/1.3.x
in repository device-tree-compiler.

commit e25487db34c3abc9310c5be4cbb16f8999cc70a9
Author: David Gibson <david at gibson.dropbear.id.au>
Date:   Mon Dec 4 12:52:45 2006 +1100

    libfdt: Fix libfdt for little endian hosts
    
    This patch fixes a number of embarrasing oversights which meant libfdt
    did not work correctly on little endian machines.  With this patch the
    testsuite now passes on x86.  Device trees are always created
    big-endian.
---
 fdt_wip.c         |  2 +-
 libfdt.h          | 20 ++++++++++----------
 tests/root_node.c |  2 +-
 tests/trees.S     | 53 +++++++++++++++++++++++++++++++++++------------------
 4 files changed, 47 insertions(+), 30 deletions(-)

diff --git a/fdt_wip.c b/fdt_wip.c
index 8d68a96..6e617ba 100644
--- a/fdt_wip.c
+++ b/fdt_wip.c
@@ -46,7 +46,7 @@ static void nop_region(void *start, int len)
 	uint32_t *p;
 
 	for (p = start; (void *)p < (start + len); p++)
-		*p = FDT_NOP;
+		*p = cpu_to_fdt32(FDT_NOP);
 }
 
 int fdt_nop_property(struct fdt_header *fdt, int nodeoffset, const char *name)
diff --git a/libfdt.h b/libfdt.h
index 3872eea..8216655 100644
--- a/libfdt.h
+++ b/libfdt.h
@@ -45,16 +45,16 @@
 
 #define FDT_ERR_MAX		14
 
-#define fdt_magic(fdt)			(fdt32_to_cpu(fdt)->magic)
-#define fdt_totalsize(fdt)		(fdt32_to_cpu(fdt)->totalsize)
-#define fdt_off_dt_struct(fdt)		(fdt32_to_cpu(fdt)->off_dt_struct)
-#define fdt_off_dt_strings(fdt)		(fdt32_to_cpu(fdt)->off_dt_strings)
-#define fdt_off_mem_rsvmap(fdt)		(fdt32_to_cpu(fdt)->off_mem_rsvmap)
-#define fdt_version(fdt)		(fdt32_to_cpu(fdt)->version)
-#define fdt_last_comp_version(fdt)	(fdt32_to_cpu(fdt)->last_comp_version)
-#define fdt_boot_cpuid_phys(fdt)	(fdt32_to_cpu(fdt)->boot_cpuid_phys)
-#define fdt_size_dt_strings(fdt)	(fdt32_to_cpu(fdt)->size_dt_strings)
-#define fdt_size_dt_struct(fdt)		(fdt32_to_cpu(fdt)->size_dt_struct)
+#define fdt_magic(fdt)			(fdt32_to_cpu(fdt->magic))
+#define fdt_totalsize(fdt)		(fdt32_to_cpu(fdt->totalsize))
+#define fdt_off_dt_struct(fdt)		(fdt32_to_cpu(fdt->off_dt_struct))
+#define fdt_off_dt_strings(fdt)		(fdt32_to_cpu(fdt->off_dt_strings))
+#define fdt_off_mem_rsvmap(fdt)		(fdt32_to_cpu(fdt->off_mem_rsvmap))
+#define fdt_version(fdt)		(fdt32_to_cpu(fdt->version))
+#define fdt_last_comp_version(fdt)	(fdt32_to_cpu(fdt->last_comp_version))
+#define fdt_boot_cpuid_phys(fdt)	(fdt32_to_cpu(fdt->boot_cpuid_phys))
+#define fdt_size_dt_strings(fdt)	(fdt32_to_cpu(fdt->size_dt_strings))
+#define fdt_size_dt_struct(fdt)		(fdt32_to_cpu(fdt->size_dt_struct))
 
 void *fdt_offset_ptr(const struct fdt_header *fdt, int offset, int checklen);
 
diff --git a/tests/root_node.c b/tests/root_node.c
index ecd1cb1..d331bdf 100644
--- a/tests/root_node.c
+++ b/tests/root_node.c
@@ -41,7 +41,7 @@ int main(int argc, char *argv[])
 	if (! nh)
 		FAIL("NULL retrieving root node");
 
-	if (nh->tag != FDT_BEGIN_NODE)
+	if (fdt32_to_cpu(nh->tag) != FDT_BEGIN_NODE)
 		FAIL("Wrong tag on root node");
 
 	if (strlen(nh->name) != 0)
diff --git a/tests/trees.S b/tests/trees.S
index 7fa4e65..ca8e145 100644
--- a/tests/trees.S
+++ b/tests/trees.S
@@ -1,32 +1,49 @@
 #include <fdt.h>
 #include "testdata.h"
 
+#define FDTLONG(val) \
+	.byte	((val) >> 24) & 0xff ; \
+	.byte	((val) >> 16) & 0xff ; \
+	.byte	((val) >> 8) & 0xff ; \
+	.byte	(val) & 0xff
+
+#define FDTQUAD(val) \
+	.byte	((val) >> 56) & 0xff ; \
+	.byte	((val) >> 48) & 0xff ; \
+	.byte	((val) >> 40) & 0xff ; \
+	.byte	((val) >> 32) & 0xff ; \
+	.byte	((val) >> 24) & 0xff ; \
+	.byte	((val) >> 16) & 0xff ; \
+	.byte	((val) >> 8) & 0xff ; \
+	.byte	(val) & 0xff
+
 #define TREE_HDR(tree) \
 	.globl	_##tree		; \
 _##tree:	\
 tree:	\
-	.long	FDT_MAGIC	; \
-	.long	tree##_end - tree ; \
-	.long	tree##_struct - tree ; \
-	.long	tree##_strings - tree ; \
-	.long	tree##_rsvmap - tree ; \
-	.long	0x11		; \
-	.long	0x10		; \
-	.long	0		; \
-	.long	tree##_end - tree##_strings ; \
-	.long	tree##_strings - tree##_struct ;
+	FDTLONG(FDT_MAGIC)	; \
+	FDTLONG(tree##_end - tree) ; \
+	FDTLONG(tree##_struct - tree) ; \
+	FDTLONG(tree##_strings - tree) ; \
+	FDTLONG(tree##_rsvmap - tree) ; \
+	FDTLONG(0x11)		; \
+	FDTLONG(0x10)		; \
+	FDTLONG(0)		; \
+	FDTLONG(tree##_end - tree##_strings) ; \
+	FDTLONG(tree##_strings - tree##_struct) ;
 
 #define RSVMAP_ENTRY(addr, len) \
-	.quad	addr		; \
-	.quad	len		;
+	FDTQUAD(addr)		; \
+	FDTQUAD(len)		;
 
 #define PROPHDR(tree, name, len) \
-	.long	FDT_PROP	; \
-	.long	tree##_##name - tree##_strings ; \
-	.long	len		;
+	FDTLONG(FDT_PROP)	; \
+	FDTLONG(tree##_##name - tree##_strings) ; \
+	FDTLONG(len)		;
 
 #define PROP_INT(tree, name, val) \
 	PROPHDR(tree, name, 4) \
+	/* For ease of testing the property values go in native-endian */ \
 	.long	val
 
 #define PROP_STR(tree, name, str) \
@@ -37,12 +54,12 @@ tree:	\
 	.balign	4
 
 #define BEGIN_NODE(name) \
-	.long	FDT_BEGIN_NODE	; \
+	FDTLONG(FDT_BEGIN_NODE)	; \
 	.string	name		; \
 	.balign 4
 
 #define END_NODE \
-	.long	FDT_END_NODE	;
+	FDTLONG(FDT_END_NODE)	;
 
 #define STRING(tree, name, str) \
 tree##_##name:	\
@@ -77,7 +94,7 @@ test_tree1_struct:
 	END_NODE
 
 	END_NODE
-	.long	FDT_END
+	FDTLONG(FDT_END)
 
 test_tree1_strings:
 	STRING(test_tree1, prop_int, "prop-int")

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/crosstoolchain/device-tree-compiler.git



More information about the Crosstoolchain-logs mailing list