blob: 540de76bbbf51ac0ff7b1bf2d7ae33ff7e50d98c [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001#ifndef _LIBFDT_H
2#define _LIBFDT_H
3/*
4 * libfdt - Flat Device Tree manipulation
5 * Copyright (C) 2006 David Gibson, IBM Corporation.
6 *
7 * libfdt is dual licensed: you can use it either under the terms of
8 * the GPL, or the BSD license, at your option.
9 *
10 * a) This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of the
13 * License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public
21 * License along with this library; if not, write to the Free
22 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
23 * MA 02110-1301 USA
24 *
25 * Alternatively,
26 *
27 * b) Redistribution and use in source and binary forms, with or
28 * without modification, are permitted provided that the following
29 * conditions are met:
30 *
31 * 1. Redistributions of source code must retain the above
32 * copyright notice, this list of conditions and the following
33 * disclaimer.
34 * 2. Redistributions in binary form must reproduce the above
35 * copyright notice, this list of conditions and the following
36 * disclaimer in the documentation and/or other materials
37 * provided with the distribution.
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
40 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
41 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
44 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
49 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
50 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
51 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 */
53
54#include <libfdt_env.h>
55#include <fdt.h>
56
57#define FDT_FIRST_SUPPORTED_VERSION 0x10
58#define FDT_LAST_SUPPORTED_VERSION 0x11
59
60/* Error codes: informative error codes */
61#define FDT_ERR_NOTFOUND 1
62 /* FDT_ERR_NOTFOUND: The requested node or property does not exist */
63#define FDT_ERR_EXISTS 2
64 /* FDT_ERR_EXISTS: Attempted to create a node or property which
65 * already exists */
66#define FDT_ERR_NOSPACE 3
67 /* FDT_ERR_NOSPACE: Operation needed to expand the device
68 * tree, but its buffer did not have sufficient space to
69 * contain the expanded tree. Use fdt_open_into() to move the
70 * device tree to a buffer with more space. */
71
72/* Error codes: codes for bad parameters */
73#define FDT_ERR_BADOFFSET 4
74 /* FDT_ERR_BADOFFSET: Function was passed a structure block
75 * offset which is out-of-bounds, or which points to an
76 * unsuitable part of the structure for the operation. */
77#define FDT_ERR_BADPATH 5
78 /* FDT_ERR_BADPATH: Function was passed a badly formatted path
79 * (e.g. missing a leading / for a function which requires an
80 * absolute path) */
81#define FDT_ERR_BADPHANDLE 6
82 /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.
83 * This can be caused either by an invalid phandle property
84 * length, or the phandle value was either 0 or -1, which are
85 * not permitted. */
86#define FDT_ERR_BADSTATE 7
87 /* FDT_ERR_BADSTATE: Function was passed an incomplete device
88 * tree created by the sequential-write functions, which is
89 * not sufficiently complete for the requested operation. */
90
91/* Error codes: codes for bad device tree blobs */
92#define FDT_ERR_TRUNCATED 8
93 /* FDT_ERR_TRUNCATED: Structure block of the given device tree
94 * ends without an FDT_END tag. */
95#define FDT_ERR_BADMAGIC 9
96 /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
97 * device tree at all - it is missing the flattened device
98 * tree magic number. */
99#define FDT_ERR_BADVERSION 10
100 /* FDT_ERR_BADVERSION: Given device tree has a version which
101 * can't be handled by the requested operation. For
102 * read-write functions, this may mean that fdt_open_into() is
103 * required to convert the tree to the expected version. */
104#define FDT_ERR_BADSTRUCTURE 11
105 /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
106 * structure block or other serious error (e.g. misnested
107 * nodes, or subnodes preceding properties). */
108#define FDT_ERR_BADLAYOUT 12
109 /* FDT_ERR_BADLAYOUT: For read-write functions, the given
110 * device tree has it's sub-blocks in an order that the
111 * function can't handle (memory reserve map, then structure,
112 * then strings). Use fdt_open_into() to reorganize the tree
113 * into a form suitable for the read-write operations. */
114
115/* "Can't happen" error indicating a bug in libfdt */
116#define FDT_ERR_INTERNAL 13
117 /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
118 * Should never be returned, if it is, it indicates a bug in
119 * libfdt itself. */
120
121/* Errors in device tree content */
122#define FDT_ERR_BADNCELLS 14
123 /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
124 * or similar property with a bad format or value */
125
126#define FDT_ERR_BADVALUE 15
127 /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
128 * value. For example: a property expected to contain a string list
129 * is not NUL-terminated within the length of its value. */
130
131#define FDT_ERR_BADOVERLAY 16
132 /* FDT_ERR_BADOVERLAY: The device tree overlay, while
133 * correctly structured, cannot be applied due to some
134 * unexpected or missing value, property or node. */
135
136#define FDT_ERR_NOPHANDLES 17
137 /* FDT_ERR_NOPHANDLES: The device tree doesn't have any
138 * phandle available anymore without causing an overflow */
139
140#define FDT_ERR_MAX 17
141
142/**********************************************************************/
143/* Low-level functions (you probably don't need these) */
144/**********************************************************************/
145
146const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
147static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
148{
149 return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
150}
151
152uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
153
154/**********************************************************************/
155/* Traversal functions */
156/**********************************************************************/
157
158int fdt_next_node(const void *fdt, int offset, int *depth);
159
160/**
161 * fdt_first_subnode() - get offset of first direct subnode
162 *
163 * @fdt: FDT blob
164 * @offset: Offset of node to check
165 * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
166 */
167int fdt_first_subnode(const void *fdt, int offset);
168
169/**
170 * fdt_next_subnode() - get offset of next direct subnode
171 *
172 * After first calling fdt_first_subnode(), call this function repeatedly to
173 * get direct subnodes of a parent node.
174 *
175 * @fdt: FDT blob
176 * @offset: Offset of previous subnode
177 * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
178 * subnodes
179 */
180int fdt_next_subnode(const void *fdt, int offset);
181
182/**
183 * fdt_for_each_subnode - iterate over all subnodes of a parent
184 *
185 * @node: child node (int, lvalue)
186 * @fdt: FDT blob (const void *)
187 * @parent: parent node (int)
188 *
189 * This is actually a wrapper around a for loop and would be used like so:
190 *
191 * fdt_for_each_subnode(node, fdt, parent) {
192 * Use node
193 * ...
194 * }
195 *
196 * if ((node < 0) && (node != -FDT_ERR_NOT_FOUND)) {
197 * Error handling
198 * }
199 *
200 * Note that this is implemented as a macro and @node is used as
201 * iterator in the loop. The parent variable be constant or even a
202 * literal.
203 *
204 */
205#define fdt_for_each_subnode(node, fdt, parent) \
206 for (node = fdt_first_subnode(fdt, parent); \
207 node >= 0; \
208 node = fdt_next_subnode(fdt, node))
209
210/**********************************************************************/
211/* General functions */
212/**********************************************************************/
213
214#define fdt_get_header(fdt, field) \
215 (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
216#define fdt_magic(fdt) (fdt_get_header(fdt, magic))
217#define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
218#define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
219#define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
220#define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
221#define fdt_version(fdt) (fdt_get_header(fdt, version))
222#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
223#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
224#define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
225#define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
226
227#define __fdt_set_hdr(name) \
228 static inline void fdt_set_##name(void *fdt, uint32_t val) \
229 { \
230 struct fdt_header *fdth = (struct fdt_header *)fdt; \
231 fdth->name = cpu_to_fdt32(val); \
232 }
233__fdt_set_hdr(magic);
234__fdt_set_hdr(totalsize);
235__fdt_set_hdr(off_dt_struct);
236__fdt_set_hdr(off_dt_strings);
237__fdt_set_hdr(off_mem_rsvmap);
238__fdt_set_hdr(version);
239__fdt_set_hdr(last_comp_version);
240__fdt_set_hdr(boot_cpuid_phys);
241__fdt_set_hdr(size_dt_strings);
242__fdt_set_hdr(size_dt_struct);
243#undef __fdt_set_hdr
244
245/**
246 * fdt_check_header - sanity check a device tree or possible device tree
247 * @fdt: pointer to data which might be a flattened device tree
248 *
249 * fdt_check_header() checks that the given buffer contains what
250 * appears to be a flattened device tree with sane information in its
251 * header.
252 *
253 * returns:
254 * 0, if the buffer appears to contain a valid device tree
255 * -FDT_ERR_BADMAGIC,
256 * -FDT_ERR_BADVERSION,
257 * -FDT_ERR_BADSTATE, standard meanings, as above
258 */
259int fdt_check_header(const void *fdt);
260
261/**
262 * fdt_move - move a device tree around in memory
263 * @fdt: pointer to the device tree to move
264 * @buf: pointer to memory where the device is to be moved
265 * @bufsize: size of the memory space at buf
266 *
267 * fdt_move() relocates, if possible, the device tree blob located at
268 * fdt to the buffer at buf of size bufsize. The buffer may overlap
269 * with the existing device tree blob at fdt. Therefore,
270 * fdt_move(fdt, fdt, fdt_totalsize(fdt))
271 * should always succeed.
272 *
273 * returns:
274 * 0, on success
275 * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
276 * -FDT_ERR_BADMAGIC,
277 * -FDT_ERR_BADVERSION,
278 * -FDT_ERR_BADSTATE, standard meanings
279 */
280int fdt_move(const void *fdt, void *buf, int bufsize);
281
282/**********************************************************************/
283/* Read-only functions */
284/**********************************************************************/
285
286/**
287 * fdt_string - retrieve a string from the strings block of a device tree
288 * @fdt: pointer to the device tree blob
289 * @stroffset: offset of the string within the strings block (native endian)
290 *
291 * fdt_string() retrieves a pointer to a single string from the
292 * strings block of the device tree blob at fdt.
293 *
294 * returns:
295 * a pointer to the string, on success
296 * NULL, if stroffset is out of bounds
297 */
298const char *fdt_string(const void *fdt, int stroffset);
299
300/**
301 * fdt_get_max_phandle - retrieves the highest phandle in a tree
302 * @fdt: pointer to the device tree blob
303 *
304 * fdt_get_max_phandle retrieves the highest phandle in the given
305 * device tree. This will ignore badly formatted phandles, or phandles
306 * with a value of 0 or -1.
307 *
308 * returns:
309 * the highest phandle on success
310 * 0, if no phandle was found in the device tree
311 * -1, if an error occurred
312 */
313uint32_t fdt_get_max_phandle(const void *fdt);
314
315/**
316 * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
317 * @fdt: pointer to the device tree blob
318 *
319 * Returns the number of entries in the device tree blob's memory
320 * reservation map. This does not include the terminating 0,0 entry
321 * or any other (0,0) entries reserved for expansion.
322 *
323 * returns:
324 * the number of entries
325 */
326int fdt_num_mem_rsv(const void *fdt);
327
328/**
329 * fdt_get_mem_rsv - retrieve one memory reserve map entry
330 * @fdt: pointer to the device tree blob
331 * @address, @size: pointers to 64-bit variables
332 *
333 * On success, *address and *size will contain the address and size of
334 * the n-th reserve map entry from the device tree blob, in
335 * native-endian format.
336 *
337 * returns:
338 * 0, on success
339 * -FDT_ERR_BADMAGIC,
340 * -FDT_ERR_BADVERSION,
341 * -FDT_ERR_BADSTATE, standard meanings
342 */
343int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
344
345/**
346 * fdt_subnode_offset_namelen - find a subnode based on substring
347 * @fdt: pointer to the device tree blob
348 * @parentoffset: structure block offset of a node
349 * @name: name of the subnode to locate
350 * @namelen: number of characters of name to consider
351 *
352 * Identical to fdt_subnode_offset(), but only examine the first
353 * namelen characters of name for matching the subnode name. This is
354 * useful for finding subnodes based on a portion of a larger string,
355 * such as a full path.
356 */
357int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
358 const char *name, int namelen);
359/**
360 * fdt_subnode_offset - find a subnode of a given node
361 * @fdt: pointer to the device tree blob
362 * @parentoffset: structure block offset of a node
363 * @name: name of the subnode to locate
364 *
365 * fdt_subnode_offset() finds a subnode of the node at structure block
366 * offset parentoffset with the given name. name may include a unit
367 * address, in which case fdt_subnode_offset() will find the subnode
368 * with that unit address, or the unit address may be omitted, in
369 * which case fdt_subnode_offset() will find an arbitrary subnode
370 * whose name excluding unit address matches the given name.
371 *
372 * returns:
373 * structure block offset of the requested subnode (>=0), on success
374 * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
375 * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
376 * tag
377 * -FDT_ERR_BADMAGIC,
378 * -FDT_ERR_BADVERSION,
379 * -FDT_ERR_BADSTATE,
380 * -FDT_ERR_BADSTRUCTURE,
381 * -FDT_ERR_TRUNCATED, standard meanings.
382 */
383int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
384
385/**
386 * fdt_path_offset_namelen - find a tree node by its full path
387 * @fdt: pointer to the device tree blob
388 * @path: full path of the node to locate
389 * @namelen: number of characters of path to consider
390 *
391 * Identical to fdt_path_offset(), but only consider the first namelen
392 * characters of path as the path name.
393 */
394int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
395
396/**
397 * fdt_path_offset - find a tree node by its full path
398 * @fdt: pointer to the device tree blob
399 * @path: full path of the node to locate
400 *
401 * fdt_path_offset() finds a node of a given path in the device tree.
402 * Each path component may omit the unit address portion, but the
403 * results of this are undefined if any such path component is
404 * ambiguous (that is if there are multiple nodes at the relevant
405 * level matching the given component, differentiated only by unit
406 * address).
407 *
408 * returns:
409 * structure block offset of the node with the requested path (>=0), on
410 * success
411 * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
412 * -FDT_ERR_NOTFOUND, if the requested node does not exist
413 * -FDT_ERR_BADMAGIC,
414 * -FDT_ERR_BADVERSION,
415 * -FDT_ERR_BADSTATE,
416 * -FDT_ERR_BADSTRUCTURE,
417 * -FDT_ERR_TRUNCATED, standard meanings.
418 */
419int fdt_path_offset(const void *fdt, const char *path);
420
421/**
422 * fdt_get_name - retrieve the name of a given node
423 * @fdt: pointer to the device tree blob
424 * @nodeoffset: structure block offset of the starting node
425 * @lenp: pointer to an integer variable (will be overwritten) or NULL
426 *
427 * fdt_get_name() retrieves the name (including unit address) of the
428 * device tree node at structure block offset nodeoffset. If lenp is
429 * non-NULL, the length of this name is also returned, in the integer
430 * pointed to by lenp.
431 *
432 * returns:
433 * pointer to the node's name, on success
434 * If lenp is non-NULL, *lenp contains the length of that name
435 * (>=0)
436 * NULL, on error
437 * if lenp is non-NULL *lenp contains an error code (<0):
438 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
439 * tag
440 * -FDT_ERR_BADMAGIC,
441 * -FDT_ERR_BADVERSION,
442 * -FDT_ERR_BADSTATE, standard meanings
443 */
444const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
445
446/**
447 * fdt_first_property_offset - find the offset of a node's first property
448 * @fdt: pointer to the device tree blob
449 * @nodeoffset: structure block offset of a node
450 *
451 * fdt_first_property_offset() finds the first property of the node at
452 * the given structure block offset.
453 *
454 * returns:
455 * structure block offset of the property (>=0), on success
456 * -FDT_ERR_NOTFOUND, if the requested node has no properties
457 * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
458 * -FDT_ERR_BADMAGIC,
459 * -FDT_ERR_BADVERSION,
460 * -FDT_ERR_BADSTATE,
461 * -FDT_ERR_BADSTRUCTURE,
462 * -FDT_ERR_TRUNCATED, standard meanings.
463 */
464int fdt_first_property_offset(const void *fdt, int nodeoffset);
465
466/**
467 * fdt_next_property_offset - step through a node's properties
468 * @fdt: pointer to the device tree blob
469 * @offset: structure block offset of a property
470 *
471 * fdt_next_property_offset() finds the property immediately after the
472 * one at the given structure block offset. This will be a property
473 * of the same node as the given property.
474 *
475 * returns:
476 * structure block offset of the next property (>=0), on success
477 * -FDT_ERR_NOTFOUND, if the given property is the last in its node
478 * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
479 * -FDT_ERR_BADMAGIC,
480 * -FDT_ERR_BADVERSION,
481 * -FDT_ERR_BADSTATE,
482 * -FDT_ERR_BADSTRUCTURE,
483 * -FDT_ERR_TRUNCATED, standard meanings.
484 */
485int fdt_next_property_offset(const void *fdt, int offset);
486
487/**
488 * fdt_for_each_property_offset - iterate over all properties of a node
489 *
490 * @property_offset: property offset (int, lvalue)
491 * @fdt: FDT blob (const void *)
492 * @node: node offset (int)
493 *
494 * This is actually a wrapper around a for loop and would be used like so:
495 *
496 * fdt_for_each_property_offset(property, fdt, node) {
497 * Use property
498 * ...
499 * }
500 *
501 * if ((property < 0) && (property != -FDT_ERR_NOT_FOUND)) {
502 * Error handling
503 * }
504 *
505 * Note that this is implemented as a macro and property is used as
506 * iterator in the loop. The node variable can be constant or even a
507 * literal.
508 */
509#define fdt_for_each_property_offset(property, fdt, node) \
510 for (property = fdt_first_property_offset(fdt, node); \
511 property >= 0; \
512 property = fdt_next_property_offset(fdt, property))
513
514/**
515 * fdt_get_property_by_offset - retrieve the property at a given offset
516 * @fdt: pointer to the device tree blob
517 * @offset: offset of the property to retrieve
518 * @lenp: pointer to an integer variable (will be overwritten) or NULL
519 *
520 * fdt_get_property_by_offset() retrieves a pointer to the
521 * fdt_property structure within the device tree blob at the given
522 * offset. If lenp is non-NULL, the length of the property value is
523 * also returned, in the integer pointed to by lenp.
524 *
525 * returns:
526 * pointer to the structure representing the property
527 * if lenp is non-NULL, *lenp contains the length of the property
528 * value (>=0)
529 * NULL, on error
530 * if lenp is non-NULL, *lenp contains an error code (<0):
531 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
532 * -FDT_ERR_BADMAGIC,
533 * -FDT_ERR_BADVERSION,
534 * -FDT_ERR_BADSTATE,
535 * -FDT_ERR_BADSTRUCTURE,
536 * -FDT_ERR_TRUNCATED, standard meanings
537 */
538const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
539 int offset,
540 int *lenp);
541
542/**
543 * fdt_get_property_namelen - find a property based on substring
544 * @fdt: pointer to the device tree blob
545 * @nodeoffset: offset of the node whose property to find
546 * @name: name of the property to find
547 * @namelen: number of characters of name to consider
548 * @lenp: pointer to an integer variable (will be overwritten) or NULL
549 *
550 * Identical to fdt_get_property(), but only examine the first namelen
551 * characters of name for matching the property name.
552 */
553const struct fdt_property *fdt_get_property_namelen(const void *fdt,
554 int nodeoffset,
555 const char *name,
556 int namelen, int *lenp);
557
558/**
559 * fdt_get_property - find a given property in a given node
560 * @fdt: pointer to the device tree blob
561 * @nodeoffset: offset of the node whose property to find
562 * @name: name of the property to find
563 * @lenp: pointer to an integer variable (will be overwritten) or NULL
564 *
565 * fdt_get_property() retrieves a pointer to the fdt_property
566 * structure within the device tree blob corresponding to the property
567 * named 'name' of the node at offset nodeoffset. If lenp is
568 * non-NULL, the length of the property value is also returned, in the
569 * integer pointed to by lenp.
570 *
571 * returns:
572 * pointer to the structure representing the property
573 * if lenp is non-NULL, *lenp contains the length of the property
574 * value (>=0)
575 * NULL, on error
576 * if lenp is non-NULL, *lenp contains an error code (<0):
577 * -FDT_ERR_NOTFOUND, node does not have named property
578 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
579 * tag
580 * -FDT_ERR_BADMAGIC,
581 * -FDT_ERR_BADVERSION,
582 * -FDT_ERR_BADSTATE,
583 * -FDT_ERR_BADSTRUCTURE,
584 * -FDT_ERR_TRUNCATED, standard meanings
585 */
586const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
587 const char *name, int *lenp);
588static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
589 const char *name,
590 int *lenp)
591{
592 return (struct fdt_property *)(uintptr_t)
593 fdt_get_property(fdt, nodeoffset, name, lenp);
594}
595
596/**
597 * fdt_getprop_by_offset - retrieve the value of a property at a given offset
598 * @fdt: pointer to the device tree blob
599 * @ffset: offset of the property to read
600 * @namep: pointer to a string variable (will be overwritten) or NULL
601 * @lenp: pointer to an integer variable (will be overwritten) or NULL
602 *
603 * fdt_getprop_by_offset() retrieves a pointer to the value of the
604 * property at structure block offset 'offset' (this will be a pointer
605 * to within the device blob itself, not a copy of the value). If
606 * lenp is non-NULL, the length of the property value is also
607 * returned, in the integer pointed to by lenp. If namep is non-NULL,
608 * the property's namne will also be returned in the char * pointed to
609 * by namep (this will be a pointer to within the device tree's string
610 * block, not a new copy of the name).
611 *
612 * returns:
613 * pointer to the property's value
614 * if lenp is non-NULL, *lenp contains the length of the property
615 * value (>=0)
616 * if namep is non-NULL *namep contiains a pointer to the property
617 * name.
618 * NULL, on error
619 * if lenp is non-NULL, *lenp contains an error code (<0):
620 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
621 * -FDT_ERR_BADMAGIC,
622 * -FDT_ERR_BADVERSION,
623 * -FDT_ERR_BADSTATE,
624 * -FDT_ERR_BADSTRUCTURE,
625 * -FDT_ERR_TRUNCATED, standard meanings
626 */
627const void *fdt_getprop_by_offset(const void *fdt, int offset,
628 const char **namep, int *lenp);
629
630/**
631 * fdt_getprop_namelen - get property value based on substring
632 * @fdt: pointer to the device tree blob
633 * @nodeoffset: offset of the node whose property to find
634 * @name: name of the property to find
635 * @namelen: number of characters of name to consider
636 * @lenp: pointer to an integer variable (will be overwritten) or NULL
637 *
638 * Identical to fdt_getprop(), but only examine the first namelen
639 * characters of name for matching the property name.
640 */
641const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
642 const char *name, int namelen, int *lenp);
643static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,
644 const char *name, int namelen,
645 int *lenp)
646{
647 return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,
648 namelen, lenp);
649}
650
651/**
652 * fdt_getprop - retrieve the value of a given property
653 * @fdt: pointer to the device tree blob
654 * @nodeoffset: offset of the node whose property to find
655 * @name: name of the property to find
656 * @lenp: pointer to an integer variable (will be overwritten) or NULL
657 *
658 * fdt_getprop() retrieves a pointer to the value of the property
659 * named 'name' of the node at offset nodeoffset (this will be a
660 * pointer to within the device blob itself, not a copy of the value).
661 * If lenp is non-NULL, the length of the property value is also
662 * returned, in the integer pointed to by lenp.
663 *
664 * returns:
665 * pointer to the property's value
666 * if lenp is non-NULL, *lenp contains the length of the property
667 * value (>=0)
668 * NULL, on error
669 * if lenp is non-NULL, *lenp contains an error code (<0):
670 * -FDT_ERR_NOTFOUND, node does not have named property
671 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
672 * tag
673 * -FDT_ERR_BADMAGIC,
674 * -FDT_ERR_BADVERSION,
675 * -FDT_ERR_BADSTATE,
676 * -FDT_ERR_BADSTRUCTURE,
677 * -FDT_ERR_TRUNCATED, standard meanings
678 */
679const void *fdt_getprop(const void *fdt, int nodeoffset,
680 const char *name, int *lenp);
681static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
682 const char *name, int *lenp)
683{
684 return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
685}
686
687/**
688 * fdt_get_phandle - retrieve the phandle of a given node
689 * @fdt: pointer to the device tree blob
690 * @nodeoffset: structure block offset of the node
691 *
692 * fdt_get_phandle() retrieves the phandle of the device tree node at
693 * structure block offset nodeoffset.
694 *
695 * returns:
696 * the phandle of the node at nodeoffset, on success (!= 0, != -1)
697 * 0, if the node has no phandle, or another error occurs
698 */
699uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
700
701/**
702 * fdt_get_alias_namelen - get alias based on substring
703 * @fdt: pointer to the device tree blob
704 * @name: name of the alias th look up
705 * @namelen: number of characters of name to consider
706 *
707 * Identical to fdt_get_alias(), but only examine the first namelen
708 * characters of name for matching the alias name.
709 */
710const char *fdt_get_alias_namelen(const void *fdt,
711 const char *name, int namelen);
712
713/**
714 * fdt_get_alias - retrieve the path referenced by a given alias
715 * @fdt: pointer to the device tree blob
716 * @name: name of the alias th look up
717 *
718 * fdt_get_alias() retrieves the value of a given alias. That is, the
719 * value of the property named 'name' in the node /aliases.
720 *
721 * returns:
722 * a pointer to the expansion of the alias named 'name', if it exists
723 * NULL, if the given alias or the /aliases node does not exist
724 */
725const char *fdt_get_alias(const void *fdt, const char *name);
726
727/**
728 * fdt_get_path - determine the full path of a node
729 * @fdt: pointer to the device tree blob
730 * @nodeoffset: offset of the node whose path to find
731 * @buf: character buffer to contain the returned path (will be overwritten)
732 * @buflen: size of the character buffer at buf
733 *
734 * fdt_get_path() computes the full path of the node at offset
735 * nodeoffset, and records that path in the buffer at buf.
736 *
737 * NOTE: This function is expensive, as it must scan the device tree
738 * structure from the start to nodeoffset.
739 *
740 * returns:
741 * 0, on success
742 * buf contains the absolute path of the node at
743 * nodeoffset, as a NUL-terminated string.
744 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
745 * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
746 * characters and will not fit in the given buffer.
747 * -FDT_ERR_BADMAGIC,
748 * -FDT_ERR_BADVERSION,
749 * -FDT_ERR_BADSTATE,
750 * -FDT_ERR_BADSTRUCTURE, standard meanings
751 */
752int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
753
754/**
755 * fdt_supernode_atdepth_offset - find a specific ancestor of a node
756 * @fdt: pointer to the device tree blob
757 * @nodeoffset: offset of the node whose parent to find
758 * @supernodedepth: depth of the ancestor to find
759 * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
760 *
761 * fdt_supernode_atdepth_offset() finds an ancestor of the given node
762 * at a specific depth from the root (where the root itself has depth
763 * 0, its immediate subnodes depth 1 and so forth). So
764 * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
765 * will always return 0, the offset of the root node. If the node at
766 * nodeoffset has depth D, then:
767 * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
768 * will return nodeoffset itself.
769 *
770 * NOTE: This function is expensive, as it must scan the device tree
771 * structure from the start to nodeoffset.
772 *
773 * returns:
774 * structure block offset of the node at node offset's ancestor
775 * of depth supernodedepth (>=0), on success
776 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
777 * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of
778 * nodeoffset
779 * -FDT_ERR_BADMAGIC,
780 * -FDT_ERR_BADVERSION,
781 * -FDT_ERR_BADSTATE,
782 * -FDT_ERR_BADSTRUCTURE, standard meanings
783 */
784int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
785 int supernodedepth, int *nodedepth);
786
787/**
788 * fdt_node_depth - find the depth of a given node
789 * @fdt: pointer to the device tree blob
790 * @nodeoffset: offset of the node whose parent to find
791 *
792 * fdt_node_depth() finds the depth of a given node. The root node
793 * has depth 0, its immediate subnodes depth 1 and so forth.
794 *
795 * NOTE: This function is expensive, as it must scan the device tree
796 * structure from the start to nodeoffset.
797 *
798 * returns:
799 * depth of the node at nodeoffset (>=0), on success
800 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
801 * -FDT_ERR_BADMAGIC,
802 * -FDT_ERR_BADVERSION,
803 * -FDT_ERR_BADSTATE,
804 * -FDT_ERR_BADSTRUCTURE, standard meanings
805 */
806int fdt_node_depth(const void *fdt, int nodeoffset);
807
808/**
809 * fdt_parent_offset - find the parent of a given node
810 * @fdt: pointer to the device tree blob
811 * @nodeoffset: offset of the node whose parent to find
812 *
813 * fdt_parent_offset() locates the parent node of a given node (that
814 * is, it finds the offset of the node which contains the node at
815 * nodeoffset as a subnode).
816 *
817 * NOTE: This function is expensive, as it must scan the device tree
818 * structure from the start to nodeoffset, *twice*.
819 *
820 * returns:
821 * structure block offset of the parent of the node at nodeoffset
822 * (>=0), on success
823 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
824 * -FDT_ERR_BADMAGIC,
825 * -FDT_ERR_BADVERSION,
826 * -FDT_ERR_BADSTATE,
827 * -FDT_ERR_BADSTRUCTURE, standard meanings
828 */
829int fdt_parent_offset(const void *fdt, int nodeoffset);
830
831/**
832 * fdt_node_offset_by_prop_value - find nodes with a given property value
833 * @fdt: pointer to the device tree blob
834 * @startoffset: only find nodes after this offset
835 * @propname: property name to check
836 * @propval: property value to search for
837 * @proplen: length of the value in propval
838 *
839 * fdt_node_offset_by_prop_value() returns the offset of the first
840 * node after startoffset, which has a property named propname whose
841 * value is of length proplen and has value equal to propval; or if
842 * startoffset is -1, the very first such node in the tree.
843 *
844 * To iterate through all nodes matching the criterion, the following
845 * idiom can be used:
846 * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
847 * propval, proplen);
848 * while (offset != -FDT_ERR_NOTFOUND) {
849 * // other code here
850 * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
851 * propval, proplen);
852 * }
853 *
854 * Note the -1 in the first call to the function, if 0 is used here
855 * instead, the function will never locate the root node, even if it
856 * matches the criterion.
857 *
858 * returns:
859 * structure block offset of the located node (>= 0, >startoffset),
860 * on success
861 * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
862 * tree after startoffset
863 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
864 * -FDT_ERR_BADMAGIC,
865 * -FDT_ERR_BADVERSION,
866 * -FDT_ERR_BADSTATE,
867 * -FDT_ERR_BADSTRUCTURE, standard meanings
868 */
869int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
870 const char *propname,
871 const void *propval, int proplen);
872
873/**
874 * fdt_node_offset_by_phandle - find the node with a given phandle
875 * @fdt: pointer to the device tree blob
876 * @phandle: phandle value
877 *
878 * fdt_node_offset_by_phandle() returns the offset of the node
879 * which has the given phandle value. If there is more than one node
880 * in the tree with the given phandle (an invalid tree), results are
881 * undefined.
882 *
883 * returns:
884 * structure block offset of the located node (>= 0), on success
885 * -FDT_ERR_NOTFOUND, no node with that phandle exists
886 * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
887 * -FDT_ERR_BADMAGIC,
888 * -FDT_ERR_BADVERSION,
889 * -FDT_ERR_BADSTATE,
890 * -FDT_ERR_BADSTRUCTURE, standard meanings
891 */
892int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
893
894/**
895 * fdt_node_check_compatible: check a node's compatible property
896 * @fdt: pointer to the device tree blob
897 * @nodeoffset: offset of a tree node
898 * @compatible: string to match against
899 *
900 *
901 * fdt_node_check_compatible() returns 0 if the given node contains a
902 * 'compatible' property with the given string as one of its elements,
903 * it returns non-zero otherwise, or on error.
904 *
905 * returns:
906 * 0, if the node has a 'compatible' property listing the given string
907 * 1, if the node has a 'compatible' property, but it does not list
908 * the given string
909 * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
910 * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
911 * -FDT_ERR_BADMAGIC,
912 * -FDT_ERR_BADVERSION,
913 * -FDT_ERR_BADSTATE,
914 * -FDT_ERR_BADSTRUCTURE, standard meanings
915 */
916int fdt_node_check_compatible(const void *fdt, int nodeoffset,
917 const char *compatible);
918
919/**
920 * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
921 * @fdt: pointer to the device tree blob
922 * @startoffset: only find nodes after this offset
923 * @compatible: 'compatible' string to match against
924 *
925 * fdt_node_offset_by_compatible() returns the offset of the first
926 * node after startoffset, which has a 'compatible' property which
927 * lists the given compatible string; or if startoffset is -1, the
928 * very first such node in the tree.
929 *
930 * To iterate through all nodes matching the criterion, the following
931 * idiom can be used:
932 * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
933 * while (offset != -FDT_ERR_NOTFOUND) {
934 * // other code here
935 * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
936 * }
937 *
938 * Note the -1 in the first call to the function, if 0 is used here
939 * instead, the function will never locate the root node, even if it
940 * matches the criterion.
941 *
942 * returns:
943 * structure block offset of the located node (>= 0, >startoffset),
944 * on success
945 * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
946 * tree after startoffset
947 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
948 * -FDT_ERR_BADMAGIC,
949 * -FDT_ERR_BADVERSION,
950 * -FDT_ERR_BADSTATE,
951 * -FDT_ERR_BADSTRUCTURE, standard meanings
952 */
953int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
954 const char *compatible);
955
956/**
957 * fdt_stringlist_contains - check a string list property for a string
958 * @strlist: Property containing a list of strings to check
959 * @listlen: Length of property
960 * @str: String to search for
961 *
962 * This is a utility function provided for convenience. The list contains
963 * one or more strings, each terminated by \0, as is found in a device tree
964 * "compatible" property.
965 *
966 * @return: 1 if the string is found in the list, 0 not found, or invalid list
967 */
968int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
969
970/**
971 * fdt_stringlist_count - count the number of strings in a string list
972 * @fdt: pointer to the device tree blob
973 * @nodeoffset: offset of a tree node
974 * @property: name of the property containing the string list
975 * @return:
976 * the number of strings in the given property
977 * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
978 * -FDT_ERR_NOTFOUND if the property does not exist
979 */
980int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);
981
982/**
983 * fdt_stringlist_search - find a string in a string list and return its index
984 * @fdt: pointer to the device tree blob
985 * @nodeoffset: offset of a tree node
986 * @property: name of the property containing the string list
987 * @string: string to look up in the string list
988 *
989 * Note that it is possible for this function to succeed on property values
990 * that are not NUL-terminated. That's because the function will stop after
991 * finding the first occurrence of @string. This can for example happen with
992 * small-valued cell properties, such as #address-cells, when searching for
993 * the empty string.
994 *
995 * @return:
996 * the index of the string in the list of strings
997 * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
998 * -FDT_ERR_NOTFOUND if the property does not exist or does not contain
999 * the given string
1000 */
1001int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
1002 const char *string);
1003
1004/**
1005 * fdt_stringlist_get() - obtain the string at a given index in a string list
1006 * @fdt: pointer to the device tree blob
1007 * @nodeoffset: offset of a tree node
1008 * @property: name of the property containing the string list
1009 * @index: index of the string to return
1010 * @lenp: return location for the string length or an error code on failure
1011 *
1012 * Note that this will successfully extract strings from properties with
1013 * non-NUL-terminated values. For example on small-valued cell properties
1014 * this function will return the empty string.
1015 *
1016 * If non-NULL, the length of the string (on success) or a negative error-code
1017 * (on failure) will be stored in the integer pointer to by lenp.
1018 *
1019 * @return:
1020 * A pointer to the string at the given index in the string list or NULL on
1021 * failure. On success the length of the string will be stored in the memory
1022 * location pointed to by the lenp parameter, if non-NULL. On failure one of
1023 * the following negative error codes will be returned in the lenp parameter
1024 * (if non-NULL):
1025 * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
1026 * -FDT_ERR_NOTFOUND if the property does not exist
1027 */
1028const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
1029 const char *property, int index,
1030 int *lenp);
1031
1032/**********************************************************************/
1033/* Read-only functions (addressing related) */
1034/**********************************************************************/
1035
1036/**
1037 * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
1038 *
1039 * This is the maximum value for #address-cells, #size-cells and
1040 * similar properties that will be processed by libfdt. IEE1275
1041 * requires that OF implementations handle values up to 4.
1042 * Implementations may support larger values, but in practice higher
1043 * values aren't used.
1044 */
1045#define FDT_MAX_NCELLS 4
1046
1047/**
1048 * fdt_address_cells - retrieve address size for a bus represented in the tree
1049 * @fdt: pointer to the device tree blob
1050 * @nodeoffset: offset of the node to find the address size for
1051 *
1052 * When the node has a valid #address-cells property, returns its value.
1053 *
1054 * returns:
1055 * 0 <= n < FDT_MAX_NCELLS, on success
1056 * 2, if the node has no #address-cells property
1057 * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
1058 * #address-cells property
1059 * -FDT_ERR_BADMAGIC,
1060 * -FDT_ERR_BADVERSION,
1061 * -FDT_ERR_BADSTATE,
1062 * -FDT_ERR_BADSTRUCTURE,
1063 * -FDT_ERR_TRUNCATED, standard meanings
1064 */
1065int fdt_address_cells(const void *fdt, int nodeoffset);
1066
1067/**
1068 * fdt_size_cells - retrieve address range size for a bus represented in the
1069 * tree
1070 * @fdt: pointer to the device tree blob
1071 * @nodeoffset: offset of the node to find the address range size for
1072 *
1073 * When the node has a valid #size-cells property, returns its value.
1074 *
1075 * returns:
1076 * 0 <= n < FDT_MAX_NCELLS, on success
1077 * 2, if the node has no #address-cells property
1078 * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
1079 * #size-cells property
1080 * -FDT_ERR_BADMAGIC,
1081 * -FDT_ERR_BADVERSION,
1082 * -FDT_ERR_BADSTATE,
1083 * -FDT_ERR_BADSTRUCTURE,
1084 * -FDT_ERR_TRUNCATED, standard meanings
1085 */
1086int fdt_size_cells(const void *fdt, int nodeoffset);
1087
1088
1089/**********************************************************************/
1090/* Write-in-place functions */
1091/**********************************************************************/
1092
1093/**
1094 * fdt_setprop_inplace_namelen_partial - change a property's value,
1095 * but not its size
1096 * @fdt: pointer to the device tree blob
1097 * @nodeoffset: offset of the node whose property to change
1098 * @name: name of the property to change
1099 * @namelen: number of characters of name to consider
1100 * @idx: index of the property to change in the array
1101 * @val: pointer to data to replace the property value with
1102 * @len: length of the property value
1103 *
1104 * Identical to fdt_setprop_inplace(), but modifies the given property
1105 * starting from the given index, and using only the first characters
1106 * of the name. It is useful when you want to manipulate only one value of
1107 * an array and you have a string that doesn't end with \0.
1108 */
1109int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
1110 const char *name, int namelen,
1111 uint32_t idx, const void *val,
1112 int len);
1113
1114/**
1115 * fdt_setprop_inplace - change a property's value, but not its size
1116 * @fdt: pointer to the device tree blob
1117 * @nodeoffset: offset of the node whose property to change
1118 * @name: name of the property to change
1119 * @val: pointer to data to replace the property value with
1120 * @len: length of the property value
1121 *
1122 * fdt_setprop_inplace() replaces the value of a given property with
1123 * the data in val, of length len. This function cannot change the
1124 * size of a property, and so will only work if len is equal to the
1125 * current length of the property.
1126 *
1127 * This function will alter only the bytes in the blob which contain
1128 * the given property value, and will not alter or move any other part
1129 * of the tree.
1130 *
1131 * returns:
1132 * 0, on success
1133 * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
1134 * -FDT_ERR_NOTFOUND, node does not have the named property
1135 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1136 * -FDT_ERR_BADMAGIC,
1137 * -FDT_ERR_BADVERSION,
1138 * -FDT_ERR_BADSTATE,
1139 * -FDT_ERR_BADSTRUCTURE,
1140 * -FDT_ERR_TRUNCATED, standard meanings
1141 */
1142int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
1143 const void *val, int len);
1144
1145/**
1146 * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
1147 * @fdt: pointer to the device tree blob
1148 * @nodeoffset: offset of the node whose property to change
1149 * @name: name of the property to change
1150 * @val: 32-bit integer value to replace the property with
1151 *
1152 * fdt_setprop_inplace_u32() replaces the value of a given property
1153 * with the 32-bit integer value in val, converting val to big-endian
1154 * if necessary. This function cannot change the size of a property,
1155 * and so will only work if the property already exists and has length
1156 * 4.
1157 *
1158 * This function will alter only the bytes in the blob which contain
1159 * the given property value, and will not alter or move any other part
1160 * of the tree.
1161 *
1162 * returns:
1163 * 0, on success
1164 * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
1165 * -FDT_ERR_NOTFOUND, node does not have the named property
1166 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1167 * -FDT_ERR_BADMAGIC,
1168 * -FDT_ERR_BADVERSION,
1169 * -FDT_ERR_BADSTATE,
1170 * -FDT_ERR_BADSTRUCTURE,
1171 * -FDT_ERR_TRUNCATED, standard meanings
1172 */
1173static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
1174 const char *name, uint32_t val)
1175{
1176 fdt32_t tmp = cpu_to_fdt32(val);
1177 return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1178}
1179
1180/**
1181 * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
1182 * @fdt: pointer to the device tree blob
1183 * @nodeoffset: offset of the node whose property to change
1184 * @name: name of the property to change
1185 * @val: 64-bit integer value to replace the property with
1186 *
1187 * fdt_setprop_inplace_u64() replaces the value of a given property
1188 * with the 64-bit integer value in val, converting val to big-endian
1189 * if necessary. This function cannot change the size of a property,
1190 * and so will only work if the property already exists and has length
1191 * 8.
1192 *
1193 * This function will alter only the bytes in the blob which contain
1194 * the given property value, and will not alter or move any other part
1195 * of the tree.
1196 *
1197 * returns:
1198 * 0, on success
1199 * -FDT_ERR_NOSPACE, if the property's length is not equal to 8
1200 * -FDT_ERR_NOTFOUND, node does not have the named property
1201 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1202 * -FDT_ERR_BADMAGIC,
1203 * -FDT_ERR_BADVERSION,
1204 * -FDT_ERR_BADSTATE,
1205 * -FDT_ERR_BADSTRUCTURE,
1206 * -FDT_ERR_TRUNCATED, standard meanings
1207 */
1208static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
1209 const char *name, uint64_t val)
1210{
1211 fdt64_t tmp = cpu_to_fdt64(val);
1212 return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1213}
1214
1215/**
1216 * fdt_setprop_inplace_cell - change the value of a single-cell property
1217 *
1218 * This is an alternative name for fdt_setprop_inplace_u32()
1219 */
1220static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
1221 const char *name, uint32_t val)
1222{
1223 return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
1224}
1225
1226/**
1227 * fdt_nop_property - replace a property with nop tags
1228 * @fdt: pointer to the device tree blob
1229 * @nodeoffset: offset of the node whose property to nop
1230 * @name: name of the property to nop
1231 *
1232 * fdt_nop_property() will replace a given property's representation
1233 * in the blob with FDT_NOP tags, effectively removing it from the
1234 * tree.
1235 *
1236 * This function will alter only the bytes in the blob which contain
1237 * the property, and will not alter or move any other part of the
1238 * tree.
1239 *
1240 * returns:
1241 * 0, on success
1242 * -FDT_ERR_NOTFOUND, node does not have the named property
1243 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1244 * -FDT_ERR_BADMAGIC,
1245 * -FDT_ERR_BADVERSION,
1246 * -FDT_ERR_BADSTATE,
1247 * -FDT_ERR_BADSTRUCTURE,
1248 * -FDT_ERR_TRUNCATED, standard meanings
1249 */
1250int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
1251
1252/**
1253 * fdt_nop_node - replace a node (subtree) with nop tags
1254 * @fdt: pointer to the device tree blob
1255 * @nodeoffset: offset of the node to nop
1256 *
1257 * fdt_nop_node() will replace a given node's representation in the
1258 * blob, including all its subnodes, if any, with FDT_NOP tags,
1259 * effectively removing it from the tree.
1260 *
1261 * This function will alter only the bytes in the blob which contain
1262 * the node and its properties and subnodes, and will not alter or
1263 * move any other part of the tree.
1264 *
1265 * returns:
1266 * 0, on success
1267 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1268 * -FDT_ERR_BADMAGIC,
1269 * -FDT_ERR_BADVERSION,
1270 * -FDT_ERR_BADSTATE,
1271 * -FDT_ERR_BADSTRUCTURE,
1272 * -FDT_ERR_TRUNCATED, standard meanings
1273 */
1274int fdt_nop_node(void *fdt, int nodeoffset);
1275
1276
1277/**********************************************************************/
1278/* Sequential write functions */
1279/**********************************************************************/
1280
1281int fdt_create(void *buf, int bufsize);
1282int fdt_resize(void *fdt, void *buf, int bufsize);
1283int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
1284int fdt_finish_reservemap(void *fdt);
1285int fdt_begin_node(void *fdt, const char *name);
1286int fdt_property(void *fdt, const char *name, const void *val, int len);
1287static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
1288{
1289 fdt32_t tmp = cpu_to_fdt32(val);
1290 return fdt_property(fdt, name, &tmp, sizeof(tmp));
1291}
1292static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
1293{
1294 fdt64_t tmp = cpu_to_fdt64(val);
1295 return fdt_property(fdt, name, &tmp, sizeof(tmp));
1296}
1297static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
1298{
1299 return fdt_property_u32(fdt, name, val);
1300}
1301#define fdt_property_string(fdt, name, str) \
1302 fdt_property(fdt, name, str, strlen(str)+1)
1303int fdt_end_node(void *fdt);
1304int fdt_finish(void *fdt);
1305
1306/**********************************************************************/
1307/* Read-write functions */
1308/**********************************************************************/
1309
1310int fdt_create_empty_tree(void *buf, int bufsize);
1311int fdt_open_into(const void *fdt, void *buf, int bufsize);
1312int fdt_pack(void *fdt);
1313
1314/**
1315 * fdt_add_mem_rsv - add one memory reserve map entry
1316 * @fdt: pointer to the device tree blob
1317 * @address, @size: 64-bit values (native endian)
1318 *
1319 * Adds a reserve map entry to the given blob reserving a region at
1320 * address address of length size.
1321 *
1322 * This function will insert data into the reserve map and will
1323 * therefore change the indexes of some entries in the table.
1324 *
1325 * returns:
1326 * 0, on success
1327 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1328 * contain the new reservation entry
1329 * -FDT_ERR_BADMAGIC,
1330 * -FDT_ERR_BADVERSION,
1331 * -FDT_ERR_BADSTATE,
1332 * -FDT_ERR_BADSTRUCTURE,
1333 * -FDT_ERR_BADLAYOUT,
1334 * -FDT_ERR_TRUNCATED, standard meanings
1335 */
1336int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
1337
1338/**
1339 * fdt_del_mem_rsv - remove a memory reserve map entry
1340 * @fdt: pointer to the device tree blob
1341 * @n: entry to remove
1342 *
1343 * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
1344 * the blob.
1345 *
1346 * This function will delete data from the reservation table and will
1347 * therefore change the indexes of some entries in the table.
1348 *
1349 * returns:
1350 * 0, on success
1351 * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
1352 * are less than n+1 reserve map entries)
1353 * -FDT_ERR_BADMAGIC,
1354 * -FDT_ERR_BADVERSION,
1355 * -FDT_ERR_BADSTATE,
1356 * -FDT_ERR_BADSTRUCTURE,
1357 * -FDT_ERR_BADLAYOUT,
1358 * -FDT_ERR_TRUNCATED, standard meanings
1359 */
1360int fdt_del_mem_rsv(void *fdt, int n);
1361
1362/**
1363 * fdt_set_name - change the name of a given node
1364 * @fdt: pointer to the device tree blob
1365 * @nodeoffset: structure block offset of a node
1366 * @name: name to give the node
1367 *
1368 * fdt_set_name() replaces the name (including unit address, if any)
1369 * of the given node with the given string. NOTE: this function can't
1370 * efficiently check if the new name is unique amongst the given
1371 * node's siblings; results are undefined if this function is invoked
1372 * with a name equal to one of the given node's siblings.
1373 *
1374 * This function may insert or delete data from the blob, and will
1375 * therefore change the offsets of some existing nodes.
1376 *
1377 * returns:
1378 * 0, on success
1379 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
1380 * to contain the new name
1381 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1382 * -FDT_ERR_BADMAGIC,
1383 * -FDT_ERR_BADVERSION,
1384 * -FDT_ERR_BADSTATE, standard meanings
1385 */
1386int fdt_set_name(void *fdt, int nodeoffset, const char *name);
1387
1388/**
1389 * fdt_setprop - create or change a property
1390 * @fdt: pointer to the device tree blob
1391 * @nodeoffset: offset of the node whose property to change
1392 * @name: name of the property to change
1393 * @val: pointer to data to set the property value to
1394 * @len: length of the property value
1395 *
1396 * fdt_setprop() sets the value of the named property in the given
1397 * node to the given value and length, creating the property if it
1398 * does not already exist.
1399 *
1400 * This function may insert or delete data from the blob, and will
1401 * therefore change the offsets of some existing nodes.
1402 *
1403 * returns:
1404 * 0, on success
1405 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1406 * contain the new property value
1407 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1408 * -FDT_ERR_BADLAYOUT,
1409 * -FDT_ERR_BADMAGIC,
1410 * -FDT_ERR_BADVERSION,
1411 * -FDT_ERR_BADSTATE,
1412 * -FDT_ERR_BADSTRUCTURE,
1413 * -FDT_ERR_BADLAYOUT,
1414 * -FDT_ERR_TRUNCATED, standard meanings
1415 */
1416int fdt_setprop(void *fdt, int nodeoffset, const char *name,
1417 const void *val, int len);
1418
1419/**
1420 * fdt_setprop_u32 - set a property to a 32-bit integer
1421 * @fdt: pointer to the device tree blob
1422 * @nodeoffset: offset of the node whose property to change
1423 * @name: name of the property to change
1424 * @val: 32-bit integer value for the property (native endian)
1425 *
1426 * fdt_setprop_u32() sets the value of the named property in the given
1427 * node to the given 32-bit integer value (converting to big-endian if
1428 * necessary), or creates a new property with that value if it does
1429 * not already exist.
1430 *
1431 * This function may insert or delete data from the blob, and will
1432 * therefore change the offsets of some existing nodes.
1433 *
1434 * returns:
1435 * 0, on success
1436 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1437 * contain the new property value
1438 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1439 * -FDT_ERR_BADLAYOUT,
1440 * -FDT_ERR_BADMAGIC,
1441 * -FDT_ERR_BADVERSION,
1442 * -FDT_ERR_BADSTATE,
1443 * -FDT_ERR_BADSTRUCTURE,
1444 * -FDT_ERR_BADLAYOUT,
1445 * -FDT_ERR_TRUNCATED, standard meanings
1446 */
1447static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
1448 uint32_t val)
1449{
1450 fdt32_t tmp = cpu_to_fdt32(val);
1451 return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1452}
1453
1454/**
1455 * fdt_setprop_u64 - set a property to a 64-bit integer
1456 * @fdt: pointer to the device tree blob
1457 * @nodeoffset: offset of the node whose property to change
1458 * @name: name of the property to change
1459 * @val: 64-bit integer value for the property (native endian)
1460 *
1461 * fdt_setprop_u64() sets the value of the named property in the given
1462 * node to the given 64-bit integer value (converting to big-endian if
1463 * necessary), or creates a new property with that value if it does
1464 * not already exist.
1465 *
1466 * This function may insert or delete data from the blob, and will
1467 * therefore change the offsets of some existing nodes.
1468 *
1469 * returns:
1470 * 0, on success
1471 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1472 * contain the new property value
1473 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1474 * -FDT_ERR_BADLAYOUT,
1475 * -FDT_ERR_BADMAGIC,
1476 * -FDT_ERR_BADVERSION,
1477 * -FDT_ERR_BADSTATE,
1478 * -FDT_ERR_BADSTRUCTURE,
1479 * -FDT_ERR_BADLAYOUT,
1480 * -FDT_ERR_TRUNCATED, standard meanings
1481 */
1482static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
1483 uint64_t val)
1484{
1485 fdt64_t tmp = cpu_to_fdt64(val);
1486 return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1487}
1488
1489/**
1490 * fdt_setprop_cell - set a property to a single cell value
1491 *
1492 * This is an alternative name for fdt_setprop_u32()
1493 */
1494static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
1495 uint32_t val)
1496{
1497 return fdt_setprop_u32(fdt, nodeoffset, name, val);
1498}
1499
1500/**
1501 * fdt_setprop_string - set a property to a string value
1502 * @fdt: pointer to the device tree blob
1503 * @nodeoffset: offset of the node whose property to change
1504 * @name: name of the property to change
1505 * @str: string value for the property
1506 *
1507 * fdt_setprop_string() sets the value of the named property in the
1508 * given node to the given string value (using the length of the
1509 * string to determine the new length of the property), or creates a
1510 * new property with that value if it does not already exist.
1511 *
1512 * This function may insert or delete data from the blob, and will
1513 * therefore change the offsets of some existing nodes.
1514 *
1515 * returns:
1516 * 0, on success
1517 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1518 * contain the new property value
1519 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1520 * -FDT_ERR_BADLAYOUT,
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
1527 */
1528#define fdt_setprop_string(fdt, nodeoffset, name, str) \
1529 fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
1530
1531/**
1532 * fdt_appendprop - append to or create a property
1533 * @fdt: pointer to the device tree blob
1534 * @nodeoffset: offset of the node whose property to change
1535 * @name: name of the property to append to
1536 * @val: pointer to data to append to the property value
1537 * @len: length of the data to append to the property value
1538 *
1539 * fdt_appendprop() appends the value to the named property in the
1540 * given node, creating the property if it does not already exist.
1541 *
1542 * This function may insert data into the blob, and will therefore
1543 * change the offsets of some existing nodes.
1544 *
1545 * returns:
1546 * 0, on success
1547 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1548 * contain the new property value
1549 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1550 * -FDT_ERR_BADLAYOUT,
1551 * -FDT_ERR_BADMAGIC,
1552 * -FDT_ERR_BADVERSION,
1553 * -FDT_ERR_BADSTATE,
1554 * -FDT_ERR_BADSTRUCTURE,
1555 * -FDT_ERR_BADLAYOUT,
1556 * -FDT_ERR_TRUNCATED, standard meanings
1557 */
1558int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
1559 const void *val, int len);
1560
1561/**
1562 * fdt_appendprop_u32 - append a 32-bit integer value to a property
1563 * @fdt: pointer to the device tree blob
1564 * @nodeoffset: offset of the node whose property to change
1565 * @name: name of the property to change
1566 * @val: 32-bit integer value to append to the property (native endian)
1567 *
1568 * fdt_appendprop_u32() appends the given 32-bit integer value
1569 * (converting to big-endian if necessary) to the value of the named
1570 * property in the given node, or creates a new property with that
1571 * value if it does not already exist.
1572 *
1573 * This function may insert data into the blob, and will therefore
1574 * change the offsets of some existing nodes.
1575 *
1576 * returns:
1577 * 0, on success
1578 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1579 * contain the new property value
1580 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1581 * -FDT_ERR_BADLAYOUT,
1582 * -FDT_ERR_BADMAGIC,
1583 * -FDT_ERR_BADVERSION,
1584 * -FDT_ERR_BADSTATE,
1585 * -FDT_ERR_BADSTRUCTURE,
1586 * -FDT_ERR_BADLAYOUT,
1587 * -FDT_ERR_TRUNCATED, standard meanings
1588 */
1589static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
1590 const char *name, uint32_t val)
1591{
1592 fdt32_t tmp = cpu_to_fdt32(val);
1593 return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1594}
1595
1596/**
1597 * fdt_appendprop_u64 - append a 64-bit integer value to a property
1598 * @fdt: pointer to the device tree blob
1599 * @nodeoffset: offset of the node whose property to change
1600 * @name: name of the property to change
1601 * @val: 64-bit integer value to append to the property (native endian)
1602 *
1603 * fdt_appendprop_u64() appends the given 64-bit integer value
1604 * (converting to big-endian if necessary) to the value of the named
1605 * property in the given node, or creates a new property with that
1606 * value if it does not already exist.
1607 *
1608 * This function may insert data into the blob, and will therefore
1609 * change the offsets of some existing nodes.
1610 *
1611 * returns:
1612 * 0, on success
1613 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1614 * contain the new property value
1615 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1616 * -FDT_ERR_BADLAYOUT,
1617 * -FDT_ERR_BADMAGIC,
1618 * -FDT_ERR_BADVERSION,
1619 * -FDT_ERR_BADSTATE,
1620 * -FDT_ERR_BADSTRUCTURE,
1621 * -FDT_ERR_BADLAYOUT,
1622 * -FDT_ERR_TRUNCATED, standard meanings
1623 */
1624static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
1625 const char *name, uint64_t val)
1626{
1627 fdt64_t tmp = cpu_to_fdt64(val);
1628 return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1629}
1630
1631/**
1632 * fdt_appendprop_cell - append a single cell value to a property
1633 *
1634 * This is an alternative name for fdt_appendprop_u32()
1635 */
1636static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
1637 const char *name, uint32_t val)
1638{
1639 return fdt_appendprop_u32(fdt, nodeoffset, name, val);
1640}
1641
1642/**
1643 * fdt_appendprop_string - append a string to a property
1644 * @fdt: pointer to the device tree blob
1645 * @nodeoffset: offset of the node whose property to change
1646 * @name: name of the property to change
1647 * @str: string value to append to the property
1648 *
1649 * fdt_appendprop_string() appends the given string to the value of
1650 * the named property in the given node, or creates a new property
1651 * with that value if it does not already exist.
1652 *
1653 * This function may insert data into the blob, and will therefore
1654 * change the offsets of some existing nodes.
1655 *
1656 * returns:
1657 * 0, on success
1658 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1659 * contain the new property value
1660 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1661 * -FDT_ERR_BADLAYOUT,
1662 * -FDT_ERR_BADMAGIC,
1663 * -FDT_ERR_BADVERSION,
1664 * -FDT_ERR_BADSTATE,
1665 * -FDT_ERR_BADSTRUCTURE,
1666 * -FDT_ERR_BADLAYOUT,
1667 * -FDT_ERR_TRUNCATED, standard meanings
1668 */
1669#define fdt_appendprop_string(fdt, nodeoffset, name, str) \
1670 fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
1671
1672/**
1673 * fdt_delprop - delete a property
1674 * @fdt: pointer to the device tree blob
1675 * @nodeoffset: offset of the node whose property to nop
1676 * @name: name of the property to nop
1677 *
1678 * fdt_del_property() will delete the given property.
1679 *
1680 * This function will delete data from the blob, and will therefore
1681 * change the offsets of some existing nodes.
1682 *
1683 * returns:
1684 * 0, on success
1685 * -FDT_ERR_NOTFOUND, node does not have the named property
1686 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1687 * -FDT_ERR_BADLAYOUT,
1688 * -FDT_ERR_BADMAGIC,
1689 * -FDT_ERR_BADVERSION,
1690 * -FDT_ERR_BADSTATE,
1691 * -FDT_ERR_BADSTRUCTURE,
1692 * -FDT_ERR_TRUNCATED, standard meanings
1693 */
1694int fdt_delprop(void *fdt, int nodeoffset, const char *name);
1695
1696/**
1697 * fdt_add_subnode_namelen - creates a new node based on substring
1698 * @fdt: pointer to the device tree blob
1699 * @parentoffset: structure block offset of a node
1700 * @name: name of the subnode to locate
1701 * @namelen: number of characters of name to consider
1702 *
1703 * Identical to fdt_add_subnode(), but use only the first namelen
1704 * characters of name as the name of the new node. This is useful for
1705 * creating subnodes based on a portion of a larger string, such as a
1706 * full path.
1707 */
1708int fdt_add_subnode_namelen(void *fdt, int parentoffset,
1709 const char *name, int namelen);
1710
1711/**
1712 * fdt_add_subnode - creates a new node
1713 * @fdt: pointer to the device tree blob
1714 * @parentoffset: structure block offset of a node
1715 * @name: name of the subnode to locate
1716 *
1717 * fdt_add_subnode() creates a new node as a subnode of the node at
1718 * structure block offset parentoffset, with the given name (which
1719 * should include the unit address, if any).
1720 *
1721 * This function will insert data into the blob, and will therefore
1722 * change the offsets of some existing nodes.
1723
1724 * returns:
1725 * structure block offset of the created nodeequested subnode (>=0), on
1726 * success
1727 * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
1728 * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
1729 * tag
1730 * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
1731 * the given name
1732 * -FDT_ERR_NOSPACE, if there is insufficient free space in the
1733 * blob to contain the new node
1734 * -FDT_ERR_NOSPACE
1735 * -FDT_ERR_BADLAYOUT
1736 * -FDT_ERR_BADMAGIC,
1737 * -FDT_ERR_BADVERSION,
1738 * -FDT_ERR_BADSTATE,
1739 * -FDT_ERR_BADSTRUCTURE,
1740 * -FDT_ERR_TRUNCATED, standard meanings.
1741 */
1742int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
1743
1744/**
1745 * fdt_del_node - delete a node (subtree)
1746 * @fdt: pointer to the device tree blob
1747 * @nodeoffset: offset of the node to nop
1748 *
1749 * fdt_del_node() will remove the given node, including all its
1750 * subnodes if any, from the blob.
1751 *
1752 * This function will delete data from the blob, and will therefore
1753 * change the offsets of some existing nodes.
1754 *
1755 * returns:
1756 * 0, on success
1757 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1758 * -FDT_ERR_BADLAYOUT,
1759 * -FDT_ERR_BADMAGIC,
1760 * -FDT_ERR_BADVERSION,
1761 * -FDT_ERR_BADSTATE,
1762 * -FDT_ERR_BADSTRUCTURE,
1763 * -FDT_ERR_TRUNCATED, standard meanings
1764 */
1765int fdt_del_node(void *fdt, int nodeoffset);
1766
1767/**
1768 * fdt_overlay_apply - Applies a DT overlay on a base DT
1769 * @fdt: pointer to the base device tree blob
1770 * @fdto: pointer to the device tree overlay blob
1771 *
1772 * fdt_overlay_apply() will apply the given device tree overlay on the
1773 * given base device tree.
1774 *
1775 * Expect the base device tree to be modified, even if the function
1776 * returns an error.
1777 *
1778 * returns:
1779 * 0, on success
1780 * -FDT_ERR_NOSPACE, there's not enough space in the base device tree
1781 * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or
1782 * properties in the base DT
1783 * -FDT_ERR_BADPHANDLE,
1784 * -FDT_ERR_BADOVERLAY,
1785 * -FDT_ERR_NOPHANDLES,
1786 * -FDT_ERR_INTERNAL,
1787 * -FDT_ERR_BADLAYOUT,
1788 * -FDT_ERR_BADMAGIC,
1789 * -FDT_ERR_BADOFFSET,
1790 * -FDT_ERR_BADPATH,
1791 * -FDT_ERR_BADVERSION,
1792 * -FDT_ERR_BADSTRUCTURE,
1793 * -FDT_ERR_BADSTATE,
1794 * -FDT_ERR_TRUNCATED, standard meanings
1795 */
1796int fdt_overlay_apply(void *fdt, void *fdto);
1797
1798/**********************************************************************/
1799/* Debugging / informational functions */
1800/**********************************************************************/
1801
1802const char *fdt_strerror(int errval);
1803
1804#endif /* _LIBFDT_H */