56#include "libfdt_internal.h"
66 const char *p = fdt_offset_ptr (fdt, offset + FDT_TAGSIZE, len+1);
73 if (memcmp (p, s, len) != 0) {
79 }
else if (!memchr (s,
'@', len) && (p[len] ==
'@')) {
92 return (
const char *)fdt + fdt_off_dt_strings (fdt) + stroffset;
103 const char *p = fdt_string (fdt, stroffset);
105 return (strlen (p) == len) && (memcmp (p, s, len) == 0);
113 uint32_t max_phandle = 0;
116 for (offset = fdt_next_node (fdt, -1,
NULL); ;
117 offset = fdt_next_node (fdt, offset,
NULL))
121 if (offset == -FDT_ERR_NOTFOUND) {
129 phandle = fdt_get_phandle (fdt, offset);
130 if (phandle == (uint32_t)-1) {
134 if (phandle > max_phandle) {
135 max_phandle = phandle;
150 FDT_CHECK_HEADER (fdt);
151 *address = fdt64_to_cpu (_fdt_mem_rsv (fdt, n)->address);
152 *size = fdt64_to_cpu (_fdt_mem_rsv (fdt, n)->size);
163 while (fdt64_to_cpu (_fdt_mem_rsv (fdt, i)->size) != 0) {
180 tag = fdt_next_tag (fdt, offset, &nextoffset);
184 if (nextoffset >= 0) {
185 return -FDT_ERR_BADSTRUCTURE;
195 }
while (tag == FDT_NOP);
197 return -FDT_ERR_NOTFOUND;
201fdt_subnode_offset_namelen (
210 FDT_CHECK_HEADER (fdt);
213 (offset >= 0) && (depth >= 0);
214 offset = fdt_next_node (fdt, offset, &depth))
217 && _fdt_nodename_eq (fdt, offset, name, namelen))
224 return -FDT_ERR_NOTFOUND;
237 return fdt_subnode_offset_namelen (fdt, parentoffset, name, strlen (name));
241fdt_path_offset_namelen (
247 const char *end = path + namelen;
248 const char *p = path;
251 FDT_CHECK_HEADER (fdt);
255 const char *q = memchr (path,
'/', end - p);
261 p = fdt_get_alias_namelen (fdt, p, q - p);
263 return -FDT_ERR_BADPATH;
266 offset = fdt_path_offset (fdt, p);
281 q = memchr (p,
'/', end - p);
286 offset = fdt_subnode_offset_namelen (fdt, offset, p, q-p);
303 return fdt_path_offset_namelen (fdt, path, strlen (path));
316 if ( ((err = fdt_check_header (fdt)) != 0)
317 || ((err = _fdt_check_node_offset (fdt, nodeoffset)) < 0))
323 *len = strlen (nh->name);
337fdt_first_property_offset (
344 if ((offset = _fdt_check_node_offset (fdt, nodeoffset)) < 0) {
348 return _nextprop (fdt, offset);
352fdt_next_property_offset (
357 if ((offset = _fdt_check_prop_offset (fdt, offset)) < 0) {
361 return _nextprop (fdt, offset);
365fdt_get_property_by_offset (
374 if ((err = _fdt_check_prop_offset (fdt, offset)) < 0) {
382 prop = _fdt_offset_ptr (fdt, offset);
385 *lenp = fdt32_to_cpu (prop->len);
392fdt_get_property_namelen (
400 for (offset = fdt_first_property_offset (fdt, offset);
402 (offset = fdt_next_property_offset (fdt, offset)))
406 if (!(prop = fdt_get_property_by_offset (fdt, offset, lenp))) {
407 offset = -FDT_ERR_INTERNAL;
413 fdt32_to_cpu (prop->nameoff),
437 return fdt_get_property_namelen (
457 prop = fdt_get_property_namelen (fdt, nodeoffset, name, namelen, lenp);
466fdt_getprop_by_offset (
475 prop = fdt_get_property_by_offset (fdt, offset, lenp);
481 *namep = fdt_string (fdt, fdt32_to_cpu (prop->nameoff));
495 return fdt_getprop_namelen (fdt, nodeoffset, name, strlen (name), lenp);
509 php = fdt_getprop (fdt, nodeoffset,
"phandle", &len);
510 if (!php || (len !=
sizeof (*php))) {
511 php = fdt_getprop (fdt, nodeoffset,
"linux,phandle", &len);
512 if (!php || (len !=
sizeof (*php))) {
517 return fdt32_to_cpu (*php);
521fdt_get_alias_namelen (
529 aliasoffset = fdt_path_offset (fdt,
"/aliases");
530 if (aliasoffset < 0) {
534 return fdt_getprop_namelen (fdt, aliasoffset, name, namelen,
NULL);
543 return fdt_get_alias_namelen (fdt, name, strlen (name));
554 int pdepth = 0, p = 0;
555 int offset, depth, namelen;
558 FDT_CHECK_HEADER (fdt);
561 return -FDT_ERR_NOSPACE;
564 for (offset = 0, depth = 0;
565 (offset >= 0) && (offset <= nodeoffset);
566 offset = fdt_next_node (fdt, offset, &depth))
568 while (pdepth > depth) {
571 }
while (buf[p-1] !=
'/');
576 if (pdepth >= depth) {
577 name = fdt_get_name (fdt, offset, &namelen);
582 if ((p + namelen + 1) <= buflen) {
583 memcpy (buf + p, name, namelen);
590 if (offset == nodeoffset) {
591 if (pdepth < (depth + 1)) {
592 return -FDT_ERR_NOSPACE;
605 if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) {
606 return -FDT_ERR_BADOFFSET;
607 }
else if (offset == -FDT_ERR_BADOFFSET) {
608 return -FDT_ERR_BADSTRUCTURE;
615fdt_supernode_atdepth_offset (
623 int supernodeoffset = -FDT_ERR_INTERNAL;
625 FDT_CHECK_HEADER (fdt);
627 if (supernodedepth < 0) {
628 return -FDT_ERR_NOTFOUND;
631 for (offset = 0, depth = 0;
632 (offset >= 0) && (offset <= nodeoffset);
633 offset = fdt_next_node (fdt, offset, &depth))
635 if (depth == supernodedepth) {
636 supernodeoffset = offset;
639 if (offset == nodeoffset) {
644 if (supernodedepth > depth) {
645 return -FDT_ERR_NOTFOUND;
647 return supernodeoffset;
652 if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) {
653 return -FDT_ERR_BADOFFSET;
654 }
else if (offset == -FDT_ERR_BADOFFSET) {
655 return -FDT_ERR_BADSTRUCTURE;
670 err = fdt_supernode_atdepth_offset (fdt, nodeoffset, 0, &nodedepth);
672 return (err < 0) ? err : -FDT_ERR_INTERNAL;
684 int nodedepth = fdt_node_depth (fdt, nodeoffset);
690 return fdt_supernode_atdepth_offset (
699fdt_node_offset_by_prop_value (
702 const char *propname,
711 FDT_CHECK_HEADER (fdt);
718 for (offset = fdt_next_node (fdt, startoffset,
NULL);
720 offset = fdt_next_node (fdt, offset,
NULL))
722 val = fdt_getprop (fdt, offset, propname, &len);
723 if ( val && (len == proplen)
724 && (memcmp (val, propval, len) == 0))
734fdt_node_offset_by_phandle (
741 if ((phandle == 0) || (phandle == -1)) {
742 return -FDT_ERR_BADPHANDLE;
745 FDT_CHECK_HEADER (fdt);
753 for (offset = fdt_next_node (fdt, -1,
NULL);
755 offset = fdt_next_node (fdt, offset,
NULL))
757 if (fdt_get_phandle (fdt, offset) == phandle) {
766fdt_stringlist_contains (
772 int len = strlen (str);
775 while (listlen >= len) {
776 if (memcmp (str, strlist, len+1) == 0) {
780 p = memchr (strlist,
'\0', listlen);
785 listlen -= (p-strlist) + 1;
793fdt_stringlist_count (
799 const char *list, *end;
800 int length, count = 0;
802 list = fdt_getprop (fdt, nodeoffset, property, &length);
810 length = strnlen (list, end - list) + 1;
813 if (list + length > end) {
814 return -FDT_ERR_BADVALUE;
825fdt_stringlist_search (
828 const char *property,
832 int length, len, idx = 0;
833 const char *list, *end;
835 list = fdt_getprop (fdt, nodeoffset, property, &length);
840 len = strlen (
string) + 1;
844 length = strnlen (list, end - list) + 1;
847 if (list + length > end) {
848 return -FDT_ERR_BADVALUE;
851 if ((length == len) && (memcmp (list,
string, length) == 0)) {
859 return -FDT_ERR_NOTFOUND;
866 const char *property,
871 const char *list, *end;
874 list = fdt_getprop (fdt, nodeoffset, property, &length);
886 length = strnlen (list, end - list) + 1;
889 if (list + length > end) {
891 *lenp = -FDT_ERR_BADVALUE;
910 *lenp = -FDT_ERR_NOTFOUND;
917fdt_node_check_compatible (
920 const char *compatible
926 prop = fdt_getprop (fdt, nodeoffset,
"compatible", &len);
931 return !fdt_stringlist_contains (prop, len, compatible);
935fdt_node_offset_by_compatible (
938 const char *compatible
943 FDT_CHECK_HEADER (fdt);
950 for (offset = fdt_next_node (fdt, startoffset,
NULL);
952 offset = fdt_next_node (fdt, offset,
NULL))
954 err = fdt_node_check_compatible (fdt, offset, compatible);
955 if ((err < 0) && (err != -FDT_ERR_NOTFOUND)) {
957 }
else if (err == 0) {