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