1*17f326ebSJerome Forissier /* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
201d6a9daSBryan O'Donoghue #ifndef LIBFDT_H
301d6a9daSBryan O'Donoghue #define LIBFDT_H
4b908c675SJens Wiklander /*
5b908c675SJens Wiklander * libfdt - Flat Device Tree manipulation
6b908c675SJens Wiklander * Copyright (C) 2006 David Gibson, IBM Corporation.
7b908c675SJens Wiklander */
8b908c675SJens Wiklander
9b908c675SJens Wiklander #include <libfdt_env.h>
10b908c675SJens Wiklander #include <fdt.h>
11b908c675SJens Wiklander
1201d6a9daSBryan O'Donoghue #define FDT_FIRST_SUPPORTED_VERSION 0x02
13b908c675SJens Wiklander #define FDT_LAST_SUPPORTED_VERSION 0x11
14b908c675SJens Wiklander
15b908c675SJens Wiklander /* Error codes: informative error codes */
16b908c675SJens Wiklander #define FDT_ERR_NOTFOUND 1
17b908c675SJens Wiklander /* FDT_ERR_NOTFOUND: The requested node or property does not exist */
18b908c675SJens Wiklander #define FDT_ERR_EXISTS 2
1901d6a9daSBryan O'Donoghue /* FDT_ERR_EXISTS: Attempted to create a node or property which
20b908c675SJens Wiklander * already exists */
21b908c675SJens Wiklander #define FDT_ERR_NOSPACE 3
22b908c675SJens Wiklander /* FDT_ERR_NOSPACE: Operation needed to expand the device
23b908c675SJens Wiklander * tree, but its buffer did not have sufficient space to
24b908c675SJens Wiklander * contain the expanded tree. Use fdt_open_into() to move the
25b908c675SJens Wiklander * device tree to a buffer with more space. */
26b908c675SJens Wiklander
27b908c675SJens Wiklander /* Error codes: codes for bad parameters */
28b908c675SJens Wiklander #define FDT_ERR_BADOFFSET 4
29b908c675SJens Wiklander /* FDT_ERR_BADOFFSET: Function was passed a structure block
30b908c675SJens Wiklander * offset which is out-of-bounds, or which points to an
31b908c675SJens Wiklander * unsuitable part of the structure for the operation. */
32b908c675SJens Wiklander #define FDT_ERR_BADPATH 5
33b908c675SJens Wiklander /* FDT_ERR_BADPATH: Function was passed a badly formatted path
34b908c675SJens Wiklander * (e.g. missing a leading / for a function which requires an
35b908c675SJens Wiklander * absolute path) */
36b908c675SJens Wiklander #define FDT_ERR_BADPHANDLE 6
3701d6a9daSBryan O'Donoghue /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.
3801d6a9daSBryan O'Donoghue * This can be caused either by an invalid phandle property
3901d6a9daSBryan O'Donoghue * length, or the phandle value was either 0 or -1, which are
4001d6a9daSBryan O'Donoghue * not permitted. */
41b908c675SJens Wiklander #define FDT_ERR_BADSTATE 7
42b908c675SJens Wiklander /* FDT_ERR_BADSTATE: Function was passed an incomplete device
43b908c675SJens Wiklander * tree created by the sequential-write functions, which is
44b908c675SJens Wiklander * not sufficiently complete for the requested operation. */
45b908c675SJens Wiklander
46b908c675SJens Wiklander /* Error codes: codes for bad device tree blobs */
47b908c675SJens Wiklander #define FDT_ERR_TRUNCATED 8
48*17f326ebSJerome Forissier /* FDT_ERR_TRUNCATED: FDT or a sub-block is improperly
49*17f326ebSJerome Forissier * terminated (overflows, goes outside allowed bounds, or
50*17f326ebSJerome Forissier * isn't properly terminated). */
51b908c675SJens Wiklander #define FDT_ERR_BADMAGIC 9
52b908c675SJens Wiklander /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
53b908c675SJens Wiklander * device tree at all - it is missing the flattened device
54b908c675SJens Wiklander * tree magic number. */
55b908c675SJens Wiklander #define FDT_ERR_BADVERSION 10
56b908c675SJens Wiklander /* FDT_ERR_BADVERSION: Given device tree has a version which
57b908c675SJens Wiklander * can't be handled by the requested operation. For
58b908c675SJens Wiklander * read-write functions, this may mean that fdt_open_into() is
59b908c675SJens Wiklander * required to convert the tree to the expected version. */
60b908c675SJens Wiklander #define FDT_ERR_BADSTRUCTURE 11
61b908c675SJens Wiklander /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
62b908c675SJens Wiklander * structure block or other serious error (e.g. misnested
63b908c675SJens Wiklander * nodes, or subnodes preceding properties). */
64b908c675SJens Wiklander #define FDT_ERR_BADLAYOUT 12
65b908c675SJens Wiklander /* FDT_ERR_BADLAYOUT: For read-write functions, the given
66b908c675SJens Wiklander * device tree has it's sub-blocks in an order that the
67b908c675SJens Wiklander * function can't handle (memory reserve map, then structure,
68b908c675SJens Wiklander * then strings). Use fdt_open_into() to reorganize the tree
69b908c675SJens Wiklander * into a form suitable for the read-write operations. */
70b908c675SJens Wiklander
71b908c675SJens Wiklander /* "Can't happen" error indicating a bug in libfdt */
72b908c675SJens Wiklander #define FDT_ERR_INTERNAL 13
73b908c675SJens Wiklander /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
74b908c675SJens Wiklander * Should never be returned, if it is, it indicates a bug in
75b908c675SJens Wiklander * libfdt itself. */
76b908c675SJens Wiklander
77b908c675SJens Wiklander /* Errors in device tree content */
78b908c675SJens Wiklander #define FDT_ERR_BADNCELLS 14
79b908c675SJens Wiklander /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
80b908c675SJens Wiklander * or similar property with a bad format or value */
81b908c675SJens Wiklander
8201d6a9daSBryan O'Donoghue #define FDT_ERR_BADVALUE 15
8301d6a9daSBryan O'Donoghue /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
8401d6a9daSBryan O'Donoghue * value. For example: a property expected to contain a string list
8501d6a9daSBryan O'Donoghue * is not NUL-terminated within the length of its value. */
8601d6a9daSBryan O'Donoghue
8701d6a9daSBryan O'Donoghue #define FDT_ERR_BADOVERLAY 16
8801d6a9daSBryan O'Donoghue /* FDT_ERR_BADOVERLAY: The device tree overlay, while
8901d6a9daSBryan O'Donoghue * correctly structured, cannot be applied due to some
9001d6a9daSBryan O'Donoghue * unexpected or missing value, property or node. */
9101d6a9daSBryan O'Donoghue
9201d6a9daSBryan O'Donoghue #define FDT_ERR_NOPHANDLES 17
9301d6a9daSBryan O'Donoghue /* FDT_ERR_NOPHANDLES: The device tree doesn't have any
9401d6a9daSBryan O'Donoghue * phandle available anymore without causing an overflow */
9501d6a9daSBryan O'Donoghue
96*17f326ebSJerome Forissier #define FDT_ERR_BADFLAGS 18
97*17f326ebSJerome Forissier /* FDT_ERR_BADFLAGS: The function was passed a flags field that
98*17f326ebSJerome Forissier * contains invalid flags or an invalid combination of flags. */
99*17f326ebSJerome Forissier
100*17f326ebSJerome Forissier #define FDT_ERR_MAX 18
101*17f326ebSJerome Forissier
102*17f326ebSJerome Forissier /* constants */
103*17f326ebSJerome Forissier #define FDT_MAX_PHANDLE 0xfffffffe
104*17f326ebSJerome Forissier /* Valid values for phandles range from 1 to 2^32-2. */
105b908c675SJens Wiklander
106b908c675SJens Wiklander /**********************************************************************/
107b908c675SJens Wiklander /* Low-level functions (you probably don't need these) */
108b908c675SJens Wiklander /**********************************************************************/
109b908c675SJens Wiklander
11001d6a9daSBryan O'Donoghue #ifndef SWIG /* This function is not useful in Python */
111b908c675SJens Wiklander const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
11201d6a9daSBryan O'Donoghue #endif
fdt_offset_ptr_w(void * fdt,int offset,int checklen)113b908c675SJens Wiklander static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
114b908c675SJens Wiklander {
115b908c675SJens Wiklander return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
116b908c675SJens Wiklander }
117b908c675SJens Wiklander
118b908c675SJens Wiklander uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
119b908c675SJens Wiklander
120*17f326ebSJerome Forissier /*
121*17f326ebSJerome Forissier * Alignment helpers:
122*17f326ebSJerome Forissier * These helpers access words from a device tree blob. They're
123*17f326ebSJerome Forissier * built to work even with unaligned pointers on platforms (ike
124*17f326ebSJerome Forissier * ARM) that don't like unaligned loads and stores
125*17f326ebSJerome Forissier */
126*17f326ebSJerome Forissier
fdt32_ld(const fdt32_t * p)127*17f326ebSJerome Forissier static inline uint32_t fdt32_ld(const fdt32_t *p)
128*17f326ebSJerome Forissier {
129*17f326ebSJerome Forissier const uint8_t *bp = (const uint8_t *)p;
130*17f326ebSJerome Forissier
131*17f326ebSJerome Forissier return ((uint32_t)bp[0] << 24)
132*17f326ebSJerome Forissier | ((uint32_t)bp[1] << 16)
133*17f326ebSJerome Forissier | ((uint32_t)bp[2] << 8)
134*17f326ebSJerome Forissier | bp[3];
135*17f326ebSJerome Forissier }
136*17f326ebSJerome Forissier
fdt32_st(void * property,uint32_t value)137*17f326ebSJerome Forissier static inline void fdt32_st(void *property, uint32_t value)
138*17f326ebSJerome Forissier {
139*17f326ebSJerome Forissier uint8_t *bp = property;
140*17f326ebSJerome Forissier
141*17f326ebSJerome Forissier bp[0] = value >> 24;
142*17f326ebSJerome Forissier bp[1] = (value >> 16) & 0xff;
143*17f326ebSJerome Forissier bp[2] = (value >> 8) & 0xff;
144*17f326ebSJerome Forissier bp[3] = value & 0xff;
145*17f326ebSJerome Forissier }
146*17f326ebSJerome Forissier
fdt64_ld(const fdt64_t * p)147*17f326ebSJerome Forissier static inline uint64_t fdt64_ld(const fdt64_t *p)
148*17f326ebSJerome Forissier {
149*17f326ebSJerome Forissier const uint8_t *bp = (const uint8_t *)p;
150*17f326ebSJerome Forissier
151*17f326ebSJerome Forissier return ((uint64_t)bp[0] << 56)
152*17f326ebSJerome Forissier | ((uint64_t)bp[1] << 48)
153*17f326ebSJerome Forissier | ((uint64_t)bp[2] << 40)
154*17f326ebSJerome Forissier | ((uint64_t)bp[3] << 32)
155*17f326ebSJerome Forissier | ((uint64_t)bp[4] << 24)
156*17f326ebSJerome Forissier | ((uint64_t)bp[5] << 16)
157*17f326ebSJerome Forissier | ((uint64_t)bp[6] << 8)
158*17f326ebSJerome Forissier | bp[7];
159*17f326ebSJerome Forissier }
160*17f326ebSJerome Forissier
fdt64_st(void * property,uint64_t value)161*17f326ebSJerome Forissier static inline void fdt64_st(void *property, uint64_t value)
162*17f326ebSJerome Forissier {
163*17f326ebSJerome Forissier uint8_t *bp = property;
164*17f326ebSJerome Forissier
165*17f326ebSJerome Forissier bp[0] = value >> 56;
166*17f326ebSJerome Forissier bp[1] = (value >> 48) & 0xff;
167*17f326ebSJerome Forissier bp[2] = (value >> 40) & 0xff;
168*17f326ebSJerome Forissier bp[3] = (value >> 32) & 0xff;
169*17f326ebSJerome Forissier bp[4] = (value >> 24) & 0xff;
170*17f326ebSJerome Forissier bp[5] = (value >> 16) & 0xff;
171*17f326ebSJerome Forissier bp[6] = (value >> 8) & 0xff;
172*17f326ebSJerome Forissier bp[7] = value & 0xff;
173*17f326ebSJerome Forissier }
174*17f326ebSJerome Forissier
175b908c675SJens Wiklander /**********************************************************************/
176b908c675SJens Wiklander /* Traversal functions */
177b908c675SJens Wiklander /**********************************************************************/
178b908c675SJens Wiklander
179b908c675SJens Wiklander int fdt_next_node(const void *fdt, int offset, int *depth);
180b908c675SJens Wiklander
181b908c675SJens Wiklander /**
182b908c675SJens Wiklander * fdt_first_subnode() - get offset of first direct subnode
183b908c675SJens Wiklander *
184b908c675SJens Wiklander * @fdt: FDT blob
185b908c675SJens Wiklander * @offset: Offset of node to check
186b908c675SJens Wiklander * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
187b908c675SJens Wiklander */
188b908c675SJens Wiklander int fdt_first_subnode(const void *fdt, int offset);
189b908c675SJens Wiklander
190b908c675SJens Wiklander /**
191b908c675SJens Wiklander * fdt_next_subnode() - get offset of next direct subnode
192b908c675SJens Wiklander *
193b908c675SJens Wiklander * After first calling fdt_first_subnode(), call this function repeatedly to
194b908c675SJens Wiklander * get direct subnodes of a parent node.
195b908c675SJens Wiklander *
196b908c675SJens Wiklander * @fdt: FDT blob
197b908c675SJens Wiklander * @offset: Offset of previous subnode
198b908c675SJens Wiklander * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
199b908c675SJens Wiklander * subnodes
200b908c675SJens Wiklander */
201b908c675SJens Wiklander int fdt_next_subnode(const void *fdt, int offset);
202b908c675SJens Wiklander
20301d6a9daSBryan O'Donoghue /**
20401d6a9daSBryan O'Donoghue * fdt_for_each_subnode - iterate over all subnodes of a parent
20501d6a9daSBryan O'Donoghue *
20601d6a9daSBryan O'Donoghue * @node: child node (int, lvalue)
20701d6a9daSBryan O'Donoghue * @fdt: FDT blob (const void *)
20801d6a9daSBryan O'Donoghue * @parent: parent node (int)
20901d6a9daSBryan O'Donoghue *
21001d6a9daSBryan O'Donoghue * This is actually a wrapper around a for loop and would be used like so:
21101d6a9daSBryan O'Donoghue *
21201d6a9daSBryan O'Donoghue * fdt_for_each_subnode(node, fdt, parent) {
21301d6a9daSBryan O'Donoghue * Use node
21401d6a9daSBryan O'Donoghue * ...
21501d6a9daSBryan O'Donoghue * }
21601d6a9daSBryan O'Donoghue *
217*17f326ebSJerome Forissier * if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) {
21801d6a9daSBryan O'Donoghue * Error handling
21901d6a9daSBryan O'Donoghue * }
22001d6a9daSBryan O'Donoghue *
22101d6a9daSBryan O'Donoghue * Note that this is implemented as a macro and @node is used as
22201d6a9daSBryan O'Donoghue * iterator in the loop. The parent variable be constant or even a
22301d6a9daSBryan O'Donoghue * literal.
22401d6a9daSBryan O'Donoghue *
22501d6a9daSBryan O'Donoghue */
22601d6a9daSBryan O'Donoghue #define fdt_for_each_subnode(node, fdt, parent) \
22701d6a9daSBryan O'Donoghue for (node = fdt_first_subnode(fdt, parent); \
22801d6a9daSBryan O'Donoghue node >= 0; \
22901d6a9daSBryan O'Donoghue node = fdt_next_subnode(fdt, node))
23001d6a9daSBryan O'Donoghue
231b908c675SJens Wiklander /**********************************************************************/
232b908c675SJens Wiklander /* General functions */
233b908c675SJens Wiklander /**********************************************************************/
234b908c675SJens Wiklander #define fdt_get_header(fdt, field) \
235*17f326ebSJerome Forissier (fdt32_ld(&((const struct fdt_header *)(fdt))->field))
236b908c675SJens Wiklander #define fdt_magic(fdt) (fdt_get_header(fdt, magic))
237b908c675SJens Wiklander #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
238b908c675SJens Wiklander #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
239b908c675SJens Wiklander #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
240b908c675SJens Wiklander #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
241b908c675SJens Wiklander #define fdt_version(fdt) (fdt_get_header(fdt, version))
242b908c675SJens Wiklander #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
243b908c675SJens Wiklander #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
244b908c675SJens Wiklander #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
245b908c675SJens Wiklander #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
246b908c675SJens Wiklander
24701d6a9daSBryan O'Donoghue #define fdt_set_hdr_(name) \
248b908c675SJens Wiklander static inline void fdt_set_##name(void *fdt, uint32_t val) \
249b908c675SJens Wiklander { \
250b908c675SJens Wiklander struct fdt_header *fdth = (struct fdt_header *)fdt; \
251b908c675SJens Wiklander fdth->name = cpu_to_fdt32(val); \
252b908c675SJens Wiklander }
253*17f326ebSJerome Forissier fdt_set_hdr_(magic);
254*17f326ebSJerome Forissier fdt_set_hdr_(totalsize);
255*17f326ebSJerome Forissier fdt_set_hdr_(off_dt_struct);
256*17f326ebSJerome Forissier fdt_set_hdr_(off_dt_strings);
257*17f326ebSJerome Forissier fdt_set_hdr_(off_mem_rsvmap);
258*17f326ebSJerome Forissier fdt_set_hdr_(version);
259*17f326ebSJerome Forissier fdt_set_hdr_(last_comp_version);
260*17f326ebSJerome Forissier fdt_set_hdr_(boot_cpuid_phys);
261*17f326ebSJerome Forissier fdt_set_hdr_(size_dt_strings);
262*17f326ebSJerome Forissier fdt_set_hdr_(size_dt_struct);
26301d6a9daSBryan O'Donoghue #undef fdt_set_hdr_
264b908c675SJens Wiklander
265b908c675SJens Wiklander /**
266*17f326ebSJerome Forissier * fdt_header_size - return the size of the tree's header
267*17f326ebSJerome Forissier * @fdt: pointer to a flattened device tree
268*17f326ebSJerome Forissier */
269*17f326ebSJerome Forissier size_t fdt_header_size_(uint32_t version);
fdt_header_size(const void * fdt)270*17f326ebSJerome Forissier static inline size_t fdt_header_size(const void *fdt)
271*17f326ebSJerome Forissier {
272*17f326ebSJerome Forissier return fdt_header_size_(fdt_version(fdt));
273*17f326ebSJerome Forissier }
274*17f326ebSJerome Forissier
275*17f326ebSJerome Forissier /**
276*17f326ebSJerome Forissier * fdt_check_header - sanity check a device tree header
277*17f326ebSJerome Forissier
278b908c675SJens Wiklander * @fdt: pointer to data which might be a flattened device tree
279b908c675SJens Wiklander *
280b908c675SJens Wiklander * fdt_check_header() checks that the given buffer contains what
281*17f326ebSJerome Forissier * appears to be a flattened device tree, and that the header contains
282*17f326ebSJerome Forissier * valid information (to the extent that can be determined from the
283*17f326ebSJerome Forissier * header alone).
284b908c675SJens Wiklander *
285b908c675SJens Wiklander * returns:
286b908c675SJens Wiklander * 0, if the buffer appears to contain a valid device tree
287b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
288b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
289*17f326ebSJerome Forissier * -FDT_ERR_BADSTATE,
290*17f326ebSJerome Forissier * -FDT_ERR_TRUNCATED, standard meanings, as above
291b908c675SJens Wiklander */
292b908c675SJens Wiklander int fdt_check_header(const void *fdt);
293b908c675SJens Wiklander
294b908c675SJens Wiklander /**
295b908c675SJens Wiklander * fdt_move - move a device tree around in memory
296b908c675SJens Wiklander * @fdt: pointer to the device tree to move
297b908c675SJens Wiklander * @buf: pointer to memory where the device is to be moved
298b908c675SJens Wiklander * @bufsize: size of the memory space at buf
299b908c675SJens Wiklander *
300b908c675SJens Wiklander * fdt_move() relocates, if possible, the device tree blob located at
301b908c675SJens Wiklander * fdt to the buffer at buf of size bufsize. The buffer may overlap
302b908c675SJens Wiklander * with the existing device tree blob at fdt. Therefore,
303b908c675SJens Wiklander * fdt_move(fdt, fdt, fdt_totalsize(fdt))
304b908c675SJens Wiklander * should always succeed.
305b908c675SJens Wiklander *
306b908c675SJens Wiklander * returns:
307b908c675SJens Wiklander * 0, on success
308b908c675SJens Wiklander * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
309b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
310b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
311b908c675SJens Wiklander * -FDT_ERR_BADSTATE, standard meanings
312b908c675SJens Wiklander */
313b908c675SJens Wiklander int fdt_move(const void *fdt, void *buf, int bufsize);
314b908c675SJens Wiklander
315b908c675SJens Wiklander /**********************************************************************/
316b908c675SJens Wiklander /* Read-only functions */
317b908c675SJens Wiklander /**********************************************************************/
318b908c675SJens Wiklander
319*17f326ebSJerome Forissier int fdt_check_full(const void *fdt, size_t bufsize);
320*17f326ebSJerome Forissier
321*17f326ebSJerome Forissier /**
322*17f326ebSJerome Forissier * fdt_get_string - retrieve a string from the strings block of a device tree
323*17f326ebSJerome Forissier * @fdt: pointer to the device tree blob
324*17f326ebSJerome Forissier * @stroffset: offset of the string within the strings block (native endian)
325*17f326ebSJerome Forissier * @lenp: optional pointer to return the string's length
326*17f326ebSJerome Forissier *
327*17f326ebSJerome Forissier * fdt_get_string() retrieves a pointer to a single string from the
328*17f326ebSJerome Forissier * strings block of the device tree blob at fdt, and optionally also
329*17f326ebSJerome Forissier * returns the string's length in *lenp.
330*17f326ebSJerome Forissier *
331*17f326ebSJerome Forissier * returns:
332*17f326ebSJerome Forissier * a pointer to the string, on success
333*17f326ebSJerome Forissier * NULL, if stroffset is out of bounds, or doesn't point to a valid string
334*17f326ebSJerome Forissier */
335*17f326ebSJerome Forissier const char *fdt_get_string(const void *fdt, int stroffset, int *lenp);
336*17f326ebSJerome Forissier
337b908c675SJens Wiklander /**
338b908c675SJens Wiklander * fdt_string - retrieve a string from the strings block of a device tree
339b908c675SJens Wiklander * @fdt: pointer to the device tree blob
340b908c675SJens Wiklander * @stroffset: offset of the string within the strings block (native endian)
341b908c675SJens Wiklander *
342b908c675SJens Wiklander * fdt_string() retrieves a pointer to a single string from the
343b908c675SJens Wiklander * strings block of the device tree blob at fdt.
344b908c675SJens Wiklander *
345b908c675SJens Wiklander * returns:
346b908c675SJens Wiklander * a pointer to the string, on success
347*17f326ebSJerome Forissier * NULL, if stroffset is out of bounds, or doesn't point to a valid string
348b908c675SJens Wiklander */
349b908c675SJens Wiklander const char *fdt_string(const void *fdt, int stroffset);
350b908c675SJens Wiklander
351b908c675SJens Wiklander /**
352*17f326ebSJerome Forissier * fdt_find_max_phandle - find and return the highest phandle in a tree
353*17f326ebSJerome Forissier * @fdt: pointer to the device tree blob
354*17f326ebSJerome Forissier * @phandle: return location for the highest phandle value found in the tree
355*17f326ebSJerome Forissier *
356*17f326ebSJerome Forissier * fdt_find_max_phandle() finds the highest phandle value in the given device
357*17f326ebSJerome Forissier * tree. The value returned in @phandle is only valid if the function returns
358*17f326ebSJerome Forissier * success.
359*17f326ebSJerome Forissier *
360*17f326ebSJerome Forissier * returns:
361*17f326ebSJerome Forissier * 0 on success or a negative error code on failure
362*17f326ebSJerome Forissier */
363*17f326ebSJerome Forissier int fdt_find_max_phandle(const void *fdt, uint32_t *phandle);
364*17f326ebSJerome Forissier
365*17f326ebSJerome Forissier /**
36601d6a9daSBryan O'Donoghue * fdt_get_max_phandle - retrieves the highest phandle in a tree
36701d6a9daSBryan O'Donoghue * @fdt: pointer to the device tree blob
36801d6a9daSBryan O'Donoghue *
36901d6a9daSBryan O'Donoghue * fdt_get_max_phandle retrieves the highest phandle in the given
37001d6a9daSBryan O'Donoghue * device tree. This will ignore badly formatted phandles, or phandles
37101d6a9daSBryan O'Donoghue * with a value of 0 or -1.
37201d6a9daSBryan O'Donoghue *
373*17f326ebSJerome Forissier * This function is deprecated in favour of fdt_find_max_phandle().
374*17f326ebSJerome Forissier *
37501d6a9daSBryan O'Donoghue * returns:
37601d6a9daSBryan O'Donoghue * the highest phandle on success
37701d6a9daSBryan O'Donoghue * 0, if no phandle was found in the device tree
37801d6a9daSBryan O'Donoghue * -1, if an error occurred
37901d6a9daSBryan O'Donoghue */
fdt_get_max_phandle(const void * fdt)380*17f326ebSJerome Forissier static inline uint32_t fdt_get_max_phandle(const void *fdt)
381*17f326ebSJerome Forissier {
382*17f326ebSJerome Forissier uint32_t phandle;
383*17f326ebSJerome Forissier int err;
384*17f326ebSJerome Forissier
385*17f326ebSJerome Forissier err = fdt_find_max_phandle(fdt, &phandle);
386*17f326ebSJerome Forissier if (err < 0)
387*17f326ebSJerome Forissier return (uint32_t)-1;
388*17f326ebSJerome Forissier
389*17f326ebSJerome Forissier return phandle;
390*17f326ebSJerome Forissier }
391*17f326ebSJerome Forissier
392*17f326ebSJerome Forissier /**
393*17f326ebSJerome Forissier * fdt_generate_phandle - return a new, unused phandle for a device tree blob
394*17f326ebSJerome Forissier * @fdt: pointer to the device tree blob
395*17f326ebSJerome Forissier * @phandle: return location for the new phandle
396*17f326ebSJerome Forissier *
397*17f326ebSJerome Forissier * Walks the device tree blob and looks for the highest phandle value. On
398*17f326ebSJerome Forissier * success, the new, unused phandle value (one higher than the previously
399*17f326ebSJerome Forissier * highest phandle value in the device tree blob) will be returned in the
400*17f326ebSJerome Forissier * @phandle parameter.
401*17f326ebSJerome Forissier *
402*17f326ebSJerome Forissier * Returns:
403*17f326ebSJerome Forissier * 0 on success or a negative error-code on failure
404*17f326ebSJerome Forissier */
405*17f326ebSJerome Forissier int fdt_generate_phandle(const void *fdt, uint32_t *phandle);
40601d6a9daSBryan O'Donoghue
40701d6a9daSBryan O'Donoghue /**
408b908c675SJens Wiklander * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
409b908c675SJens Wiklander * @fdt: pointer to the device tree blob
410b908c675SJens Wiklander *
411b908c675SJens Wiklander * Returns the number of entries in the device tree blob's memory
412b908c675SJens Wiklander * reservation map. This does not include the terminating 0,0 entry
413b908c675SJens Wiklander * or any other (0,0) entries reserved for expansion.
414b908c675SJens Wiklander *
415b908c675SJens Wiklander * returns:
416b908c675SJens Wiklander * the number of entries
417b908c675SJens Wiklander */
418b908c675SJens Wiklander int fdt_num_mem_rsv(const void *fdt);
419b908c675SJens Wiklander
420b908c675SJens Wiklander /**
421b908c675SJens Wiklander * fdt_get_mem_rsv - retrieve one memory reserve map entry
422b908c675SJens Wiklander * @fdt: pointer to the device tree blob
423b908c675SJens Wiklander * @address, @size: pointers to 64-bit variables
424b908c675SJens Wiklander *
425b908c675SJens Wiklander * On success, *address and *size will contain the address and size of
426b908c675SJens Wiklander * the n-th reserve map entry from the device tree blob, in
427b908c675SJens Wiklander * native-endian format.
428b908c675SJens Wiklander *
429b908c675SJens Wiklander * returns:
430b908c675SJens Wiklander * 0, on success
431b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
432b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
433b908c675SJens Wiklander * -FDT_ERR_BADSTATE, standard meanings
434b908c675SJens Wiklander */
435b908c675SJens Wiklander int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
436b908c675SJens Wiklander
437b908c675SJens Wiklander /**
438b908c675SJens Wiklander * fdt_subnode_offset_namelen - find a subnode based on substring
439b908c675SJens Wiklander * @fdt: pointer to the device tree blob
440b908c675SJens Wiklander * @parentoffset: structure block offset of a node
441b908c675SJens Wiklander * @name: name of the subnode to locate
442b908c675SJens Wiklander * @namelen: number of characters of name to consider
443b908c675SJens Wiklander *
444b908c675SJens Wiklander * Identical to fdt_subnode_offset(), but only examine the first
445b908c675SJens Wiklander * namelen characters of name for matching the subnode name. This is
446b908c675SJens Wiklander * useful for finding subnodes based on a portion of a larger string,
447b908c675SJens Wiklander * such as a full path.
448b908c675SJens Wiklander */
44901d6a9daSBryan O'Donoghue #ifndef SWIG /* Not available in Python */
450b908c675SJens Wiklander int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
451b908c675SJens Wiklander const char *name, int namelen);
45201d6a9daSBryan O'Donoghue #endif
453b908c675SJens Wiklander /**
454b908c675SJens Wiklander * fdt_subnode_offset - find a subnode of a given node
455b908c675SJens Wiklander * @fdt: pointer to the device tree blob
456b908c675SJens Wiklander * @parentoffset: structure block offset of a node
457b908c675SJens Wiklander * @name: name of the subnode to locate
458b908c675SJens Wiklander *
459b908c675SJens Wiklander * fdt_subnode_offset() finds a subnode of the node at structure block
460b908c675SJens Wiklander * offset parentoffset with the given name. name may include a unit
461b908c675SJens Wiklander * address, in which case fdt_subnode_offset() will find the subnode
462b908c675SJens Wiklander * with that unit address, or the unit address may be omitted, in
463b908c675SJens Wiklander * which case fdt_subnode_offset() will find an arbitrary subnode
464b908c675SJens Wiklander * whose name excluding unit address matches the given name.
465b908c675SJens Wiklander *
466b908c675SJens Wiklander * returns:
467b908c675SJens Wiklander * structure block offset of the requested subnode (>=0), on success
468b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
46901d6a9daSBryan O'Donoghue * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
47001d6a9daSBryan O'Donoghue * tag
471b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
472b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
473b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
474b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
475b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings.
476b908c675SJens Wiklander */
477b908c675SJens Wiklander int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
478b908c675SJens Wiklander
479b908c675SJens Wiklander /**
48001d6a9daSBryan O'Donoghue * fdt_path_offset_namelen - find a tree node by its full path
48101d6a9daSBryan O'Donoghue * @fdt: pointer to the device tree blob
48201d6a9daSBryan O'Donoghue * @path: full path of the node to locate
48301d6a9daSBryan O'Donoghue * @namelen: number of characters of path to consider
48401d6a9daSBryan O'Donoghue *
48501d6a9daSBryan O'Donoghue * Identical to fdt_path_offset(), but only consider the first namelen
48601d6a9daSBryan O'Donoghue * characters of path as the path name.
48701d6a9daSBryan O'Donoghue */
48801d6a9daSBryan O'Donoghue #ifndef SWIG /* Not available in Python */
48901d6a9daSBryan O'Donoghue int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
49001d6a9daSBryan O'Donoghue #endif
49101d6a9daSBryan O'Donoghue
49201d6a9daSBryan O'Donoghue /**
493b908c675SJens Wiklander * fdt_path_offset - find a tree node by its full path
494b908c675SJens Wiklander * @fdt: pointer to the device tree blob
495b908c675SJens Wiklander * @path: full path of the node to locate
496b908c675SJens Wiklander *
497b908c675SJens Wiklander * fdt_path_offset() finds a node of a given path in the device tree.
498b908c675SJens Wiklander * Each path component may omit the unit address portion, but the
499b908c675SJens Wiklander * results of this are undefined if any such path component is
500b908c675SJens Wiklander * ambiguous (that is if there are multiple nodes at the relevant
501b908c675SJens Wiklander * level matching the given component, differentiated only by unit
502b908c675SJens Wiklander * address).
503b908c675SJens Wiklander *
504b908c675SJens Wiklander * returns:
50501d6a9daSBryan O'Donoghue * structure block offset of the node with the requested path (>=0), on
50601d6a9daSBryan O'Donoghue * success
507b908c675SJens Wiklander * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
508b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, if the requested node does not exist
509b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
510b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
511b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
512b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
513b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings.
514b908c675SJens Wiklander */
515b908c675SJens Wiklander int fdt_path_offset(const void *fdt, const char *path);
516b908c675SJens Wiklander
517b908c675SJens Wiklander /**
518b908c675SJens Wiklander * fdt_get_name - retrieve the name of a given node
519b908c675SJens Wiklander * @fdt: pointer to the device tree blob
520b908c675SJens Wiklander * @nodeoffset: structure block offset of the starting node
521b908c675SJens Wiklander * @lenp: pointer to an integer variable (will be overwritten) or NULL
522b908c675SJens Wiklander *
523b908c675SJens Wiklander * fdt_get_name() retrieves the name (including unit address) of the
524b908c675SJens Wiklander * device tree node at structure block offset nodeoffset. If lenp is
525b908c675SJens Wiklander * non-NULL, the length of this name is also returned, in the integer
526b908c675SJens Wiklander * pointed to by lenp.
527b908c675SJens Wiklander *
528b908c675SJens Wiklander * returns:
529b908c675SJens Wiklander * pointer to the node's name, on success
53001d6a9daSBryan O'Donoghue * If lenp is non-NULL, *lenp contains the length of that name
53101d6a9daSBryan O'Donoghue * (>=0)
532b908c675SJens Wiklander * NULL, on error
533b908c675SJens Wiklander * if lenp is non-NULL *lenp contains an error code (<0):
53401d6a9daSBryan O'Donoghue * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
53501d6a9daSBryan O'Donoghue * tag
536b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
537b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
538b908c675SJens Wiklander * -FDT_ERR_BADSTATE, standard meanings
539b908c675SJens Wiklander */
540b908c675SJens Wiklander const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
541b908c675SJens Wiklander
542b908c675SJens Wiklander /**
543b908c675SJens Wiklander * fdt_first_property_offset - find the offset of a node's first property
544b908c675SJens Wiklander * @fdt: pointer to the device tree blob
545b908c675SJens Wiklander * @nodeoffset: structure block offset of a node
546b908c675SJens Wiklander *
547b908c675SJens Wiklander * fdt_first_property_offset() finds the first property of the node at
548b908c675SJens Wiklander * the given structure block offset.
549b908c675SJens Wiklander *
550b908c675SJens Wiklander * returns:
551b908c675SJens Wiklander * structure block offset of the property (>=0), on success
552b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, if the requested node has no properties
553b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
554b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
555b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
556b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
557b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
558b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings.
559b908c675SJens Wiklander */
560b908c675SJens Wiklander int fdt_first_property_offset(const void *fdt, int nodeoffset);
561b908c675SJens Wiklander
562b908c675SJens Wiklander /**
563b908c675SJens Wiklander * fdt_next_property_offset - step through a node's properties
564b908c675SJens Wiklander * @fdt: pointer to the device tree blob
565b908c675SJens Wiklander * @offset: structure block offset of a property
566b908c675SJens Wiklander *
567b908c675SJens Wiklander * fdt_next_property_offset() finds the property immediately after the
568b908c675SJens Wiklander * one at the given structure block offset. This will be a property
569b908c675SJens Wiklander * of the same node as the given property.
570b908c675SJens Wiklander *
571b908c675SJens Wiklander * returns:
572b908c675SJens Wiklander * structure block offset of the next property (>=0), on success
573b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, if the given property is the last in its node
574b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
575b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
576b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
577b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
578b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
579b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings.
580b908c675SJens Wiklander */
581b908c675SJens Wiklander int fdt_next_property_offset(const void *fdt, int offset);
582b908c675SJens Wiklander
583b908c675SJens Wiklander /**
58401d6a9daSBryan O'Donoghue * fdt_for_each_property_offset - iterate over all properties of a node
58501d6a9daSBryan O'Donoghue *
58601d6a9daSBryan O'Donoghue * @property_offset: property offset (int, lvalue)
58701d6a9daSBryan O'Donoghue * @fdt: FDT blob (const void *)
58801d6a9daSBryan O'Donoghue * @node: node offset (int)
58901d6a9daSBryan O'Donoghue *
59001d6a9daSBryan O'Donoghue * This is actually a wrapper around a for loop and would be used like so:
59101d6a9daSBryan O'Donoghue *
59201d6a9daSBryan O'Donoghue * fdt_for_each_property_offset(property, fdt, node) {
59301d6a9daSBryan O'Donoghue * Use property
59401d6a9daSBryan O'Donoghue * ...
59501d6a9daSBryan O'Donoghue * }
59601d6a9daSBryan O'Donoghue *
597*17f326ebSJerome Forissier * if ((property < 0) && (property != -FDT_ERR_NOTFOUND)) {
59801d6a9daSBryan O'Donoghue * Error handling
59901d6a9daSBryan O'Donoghue * }
60001d6a9daSBryan O'Donoghue *
60101d6a9daSBryan O'Donoghue * Note that this is implemented as a macro and property is used as
60201d6a9daSBryan O'Donoghue * iterator in the loop. The node variable can be constant or even a
60301d6a9daSBryan O'Donoghue * literal.
60401d6a9daSBryan O'Donoghue */
60501d6a9daSBryan O'Donoghue #define fdt_for_each_property_offset(property, fdt, node) \
60601d6a9daSBryan O'Donoghue for (property = fdt_first_property_offset(fdt, node); \
60701d6a9daSBryan O'Donoghue property >= 0; \
60801d6a9daSBryan O'Donoghue property = fdt_next_property_offset(fdt, property))
60901d6a9daSBryan O'Donoghue
61001d6a9daSBryan O'Donoghue /**
611b908c675SJens Wiklander * fdt_get_property_by_offset - retrieve the property at a given offset
612b908c675SJens Wiklander * @fdt: pointer to the device tree blob
613b908c675SJens Wiklander * @offset: offset of the property to retrieve
614b908c675SJens Wiklander * @lenp: pointer to an integer variable (will be overwritten) or NULL
615b908c675SJens Wiklander *
616b908c675SJens Wiklander * fdt_get_property_by_offset() retrieves a pointer to the
617b908c675SJens Wiklander * fdt_property structure within the device tree blob at the given
618b908c675SJens Wiklander * offset. If lenp is non-NULL, the length of the property value is
619b908c675SJens Wiklander * also returned, in the integer pointed to by lenp.
620b908c675SJens Wiklander *
62101d6a9daSBryan O'Donoghue * Note that this code only works on device tree versions >= 16. fdt_getprop()
62201d6a9daSBryan O'Donoghue * works on all versions.
62301d6a9daSBryan O'Donoghue *
624b908c675SJens Wiklander * returns:
625b908c675SJens Wiklander * pointer to the structure representing the property
626b908c675SJens Wiklander * if lenp is non-NULL, *lenp contains the length of the property
627b908c675SJens Wiklander * value (>=0)
628b908c675SJens Wiklander * NULL, on error
629b908c675SJens Wiklander * if lenp is non-NULL, *lenp contains an error code (<0):
630b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
631b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
632b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
633b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
634b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
635b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
636b908c675SJens Wiklander */
637b908c675SJens Wiklander const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
638b908c675SJens Wiklander int offset,
639b908c675SJens Wiklander int *lenp);
640b908c675SJens Wiklander
641b908c675SJens Wiklander /**
642b908c675SJens Wiklander * fdt_get_property_namelen - find a property based on substring
643b908c675SJens Wiklander * @fdt: pointer to the device tree blob
644b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to find
645b908c675SJens Wiklander * @name: name of the property to find
646b908c675SJens Wiklander * @namelen: number of characters of name to consider
647b908c675SJens Wiklander * @lenp: pointer to an integer variable (will be overwritten) or NULL
648b908c675SJens Wiklander *
64901d6a9daSBryan O'Donoghue * Identical to fdt_get_property(), but only examine the first namelen
65001d6a9daSBryan O'Donoghue * characters of name for matching the property name.
651b908c675SJens Wiklander */
65201d6a9daSBryan O'Donoghue #ifndef SWIG /* Not available in Python */
653b908c675SJens Wiklander const struct fdt_property *fdt_get_property_namelen(const void *fdt,
654b908c675SJens Wiklander int nodeoffset,
655b908c675SJens Wiklander const char *name,
656b908c675SJens Wiklander int namelen, int *lenp);
65701d6a9daSBryan O'Donoghue #endif
658b908c675SJens Wiklander
659b908c675SJens Wiklander /**
660b908c675SJens Wiklander * fdt_get_property - find a given property in a given node
661b908c675SJens Wiklander * @fdt: pointer to the device tree blob
662b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to find
663b908c675SJens Wiklander * @name: name of the property to find
664b908c675SJens Wiklander * @lenp: pointer to an integer variable (will be overwritten) or NULL
665b908c675SJens Wiklander *
666b908c675SJens Wiklander * fdt_get_property() retrieves a pointer to the fdt_property
667b908c675SJens Wiklander * structure within the device tree blob corresponding to the property
668b908c675SJens Wiklander * named 'name' of the node at offset nodeoffset. If lenp is
669b908c675SJens Wiklander * non-NULL, the length of the property value is also returned, in the
670b908c675SJens Wiklander * integer pointed to by lenp.
671b908c675SJens Wiklander *
672b908c675SJens Wiklander * returns:
673b908c675SJens Wiklander * pointer to the structure representing the property
674b908c675SJens Wiklander * if lenp is non-NULL, *lenp contains the length of the property
675b908c675SJens Wiklander * value (>=0)
676b908c675SJens Wiklander * NULL, on error
677b908c675SJens Wiklander * if lenp is non-NULL, *lenp contains an error code (<0):
678b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, node does not have named property
67901d6a9daSBryan O'Donoghue * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
68001d6a9daSBryan O'Donoghue * tag
681b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
682b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
683b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
684b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
685b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
686b908c675SJens Wiklander */
687b908c675SJens Wiklander const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
688b908c675SJens Wiklander const char *name, int *lenp);
fdt_get_property_w(void * fdt,int nodeoffset,const char * name,int * lenp)689b908c675SJens Wiklander static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
690b908c675SJens Wiklander const char *name,
691b908c675SJens Wiklander int *lenp)
692b908c675SJens Wiklander {
693b908c675SJens Wiklander return (struct fdt_property *)(uintptr_t)
694b908c675SJens Wiklander fdt_get_property(fdt, nodeoffset, name, lenp);
695b908c675SJens Wiklander }
696b908c675SJens Wiklander
697b908c675SJens Wiklander /**
698b908c675SJens Wiklander * fdt_getprop_by_offset - retrieve the value of a property at a given offset
699b908c675SJens Wiklander * @fdt: pointer to the device tree blob
700*17f326ebSJerome Forissier * @offset: offset of the property to read
701b908c675SJens Wiklander * @namep: pointer to a string variable (will be overwritten) or NULL
702b908c675SJens Wiklander * @lenp: pointer to an integer variable (will be overwritten) or NULL
703b908c675SJens Wiklander *
704b908c675SJens Wiklander * fdt_getprop_by_offset() retrieves a pointer to the value of the
705b908c675SJens Wiklander * property at structure block offset 'offset' (this will be a pointer
706b908c675SJens Wiklander * to within the device blob itself, not a copy of the value). If
707b908c675SJens Wiklander * lenp is non-NULL, the length of the property value is also
708b908c675SJens Wiklander * returned, in the integer pointed to by lenp. If namep is non-NULL,
709b908c675SJens Wiklander * the property's namne will also be returned in the char * pointed to
710b908c675SJens Wiklander * by namep (this will be a pointer to within the device tree's string
711b908c675SJens Wiklander * block, not a new copy of the name).
712b908c675SJens Wiklander *
713b908c675SJens Wiklander * returns:
714b908c675SJens Wiklander * pointer to the property's value
715b908c675SJens Wiklander * if lenp is non-NULL, *lenp contains the length of the property
716b908c675SJens Wiklander * value (>=0)
717b908c675SJens Wiklander * if namep is non-NULL *namep contiains a pointer to the property
718b908c675SJens Wiklander * name.
719b908c675SJens Wiklander * NULL, on error
720b908c675SJens Wiklander * if lenp is non-NULL, *lenp contains an error code (<0):
721b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
722b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
723b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
724b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
725b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
726b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
727b908c675SJens Wiklander */
72801d6a9daSBryan O'Donoghue #ifndef SWIG /* This function is not useful in Python */
729b908c675SJens Wiklander const void *fdt_getprop_by_offset(const void *fdt, int offset,
730b908c675SJens Wiklander const char **namep, int *lenp);
73101d6a9daSBryan O'Donoghue #endif
732b908c675SJens Wiklander
733b908c675SJens Wiklander /**
734b908c675SJens Wiklander * fdt_getprop_namelen - get property value based on substring
735b908c675SJens Wiklander * @fdt: pointer to the device tree blob
736b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to find
737b908c675SJens Wiklander * @name: name of the property to find
738b908c675SJens Wiklander * @namelen: number of characters of name to consider
739b908c675SJens Wiklander * @lenp: pointer to an integer variable (will be overwritten) or NULL
740b908c675SJens Wiklander *
741b908c675SJens Wiklander * Identical to fdt_getprop(), but only examine the first namelen
742b908c675SJens Wiklander * characters of name for matching the property name.
743b908c675SJens Wiklander */
74401d6a9daSBryan O'Donoghue #ifndef SWIG /* Not available in Python */
745b908c675SJens Wiklander const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
746b908c675SJens Wiklander const char *name, int namelen, int *lenp);
fdt_getprop_namelen_w(void * fdt,int nodeoffset,const char * name,int namelen,int * lenp)74701d6a9daSBryan O'Donoghue static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,
74801d6a9daSBryan O'Donoghue const char *name, int namelen,
74901d6a9daSBryan O'Donoghue int *lenp)
75001d6a9daSBryan O'Donoghue {
75101d6a9daSBryan O'Donoghue return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,
75201d6a9daSBryan O'Donoghue namelen, lenp);
75301d6a9daSBryan O'Donoghue }
75401d6a9daSBryan O'Donoghue #endif
755b908c675SJens Wiklander
756b908c675SJens Wiklander /**
757b908c675SJens Wiklander * fdt_getprop - retrieve the value of a given property
758b908c675SJens Wiklander * @fdt: pointer to the device tree blob
759b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to find
760b908c675SJens Wiklander * @name: name of the property to find
761b908c675SJens Wiklander * @lenp: pointer to an integer variable (will be overwritten) or NULL
762b908c675SJens Wiklander *
763b908c675SJens Wiklander * fdt_getprop() retrieves a pointer to the value of the property
764b908c675SJens Wiklander * named 'name' of the node at offset nodeoffset (this will be a
765b908c675SJens Wiklander * pointer to within the device blob itself, not a copy of the value).
766b908c675SJens Wiklander * If lenp is non-NULL, the length of the property value is also
767b908c675SJens Wiklander * returned, in the integer pointed to by lenp.
768b908c675SJens Wiklander *
769b908c675SJens Wiklander * returns:
770b908c675SJens Wiklander * pointer to the property's value
771b908c675SJens Wiklander * if lenp is non-NULL, *lenp contains the length of the property
772b908c675SJens Wiklander * value (>=0)
773b908c675SJens Wiklander * NULL, on error
774b908c675SJens Wiklander * if lenp is non-NULL, *lenp contains an error code (<0):
775b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, node does not have named property
77601d6a9daSBryan O'Donoghue * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
77701d6a9daSBryan O'Donoghue * tag
778b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
779b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
780b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
781b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
782b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
783b908c675SJens Wiklander */
784b908c675SJens Wiklander const void *fdt_getprop(const void *fdt, int nodeoffset,
785b908c675SJens Wiklander const char *name, int *lenp);
fdt_getprop_w(void * fdt,int nodeoffset,const char * name,int * lenp)786b908c675SJens Wiklander static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
787b908c675SJens Wiklander const char *name, int *lenp)
788b908c675SJens Wiklander {
789b908c675SJens Wiklander return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
790b908c675SJens Wiklander }
791b908c675SJens Wiklander
792b908c675SJens Wiklander /**
793b908c675SJens Wiklander * fdt_get_phandle - retrieve the phandle of a given node
794b908c675SJens Wiklander * @fdt: pointer to the device tree blob
795b908c675SJens Wiklander * @nodeoffset: structure block offset of the node
796b908c675SJens Wiklander *
797b908c675SJens Wiklander * fdt_get_phandle() retrieves the phandle of the device tree node at
798b908c675SJens Wiklander * structure block offset nodeoffset.
799b908c675SJens Wiklander *
800b908c675SJens Wiklander * returns:
801b908c675SJens Wiklander * the phandle of the node at nodeoffset, on success (!= 0, != -1)
802b908c675SJens Wiklander * 0, if the node has no phandle, or another error occurs
803b908c675SJens Wiklander */
804b908c675SJens Wiklander uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
805b908c675SJens Wiklander
806b908c675SJens Wiklander /**
807b908c675SJens Wiklander * fdt_get_alias_namelen - get alias based on substring
808b908c675SJens Wiklander * @fdt: pointer to the device tree blob
809b908c675SJens Wiklander * @name: name of the alias th look up
810b908c675SJens Wiklander * @namelen: number of characters of name to consider
811b908c675SJens Wiklander *
812b908c675SJens Wiklander * Identical to fdt_get_alias(), but only examine the first namelen
813b908c675SJens Wiklander * characters of name for matching the alias name.
814b908c675SJens Wiklander */
81501d6a9daSBryan O'Donoghue #ifndef SWIG /* Not available in Python */
816b908c675SJens Wiklander const char *fdt_get_alias_namelen(const void *fdt,
817b908c675SJens Wiklander const char *name, int namelen);
81801d6a9daSBryan O'Donoghue #endif
819b908c675SJens Wiklander
820b908c675SJens Wiklander /**
82101d6a9daSBryan O'Donoghue * fdt_get_alias - retrieve the path referenced by a given alias
822b908c675SJens Wiklander * @fdt: pointer to the device tree blob
823b908c675SJens Wiklander * @name: name of the alias th look up
824b908c675SJens Wiklander *
825b908c675SJens Wiklander * fdt_get_alias() retrieves the value of a given alias. That is, the
826b908c675SJens Wiklander * value of the property named 'name' in the node /aliases.
827b908c675SJens Wiklander *
828b908c675SJens Wiklander * returns:
829b908c675SJens Wiklander * a pointer to the expansion of the alias named 'name', if it exists
830b908c675SJens Wiklander * NULL, if the given alias or the /aliases node does not exist
831b908c675SJens Wiklander */
832b908c675SJens Wiklander const char *fdt_get_alias(const void *fdt, const char *name);
833b908c675SJens Wiklander
834b908c675SJens Wiklander /**
835b908c675SJens Wiklander * fdt_get_path - determine the full path of a node
836b908c675SJens Wiklander * @fdt: pointer to the device tree blob
837b908c675SJens Wiklander * @nodeoffset: offset of the node whose path to find
838b908c675SJens Wiklander * @buf: character buffer to contain the returned path (will be overwritten)
839b908c675SJens Wiklander * @buflen: size of the character buffer at buf
840b908c675SJens Wiklander *
841b908c675SJens Wiklander * fdt_get_path() computes the full path of the node at offset
842b908c675SJens Wiklander * nodeoffset, and records that path in the buffer at buf.
843b908c675SJens Wiklander *
844b908c675SJens Wiklander * NOTE: This function is expensive, as it must scan the device tree
845b908c675SJens Wiklander * structure from the start to nodeoffset.
846b908c675SJens Wiklander *
847b908c675SJens Wiklander * returns:
848b908c675SJens Wiklander * 0, on success
849b908c675SJens Wiklander * buf contains the absolute path of the node at
850b908c675SJens Wiklander * nodeoffset, as a NUL-terminated string.
851b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
852b908c675SJens Wiklander * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
853b908c675SJens Wiklander * characters and will not fit in the given buffer.
854b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
855b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
856b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
857b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE, standard meanings
858b908c675SJens Wiklander */
859b908c675SJens Wiklander int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
860b908c675SJens Wiklander
861b908c675SJens Wiklander /**
862b908c675SJens Wiklander * fdt_supernode_atdepth_offset - find a specific ancestor of a node
863b908c675SJens Wiklander * @fdt: pointer to the device tree blob
864b908c675SJens Wiklander * @nodeoffset: offset of the node whose parent to find
865b908c675SJens Wiklander * @supernodedepth: depth of the ancestor to find
866b908c675SJens Wiklander * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
867b908c675SJens Wiklander *
868b908c675SJens Wiklander * fdt_supernode_atdepth_offset() finds an ancestor of the given node
869b908c675SJens Wiklander * at a specific depth from the root (where the root itself has depth
870b908c675SJens Wiklander * 0, its immediate subnodes depth 1 and so forth). So
871b908c675SJens Wiklander * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
872b908c675SJens Wiklander * will always return 0, the offset of the root node. If the node at
873b908c675SJens Wiklander * nodeoffset has depth D, then:
874b908c675SJens Wiklander * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
875b908c675SJens Wiklander * will return nodeoffset itself.
876b908c675SJens Wiklander *
877b908c675SJens Wiklander * NOTE: This function is expensive, as it must scan the device tree
878b908c675SJens Wiklander * structure from the start to nodeoffset.
879b908c675SJens Wiklander *
880b908c675SJens Wiklander * returns:
881b908c675SJens Wiklander * structure block offset of the node at node offset's ancestor
882b908c675SJens Wiklander * of depth supernodedepth (>=0), on success
883b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
88401d6a9daSBryan O'Donoghue * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of
88501d6a9daSBryan O'Donoghue * nodeoffset
886b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
887b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
888b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
889b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE, standard meanings
890b908c675SJens Wiklander */
891b908c675SJens Wiklander int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
892b908c675SJens Wiklander int supernodedepth, int *nodedepth);
893b908c675SJens Wiklander
894b908c675SJens Wiklander /**
895b908c675SJens Wiklander * fdt_node_depth - find the depth of a given node
896b908c675SJens Wiklander * @fdt: pointer to the device tree blob
897b908c675SJens Wiklander * @nodeoffset: offset of the node whose parent to find
898b908c675SJens Wiklander *
899b908c675SJens Wiklander * fdt_node_depth() finds the depth of a given node. The root node
900b908c675SJens Wiklander * has depth 0, its immediate subnodes depth 1 and so forth.
901b908c675SJens Wiklander *
902b908c675SJens Wiklander * NOTE: This function is expensive, as it must scan the device tree
903b908c675SJens Wiklander * structure from the start to nodeoffset.
904b908c675SJens Wiklander *
905b908c675SJens Wiklander * returns:
906b908c675SJens Wiklander * depth of the node at nodeoffset (>=0), on success
907b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
908b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
909b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
910b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
911b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE, standard meanings
912b908c675SJens Wiklander */
913b908c675SJens Wiklander int fdt_node_depth(const void *fdt, int nodeoffset);
914b908c675SJens Wiklander
915b908c675SJens Wiklander /**
916b908c675SJens Wiklander * fdt_parent_offset - find the parent of a given node
917b908c675SJens Wiklander * @fdt: pointer to the device tree blob
918b908c675SJens Wiklander * @nodeoffset: offset of the node whose parent to find
919b908c675SJens Wiklander *
920b908c675SJens Wiklander * fdt_parent_offset() locates the parent node of a given node (that
921b908c675SJens Wiklander * is, it finds the offset of the node which contains the node at
922b908c675SJens Wiklander * nodeoffset as a subnode).
923b908c675SJens Wiklander *
924b908c675SJens Wiklander * NOTE: This function is expensive, as it must scan the device tree
925b908c675SJens Wiklander * structure from the start to nodeoffset, *twice*.
926b908c675SJens Wiklander *
927b908c675SJens Wiklander * returns:
928b908c675SJens Wiklander * structure block offset of the parent of the node at nodeoffset
929b908c675SJens Wiklander * (>=0), on success
930b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
931b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
932b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
933b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
934b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE, standard meanings
935b908c675SJens Wiklander */
936b908c675SJens Wiklander int fdt_parent_offset(const void *fdt, int nodeoffset);
937b908c675SJens Wiklander
938b908c675SJens Wiklander /**
939b908c675SJens Wiklander * fdt_node_offset_by_prop_value - find nodes with a given property value
940b908c675SJens Wiklander * @fdt: pointer to the device tree blob
941b908c675SJens Wiklander * @startoffset: only find nodes after this offset
942b908c675SJens Wiklander * @propname: property name to check
943b908c675SJens Wiklander * @propval: property value to search for
944b908c675SJens Wiklander * @proplen: length of the value in propval
945b908c675SJens Wiklander *
946b908c675SJens Wiklander * fdt_node_offset_by_prop_value() returns the offset of the first
947b908c675SJens Wiklander * node after startoffset, which has a property named propname whose
948b908c675SJens Wiklander * value is of length proplen and has value equal to propval; or if
949b908c675SJens Wiklander * startoffset is -1, the very first such node in the tree.
950b908c675SJens Wiklander *
951b908c675SJens Wiklander * To iterate through all nodes matching the criterion, the following
952b908c675SJens Wiklander * idiom can be used:
953b908c675SJens Wiklander * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
954b908c675SJens Wiklander * propval, proplen);
955b908c675SJens Wiklander * while (offset != -FDT_ERR_NOTFOUND) {
956b908c675SJens Wiklander * // other code here
957b908c675SJens Wiklander * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
958b908c675SJens Wiklander * propval, proplen);
959b908c675SJens Wiklander * }
960b908c675SJens Wiklander *
961b908c675SJens Wiklander * Note the -1 in the first call to the function, if 0 is used here
962b908c675SJens Wiklander * instead, the function will never locate the root node, even if it
963b908c675SJens Wiklander * matches the criterion.
964b908c675SJens Wiklander *
965b908c675SJens Wiklander * returns:
966b908c675SJens Wiklander * structure block offset of the located node (>= 0, >startoffset),
967b908c675SJens Wiklander * on success
968b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
969b908c675SJens Wiklander * tree after startoffset
970b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
971b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
972b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
973b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
974b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE, standard meanings
975b908c675SJens Wiklander */
976b908c675SJens Wiklander int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
977b908c675SJens Wiklander const char *propname,
978b908c675SJens Wiklander const void *propval, int proplen);
979b908c675SJens Wiklander
980b908c675SJens Wiklander /**
981b908c675SJens Wiklander * fdt_node_offset_by_phandle - find the node with a given phandle
982b908c675SJens Wiklander * @fdt: pointer to the device tree blob
983b908c675SJens Wiklander * @phandle: phandle value
984b908c675SJens Wiklander *
985b908c675SJens Wiklander * fdt_node_offset_by_phandle() returns the offset of the node
986b908c675SJens Wiklander * which has the given phandle value. If there is more than one node
987b908c675SJens Wiklander * in the tree with the given phandle (an invalid tree), results are
988b908c675SJens Wiklander * undefined.
989b908c675SJens Wiklander *
990b908c675SJens Wiklander * returns:
991b908c675SJens Wiklander * structure block offset of the located node (>= 0), on success
992b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, no node with that phandle exists
993b908c675SJens Wiklander * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
994b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
995b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
996b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
997b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE, standard meanings
998b908c675SJens Wiklander */
999b908c675SJens Wiklander int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
1000b908c675SJens Wiklander
1001b908c675SJens Wiklander /**
1002b908c675SJens Wiklander * fdt_node_check_compatible: check a node's compatible property
1003b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1004b908c675SJens Wiklander * @nodeoffset: offset of a tree node
1005b908c675SJens Wiklander * @compatible: string to match against
1006b908c675SJens Wiklander *
1007b908c675SJens Wiklander *
1008b908c675SJens Wiklander * fdt_node_check_compatible() returns 0 if the given node contains a
1009b908c675SJens Wiklander * 'compatible' property with the given string as one of its elements,
1010b908c675SJens Wiklander * it returns non-zero otherwise, or on error.
1011b908c675SJens Wiklander *
1012b908c675SJens Wiklander * returns:
1013b908c675SJens Wiklander * 0, if the node has a 'compatible' property listing the given string
1014b908c675SJens Wiklander * 1, if the node has a 'compatible' property, but it does not list
1015b908c675SJens Wiklander * the given string
1016b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
1017b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
1018b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1019b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1020b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1021b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE, standard meanings
1022b908c675SJens Wiklander */
1023b908c675SJens Wiklander int fdt_node_check_compatible(const void *fdt, int nodeoffset,
1024b908c675SJens Wiklander const char *compatible);
1025b908c675SJens Wiklander
1026b908c675SJens Wiklander /**
1027b908c675SJens Wiklander * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
1028b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1029b908c675SJens Wiklander * @startoffset: only find nodes after this offset
1030b908c675SJens Wiklander * @compatible: 'compatible' string to match against
1031b908c675SJens Wiklander *
1032b908c675SJens Wiklander * fdt_node_offset_by_compatible() returns the offset of the first
1033b908c675SJens Wiklander * node after startoffset, which has a 'compatible' property which
1034b908c675SJens Wiklander * lists the given compatible string; or if startoffset is -1, the
1035b908c675SJens Wiklander * very first such node in the tree.
1036b908c675SJens Wiklander *
1037b908c675SJens Wiklander * To iterate through all nodes matching the criterion, the following
1038b908c675SJens Wiklander * idiom can be used:
1039b908c675SJens Wiklander * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
1040b908c675SJens Wiklander * while (offset != -FDT_ERR_NOTFOUND) {
1041b908c675SJens Wiklander * // other code here
1042b908c675SJens Wiklander * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
1043b908c675SJens Wiklander * }
1044b908c675SJens Wiklander *
1045b908c675SJens Wiklander * Note the -1 in the first call to the function, if 0 is used here
1046b908c675SJens Wiklander * instead, the function will never locate the root node, even if it
1047b908c675SJens Wiklander * matches the criterion.
1048b908c675SJens Wiklander *
1049b908c675SJens Wiklander * returns:
1050b908c675SJens Wiklander * structure block offset of the located node (>= 0, >startoffset),
1051b908c675SJens Wiklander * on success
1052b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
1053b908c675SJens Wiklander * tree after startoffset
1054b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
1055b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1056b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1057b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1058b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE, standard meanings
1059b908c675SJens Wiklander */
1060b908c675SJens Wiklander int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
1061b908c675SJens Wiklander const char *compatible);
1062b908c675SJens Wiklander
1063b908c675SJens Wiklander /**
1064b908c675SJens Wiklander * fdt_stringlist_contains - check a string list property for a string
1065b908c675SJens Wiklander * @strlist: Property containing a list of strings to check
1066b908c675SJens Wiklander * @listlen: Length of property
1067b908c675SJens Wiklander * @str: String to search for
1068b908c675SJens Wiklander *
1069b908c675SJens Wiklander * This is a utility function provided for convenience. The list contains
1070b908c675SJens Wiklander * one or more strings, each terminated by \0, as is found in a device tree
1071b908c675SJens Wiklander * "compatible" property.
1072b908c675SJens Wiklander *
1073b908c675SJens Wiklander * @return: 1 if the string is found in the list, 0 not found, or invalid list
1074b908c675SJens Wiklander */
1075b908c675SJens Wiklander int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
1076b908c675SJens Wiklander
107701d6a9daSBryan O'Donoghue /**
107801d6a9daSBryan O'Donoghue * fdt_stringlist_count - count the number of strings in a string list
107901d6a9daSBryan O'Donoghue * @fdt: pointer to the device tree blob
108001d6a9daSBryan O'Donoghue * @nodeoffset: offset of a tree node
108101d6a9daSBryan O'Donoghue * @property: name of the property containing the string list
108201d6a9daSBryan O'Donoghue * @return:
108301d6a9daSBryan O'Donoghue * the number of strings in the given property
108401d6a9daSBryan O'Donoghue * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
108501d6a9daSBryan O'Donoghue * -FDT_ERR_NOTFOUND if the property does not exist
108601d6a9daSBryan O'Donoghue */
108701d6a9daSBryan O'Donoghue int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);
108801d6a9daSBryan O'Donoghue
108901d6a9daSBryan O'Donoghue /**
109001d6a9daSBryan O'Donoghue * fdt_stringlist_search - find a string in a string list and return its index
109101d6a9daSBryan O'Donoghue * @fdt: pointer to the device tree blob
109201d6a9daSBryan O'Donoghue * @nodeoffset: offset of a tree node
109301d6a9daSBryan O'Donoghue * @property: name of the property containing the string list
109401d6a9daSBryan O'Donoghue * @string: string to look up in the string list
109501d6a9daSBryan O'Donoghue *
109601d6a9daSBryan O'Donoghue * Note that it is possible for this function to succeed on property values
109701d6a9daSBryan O'Donoghue * that are not NUL-terminated. That's because the function will stop after
109801d6a9daSBryan O'Donoghue * finding the first occurrence of @string. This can for example happen with
109901d6a9daSBryan O'Donoghue * small-valued cell properties, such as #address-cells, when searching for
110001d6a9daSBryan O'Donoghue * the empty string.
110101d6a9daSBryan O'Donoghue *
110201d6a9daSBryan O'Donoghue * @return:
110301d6a9daSBryan O'Donoghue * the index of the string in the list of strings
110401d6a9daSBryan O'Donoghue * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
110501d6a9daSBryan O'Donoghue * -FDT_ERR_NOTFOUND if the property does not exist or does not contain
110601d6a9daSBryan O'Donoghue * the given string
110701d6a9daSBryan O'Donoghue */
110801d6a9daSBryan O'Donoghue int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
110901d6a9daSBryan O'Donoghue const char *string);
111001d6a9daSBryan O'Donoghue
111101d6a9daSBryan O'Donoghue /**
111201d6a9daSBryan O'Donoghue * fdt_stringlist_get() - obtain the string at a given index in a string list
111301d6a9daSBryan O'Donoghue * @fdt: pointer to the device tree blob
111401d6a9daSBryan O'Donoghue * @nodeoffset: offset of a tree node
111501d6a9daSBryan O'Donoghue * @property: name of the property containing the string list
111601d6a9daSBryan O'Donoghue * @index: index of the string to return
111701d6a9daSBryan O'Donoghue * @lenp: return location for the string length or an error code on failure
111801d6a9daSBryan O'Donoghue *
111901d6a9daSBryan O'Donoghue * Note that this will successfully extract strings from properties with
112001d6a9daSBryan O'Donoghue * non-NUL-terminated values. For example on small-valued cell properties
112101d6a9daSBryan O'Donoghue * this function will return the empty string.
112201d6a9daSBryan O'Donoghue *
112301d6a9daSBryan O'Donoghue * If non-NULL, the length of the string (on success) or a negative error-code
112401d6a9daSBryan O'Donoghue * (on failure) will be stored in the integer pointer to by lenp.
112501d6a9daSBryan O'Donoghue *
112601d6a9daSBryan O'Donoghue * @return:
112701d6a9daSBryan O'Donoghue * A pointer to the string at the given index in the string list or NULL on
112801d6a9daSBryan O'Donoghue * failure. On success the length of the string will be stored in the memory
112901d6a9daSBryan O'Donoghue * location pointed to by the lenp parameter, if non-NULL. On failure one of
113001d6a9daSBryan O'Donoghue * the following negative error codes will be returned in the lenp parameter
113101d6a9daSBryan O'Donoghue * (if non-NULL):
113201d6a9daSBryan O'Donoghue * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
113301d6a9daSBryan O'Donoghue * -FDT_ERR_NOTFOUND if the property does not exist
113401d6a9daSBryan O'Donoghue */
113501d6a9daSBryan O'Donoghue const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
113601d6a9daSBryan O'Donoghue const char *property, int index,
113701d6a9daSBryan O'Donoghue int *lenp);
113801d6a9daSBryan O'Donoghue
1139b908c675SJens Wiklander /**********************************************************************/
1140b908c675SJens Wiklander /* Read-only functions (addressing related) */
1141b908c675SJens Wiklander /**********************************************************************/
1142b908c675SJens Wiklander
1143b908c675SJens Wiklander /**
1144b908c675SJens Wiklander * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
1145b908c675SJens Wiklander *
1146b908c675SJens Wiklander * This is the maximum value for #address-cells, #size-cells and
1147b908c675SJens Wiklander * similar properties that will be processed by libfdt. IEE1275
1148b908c675SJens Wiklander * requires that OF implementations handle values up to 4.
1149b908c675SJens Wiklander * Implementations may support larger values, but in practice higher
1150b908c675SJens Wiklander * values aren't used.
1151b908c675SJens Wiklander */
1152b908c675SJens Wiklander #define FDT_MAX_NCELLS 4
1153b908c675SJens Wiklander
1154b908c675SJens Wiklander /**
1155b908c675SJens Wiklander * fdt_address_cells - retrieve address size for a bus represented in the tree
1156b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1157b908c675SJens Wiklander * @nodeoffset: offset of the node to find the address size for
1158b908c675SJens Wiklander *
1159b908c675SJens Wiklander * When the node has a valid #address-cells property, returns its value.
1160b908c675SJens Wiklander *
1161b908c675SJens Wiklander * returns:
1162b908c675SJens Wiklander * 0 <= n < FDT_MAX_NCELLS, on success
1163b908c675SJens Wiklander * 2, if the node has no #address-cells property
116401d6a9daSBryan O'Donoghue * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
116501d6a9daSBryan O'Donoghue * #address-cells property
1166b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1167b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1168b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1169b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1170b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1171b908c675SJens Wiklander */
1172b908c675SJens Wiklander int fdt_address_cells(const void *fdt, int nodeoffset);
1173b908c675SJens Wiklander
1174b908c675SJens Wiklander /**
1175b908c675SJens Wiklander * fdt_size_cells - retrieve address range size for a bus represented in the
1176b908c675SJens Wiklander * tree
1177b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1178b908c675SJens Wiklander * @nodeoffset: offset of the node to find the address range size for
1179b908c675SJens Wiklander *
1180b908c675SJens Wiklander * When the node has a valid #size-cells property, returns its value.
1181b908c675SJens Wiklander *
1182b908c675SJens Wiklander * returns:
1183b908c675SJens Wiklander * 0 <= n < FDT_MAX_NCELLS, on success
1184*17f326ebSJerome Forissier * 1, if the node has no #size-cells property
118501d6a9daSBryan O'Donoghue * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
118601d6a9daSBryan O'Donoghue * #size-cells property
1187b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1188b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1189b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1190b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1191b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1192b908c675SJens Wiklander */
1193b908c675SJens Wiklander int fdt_size_cells(const void *fdt, int nodeoffset);
1194b908c675SJens Wiklander
1195b908c675SJens Wiklander
1196b908c675SJens Wiklander /**********************************************************************/
1197b908c675SJens Wiklander /* Write-in-place functions */
1198b908c675SJens Wiklander /**********************************************************************/
1199b908c675SJens Wiklander
1200b908c675SJens Wiklander /**
120101d6a9daSBryan O'Donoghue * fdt_setprop_inplace_namelen_partial - change a property's value,
120201d6a9daSBryan O'Donoghue * but not its size
120301d6a9daSBryan O'Donoghue * @fdt: pointer to the device tree blob
120401d6a9daSBryan O'Donoghue * @nodeoffset: offset of the node whose property to change
120501d6a9daSBryan O'Donoghue * @name: name of the property to change
120601d6a9daSBryan O'Donoghue * @namelen: number of characters of name to consider
120701d6a9daSBryan O'Donoghue * @idx: index of the property to change in the array
120801d6a9daSBryan O'Donoghue * @val: pointer to data to replace the property value with
120901d6a9daSBryan O'Donoghue * @len: length of the property value
121001d6a9daSBryan O'Donoghue *
121101d6a9daSBryan O'Donoghue * Identical to fdt_setprop_inplace(), but modifies the given property
121201d6a9daSBryan O'Donoghue * starting from the given index, and using only the first characters
121301d6a9daSBryan O'Donoghue * of the name. It is useful when you want to manipulate only one value of
121401d6a9daSBryan O'Donoghue * an array and you have a string that doesn't end with \0.
121501d6a9daSBryan O'Donoghue */
121601d6a9daSBryan O'Donoghue #ifndef SWIG /* Not available in Python */
121701d6a9daSBryan O'Donoghue int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
121801d6a9daSBryan O'Donoghue const char *name, int namelen,
121901d6a9daSBryan O'Donoghue uint32_t idx, const void *val,
122001d6a9daSBryan O'Donoghue int len);
122101d6a9daSBryan O'Donoghue #endif
122201d6a9daSBryan O'Donoghue
122301d6a9daSBryan O'Donoghue /**
1224b908c675SJens Wiklander * fdt_setprop_inplace - change a property's value, but not its size
1225b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1226b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to change
1227b908c675SJens Wiklander * @name: name of the property to change
1228b908c675SJens Wiklander * @val: pointer to data to replace the property value with
1229b908c675SJens Wiklander * @len: length of the property value
1230b908c675SJens Wiklander *
1231b908c675SJens Wiklander * fdt_setprop_inplace() replaces the value of a given property with
1232b908c675SJens Wiklander * the data in val, of length len. This function cannot change the
1233b908c675SJens Wiklander * size of a property, and so will only work if len is equal to the
1234b908c675SJens Wiklander * current length of the property.
1235b908c675SJens Wiklander *
1236b908c675SJens Wiklander * This function will alter only the bytes in the blob which contain
1237b908c675SJens Wiklander * the given property value, and will not alter or move any other part
1238b908c675SJens Wiklander * of the tree.
1239b908c675SJens Wiklander *
1240b908c675SJens Wiklander * returns:
1241b908c675SJens Wiklander * 0, on success
1242b908c675SJens Wiklander * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
1243b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, node does not have the named property
1244b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1245b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1246b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1247b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1248b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1249b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1250b908c675SJens Wiklander */
125101d6a9daSBryan O'Donoghue #ifndef SWIG /* Not available in Python */
1252b908c675SJens Wiklander int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
1253b908c675SJens Wiklander const void *val, int len);
125401d6a9daSBryan O'Donoghue #endif
1255b908c675SJens Wiklander
1256b908c675SJens Wiklander /**
1257b908c675SJens Wiklander * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
1258b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1259b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to change
1260b908c675SJens Wiklander * @name: name of the property to change
1261b908c675SJens Wiklander * @val: 32-bit integer value to replace the property with
1262b908c675SJens Wiklander *
1263b908c675SJens Wiklander * fdt_setprop_inplace_u32() replaces the value of a given property
1264b908c675SJens Wiklander * with the 32-bit integer value in val, converting val to big-endian
1265b908c675SJens Wiklander * if necessary. This function cannot change the size of a property,
1266b908c675SJens Wiklander * and so will only work if the property already exists and has length
1267b908c675SJens Wiklander * 4.
1268b908c675SJens Wiklander *
1269b908c675SJens Wiklander * This function will alter only the bytes in the blob which contain
1270b908c675SJens Wiklander * the given property value, and will not alter or move any other part
1271b908c675SJens Wiklander * of the tree.
1272b908c675SJens Wiklander *
1273b908c675SJens Wiklander * returns:
1274b908c675SJens Wiklander * 0, on success
1275b908c675SJens Wiklander * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
1276b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, node does not have the named property
1277b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1278b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1279b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1280b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1281b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1282b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1283b908c675SJens Wiklander */
fdt_setprop_inplace_u32(void * fdt,int nodeoffset,const char * name,uint32_t val)1284b908c675SJens Wiklander static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
1285b908c675SJens Wiklander const char *name, uint32_t val)
1286b908c675SJens Wiklander {
1287b908c675SJens Wiklander fdt32_t tmp = cpu_to_fdt32(val);
1288b908c675SJens Wiklander return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1289b908c675SJens Wiklander }
1290b908c675SJens Wiklander
1291b908c675SJens Wiklander /**
1292b908c675SJens Wiklander * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
1293b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1294b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to change
1295b908c675SJens Wiklander * @name: name of the property to change
1296b908c675SJens Wiklander * @val: 64-bit integer value to replace the property with
1297b908c675SJens Wiklander *
1298b908c675SJens Wiklander * fdt_setprop_inplace_u64() replaces the value of a given property
1299b908c675SJens Wiklander * with the 64-bit integer value in val, converting val to big-endian
1300b908c675SJens Wiklander * if necessary. This function cannot change the size of a property,
1301b908c675SJens Wiklander * and so will only work if the property already exists and has length
1302b908c675SJens Wiklander * 8.
1303b908c675SJens Wiklander *
1304b908c675SJens Wiklander * This function will alter only the bytes in the blob which contain
1305b908c675SJens Wiklander * the given property value, and will not alter or move any other part
1306b908c675SJens Wiklander * of the tree.
1307b908c675SJens Wiklander *
1308b908c675SJens Wiklander * returns:
1309b908c675SJens Wiklander * 0, on success
1310b908c675SJens Wiklander * -FDT_ERR_NOSPACE, if the property's length is not equal to 8
1311b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, node does not have the named property
1312b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1313b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1314b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1315b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1316b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1317b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1318b908c675SJens Wiklander */
fdt_setprop_inplace_u64(void * fdt,int nodeoffset,const char * name,uint64_t val)1319b908c675SJens Wiklander static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
1320b908c675SJens Wiklander const char *name, uint64_t val)
1321b908c675SJens Wiklander {
1322b908c675SJens Wiklander fdt64_t tmp = cpu_to_fdt64(val);
1323b908c675SJens Wiklander return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1324b908c675SJens Wiklander }
1325b908c675SJens Wiklander
1326b908c675SJens Wiklander /**
1327b908c675SJens Wiklander * fdt_setprop_inplace_cell - change the value of a single-cell property
1328b908c675SJens Wiklander *
1329b908c675SJens Wiklander * This is an alternative name for fdt_setprop_inplace_u32()
1330b908c675SJens Wiklander */
fdt_setprop_inplace_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)1331b908c675SJens Wiklander static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
1332b908c675SJens Wiklander const char *name, uint32_t val)
1333b908c675SJens Wiklander {
1334b908c675SJens Wiklander return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
1335b908c675SJens Wiklander }
1336b908c675SJens Wiklander
1337b908c675SJens Wiklander /**
1338b908c675SJens Wiklander * fdt_nop_property - replace a property with nop tags
1339b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1340b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to nop
1341b908c675SJens Wiklander * @name: name of the property to nop
1342b908c675SJens Wiklander *
1343b908c675SJens Wiklander * fdt_nop_property() will replace a given property's representation
1344b908c675SJens Wiklander * in the blob with FDT_NOP tags, effectively removing it from the
1345b908c675SJens Wiklander * tree.
1346b908c675SJens Wiklander *
1347b908c675SJens Wiklander * This function will alter only the bytes in the blob which contain
1348b908c675SJens Wiklander * the property, and will not alter or move any other part of the
1349b908c675SJens Wiklander * tree.
1350b908c675SJens Wiklander *
1351b908c675SJens Wiklander * returns:
1352b908c675SJens Wiklander * 0, on success
1353b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, node does not have the named property
1354b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1355b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1356b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1357b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1358b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1359b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1360b908c675SJens Wiklander */
1361b908c675SJens Wiklander int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
1362b908c675SJens Wiklander
1363b908c675SJens Wiklander /**
1364b908c675SJens Wiklander * fdt_nop_node - replace a node (subtree) with nop tags
1365b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1366b908c675SJens Wiklander * @nodeoffset: offset of the node to nop
1367b908c675SJens Wiklander *
1368b908c675SJens Wiklander * fdt_nop_node() will replace a given node's representation in the
1369b908c675SJens Wiklander * blob, including all its subnodes, if any, with FDT_NOP tags,
1370b908c675SJens Wiklander * effectively removing it from the tree.
1371b908c675SJens Wiklander *
1372b908c675SJens Wiklander * This function will alter only the bytes in the blob which contain
1373b908c675SJens Wiklander * the node and its properties and subnodes, and will not alter or
1374b908c675SJens Wiklander * move any other part of the tree.
1375b908c675SJens Wiklander *
1376b908c675SJens Wiklander * returns:
1377b908c675SJens Wiklander * 0, on success
1378b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1379b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1380b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1381b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1382b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1383b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1384b908c675SJens Wiklander */
1385b908c675SJens Wiklander int fdt_nop_node(void *fdt, int nodeoffset);
1386b908c675SJens Wiklander
1387b908c675SJens Wiklander /**********************************************************************/
1388b908c675SJens Wiklander /* Sequential write functions */
1389b908c675SJens Wiklander /**********************************************************************/
1390b908c675SJens Wiklander
1391*17f326ebSJerome Forissier /* fdt_create_with_flags flags */
1392*17f326ebSJerome Forissier #define FDT_CREATE_FLAG_NO_NAME_DEDUP 0x1
1393*17f326ebSJerome Forissier /* FDT_CREATE_FLAG_NO_NAME_DEDUP: Do not try to de-duplicate property
1394*17f326ebSJerome Forissier * names in the fdt. This can result in faster creation times, but
1395*17f326ebSJerome Forissier * a larger fdt. */
1396*17f326ebSJerome Forissier
1397*17f326ebSJerome Forissier #define FDT_CREATE_FLAGS_ALL (FDT_CREATE_FLAG_NO_NAME_DEDUP)
1398*17f326ebSJerome Forissier
1399*17f326ebSJerome Forissier /**
1400*17f326ebSJerome Forissier * fdt_create_with_flags - begin creation of a new fdt
1401*17f326ebSJerome Forissier * @fdt: pointer to memory allocated where fdt will be created
1402*17f326ebSJerome Forissier * @bufsize: size of the memory space at fdt
1403*17f326ebSJerome Forissier * @flags: a valid combination of FDT_CREATE_FLAG_ flags, or 0.
1404*17f326ebSJerome Forissier *
1405*17f326ebSJerome Forissier * fdt_create_with_flags() begins the process of creating a new fdt with
1406*17f326ebSJerome Forissier * the sequential write interface.
1407*17f326ebSJerome Forissier *
1408*17f326ebSJerome Forissier * fdt creation process must end with fdt_finished() to produce a valid fdt.
1409*17f326ebSJerome Forissier *
1410*17f326ebSJerome Forissier * returns:
1411*17f326ebSJerome Forissier * 0, on success
1412*17f326ebSJerome Forissier * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
1413*17f326ebSJerome Forissier * -FDT_ERR_BADFLAGS, flags is not valid
1414*17f326ebSJerome Forissier */
1415*17f326ebSJerome Forissier int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags);
1416*17f326ebSJerome Forissier
1417*17f326ebSJerome Forissier /**
1418*17f326ebSJerome Forissier * fdt_create - begin creation of a new fdt
1419*17f326ebSJerome Forissier * @fdt: pointer to memory allocated where fdt will be created
1420*17f326ebSJerome Forissier * @bufsize: size of the memory space at fdt
1421*17f326ebSJerome Forissier *
1422*17f326ebSJerome Forissier * fdt_create() is equivalent to fdt_create_with_flags() with flags=0.
1423*17f326ebSJerome Forissier *
1424*17f326ebSJerome Forissier * returns:
1425*17f326ebSJerome Forissier * 0, on success
1426*17f326ebSJerome Forissier * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
1427*17f326ebSJerome Forissier */
1428b908c675SJens Wiklander int fdt_create(void *buf, int bufsize);
1429*17f326ebSJerome Forissier
1430b908c675SJens Wiklander int fdt_resize(void *fdt, void *buf, int bufsize);
1431b908c675SJens Wiklander int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
1432b908c675SJens Wiklander int fdt_finish_reservemap(void *fdt);
1433b908c675SJens Wiklander int fdt_begin_node(void *fdt, const char *name);
1434b908c675SJens Wiklander int fdt_property(void *fdt, const char *name, const void *val, int len);
fdt_property_u32(void * fdt,const char * name,uint32_t val)1435b908c675SJens Wiklander static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
1436b908c675SJens Wiklander {
1437b908c675SJens Wiklander fdt32_t tmp = cpu_to_fdt32(val);
1438b908c675SJens Wiklander return fdt_property(fdt, name, &tmp, sizeof(tmp));
1439b908c675SJens Wiklander }
fdt_property_u64(void * fdt,const char * name,uint64_t val)1440b908c675SJens Wiklander static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
1441b908c675SJens Wiklander {
1442b908c675SJens Wiklander fdt64_t tmp = cpu_to_fdt64(val);
1443b908c675SJens Wiklander return fdt_property(fdt, name, &tmp, sizeof(tmp));
1444b908c675SJens Wiklander }
1445*17f326ebSJerome Forissier
1446*17f326ebSJerome Forissier #ifndef SWIG /* Not available in Python */
fdt_property_cell(void * fdt,const char * name,uint32_t val)1447b908c675SJens Wiklander static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
1448b908c675SJens Wiklander {
1449b908c675SJens Wiklander return fdt_property_u32(fdt, name, val);
1450b908c675SJens Wiklander }
1451*17f326ebSJerome Forissier #endif
145201d6a9daSBryan O'Donoghue
145301d6a9daSBryan O'Donoghue /**
145401d6a9daSBryan O'Donoghue * fdt_property_placeholder - add a new property and return a ptr to its value
145501d6a9daSBryan O'Donoghue *
145601d6a9daSBryan O'Donoghue * @fdt: pointer to the device tree blob
145701d6a9daSBryan O'Donoghue * @name: name of property to add
145801d6a9daSBryan O'Donoghue * @len: length of property value in bytes
145901d6a9daSBryan O'Donoghue * @valp: returns a pointer to where where the value should be placed
146001d6a9daSBryan O'Donoghue *
146101d6a9daSBryan O'Donoghue * returns:
146201d6a9daSBryan O'Donoghue * 0, on success
146301d6a9daSBryan O'Donoghue * -FDT_ERR_BADMAGIC,
146401d6a9daSBryan O'Donoghue * -FDT_ERR_NOSPACE, standard meanings
146501d6a9daSBryan O'Donoghue */
146601d6a9daSBryan O'Donoghue int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp);
146701d6a9daSBryan O'Donoghue
1468b908c675SJens Wiklander #define fdt_property_string(fdt, name, str) \
1469b908c675SJens Wiklander fdt_property(fdt, name, str, strlen(str)+1)
1470b908c675SJens Wiklander int fdt_end_node(void *fdt);
1471b908c675SJens Wiklander int fdt_finish(void *fdt);
1472b908c675SJens Wiklander
1473b908c675SJens Wiklander /**********************************************************************/
1474b908c675SJens Wiklander /* Read-write functions */
1475b908c675SJens Wiklander /**********************************************************************/
1476b908c675SJens Wiklander
1477b908c675SJens Wiklander int fdt_create_empty_tree(void *buf, int bufsize);
1478b908c675SJens Wiklander int fdt_open_into(const void *fdt, void *buf, int bufsize);
1479b908c675SJens Wiklander int fdt_pack(void *fdt);
1480b908c675SJens Wiklander
1481b908c675SJens Wiklander /**
1482b908c675SJens Wiklander * fdt_add_mem_rsv - add one memory reserve map entry
1483b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1484b908c675SJens Wiklander * @address, @size: 64-bit values (native endian)
1485b908c675SJens Wiklander *
1486b908c675SJens Wiklander * Adds a reserve map entry to the given blob reserving a region at
1487b908c675SJens Wiklander * address address of length size.
1488b908c675SJens Wiklander *
1489b908c675SJens Wiklander * This function will insert data into the reserve map and will
1490b908c675SJens Wiklander * therefore change the indexes of some entries in the table.
1491b908c675SJens Wiklander *
1492b908c675SJens Wiklander * returns:
1493b908c675SJens Wiklander * 0, on success
1494b908c675SJens Wiklander * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1495b908c675SJens Wiklander * contain the new reservation entry
1496b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1497b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1498b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1499b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1500b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1501b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1502b908c675SJens Wiklander */
1503b908c675SJens Wiklander int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
1504b908c675SJens Wiklander
1505b908c675SJens Wiklander /**
1506b908c675SJens Wiklander * fdt_del_mem_rsv - remove a memory reserve map entry
1507b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1508b908c675SJens Wiklander * @n: entry to remove
1509b908c675SJens Wiklander *
1510b908c675SJens Wiklander * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
1511b908c675SJens Wiklander * the blob.
1512b908c675SJens Wiklander *
1513b908c675SJens Wiklander * This function will delete data from the reservation table and will
1514b908c675SJens Wiklander * therefore change the indexes of some entries in the table.
1515b908c675SJens Wiklander *
1516b908c675SJens Wiklander * returns:
1517b908c675SJens Wiklander * 0, on success
1518b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
1519b908c675SJens Wiklander * are less than n+1 reserve map entries)
1520b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1521b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1522b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1523b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1524b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1525b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1526b908c675SJens Wiklander */
1527b908c675SJens Wiklander int fdt_del_mem_rsv(void *fdt, int n);
1528b908c675SJens Wiklander
1529b908c675SJens Wiklander /**
1530b908c675SJens Wiklander * fdt_set_name - change the name of a given node
1531b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1532b908c675SJens Wiklander * @nodeoffset: structure block offset of a node
1533b908c675SJens Wiklander * @name: name to give the node
1534b908c675SJens Wiklander *
1535b908c675SJens Wiklander * fdt_set_name() replaces the name (including unit address, if any)
1536b908c675SJens Wiklander * of the given node with the given string. NOTE: this function can't
1537b908c675SJens Wiklander * efficiently check if the new name is unique amongst the given
1538b908c675SJens Wiklander * node's siblings; results are undefined if this function is invoked
1539b908c675SJens Wiklander * with a name equal to one of the given node's siblings.
1540b908c675SJens Wiklander *
1541b908c675SJens Wiklander * This function may insert or delete data from the blob, and will
1542b908c675SJens Wiklander * therefore change the offsets of some existing nodes.
1543b908c675SJens Wiklander *
1544b908c675SJens Wiklander * returns:
1545b908c675SJens Wiklander * 0, on success
1546b908c675SJens Wiklander * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
1547b908c675SJens Wiklander * to contain the new name
1548b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1549b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1550b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1551b908c675SJens Wiklander * -FDT_ERR_BADSTATE, standard meanings
1552b908c675SJens Wiklander */
1553b908c675SJens Wiklander int fdt_set_name(void *fdt, int nodeoffset, const char *name);
1554b908c675SJens Wiklander
1555b908c675SJens Wiklander /**
1556b908c675SJens Wiklander * fdt_setprop - create or change a property
1557b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1558b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to change
1559b908c675SJens Wiklander * @name: name of the property to change
1560b908c675SJens Wiklander * @val: pointer to data to set the property value to
1561b908c675SJens Wiklander * @len: length of the property value
1562b908c675SJens Wiklander *
1563b908c675SJens Wiklander * fdt_setprop() sets the value of the named property in the given
1564b908c675SJens Wiklander * node to the given value and length, creating the property if it
1565b908c675SJens Wiklander * does not already exist.
1566b908c675SJens Wiklander *
1567b908c675SJens Wiklander * This function may insert or delete data from the blob, and will
1568b908c675SJens Wiklander * therefore change the offsets of some existing nodes.
1569b908c675SJens Wiklander *
1570b908c675SJens Wiklander * returns:
1571b908c675SJens Wiklander * 0, on success
1572b908c675SJens Wiklander * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1573b908c675SJens Wiklander * contain the new property value
1574b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1575b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1576b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1577b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1578b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1579b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1580b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1581b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1582b908c675SJens Wiklander */
1583b908c675SJens Wiklander int fdt_setprop(void *fdt, int nodeoffset, const char *name,
1584b908c675SJens Wiklander const void *val, int len);
1585b908c675SJens Wiklander
1586b908c675SJens Wiklander /**
158701d6a9daSBryan O'Donoghue * fdt_setprop_placeholder - allocate space for a property
158801d6a9daSBryan O'Donoghue * @fdt: pointer to the device tree blob
158901d6a9daSBryan O'Donoghue * @nodeoffset: offset of the node whose property to change
159001d6a9daSBryan O'Donoghue * @name: name of the property to change
159101d6a9daSBryan O'Donoghue * @len: length of the property value
159201d6a9daSBryan O'Donoghue * @prop_data: return pointer to property data
159301d6a9daSBryan O'Donoghue *
159401d6a9daSBryan O'Donoghue * fdt_setprop_placeholer() allocates the named property in the given node.
159501d6a9daSBryan O'Donoghue * If the property exists it is resized. In either case a pointer to the
159601d6a9daSBryan O'Donoghue * property data is returned.
159701d6a9daSBryan O'Donoghue *
159801d6a9daSBryan O'Donoghue * This function may insert or delete data from the blob, and will
159901d6a9daSBryan O'Donoghue * therefore change the offsets of some existing nodes.
160001d6a9daSBryan O'Donoghue *
160101d6a9daSBryan O'Donoghue * returns:
160201d6a9daSBryan O'Donoghue * 0, on success
160301d6a9daSBryan O'Donoghue * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
160401d6a9daSBryan O'Donoghue * contain the new property value
160501d6a9daSBryan O'Donoghue * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
160601d6a9daSBryan O'Donoghue * -FDT_ERR_BADLAYOUT,
160701d6a9daSBryan O'Donoghue * -FDT_ERR_BADMAGIC,
160801d6a9daSBryan O'Donoghue * -FDT_ERR_BADVERSION,
160901d6a9daSBryan O'Donoghue * -FDT_ERR_BADSTATE,
161001d6a9daSBryan O'Donoghue * -FDT_ERR_BADSTRUCTURE,
161101d6a9daSBryan O'Donoghue * -FDT_ERR_BADLAYOUT,
161201d6a9daSBryan O'Donoghue * -FDT_ERR_TRUNCATED, standard meanings
161301d6a9daSBryan O'Donoghue */
161401d6a9daSBryan O'Donoghue int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,
161501d6a9daSBryan O'Donoghue int len, void **prop_data);
161601d6a9daSBryan O'Donoghue
161701d6a9daSBryan O'Donoghue /**
1618b908c675SJens Wiklander * fdt_setprop_u32 - set a property to a 32-bit integer
1619b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1620b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to change
1621b908c675SJens Wiklander * @name: name of the property to change
1622b908c675SJens Wiklander * @val: 32-bit integer value for the property (native endian)
1623b908c675SJens Wiklander *
1624b908c675SJens Wiklander * fdt_setprop_u32() sets the value of the named property in the given
1625b908c675SJens Wiklander * node to the given 32-bit integer value (converting to big-endian if
1626b908c675SJens Wiklander * necessary), or creates a new property with that value if it does
1627b908c675SJens Wiklander * not already exist.
1628b908c675SJens Wiklander *
1629b908c675SJens Wiklander * This function may insert or delete data from the blob, and will
1630b908c675SJens Wiklander * therefore change the offsets of some existing nodes.
1631b908c675SJens Wiklander *
1632b908c675SJens Wiklander * returns:
1633b908c675SJens Wiklander * 0, on success
1634b908c675SJens Wiklander * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1635b908c675SJens Wiklander * contain the new property value
1636b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1637b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1638b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1639b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1640b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1641b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1642b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1643b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1644b908c675SJens Wiklander */
fdt_setprop_u32(void * fdt,int nodeoffset,const char * name,uint32_t val)1645b908c675SJens Wiklander static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
1646b908c675SJens Wiklander uint32_t val)
1647b908c675SJens Wiklander {
1648b908c675SJens Wiklander fdt32_t tmp = cpu_to_fdt32(val);
1649b908c675SJens Wiklander return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1650b908c675SJens Wiklander }
1651b908c675SJens Wiklander
1652b908c675SJens Wiklander /**
1653b908c675SJens Wiklander * fdt_setprop_u64 - set a property to a 64-bit integer
1654b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1655b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to change
1656b908c675SJens Wiklander * @name: name of the property to change
1657b908c675SJens Wiklander * @val: 64-bit integer value for the property (native endian)
1658b908c675SJens Wiklander *
1659b908c675SJens Wiklander * fdt_setprop_u64() sets the value of the named property in the given
1660b908c675SJens Wiklander * node to the given 64-bit integer value (converting to big-endian if
1661b908c675SJens Wiklander * necessary), or creates a new property with that value if it does
1662b908c675SJens Wiklander * not already exist.
1663b908c675SJens Wiklander *
1664b908c675SJens Wiklander * This function may insert or delete data from the blob, and will
1665b908c675SJens Wiklander * therefore change the offsets of some existing nodes.
1666b908c675SJens Wiklander *
1667b908c675SJens Wiklander * returns:
1668b908c675SJens Wiklander * 0, on success
1669b908c675SJens Wiklander * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1670b908c675SJens Wiklander * contain the new property value
1671b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1672b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1673b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1674b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1675b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1676b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1677b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1678b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1679b908c675SJens Wiklander */
fdt_setprop_u64(void * fdt,int nodeoffset,const char * name,uint64_t val)1680b908c675SJens Wiklander static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
1681b908c675SJens Wiklander uint64_t val)
1682b908c675SJens Wiklander {
1683b908c675SJens Wiklander fdt64_t tmp = cpu_to_fdt64(val);
1684b908c675SJens Wiklander return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1685b908c675SJens Wiklander }
1686b908c675SJens Wiklander
1687b908c675SJens Wiklander /**
1688b908c675SJens Wiklander * fdt_setprop_cell - set a property to a single cell value
1689b908c675SJens Wiklander *
1690b908c675SJens Wiklander * This is an alternative name for fdt_setprop_u32()
1691b908c675SJens Wiklander */
fdt_setprop_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)1692b908c675SJens Wiklander static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
1693b908c675SJens Wiklander uint32_t val)
1694b908c675SJens Wiklander {
1695b908c675SJens Wiklander return fdt_setprop_u32(fdt, nodeoffset, name, val);
1696b908c675SJens Wiklander }
1697b908c675SJens Wiklander
1698b908c675SJens Wiklander /**
1699b908c675SJens Wiklander * fdt_setprop_string - set a property to a string value
1700b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1701b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to change
1702b908c675SJens Wiklander * @name: name of the property to change
1703b908c675SJens Wiklander * @str: string value for the property
1704b908c675SJens Wiklander *
1705b908c675SJens Wiklander * fdt_setprop_string() sets the value of the named property in the
1706b908c675SJens Wiklander * given node to the given string value (using the length of the
1707b908c675SJens Wiklander * string to determine the new length of the property), or creates a
1708b908c675SJens Wiklander * new property with that value if it does not already exist.
1709b908c675SJens Wiklander *
1710b908c675SJens Wiklander * This function may insert or delete data from the blob, and will
1711b908c675SJens Wiklander * therefore change the offsets of some existing nodes.
1712b908c675SJens Wiklander *
1713b908c675SJens Wiklander * returns:
1714b908c675SJens Wiklander * 0, on success
1715b908c675SJens Wiklander * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1716b908c675SJens Wiklander * contain the new property value
1717b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1718b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1719b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1720b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1721b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1722b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1723b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1724b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1725b908c675SJens Wiklander */
1726b908c675SJens Wiklander #define fdt_setprop_string(fdt, nodeoffset, name, str) \
1727b908c675SJens Wiklander fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
1728b908c675SJens Wiklander
172901d6a9daSBryan O'Donoghue
173001d6a9daSBryan O'Donoghue /**
173101d6a9daSBryan O'Donoghue * fdt_setprop_empty - set a property to an empty value
173201d6a9daSBryan O'Donoghue * @fdt: pointer to the device tree blob
173301d6a9daSBryan O'Donoghue * @nodeoffset: offset of the node whose property to change
173401d6a9daSBryan O'Donoghue * @name: name of the property to change
173501d6a9daSBryan O'Donoghue *
173601d6a9daSBryan O'Donoghue * fdt_setprop_empty() sets the value of the named property in the
173701d6a9daSBryan O'Donoghue * given node to an empty (zero length) value, or creates a new empty
173801d6a9daSBryan O'Donoghue * property if it does not already exist.
173901d6a9daSBryan O'Donoghue *
174001d6a9daSBryan O'Donoghue * This function may insert or delete data from the blob, and will
174101d6a9daSBryan O'Donoghue * therefore change the offsets of some existing nodes.
174201d6a9daSBryan O'Donoghue *
174301d6a9daSBryan O'Donoghue * returns:
174401d6a9daSBryan O'Donoghue * 0, on success
174501d6a9daSBryan O'Donoghue * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
174601d6a9daSBryan O'Donoghue * contain the new property value
174701d6a9daSBryan O'Donoghue * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
174801d6a9daSBryan O'Donoghue * -FDT_ERR_BADLAYOUT,
174901d6a9daSBryan O'Donoghue * -FDT_ERR_BADMAGIC,
175001d6a9daSBryan O'Donoghue * -FDT_ERR_BADVERSION,
175101d6a9daSBryan O'Donoghue * -FDT_ERR_BADSTATE,
175201d6a9daSBryan O'Donoghue * -FDT_ERR_BADSTRUCTURE,
175301d6a9daSBryan O'Donoghue * -FDT_ERR_BADLAYOUT,
175401d6a9daSBryan O'Donoghue * -FDT_ERR_TRUNCATED, standard meanings
175501d6a9daSBryan O'Donoghue */
175601d6a9daSBryan O'Donoghue #define fdt_setprop_empty(fdt, nodeoffset, name) \
175701d6a9daSBryan O'Donoghue fdt_setprop((fdt), (nodeoffset), (name), NULL, 0)
175801d6a9daSBryan O'Donoghue
1759b908c675SJens Wiklander /**
1760b908c675SJens Wiklander * fdt_appendprop - append to or create a property
1761b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1762b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to change
1763b908c675SJens Wiklander * @name: name of the property to append to
1764b908c675SJens Wiklander * @val: pointer to data to append to the property value
1765b908c675SJens Wiklander * @len: length of the data to append to the property value
1766b908c675SJens Wiklander *
1767b908c675SJens Wiklander * fdt_appendprop() appends the value to the named property in the
1768b908c675SJens Wiklander * given node, creating the property if it does not already exist.
1769b908c675SJens Wiklander *
1770b908c675SJens Wiklander * This function may insert data into the blob, and will therefore
1771b908c675SJens Wiklander * change the offsets of some existing nodes.
1772b908c675SJens Wiklander *
1773b908c675SJens Wiklander * returns:
1774b908c675SJens Wiklander * 0, on success
1775b908c675SJens Wiklander * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1776b908c675SJens Wiklander * contain the new property value
1777b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1778b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1779b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1780b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1781b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1782b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1783b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1784b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1785b908c675SJens Wiklander */
1786b908c675SJens Wiklander int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
1787b908c675SJens Wiklander const void *val, int len);
1788b908c675SJens Wiklander
1789b908c675SJens Wiklander /**
1790b908c675SJens Wiklander * fdt_appendprop_u32 - append a 32-bit integer value to a property
1791b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1792b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to change
1793b908c675SJens Wiklander * @name: name of the property to change
1794b908c675SJens Wiklander * @val: 32-bit integer value to append to the property (native endian)
1795b908c675SJens Wiklander *
1796b908c675SJens Wiklander * fdt_appendprop_u32() appends the given 32-bit integer value
1797b908c675SJens Wiklander * (converting to big-endian if necessary) to the value of the named
1798b908c675SJens Wiklander * property in the given node, or creates a new property with that
1799b908c675SJens Wiklander * value if it does not already exist.
1800b908c675SJens Wiklander *
1801b908c675SJens Wiklander * This function may insert data into the blob, and will therefore
1802b908c675SJens Wiklander * change the offsets of some existing nodes.
1803b908c675SJens Wiklander *
1804b908c675SJens Wiklander * returns:
1805b908c675SJens Wiklander * 0, on success
1806b908c675SJens Wiklander * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1807b908c675SJens Wiklander * contain the new property value
1808b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1809b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1810b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1811b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1812b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1813b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1814b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1815b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1816b908c675SJens Wiklander */
fdt_appendprop_u32(void * fdt,int nodeoffset,const char * name,uint32_t val)1817b908c675SJens Wiklander static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
1818b908c675SJens Wiklander const char *name, uint32_t val)
1819b908c675SJens Wiklander {
1820b908c675SJens Wiklander fdt32_t tmp = cpu_to_fdt32(val);
1821b908c675SJens Wiklander return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1822b908c675SJens Wiklander }
1823b908c675SJens Wiklander
1824b908c675SJens Wiklander /**
1825b908c675SJens Wiklander * fdt_appendprop_u64 - append a 64-bit integer value to a property
1826b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1827b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to change
1828b908c675SJens Wiklander * @name: name of the property to change
1829b908c675SJens Wiklander * @val: 64-bit integer value to append to the property (native endian)
1830b908c675SJens Wiklander *
1831b908c675SJens Wiklander * fdt_appendprop_u64() appends the given 64-bit integer value
1832b908c675SJens Wiklander * (converting to big-endian if necessary) to the value of the named
1833b908c675SJens Wiklander * property in the given node, or creates a new property with that
1834b908c675SJens Wiklander * value if it does not already exist.
1835b908c675SJens Wiklander *
1836b908c675SJens Wiklander * This function may insert data into the blob, and will therefore
1837b908c675SJens Wiklander * change the offsets of some existing nodes.
1838b908c675SJens Wiklander *
1839b908c675SJens Wiklander * returns:
1840b908c675SJens Wiklander * 0, on success
1841b908c675SJens Wiklander * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1842b908c675SJens Wiklander * contain the new property value
1843b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1844b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1845b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1846b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1847b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1848b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1849b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1850b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1851b908c675SJens Wiklander */
fdt_appendprop_u64(void * fdt,int nodeoffset,const char * name,uint64_t val)1852b908c675SJens Wiklander static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
1853b908c675SJens Wiklander const char *name, uint64_t val)
1854b908c675SJens Wiklander {
1855b908c675SJens Wiklander fdt64_t tmp = cpu_to_fdt64(val);
1856b908c675SJens Wiklander return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1857b908c675SJens Wiklander }
1858b908c675SJens Wiklander
1859b908c675SJens Wiklander /**
1860b908c675SJens Wiklander * fdt_appendprop_cell - append a single cell value to a property
1861b908c675SJens Wiklander *
1862b908c675SJens Wiklander * This is an alternative name for fdt_appendprop_u32()
1863b908c675SJens Wiklander */
fdt_appendprop_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)1864b908c675SJens Wiklander static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
1865b908c675SJens Wiklander const char *name, uint32_t val)
1866b908c675SJens Wiklander {
1867b908c675SJens Wiklander return fdt_appendprop_u32(fdt, nodeoffset, name, val);
1868b908c675SJens Wiklander }
1869b908c675SJens Wiklander
1870b908c675SJens Wiklander /**
1871b908c675SJens Wiklander * fdt_appendprop_string - append a string to a property
1872b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1873b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to change
1874b908c675SJens Wiklander * @name: name of the property to change
1875b908c675SJens Wiklander * @str: string value to append to the property
1876b908c675SJens Wiklander *
1877b908c675SJens Wiklander * fdt_appendprop_string() appends the given string to the value of
1878b908c675SJens Wiklander * the named property in the given node, or creates a new property
1879b908c675SJens Wiklander * with that value if it does not already exist.
1880b908c675SJens Wiklander *
1881b908c675SJens Wiklander * This function may insert data into the blob, and will therefore
1882b908c675SJens Wiklander * change the offsets of some existing nodes.
1883b908c675SJens Wiklander *
1884b908c675SJens Wiklander * returns:
1885b908c675SJens Wiklander * 0, on success
1886b908c675SJens Wiklander * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1887b908c675SJens Wiklander * contain the new property value
1888b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1889b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1890b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1891b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1892b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1893b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1894b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1895b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1896b908c675SJens Wiklander */
1897b908c675SJens Wiklander #define fdt_appendprop_string(fdt, nodeoffset, name, str) \
1898b908c675SJens Wiklander fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
1899b908c675SJens Wiklander
1900b908c675SJens Wiklander /**
1901*17f326ebSJerome Forissier * fdt_appendprop_addrrange - append a address range property
1902*17f326ebSJerome Forissier * @fdt: pointer to the device tree blob
1903*17f326ebSJerome Forissier * @parent: offset of the parent node
1904*17f326ebSJerome Forissier * @nodeoffset: offset of the node to add a property at
1905*17f326ebSJerome Forissier * @name: name of property
1906*17f326ebSJerome Forissier * @addr: start address of a given range
1907*17f326ebSJerome Forissier * @size: size of a given range
1908*17f326ebSJerome Forissier *
1909*17f326ebSJerome Forissier * fdt_appendprop_addrrange() appends an address range value (start
1910*17f326ebSJerome Forissier * address and size) to the value of the named property in the given
1911*17f326ebSJerome Forissier * node, or creates a new property with that value if it does not
1912*17f326ebSJerome Forissier * already exist.
1913*17f326ebSJerome Forissier * If "name" is not specified, a default "reg" is used.
1914*17f326ebSJerome Forissier * Cell sizes are determined by parent's #address-cells and #size-cells.
1915*17f326ebSJerome Forissier *
1916*17f326ebSJerome Forissier * This function may insert data into the blob, and will therefore
1917*17f326ebSJerome Forissier * change the offsets of some existing nodes.
1918*17f326ebSJerome Forissier *
1919*17f326ebSJerome Forissier * returns:
1920*17f326ebSJerome Forissier * 0, on success
1921*17f326ebSJerome Forissier * -FDT_ERR_BADLAYOUT,
1922*17f326ebSJerome Forissier * -FDT_ERR_BADMAGIC,
1923*17f326ebSJerome Forissier * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
1924*17f326ebSJerome Forissier * #address-cells property
1925*17f326ebSJerome Forissier * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1926*17f326ebSJerome Forissier * -FDT_ERR_BADSTATE,
1927*17f326ebSJerome Forissier * -FDT_ERR_BADSTRUCTURE,
1928*17f326ebSJerome Forissier * -FDT_ERR_BADVERSION,
1929*17f326ebSJerome Forissier * -FDT_ERR_BADVALUE, addr or size doesn't fit to respective cells size
1930*17f326ebSJerome Forissier * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1931*17f326ebSJerome Forissier * contain a new property
1932*17f326ebSJerome Forissier * -FDT_ERR_TRUNCATED, standard meanings
1933*17f326ebSJerome Forissier */
1934*17f326ebSJerome Forissier int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,
1935*17f326ebSJerome Forissier const char *name, uint64_t addr, uint64_t size);
1936*17f326ebSJerome Forissier
1937*17f326ebSJerome Forissier /**
1938b908c675SJens Wiklander * fdt_delprop - delete a property
1939b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1940b908c675SJens Wiklander * @nodeoffset: offset of the node whose property to nop
1941b908c675SJens Wiklander * @name: name of the property to nop
1942b908c675SJens Wiklander *
1943b908c675SJens Wiklander * fdt_del_property() will delete the given property.
1944b908c675SJens Wiklander *
1945b908c675SJens Wiklander * This function will delete data from the blob, and will therefore
1946b908c675SJens Wiklander * change the offsets of some existing nodes.
1947b908c675SJens Wiklander *
1948b908c675SJens Wiklander * returns:
1949b908c675SJens Wiklander * 0, on success
1950b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, node does not have the named property
1951b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1952b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
1953b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
1954b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
1955b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
1956b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
1957b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
1958b908c675SJens Wiklander */
1959b908c675SJens Wiklander int fdt_delprop(void *fdt, int nodeoffset, const char *name);
1960b908c675SJens Wiklander
1961b908c675SJens Wiklander /**
1962b908c675SJens Wiklander * fdt_add_subnode_namelen - creates a new node based on substring
1963b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1964b908c675SJens Wiklander * @parentoffset: structure block offset of a node
1965b908c675SJens Wiklander * @name: name of the subnode to locate
1966b908c675SJens Wiklander * @namelen: number of characters of name to consider
1967b908c675SJens Wiklander *
1968b908c675SJens Wiklander * Identical to fdt_add_subnode(), but use only the first namelen
1969b908c675SJens Wiklander * characters of name as the name of the new node. This is useful for
1970b908c675SJens Wiklander * creating subnodes based on a portion of a larger string, such as a
1971b908c675SJens Wiklander * full path.
1972b908c675SJens Wiklander */
197301d6a9daSBryan O'Donoghue #ifndef SWIG /* Not available in Python */
1974b908c675SJens Wiklander int fdt_add_subnode_namelen(void *fdt, int parentoffset,
1975b908c675SJens Wiklander const char *name, int namelen);
197601d6a9daSBryan O'Donoghue #endif
1977b908c675SJens Wiklander
1978b908c675SJens Wiklander /**
1979b908c675SJens Wiklander * fdt_add_subnode - creates a new node
1980b908c675SJens Wiklander * @fdt: pointer to the device tree blob
1981b908c675SJens Wiklander * @parentoffset: structure block offset of a node
1982b908c675SJens Wiklander * @name: name of the subnode to locate
1983b908c675SJens Wiklander *
1984b908c675SJens Wiklander * fdt_add_subnode() creates a new node as a subnode of the node at
1985b908c675SJens Wiklander * structure block offset parentoffset, with the given name (which
1986b908c675SJens Wiklander * should include the unit address, if any).
1987b908c675SJens Wiklander *
1988b908c675SJens Wiklander * This function will insert data into the blob, and will therefore
1989b908c675SJens Wiklander * change the offsets of some existing nodes.
1990b908c675SJens Wiklander
1991b908c675SJens Wiklander * returns:
199201d6a9daSBryan O'Donoghue * structure block offset of the created nodeequested subnode (>=0), on
199301d6a9daSBryan O'Donoghue * success
1994b908c675SJens Wiklander * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
199501d6a9daSBryan O'Donoghue * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
199601d6a9daSBryan O'Donoghue * tag
1997b908c675SJens Wiklander * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
1998b908c675SJens Wiklander * the given name
1999b908c675SJens Wiklander * -FDT_ERR_NOSPACE, if there is insufficient free space in the
2000b908c675SJens Wiklander * blob to contain the new node
2001b908c675SJens Wiklander * -FDT_ERR_NOSPACE
2002b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT
2003b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
2004b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
2005b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
2006b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
2007b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings.
2008b908c675SJens Wiklander */
2009b908c675SJens Wiklander int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
2010b908c675SJens Wiklander
2011b908c675SJens Wiklander /**
2012b908c675SJens Wiklander * fdt_del_node - delete a node (subtree)
2013b908c675SJens Wiklander * @fdt: pointer to the device tree blob
2014b908c675SJens Wiklander * @nodeoffset: offset of the node to nop
2015b908c675SJens Wiklander *
2016b908c675SJens Wiklander * fdt_del_node() will remove the given node, including all its
2017b908c675SJens Wiklander * subnodes if any, from the blob.
2018b908c675SJens Wiklander *
2019b908c675SJens Wiklander * This function will delete data from the blob, and will therefore
2020b908c675SJens Wiklander * change the offsets of some existing nodes.
2021b908c675SJens Wiklander *
2022b908c675SJens Wiklander * returns:
2023b908c675SJens Wiklander * 0, on success
2024b908c675SJens Wiklander * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
2025b908c675SJens Wiklander * -FDT_ERR_BADLAYOUT,
2026b908c675SJens Wiklander * -FDT_ERR_BADMAGIC,
2027b908c675SJens Wiklander * -FDT_ERR_BADVERSION,
2028b908c675SJens Wiklander * -FDT_ERR_BADSTATE,
2029b908c675SJens Wiklander * -FDT_ERR_BADSTRUCTURE,
2030b908c675SJens Wiklander * -FDT_ERR_TRUNCATED, standard meanings
2031b908c675SJens Wiklander */
2032b908c675SJens Wiklander int fdt_del_node(void *fdt, int nodeoffset);
2033b908c675SJens Wiklander
203401d6a9daSBryan O'Donoghue /**
203501d6a9daSBryan O'Donoghue * fdt_overlay_apply - Applies a DT overlay on a base DT
203601d6a9daSBryan O'Donoghue * @fdt: pointer to the base device tree blob
203701d6a9daSBryan O'Donoghue * @fdto: pointer to the device tree overlay blob
203801d6a9daSBryan O'Donoghue *
203901d6a9daSBryan O'Donoghue * fdt_overlay_apply() will apply the given device tree overlay on the
204001d6a9daSBryan O'Donoghue * given base device tree.
204101d6a9daSBryan O'Donoghue *
204201d6a9daSBryan O'Donoghue * Expect the base device tree to be modified, even if the function
204301d6a9daSBryan O'Donoghue * returns an error.
204401d6a9daSBryan O'Donoghue *
204501d6a9daSBryan O'Donoghue * returns:
204601d6a9daSBryan O'Donoghue * 0, on success
204701d6a9daSBryan O'Donoghue * -FDT_ERR_NOSPACE, there's not enough space in the base device tree
204801d6a9daSBryan O'Donoghue * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or
204901d6a9daSBryan O'Donoghue * properties in the base DT
205001d6a9daSBryan O'Donoghue * -FDT_ERR_BADPHANDLE,
205101d6a9daSBryan O'Donoghue * -FDT_ERR_BADOVERLAY,
205201d6a9daSBryan O'Donoghue * -FDT_ERR_NOPHANDLES,
205301d6a9daSBryan O'Donoghue * -FDT_ERR_INTERNAL,
205401d6a9daSBryan O'Donoghue * -FDT_ERR_BADLAYOUT,
205501d6a9daSBryan O'Donoghue * -FDT_ERR_BADMAGIC,
205601d6a9daSBryan O'Donoghue * -FDT_ERR_BADOFFSET,
205701d6a9daSBryan O'Donoghue * -FDT_ERR_BADPATH,
205801d6a9daSBryan O'Donoghue * -FDT_ERR_BADVERSION,
205901d6a9daSBryan O'Donoghue * -FDT_ERR_BADSTRUCTURE,
206001d6a9daSBryan O'Donoghue * -FDT_ERR_BADSTATE,
206101d6a9daSBryan O'Donoghue * -FDT_ERR_TRUNCATED, standard meanings
206201d6a9daSBryan O'Donoghue */
206301d6a9daSBryan O'Donoghue int fdt_overlay_apply(void *fdt, void *fdto);
206401d6a9daSBryan O'Donoghue
2065b908c675SJens Wiklander /**********************************************************************/
2066b908c675SJens Wiklander /* Debugging / informational functions */
2067b908c675SJens Wiklander /**********************************************************************/
2068b908c675SJens Wiklander
2069b908c675SJens Wiklander const char *fdt_strerror(int errval);
2070b908c675SJens Wiklander
207101d6a9daSBryan O'Donoghue #endif /* LIBFDT_H */
2072