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