1 /* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
5 * libfdt - Flat Device Tree manipulation
6 * Copyright (C) 2006 David Gibson, IBM Corporation.
9 #include "libfdt_env.h"
12 #define FDT_FIRST_SUPPORTED_VERSION 0x02
13 #define FDT_LAST_SUPPORTED_VERSION 0x11
15 /* Error codes: informative error codes */
16 #define FDT_ERR_NOTFOUND 1
17 /* FDT_ERR_NOTFOUND: The requested node or property does not exist */
18 #define FDT_ERR_EXISTS 2
19 /* FDT_ERR_EXISTS: Attempted to create a node or property which
21 #define FDT_ERR_NOSPACE 3
22 /* FDT_ERR_NOSPACE: Operation needed to expand the device
23 * tree, but its buffer did not have sufficient space to
24 * contain the expanded tree. Use fdt_open_into() to move the
25 * device tree to a buffer with more space. */
27 /* Error codes: codes for bad parameters */
28 #define FDT_ERR_BADOFFSET 4
29 /* FDT_ERR_BADOFFSET: Function was passed a structure block
30 * offset which is out-of-bounds, or which points to an
31 * unsuitable part of the structure for the operation. */
32 #define FDT_ERR_BADPATH 5
33 /* FDT_ERR_BADPATH: Function was passed a badly formatted path
34 * (e.g. missing a leading / for a function which requires an
36 #define FDT_ERR_BADPHANDLE 6
37 /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.
38 * This can be caused either by an invalid phandle property
39 * length, or the phandle value was either 0 or -1, which are
41 #define FDT_ERR_BADSTATE 7
42 /* FDT_ERR_BADSTATE: Function was passed an incomplete device
43 * tree created by the sequential-write functions, which is
44 * not sufficiently complete for the requested operation. */
46 /* Error codes: codes for bad device tree blobs */
47 #define FDT_ERR_TRUNCATED 8
48 /* FDT_ERR_TRUNCATED: FDT or a sub-block is improperly
49 * terminated (overflows, goes outside allowed bounds, or
50 * isn't properly terminated). */
51 #define FDT_ERR_BADMAGIC 9
52 /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
53 * device tree at all - it is missing the flattened device
54 * tree magic number. */
55 #define FDT_ERR_BADVERSION 10
56 /* FDT_ERR_BADVERSION: Given device tree has a version which
57 * can't be handled by the requested operation. For
58 * read-write functions, this may mean that fdt_open_into() is
59 * required to convert the tree to the expected version. */
60 #define FDT_ERR_BADSTRUCTURE 11
61 /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
62 * structure block or other serious error (e.g. misnested
63 * nodes, or subnodes preceding properties). */
64 #define FDT_ERR_BADLAYOUT 12
65 /* FDT_ERR_BADLAYOUT: For read-write functions, the given
66 * device tree has it's sub-blocks in an order that the
67 * function can't handle (memory reserve map, then structure,
68 * then strings). Use fdt_open_into() to reorganize the tree
69 * into a form suitable for the read-write operations. */
71 /* "Can't happen" error indicating a bug in libfdt */
72 #define FDT_ERR_INTERNAL 13
73 /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
74 * Should never be returned, if it is, it indicates a bug in
77 /* Errors in device tree content */
78 #define FDT_ERR_BADNCELLS 14
79 /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
80 * or similar property with a bad format or value */
82 #define FDT_ERR_BADVALUE 15
83 /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
84 * value. For example: a property expected to contain a string list
85 * is not NUL-terminated within the length of its value. */
87 #define FDT_ERR_BADOVERLAY 16
88 /* FDT_ERR_BADOVERLAY: The device tree overlay, while
89 * correctly structured, cannot be applied due to some
90 * unexpected or missing value, property or node. */
92 #define FDT_ERR_NOPHANDLES 17
93 /* FDT_ERR_NOPHANDLES: The device tree doesn't have any
94 * phandle available anymore without causing an overflow */
96 #define FDT_ERR_BADFLAGS 18
97 /* FDT_ERR_BADFLAGS: The function was passed a flags field that
98 * contains invalid flags or an invalid combination of flags. */
100 #define FDT_ERR_MAX 18
103 #define FDT_MAX_PHANDLE 0xfffffffe
104 /* Valid values for phandles range from 1 to 2^32-2. */
106 /**********************************************************************/
107 /* Low-level functions (you probably don't need these) */
108 /**********************************************************************/
110 #ifndef SWIG /* This function is not useful in Python */
111 const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
113 static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
115 return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
118 uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
122 * These helpers access words from a device tree blob. They're
123 * built to work even with unaligned pointers on platforms (ike
124 * ARM) that don't like unaligned loads and stores
127 static inline uint32_t fdt32_ld(const fdt32_t *p)
129 const uint8_t *bp = (const uint8_t *)p;
131 return ((uint32_t)bp[0] << 24)
132 | ((uint32_t)bp[1] << 16)
133 | ((uint32_t)bp[2] << 8)
137 static inline void fdt32_st(void *property, uint32_t value)
139 uint8_t *bp = (uint8_t *)property;
142 bp[1] = (value >> 16) & 0xff;
143 bp[2] = (value >> 8) & 0xff;
144 bp[3] = value & 0xff;
147 static inline uint64_t fdt64_ld(const fdt64_t *p)
149 const uint8_t *bp = (const uint8_t *)p;
151 return ((uint64_t)bp[0] << 56)
152 | ((uint64_t)bp[1] << 48)
153 | ((uint64_t)bp[2] << 40)
154 | ((uint64_t)bp[3] << 32)
155 | ((uint64_t)bp[4] << 24)
156 | ((uint64_t)bp[5] << 16)
157 | ((uint64_t)bp[6] << 8)
161 static inline void fdt64_st(void *property, uint64_t value)
163 uint8_t *bp = (uint8_t *)property;
166 bp[1] = (value >> 48) & 0xff;
167 bp[2] = (value >> 40) & 0xff;
168 bp[3] = (value >> 32) & 0xff;
169 bp[4] = (value >> 24) & 0xff;
170 bp[5] = (value >> 16) & 0xff;
171 bp[6] = (value >> 8) & 0xff;
172 bp[7] = value & 0xff;
175 /**********************************************************************/
176 /* Traversal functions */
177 /**********************************************************************/
179 int fdt_next_node(const void *fdt, int offset, int *depth);
182 * fdt_first_subnode() - get offset of first direct subnode
185 * @offset: Offset of node to check
186 * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
188 int fdt_first_subnode(const void *fdt, int offset);
191 * fdt_next_subnode() - get offset of next direct subnode
193 * After first calling fdt_first_subnode(), call this function repeatedly to
194 * get direct subnodes of a parent node.
197 * @offset: Offset of previous subnode
198 * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
201 int fdt_next_subnode(const void *fdt, int offset);
204 * fdt_for_each_subnode - iterate over all subnodes of a parent
206 * @node: child node (int, lvalue)
207 * @fdt: FDT blob (const void *)
208 * @parent: parent node (int)
210 * This is actually a wrapper around a for loop and would be used like so:
212 * fdt_for_each_subnode(node, fdt, parent) {
217 * if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) {
221 * Note that this is implemented as a macro and @node is used as
222 * iterator in the loop. The parent variable be constant or even a
226 #define fdt_for_each_subnode(node, fdt, parent) \
227 for (node = fdt_first_subnode(fdt, parent); \
229 node = fdt_next_subnode(fdt, node))
231 /**********************************************************************/
232 /* General functions */
233 /**********************************************************************/
234 #define fdt_get_header(fdt, field) \
235 (fdt32_ld(&((const struct fdt_header *)(fdt))->field))
236 #define fdt_magic(fdt) (fdt_get_header(fdt, magic))
237 #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
238 #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
239 #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
240 #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
241 #define fdt_version(fdt) (fdt_get_header(fdt, version))
242 #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
243 #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
244 #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
245 #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
247 #define fdt_set_hdr_(name) \
248 static inline void fdt_set_##name(void *fdt, uint32_t val) \
250 struct fdt_header *fdth = (struct fdt_header *)fdt; \
251 fdth->name = cpu_to_fdt32(val); \
254 fdt_set_hdr_(totalsize);
255 fdt_set_hdr_(off_dt_struct);
256 fdt_set_hdr_(off_dt_strings);
257 fdt_set_hdr_(off_mem_rsvmap);
258 fdt_set_hdr_(version);
259 fdt_set_hdr_(last_comp_version);
260 fdt_set_hdr_(boot_cpuid_phys);
261 fdt_set_hdr_(size_dt_strings);
262 fdt_set_hdr_(size_dt_struct);
266 * fdt_header_size - return the size of the tree's header
267 * @fdt: pointer to a flattened device tree
269 size_t fdt_header_size(const void *fdt);
272 * fdt_header_size_ - internal function which takes a version number
274 size_t fdt_header_size_(uint32_t version);
277 * fdt_check_header - sanity check a device tree header
279 * @fdt: pointer to data which might be a flattened device tree
281 * fdt_check_header() checks that the given buffer contains what
282 * appears to be a flattened device tree, and that the header contains
283 * valid information (to the extent that can be determined from the
287 * 0, if the buffer appears to contain a valid device tree
289 * -FDT_ERR_BADVERSION,
291 * -FDT_ERR_TRUNCATED, standard meanings, as above
293 int fdt_check_header(const void *fdt);
296 * fdt_move - move a device tree around in memory
297 * @fdt: pointer to the device tree to move
298 * @buf: pointer to memory where the device is to be moved
299 * @bufsize: size of the memory space at buf
301 * fdt_move() relocates, if possible, the device tree blob located at
302 * fdt to the buffer at buf of size bufsize. The buffer may overlap
303 * with the existing device tree blob at fdt. Therefore,
304 * fdt_move(fdt, fdt, fdt_totalsize(fdt))
305 * should always succeed.
309 * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
311 * -FDT_ERR_BADVERSION,
312 * -FDT_ERR_BADSTATE, standard meanings
314 int fdt_move(const void *fdt, void *buf, int bufsize);
316 /**********************************************************************/
317 /* Read-only functions */
318 /**********************************************************************/
320 int fdt_check_full(const void *fdt, size_t bufsize);
323 * fdt_get_string - retrieve a string from the strings block of a device tree
324 * @fdt: pointer to the device tree blob
325 * @stroffset: offset of the string within the strings block (native endian)
326 * @lenp: optional pointer to return the string's length
328 * fdt_get_string() retrieves a pointer to a single string from the
329 * strings block of the device tree blob at fdt, and optionally also
330 * returns the string's length in *lenp.
333 * a pointer to the string, on success
334 * NULL, if stroffset is out of bounds, or doesn't point to a valid string
336 const char *fdt_get_string(const void *fdt, int stroffset, int *lenp);
339 * fdt_string - retrieve a string from the strings block of a device tree
340 * @fdt: pointer to the device tree blob
341 * @stroffset: offset of the string within the strings block (native endian)
343 * fdt_string() retrieves a pointer to a single string from the
344 * strings block of the device tree blob at fdt.
347 * a pointer to the string, on success
348 * NULL, if stroffset is out of bounds, or doesn't point to a valid string
350 const char *fdt_string(const void *fdt, int stroffset);
353 * fdt_find_max_phandle - find and return the highest phandle in a tree
354 * @fdt: pointer to the device tree blob
355 * @phandle: return location for the highest phandle value found in the tree
357 * fdt_find_max_phandle() finds the highest phandle value in the given device
358 * tree. The value returned in @phandle is only valid if the function returns
362 * 0 on success or a negative error code on failure
364 int fdt_find_max_phandle(const void *fdt, uint32_t *phandle);
367 * fdt_get_max_phandle - retrieves the highest phandle in a tree
368 * @fdt: pointer to the device tree blob
370 * fdt_get_max_phandle retrieves the highest phandle in the given
371 * device tree. This will ignore badly formatted phandles, or phandles
372 * with a value of 0 or -1.
374 * This function is deprecated in favour of fdt_find_max_phandle().
377 * the highest phandle on success
378 * 0, if no phandle was found in the device tree
379 * -1, if an error occurred
381 static inline uint32_t fdt_get_max_phandle(const void *fdt)
386 err = fdt_find_max_phandle(fdt, &phandle);
394 * fdt_generate_phandle - return a new, unused phandle for a device tree blob
395 * @fdt: pointer to the device tree blob
396 * @phandle: return location for the new phandle
398 * Walks the device tree blob and looks for the highest phandle value. On
399 * success, the new, unused phandle value (one higher than the previously
400 * highest phandle value in the device tree blob) will be returned in the
401 * @phandle parameter.
404 * 0 on success or a negative error-code on failure
406 int fdt_generate_phandle(const void *fdt, uint32_t *phandle);
409 * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
410 * @fdt: pointer to the device tree blob
412 * Returns the number of entries in the device tree blob's memory
413 * reservation map. This does not include the terminating 0,0 entry
414 * or any other (0,0) entries reserved for expansion.
417 * the number of entries
419 int fdt_num_mem_rsv(const void *fdt);
422 * fdt_get_mem_rsv - retrieve one memory reserve map entry
423 * @fdt: pointer to the device tree blob
424 * @address, @size: pointers to 64-bit variables
426 * On success, *address and *size will contain the address and size of
427 * the n-th reserve map entry from the device tree blob, in
428 * native-endian format.
433 * -FDT_ERR_BADVERSION,
434 * -FDT_ERR_BADSTATE, standard meanings
436 int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
439 * fdt_subnode_offset_namelen - find a subnode based on substring
440 * @fdt: pointer to the device tree blob
441 * @parentoffset: structure block offset of a node
442 * @name: name of the subnode to locate
443 * @namelen: number of characters of name to consider
445 * Identical to fdt_subnode_offset(), but only examine the first
446 * namelen characters of name for matching the subnode name. This is
447 * useful for finding subnodes based on a portion of a larger string,
448 * such as a full path.
450 #ifndef SWIG /* Not available in Python */
451 int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
452 const char *name, int namelen);
455 * fdt_subnode_offset - find a subnode of a given node
456 * @fdt: pointer to the device tree blob
457 * @parentoffset: structure block offset of a node
458 * @name: name of the subnode to locate
460 * fdt_subnode_offset() finds a subnode of the node at structure block
461 * offset parentoffset with the given name. name may include a unit
462 * address, in which case fdt_subnode_offset() will find the subnode
463 * with that unit address, or the unit address may be omitted, in
464 * which case fdt_subnode_offset() will find an arbitrary subnode
465 * whose name excluding unit address matches the given name.
468 * structure block offset of the requested subnode (>=0), on success
469 * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
470 * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
473 * -FDT_ERR_BADVERSION,
475 * -FDT_ERR_BADSTRUCTURE,
476 * -FDT_ERR_TRUNCATED, standard meanings.
478 int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
481 * fdt_path_offset_namelen - find a tree node by its full path
482 * @fdt: pointer to the device tree blob
483 * @path: full path of the node to locate
484 * @namelen: number of characters of path to consider
486 * Identical to fdt_path_offset(), but only consider the first namelen
487 * characters of path as the path name.
489 #ifndef SWIG /* Not available in Python */
490 int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
494 * fdt_path_offset - find a tree node by its full path
495 * @fdt: pointer to the device tree blob
496 * @path: full path of the node to locate
498 * fdt_path_offset() finds a node of a given path in the device tree.
499 * Each path component may omit the unit address portion, but the
500 * results of this are undefined if any such path component is
501 * ambiguous (that is if there are multiple nodes at the relevant
502 * level matching the given component, differentiated only by unit
506 * structure block offset of the node with the requested path (>=0), on
508 * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
509 * -FDT_ERR_NOTFOUND, if the requested node does not exist
511 * -FDT_ERR_BADVERSION,
513 * -FDT_ERR_BADSTRUCTURE,
514 * -FDT_ERR_TRUNCATED, standard meanings.
516 int fdt_path_offset(const void *fdt, const char *path);
519 * fdt_get_name - retrieve the name of a given node
520 * @fdt: pointer to the device tree blob
521 * @nodeoffset: structure block offset of the starting node
522 * @lenp: pointer to an integer variable (will be overwritten) or NULL
524 * fdt_get_name() retrieves the name (including unit address) of the
525 * device tree node at structure block offset nodeoffset. If lenp is
526 * non-NULL, the length of this name is also returned, in the integer
527 * pointed to by lenp.
530 * pointer to the node's name, on success
531 * If lenp is non-NULL, *lenp contains the length of that name
534 * if lenp is non-NULL *lenp contains an error code (<0):
535 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
538 * -FDT_ERR_BADVERSION,
539 * -FDT_ERR_BADSTATE, standard meanings
541 const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
544 * fdt_first_property_offset - find the offset of a node's first property
545 * @fdt: pointer to the device tree blob
546 * @nodeoffset: structure block offset of a node
548 * fdt_first_property_offset() finds the first property of the node at
549 * the given structure block offset.
552 * structure block offset of the property (>=0), on success
553 * -FDT_ERR_NOTFOUND, if the requested node has no properties
554 * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
556 * -FDT_ERR_BADVERSION,
558 * -FDT_ERR_BADSTRUCTURE,
559 * -FDT_ERR_TRUNCATED, standard meanings.
561 int fdt_first_property_offset(const void *fdt, int nodeoffset);
564 * fdt_next_property_offset - step through a node's properties
565 * @fdt: pointer to the device tree blob
566 * @offset: structure block offset of a property
568 * fdt_next_property_offset() finds the property immediately after the
569 * one at the given structure block offset. This will be a property
570 * of the same node as the given property.
573 * structure block offset of the next property (>=0), on success
574 * -FDT_ERR_NOTFOUND, if the given property is the last in its node
575 * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
577 * -FDT_ERR_BADVERSION,
579 * -FDT_ERR_BADSTRUCTURE,
580 * -FDT_ERR_TRUNCATED, standard meanings.
582 int fdt_next_property_offset(const void *fdt, int offset);
585 * fdt_for_each_property_offset - iterate over all properties of a node
587 * @property_offset: property offset (int, lvalue)
588 * @fdt: FDT blob (const void *)
589 * @node: node offset (int)
591 * This is actually a wrapper around a for loop and would be used like so:
593 * fdt_for_each_property_offset(property, fdt, node) {
598 * if ((property < 0) && (property != -FDT_ERR_NOTFOUND)) {
602 * Note that this is implemented as a macro and property is used as
603 * iterator in the loop. The node variable can be constant or even a
606 #define fdt_for_each_property_offset(property, fdt, node) \
607 for (property = fdt_first_property_offset(fdt, node); \
609 property = fdt_next_property_offset(fdt, property))
612 * fdt_get_property_by_offset - retrieve the property at a given offset
613 * @fdt: pointer to the device tree blob
614 * @offset: offset of the property to retrieve
615 * @lenp: pointer to an integer variable (will be overwritten) or NULL
617 * fdt_get_property_by_offset() retrieves a pointer to the
618 * fdt_property structure within the device tree blob at the given
619 * offset. If lenp is non-NULL, the length of the property value is
620 * also returned, in the integer pointed to by lenp.
622 * Note that this code only works on device tree versions >= 16. fdt_getprop()
623 * works on all versions.
626 * pointer to the structure representing the property
627 * if lenp is non-NULL, *lenp contains the length of the property
630 * if lenp is non-NULL, *lenp contains an error code (<0):
631 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
633 * -FDT_ERR_BADVERSION,
635 * -FDT_ERR_BADSTRUCTURE,
636 * -FDT_ERR_TRUNCATED, standard meanings
638 const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
643 * fdt_get_property_namelen - find a property based on substring
644 * @fdt: pointer to the device tree blob
645 * @nodeoffset: offset of the node whose property to find
646 * @name: name of the property to find
647 * @namelen: number of characters of name to consider
648 * @lenp: pointer to an integer variable (will be overwritten) or NULL
650 * Identical to fdt_get_property(), but only examine the first namelen
651 * characters of name for matching the property name.
653 #ifndef SWIG /* Not available in Python */
654 const struct fdt_property *fdt_get_property_namelen(const void *fdt,
657 int namelen, int *lenp);
661 * fdt_get_property - find a given property in a given node
662 * @fdt: pointer to the device tree blob
663 * @nodeoffset: offset of the node whose property to find
664 * @name: name of the property to find
665 * @lenp: pointer to an integer variable (will be overwritten) or NULL
667 * fdt_get_property() retrieves a pointer to the fdt_property
668 * structure within the device tree blob corresponding to the property
669 * named 'name' of the node at offset nodeoffset. If lenp is
670 * non-NULL, the length of the property value is also returned, in the
671 * integer pointed to by lenp.
674 * pointer to the structure representing the property
675 * if lenp is non-NULL, *lenp contains the length of the property
678 * if lenp is non-NULL, *lenp contains an error code (<0):
679 * -FDT_ERR_NOTFOUND, node does not have named property
680 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
683 * -FDT_ERR_BADVERSION,
685 * -FDT_ERR_BADSTRUCTURE,
686 * -FDT_ERR_TRUNCATED, standard meanings
688 const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
689 const char *name, int *lenp);
690 static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
694 return (struct fdt_property *)(uintptr_t)
695 fdt_get_property(fdt, nodeoffset, name, lenp);
699 * fdt_getprop_by_offset - retrieve the value of a property at a given offset
700 * @fdt: pointer to the device tree blob
701 * @offset: offset of the property to read
702 * @namep: pointer to a string variable (will be overwritten) or NULL
703 * @lenp: pointer to an integer variable (will be overwritten) or NULL
705 * fdt_getprop_by_offset() retrieves a pointer to the value of the
706 * property at structure block offset 'offset' (this will be a pointer
707 * to within the device blob itself, not a copy of the value). If
708 * lenp is non-NULL, the length of the property value is also
709 * returned, in the integer pointed to by lenp. If namep is non-NULL,
710 * the property's namne will also be returned in the char * pointed to
711 * by namep (this will be a pointer to within the device tree's string
712 * block, not a new copy of the name).
715 * pointer to the property's value
716 * if lenp is non-NULL, *lenp contains the length of the property
718 * if namep is non-NULL *namep contiains a pointer to the property
721 * if lenp is non-NULL, *lenp contains an error code (<0):
722 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
724 * -FDT_ERR_BADVERSION,
726 * -FDT_ERR_BADSTRUCTURE,
727 * -FDT_ERR_TRUNCATED, standard meanings
729 #ifndef SWIG /* This function is not useful in Python */
730 const void *fdt_getprop_by_offset(const void *fdt, int offset,
731 const char **namep, int *lenp);
735 * fdt_getprop_namelen - get property value based on substring
736 * @fdt: pointer to the device tree blob
737 * @nodeoffset: offset of the node whose property to find
738 * @name: name of the property to find
739 * @namelen: number of characters of name to consider
740 * @lenp: pointer to an integer variable (will be overwritten) or NULL
742 * Identical to fdt_getprop(), but only examine the first namelen
743 * characters of name for matching the property name.
745 #ifndef SWIG /* Not available in Python */
746 const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
747 const char *name, int namelen, int *lenp);
748 static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,
749 const char *name, int namelen,
752 return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,
758 * fdt_getprop - retrieve the value of a given property
759 * @fdt: pointer to the device tree blob
760 * @nodeoffset: offset of the node whose property to find
761 * @name: name of the property to find
762 * @lenp: pointer to an integer variable (will be overwritten) or NULL
764 * fdt_getprop() retrieves a pointer to the value of the property
765 * named 'name' of the node at offset nodeoffset (this will be a
766 * pointer to within the device blob itself, not a copy of the value).
767 * If lenp is non-NULL, the length of the property value is also
768 * returned, in the integer pointed to by lenp.
771 * pointer to the property's value
772 * if lenp is non-NULL, *lenp contains the length of the property
775 * if lenp is non-NULL, *lenp contains an error code (<0):
776 * -FDT_ERR_NOTFOUND, node does not have named property
777 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
780 * -FDT_ERR_BADVERSION,
782 * -FDT_ERR_BADSTRUCTURE,
783 * -FDT_ERR_TRUNCATED, standard meanings
785 const void *fdt_getprop(const void *fdt, int nodeoffset,
786 const char *name, int *lenp);
787 static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
788 const char *name, int *lenp)
790 return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
794 * fdt_get_phandle - retrieve the phandle of a given node
795 * @fdt: pointer to the device tree blob
796 * @nodeoffset: structure block offset of the node
798 * fdt_get_phandle() retrieves the phandle of the device tree node at
799 * structure block offset nodeoffset.
802 * the phandle of the node at nodeoffset, on success (!= 0, != -1)
803 * 0, if the node has no phandle, or another error occurs
805 uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
808 * fdt_get_alias_namelen - get alias based on substring
809 * @fdt: pointer to the device tree blob
810 * @name: name of the alias th look up
811 * @namelen: number of characters of name to consider
813 * Identical to fdt_get_alias(), but only examine the first namelen
814 * characters of name for matching the alias name.
816 #ifndef SWIG /* Not available in Python */
817 const char *fdt_get_alias_namelen(const void *fdt,
818 const char *name, int namelen);
822 * fdt_get_alias - retrieve the path referenced by a given alias
823 * @fdt: pointer to the device tree blob
824 * @name: name of the alias th look up
826 * fdt_get_alias() retrieves the value of a given alias. That is, the
827 * value of the property named 'name' in the node /aliases.
830 * a pointer to the expansion of the alias named 'name', if it exists
831 * NULL, if the given alias or the /aliases node does not exist
833 const char *fdt_get_alias(const void *fdt, const char *name);
836 * fdt_get_path - determine the full path of a node
837 * @fdt: pointer to the device tree blob
838 * @nodeoffset: offset of the node whose path to find
839 * @buf: character buffer to contain the returned path (will be overwritten)
840 * @buflen: size of the character buffer at buf
842 * fdt_get_path() computes the full path of the node at offset
843 * nodeoffset, and records that path in the buffer at buf.
845 * NOTE: This function is expensive, as it must scan the device tree
846 * structure from the start to nodeoffset.
850 * buf contains the absolute path of the node at
851 * nodeoffset, as a NUL-terminated string.
852 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
853 * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
854 * characters and will not fit in the given buffer.
856 * -FDT_ERR_BADVERSION,
858 * -FDT_ERR_BADSTRUCTURE, standard meanings
860 int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
863 * fdt_supernode_atdepth_offset - find a specific ancestor of a node
864 * @fdt: pointer to the device tree blob
865 * @nodeoffset: offset of the node whose parent to find
866 * @supernodedepth: depth of the ancestor to find
867 * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
869 * fdt_supernode_atdepth_offset() finds an ancestor of the given node
870 * at a specific depth from the root (where the root itself has depth
871 * 0, its immediate subnodes depth 1 and so forth). So
872 * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
873 * will always return 0, the offset of the root node. If the node at
874 * nodeoffset has depth D, then:
875 * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
876 * will return nodeoffset itself.
878 * NOTE: This function is expensive, as it must scan the device tree
879 * structure from the start to nodeoffset.
882 * structure block offset of the node at node offset's ancestor
883 * of depth supernodedepth (>=0), on success
884 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
885 * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of
888 * -FDT_ERR_BADVERSION,
890 * -FDT_ERR_BADSTRUCTURE, standard meanings
892 int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
893 int supernodedepth, int *nodedepth);
896 * fdt_node_depth - find the depth of a given node
897 * @fdt: pointer to the device tree blob
898 * @nodeoffset: offset of the node whose parent to find
900 * fdt_node_depth() finds the depth of a given node. The root node
901 * has depth 0, its immediate subnodes depth 1 and so forth.
903 * NOTE: This function is expensive, as it must scan the device tree
904 * structure from the start to nodeoffset.
907 * depth of the node at nodeoffset (>=0), on success
908 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
910 * -FDT_ERR_BADVERSION,
912 * -FDT_ERR_BADSTRUCTURE, standard meanings
914 int fdt_node_depth(const void *fdt, int nodeoffset);
917 * fdt_parent_offset - find the parent of a given node
918 * @fdt: pointer to the device tree blob
919 * @nodeoffset: offset of the node whose parent to find
921 * fdt_parent_offset() locates the parent node of a given node (that
922 * is, it finds the offset of the node which contains the node at
923 * nodeoffset as a subnode).
925 * NOTE: This function is expensive, as it must scan the device tree
926 * structure from the start to nodeoffset, *twice*.
929 * structure block offset of the parent of the node at nodeoffset
931 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
933 * -FDT_ERR_BADVERSION,
935 * -FDT_ERR_BADSTRUCTURE, standard meanings
937 int fdt_parent_offset(const void *fdt, int nodeoffset);
940 * fdt_node_offset_by_prop_value - find nodes with a given property value
941 * @fdt: pointer to the device tree blob
942 * @startoffset: only find nodes after this offset
943 * @propname: property name to check
944 * @propval: property value to search for
945 * @proplen: length of the value in propval
947 * fdt_node_offset_by_prop_value() returns the offset of the first
948 * node after startoffset, which has a property named propname whose
949 * value is of length proplen and has value equal to propval; or if
950 * startoffset is -1, the very first such node in the tree.
952 * To iterate through all nodes matching the criterion, the following
954 * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
956 * while (offset != -FDT_ERR_NOTFOUND) {
958 * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
962 * Note the -1 in the first call to the function, if 0 is used here
963 * instead, the function will never locate the root node, even if it
964 * matches the criterion.
967 * structure block offset of the located node (>= 0, >startoffset),
969 * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
970 * tree after startoffset
971 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
973 * -FDT_ERR_BADVERSION,
975 * -FDT_ERR_BADSTRUCTURE, standard meanings
977 int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
978 const char *propname,
979 const void *propval, int proplen);
982 * fdt_node_offset_by_phandle - find the node with a given phandle
983 * @fdt: pointer to the device tree blob
984 * @phandle: phandle value
986 * fdt_node_offset_by_phandle() returns the offset of the node
987 * which has the given phandle value. If there is more than one node
988 * in the tree with the given phandle (an invalid tree), results are
992 * structure block offset of the located node (>= 0), on success
993 * -FDT_ERR_NOTFOUND, no node with that phandle exists
994 * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
996 * -FDT_ERR_BADVERSION,
998 * -FDT_ERR_BADSTRUCTURE, standard meanings
1000 int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
1003 * fdt_node_check_compatible: check a node's compatible property
1004 * @fdt: pointer to the device tree blob
1005 * @nodeoffset: offset of a tree node
1006 * @compatible: string to match against
1009 * fdt_node_check_compatible() returns 0 if the given node contains a
1010 * 'compatible' property with the given string as one of its elements,
1011 * it returns non-zero otherwise, or on error.
1014 * 0, if the node has a 'compatible' property listing the given string
1015 * 1, if the node has a 'compatible' property, but it does not list
1017 * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
1018 * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
1019 * -FDT_ERR_BADMAGIC,
1020 * -FDT_ERR_BADVERSION,
1021 * -FDT_ERR_BADSTATE,
1022 * -FDT_ERR_BADSTRUCTURE, standard meanings
1024 int fdt_node_check_compatible(const void *fdt, int nodeoffset,
1025 const char *compatible);
1028 * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
1029 * @fdt: pointer to the device tree blob
1030 * @startoffset: only find nodes after this offset
1031 * @compatible: 'compatible' string to match against
1033 * fdt_node_offset_by_compatible() returns the offset of the first
1034 * node after startoffset, which has a 'compatible' property which
1035 * lists the given compatible string; or if startoffset is -1, the
1036 * very first such node in the tree.
1038 * To iterate through all nodes matching the criterion, the following
1039 * idiom can be used:
1040 * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
1041 * while (offset != -FDT_ERR_NOTFOUND) {
1042 * // other code here
1043 * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
1046 * Note the -1 in the first call to the function, if 0 is used here
1047 * instead, the function will never locate the root node, even if it
1048 * matches the criterion.
1051 * structure block offset of the located node (>= 0, >startoffset),
1053 * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
1054 * tree after startoffset
1055 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
1056 * -FDT_ERR_BADMAGIC,
1057 * -FDT_ERR_BADVERSION,
1058 * -FDT_ERR_BADSTATE,
1059 * -FDT_ERR_BADSTRUCTURE, standard meanings
1061 int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
1062 const char *compatible);
1065 * fdt_stringlist_contains - check a string list property for a string
1066 * @strlist: Property containing a list of strings to check
1067 * @listlen: Length of property
1068 * @str: String to search for
1070 * This is a utility function provided for convenience. The list contains
1071 * one or more strings, each terminated by \0, as is found in a device tree
1072 * "compatible" property.
1074 * @return: 1 if the string is found in the list, 0 not found, or invalid list
1076 int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
1079 * fdt_stringlist_count - count the number of strings in a string list
1080 * @fdt: pointer to the device tree blob
1081 * @nodeoffset: offset of a tree node
1082 * @property: name of the property containing the string list
1084 * the number of strings in the given property
1085 * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
1086 * -FDT_ERR_NOTFOUND if the property does not exist
1088 int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);
1091 * fdt_stringlist_search - find a string in a string list and return its index
1092 * @fdt: pointer to the device tree blob
1093 * @nodeoffset: offset of a tree node
1094 * @property: name of the property containing the string list
1095 * @string: string to look up in the string list
1097 * Note that it is possible for this function to succeed on property values
1098 * that are not NUL-terminated. That's because the function will stop after
1099 * finding the first occurrence of @string. This can for example happen with
1100 * small-valued cell properties, such as #address-cells, when searching for
1104 * the index of the string in the list of strings
1105 * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
1106 * -FDT_ERR_NOTFOUND if the property does not exist or does not contain
1109 int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
1110 const char *string);
1113 * fdt_stringlist_get() - obtain the string at a given index in a string list
1114 * @fdt: pointer to the device tree blob
1115 * @nodeoffset: offset of a tree node
1116 * @property: name of the property containing the string list
1117 * @index: index of the string to return
1118 * @lenp: return location for the string length or an error code on failure
1120 * Note that this will successfully extract strings from properties with
1121 * non-NUL-terminated values. For example on small-valued cell properties
1122 * this function will return the empty string.
1124 * If non-NULL, the length of the string (on success) or a negative error-code
1125 * (on failure) will be stored in the integer pointer to by lenp.
1128 * A pointer to the string at the given index in the string list or NULL on
1129 * failure. On success the length of the string will be stored in the memory
1130 * location pointed to by the lenp parameter, if non-NULL. On failure one of
1131 * the following negative error codes will be returned in the lenp parameter
1133 * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
1134 * -FDT_ERR_NOTFOUND if the property does not exist
1136 const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
1137 const char *property, int index,
1140 /**********************************************************************/
1141 /* Read-only functions (addressing related) */
1142 /**********************************************************************/
1145 * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
1147 * This is the maximum value for #address-cells, #size-cells and
1148 * similar properties that will be processed by libfdt. IEE1275
1149 * requires that OF implementations handle values up to 4.
1150 * Implementations may support larger values, but in practice higher
1151 * values aren't used.
1153 #define FDT_MAX_NCELLS 4
1156 * fdt_address_cells - retrieve address size for a bus represented in the tree
1157 * @fdt: pointer to the device tree blob
1158 * @nodeoffset: offset of the node to find the address size for
1160 * When the node has a valid #address-cells property, returns its value.
1163 * 0 <= n < FDT_MAX_NCELLS, on success
1164 * 2, if the node has no #address-cells property
1165 * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
1166 * #address-cells property
1167 * -FDT_ERR_BADMAGIC,
1168 * -FDT_ERR_BADVERSION,
1169 * -FDT_ERR_BADSTATE,
1170 * -FDT_ERR_BADSTRUCTURE,
1171 * -FDT_ERR_TRUNCATED, standard meanings
1173 int fdt_address_cells(const void *fdt, int nodeoffset);
1176 * fdt_size_cells - retrieve address range size for a bus represented in the
1178 * @fdt: pointer to the device tree blob
1179 * @nodeoffset: offset of the node to find the address range size for
1181 * When the node has a valid #size-cells property, returns its value.
1184 * 0 <= n < FDT_MAX_NCELLS, on success
1185 * 1, if the node has no #size-cells property
1186 * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
1187 * #size-cells property
1188 * -FDT_ERR_BADMAGIC,
1189 * -FDT_ERR_BADVERSION,
1190 * -FDT_ERR_BADSTATE,
1191 * -FDT_ERR_BADSTRUCTURE,
1192 * -FDT_ERR_TRUNCATED, standard meanings
1194 int fdt_size_cells(const void *fdt, int nodeoffset);
1197 /**********************************************************************/
1198 /* Write-in-place functions */
1199 /**********************************************************************/
1202 * fdt_setprop_inplace_namelen_partial - change a property's value,
1204 * @fdt: pointer to the device tree blob
1205 * @nodeoffset: offset of the node whose property to change
1206 * @name: name of the property to change
1207 * @namelen: number of characters of name to consider
1208 * @idx: index of the property to change in the array
1209 * @val: pointer to data to replace the property value with
1210 * @len: length of the property value
1212 * Identical to fdt_setprop_inplace(), but modifies the given property
1213 * starting from the given index, and using only the first characters
1214 * of the name. It is useful when you want to manipulate only one value of
1215 * an array and you have a string that doesn't end with \0.
1217 #ifndef SWIG /* Not available in Python */
1218 int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
1219 const char *name, int namelen,
1220 uint32_t idx, const void *val,
1225 * fdt_setprop_inplace - change a property's value, but not its size
1226 * @fdt: pointer to the device tree blob
1227 * @nodeoffset: offset of the node whose property to change
1228 * @name: name of the property to change
1229 * @val: pointer to data to replace the property value with
1230 * @len: length of the property value
1232 * fdt_setprop_inplace() replaces the value of a given property with
1233 * the data in val, of length len. This function cannot change the
1234 * size of a property, and so will only work if len is equal to the
1235 * current length of the property.
1237 * This function will alter only the bytes in the blob which contain
1238 * the given property value, and will not alter or move any other part
1243 * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
1244 * -FDT_ERR_NOTFOUND, node does not have the named property
1245 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1246 * -FDT_ERR_BADMAGIC,
1247 * -FDT_ERR_BADVERSION,
1248 * -FDT_ERR_BADSTATE,
1249 * -FDT_ERR_BADSTRUCTURE,
1250 * -FDT_ERR_TRUNCATED, standard meanings
1252 #ifndef SWIG /* Not available in Python */
1253 int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
1254 const void *val, int len);
1258 * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
1259 * @fdt: pointer to the device tree blob
1260 * @nodeoffset: offset of the node whose property to change
1261 * @name: name of the property to change
1262 * @val: 32-bit integer value to replace the property with
1264 * fdt_setprop_inplace_u32() replaces the value of a given property
1265 * with the 32-bit integer value in val, converting val to big-endian
1266 * if necessary. This function cannot change the size of a property,
1267 * and so will only work if the property already exists and has length
1270 * This function will alter only the bytes in the blob which contain
1271 * the given property value, and will not alter or move any other part
1276 * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
1277 * -FDT_ERR_NOTFOUND, node does not have the named property
1278 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1279 * -FDT_ERR_BADMAGIC,
1280 * -FDT_ERR_BADVERSION,
1281 * -FDT_ERR_BADSTATE,
1282 * -FDT_ERR_BADSTRUCTURE,
1283 * -FDT_ERR_TRUNCATED, standard meanings
1285 static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
1286 const char *name, uint32_t val)
1288 fdt32_t tmp = cpu_to_fdt32(val);
1289 return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1293 * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
1294 * @fdt: pointer to the device tree blob
1295 * @nodeoffset: offset of the node whose property to change
1296 * @name: name of the property to change
1297 * @val: 64-bit integer value to replace the property with
1299 * fdt_setprop_inplace_u64() replaces the value of a given property
1300 * with the 64-bit integer value in val, converting val to big-endian
1301 * if necessary. This function cannot change the size of a property,
1302 * and so will only work if the property already exists and has length
1305 * This function will alter only the bytes in the blob which contain
1306 * the given property value, and will not alter or move any other part
1311 * -FDT_ERR_NOSPACE, if the property's length is not equal to 8
1312 * -FDT_ERR_NOTFOUND, node does not have the named property
1313 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1314 * -FDT_ERR_BADMAGIC,
1315 * -FDT_ERR_BADVERSION,
1316 * -FDT_ERR_BADSTATE,
1317 * -FDT_ERR_BADSTRUCTURE,
1318 * -FDT_ERR_TRUNCATED, standard meanings
1320 static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
1321 const char *name, uint64_t val)
1323 fdt64_t tmp = cpu_to_fdt64(val);
1324 return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1328 * fdt_setprop_inplace_cell - change the value of a single-cell property
1330 * This is an alternative name for fdt_setprop_inplace_u32()
1332 static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
1333 const char *name, uint32_t val)
1335 return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
1339 * fdt_nop_property - replace a property with nop tags
1340 * @fdt: pointer to the device tree blob
1341 * @nodeoffset: offset of the node whose property to nop
1342 * @name: name of the property to nop
1344 * fdt_nop_property() will replace a given property's representation
1345 * in the blob with FDT_NOP tags, effectively removing it from the
1348 * This function will alter only the bytes in the blob which contain
1349 * the property, and will not alter or move any other part of the
1354 * -FDT_ERR_NOTFOUND, node does not have the named property
1355 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1356 * -FDT_ERR_BADMAGIC,
1357 * -FDT_ERR_BADVERSION,
1358 * -FDT_ERR_BADSTATE,
1359 * -FDT_ERR_BADSTRUCTURE,
1360 * -FDT_ERR_TRUNCATED, standard meanings
1362 int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
1365 * fdt_nop_node - replace a node (subtree) with nop tags
1366 * @fdt: pointer to the device tree blob
1367 * @nodeoffset: offset of the node to nop
1369 * fdt_nop_node() will replace a given node's representation in the
1370 * blob, including all its subnodes, if any, with FDT_NOP tags,
1371 * effectively removing it from the tree.
1373 * This function will alter only the bytes in the blob which contain
1374 * the node and its properties and subnodes, and will not alter or
1375 * move any other part of the tree.
1379 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1380 * -FDT_ERR_BADMAGIC,
1381 * -FDT_ERR_BADVERSION,
1382 * -FDT_ERR_BADSTATE,
1383 * -FDT_ERR_BADSTRUCTURE,
1384 * -FDT_ERR_TRUNCATED, standard meanings
1386 int fdt_nop_node(void *fdt, int nodeoffset);
1388 /**********************************************************************/
1389 /* Sequential write functions */
1390 /**********************************************************************/
1392 /* fdt_create_with_flags flags */
1393 #define FDT_CREATE_FLAG_NO_NAME_DEDUP 0x1
1394 /* FDT_CREATE_FLAG_NO_NAME_DEDUP: Do not try to de-duplicate property
1395 * names in the fdt. This can result in faster creation times, but
1398 #define FDT_CREATE_FLAGS_ALL (FDT_CREATE_FLAG_NO_NAME_DEDUP)
1401 * fdt_create_with_flags - begin creation of a new fdt
1402 * @fdt: pointer to memory allocated where fdt will be created
1403 * @bufsize: size of the memory space at fdt
1404 * @flags: a valid combination of FDT_CREATE_FLAG_ flags, or 0.
1406 * fdt_create_with_flags() begins the process of creating a new fdt with
1407 * the sequential write interface.
1409 * fdt creation process must end with fdt_finished() to produce a valid fdt.
1413 * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
1414 * -FDT_ERR_BADFLAGS, flags is not valid
1416 int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags);
1419 * fdt_create - begin creation of a new fdt
1420 * @fdt: pointer to memory allocated where fdt will be created
1421 * @bufsize: size of the memory space at fdt
1423 * fdt_create() is equivalent to fdt_create_with_flags() with flags=0.
1427 * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
1429 int fdt_create(void *buf, int bufsize);
1431 int fdt_resize(void *fdt, void *buf, int bufsize);
1432 int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
1433 int fdt_finish_reservemap(void *fdt);
1434 int fdt_begin_node(void *fdt, const char *name);
1435 int fdt_property(void *fdt, const char *name, const void *val, int len);
1436 static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
1438 fdt32_t tmp = cpu_to_fdt32(val);
1439 return fdt_property(fdt, name, &tmp, sizeof(tmp));
1441 static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
1443 fdt64_t tmp = cpu_to_fdt64(val);
1444 return fdt_property(fdt, name, &tmp, sizeof(tmp));
1447 #ifndef SWIG /* Not available in Python */
1448 static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
1450 return fdt_property_u32(fdt, name, val);
1455 * fdt_property_placeholder - add a new property and return a ptr to its value
1457 * @fdt: pointer to the device tree blob
1458 * @name: name of property to add
1459 * @len: length of property value in bytes
1460 * @valp: returns a pointer to where where the value should be placed
1464 * -FDT_ERR_BADMAGIC,
1465 * -FDT_ERR_NOSPACE, standard meanings
1467 int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp);
1469 #define fdt_property_string(fdt, name, str) \
1470 fdt_property(fdt, name, str, strlen(str)+1)
1471 int fdt_end_node(void *fdt);
1472 int fdt_finish(void *fdt);
1474 /**********************************************************************/
1475 /* Read-write functions */
1476 /**********************************************************************/
1478 int fdt_create_empty_tree(void *buf, int bufsize);
1479 int fdt_open_into(const void *fdt, void *buf, int bufsize);
1480 int fdt_pack(void *fdt);
1483 * fdt_add_mem_rsv - add one memory reserve map entry
1484 * @fdt: pointer to the device tree blob
1485 * @address, @size: 64-bit values (native endian)
1487 * Adds a reserve map entry to the given blob reserving a region at
1488 * address address of length size.
1490 * This function will insert data into the reserve map and will
1491 * therefore change the indexes of some entries in the table.
1495 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1496 * contain the new reservation entry
1497 * -FDT_ERR_BADMAGIC,
1498 * -FDT_ERR_BADVERSION,
1499 * -FDT_ERR_BADSTATE,
1500 * -FDT_ERR_BADSTRUCTURE,
1501 * -FDT_ERR_BADLAYOUT,
1502 * -FDT_ERR_TRUNCATED, standard meanings
1504 int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
1507 * fdt_del_mem_rsv - remove a memory reserve map entry
1508 * @fdt: pointer to the device tree blob
1509 * @n: entry to remove
1511 * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
1514 * This function will delete data from the reservation table and will
1515 * therefore change the indexes of some entries in the table.
1519 * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
1520 * are less than n+1 reserve map entries)
1521 * -FDT_ERR_BADMAGIC,
1522 * -FDT_ERR_BADVERSION,
1523 * -FDT_ERR_BADSTATE,
1524 * -FDT_ERR_BADSTRUCTURE,
1525 * -FDT_ERR_BADLAYOUT,
1526 * -FDT_ERR_TRUNCATED, standard meanings
1528 int fdt_del_mem_rsv(void *fdt, int n);
1531 * fdt_set_name - change the name of a given node
1532 * @fdt: pointer to the device tree blob
1533 * @nodeoffset: structure block offset of a node
1534 * @name: name to give the node
1536 * fdt_set_name() replaces the name (including unit address, if any)
1537 * of the given node with the given string. NOTE: this function can't
1538 * efficiently check if the new name is unique amongst the given
1539 * node's siblings; results are undefined if this function is invoked
1540 * with a name equal to one of the given node's siblings.
1542 * This function may insert or delete data from the blob, and will
1543 * therefore change the offsets of some existing nodes.
1547 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
1548 * to contain the new name
1549 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1550 * -FDT_ERR_BADMAGIC,
1551 * -FDT_ERR_BADVERSION,
1552 * -FDT_ERR_BADSTATE, standard meanings
1554 int fdt_set_name(void *fdt, int nodeoffset, const char *name);
1557 * fdt_setprop - create or change a property
1558 * @fdt: pointer to the device tree blob
1559 * @nodeoffset: offset of the node whose property to change
1560 * @name: name of the property to change
1561 * @val: pointer to data to set the property value to
1562 * @len: length of the property value
1564 * fdt_setprop() sets the value of the named property in the given
1565 * node to the given value and length, creating the property if it
1566 * does not already exist.
1568 * This function may insert or delete data from the blob, and will
1569 * therefore change the offsets of some existing nodes.
1573 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1574 * contain the new property value
1575 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1576 * -FDT_ERR_BADLAYOUT,
1577 * -FDT_ERR_BADMAGIC,
1578 * -FDT_ERR_BADVERSION,
1579 * -FDT_ERR_BADSTATE,
1580 * -FDT_ERR_BADSTRUCTURE,
1581 * -FDT_ERR_BADLAYOUT,
1582 * -FDT_ERR_TRUNCATED, standard meanings
1584 int fdt_setprop(void *fdt, int nodeoffset, const char *name,
1585 const void *val, int len);
1588 * fdt_setprop_placeholder - allocate space for a property
1589 * @fdt: pointer to the device tree blob
1590 * @nodeoffset: offset of the node whose property to change
1591 * @name: name of the property to change
1592 * @len: length of the property value
1593 * @prop_data: return pointer to property data
1595 * fdt_setprop_placeholer() allocates the named property in the given node.
1596 * If the property exists it is resized. In either case a pointer to the
1597 * property data is returned.
1599 * This function may insert or delete data from the blob, and will
1600 * therefore change the offsets of some existing nodes.
1604 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1605 * contain the new property value
1606 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1607 * -FDT_ERR_BADLAYOUT,
1608 * -FDT_ERR_BADMAGIC,
1609 * -FDT_ERR_BADVERSION,
1610 * -FDT_ERR_BADSTATE,
1611 * -FDT_ERR_BADSTRUCTURE,
1612 * -FDT_ERR_BADLAYOUT,
1613 * -FDT_ERR_TRUNCATED, standard meanings
1615 int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,
1616 int len, void **prop_data);
1619 * fdt_setprop_u32 - set a property to a 32-bit integer
1620 * @fdt: pointer to the device tree blob
1621 * @nodeoffset: offset of the node whose property to change
1622 * @name: name of the property to change
1623 * @val: 32-bit integer value for the property (native endian)
1625 * fdt_setprop_u32() sets the value of the named property in the given
1626 * node to the given 32-bit integer value (converting to big-endian if
1627 * necessary), or creates a new property with that value if it does
1628 * not already exist.
1630 * This function may insert or delete data from the blob, and will
1631 * therefore change the offsets of some existing nodes.
1635 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1636 * contain the new property value
1637 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1638 * -FDT_ERR_BADLAYOUT,
1639 * -FDT_ERR_BADMAGIC,
1640 * -FDT_ERR_BADVERSION,
1641 * -FDT_ERR_BADSTATE,
1642 * -FDT_ERR_BADSTRUCTURE,
1643 * -FDT_ERR_BADLAYOUT,
1644 * -FDT_ERR_TRUNCATED, standard meanings
1646 static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
1649 fdt32_t tmp = cpu_to_fdt32(val);
1650 return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1654 * fdt_setprop_u64 - set a property to a 64-bit integer
1655 * @fdt: pointer to the device tree blob
1656 * @nodeoffset: offset of the node whose property to change
1657 * @name: name of the property to change
1658 * @val: 64-bit integer value for the property (native endian)
1660 * fdt_setprop_u64() sets the value of the named property in the given
1661 * node to the given 64-bit integer value (converting to big-endian if
1662 * necessary), or creates a new property with that value if it does
1663 * not already exist.
1665 * This function may insert or delete data from the blob, and will
1666 * therefore change the offsets of some existing nodes.
1670 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1671 * contain the new property value
1672 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1673 * -FDT_ERR_BADLAYOUT,
1674 * -FDT_ERR_BADMAGIC,
1675 * -FDT_ERR_BADVERSION,
1676 * -FDT_ERR_BADSTATE,
1677 * -FDT_ERR_BADSTRUCTURE,
1678 * -FDT_ERR_BADLAYOUT,
1679 * -FDT_ERR_TRUNCATED, standard meanings
1681 static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
1684 fdt64_t tmp = cpu_to_fdt64(val);
1685 return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1689 * fdt_setprop_cell - set a property to a single cell value
1691 * This is an alternative name for fdt_setprop_u32()
1693 static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
1696 return fdt_setprop_u32(fdt, nodeoffset, name, val);
1700 * fdt_setprop_string - set a property to a string value
1701 * @fdt: pointer to the device tree blob
1702 * @nodeoffset: offset of the node whose property to change
1703 * @name: name of the property to change
1704 * @str: string value for the property
1706 * fdt_setprop_string() sets the value of the named property in the
1707 * given node to the given string value (using the length of the
1708 * string to determine the new length of the property), or creates a
1709 * new property with that value if it does not already exist.
1711 * This function may insert or delete data from the blob, and will
1712 * therefore change the offsets of some existing nodes.
1716 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1717 * contain the new property value
1718 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1719 * -FDT_ERR_BADLAYOUT,
1720 * -FDT_ERR_BADMAGIC,
1721 * -FDT_ERR_BADVERSION,
1722 * -FDT_ERR_BADSTATE,
1723 * -FDT_ERR_BADSTRUCTURE,
1724 * -FDT_ERR_BADLAYOUT,
1725 * -FDT_ERR_TRUNCATED, standard meanings
1727 #define fdt_setprop_string(fdt, nodeoffset, name, str) \
1728 fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
1732 * fdt_setprop_empty - set a property to an empty value
1733 * @fdt: pointer to the device tree blob
1734 * @nodeoffset: offset of the node whose property to change
1735 * @name: name of the property to change
1737 * fdt_setprop_empty() sets the value of the named property in the
1738 * given node to an empty (zero length) value, or creates a new empty
1739 * property if it does not already exist.
1741 * This function may insert or delete data from the blob, and will
1742 * therefore change the offsets of some existing nodes.
1746 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1747 * contain the new property value
1748 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1749 * -FDT_ERR_BADLAYOUT,
1750 * -FDT_ERR_BADMAGIC,
1751 * -FDT_ERR_BADVERSION,
1752 * -FDT_ERR_BADSTATE,
1753 * -FDT_ERR_BADSTRUCTURE,
1754 * -FDT_ERR_BADLAYOUT,
1755 * -FDT_ERR_TRUNCATED, standard meanings
1757 #define fdt_setprop_empty(fdt, nodeoffset, name) \
1758 fdt_setprop((fdt), (nodeoffset), (name), NULL, 0)
1761 * fdt_appendprop - append to or create a property
1762 * @fdt: pointer to the device tree blob
1763 * @nodeoffset: offset of the node whose property to change
1764 * @name: name of the property to append to
1765 * @val: pointer to data to append to the property value
1766 * @len: length of the data to append to the property value
1768 * fdt_appendprop() appends the value to the named property in the
1769 * given node, creating the property if it does not already exist.
1771 * This function may insert data into the blob, and will therefore
1772 * change the offsets of some existing nodes.
1776 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1777 * contain the new property value
1778 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1779 * -FDT_ERR_BADLAYOUT,
1780 * -FDT_ERR_BADMAGIC,
1781 * -FDT_ERR_BADVERSION,
1782 * -FDT_ERR_BADSTATE,
1783 * -FDT_ERR_BADSTRUCTURE,
1784 * -FDT_ERR_BADLAYOUT,
1785 * -FDT_ERR_TRUNCATED, standard meanings
1787 int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
1788 const void *val, int len);
1791 * fdt_appendprop_u32 - append a 32-bit integer value to a property
1792 * @fdt: pointer to the device tree blob
1793 * @nodeoffset: offset of the node whose property to change
1794 * @name: name of the property to change
1795 * @val: 32-bit integer value to append to the property (native endian)
1797 * fdt_appendprop_u32() appends the given 32-bit integer value
1798 * (converting to big-endian if necessary) to the value of the named
1799 * property in the given node, or creates a new property with that
1800 * value if it does not already exist.
1802 * This function may insert data into the blob, and will therefore
1803 * change the offsets of some existing nodes.
1807 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1808 * contain the new property value
1809 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1810 * -FDT_ERR_BADLAYOUT,
1811 * -FDT_ERR_BADMAGIC,
1812 * -FDT_ERR_BADVERSION,
1813 * -FDT_ERR_BADSTATE,
1814 * -FDT_ERR_BADSTRUCTURE,
1815 * -FDT_ERR_BADLAYOUT,
1816 * -FDT_ERR_TRUNCATED, standard meanings
1818 static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
1819 const char *name, uint32_t val)
1821 fdt32_t tmp = cpu_to_fdt32(val);
1822 return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1826 * fdt_appendprop_u64 - append a 64-bit integer value to a property
1827 * @fdt: pointer to the device tree blob
1828 * @nodeoffset: offset of the node whose property to change
1829 * @name: name of the property to change
1830 * @val: 64-bit integer value to append to the property (native endian)
1832 * fdt_appendprop_u64() appends the given 64-bit integer value
1833 * (converting to big-endian if necessary) to the value of the named
1834 * property in the given node, or creates a new property with that
1835 * value if it does not already exist.
1837 * This function may insert data into the blob, and will therefore
1838 * change the offsets of some existing nodes.
1842 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1843 * contain the new property value
1844 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1845 * -FDT_ERR_BADLAYOUT,
1846 * -FDT_ERR_BADMAGIC,
1847 * -FDT_ERR_BADVERSION,
1848 * -FDT_ERR_BADSTATE,
1849 * -FDT_ERR_BADSTRUCTURE,
1850 * -FDT_ERR_BADLAYOUT,
1851 * -FDT_ERR_TRUNCATED, standard meanings
1853 static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
1854 const char *name, uint64_t val)
1856 fdt64_t tmp = cpu_to_fdt64(val);
1857 return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1861 * fdt_appendprop_cell - append a single cell value to a property
1863 * This is an alternative name for fdt_appendprop_u32()
1865 static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
1866 const char *name, uint32_t val)
1868 return fdt_appendprop_u32(fdt, nodeoffset, name, val);
1872 * fdt_appendprop_string - append a string to a property
1873 * @fdt: pointer to the device tree blob
1874 * @nodeoffset: offset of the node whose property to change
1875 * @name: name of the property to change
1876 * @str: string value to append to the property
1878 * fdt_appendprop_string() appends the given string to the value of
1879 * the named property in the given node, or creates a new property
1880 * with that value if it does not already exist.
1882 * This function may insert data into the blob, and will therefore
1883 * change the offsets of some existing nodes.
1887 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1888 * contain the new property value
1889 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1890 * -FDT_ERR_BADLAYOUT,
1891 * -FDT_ERR_BADMAGIC,
1892 * -FDT_ERR_BADVERSION,
1893 * -FDT_ERR_BADSTATE,
1894 * -FDT_ERR_BADSTRUCTURE,
1895 * -FDT_ERR_BADLAYOUT,
1896 * -FDT_ERR_TRUNCATED, standard meanings
1898 #define fdt_appendprop_string(fdt, nodeoffset, name, str) \
1899 fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
1902 * fdt_appendprop_addrrange - append a address range property
1903 * @fdt: pointer to the device tree blob
1904 * @parent: offset of the parent node
1905 * @nodeoffset: offset of the node to add a property at
1906 * @name: name of property
1907 * @addr: start address of a given range
1908 * @size: size of a given range
1910 * fdt_appendprop_addrrange() appends an address range value (start
1911 * address and size) to the value of the named property in the given
1912 * node, or creates a new property with that value if it does not
1914 * If "name" is not specified, a default "reg" is used.
1915 * Cell sizes are determined by parent's #address-cells and #size-cells.
1917 * This function may insert data into the blob, and will therefore
1918 * change the offsets of some existing nodes.
1922 * -FDT_ERR_BADLAYOUT,
1923 * -FDT_ERR_BADMAGIC,
1924 * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
1925 * #address-cells property
1926 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1927 * -FDT_ERR_BADSTATE,
1928 * -FDT_ERR_BADSTRUCTURE,
1929 * -FDT_ERR_BADVERSION,
1930 * -FDT_ERR_BADVALUE, addr or size doesn't fit to respective cells size
1931 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1932 * contain a new property
1933 * -FDT_ERR_TRUNCATED, standard meanings
1935 int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,
1936 const char *name, uint64_t addr, uint64_t size);
1939 * fdt_delprop - delete a property
1940 * @fdt: pointer to the device tree blob
1941 * @nodeoffset: offset of the node whose property to nop
1942 * @name: name of the property to nop
1944 * fdt_del_property() will delete the given property.
1946 * This function will delete data from the blob, and will therefore
1947 * change the offsets of some existing nodes.
1951 * -FDT_ERR_NOTFOUND, node does not have the named property
1952 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1953 * -FDT_ERR_BADLAYOUT,
1954 * -FDT_ERR_BADMAGIC,
1955 * -FDT_ERR_BADVERSION,
1956 * -FDT_ERR_BADSTATE,
1957 * -FDT_ERR_BADSTRUCTURE,
1958 * -FDT_ERR_TRUNCATED, standard meanings
1960 int fdt_delprop(void *fdt, int nodeoffset, const char *name);
1963 * fdt_add_subnode_namelen - creates a new node based on substring
1964 * @fdt: pointer to the device tree blob
1965 * @parentoffset: structure block offset of a node
1966 * @name: name of the subnode to locate
1967 * @namelen: number of characters of name to consider
1969 * Identical to fdt_add_subnode(), but use only the first namelen
1970 * characters of name as the name of the new node. This is useful for
1971 * creating subnodes based on a portion of a larger string, such as a
1974 #ifndef SWIG /* Not available in Python */
1975 int fdt_add_subnode_namelen(void *fdt, int parentoffset,
1976 const char *name, int namelen);
1980 * fdt_add_subnode - creates a new node
1981 * @fdt: pointer to the device tree blob
1982 * @parentoffset: structure block offset of a node
1983 * @name: name of the subnode to locate
1985 * fdt_add_subnode() creates a new node as a subnode of the node at
1986 * structure block offset parentoffset, with the given name (which
1987 * should include the unit address, if any).
1989 * This function will insert data into the blob, and will therefore
1990 * change the offsets of some existing nodes.
1993 * structure block offset of the created nodeequested subnode (>=0), on
1995 * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
1996 * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
1998 * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
2000 * -FDT_ERR_NOSPACE, if there is insufficient free space in the
2001 * blob to contain the new node
2003 * -FDT_ERR_BADLAYOUT
2004 * -FDT_ERR_BADMAGIC,
2005 * -FDT_ERR_BADVERSION,
2006 * -FDT_ERR_BADSTATE,
2007 * -FDT_ERR_BADSTRUCTURE,
2008 * -FDT_ERR_TRUNCATED, standard meanings.
2010 int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
2013 * fdt_del_node - delete a node (subtree)
2014 * @fdt: pointer to the device tree blob
2015 * @nodeoffset: offset of the node to nop
2017 * fdt_del_node() will remove the given node, including all its
2018 * subnodes if any, from the blob.
2020 * This function will delete data from the blob, and will therefore
2021 * change the offsets of some existing nodes.
2025 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
2026 * -FDT_ERR_BADLAYOUT,
2027 * -FDT_ERR_BADMAGIC,
2028 * -FDT_ERR_BADVERSION,
2029 * -FDT_ERR_BADSTATE,
2030 * -FDT_ERR_BADSTRUCTURE,
2031 * -FDT_ERR_TRUNCATED, standard meanings
2033 int fdt_del_node(void *fdt, int nodeoffset);
2036 * fdt_overlay_apply - Applies a DT overlay on a base DT
2037 * @fdt: pointer to the base device tree blob
2038 * @fdto: pointer to the device tree overlay blob
2040 * fdt_overlay_apply() will apply the given device tree overlay on the
2041 * given base device tree.
2043 * Expect the base device tree to be modified, even if the function
2048 * -FDT_ERR_NOSPACE, there's not enough space in the base device tree
2049 * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or
2050 * properties in the base DT
2051 * -FDT_ERR_BADPHANDLE,
2052 * -FDT_ERR_BADOVERLAY,
2053 * -FDT_ERR_NOPHANDLES,
2054 * -FDT_ERR_INTERNAL,
2055 * -FDT_ERR_BADLAYOUT,
2056 * -FDT_ERR_BADMAGIC,
2057 * -FDT_ERR_BADOFFSET,
2059 * -FDT_ERR_BADVERSION,
2060 * -FDT_ERR_BADSTRUCTURE,
2061 * -FDT_ERR_BADSTATE,
2062 * -FDT_ERR_TRUNCATED, standard meanings
2064 int fdt_overlay_apply(void *fdt, void *fdto);
2066 /**********************************************************************/
2067 /* Debugging / informational functions */
2068 /**********************************************************************/
2070 const char *fdt_strerror(int errval);
2072 #endif /* LIBFDT_H */