libfdt: Rename and publish _fdt_next_tag()

Although it's a low-level function that shouldn't normally be needed,
there are circumstances where it's useful for users of libfdt to use
the _fdt_next_tag() function.  Therefore, this patch renames it to
fdt_next_tag() and publishes it in libfdt.h.

In addition, this patch adds a new testcase using fdt_next_tag(),
dtbs_equal_ordered.  This testcase tests for structural equality of
two dtbs, including the order of properties and subnodes, but ignoring
NOP tags, the order of the dtb sections and the layout of strings in
the strings block.  This will be useful for testing other dtc
functionality in the future.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2007-10-24 11:06:09 +10:00 committed by Jon Loeliger
parent 96b5fad3a1
commit 3c44c87bde
10 changed files with 162 additions and 21 deletions

View file

@ -90,7 +90,7 @@ const 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)
uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset)
{
const uint32_t *tagp, *lenp;
uint32_t tag;

View file

@ -113,13 +113,13 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
CHECK_HEADER(fdt);
tag = _fdt_next_tag(fdt, parentoffset, &nextoffset);
tag = fdt_next_tag(fdt, parentoffset, &nextoffset);
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);
switch (tag) {
case FDT_END:
@ -229,14 +229,14 @@ const struct fdt_property *fdt_get_property(const void *fdt,
if (nodeoffset % FDT_TAGSIZE)
goto fail;
tag = _fdt_next_tag(fdt, nodeoffset, &nextoffset);
tag = fdt_next_tag(fdt, nodeoffset, &nextoffset);
if (tag != FDT_BEGIN_NODE)
goto fail;
do {
offset = nextoffset;
tag = _fdt_next_tag(fdt, offset, &nextoffset);
tag = fdt_next_tag(fdt, offset, &nextoffset);
switch (tag) {
case FDT_END:
err = -FDT_ERR_TRUNCATED;
@ -302,7 +302,7 @@ int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
CHECK_HEADER(fdt);
tag = _fdt_next_tag(fdt, 0, &nextoffset);
tag = fdt_next_tag(fdt, 0, &nextoffset);
if (tag != FDT_BEGIN_NODE)
return -FDT_ERR_BADSTRUCTURE;
@ -313,7 +313,7 @@ int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
while (nextoffset <= nodeoffset) {
offset = nextoffset;
tag = _fdt_next_tag(fdt, offset, &nextoffset);
tag = fdt_next_tag(fdt, offset, &nextoffset);
switch (tag) {
case FDT_END:
return -FDT_ERR_BADOFFSET;
@ -374,7 +374,7 @@ int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
do {
offset = nextoffset;
tag = _fdt_next_tag(fdt, offset, &nextoffset);
tag = fdt_next_tag(fdt, offset, &nextoffset);
switch (tag) {
case FDT_END:
return -FDT_ERR_BADOFFSET;
@ -439,7 +439,7 @@ int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
CHECK_HEADER(fdt);
if (startoffset >= 0) {
tag = _fdt_next_tag(fdt, startoffset, &nextoffset);
tag = fdt_next_tag(fdt, startoffset, &nextoffset);
if (tag != FDT_BEGIN_NODE)
return -FDT_ERR_BADOFFSET;
} else {
@ -453,7 +453,7 @@ int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
* approach; performance can come later. */
do {
offset = nextoffset;
tag = _fdt_next_tag(fdt, offset, &nextoffset);
tag = fdt_next_tag(fdt, offset, &nextoffset);
switch (tag) {
case FDT_BEGIN_NODE:
@ -520,7 +520,7 @@ int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
CHECK_HEADER(fdt);
if (startoffset >= 0) {
tag = _fdt_next_tag(fdt, startoffset, &nextoffset);
tag = fdt_next_tag(fdt, startoffset, &nextoffset);
if (tag != FDT_BEGIN_NODE)
return -FDT_ERR_BADOFFSET;
} else {
@ -534,7 +534,7 @@ int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
* implement approach; performance can come later. */
do {
offset = nextoffset;
tag = _fdt_next_tag(fdt, offset, &nextoffset);
tag = fdt_next_tag(fdt, offset, &nextoffset);
switch (tag) {
case FDT_BEGIN_NODE:

View file

@ -224,7 +224,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);
if (tag != FDT_BEGIN_NODE)
return -FDT_ERR_BADOFFSET;
@ -298,10 +298,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); /* skip the BEGIN_NODE */
do {
offset = nextoffset;
tag = _fdt_next_tag(fdt, offset, &nextoffset);
tag = fdt_next_tag(fdt, offset, &nextoffset);
} while (tag == FDT_PROP);
nh = _fdt_offset_ptr_w(fdt, offset);

View file

@ -235,7 +235,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)) != FDT_END) {
if (tag == FDT_PROP) {
struct fdt_property *prop =
fdt_offset_ptr_w(fdt, offset, sizeof(*prop));

View file

@ -100,12 +100,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);
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);
switch (tag) {
case FDT_END:

View file

@ -93,8 +93,9 @@ static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
#define fdt_offset_ptr_typed_w(fdt, offset, var) \
((typeof(var))(fdt_offset_ptr_w((fdt), (offset), sizeof(*(var)))))
/* General functions */
uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
/* General functions */
#define fdt_get_header(fdt, field) \
(fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
#define fdt_magic(fdt) (fdt_get_header(fdt, magic))