libfdt: More consistent handling of returned error codes.
At present, libfdt functions returning a structure offset return a zero-or-positive offset on success, and return a negative error code on failure. Functions which only return an error code return a positive version of the error code, or 0 on success. This patch improves consistency by always returning negative error codes on failure, for both types of function. With this change, we do away with the special fdt_offset_error() macro for checking whether a returned offset value is an error and extracting the encoded error value within. Instead an explicit (ret_value < 0) is now the preferred way of checking return values for both offset-returning and error-code-returning functions. The fdt_strerror() function in the test code is updated correspondingly to make more sense with the new conventions. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>main
parent
a7ee95ded6
commit
9a9fdf5991
12
fdt.c
12
fdt.c
|
@ -28,15 +28,15 @@ int _fdt_check_header(const void *fdt)
|
||||||
if (fdt_magic(fdt) == FDT_MAGIC) {
|
if (fdt_magic(fdt) == FDT_MAGIC) {
|
||||||
/* Complete tree */
|
/* Complete tree */
|
||||||
if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
|
if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
|
||||||
return FDT_ERR_BADVERSION;
|
return -FDT_ERR_BADVERSION;
|
||||||
if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION)
|
if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION)
|
||||||
return FDT_ERR_BADVERSION;
|
return -FDT_ERR_BADVERSION;
|
||||||
} else if (fdt_magic(fdt) == SW_MAGIC) {
|
} else if (fdt_magic(fdt) == SW_MAGIC) {
|
||||||
/* Unfinished sequential-write blob */
|
/* Unfinished sequential-write blob */
|
||||||
if (fdt_size_dt_struct(fdt) == 0)
|
if (fdt_size_dt_struct(fdt) == 0)
|
||||||
return FDT_ERR_BADSTATE;
|
return -FDT_ERR_BADSTATE;
|
||||||
} else {
|
} else {
|
||||||
return FDT_ERR_BADMAGIC;
|
return -FDT_ERR_BADMAGIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -117,8 +117,8 @@ int fdt_move(const void *fdt, void *buf, int bufsize)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (fdt_totalsize(fdt) > bufsize)
|
if (fdt_totalsize(fdt) > bufsize)
|
||||||
return FDT_ERR_NOSPACE;
|
return -FDT_ERR_NOSPACE;
|
||||||
|
|
||||||
memmove(buf, fdt, fdt_totalsize(fdt));
|
memmove(buf, fdt, fdt_totalsize(fdt));
|
||||||
return FDT_ERR_OK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
36
fdt_ro.c
36
fdt_ro.c
|
@ -23,11 +23,11 @@
|
||||||
|
|
||||||
#include "libfdt_internal.h"
|
#include "libfdt_internal.h"
|
||||||
|
|
||||||
#define OFFSET_CHECK_HEADER(fdt) \
|
#define CHECK_HEADER(fdt) \
|
||||||
{ \
|
{ \
|
||||||
int err; \
|
int err; \
|
||||||
if ((err = _fdt_check_header(fdt)) != 0) \
|
if ((err = _fdt_check_header(fdt)) != 0) \
|
||||||
return OFFSET_ERROR(err); \
|
return err; \
|
||||||
}
|
}
|
||||||
|
|
||||||
static int offset_streq(const void *fdt, int offset,
|
static int offset_streq(const void *fdt, int offset,
|
||||||
|
@ -60,11 +60,11 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
int offset, nextoffset;
|
int offset, nextoffset;
|
||||||
|
|
||||||
OFFSET_CHECK_HEADER(fdt);
|
CHECK_HEADER(fdt);
|
||||||
|
|
||||||
tag = _fdt_next_tag(fdt, parentoffset, &nextoffset);
|
tag = _fdt_next_tag(fdt, parentoffset, &nextoffset);
|
||||||
if (tag != FDT_BEGIN_NODE)
|
if (tag != FDT_BEGIN_NODE)
|
||||||
return OFFSET_ERROR(FDT_ERR_BADOFFSET);
|
return -FDT_ERR_BADOFFSET;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
offset = nextoffset;
|
offset = nextoffset;
|
||||||
|
@ -72,7 +72,7 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
|
||||||
|
|
||||||
switch (tag) {
|
switch (tag) {
|
||||||
case FDT_END:
|
case FDT_END:
|
||||||
return OFFSET_ERROR(FDT_ERR_TRUNCATED);
|
return -FDT_ERR_TRUNCATED;
|
||||||
|
|
||||||
case FDT_BEGIN_NODE:
|
case FDT_BEGIN_NODE:
|
||||||
level++;
|
level++;
|
||||||
|
@ -92,11 +92,11 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return OFFSET_ERROR(FDT_ERR_BADSTRUCTURE);
|
return -FDT_ERR_BADSTRUCTURE;
|
||||||
}
|
}
|
||||||
} while (level >= 0);
|
} while (level >= 0);
|
||||||
|
|
||||||
return OFFSET_ERROR(FDT_ERR_NOTFOUND);
|
return -FDT_ERR_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fdt_subnode_offset(const void *fdt, int parentoffset,
|
int fdt_subnode_offset(const void *fdt, int parentoffset,
|
||||||
|
@ -111,10 +111,10 @@ int fdt_path_offset(const void *fdt, const char *path)
|
||||||
const char *p = path;
|
const char *p = path;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
OFFSET_CHECK_HEADER(fdt);
|
CHECK_HEADER(fdt);
|
||||||
|
|
||||||
if (*path != '/')
|
if (*path != '/')
|
||||||
return OFFSET_ERROR(FDT_ERR_BADPATH);
|
return -FDT_ERR_BADPATH;
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
const char *q;
|
const char *q;
|
||||||
|
@ -122,13 +122,13 @@ int fdt_path_offset(const void *fdt, const char *path)
|
||||||
while (*p == '/')
|
while (*p == '/')
|
||||||
p++;
|
p++;
|
||||||
if (! *p)
|
if (! *p)
|
||||||
return OFFSET_ERROR(FDT_ERR_BADPATH);
|
return -FDT_ERR_BADPATH;
|
||||||
q = strchr(p, '/');
|
q = strchr(p, '/');
|
||||||
if (! q)
|
if (! q)
|
||||||
q = end;
|
q = end;
|
||||||
|
|
||||||
offset = fdt_subnode_offset_namelen(fdt, offset, p, q-p);
|
offset = fdt_subnode_offset_namelen(fdt, offset, p, q-p);
|
||||||
if (fdt_offset_error(offset))
|
if (offset < 0)
|
||||||
return offset;
|
return offset;
|
||||||
|
|
||||||
p = q;
|
p = q;
|
||||||
|
@ -151,7 +151,7 @@ struct fdt_property *fdt_get_property(const void *fdt,
|
||||||
if ((err = _fdt_check_header(fdt)) != 0)
|
if ((err = _fdt_check_header(fdt)) != 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
err = FDT_ERR_BADOFFSET;
|
err = -FDT_ERR_BADOFFSET;
|
||||||
if (nodeoffset % FDT_TAGSIZE)
|
if (nodeoffset % FDT_TAGSIZE)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
@ -161,14 +161,14 @@ struct fdt_property *fdt_get_property(const void *fdt,
|
||||||
|
|
||||||
do {
|
do {
|
||||||
offset = nextoffset;
|
offset = nextoffset;
|
||||||
err = FDT_ERR_INTERNAL;
|
err = -FDT_ERR_INTERNAL;
|
||||||
if (offset % FDT_TAGSIZE)
|
if (offset % FDT_TAGSIZE)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
tag = _fdt_next_tag(fdt, offset, &nextoffset);
|
tag = _fdt_next_tag(fdt, offset, &nextoffset);
|
||||||
switch (tag) {
|
switch (tag) {
|
||||||
case FDT_END:
|
case FDT_END:
|
||||||
err = FDT_ERR_TRUNCATED;
|
err = -FDT_ERR_TRUNCATED;
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
case FDT_BEGIN_NODE:
|
case FDT_BEGIN_NODE:
|
||||||
|
@ -183,7 +183,7 @@ struct fdt_property *fdt_get_property(const void *fdt,
|
||||||
if (level != 0)
|
if (level != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
err = FDT_ERR_BADSTRUCTURE;
|
err = -FDT_ERR_BADSTRUCTURE;
|
||||||
prop = fdt_offset_ptr_typed(fdt, offset, prop);
|
prop = fdt_offset_ptr_typed(fdt, offset, prop);
|
||||||
if (! prop)
|
if (! prop)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -207,15 +207,15 @@ struct fdt_property *fdt_get_property(const void *fdt,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
err = FDT_ERR_BADSTRUCTURE;
|
err = -FDT_ERR_BADSTRUCTURE;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
} while (level >= 0);
|
} while (level >= 0);
|
||||||
|
|
||||||
err = FDT_ERR_NOTFOUND;
|
err = -FDT_ERR_NOTFOUND;
|
||||||
fail:
|
fail:
|
||||||
if (lenp)
|
if (lenp)
|
||||||
*lenp = -err;
|
*lenp = err;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
53
fdt_rw.c
53
fdt_rw.c
|
@ -30,26 +30,26 @@ static int rw_check_header(void *fdt)
|
||||||
if ((err = _fdt_check_header(fdt)))
|
if ((err = _fdt_check_header(fdt)))
|
||||||
return err;
|
return err;
|
||||||
if (fdt_version(fdt) < 0x11)
|
if (fdt_version(fdt) < 0x11)
|
||||||
return FDT_ERR_BADVERSION;
|
return -FDT_ERR_BADVERSION;
|
||||||
if (fdt_off_mem_rsvmap(fdt) < ALIGN(sizeof(struct fdt_header), 8))
|
if (fdt_off_mem_rsvmap(fdt) < ALIGN(sizeof(struct fdt_header), 8))
|
||||||
return FDT_ERR_BADLAYOUT;
|
return -FDT_ERR_BADLAYOUT;
|
||||||
if (fdt_off_dt_struct(fdt) <
|
if (fdt_off_dt_struct(fdt) <
|
||||||
(fdt_off_mem_rsvmap(fdt) + sizeof(struct fdt_reserve_entry)))
|
(fdt_off_mem_rsvmap(fdt) + sizeof(struct fdt_reserve_entry)))
|
||||||
return FDT_ERR_BADLAYOUT;
|
return -FDT_ERR_BADLAYOUT;
|
||||||
if (fdt_off_dt_strings(fdt) <
|
if (fdt_off_dt_strings(fdt) <
|
||||||
(fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt)))
|
(fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt)))
|
||||||
return FDT_ERR_BADLAYOUT;
|
return -FDT_ERR_BADLAYOUT;
|
||||||
if (fdt_totalsize(fdt) <
|
if (fdt_totalsize(fdt) <
|
||||||
(fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt)))
|
(fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt)))
|
||||||
return FDT_ERR_BADLAYOUT;
|
return -FDT_ERR_BADLAYOUT;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RW_OFFSET_CHECK_HEADER(fdt) \
|
#define RW_CHECK_HEADER(fdt) \
|
||||||
{ \
|
{ \
|
||||||
int err; \
|
int err; \
|
||||||
if ((err = rw_check_header(fdt)) != 0) \
|
if ((err = rw_check_header(fdt)) != 0) \
|
||||||
return OFFSET_ERROR(err); \
|
return err; \
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int _blob_data_size(void *fdt)
|
static inline int _blob_data_size(void *fdt)
|
||||||
|
@ -62,9 +62,9 @@ static int _blob_splice(void *fdt, void *p, int oldlen, int newlen)
|
||||||
void *end = fdt + _blob_data_size(fdt);
|
void *end = fdt + _blob_data_size(fdt);
|
||||||
|
|
||||||
if (((p + oldlen) < p) || ((p + oldlen) > end))
|
if (((p + oldlen) < p) || ((p + oldlen) > end))
|
||||||
return FDT_ERR_BADOFFSET;
|
return -FDT_ERR_BADOFFSET;
|
||||||
if ((end - oldlen + newlen) > (fdt + fdt_totalsize(fdt)))
|
if ((end - oldlen + newlen) > (fdt + fdt_totalsize(fdt)))
|
||||||
return FDT_ERR_NOSPACE;
|
return -FDT_ERR_NOSPACE;
|
||||||
memmove(p + newlen, p + oldlen, end - p - oldlen);
|
memmove(p + newlen, p + oldlen, end - p - oldlen);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ static int _find_add_string(void *fdt, const char *s)
|
||||||
new = strtab + fdt_size_dt_strings(fdt);
|
new = strtab + fdt_size_dt_strings(fdt);
|
||||||
err = _blob_splice_string(fdt, len);
|
err = _blob_splice_string(fdt, len);
|
||||||
if (err)
|
if (err)
|
||||||
return -err;
|
return err;
|
||||||
|
|
||||||
memcpy(new, s, len);
|
memcpy(new, s, len);
|
||||||
return (new - strtab);
|
return (new - strtab);
|
||||||
|
@ -125,7 +125,7 @@ static int _resize_property(void *fdt, int nodeoffset, const char *name, int len
|
||||||
|
|
||||||
*prop = fdt_get_property(fdt, nodeoffset, name, &oldlen);
|
*prop = fdt_get_property(fdt, nodeoffset, name, &oldlen);
|
||||||
if (! (*prop))
|
if (! (*prop))
|
||||||
return -oldlen;
|
return oldlen;
|
||||||
|
|
||||||
if ((err = _blob_splice_struct(fdt, (*prop)->data,
|
if ((err = _blob_splice_struct(fdt, (*prop)->data,
|
||||||
ALIGN(oldlen, FDT_TAGSIZE),
|
ALIGN(oldlen, FDT_TAGSIZE),
|
||||||
|
@ -147,11 +147,11 @@ static int _add_property(void *fdt, int nodeoffset, const char *name, int len,
|
||||||
|
|
||||||
tag = _fdt_next_tag(fdt, nodeoffset, &nextoffset);
|
tag = _fdt_next_tag(fdt, nodeoffset, &nextoffset);
|
||||||
if (tag != FDT_BEGIN_NODE)
|
if (tag != FDT_BEGIN_NODE)
|
||||||
return FDT_ERR_BADOFFSET;
|
return -FDT_ERR_BADOFFSET;
|
||||||
|
|
||||||
namestroff = _find_add_string(fdt, name);
|
namestroff = _find_add_string(fdt, name);
|
||||||
if (namestroff < 0)
|
if (namestroff < 0)
|
||||||
return -namestroff;
|
return namestroff;
|
||||||
|
|
||||||
*prop = _fdt_offset_ptr(fdt, nextoffset);
|
*prop = _fdt_offset_ptr(fdt, nextoffset);
|
||||||
proplen = sizeof(**prop) + ALIGN(len, FDT_TAGSIZE);
|
proplen = sizeof(**prop) + ALIGN(len, FDT_TAGSIZE);
|
||||||
|
@ -176,7 +176,7 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name,
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
err = _resize_property(fdt, nodeoffset, name, len, &prop);
|
err = _resize_property(fdt, nodeoffset, name, len, &prop);
|
||||||
if (err == FDT_ERR_NOTFOUND)
|
if (err == -FDT_ERR_NOTFOUND)
|
||||||
err = _add_property(fdt, nodeoffset, name, len, &prop);
|
err = _add_property(fdt, nodeoffset, name, len, &prop);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
@ -190,11 +190,11 @@ int fdt_delprop(void *fdt, int nodeoffset, const char *name)
|
||||||
struct fdt_property *prop;
|
struct fdt_property *prop;
|
||||||
int len, proplen;
|
int len, proplen;
|
||||||
|
|
||||||
RW_OFFSET_CHECK_HEADER(fdt);
|
RW_CHECK_HEADER(fdt);
|
||||||
|
|
||||||
prop = fdt_get_property(fdt, nodeoffset, name, &len);
|
prop = fdt_get_property(fdt, nodeoffset, name, &len);
|
||||||
if (! prop)
|
if (! prop)
|
||||||
return -len;
|
return len;
|
||||||
|
|
||||||
proplen = sizeof(*prop) + ALIGN(len, FDT_TAGSIZE);
|
proplen = sizeof(*prop) + ALIGN(len, FDT_TAGSIZE);
|
||||||
return _blob_splice_struct(fdt, prop, proplen, 0);
|
return _blob_splice_struct(fdt, prop, proplen, 0);
|
||||||
|
@ -210,13 +210,13 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
uint32_t *endtag;
|
uint32_t *endtag;
|
||||||
|
|
||||||
RW_OFFSET_CHECK_HEADER(fdt);
|
RW_CHECK_HEADER(fdt);
|
||||||
|
|
||||||
offset = fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen);
|
offset = fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen);
|
||||||
if ((err = fdt_offset_error(offset)) == 0)
|
if (offset >= 0)
|
||||||
return OFFSET_ERROR(FDT_ERR_EXISTS);
|
return -FDT_ERR_EXISTS;
|
||||||
else if (err != FDT_ERR_NOTFOUND)
|
else if (offset != -FDT_ERR_NOTFOUND)
|
||||||
return OFFSET_ERROR(err);
|
return offset;
|
||||||
|
|
||||||
/* Try to place the new node after the parent's properties */
|
/* 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 */
|
||||||
|
@ -230,7 +230,7 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
|
||||||
|
|
||||||
err = _blob_splice_struct(fdt, nh, 0, nodelen);
|
err = _blob_splice_struct(fdt, nh, 0, nodelen);
|
||||||
if (err)
|
if (err)
|
||||||
return OFFSET_ERROR(err);
|
return err;
|
||||||
|
|
||||||
nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
|
nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
|
||||||
memset(nh->name, 0, ALIGN(namelen+1, FDT_TAGSIZE));
|
memset(nh->name, 0, ALIGN(namelen+1, FDT_TAGSIZE));
|
||||||
|
@ -249,11 +249,10 @@ int fdt_add_subnode(void *fdt, int parentoffset, const char *name)
|
||||||
int fdt_del_node(void *fdt, int nodeoffset)
|
int fdt_del_node(void *fdt, int nodeoffset)
|
||||||
{
|
{
|
||||||
int endoffset;
|
int endoffset;
|
||||||
int err;
|
|
||||||
|
|
||||||
endoffset = _fdt_node_end_offset(fdt, nodeoffset);
|
endoffset = _fdt_node_end_offset(fdt, nodeoffset);
|
||||||
if ((err = fdt_offset_error(endoffset)))
|
if (endoffset < 0)
|
||||||
return err;
|
return endoffset;
|
||||||
|
|
||||||
return _blob_splice_struct(fdt, _fdt_offset_ptr(fdt, nodeoffset),
|
return _blob_splice_struct(fdt, _fdt_offset_ptr(fdt, nodeoffset),
|
||||||
endoffset - nodeoffset, 0);
|
endoffset - nodeoffset, 0);
|
||||||
|
@ -277,7 +276,7 @@ int fdt_open_into(void *fdt, void *buf, int bufsize)
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
return FDT_ERR_OK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fdt_pack(void *fdt)
|
int fdt_pack(void *fdt)
|
||||||
|
@ -290,5 +289,5 @@ int fdt_pack(void *fdt)
|
||||||
|
|
||||||
/* FIXME: pack components */
|
/* FIXME: pack components */
|
||||||
fdt_set_header(fdt, totalsize, _blob_data_size(fdt));
|
fdt_set_header(fdt, totalsize, _blob_data_size(fdt));
|
||||||
return FDT_ERR_OK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
22
fdt_sw.c
22
fdt_sw.c
|
@ -26,7 +26,7 @@
|
||||||
static int check_header_sw(void *fdt)
|
static int check_header_sw(void *fdt)
|
||||||
{
|
{
|
||||||
if (fdt_magic(fdt) != SW_MAGIC)
|
if (fdt_magic(fdt) != SW_MAGIC)
|
||||||
return FDT_ERR_BADMAGIC;
|
return -FDT_ERR_BADMAGIC;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ int fdt_create(void *buf, int bufsize)
|
||||||
void *fdt = buf;
|
void *fdt = buf;
|
||||||
|
|
||||||
if (bufsize < sizeof(struct fdt_header))
|
if (bufsize < sizeof(struct fdt_header))
|
||||||
return FDT_ERR_NOSPACE;
|
return -FDT_ERR_NOSPACE;
|
||||||
|
|
||||||
memset(buf, 0, bufsize);
|
memset(buf, 0, bufsize);
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ int fdt_create(void *buf, int bufsize)
|
||||||
fdt_set_header(fdt, off_dt_struct, fdt_off_mem_rsvmap(fdt));
|
fdt_set_header(fdt, off_dt_struct, fdt_off_mem_rsvmap(fdt));
|
||||||
fdt_set_header(fdt, off_dt_strings, bufsize);
|
fdt_set_header(fdt, off_dt_strings, bufsize);
|
||||||
|
|
||||||
return FDT_ERR_OK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size)
|
int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size)
|
||||||
|
@ -76,11 +76,11 @@ int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size)
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
if (fdt_size_dt_struct(fdt))
|
if (fdt_size_dt_struct(fdt))
|
||||||
return FDT_ERR_BADSTATE;
|
return -FDT_ERR_BADSTATE;
|
||||||
|
|
||||||
offset = fdt_off_dt_struct(fdt);
|
offset = fdt_off_dt_struct(fdt);
|
||||||
if ((offset + sizeof(*re)) > fdt_totalsize(fdt))
|
if ((offset + sizeof(*re)) > fdt_totalsize(fdt))
|
||||||
return FDT_ERR_NOSPACE;
|
return -FDT_ERR_NOSPACE;
|
||||||
|
|
||||||
re = (struct fdt_reserve_entry *)((void *)fdt + offset);
|
re = (struct fdt_reserve_entry *)((void *)fdt + offset);
|
||||||
re->address = cpu_to_fdt64(addr);
|
re->address = cpu_to_fdt64(addr);
|
||||||
|
@ -107,7 +107,7 @@ int fdt_begin_node(void *fdt, const char *name)
|
||||||
|
|
||||||
nh = grab_space(fdt, sizeof(*nh) + ALIGN(namelen, FDT_TAGSIZE));
|
nh = grab_space(fdt, sizeof(*nh) + ALIGN(namelen, FDT_TAGSIZE));
|
||||||
if (! nh)
|
if (! nh)
|
||||||
return FDT_ERR_NOSPACE;
|
return -FDT_ERR_NOSPACE;
|
||||||
|
|
||||||
nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
|
nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
|
||||||
memcpy(nh->name, name, namelen);
|
memcpy(nh->name, name, namelen);
|
||||||
|
@ -124,7 +124,7 @@ int fdt_end_node(void *fdt)
|
||||||
|
|
||||||
en = grab_space(fdt, FDT_TAGSIZE);
|
en = grab_space(fdt, FDT_TAGSIZE);
|
||||||
if (! en)
|
if (! en)
|
||||||
return FDT_ERR_NOSPACE;
|
return -FDT_ERR_NOSPACE;
|
||||||
|
|
||||||
*en = cpu_to_fdt32(FDT_END_NODE);
|
*en = cpu_to_fdt32(FDT_END_NODE);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -164,11 +164,11 @@ int fdt_property(void *fdt, const char *name, const void *val, int len)
|
||||||
|
|
||||||
nameoff = find_add_string(fdt, name);
|
nameoff = find_add_string(fdt, name);
|
||||||
if (nameoff == 0)
|
if (nameoff == 0)
|
||||||
return FDT_ERR_NOSPACE;
|
return -FDT_ERR_NOSPACE;
|
||||||
|
|
||||||
prop = grab_space(fdt, sizeof(*prop) + ALIGN(len, FDT_TAGSIZE));
|
prop = grab_space(fdt, sizeof(*prop) + ALIGN(len, FDT_TAGSIZE));
|
||||||
if (! prop)
|
if (! prop)
|
||||||
return FDT_ERR_NOSPACE;
|
return -FDT_ERR_NOSPACE;
|
||||||
|
|
||||||
prop->tag = cpu_to_fdt32(FDT_PROP);
|
prop->tag = cpu_to_fdt32(FDT_PROP);
|
||||||
prop->nameoff = cpu_to_fdt32(nameoff);
|
prop->nameoff = cpu_to_fdt32(nameoff);
|
||||||
|
@ -192,7 +192,7 @@ int fdt_finish(void *fdt)
|
||||||
/* Add terminator */
|
/* Add terminator */
|
||||||
end = grab_space(fdt, sizeof(*end));
|
end = grab_space(fdt, sizeof(*end));
|
||||||
if (! end)
|
if (! end)
|
||||||
return FDT_ERR_NOSPACE;
|
return -FDT_ERR_NOSPACE;
|
||||||
*end = cpu_to_fdt32(FDT_END);
|
*end = cpu_to_fdt32(FDT_END);
|
||||||
|
|
||||||
/* Relocate the string table */
|
/* Relocate the string table */
|
||||||
|
@ -210,7 +210,7 @@ int fdt_finish(void *fdt)
|
||||||
int nameoff;
|
int nameoff;
|
||||||
|
|
||||||
if (! prop)
|
if (! prop)
|
||||||
return FDT_ERR_BADSTRUCTURE;
|
return -FDT_ERR_BADSTRUCTURE;
|
||||||
|
|
||||||
nameoff = fdt32_to_cpu(prop->nameoff);
|
nameoff = fdt32_to_cpu(prop->nameoff);
|
||||||
nameoff += fdt_size_dt_strings(fdt);
|
nameoff += fdt_size_dt_strings(fdt);
|
||||||
|
|
15
fdt_wip.c
15
fdt_wip.c
|
@ -31,10 +31,10 @@ int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
|
||||||
|
|
||||||
propval = fdt_getprop(fdt, nodeoffset, name, &proplen);
|
propval = fdt_getprop(fdt, nodeoffset, name, &proplen);
|
||||||
if (! propval)
|
if (! propval)
|
||||||
return -proplen;
|
return proplen;
|
||||||
|
|
||||||
if (proplen != len)
|
if (proplen != len)
|
||||||
return FDT_ERR_SIZE_MISMATCH;
|
return -FDT_ERR_SIZE_MISMATCH;
|
||||||
|
|
||||||
memcpy(propval, val, len);
|
memcpy(propval, val, len);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -55,7 +55,7 @@ int fdt_nop_property(void *fdt, int nodeoffset, const char *name)
|
||||||
|
|
||||||
prop = fdt_get_property(fdt, nodeoffset, name, &len);
|
prop = fdt_get_property(fdt, nodeoffset, name, &len);
|
||||||
if (! prop)
|
if (! prop)
|
||||||
return -len;
|
return len;
|
||||||
|
|
||||||
nop_region(prop, len + sizeof(*prop));
|
nop_region(prop, len + sizeof(*prop));
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ int _fdt_node_end_offset(void *fdt, int nodeoffset)
|
||||||
|
|
||||||
tag = _fdt_next_tag(fdt, nodeoffset, &nextoffset);
|
tag = _fdt_next_tag(fdt, nodeoffset, &nextoffset);
|
||||||
if (tag != FDT_BEGIN_NODE)
|
if (tag != FDT_BEGIN_NODE)
|
||||||
return FDT_ERR_BADOFFSET;
|
return -FDT_ERR_BADOFFSET;
|
||||||
do {
|
do {
|
||||||
offset = nextoffset;
|
offset = nextoffset;
|
||||||
tag = _fdt_next_tag(fdt, offset, &nextoffset);
|
tag = _fdt_next_tag(fdt, offset, &nextoffset);
|
||||||
|
@ -92,7 +92,7 @@ int _fdt_node_end_offset(void *fdt, int nodeoffset)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return FDT_ERR_BADSTRUCTURE;
|
return -FDT_ERR_BADSTRUCTURE;
|
||||||
}
|
}
|
||||||
} while (level >= 0);
|
} while (level >= 0);
|
||||||
|
|
||||||
|
@ -102,11 +102,10 @@ int _fdt_node_end_offset(void *fdt, int nodeoffset)
|
||||||
int fdt_nop_node(void *fdt, int nodeoffset)
|
int fdt_nop_node(void *fdt, int nodeoffset)
|
||||||
{
|
{
|
||||||
int endoffset;
|
int endoffset;
|
||||||
int err;
|
|
||||||
|
|
||||||
endoffset = _fdt_node_end_offset(fdt, nodeoffset);
|
endoffset = _fdt_node_end_offset(fdt, nodeoffset);
|
||||||
if ((err = fdt_offset_error(endoffset)))
|
if (endoffset < 0)
|
||||||
return err;
|
return endoffset;
|
||||||
|
|
||||||
nop_region(fdt_offset_ptr(fdt, nodeoffset, 0), endoffset - nodeoffset);
|
nop_region(fdt_offset_ptr(fdt, nodeoffset, 0), endoffset - nodeoffset);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
6
libfdt.h
6
libfdt.h
|
@ -66,12 +66,6 @@ void *fdt_offset_ptr(const void *fdt, int offset, int checklen);
|
||||||
#define fdt_offset_ptr_typed(fdt, offset, var) \
|
#define fdt_offset_ptr_typed(fdt, offset, var) \
|
||||||
((typeof(var))(fdt_offset_ptr((fdt), (offset), sizeof(*(var)))))
|
((typeof(var))(fdt_offset_ptr((fdt), (offset), sizeof(*(var)))))
|
||||||
|
|
||||||
#define fdt_offset_error(offset) \
|
|
||||||
( (offset) < 0 ? -(offset) : 0 )
|
|
||||||
|
|
||||||
#define fdt_ptrlen_error(p, len) \
|
|
||||||
( (p) ? 0 : -(len) )
|
|
||||||
|
|
||||||
int fdt_move(const void *fdt, void *buf, int bufsize);
|
int fdt_move(const void *fdt, void *buf, int bufsize);
|
||||||
|
|
||||||
/* Read-only functions */
|
/* Read-only functions */
|
||||||
|
|
|
@ -36,8 +36,6 @@ static inline void *_fdt_offset_ptr(const struct fdt_header *fdt, int offset)
|
||||||
return (void *)fdt + fdt_off_dt_struct(fdt) + offset;
|
return (void *)fdt + fdt_off_dt_struct(fdt) + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define OFFSET_ERROR(code) -(code)
|
|
||||||
|
|
||||||
#define SW_MAGIC (~FDT_MAGIC)
|
#define SW_MAGIC (~FDT_MAGIC)
|
||||||
|
|
||||||
#endif /* _LIBFDT_INTERNAL_H */
|
#endif /* _LIBFDT_INTERNAL_H */
|
||||||
|
|
|
@ -42,19 +42,21 @@ int main(int argc, char *argv[])
|
||||||
oldsize = fdt_totalsize(fdt);
|
oldsize = fdt_totalsize(fdt);
|
||||||
|
|
||||||
subnode1_offset = fdt_path_offset(fdt, "/subnode1");
|
subnode1_offset = fdt_path_offset(fdt, "/subnode1");
|
||||||
if ((err = fdt_offset_error(subnode1_offset)))
|
if (subnode1_offset < 0)
|
||||||
FAIL("Couldn't find \"/subnode1\": %s", fdt_strerror(err));
|
FAIL("Couldn't find \"/subnode1\": %s",
|
||||||
|
fdt_strerror(subnode1_offset));
|
||||||
check_getprop_typed(fdt, subnode1_offset, "prop-int", TEST_VALUE_1);
|
check_getprop_typed(fdt, subnode1_offset, "prop-int", TEST_VALUE_1);
|
||||||
|
|
||||||
subnode2_offset = fdt_path_offset(fdt, "/subnode2");
|
subnode2_offset = fdt_path_offset(fdt, "/subnode2");
|
||||||
if ((err = fdt_offset_error(subnode2_offset)))
|
if (subnode2_offset < 0)
|
||||||
FAIL("Couldn't find \"/subnode2\": %s", fdt_strerror(err));
|
FAIL("Couldn't find \"/subnode2\": %s",
|
||||||
|
fdt_strerror(subnode2_offset));
|
||||||
check_getprop_typed(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
|
check_getprop_typed(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
|
||||||
|
|
||||||
subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
|
subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
|
||||||
if ((err = fdt_offset_error(subsubnode2_offset)))
|
if (subsubnode2_offset < 0)
|
||||||
FAIL("Couldn't find \"/subnode2/subsubnode\": %s",
|
FAIL("Couldn't find \"/subnode2/subsubnode\": %s",
|
||||||
fdt_strerror(err));
|
fdt_strerror(subsubnode2_offset));
|
||||||
check_getprop_typed(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
|
check_getprop_typed(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
|
||||||
|
|
||||||
err = fdt_del_node(fdt, subnode1_offset);
|
err = fdt_del_node(fdt, subnode1_offset);
|
||||||
|
@ -62,19 +64,21 @@ int main(int argc, char *argv[])
|
||||||
FAIL("fdt_del_node(subnode1): %s", fdt_strerror(err));
|
FAIL("fdt_del_node(subnode1): %s", fdt_strerror(err));
|
||||||
|
|
||||||
subnode1_offset = fdt_path_offset(fdt, "/subnode1");
|
subnode1_offset = fdt_path_offset(fdt, "/subnode1");
|
||||||
if ((err = fdt_offset_error(subnode1_offset)) != FDT_ERR_NOTFOUND)
|
if (subnode1_offset != -FDT_ERR_NOTFOUND)
|
||||||
FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
|
FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
|
||||||
fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND));
|
fdt_strerror(subnode1_offset),
|
||||||
|
fdt_strerror(-FDT_ERR_NOTFOUND));
|
||||||
|
|
||||||
subnode2_offset = fdt_path_offset(fdt, "/subnode2");
|
subnode2_offset = fdt_path_offset(fdt, "/subnode2");
|
||||||
if ((err = fdt_offset_error(subnode2_offset)))
|
if (subnode2_offset < 0)
|
||||||
FAIL("Couldn't find \"/subnode2\": %s", fdt_strerror(err));
|
FAIL("Couldn't find \"/subnode2\": %s",
|
||||||
|
fdt_strerror(subnode2_offset));
|
||||||
check_getprop_typed(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
|
check_getprop_typed(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
|
||||||
|
|
||||||
subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
|
subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
|
||||||
if ((err = fdt_offset_error(subsubnode2_offset)))
|
if (subsubnode2_offset < 0)
|
||||||
FAIL("Couldn't find \"/subnode2/subsubnode\": %s",
|
FAIL("Couldn't find \"/subnode2/subsubnode\": %s",
|
||||||
fdt_strerror(err));
|
fdt_strerror(subsubnode2_offset));
|
||||||
check_getprop_typed(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
|
check_getprop_typed(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
|
||||||
|
|
||||||
err = fdt_del_node(fdt, subnode2_offset);
|
err = fdt_del_node(fdt, subnode2_offset);
|
||||||
|
@ -82,19 +86,22 @@ int main(int argc, char *argv[])
|
||||||
FAIL("fdt_del_node(subnode2): %s", fdt_strerror(err));
|
FAIL("fdt_del_node(subnode2): %s", fdt_strerror(err));
|
||||||
|
|
||||||
subnode1_offset = fdt_path_offset(fdt, "/subnode1");
|
subnode1_offset = fdt_path_offset(fdt, "/subnode1");
|
||||||
if ((err = fdt_offset_error(subnode1_offset)) != FDT_ERR_NOTFOUND)
|
if (subnode1_offset != -FDT_ERR_NOTFOUND)
|
||||||
FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
|
FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
|
||||||
fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND));
|
fdt_strerror(subnode1_offset),
|
||||||
|
fdt_strerror(-FDT_ERR_NOTFOUND));
|
||||||
|
|
||||||
subnode2_offset = fdt_path_offset(fdt, "/subnode2");
|
subnode2_offset = fdt_path_offset(fdt, "/subnode2");
|
||||||
if ((err = fdt_offset_error(subnode2_offset)) != FDT_ERR_NOTFOUND)
|
if (subnode2_offset != -FDT_ERR_NOTFOUND)
|
||||||
FAIL("fdt_path_offset(subnode2) returned \"%s\" instead of \"%s\"",
|
FAIL("fdt_path_offset(subnode2) returned \"%s\" instead of \"%s\"",
|
||||||
fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND));
|
fdt_strerror(subnode2_offset),
|
||||||
|
fdt_strerror(-FDT_ERR_NOTFOUND));
|
||||||
|
|
||||||
subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
|
subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
|
||||||
if ((err = fdt_offset_error(subsubnode2_offset)) != FDT_ERR_NOTFOUND)
|
if (subsubnode2_offset != -FDT_ERR_NOTFOUND)
|
||||||
FAIL("fdt_path_offset(subsubnode2) returned \"%s\" instead of \"%s\"",
|
FAIL("fdt_path_offset(subsubnode2) returned \"%s\" instead of \"%s\"",
|
||||||
fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND));
|
fdt_strerror(subsubnode2_offset),
|
||||||
|
fdt_strerror(-FDT_ERR_NOTFOUND));
|
||||||
|
|
||||||
delsize = fdt_totalsize(fdt);
|
delsize = fdt_totalsize(fdt);
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,9 @@ int main(int argc, char *argv[])
|
||||||
intp = fdt_getprop(fdt, 0, "prop-int", &lenerr);
|
intp = fdt_getprop(fdt, 0, "prop-int", &lenerr);
|
||||||
if (intp)
|
if (intp)
|
||||||
FAIL("prop-int still present after deletion");
|
FAIL("prop-int still present after deletion");
|
||||||
if ((err = fdt_ptrlen_error(intp, lenerr)) != FDT_ERR_NOTFOUND)
|
if (lenerr != -FDT_ERR_NOTFOUND)
|
||||||
FAIL("Unexpected error on second getprop: %s", fdt_strerror(err));
|
FAIL("Unexpected error on second getprop: %s",
|
||||||
|
fdt_strerror(lenerr));
|
||||||
|
|
||||||
strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
|
strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
|
||||||
TEST_STRING_1);
|
TEST_STRING_1);
|
||||||
|
@ -65,8 +66,9 @@ int main(int argc, char *argv[])
|
||||||
strp = fdt_getprop(fdt, 0, "prop-str", &lenerr);
|
strp = fdt_getprop(fdt, 0, "prop-str", &lenerr);
|
||||||
if (strp)
|
if (strp)
|
||||||
FAIL("prop-str still present after deletion");
|
FAIL("prop-str still present after deletion");
|
||||||
if ((err = fdt_ptrlen_error(strp, lenerr)) != FDT_ERR_NOTFOUND)
|
if (lenerr != -FDT_ERR_NOTFOUND)
|
||||||
FAIL("Unexpected error on second getprop: %s", fdt_strerror(err));
|
FAIL("Unexpected error on second getprop: %s",
|
||||||
|
fdt_strerror(lenerr));
|
||||||
|
|
||||||
delsize = fdt_totalsize(fdt);
|
delsize = fdt_totalsize(fdt);
|
||||||
|
|
||||||
|
|
|
@ -39,19 +39,21 @@ int main(int argc, char *argv[])
|
||||||
fdt = load_blob_arg(argc, argv);
|
fdt = load_blob_arg(argc, argv);
|
||||||
|
|
||||||
subnode1_offset = fdt_path_offset(fdt, "/subnode1");
|
subnode1_offset = fdt_path_offset(fdt, "/subnode1");
|
||||||
if ((err = fdt_offset_error(subnode1_offset)))
|
if (subnode1_offset < 0)
|
||||||
FAIL("Couldn't find \"/subnode1\": %s", fdt_strerror(err));
|
FAIL("Couldn't find \"/subnode1\": %s",
|
||||||
|
fdt_strerror(subnode1_offset));
|
||||||
check_getprop_typed(fdt, subnode1_offset, "prop-int", TEST_VALUE_1);
|
check_getprop_typed(fdt, subnode1_offset, "prop-int", TEST_VALUE_1);
|
||||||
|
|
||||||
subnode2_offset = fdt_path_offset(fdt, "/subnode2");
|
subnode2_offset = fdt_path_offset(fdt, "/subnode2");
|
||||||
if ((err = fdt_offset_error(subnode2_offset)))
|
if (subnode2_offset < 0)
|
||||||
FAIL("Couldn't find \"/subnode2\": %s", fdt_strerror(err));
|
FAIL("Couldn't find \"/subnode2\": %s",
|
||||||
|
fdt_strerror(subnode2_offset));
|
||||||
check_getprop_typed(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
|
check_getprop_typed(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
|
||||||
|
|
||||||
subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
|
subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
|
||||||
if ((err = fdt_offset_error(subsubnode2_offset)))
|
if (subsubnode2_offset < 0)
|
||||||
FAIL("Couldn't find \"/subnode2/subsubnode\": %s",
|
FAIL("Couldn't find \"/subnode2/subsubnode\": %s",
|
||||||
fdt_strerror(err));
|
fdt_strerror(subsubnode2_offset));
|
||||||
check_getprop_typed(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
|
check_getprop_typed(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
|
||||||
|
|
||||||
err = fdt_nop_node(fdt, subnode1_offset);
|
err = fdt_nop_node(fdt, subnode1_offset);
|
||||||
|
@ -59,19 +61,21 @@ int main(int argc, char *argv[])
|
||||||
FAIL("fdt_nop_node(subnode1): %s", fdt_strerror(err));
|
FAIL("fdt_nop_node(subnode1): %s", fdt_strerror(err));
|
||||||
|
|
||||||
subnode1_offset = fdt_path_offset(fdt, "/subnode1");
|
subnode1_offset = fdt_path_offset(fdt, "/subnode1");
|
||||||
if ((err = fdt_offset_error(subnode1_offset)) != FDT_ERR_NOTFOUND)
|
if (subnode1_offset != -FDT_ERR_NOTFOUND)
|
||||||
FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
|
FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
|
||||||
fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND));
|
fdt_strerror(subnode1_offset),
|
||||||
|
fdt_strerror(-FDT_ERR_NOTFOUND));
|
||||||
|
|
||||||
subnode2_offset = fdt_path_offset(fdt, "/subnode2");
|
subnode2_offset = fdt_path_offset(fdt, "/subnode2");
|
||||||
if ((err = fdt_offset_error(subnode2_offset)))
|
if (subnode2_offset < 0)
|
||||||
FAIL("Couldn't find \"/subnode2\": %s", fdt_strerror(err));
|
FAIL("Couldn't find \"/subnode2\": %s",
|
||||||
|
fdt_strerror(subnode2_offset));
|
||||||
check_getprop_typed(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
|
check_getprop_typed(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
|
||||||
|
|
||||||
subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
|
subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
|
||||||
if ((err = fdt_offset_error(subsubnode2_offset)))
|
if (subsubnode2_offset < 0)
|
||||||
FAIL("Couldn't find \"/subnode2/subsubnode\": %s",
|
FAIL("Couldn't find \"/subnode2/subsubnode\": %s",
|
||||||
fdt_strerror(err));
|
fdt_strerror(subsubnode2_offset));
|
||||||
check_getprop_typed(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
|
check_getprop_typed(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
|
||||||
|
|
||||||
err = fdt_nop_node(fdt, subnode2_offset);
|
err = fdt_nop_node(fdt, subnode2_offset);
|
||||||
|
@ -79,19 +83,22 @@ int main(int argc, char *argv[])
|
||||||
FAIL("fdt_nop_node(subnode2): %s", fdt_strerror(err));
|
FAIL("fdt_nop_node(subnode2): %s", fdt_strerror(err));
|
||||||
|
|
||||||
subnode1_offset = fdt_path_offset(fdt, "/subnode1");
|
subnode1_offset = fdt_path_offset(fdt, "/subnode1");
|
||||||
if ((err = fdt_offset_error(subnode1_offset)) != FDT_ERR_NOTFOUND)
|
if (subnode1_offset != -FDT_ERR_NOTFOUND)
|
||||||
FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
|
FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
|
||||||
fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND));
|
fdt_strerror(subnode1_offset),
|
||||||
|
fdt_strerror(-FDT_ERR_NOTFOUND));
|
||||||
|
|
||||||
subnode2_offset = fdt_path_offset(fdt, "/subnode2");
|
subnode2_offset = fdt_path_offset(fdt, "/subnode2");
|
||||||
if ((err = fdt_offset_error(subnode2_offset)) != FDT_ERR_NOTFOUND)
|
if (subnode2_offset != -FDT_ERR_NOTFOUND)
|
||||||
FAIL("fdt_path_offset(subnode2) returned \"%s\" instead of \"%s\"",
|
FAIL("fdt_path_offset(subnode2) returned \"%s\" instead of \"%s\"",
|
||||||
fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND));
|
fdt_strerror(subnode2_offset),
|
||||||
|
fdt_strerror(-FDT_ERR_NOTFOUND));
|
||||||
|
|
||||||
subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
|
subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
|
||||||
if ((err = fdt_offset_error(subsubnode2_offset)) != FDT_ERR_NOTFOUND)
|
if (subsubnode2_offset != -FDT_ERR_NOTFOUND)
|
||||||
FAIL("fdt_path_offset(subsubnode2) returned \"%s\" instead of \"%s\"",
|
FAIL("fdt_path_offset(subsubnode2) returned \"%s\" instead of \"%s\"",
|
||||||
fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND));
|
fdt_strerror(subsubnode2_offset),
|
||||||
|
fdt_strerror(-FDT_ERR_NOTFOUND));
|
||||||
|
|
||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ int main(int argc, char *argv[])
|
||||||
intp = fdt_getprop(fdt, 0, "prop-int", &lenerr);
|
intp = fdt_getprop(fdt, 0, "prop-int", &lenerr);
|
||||||
if (intp)
|
if (intp)
|
||||||
FAIL("prop-int still present after nopping");
|
FAIL("prop-int still present after nopping");
|
||||||
if ((err = fdt_ptrlen_error(intp, lenerr)) != FDT_ERR_NOTFOUND)
|
if (lenerr != -FDT_ERR_NOTFOUND)
|
||||||
FAIL("Unexpected error on second getprop: %s", fdt_strerror(err));
|
FAIL("Unexpected error on second getprop: %s", fdt_strerror(err));
|
||||||
|
|
||||||
strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
|
strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
|
||||||
|
@ -63,7 +63,7 @@ int main(int argc, char *argv[])
|
||||||
strp = fdt_getprop(fdt, 0, "prop-str", &lenerr);
|
strp = fdt_getprop(fdt, 0, "prop-str", &lenerr);
|
||||||
if (strp)
|
if (strp)
|
||||||
FAIL("prop-str still present after nopping");
|
FAIL("prop-str still present after nopping");
|
||||||
if ((err = fdt_ptrlen_error(strp, lenerr)) != FDT_ERR_NOTFOUND)
|
if (lenerr != -FDT_ERR_NOTFOUND)
|
||||||
FAIL("Unexpected error on second getprop: %s", fdt_strerror(err));
|
FAIL("Unexpected error on second getprop: %s", fdt_strerror(err));
|
||||||
|
|
||||||
PASS();
|
PASS();
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
|
|
||||||
void check_error(const char *s, int err)
|
void check_error(const char *s, int err)
|
||||||
{
|
{
|
||||||
if (err != FDT_ERR_NOTFOUND)
|
if (err != -FDT_ERR_NOTFOUND)
|
||||||
FAIL("%s return error %s instead of FDT_ERR_NOTFOUND", s,
|
FAIL("%s return error %s instead of -FDT_ERR_NOTFOUND", s,
|
||||||
fdt_strerror(err));
|
fdt_strerror(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,38 +41,32 @@ int main(int argc, char *argv[])
|
||||||
int offset;
|
int offset;
|
||||||
int subnode1_offset;
|
int subnode1_offset;
|
||||||
void *val;
|
void *val;
|
||||||
int err;
|
|
||||||
int lenerr;
|
int lenerr;
|
||||||
|
|
||||||
test_init(argc, argv);
|
test_init(argc, argv);
|
||||||
fdt = load_blob_arg(argc, argv);
|
fdt = load_blob_arg(argc, argv);
|
||||||
|
|
||||||
prop = fdt_get_property(fdt, 0, "nonexistant-property", &lenerr);
|
prop = fdt_get_property(fdt, 0, "nonexistant-property", &lenerr);
|
||||||
check_error("fdt_get_property(\"nonexistant-property\")",
|
check_error("fdt_get_property(\"nonexistant-property\")", lenerr);
|
||||||
fdt_ptrlen_error(prop, lenerr));
|
|
||||||
|
|
||||||
val = fdt_getprop(fdt, 0, "nonexistant-property", &lenerr);
|
val = fdt_getprop(fdt, 0, "nonexistant-property", &lenerr);
|
||||||
check_error("fdt_getprop(\"nonexistant-property\"",
|
check_error("fdt_getprop(\"nonexistant-property\"", lenerr);
|
||||||
fdt_ptrlen_error(val, lenerr));
|
|
||||||
|
|
||||||
subnode1_offset = fdt_subnode_offset(fdt, 0, "subnode1");
|
subnode1_offset = fdt_subnode_offset(fdt, 0, "subnode1");
|
||||||
if ((err = fdt_offset_error(subnode1_offset)))
|
if (subnode1_offset < 0)
|
||||||
FAIL("Couldn't find subnode1: %s", fdt_strerror(err));
|
FAIL("Couldn't find subnode1: %s", fdt_strerror(subnode1_offset));
|
||||||
|
|
||||||
val = fdt_getprop(fdt, subnode1_offset, "prop-str", &lenerr);
|
val = fdt_getprop(fdt, subnode1_offset, "prop-str", &lenerr);
|
||||||
check_error("fdt_getprop(\"prop-str\")", fdt_ptrlen_error(val, lenerr));
|
check_error("fdt_getprop(\"prop-str\")", lenerr);
|
||||||
|
|
||||||
offset = fdt_subnode_offset(fdt, 0, "nonexistant-subnode");
|
offset = fdt_subnode_offset(fdt, 0, "nonexistant-subnode");
|
||||||
check_error("fdt_subnode_offset(\"nonexistant-subnode\")",
|
check_error("fdt_subnode_offset(\"nonexistant-subnode\")", offset);
|
||||||
fdt_offset_error(offset));
|
|
||||||
|
|
||||||
offset = fdt_subnode_offset(fdt, 0, "subsubnode");
|
offset = fdt_subnode_offset(fdt, 0, "subsubnode");
|
||||||
check_error("fdt_subnode_offset(\"subsubnode\")",
|
check_error("fdt_subnode_offset(\"subsubnode\")", offset);
|
||||||
fdt_offset_error(offset));
|
|
||||||
|
|
||||||
offset = fdt_path_offset(fdt, "/nonexistant-subnode");
|
offset = fdt_path_offset(fdt, "/nonexistant-subnode");
|
||||||
check_error("fdt_path_offset(\"/nonexistant-subnode\")",
|
check_error("fdt_path_offset(\"/nonexistant-subnode\")", offset);
|
||||||
fdt_offset_error(offset));
|
|
||||||
|
|
||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,15 +30,14 @@
|
||||||
int check_subnode(void *fdt, int parent, const char *name)
|
int check_subnode(void *fdt, int parent, const char *name)
|
||||||
{
|
{
|
||||||
int offset;
|
int offset;
|
||||||
int err;
|
|
||||||
struct fdt_node_header *nh;
|
struct fdt_node_header *nh;
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
|
|
||||||
verbose_printf("Checking subnode \"%s\" of %d...", name, parent);
|
verbose_printf("Checking subnode \"%s\" of %d...", name, parent);
|
||||||
offset = fdt_subnode_offset(fdt, parent, name);
|
offset = fdt_subnode_offset(fdt, parent, name);
|
||||||
verbose_printf("offset %d...", offset);
|
verbose_printf("offset %d...", offset);
|
||||||
if ((err = fdt_offset_error(offset)))
|
if (offset < 0)
|
||||||
FAIL("fdt_subnode_offset(\"%s\"): %s", name, fdt_strerror(err));
|
FAIL("fdt_subnode_offset(\"%s\"): %s", name, fdt_strerror(offset));
|
||||||
nh = fdt_offset_ptr_typed(fdt, offset, nh);
|
nh = fdt_offset_ptr_typed(fdt, offset, nh);
|
||||||
verbose_printf("pointer %p\n", nh);
|
verbose_printf("pointer %p\n", nh);
|
||||||
if (! nh)
|
if (! nh)
|
||||||
|
|
|
@ -40,9 +40,9 @@
|
||||||
|
|
||||||
#define OFF_CHECK(off, code) \
|
#define OFF_CHECK(off, code) \
|
||||||
{ \
|
{ \
|
||||||
err = fdt_offset_error((off) = (code)); \
|
(off) = (code); \
|
||||||
if (err) \
|
if (off < 0) \
|
||||||
FAIL(#code ": %s", fdt_strerror(err)); \
|
FAIL(#code ": %s", fdt_strerror(off)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|
|
@ -30,15 +30,14 @@
|
||||||
int check_subnode(struct fdt_header *fdt, int parent, const char *name)
|
int check_subnode(struct fdt_header *fdt, int parent, const char *name)
|
||||||
{
|
{
|
||||||
int offset;
|
int offset;
|
||||||
int err;
|
|
||||||
struct fdt_node_header *nh;
|
struct fdt_node_header *nh;
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
|
|
||||||
verbose_printf("Checking subnode \"%s\" of %d...", name, parent);
|
verbose_printf("Checking subnode \"%s\" of %d...", name, parent);
|
||||||
offset = fdt_subnode_offset(fdt, parent, name);
|
offset = fdt_subnode_offset(fdt, parent, name);
|
||||||
verbose_printf("offset %d...", offset);
|
verbose_printf("offset %d...", offset);
|
||||||
if ((err = fdt_offset_error(offset)))
|
if (offset < 0)
|
||||||
FAIL("fdt_subnode_offset(\"%s\"): %s", name, fdt_strerror(err));
|
FAIL("fdt_subnode_offset(\"%s\"): %s", name, fdt_strerror(offset));
|
||||||
nh = fdt_offset_ptr_typed(fdt, offset, nh);
|
nh = fdt_offset_ptr_typed(fdt, offset, nh);
|
||||||
verbose_printf("pointer %p\n", nh);
|
verbose_printf("pointer %p\n", nh);
|
||||||
if (! nh)
|
if (! nh)
|
||||||
|
|
|
@ -97,10 +97,12 @@ static struct errtabent errtable[] = {
|
||||||
|
|
||||||
const char *fdt_strerror(int errval)
|
const char *fdt_strerror(int errval)
|
||||||
{
|
{
|
||||||
if ((errval >= 0) && (errval < ERRTABSIZE))
|
if (errval > 0)
|
||||||
return errtable[errval].str;
|
return "<valid offset>";
|
||||||
|
else if (errval < -ERRTABSIZE)
|
||||||
|
return "<unknown error>";
|
||||||
else
|
else
|
||||||
return "Unknown FDT error code";
|
return errtable[-errval].str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_property(void *fdt, int nodeoffset, const char *name,
|
void check_property(void *fdt, int nodeoffset, const char *name,
|
||||||
|
|
|
@ -40,10 +40,9 @@ int main(int argc, char *argv[])
|
||||||
prop = fdt_getprop(fdt, 0, "truncated", &len);
|
prop = fdt_getprop(fdt, 0, "truncated", &len);
|
||||||
if (prop)
|
if (prop)
|
||||||
FAIL("fdt_getprop() succeeded on truncated property");
|
FAIL("fdt_getprop() succeeded on truncated property");
|
||||||
err = fdt_ptrlen_error(prop, len);
|
if (len != -FDT_ERR_BADSTRUCTURE)
|
||||||
if (err != FDT_ERR_BADSTRUCTURE)
|
|
||||||
FAIL("fdt_getprop() failed with \"%s\" instead of \"%s\"",
|
FAIL("fdt_getprop() failed with \"%s\" instead of \"%s\"",
|
||||||
fdt_strerror(err), fdt_strerror(FDT_ERR_BADSTRUCTURE));
|
fdt_strerror(err), fdt_strerror(-FDT_ERR_BADSTRUCTURE));
|
||||||
|
|
||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue