Skip to contentSkip to conversation

libfdt: Enhanced and published fdt_next_tag()

PATCH New Jerry Van Baren 1 participant 1 message Mar 31, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 4/6 libfdt: Enhanced and published fdt_next_tag()

Enhanced the formerly private function _fdt_next_tag() to allow stepping
through the tree, used to produce a human-readable dump, and made it part of the published interface.
Also added some comments.

---
 include/libfdt.h         |    3 +
 libfdt/fdt.c             |   39 ---------------
 libfdt/fdt_ro.c          |  116 +++++++++++++++++++++++++++++++++++++++++++--
 libfdt/fdt_rw.c          |    6 +-
 libfdt/fdt_sw.c          |    2 +-
 libfdt/fdt_wip.c         |    4 +-
 libfdt/libfdt_internal.h |    1 -
 7 files changed, 119 insertions(+), 52 deletions(-)
include/libfdt.h +3 -0
index acdc72e..c4b3c24 100644
@@ -81,6 +81,9 @@ struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
 void *fdt_getprop(const void *fdt, int nodeoffset,
 		  const char *name, int *lenp);
 
+uint32_t fdt_next_tag(const void *fdt, int offset,
+                      int *nextoffset, char **namep);
+
 /* Write-in-place functions */
 int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
 			const void *val, int len);
libfdt/fdt.c +0 -39
index 772da46..4b1c8ab 100644
@@ -58,45 +58,6 @@ void *fdt_offset_ptr(const void *fdt, int offset, int len)
 	return p;
 }
 
-uint32_t _fdt_next_tag(const void *fdt, int offset, int *nextoffset)
-{
-	const uint32_t *tagp, *lenp;
-	uint32_t tag;
-	const char *p;
-
-	if (offset % FDT_TAGSIZE)
-		return -1;
-
-	tagp = fdt_offset_ptr(fdt, offset, FDT_TAGSIZE);
-	if (! tagp)
-		return FDT_END; /* premature end */
-	tag = fdt32_to_cpu(*tagp);
-	offset += FDT_TAGSIZE;
-
-	switch (tag) {
-	case FDT_BEGIN_NODE:
-		/* skip name */
-		do {
-			p = fdt_offset_ptr(fdt, offset++, 1);
-		} while (p && (*p != '\0'));
-		if (! p)
-			return FDT_END;
-		break;
-	case FDT_PROP:
-		lenp = fdt_offset_ptr(fdt, offset, sizeof(*lenp));
-		if (! lenp)
-			return FDT_END;
-		/* skip name offset, length and value */
-		offset += 2*FDT_TAGSIZE + fdt32_to_cpu(*lenp);
-		break;
-	}
-
-	if (nextoffset)
-		*nextoffset = ALIGN(offset, FDT_TAGSIZE);
-
-	return tag;
-}
-
 const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)
 {
 	int len = strlen(s) + 1;
libfdt/fdt_ro.c +110 -6

214 lines not on this page · raw message

libfdt/fdt_rw.c +3 -3
index 7396645..b33fbf4 100644
@@ -145,7 +145,7 @@ static int _add_property(void *fdt, int nodeoffset, const char *name, int len,
 	int namestroff;
 	int err;
 
-	tag = _fdt_next_tag(fdt, nodeoffset, &nextoffset);
+	tag = fdt_next_tag(fdt, nodeoffset, &nextoffset, NULL);
 	if (tag != FDT_BEGIN_NODE)
 		return -FDT_ERR_BADOFFSET;
 
@@ -219,10 +219,10 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
 		return offset;
 
 	/* Try to place the new node after the parent's properties */
-	_fdt_next_tag(fdt, parentoffset, &nextoffset); /* skip the BEGIN_NODE */
+	fdt_next_tag(fdt, parentoffset, &nextoffset, NULL); /* skip the BEGIN_NODE */
 	do {
 		offset = nextoffset;
-		tag = _fdt_next_tag(fdt, offset, &nextoffset);
+		tag = fdt_next_tag(fdt, offset, &nextoffset, NULL);
 	} while (tag == FDT_PROP);
 
 	nh = _fdt_offset_ptr(fdt, offset);
libfdt/fdt_sw.c +1 -1
index 41d4891..672f4dd 100644
@@ -203,7 +203,7 @@ int fdt_finish(void *fdt)
 
 	/* Walk the structure, correcting string offsets */
 	offset = 0;
-	while ((tag = _fdt_next_tag(fdt, offset, &nextoffset)) != FDT_END) {
+	while ((tag = fdt_next_tag(fdt, offset, &nextoffset, NULL)) != FDT_END) {
 		if (tag == FDT_PROP) {
 			struct fdt_property *prop = fdt_offset_ptr(fdt, offset,
 								   sizeof(*prop));
libfdt/fdt_wip.c +2 -2
index 0db7d25..261b9b0 100644
@@ -68,12 +68,12 @@ int _fdt_node_end_offset(void *fdt, int nodeoffset)
 	uint32_t tag;
 	int offset, nextoffset;
 
-	tag = _fdt_next_tag(fdt, nodeoffset, &nextoffset);
+	tag = fdt_next_tag(fdt, nodeoffset, &nextoffset, NULL);
 	if (tag != FDT_BEGIN_NODE)
 		return -FDT_ERR_BADOFFSET;
 	do {
 		offset = nextoffset;
-		tag = _fdt_next_tag(fdt, offset, &nextoffset);
+		tag = fdt_next_tag(fdt, offset, &nextoffset, NULL);
 
 		switch (tag) {
 		case FDT_END:
libfdt/libfdt_internal.h +0 -1
index 124bef7..cc9633c 100644
@@ -27,7 +27,6 @@
 #define streq(p, q)	(strcmp((p), (q)) == 0)
 
 int _fdt_check_header(const void *fdt);
-uint32_t _fdt_next_tag(const void *fdt, int startoffset, int *nextoffset);
 const char *_fdt_find_string(const char *strtab, int tabsize, const char *s);
 int _fdt_node_end_offset(void *fdt, int nodeoffset);
 
Signature · 1 line
1.4.4.4