]>
git.proxmox.com Git - mirror_edk2.git/blob - EmbeddedPkg/Include/libfdt.h
5 * libfdt - Flat Device Tree manipulation
6 * Copyright (C) 2006 David Gibson, IBM Corporation.
8 * libfdt is dual licensed: you can use it either under the terms of
9 * the GPL, or the BSD license, at your option.
11 * a) This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of the
14 * License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public
22 * License along with this library; if not, write to the Free
23 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
28 * b) Redistribution and use in source and binary forms, with or
29 * without modification, are permitted provided that the following
32 * 1. Redistributions of source code must retain the above
33 * copyright notice, this list of conditions and the following
35 * 2. Redistributions in binary form must reproduce the above
36 * copyright notice, this list of conditions and the following
37 * disclaimer in the documentation and/or other materials
38 * provided with the distribution.
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
41 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
42 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
43 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
45 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
50 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
51 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
52 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 #include <libfdt_env.h>
58 #define FDT_FIRST_SUPPORTED_VERSION 0x10
59 #define FDT_LAST_SUPPORTED_VERSION 0x11
61 /* Error codes: informative error codes */
62 #define FDT_ERR_NOTFOUND 1
63 /* FDT_ERR_NOTFOUND: The requested node or property does not exist */
64 #define FDT_ERR_EXISTS 2
66 /* FDT_ERR_EXISTS: Attempted to create a node or property which
68 #define FDT_ERR_NOSPACE 3
70 /* FDT_ERR_NOSPACE: Operation needed to expand the device
71 * tree, but its buffer did not have sufficient space to
72 * contain the expanded tree. Use fdt_open_into() to move the
73 * device tree to a buffer with more space. */
75 /* Error codes: codes for bad parameters */
76 #define FDT_ERR_BADOFFSET 4
78 /* FDT_ERR_BADOFFSET: Function was passed a structure block
79 * offset which is out-of-bounds, or which points to an
80 * unsuitable part of the structure for the operation. */
81 #define FDT_ERR_BADPATH 5
83 /* FDT_ERR_BADPATH: Function was passed a badly formatted path
84 * (e.g. missing a leading / for a function which requires an
86 #define FDT_ERR_BADPHANDLE 6
88 /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.
89 * This can be caused either by an invalid phandle property
90 * length, or the phandle value was either 0 or -1, which are
92 #define FDT_ERR_BADSTATE 7
94 /* FDT_ERR_BADSTATE: Function was passed an incomplete device
95 * tree created by the sequential-write functions, which is
96 * not sufficiently complete for the requested operation. */
98 /* Error codes: codes for bad device tree blobs */
99 #define FDT_ERR_TRUNCATED 8
101 /* FDT_ERR_TRUNCATED: Structure block of the given device tree
102 * ends without an FDT_END tag. */
103 #define FDT_ERR_BADMAGIC 9
105 /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
106 * device tree at all - it is missing the flattened device
107 * tree magic number. */
108 #define FDT_ERR_BADVERSION 10
110 /* FDT_ERR_BADVERSION: Given device tree has a version which
111 * can't be handled by the requested operation. For
112 * read-write functions, this may mean that fdt_open_into() is
113 * required to convert the tree to the expected version. */
114 #define FDT_ERR_BADSTRUCTURE 11
116 /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
117 * structure block or other serious error (e.g. misnested
118 * nodes, or subnodes preceding properties). */
119 #define FDT_ERR_BADLAYOUT 12
121 /* FDT_ERR_BADLAYOUT: For read-write functions, the given
122 * device tree has it's sub-blocks in an order that the
123 * function can't handle (memory reserve map, then structure,
124 * then strings). Use fdt_open_into() to reorganize the tree
125 * into a form suitable for the read-write operations. */
127 /* "Can't happen" error indicating a bug in libfdt */
128 #define FDT_ERR_INTERNAL 13
130 /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
131 * Should never be returned, if it is, it indicates a bug in
134 /* Errors in device tree content */
135 #define FDT_ERR_BADNCELLS 14
137 /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
138 * or similar property with a bad format or value */
140 #define FDT_ERR_BADVALUE 15
142 /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
143 * value. For example: a property expected to contain a string list
144 * is not NUL-terminated within the length of its value. */
146 #define FDT_ERR_BADOVERLAY 16
148 /* FDT_ERR_BADOVERLAY: The device tree overlay, while
149 * correctly structured, cannot be applied due to some
150 * unexpected or missing value, property or node. */
152 #define FDT_ERR_NOPHANDLES 17
154 /* FDT_ERR_NOPHANDLES: The device tree doesn't have any
155 * phandle available anymore without causing an overflow */
157 #define FDT_ERR_MAX 17
159 /**********************************************************************/
160 /* Low-level functions (you probably don't need these) */
161 /**********************************************************************/
163 #ifndef SWIG /* This function is not useful in Python */
168 unsigned int checklen
179 return (void *)(uintptr_t)fdt_offset_ptr (fdt
, offset
, checklen
);
189 /**********************************************************************/
190 /* Traversal functions */
191 /**********************************************************************/
201 * fdt_first_subnode() - get offset of first direct subnode
204 * @offset: Offset of node to check
205 * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
214 * fdt_next_subnode() - get offset of next direct subnode
216 * After first calling fdt_first_subnode(), call this function repeatedly to
217 * get direct subnodes of a parent node.
220 * @offset: Offset of previous subnode
221 * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
231 * fdt_for_each_subnode - iterate over all subnodes of a parent
233 * @node: child node (int, lvalue)
234 * @fdt: FDT blob (const void *)
235 * @parent: parent node (int)
237 * This is actually a wrapper around a for loop and would be used like so:
239 * fdt_for_each_subnode(node, fdt, parent) {
244 * if ((node < 0) && (node != -FDT_ERR_NOT_FOUND)) {
248 * Note that this is implemented as a macro and @node is used as
249 * iterator in the loop. The parent variable be constant or even a
253 #define fdt_for_each_subnode(node, fdt, parent) \
254 for (node = fdt_first_subnode(fdt, parent); \
256 node = fdt_next_subnode(fdt, node))
258 /**********************************************************************/
259 /* General functions */
260 /**********************************************************************/
261 #define fdt_get_header(fdt, field) \
262 (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
263 #define fdt_magic(fdt) (fdt_get_header(fdt, magic))
264 #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
265 #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
266 #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
267 #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
268 #define fdt_version(fdt) (fdt_get_header(fdt, version))
269 #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
270 #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
271 #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
272 #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
274 #define __fdt_set_hdr(name) \
275 static inline void fdt_set_##name(void *fdt, uint32_t val) \
277 struct fdt_header *fdth = (struct fdt_header *)fdt; \
278 fdth->name = cpu_to_fdt32(val); \
280 __fdt_set_hdr (magic
);
281 __fdt_set_hdr (totalsize
);
282 __fdt_set_hdr (off_dt_struct
);
283 __fdt_set_hdr (off_dt_strings
);
284 __fdt_set_hdr (off_mem_rsvmap
);
285 __fdt_set_hdr (version
);
286 __fdt_set_hdr (last_comp_version
);
287 __fdt_set_hdr (boot_cpuid_phys
);
288 __fdt_set_hdr (size_dt_strings
);
289 __fdt_set_hdr (size_dt_struct
);
293 * fdt_check_header - sanity check a device tree or possible device tree
294 * @fdt: pointer to data which might be a flattened device tree
296 * fdt_check_header() checks that the given buffer contains what
297 * appears to be a flattened device tree with sane information in its
301 * 0, if the buffer appears to contain a valid device tree
303 * -FDT_ERR_BADVERSION,
304 * -FDT_ERR_BADSTATE, standard meanings, as above
312 * fdt_move - move a device tree around in memory
313 * @fdt: pointer to the device tree to move
314 * @buf: pointer to memory where the device is to be moved
315 * @bufsize: size of the memory space at buf
317 * fdt_move() relocates, if possible, the device tree blob located at
318 * fdt to the buffer at buf of size bufsize. The buffer may overlap
319 * with the existing device tree blob at fdt. Therefore,
320 * fdt_move(fdt, fdt, fdt_totalsize(fdt))
321 * should always succeed.
325 * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
327 * -FDT_ERR_BADVERSION,
328 * -FDT_ERR_BADSTATE, standard meanings
337 /**********************************************************************/
338 /* Read-only functions */
339 /**********************************************************************/
342 * fdt_string - retrieve a string from the strings block of a device tree
343 * @fdt: pointer to the device tree blob
344 * @stroffset: offset of the string within the strings block (native endian)
346 * fdt_string() retrieves a pointer to a single string from the
347 * strings block of the device tree blob at fdt.
350 * a pointer to the string, on success
351 * NULL, if stroffset is out of bounds
360 * fdt_get_max_phandle - retrieves the highest phandle in a tree
361 * @fdt: pointer to the device tree blob
363 * fdt_get_max_phandle retrieves the highest phandle in the given
364 * device tree. This will ignore badly formatted phandles, or phandles
365 * with a value of 0 or -1.
368 * the highest phandle on success
369 * 0, if no phandle was found in the device tree
370 * -1, if an error occurred
373 fdt_get_max_phandle (
378 * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
379 * @fdt: pointer to the device tree blob
381 * Returns the number of entries in the device tree blob's memory
382 * reservation map. This does not include the terminating 0,0 entry
383 * or any other (0,0) entries reserved for expansion.
386 * the number of entries
394 * fdt_get_mem_rsv - retrieve one memory reserve map entry
395 * @fdt: pointer to the device tree blob
396 * @address, @size: pointers to 64-bit variables
398 * On success, *address and *size will contain the address and size of
399 * the n-th reserve map entry from the device tree blob, in
400 * native-endian format.
405 * -FDT_ERR_BADVERSION,
406 * -FDT_ERR_BADSTATE, standard meanings
417 * fdt_subnode_offset_namelen - find a subnode based on substring
418 * @fdt: pointer to the device tree blob
419 * @parentoffset: structure block offset of a node
420 * @name: name of the subnode to locate
421 * @namelen: number of characters of name to consider
423 * Identical to fdt_subnode_offset(), but only examine the first
424 * namelen characters of name for matching the subnode name. This is
425 * useful for finding subnodes based on a portion of a larger string,
426 * such as a full path.
428 #ifndef SWIG /* Not available in Python */
430 fdt_subnode_offset_namelen (
440 * fdt_subnode_offset - find a subnode of a given node
441 * @fdt: pointer to the device tree blob
442 * @parentoffset: structure block offset of a node
443 * @name: name of the subnode to locate
445 * fdt_subnode_offset() finds a subnode of the node at structure block
446 * offset parentoffset with the given name. name may include a unit
447 * address, in which case fdt_subnode_offset() will find the subnode
448 * with that unit address, or the unit address may be omitted, in
449 * which case fdt_subnode_offset() will find an arbitrary subnode
450 * whose name excluding unit address matches the given name.
453 * structure block offset of the requested subnode (>=0), on success
454 * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
455 * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
458 * -FDT_ERR_BADVERSION,
460 * -FDT_ERR_BADSTRUCTURE,
461 * -FDT_ERR_TRUNCATED, standard meanings.
471 * fdt_path_offset_namelen - find a tree node by its full path
472 * @fdt: pointer to the device tree blob
473 * @path: full path of the node to locate
474 * @namelen: number of characters of path to consider
476 * Identical to fdt_path_offset(), but only consider the first namelen
477 * characters of path as the path name.
479 #ifndef SWIG /* Not available in Python */
481 fdt_path_offset_namelen (
490 * fdt_path_offset - find a tree node by its full path
491 * @fdt: pointer to the device tree blob
492 * @path: full path of the node to locate
494 * fdt_path_offset() finds a node of a given path in the device tree.
495 * Each path component may omit the unit address portion, but the
496 * results of this are undefined if any such path component is
497 * ambiguous (that is if there are multiple nodes at the relevant
498 * level matching the given component, differentiated only by unit
502 * structure block offset of the node with the requested path (>=0), on
504 * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
505 * -FDT_ERR_NOTFOUND, if the requested node does not exist
507 * -FDT_ERR_BADVERSION,
509 * -FDT_ERR_BADSTRUCTURE,
510 * -FDT_ERR_TRUNCATED, standard meanings.
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
549 * fdt_first_property_offset - find the offset of a node's first property
550 * @fdt: pointer to the device tree blob
551 * @nodeoffset: structure block offset of a node
553 * fdt_first_property_offset() finds the first property of the node at
554 * the given structure block offset.
557 * structure block offset of the property (>=0), on success
558 * -FDT_ERR_NOTFOUND, if the requested node has no properties
559 * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
561 * -FDT_ERR_BADVERSION,
563 * -FDT_ERR_BADSTRUCTURE,
564 * -FDT_ERR_TRUNCATED, standard meanings.
567 fdt_first_property_offset (
573 * fdt_next_property_offset - step through a node's properties
574 * @fdt: pointer to the device tree blob
575 * @offset: structure block offset of a property
577 * fdt_next_property_offset() finds the property immediately after the
578 * one at the given structure block offset. This will be a property
579 * of the same node as the given property.
582 * structure block offset of the next property (>=0), on success
583 * -FDT_ERR_NOTFOUND, if the given property is the last in its node
584 * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
586 * -FDT_ERR_BADVERSION,
588 * -FDT_ERR_BADSTRUCTURE,
589 * -FDT_ERR_TRUNCATED, standard meanings.
592 fdt_next_property_offset (
598 * fdt_for_each_property_offset - iterate over all properties of a node
600 * @property_offset: property offset (int, lvalue)
601 * @fdt: FDT blob (const void *)
602 * @node: node offset (int)
604 * This is actually a wrapper around a for loop and would be used like so:
606 * fdt_for_each_property_offset(property, fdt, node) {
611 * if ((property < 0) && (property != -FDT_ERR_NOT_FOUND)) {
615 * Note that this is implemented as a macro and property is used as
616 * iterator in the loop. The node variable can be constant or even a
619 #define fdt_for_each_property_offset(property, fdt, node) \
620 for (property = fdt_first_property_offset(fdt, node); \
622 property = fdt_next_property_offset(fdt, property))
625 * fdt_get_property_by_offset - retrieve the property at a given offset
626 * @fdt: pointer to the device tree blob
627 * @offset: offset of the property to retrieve
628 * @lenp: pointer to an integer variable (will be overwritten) or NULL
630 * fdt_get_property_by_offset() retrieves a pointer to the
631 * fdt_property structure within the device tree blob at the given
632 * offset. If lenp is non-NULL, the length of the property value is
633 * also returned, in the integer pointed to by lenp.
636 * pointer to the structure representing the property
637 * if lenp is non-NULL, *lenp contains the length of the property
640 * if lenp is non-NULL, *lenp contains an error code (<0):
641 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
643 * -FDT_ERR_BADVERSION,
645 * -FDT_ERR_BADSTRUCTURE,
646 * -FDT_ERR_TRUNCATED, standard meanings
648 const struct fdt_property
*
649 fdt_get_property_by_offset (
656 * fdt_get_property_namelen - find a property based on substring
657 * @fdt: pointer to the device tree blob
658 * @nodeoffset: offset of the node whose property to find
659 * @name: name of the property to find
660 * @namelen: number of characters of name to consider
661 * @lenp: pointer to an integer variable (will be overwritten) or NULL
663 * Identical to fdt_get_property(), but only examine the first namelen
664 * characters of name for matching the property name.
666 #ifndef SWIG /* Not available in Python */
667 const struct fdt_property
*
668 fdt_get_property_namelen (
679 * fdt_get_property - find a given property in a given node
680 * @fdt: pointer to the device tree blob
681 * @nodeoffset: offset of the node whose property to find
682 * @name: name of the property to find
683 * @lenp: pointer to an integer variable (will be overwritten) or NULL
685 * fdt_get_property() retrieves a pointer to the fdt_property
686 * structure within the device tree blob corresponding to the property
687 * named 'name' of the node at offset nodeoffset. If lenp is
688 * non-NULL, the length of the property value is also returned, in the
689 * integer pointed to by lenp.
692 * pointer to the structure representing the property
693 * if lenp is non-NULL, *lenp contains the length of the property
696 * if lenp is non-NULL, *lenp contains an error code (<0):
697 * -FDT_ERR_NOTFOUND, node does not have named property
698 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
701 * -FDT_ERR_BADVERSION,
703 * -FDT_ERR_BADSTRUCTURE,
704 * -FDT_ERR_TRUNCATED, standard meanings
706 const struct fdt_property
*
714 static inline struct fdt_property
*
722 return (struct fdt_property
*)(uintptr_t)
723 fdt_get_property (fdt
, nodeoffset
, name
, lenp
);
727 * fdt_getprop_by_offset - retrieve the value of a property at a given offset
728 * @fdt: pointer to the device tree blob
729 * @ffset: offset of the property to read
730 * @namep: pointer to a string variable (will be overwritten) or NULL
731 * @lenp: pointer to an integer variable (will be overwritten) or NULL
733 * fdt_getprop_by_offset() retrieves a pointer to the value of the
734 * property at structure block offset 'offset' (this will be a pointer
735 * to within the device blob itself, not a copy of the value). If
736 * lenp is non-NULL, the length of the property value is also
737 * returned, in the integer pointed to by lenp. If namep is non-NULL,
738 * the property's namne will also be returned in the char * pointed to
739 * by namep (this will be a pointer to within the device tree's string
740 * block, not a new copy of the name).
743 * pointer to the property's value
744 * if lenp is non-NULL, *lenp contains the length of the property
746 * if namep is non-NULL *namep contiains a pointer to the property
749 * if lenp is non-NULL, *lenp contains an error code (<0):
750 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
752 * -FDT_ERR_BADVERSION,
754 * -FDT_ERR_BADSTRUCTURE,
755 * -FDT_ERR_TRUNCATED, standard meanings
757 #ifndef SWIG /* This function is not useful in Python */
759 fdt_getprop_by_offset (
769 * fdt_getprop_namelen - get property value based on substring
770 * @fdt: pointer to the device tree blob
771 * @nodeoffset: offset of the node whose property to find
772 * @name: name of the property to find
773 * @namelen: number of characters of name to consider
774 * @lenp: pointer to an integer variable (will be overwritten) or NULL
776 * Identical to fdt_getprop(), but only examine the first namelen
777 * characters of name for matching the property name.
779 #ifndef SWIG /* Not available in Python */
781 fdt_getprop_namelen (
790 fdt_getprop_namelen_w (
798 return (void *)(uintptr_t)fdt_getprop_namelen (
810 * fdt_getprop - retrieve the value of a given property
811 * @fdt: pointer to the device tree blob
812 * @nodeoffset: offset of the node whose property to find
813 * @name: name of the property to find
814 * @lenp: pointer to an integer variable (will be overwritten) or NULL
816 * fdt_getprop() retrieves a pointer to the value of the property
817 * named 'name' of the node at offset nodeoffset (this will be a
818 * pointer to within the device blob itself, not a copy of the value).
819 * If lenp is non-NULL, the length of the property value is also
820 * returned, in the integer pointed to by lenp.
823 * pointer to the property's value
824 * if lenp is non-NULL, *lenp contains the length of the property
827 * if lenp is non-NULL, *lenp contains an error code (<0):
828 * -FDT_ERR_NOTFOUND, node does not have named property
829 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
832 * -FDT_ERR_BADVERSION,
834 * -FDT_ERR_BADSTRUCTURE,
835 * -FDT_ERR_TRUNCATED, standard meanings
853 return (void *)(uintptr_t)fdt_getprop (fdt
, nodeoffset
, name
, lenp
);
857 * fdt_get_phandle - retrieve the phandle of a given node
858 * @fdt: pointer to the device tree blob
859 * @nodeoffset: structure block offset of the node
861 * fdt_get_phandle() retrieves the phandle of the device tree node at
862 * structure block offset nodeoffset.
865 * the phandle of the node at nodeoffset, on success (!= 0, != -1)
866 * 0, if the node has no phandle, or another error occurs
875 * fdt_get_alias_namelen - get alias based on substring
876 * @fdt: pointer to the device tree blob
877 * @name: name of the alias th look up
878 * @namelen: number of characters of name to consider
880 * Identical to fdt_get_alias(), but only examine the first namelen
881 * characters of name for matching the alias name.
883 #ifndef SWIG /* Not available in Python */
885 fdt_get_alias_namelen (
894 * fdt_get_alias - retrieve the path referenced by a given alias
895 * @fdt: pointer to the device tree blob
896 * @name: name of the alias th look up
898 * fdt_get_alias() retrieves the value of a given alias. That is, the
899 * value of the property named 'name' in the node /aliases.
902 * a pointer to the expansion of the alias named 'name', if it exists
903 * NULL, if the given alias or the /aliases node does not exist
912 * fdt_get_path - determine the full path of a node
913 * @fdt: pointer to the device tree blob
914 * @nodeoffset: offset of the node whose path to find
915 * @buf: character buffer to contain the returned path (will be overwritten)
916 * @buflen: size of the character buffer at buf
918 * fdt_get_path() computes the full path of the node at offset
919 * nodeoffset, and records that path in the buffer at buf.
921 * NOTE: This function is expensive, as it must scan the device tree
922 * structure from the start to nodeoffset.
926 * buf contains the absolute path of the node at
927 * nodeoffset, as a NUL-terminated string.
928 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
929 * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
930 * characters and will not fit in the given buffer.
932 * -FDT_ERR_BADVERSION,
934 * -FDT_ERR_BADSTRUCTURE, standard meanings
945 * fdt_supernode_atdepth_offset - find a specific ancestor of a node
946 * @fdt: pointer to the device tree blob
947 * @nodeoffset: offset of the node whose parent to find
948 * @supernodedepth: depth of the ancestor to find
949 * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
951 * fdt_supernode_atdepth_offset() finds an ancestor of the given node
952 * at a specific depth from the root (where the root itself has depth
953 * 0, its immediate subnodes depth 1 and so forth). So
954 * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
955 * will always return 0, the offset of the root node. If the node at
956 * nodeoffset has depth D, then:
957 * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
958 * will return nodeoffset itself.
960 * NOTE: This function is expensive, as it must scan the device tree
961 * structure from the start to nodeoffset.
964 * structure block offset of the node at node offset's ancestor
965 * of depth supernodedepth (>=0), on success
966 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
967 * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of
970 * -FDT_ERR_BADVERSION,
972 * -FDT_ERR_BADSTRUCTURE, standard meanings
975 fdt_supernode_atdepth_offset (
983 * fdt_node_depth - find the depth of a given node
984 * @fdt: pointer to the device tree blob
985 * @nodeoffset: offset of the node whose parent to find
987 * fdt_node_depth() finds the depth of a given node. The root node
988 * has depth 0, its immediate subnodes depth 1 and so forth.
990 * NOTE: This function is expensive, as it must scan the device tree
991 * structure from the start to nodeoffset.
994 * depth of the node at nodeoffset (>=0), on success
995 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
997 * -FDT_ERR_BADVERSION,
999 * -FDT_ERR_BADSTRUCTURE, standard meanings
1008 * fdt_parent_offset - find the parent of a given node
1009 * @fdt: pointer to the device tree blob
1010 * @nodeoffset: offset of the node whose parent to find
1012 * fdt_parent_offset() locates the parent node of a given node (that
1013 * is, it finds the offset of the node which contains the node at
1014 * nodeoffset as a subnode).
1016 * NOTE: This function is expensive, as it must scan the device tree
1017 * structure from the start to nodeoffset, *twice*.
1020 * structure block offset of the parent of the node at nodeoffset
1022 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
1023 * -FDT_ERR_BADMAGIC,
1024 * -FDT_ERR_BADVERSION,
1025 * -FDT_ERR_BADSTATE,
1026 * -FDT_ERR_BADSTRUCTURE, standard meanings
1035 * fdt_node_offset_by_prop_value - find nodes with a given property value
1036 * @fdt: pointer to the device tree blob
1037 * @startoffset: only find nodes after this offset
1038 * @propname: property name to check
1039 * @propval: property value to search for
1040 * @proplen: length of the value in propval
1042 * fdt_node_offset_by_prop_value() returns the offset of the first
1043 * node after startoffset, which has a property named propname whose
1044 * value is of length proplen and has value equal to propval; or if
1045 * startoffset is -1, the very first such node in the tree.
1047 * To iterate through all nodes matching the criterion, the following
1048 * idiom can be used:
1049 * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
1050 * propval, proplen);
1051 * while (offset != -FDT_ERR_NOTFOUND) {
1052 * // other code here
1053 * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
1054 * propval, proplen);
1057 * Note the -1 in the first call to the function, if 0 is used here
1058 * instead, the function will never locate the root node, even if it
1059 * matches the criterion.
1062 * structure block offset of the located node (>= 0, >startoffset),
1064 * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
1065 * tree after startoffset
1066 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
1067 * -FDT_ERR_BADMAGIC,
1068 * -FDT_ERR_BADVERSION,
1069 * -FDT_ERR_BADSTATE,
1070 * -FDT_ERR_BADSTRUCTURE, standard meanings
1073 fdt_node_offset_by_prop_value (
1076 const char *propname
,
1077 const void *propval
,
1082 * fdt_node_offset_by_phandle - find the node with a given phandle
1083 * @fdt: pointer to the device tree blob
1084 * @phandle: phandle value
1086 * fdt_node_offset_by_phandle() returns the offset of the node
1087 * which has the given phandle value. If there is more than one node
1088 * in the tree with the given phandle (an invalid tree), results are
1092 * structure block offset of the located node (>= 0), on success
1093 * -FDT_ERR_NOTFOUND, no node with that phandle exists
1094 * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
1095 * -FDT_ERR_BADMAGIC,
1096 * -FDT_ERR_BADVERSION,
1097 * -FDT_ERR_BADSTATE,
1098 * -FDT_ERR_BADSTRUCTURE, standard meanings
1101 fdt_node_offset_by_phandle (
1107 * fdt_node_check_compatible: check a node's compatible property
1108 * @fdt: pointer to the device tree blob
1109 * @nodeoffset: offset of a tree node
1110 * @compatible: string to match against
1113 * fdt_node_check_compatible() returns 0 if the given node contains a
1114 * 'compatible' property with the given string as one of its elements,
1115 * it returns non-zero otherwise, or on error.
1118 * 0, if the node has a 'compatible' property listing the given string
1119 * 1, if the node has a 'compatible' property, but it does not list
1121 * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
1122 * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
1123 * -FDT_ERR_BADMAGIC,
1124 * -FDT_ERR_BADVERSION,
1125 * -FDT_ERR_BADSTATE,
1126 * -FDT_ERR_BADSTRUCTURE, standard meanings
1129 fdt_node_check_compatible (
1132 const char *compatible
1136 * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
1137 * @fdt: pointer to the device tree blob
1138 * @startoffset: only find nodes after this offset
1139 * @compatible: 'compatible' string to match against
1141 * fdt_node_offset_by_compatible() returns the offset of the first
1142 * node after startoffset, which has a 'compatible' property which
1143 * lists the given compatible string; or if startoffset is -1, the
1144 * very first such node in the tree.
1146 * To iterate through all nodes matching the criterion, the following
1147 * idiom can be used:
1148 * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
1149 * while (offset != -FDT_ERR_NOTFOUND) {
1150 * // other code here
1151 * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
1154 * Note the -1 in the first call to the function, if 0 is used here
1155 * instead, the function will never locate the root node, even if it
1156 * matches the criterion.
1159 * structure block offset of the located node (>= 0, >startoffset),
1161 * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
1162 * tree after startoffset
1163 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
1164 * -FDT_ERR_BADMAGIC,
1165 * -FDT_ERR_BADVERSION,
1166 * -FDT_ERR_BADSTATE,
1167 * -FDT_ERR_BADSTRUCTURE, standard meanings
1170 fdt_node_offset_by_compatible (
1173 const char *compatible
1177 * fdt_stringlist_contains - check a string list property for a string
1178 * @strlist: Property containing a list of strings to check
1179 * @listlen: Length of property
1180 * @str: String to search for
1182 * This is a utility function provided for convenience. The list contains
1183 * one or more strings, each terminated by \0, as is found in a device tree
1184 * "compatible" property.
1186 * @return: 1 if the string is found in the list, 0 not found, or invalid list
1189 fdt_stringlist_contains (
1190 const char *strlist
,
1196 * fdt_stringlist_count - count the number of strings in a string list
1197 * @fdt: pointer to the device tree blob
1198 * @nodeoffset: offset of a tree node
1199 * @property: name of the property containing the string list
1201 * the number of strings in the given property
1202 * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
1203 * -FDT_ERR_NOTFOUND if the property does not exist
1206 fdt_stringlist_count (
1209 const char *property
1213 * fdt_stringlist_search - find a string in a string list and return its index
1214 * @fdt: pointer to the device tree blob
1215 * @nodeoffset: offset of a tree node
1216 * @property: name of the property containing the string list
1217 * @string: string to look up in the string list
1219 * Note that it is possible for this function to succeed on property values
1220 * that are not NUL-terminated. That's because the function will stop after
1221 * finding the first occurrence of @string. This can for example happen with
1222 * small-valued cell properties, such as #address-cells, when searching for
1226 * the index of the string in the list of strings
1227 * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
1228 * -FDT_ERR_NOTFOUND if the property does not exist or does not contain
1232 fdt_stringlist_search (
1235 const char *property
,
1240 * fdt_stringlist_get() - obtain the string at a given index in a string list
1241 * @fdt: pointer to the device tree blob
1242 * @nodeoffset: offset of a tree node
1243 * @property: name of the property containing the string list
1244 * @index: index of the string to return
1245 * @lenp: return location for the string length or an error code on failure
1247 * Note that this will successfully extract strings from properties with
1248 * non-NUL-terminated values. For example on small-valued cell properties
1249 * this function will return the empty string.
1251 * If non-NULL, the length of the string (on success) or a negative error-code
1252 * (on failure) will be stored in the integer pointer to by lenp.
1255 * A pointer to the string at the given index in the string list or NULL on
1256 * failure. On success the length of the string will be stored in the memory
1257 * location pointed to by the lenp parameter, if non-NULL. On failure one of
1258 * the following negative error codes will be returned in the lenp parameter
1260 * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
1261 * -FDT_ERR_NOTFOUND if the property does not exist
1264 fdt_stringlist_get (
1267 const char *property
,
1272 /**********************************************************************/
1273 /* Read-only functions (addressing related) */
1274 /**********************************************************************/
1277 * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
1279 * This is the maximum value for #address-cells, #size-cells and
1280 * similar properties that will be processed by libfdt. IEE1275
1281 * requires that OF implementations handle values up to 4.
1282 * Implementations may support larger values, but in practice higher
1283 * values aren't used.
1285 #define FDT_MAX_NCELLS 4
1288 * fdt_address_cells - retrieve address size for a bus represented in the tree
1289 * @fdt: pointer to the device tree blob
1290 * @nodeoffset: offset of the node to find the address size for
1292 * When the node has a valid #address-cells property, returns its value.
1295 * 0 <= n < FDT_MAX_NCELLS, on success
1296 * 2, if the node has no #address-cells property
1297 * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
1298 * #address-cells property
1299 * -FDT_ERR_BADMAGIC,
1300 * -FDT_ERR_BADVERSION,
1301 * -FDT_ERR_BADSTATE,
1302 * -FDT_ERR_BADSTRUCTURE,
1303 * -FDT_ERR_TRUNCATED, standard meanings
1312 * fdt_size_cells - retrieve address range size for a bus represented in the
1314 * @fdt: pointer to the device tree blob
1315 * @nodeoffset: offset of the node to find the address range size for
1317 * When the node has a valid #size-cells property, returns its value.
1320 * 0 <= n < FDT_MAX_NCELLS, on success
1321 * 2, if the node has no #address-cells property
1322 * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
1323 * #size-cells property
1324 * -FDT_ERR_BADMAGIC,
1325 * -FDT_ERR_BADVERSION,
1326 * -FDT_ERR_BADSTATE,
1327 * -FDT_ERR_BADSTRUCTURE,
1328 * -FDT_ERR_TRUNCATED, standard meanings
1336 /**********************************************************************/
1337 /* Write-in-place functions */
1338 /**********************************************************************/
1341 * fdt_setprop_inplace_namelen_partial - change a property's value,
1343 * @fdt: pointer to the device tree blob
1344 * @nodeoffset: offset of the node whose property to change
1345 * @name: name of the property to change
1346 * @namelen: number of characters of name to consider
1347 * @idx: index of the property to change in the array
1348 * @val: pointer to data to replace the property value with
1349 * @len: length of the property value
1351 * Identical to fdt_setprop_inplace(), but modifies the given property
1352 * starting from the given index, and using only the first characters
1353 * of the name. It is useful when you want to manipulate only one value of
1354 * an array and you have a string that doesn't end with \0.
1356 #ifndef SWIG /* Not available in Python */
1358 fdt_setprop_inplace_namelen_partial (
1371 * fdt_setprop_inplace - change a property's value, but not its size
1372 * @fdt: pointer to the device tree blob
1373 * @nodeoffset: offset of the node whose property to change
1374 * @name: name of the property to change
1375 * @val: pointer to data to replace the property value with
1376 * @len: length of the property value
1378 * fdt_setprop_inplace() replaces the value of a given property with
1379 * the data in val, of length len. This function cannot change the
1380 * size of a property, and so will only work if len is equal to the
1381 * current length of the property.
1383 * This function will alter only the bytes in the blob which contain
1384 * the given property value, and will not alter or move any other part
1389 * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
1390 * -FDT_ERR_NOTFOUND, node does not have the named property
1391 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1392 * -FDT_ERR_BADMAGIC,
1393 * -FDT_ERR_BADVERSION,
1394 * -FDT_ERR_BADSTATE,
1395 * -FDT_ERR_BADSTRUCTURE,
1396 * -FDT_ERR_TRUNCATED, standard meanings
1398 #ifndef SWIG /* Not available in Python */
1400 fdt_setprop_inplace (
1411 * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
1412 * @fdt: pointer to the device tree blob
1413 * @nodeoffset: offset of the node whose property to change
1414 * @name: name of the property to change
1415 * @val: 32-bit integer value to replace the property with
1417 * fdt_setprop_inplace_u32() replaces the value of a given property
1418 * with the 32-bit integer value in val, converting val to big-endian
1419 * if necessary. This function cannot change the size of a property,
1420 * and so will only work if the property already exists and has length
1423 * This function will alter only the bytes in the blob which contain
1424 * the given property value, and will not alter or move any other part
1429 * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
1430 * -FDT_ERR_NOTFOUND, node does not have the named property
1431 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1432 * -FDT_ERR_BADMAGIC,
1433 * -FDT_ERR_BADVERSION,
1434 * -FDT_ERR_BADSTATE,
1435 * -FDT_ERR_BADSTRUCTURE,
1436 * -FDT_ERR_TRUNCATED, standard meanings
1439 fdt_setprop_inplace_u32 (
1446 fdt32_t tmp
= cpu_to_fdt32 (val
);
1448 return fdt_setprop_inplace (fdt
, nodeoffset
, name
, &tmp
, sizeof (tmp
));
1452 * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
1453 * @fdt: pointer to the device tree blob
1454 * @nodeoffset: offset of the node whose property to change
1455 * @name: name of the property to change
1456 * @val: 64-bit integer value to replace the property with
1458 * fdt_setprop_inplace_u64() replaces the value of a given property
1459 * with the 64-bit integer value in val, converting val to big-endian
1460 * if necessary. This function cannot change the size of a property,
1461 * and so will only work if the property already exists and has length
1464 * This function will alter only the bytes in the blob which contain
1465 * the given property value, and will not alter or move any other part
1470 * -FDT_ERR_NOSPACE, if the property's length is not equal to 8
1471 * -FDT_ERR_NOTFOUND, node does not have the named property
1472 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1473 * -FDT_ERR_BADMAGIC,
1474 * -FDT_ERR_BADVERSION,
1475 * -FDT_ERR_BADSTATE,
1476 * -FDT_ERR_BADSTRUCTURE,
1477 * -FDT_ERR_TRUNCATED, standard meanings
1480 fdt_setprop_inplace_u64 (
1487 fdt64_t tmp
= cpu_to_fdt64 (val
);
1489 return fdt_setprop_inplace (fdt
, nodeoffset
, name
, &tmp
, sizeof (tmp
));
1493 * fdt_setprop_inplace_cell - change the value of a single-cell property
1495 * This is an alternative name for fdt_setprop_inplace_u32()
1498 fdt_setprop_inplace_cell (
1505 return fdt_setprop_inplace_u32 (fdt
, nodeoffset
, name
, val
);
1509 * fdt_nop_property - replace a property with nop tags
1510 * @fdt: pointer to the device tree blob
1511 * @nodeoffset: offset of the node whose property to nop
1512 * @name: name of the property to nop
1514 * fdt_nop_property() will replace a given property's representation
1515 * in the blob with FDT_NOP tags, effectively removing it from the
1518 * This function will alter only the bytes in the blob which contain
1519 * the property, and will not alter or move any other part of the
1524 * -FDT_ERR_NOTFOUND, node does not have the named property
1525 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1526 * -FDT_ERR_BADMAGIC,
1527 * -FDT_ERR_BADVERSION,
1528 * -FDT_ERR_BADSTATE,
1529 * -FDT_ERR_BADSTRUCTURE,
1530 * -FDT_ERR_TRUNCATED, standard meanings
1540 * fdt_nop_node - replace a node (subtree) with nop tags
1541 * @fdt: pointer to the device tree blob
1542 * @nodeoffset: offset of the node to nop
1544 * fdt_nop_node() will replace a given node's representation in the
1545 * blob, including all its subnodes, if any, with FDT_NOP tags,
1546 * effectively removing it from the tree.
1548 * This function will alter only the bytes in the blob which contain
1549 * the node and its properties and subnodes, and will not alter or
1550 * move any other part of the tree.
1554 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1555 * -FDT_ERR_BADMAGIC,
1556 * -FDT_ERR_BADVERSION,
1557 * -FDT_ERR_BADSTATE,
1558 * -FDT_ERR_BADSTRUCTURE,
1559 * -FDT_ERR_TRUNCATED, standard meanings
1567 /**********************************************************************/
1568 /* Sequential write functions */
1569 /**********************************************************************/
1585 fdt_add_reservemap_entry (
1592 fdt_finish_reservemap (
1617 fdt32_t tmp
= cpu_to_fdt32 (val
);
1619 return fdt_property (fdt
, name
, &tmp
, sizeof (tmp
));
1629 fdt64_t tmp
= cpu_to_fdt64 (val
);
1631 return fdt_property (fdt
, name
, &tmp
, sizeof (tmp
));
1641 return fdt_property_u32 (fdt
, name
, val
);
1645 * fdt_property_placeholder - add a new property and return a ptr to its value
1647 * @fdt: pointer to the device tree blob
1648 * @name: name of property to add
1649 * @len: length of property value in bytes
1650 * @valp: returns a pointer to where where the value should be placed
1654 * -FDT_ERR_BADMAGIC,
1655 * -FDT_ERR_NOSPACE, standard meanings
1658 fdt_property_placeholder (
1665 #define fdt_property_string(fdt, name, str) \
1666 fdt_property(fdt, name, str, strlen(str)+1)
1677 /**********************************************************************/
1678 /* Read-write functions */
1679 /**********************************************************************/
1682 fdt_create_empty_tree (
1700 * fdt_add_mem_rsv - add one memory reserve map entry
1701 * @fdt: pointer to the device tree blob
1702 * @address, @size: 64-bit values (native endian)
1704 * Adds a reserve map entry to the given blob reserving a region at
1705 * address address of length size.
1707 * This function will insert data into the reserve map and will
1708 * therefore change the indexes of some entries in the table.
1712 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1713 * contain the new reservation entry
1714 * -FDT_ERR_BADMAGIC,
1715 * -FDT_ERR_BADVERSION,
1716 * -FDT_ERR_BADSTATE,
1717 * -FDT_ERR_BADSTRUCTURE,
1718 * -FDT_ERR_BADLAYOUT,
1719 * -FDT_ERR_TRUNCATED, standard meanings
1729 * fdt_del_mem_rsv - remove a memory reserve map entry
1730 * @fdt: pointer to the device tree blob
1731 * @n: entry to remove
1733 * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
1736 * This function will delete data from the reservation table and will
1737 * therefore change the indexes of some entries in the table.
1741 * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
1742 * are less than n+1 reserve map entries)
1743 * -FDT_ERR_BADMAGIC,
1744 * -FDT_ERR_BADVERSION,
1745 * -FDT_ERR_BADSTATE,
1746 * -FDT_ERR_BADSTRUCTURE,
1747 * -FDT_ERR_BADLAYOUT,
1748 * -FDT_ERR_TRUNCATED, standard meanings
1757 * fdt_set_name - change the name of a given node
1758 * @fdt: pointer to the device tree blob
1759 * @nodeoffset: structure block offset of a node
1760 * @name: name to give the node
1762 * fdt_set_name() replaces the name (including unit address, if any)
1763 * of the given node with the given string. NOTE: this function can't
1764 * efficiently check if the new name is unique amongst the given
1765 * node's siblings; results are undefined if this function is invoked
1766 * with a name equal to one of the given node's siblings.
1768 * This function may insert or delete data from the blob, and will
1769 * therefore change the offsets of some existing nodes.
1773 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
1774 * to contain the new name
1775 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1776 * -FDT_ERR_BADMAGIC,
1777 * -FDT_ERR_BADVERSION,
1778 * -FDT_ERR_BADSTATE, standard meanings
1788 * fdt_setprop - create or change a property
1789 * @fdt: pointer to the device tree blob
1790 * @nodeoffset: offset of the node whose property to change
1791 * @name: name of the property to change
1792 * @val: pointer to data to set the property value to
1793 * @len: length of the property value
1795 * fdt_setprop() sets the value of the named property in the given
1796 * node to the given value and length, creating the property if it
1797 * does not already exist.
1799 * This function may insert or delete data from the blob, and will
1800 * therefore change the offsets of some existing nodes.
1804 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1805 * contain the new property value
1806 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1807 * -FDT_ERR_BADLAYOUT,
1808 * -FDT_ERR_BADMAGIC,
1809 * -FDT_ERR_BADVERSION,
1810 * -FDT_ERR_BADSTATE,
1811 * -FDT_ERR_BADSTRUCTURE,
1812 * -FDT_ERR_BADLAYOUT,
1813 * -FDT_ERR_TRUNCATED, standard meanings
1825 * fdt_setprop _placeholder - allocate space for a property
1826 * @fdt: pointer to the device tree blob
1827 * @nodeoffset: offset of the node whose property to change
1828 * @name: name of the property to change
1829 * @len: length of the property value
1830 * @prop_data: return pointer to property data
1832 * fdt_setprop_placeholer() allocates the named property in the given node.
1833 * If the property exists it is resized. In either case a pointer to the
1834 * property data is returned.
1836 * This function may insert or delete data from the blob, and will
1837 * therefore change the offsets of some existing nodes.
1841 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1842 * contain the new property value
1843 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1844 * -FDT_ERR_BADLAYOUT,
1845 * -FDT_ERR_BADMAGIC,
1846 * -FDT_ERR_BADVERSION,
1847 * -FDT_ERR_BADSTATE,
1848 * -FDT_ERR_BADSTRUCTURE,
1849 * -FDT_ERR_BADLAYOUT,
1850 * -FDT_ERR_TRUNCATED, standard meanings
1853 fdt_setprop_placeholder (
1862 * fdt_setprop_u32 - set a property to a 32-bit integer
1863 * @fdt: pointer to the device tree blob
1864 * @nodeoffset: offset of the node whose property to change
1865 * @name: name of the property to change
1866 * @val: 32-bit integer value for the property (native endian)
1868 * fdt_setprop_u32() sets the value of the named property in the given
1869 * node to the given 32-bit integer value (converting to big-endian if
1870 * necessary), or creates a new property with that value if it does
1871 * not already exist.
1873 * This function may insert or delete data from the blob, and will
1874 * therefore change the offsets of some existing nodes.
1878 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1879 * contain the new property value
1880 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1881 * -FDT_ERR_BADLAYOUT,
1882 * -FDT_ERR_BADMAGIC,
1883 * -FDT_ERR_BADVERSION,
1884 * -FDT_ERR_BADSTATE,
1885 * -FDT_ERR_BADSTRUCTURE,
1886 * -FDT_ERR_BADLAYOUT,
1887 * -FDT_ERR_TRUNCATED, standard meanings
1897 fdt32_t tmp
= cpu_to_fdt32 (val
);
1899 return fdt_setprop (fdt
, nodeoffset
, name
, &tmp
, sizeof (tmp
));
1903 * fdt_setprop_u64 - set a property to a 64-bit integer
1904 * @fdt: pointer to the device tree blob
1905 * @nodeoffset: offset of the node whose property to change
1906 * @name: name of the property to change
1907 * @val: 64-bit integer value for the property (native endian)
1909 * fdt_setprop_u64() sets the value of the named property in the given
1910 * node to the given 64-bit integer value (converting to big-endian if
1911 * necessary), or creates a new property with that value if it does
1912 * not already exist.
1914 * This function may insert or delete data from the blob, and will
1915 * therefore change the offsets of some existing nodes.
1919 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1920 * contain the new property value
1921 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1922 * -FDT_ERR_BADLAYOUT,
1923 * -FDT_ERR_BADMAGIC,
1924 * -FDT_ERR_BADVERSION,
1925 * -FDT_ERR_BADSTATE,
1926 * -FDT_ERR_BADSTRUCTURE,
1927 * -FDT_ERR_BADLAYOUT,
1928 * -FDT_ERR_TRUNCATED, standard meanings
1938 fdt64_t tmp
= cpu_to_fdt64 (val
);
1940 return fdt_setprop (fdt
, nodeoffset
, name
, &tmp
, sizeof (tmp
));
1944 * fdt_setprop_cell - set a property to a single cell value
1946 * This is an alternative name for fdt_setprop_u32()
1956 return fdt_setprop_u32 (fdt
, nodeoffset
, name
, val
);
1960 * fdt_setprop_string - set a property to a string value
1961 * @fdt: pointer to the device tree blob
1962 * @nodeoffset: offset of the node whose property to change
1963 * @name: name of the property to change
1964 * @str: string value for the property
1966 * fdt_setprop_string() sets the value of the named property in the
1967 * given node to the given string value (using the length of the
1968 * string to determine the new length of the property), or creates a
1969 * new property with that value if it does not already exist.
1971 * This function may insert or delete data from the blob, and will
1972 * therefore change the offsets of some existing nodes.
1976 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1977 * contain the new property value
1978 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1979 * -FDT_ERR_BADLAYOUT,
1980 * -FDT_ERR_BADMAGIC,
1981 * -FDT_ERR_BADVERSION,
1982 * -FDT_ERR_BADSTATE,
1983 * -FDT_ERR_BADSTRUCTURE,
1984 * -FDT_ERR_BADLAYOUT,
1985 * -FDT_ERR_TRUNCATED, standard meanings
1987 #define fdt_setprop_string(fdt, nodeoffset, name, str) \
1988 fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
1991 * fdt_setprop_empty - set a property to an empty value
1992 * @fdt: pointer to the device tree blob
1993 * @nodeoffset: offset of the node whose property to change
1994 * @name: name of the property to change
1996 * fdt_setprop_empty() sets the value of the named property in the
1997 * given node to an empty (zero length) value, or creates a new empty
1998 * property if it does not already exist.
2000 * This function may insert or delete data from the blob, and will
2001 * therefore change the offsets of some existing nodes.
2005 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
2006 * contain the new property value
2007 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
2008 * -FDT_ERR_BADLAYOUT,
2009 * -FDT_ERR_BADMAGIC,
2010 * -FDT_ERR_BADVERSION,
2011 * -FDT_ERR_BADSTATE,
2012 * -FDT_ERR_BADSTRUCTURE,
2013 * -FDT_ERR_BADLAYOUT,
2014 * -FDT_ERR_TRUNCATED, standard meanings
2016 #define fdt_setprop_empty(fdt, nodeoffset, name) \
2017 fdt_setprop((fdt), (nodeoffset), (name), NULL, 0)
2020 * fdt_appendprop - append to or create a property
2021 * @fdt: pointer to the device tree blob
2022 * @nodeoffset: offset of the node whose property to change
2023 * @name: name of the property to append to
2024 * @val: pointer to data to append to the property value
2025 * @len: length of the data to append to the property value
2027 * fdt_appendprop() appends the value to the named property in the
2028 * given node, creating the property if it does not already exist.
2030 * This function may insert data into the blob, and will therefore
2031 * change the offsets of some existing nodes.
2035 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
2036 * contain the new property value
2037 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
2038 * -FDT_ERR_BADLAYOUT,
2039 * -FDT_ERR_BADMAGIC,
2040 * -FDT_ERR_BADVERSION,
2041 * -FDT_ERR_BADSTATE,
2042 * -FDT_ERR_BADSTRUCTURE,
2043 * -FDT_ERR_BADLAYOUT,
2044 * -FDT_ERR_TRUNCATED, standard meanings
2056 * fdt_appendprop_u32 - append a 32-bit integer value to a property
2057 * @fdt: pointer to the device tree blob
2058 * @nodeoffset: offset of the node whose property to change
2059 * @name: name of the property to change
2060 * @val: 32-bit integer value to append to the property (native endian)
2062 * fdt_appendprop_u32() appends the given 32-bit integer value
2063 * (converting to big-endian if necessary) to the value of the named
2064 * property in the given node, or creates a new property with that
2065 * value if it does not already exist.
2067 * This function may insert data into the blob, and will therefore
2068 * change the offsets of some existing nodes.
2072 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
2073 * contain the new property value
2074 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
2075 * -FDT_ERR_BADLAYOUT,
2076 * -FDT_ERR_BADMAGIC,
2077 * -FDT_ERR_BADVERSION,
2078 * -FDT_ERR_BADSTATE,
2079 * -FDT_ERR_BADSTRUCTURE,
2080 * -FDT_ERR_BADLAYOUT,
2081 * -FDT_ERR_TRUNCATED, standard meanings
2084 fdt_appendprop_u32 (
2091 fdt32_t tmp
= cpu_to_fdt32 (val
);
2093 return fdt_appendprop (fdt
, nodeoffset
, name
, &tmp
, sizeof (tmp
));
2097 * fdt_appendprop_u64 - append a 64-bit integer value to a property
2098 * @fdt: pointer to the device tree blob
2099 * @nodeoffset: offset of the node whose property to change
2100 * @name: name of the property to change
2101 * @val: 64-bit integer value to append to the property (native endian)
2103 * fdt_appendprop_u64() appends the given 64-bit integer value
2104 * (converting to big-endian if necessary) to the value of the named
2105 * property in the given node, or creates a new property with that
2106 * value if it does not already exist.
2108 * This function may insert data into the blob, and will therefore
2109 * change the offsets of some existing nodes.
2113 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
2114 * contain the new property value
2115 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
2116 * -FDT_ERR_BADLAYOUT,
2117 * -FDT_ERR_BADMAGIC,
2118 * -FDT_ERR_BADVERSION,
2119 * -FDT_ERR_BADSTATE,
2120 * -FDT_ERR_BADSTRUCTURE,
2121 * -FDT_ERR_BADLAYOUT,
2122 * -FDT_ERR_TRUNCATED, standard meanings
2125 fdt_appendprop_u64 (
2132 fdt64_t tmp
= cpu_to_fdt64 (val
);
2134 return fdt_appendprop (fdt
, nodeoffset
, name
, &tmp
, sizeof (tmp
));
2138 * fdt_appendprop_cell - append a single cell value to a property
2140 * This is an alternative name for fdt_appendprop_u32()
2143 fdt_appendprop_cell (
2150 return fdt_appendprop_u32 (fdt
, nodeoffset
, name
, val
);
2154 * fdt_appendprop_string - append a string to a property
2155 * @fdt: pointer to the device tree blob
2156 * @nodeoffset: offset of the node whose property to change
2157 * @name: name of the property to change
2158 * @str: string value to append to the property
2160 * fdt_appendprop_string() appends the given string to the value of
2161 * the named property in the given node, or creates a new property
2162 * with that value if it does not already exist.
2164 * This function may insert data into the blob, and will therefore
2165 * change the offsets of some existing nodes.
2169 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
2170 * contain the new property value
2171 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
2172 * -FDT_ERR_BADLAYOUT,
2173 * -FDT_ERR_BADMAGIC,
2174 * -FDT_ERR_BADVERSION,
2175 * -FDT_ERR_BADSTATE,
2176 * -FDT_ERR_BADSTRUCTURE,
2177 * -FDT_ERR_BADLAYOUT,
2178 * -FDT_ERR_TRUNCATED, standard meanings
2180 #define fdt_appendprop_string(fdt, nodeoffset, name, str) \
2181 fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
2184 * fdt_delprop - delete a property
2185 * @fdt: pointer to the device tree blob
2186 * @nodeoffset: offset of the node whose property to nop
2187 * @name: name of the property to nop
2189 * fdt_del_property() will delete the given property.
2191 * This function will delete data from the blob, and will therefore
2192 * change the offsets of some existing nodes.
2196 * -FDT_ERR_NOTFOUND, node does not have the named property
2197 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
2198 * -FDT_ERR_BADLAYOUT,
2199 * -FDT_ERR_BADMAGIC,
2200 * -FDT_ERR_BADVERSION,
2201 * -FDT_ERR_BADSTATE,
2202 * -FDT_ERR_BADSTRUCTURE,
2203 * -FDT_ERR_TRUNCATED, standard meanings
2213 * fdt_add_subnode_namelen - creates a new node based on substring
2214 * @fdt: pointer to the device tree blob
2215 * @parentoffset: structure block offset of a node
2216 * @name: name of the subnode to locate
2217 * @namelen: number of characters of name to consider
2219 * Identical to fdt_add_subnode(), but use only the first namelen
2220 * characters of name as the name of the new node. This is useful for
2221 * creating subnodes based on a portion of a larger string, such as a
2224 #ifndef SWIG /* Not available in Python */
2226 fdt_add_subnode_namelen (
2236 * fdt_add_subnode - creates a new node
2237 * @fdt: pointer to the device tree blob
2238 * @parentoffset: structure block offset of a node
2239 * @name: name of the subnode to locate
2241 * fdt_add_subnode() creates a new node as a subnode of the node at
2242 * structure block offset parentoffset, with the given name (which
2243 * should include the unit address, if any).
2245 * This function will insert data into the blob, and will therefore
2246 * change the offsets of some existing nodes.
2249 * structure block offset of the created nodeequested subnode (>=0), on
2251 * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
2252 * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
2254 * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
2256 * -FDT_ERR_NOSPACE, if there is insufficient free space in the
2257 * blob to contain the new node
2259 * -FDT_ERR_BADLAYOUT
2260 * -FDT_ERR_BADMAGIC,
2261 * -FDT_ERR_BADVERSION,
2262 * -FDT_ERR_BADSTATE,
2263 * -FDT_ERR_BADSTRUCTURE,
2264 * -FDT_ERR_TRUNCATED, standard meanings.
2274 * fdt_del_node - delete a node (subtree)
2275 * @fdt: pointer to the device tree blob
2276 * @nodeoffset: offset of the node to nop
2278 * fdt_del_node() will remove the given node, including all its
2279 * subnodes if any, from the blob.
2281 * This function will delete data from the blob, and will therefore
2282 * change the offsets of some existing nodes.
2286 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
2287 * -FDT_ERR_BADLAYOUT,
2288 * -FDT_ERR_BADMAGIC,
2289 * -FDT_ERR_BADVERSION,
2290 * -FDT_ERR_BADSTATE,
2291 * -FDT_ERR_BADSTRUCTURE,
2292 * -FDT_ERR_TRUNCATED, standard meanings
2301 * fdt_overlay_apply - Applies a DT overlay on a base DT
2302 * @fdt: pointer to the base device tree blob
2303 * @fdto: pointer to the device tree overlay blob
2305 * fdt_overlay_apply() will apply the given device tree overlay on the
2306 * given base device tree.
2308 * Expect the base device tree to be modified, even if the function
2313 * -FDT_ERR_NOSPACE, there's not enough space in the base device tree
2314 * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or
2315 * properties in the base DT
2316 * -FDT_ERR_BADPHANDLE,
2317 * -FDT_ERR_BADOVERLAY,
2318 * -FDT_ERR_NOPHANDLES,
2319 * -FDT_ERR_INTERNAL,
2320 * -FDT_ERR_BADLAYOUT,
2321 * -FDT_ERR_BADMAGIC,
2322 * -FDT_ERR_BADOFFSET,
2324 * -FDT_ERR_BADVERSION,
2325 * -FDT_ERR_BADSTRUCTURE,
2326 * -FDT_ERR_BADSTATE,
2327 * -FDT_ERR_TRUNCATED, standard meanings
2335 /**********************************************************************/
2336 /* Debugging / informational functions */
2337 /**********************************************************************/
2344 #endif /* _LIBFDT_H */