16#define FDT_FIRST_SUPPORTED_VERSION 0x02
17#define FDT_LAST_COMPATIBLE_VERSION 0x10
18#define FDT_LAST_SUPPORTED_VERSION 0x11
21#define FDT_ERR_NOTFOUND 1
23#define FDT_ERR_EXISTS 2
26#define FDT_ERR_NOSPACE 3
33#define FDT_ERR_BADOFFSET 4
37#define FDT_ERR_BADPATH 5
41#define FDT_ERR_BADPHANDLE 6
46#define FDT_ERR_BADSTATE 7
52#define FDT_ERR_TRUNCATED 8
56#define FDT_ERR_BADMAGIC 9
60#define FDT_ERR_BADVERSION 10
65#define FDT_ERR_BADSTRUCTURE 11
69#define FDT_ERR_BADLAYOUT 12
77#define FDT_ERR_INTERNAL 13
83#define FDT_ERR_BADNCELLS 14
87#define FDT_ERR_BADVALUE 15
92#define FDT_ERR_BADOVERLAY 16
97#define FDT_ERR_NOPHANDLES 17
101#define FDT_ERR_BADFLAGS 18
105#define FDT_ERR_ALIGNMENT 19
109#define FDT_ERR_MAX 19
112#define FDT_MAX_PHANDLE 0xfffffffe
120const void *fdt_offset_ptr(
const void *fdt,
int offset,
unsigned int checklen);
122static inline void *fdt_offset_ptr_w(
void *fdt,
int offset,
int checklen)
124 return (
void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
127uint32_t fdt_next_tag(
const void *fdt,
int offset,
int *nextoffset);
134static inline uint16_t fdt16_ld(
const fdt16_t *p)
136 const uint8_t *bp = (
const uint8_t *)p;
138 return ((uint16_t)bp[0] << 8) | bp[1];
141static inline uint32_t fdt32_ld(
const fdt32_t *p)
143 const uint8_t *bp = (
const uint8_t *)p;
145 return ((uint32_t)bp[0] << 24)
146 | ((uint32_t)bp[1] << 16)
147 | ((uint32_t)bp[2] << 8)
151static inline void fdt32_st(
void *property, uint32_t value)
153 uint8_t *bp = (uint8_t *)property;
156 bp[1] = (value >> 16) & 0xff;
157 bp[2] = (value >> 8) & 0xff;
158 bp[3] = value & 0xff;
161static inline uint64_t fdt64_ld(
const fdt64_t *p)
163 const uint8_t *bp = (
const uint8_t *)p;
165 return ((uint64_t)bp[0] << 56)
166 | ((uint64_t)bp[1] << 48)
167 | ((uint64_t)bp[2] << 40)
168 | ((uint64_t)bp[3] << 32)
169 | ((uint64_t)bp[4] << 24)
170 | ((uint64_t)bp[5] << 16)
171 | ((uint64_t)bp[6] << 8)
175static inline void fdt64_st(
void *property, uint64_t value)
177 uint8_t *bp = (uint8_t *)property;
180 bp[1] = (value >> 48) & 0xff;
181 bp[2] = (value >> 40) & 0xff;
182 bp[3] = (value >> 32) & 0xff;
183 bp[4] = (value >> 24) & 0xff;
184 bp[5] = (value >> 16) & 0xff;
185 bp[6] = (value >> 8) & 0xff;
186 bp[7] = value & 0xff;
193int fdt_next_node(
const void *fdt,
int offset,
int *depth);
202int fdt_first_subnode(
const void *fdt,
int offset);
215int fdt_next_subnode(
const void *fdt,
int offset);
239#define fdt_for_each_subnode(node, fdt, parent) \
240 for (node = fdt_first_subnode(fdt, parent); \
242 node = fdt_next_subnode(fdt, node))
247#define fdt_get_header(fdt, field) \
248 (fdt32_ld(&((const struct fdt_header *)(fdt))->field))
249#define fdt_magic(fdt) (fdt_get_header(fdt, magic))
250#define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
251#define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
252#define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
253#define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
254#define fdt_version(fdt) (fdt_get_header(fdt, version))
255#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
256#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
257#define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
258#define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
260#define fdt_set_hdr_(name) \
261 static inline void fdt_set_##name(void *fdt, uint32_t val) \
263 struct fdt_header *fdth = (struct fdt_header *)fdt; \
264 fdth->name = cpu_to_fdt32(val); \
267fdt_set_hdr_(totalsize)
268fdt_set_hdr_(off_dt_struct)
269fdt_set_hdr_(off_dt_strings)
270fdt_set_hdr_(off_mem_rsvmap)
272fdt_set_hdr_(last_comp_version)
273fdt_set_hdr_(boot_cpuid_phys)
274fdt_set_hdr_(size_dt_strings)
275fdt_set_hdr_(size_dt_struct)
284size_t fdt_header_size(
const void *fdt);
292size_t fdt_header_size_(uint32_t version);
310int fdt_check_header(
const void *fdt);
331int fdt_move(
const void *fdt,
void *buf,
int bufsize);
337int fdt_check_full(
const void *fdt,
size_t bufsize);
353const char *fdt_get_string(
const void *fdt,
int stroffset,
int *lenp);
367const char *fdt_string(
const void *fdt,
int stroffset);
381int fdt_find_max_phandle(
const void *fdt, uint32_t *phandle);
398static inline uint32_t fdt_get_max_phandle(
const void *fdt)
403 err = fdt_find_max_phandle(fdt, &phandle);
422int fdt_generate_phandle(
const void *fdt, uint32_t *phandle);
435int fdt_num_mem_rsv(
const void *fdt);
454int fdt_get_mem_rsv(
const void *fdt,
int n, uint64_t *address, uint64_t *size);
471int fdt_subnode_offset_namelen(
const void *fdt,
int parentoffset,
472 const char *name,
int namelen);
498int fdt_subnode_offset(
const void *fdt,
int parentoffset,
const char *name);
512int fdt_path_offset_namelen(
const void *fdt,
const char *path,
int namelen);
563int fdt_path_offset(
const void *fdt,
const char *path);
588const char *fdt_get_name(
const void *fdt,
int nodeoffset,
int *lenp);
608int fdt_first_property_offset(
const void *fdt,
int nodeoffset);
629int fdt_next_property_offset(
const void *fdt,
int offset);
653#define fdt_for_each_property_offset(property, fdt, node) \
654 for (property = fdt_first_property_offset(fdt, node); \
656 property = fdt_next_property_offset(fdt, property))
685const struct fdt_property *fdt_get_property_by_offset(
const void *fdt,
688static inline struct fdt_property *fdt_get_property_by_offset_w(
void *fdt,
693 fdt_get_property_by_offset(fdt, offset, lenp);
711const struct fdt_property *fdt_get_property_namelen(
const void *fdt,
714 int namelen,
int *lenp);
716fdt_get_property_namelen_w(
void *fdt,
int nodeoffset,
const char *name,
717 int namelen,
int *lenp)
719 return (
struct fdt_property *)(uintptr_t)fdt_get_property_namelen(
720 fdt, nodeoffset, name, namelen, lenp);
752const struct fdt_property *fdt_get_property(
const void *fdt,
int nodeoffset,
753 const char *name,
int *lenp);
754static inline struct fdt_property *fdt_get_property_w(
void *fdt,
int nodeoffset,
759 fdt_get_property(fdt, nodeoffset, name, lenp);
794const void *fdt_getprop_by_offset(
const void *fdt,
int offset,
795 const char **namep,
int *lenp);
812const void *fdt_getprop_namelen(
const void *fdt,
int nodeoffset,
813 const char *name,
int namelen,
int *lenp);
814static inline void *fdt_getprop_namelen_w(
void *fdt,
int nodeoffset,
815 const char *name,
int namelen,
818 return (
void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,
851const void *fdt_getprop(
const void *fdt,
int nodeoffset,
852 const char *name,
int *lenp);
853static inline void *fdt_getprop_w(
void *fdt,
int nodeoffset,
854 const char *name,
int *lenp)
856 return (
void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
871uint32_t fdt_get_phandle(
const void *fdt,
int nodeoffset);
886const char *fdt_get_alias_namelen(
const void *fdt,
887 const char *name,
int namelen);
902const char *fdt_get_alias(
const void *fdt,
const char *name);
917const char *fdt_get_symbol_namelen(
const void *fdt,
918 const char *name,
int namelen);
938const char *fdt_get_symbol(
const void *fdt,
const char *name);
965int fdt_get_path(
const void *fdt,
int nodeoffset,
char *buf,
int buflen);
997int fdt_supernode_atdepth_offset(
const void *fdt,
int nodeoffset,
998 int supernodedepth,
int *nodedepth);
1019int fdt_node_depth(
const void *fdt,
int nodeoffset);
1042int fdt_parent_offset(
const void *fdt,
int nodeoffset);
1082int fdt_node_offset_by_prop_value(
const void *fdt,
int startoffset,
1083 const char *propname,
1084 const void *propval,
int proplen);
1105int fdt_node_offset_by_phandle(
const void *fdt, uint32_t phandle);
1128int fdt_node_check_compatible(
const void *fdt,
int nodeoffset,
1129 const char *compatible);
1165int fdt_node_offset_by_compatible(
const void *fdt,
int startoffset,
1166 const char *compatible);
1180int fdt_stringlist_contains(
const char *strlist,
int listlen,
const char *str);
1193int fdt_stringlist_count(
const void *fdt,
int nodeoffset,
const char *property);
1214int fdt_stringlist_search(
const void *fdt,
int nodeoffset,
const char *property,
1215 const char *
string);
1241const char *fdt_stringlist_get(
const void *fdt,
int nodeoffset,
1242 const char *property,
int index,
1258#define FDT_MAX_NCELLS 4
1278int fdt_address_cells(
const void *fdt,
int nodeoffset);
1299int fdt_size_cells(
const void *fdt,
int nodeoffset);
1325int fdt_setprop_inplace_namelen_partial(
void *fdt,
int nodeoffset,
1326 const char *name,
int namelen,
1327 uint32_t idx,
const void *val,
1360int fdt_setprop_inplace(
void *fdt,
int nodeoffset,
const char *name,
1361 const void *val,
int len);
1392static inline int fdt_setprop_inplace_u32(
void *fdt,
int nodeoffset,
1393 const char *name, uint32_t val)
1395 fdt32_t tmp = cpu_to_fdt32(val);
1396 return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp,
sizeof(tmp));
1427static inline int fdt_setprop_inplace_u64(
void *fdt,
int nodeoffset,
1428 const char *name, uint64_t val)
1430 fdt64_t tmp = cpu_to_fdt64(val);
1431 return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp,
sizeof(tmp));
1444static inline int fdt_setprop_inplace_cell(
void *fdt,
int nodeoffset,
1445 const char *name, uint32_t val)
1447 return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
1474int fdt_nop_property(
void *fdt,
int nodeoffset,
const char *name);
1498int fdt_nop_node(
void *fdt,
int nodeoffset);
1505#define FDT_CREATE_FLAG_NO_NAME_DEDUP 0x1
1510#define FDT_CREATE_FLAGS_ALL (FDT_CREATE_FLAG_NO_NAME_DEDUP)
1528int fdt_create_with_flags(
void *buf,
int bufsize, uint32_t flags);
1541int fdt_create(
void *buf,
int bufsize);
1543int fdt_resize(
void *fdt,
void *buf,
int bufsize);
1544int fdt_add_reservemap_entry(
void *fdt, uint64_t addr, uint64_t size);
1545int fdt_finish_reservemap(
void *fdt);
1546int fdt_begin_node(
void *fdt,
const char *name);
1547int fdt_property(
void *fdt,
const char *name,
const void *val,
int len);
1548static inline int fdt_property_u32(
void *fdt,
const char *name, uint32_t val)
1550 fdt32_t tmp = cpu_to_fdt32(val);
1553static inline int fdt_property_u64(
void *fdt,
const char *name, uint64_t val)
1555 fdt64_t tmp = cpu_to_fdt64(val);
1560static inline int fdt_property_cell(
void *fdt,
const char *name, uint32_t val)
1562 return fdt_property_u32(fdt, name, val);
1579int fdt_property_placeholder(
void *fdt,
const char *name,
int len,
void **valp);
1581#define fdt_property_string(fdt, name, str) \
1582 fdt_property(fdt, name, str, strlen(str)+1)
1583int fdt_end_node(
void *fdt);
1584int fdt_finish(
void *fdt);
1590int fdt_create_empty_tree(
void *buf,
int bufsize);
1591int fdt_open_into(
const void *fdt,
void *buf,
int bufsize);
1592int fdt_pack(
void *fdt);
1617int fdt_add_mem_rsv(
void *fdt, uint64_t address, uint64_t size);
1641int fdt_del_mem_rsv(
void *fdt,
int n);
1667int fdt_set_name(
void *fdt,
int nodeoffset,
const char *name);
1698int fdt_setprop_namelen(
void *fdt,
int nodeoffset,
const char *name,
1699 int namelen,
const void *val,
int len);
1729static inline int fdt_setprop(
void *fdt,
int nodeoffset,
const char *name,
1730 const void *val,
int len)
1732 return fdt_setprop_namelen(fdt, nodeoffset, name, strlen(name), val,
1765int fdt_setprop_placeholder_namelen(
void *fdt,
int nodeoffset,
const char *name,
1766 int namelen,
int len,
void **prop_data);
1796static inline int fdt_setprop_placeholder(
void *fdt,
int nodeoffset,
1797 const char *name,
int len,
1800 return fdt_setprop_placeholder_namelen(fdt, nodeoffset, name,
1801 strlen(name), len, prop_data);
1832static inline int fdt_setprop_u32(
void *fdt,
int nodeoffset,
const char *name,
1835 fdt32_t tmp = cpu_to_fdt32(val);
1836 return fdt_setprop(fdt, nodeoffset, name, &tmp,
sizeof(tmp));
1867static inline int fdt_setprop_u64(
void *fdt,
int nodeoffset,
const char *name,
1870 fdt64_t tmp = cpu_to_fdt64(val);
1871 return fdt_setprop(fdt, nodeoffset, name, &tmp,
sizeof(tmp));
1885static inline int fdt_setprop_cell(
void *fdt,
int nodeoffset,
const char *name,
1888 return fdt_setprop_u32(fdt, nodeoffset, name, val);
1919#define fdt_setprop_string(fdt, nodeoffset, name, str) \
1920 fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
1951#define fdt_setprop_namelen_string(fdt, nodeoffset, name, namelen, str) \
1952 fdt_setprop_namelen((fdt), (nodeoffset), (name), (namelen), (str), \
1981#define fdt_setprop_empty(fdt, nodeoffset, name) \
1982 fdt_setprop((fdt), (nodeoffset), (name), NULL, 0)
2011int fdt_appendprop(
void *fdt,
int nodeoffset,
const char *name,
2012 const void *val,
int len);
2042static inline int fdt_appendprop_u32(
void *fdt,
int nodeoffset,
2043 const char *name, uint32_t val)
2045 fdt32_t tmp = cpu_to_fdt32(val);
2046 return fdt_appendprop(fdt, nodeoffset, name, &tmp,
sizeof(tmp));
2077static inline int fdt_appendprop_u64(
void *fdt,
int nodeoffset,
2078 const char *name, uint64_t val)
2080 fdt64_t tmp = cpu_to_fdt64(val);
2081 return fdt_appendprop(fdt, nodeoffset, name, &tmp,
sizeof(tmp));
2095static inline int fdt_appendprop_cell(
void *fdt,
int nodeoffset,
2096 const char *name, uint32_t val)
2098 return fdt_appendprop_u32(fdt, nodeoffset, name, val);
2128#define fdt_appendprop_string(fdt, nodeoffset, name, str) \
2129 fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
2165int fdt_appendprop_addrrange(
void *fdt,
int parent,
int nodeoffset,
2166 const char *name, uint64_t addr, uint64_t size);
2190int fdt_delprop(
void *fdt,
int nodeoffset,
const char *name);
2208int fdt_add_subnode_namelen(
void *fdt,
int parentoffset,
2209 const char *name,
int namelen);
2242int fdt_add_subnode(
void *fdt,
int parentoffset,
const char *name);
2265int fdt_del_node(
void *fdt,
int nodeoffset);
2296int fdt_overlay_apply(
void *fdt,
void *fdto);
2313int fdt_overlay_target_offset(
const void *fdt,
const void *fdto,
2314 int fragment_offset,
char const **pathp);
2320const char *fdt_strerror(
int errval);