aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/dtc/libfdt
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/dtc/libfdt')
-rw-r--r--scripts/dtc/libfdt/Makefile.libfdt2
-rw-r--r--scripts/dtc/libfdt/fdt_ro.c30
-rw-r--r--scripts/dtc/libfdt/fdt_rw.c6
-rw-r--r--scripts/dtc/libfdt/fdt_strerror.c6
-rw-r--r--scripts/dtc/libfdt/fdt_wip.c29
-rw-r--r--scripts/dtc/libfdt/libfdt.h210
-rw-r--r--scripts/dtc/libfdt/libfdt_env.h1
7 files changed, 242 insertions, 42 deletions
diff --git a/scripts/dtc/libfdt/Makefile.libfdt b/scripts/dtc/libfdt/Makefile.libfdt
index 09c322ed82ba..098b3f36e668 100644
--- a/scripts/dtc/libfdt/Makefile.libfdt
+++ b/scripts/dtc/libfdt/Makefile.libfdt
@@ -7,5 +7,5 @@ LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1
7LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h 7LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h
8LIBFDT_VERSION = version.lds 8LIBFDT_VERSION = version.lds
9LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \ 9LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \
10 fdt_addresses.c 10 fdt_addresses.c fdt_overlay.c
11LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o) 11LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)
diff --git a/scripts/dtc/libfdt/fdt_ro.c b/scripts/dtc/libfdt/fdt_ro.c
index 50cce864283c..3d00d2eee0e3 100644
--- a/scripts/dtc/libfdt/fdt_ro.c
+++ b/scripts/dtc/libfdt/fdt_ro.c
@@ -88,6 +88,32 @@ static int _fdt_string_eq(const void *fdt, int stroffset,
88 return (strlen(p) == len) && (memcmp(p, s, len) == 0); 88 return (strlen(p) == len) && (memcmp(p, s, len) == 0);
89} 89}
90 90
91uint32_t fdt_get_max_phandle(const void *fdt)
92{
93 uint32_t max_phandle = 0;
94 int offset;
95
96 for (offset = fdt_next_node(fdt, -1, NULL);;
97 offset = fdt_next_node(fdt, offset, NULL)) {
98 uint32_t phandle;
99
100 if (offset == -FDT_ERR_NOTFOUND)
101 return max_phandle;
102
103 if (offset < 0)
104 return (uint32_t)-1;
105
106 phandle = fdt_get_phandle(fdt, offset);
107 if (phandle == (uint32_t)-1)
108 continue;
109
110 if (phandle > max_phandle)
111 max_phandle = phandle;
112 }
113
114 return 0;
115}
116
91int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size) 117int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size)
92{ 118{
93 FDT_CHECK_HEADER(fdt); 119 FDT_CHECK_HEADER(fdt);
@@ -545,7 +571,7 @@ int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property)
545 571
546 list = fdt_getprop(fdt, nodeoffset, property, &length); 572 list = fdt_getprop(fdt, nodeoffset, property, &length);
547 if (!list) 573 if (!list)
548 return -length; 574 return length;
549 575
550 end = list + length; 576 end = list + length;
551 577
@@ -571,7 +597,7 @@ int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
571 597
572 list = fdt_getprop(fdt, nodeoffset, property, &length); 598 list = fdt_getprop(fdt, nodeoffset, property, &length);
573 if (!list) 599 if (!list)
574 return -length; 600 return length;
575 601
576 len = strlen(string) + 1; 602 len = strlen(string) + 1;
577 end = list + length; 603 end = list + length;
diff --git a/scripts/dtc/libfdt/fdt_rw.c b/scripts/dtc/libfdt/fdt_rw.c
index 8be02b1f68f3..2eed4f58387c 100644
--- a/scripts/dtc/libfdt/fdt_rw.c
+++ b/scripts/dtc/libfdt/fdt_rw.c
@@ -191,17 +191,13 @@ int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size)
191int fdt_del_mem_rsv(void *fdt, int n) 191int fdt_del_mem_rsv(void *fdt, int n)
192{ 192{
193 struct fdt_reserve_entry *re = _fdt_mem_rsv_w(fdt, n); 193 struct fdt_reserve_entry *re = _fdt_mem_rsv_w(fdt, n);
194 int err;
195 194
196 FDT_RW_CHECK_HEADER(fdt); 195 FDT_RW_CHECK_HEADER(fdt);
197 196
198 if (n >= fdt_num_mem_rsv(fdt)) 197 if (n >= fdt_num_mem_rsv(fdt))
199 return -FDT_ERR_NOTFOUND; 198 return -FDT_ERR_NOTFOUND;
200 199
201 err = _fdt_splice_mem_rsv(fdt, re, 1, 0); 200 return _fdt_splice_mem_rsv(fdt, re, 1, 0);
202 if (err)
203 return err;
204 return 0;
205} 201}
206 202
207static int _fdt_resize_property(void *fdt, int nodeoffset, const char *name, 203static int _fdt_resize_property(void *fdt, int nodeoffset, const char *name,
diff --git a/scripts/dtc/libfdt/fdt_strerror.c b/scripts/dtc/libfdt/fdt_strerror.c
index e6c3ceee8c58..9677a1887e57 100644
--- a/scripts/dtc/libfdt/fdt_strerror.c
+++ b/scripts/dtc/libfdt/fdt_strerror.c
@@ -69,6 +69,7 @@ static struct fdt_errtabent fdt_errtable[] = {
69 69
70 FDT_ERRTABENT(FDT_ERR_BADOFFSET), 70 FDT_ERRTABENT(FDT_ERR_BADOFFSET),
71 FDT_ERRTABENT(FDT_ERR_BADPATH), 71 FDT_ERRTABENT(FDT_ERR_BADPATH),
72 FDT_ERRTABENT(FDT_ERR_BADPHANDLE),
72 FDT_ERRTABENT(FDT_ERR_BADSTATE), 73 FDT_ERRTABENT(FDT_ERR_BADSTATE),
73 74
74 FDT_ERRTABENT(FDT_ERR_TRUNCATED), 75 FDT_ERRTABENT(FDT_ERR_TRUNCATED),
@@ -76,6 +77,11 @@ static struct fdt_errtabent fdt_errtable[] = {
76 FDT_ERRTABENT(FDT_ERR_BADVERSION), 77 FDT_ERRTABENT(FDT_ERR_BADVERSION),
77 FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE), 78 FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE),
78 FDT_ERRTABENT(FDT_ERR_BADLAYOUT), 79 FDT_ERRTABENT(FDT_ERR_BADLAYOUT),
80 FDT_ERRTABENT(FDT_ERR_INTERNAL),
81 FDT_ERRTABENT(FDT_ERR_BADNCELLS),
82 FDT_ERRTABENT(FDT_ERR_BADVALUE),
83 FDT_ERRTABENT(FDT_ERR_BADOVERLAY),
84 FDT_ERRTABENT(FDT_ERR_NOPHANDLES),
79}; 85};
80#define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0])) 86#define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))
81 87
diff --git a/scripts/dtc/libfdt/fdt_wip.c b/scripts/dtc/libfdt/fdt_wip.c
index c5bbb68d3273..6aaab399929c 100644
--- a/scripts/dtc/libfdt/fdt_wip.c
+++ b/scripts/dtc/libfdt/fdt_wip.c
@@ -55,21 +55,42 @@
55 55
56#include "libfdt_internal.h" 56#include "libfdt_internal.h"
57 57
58int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
59 const char *name, int namelen,
60 uint32_t idx, const void *val,
61 int len)
62{
63 void *propval;
64 int proplen;
65
66 propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen,
67 &proplen);
68 if (!propval)
69 return proplen;
70
71 if (proplen < (len + idx))
72 return -FDT_ERR_NOSPACE;
73
74 memcpy((char *)propval + idx, val, len);
75 return 0;
76}
77
58int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, 78int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
59 const void *val, int len) 79 const void *val, int len)
60{ 80{
61 void *propval; 81 const void *propval;
62 int proplen; 82 int proplen;
63 83
64 propval = fdt_getprop_w(fdt, nodeoffset, name, &proplen); 84 propval = fdt_getprop(fdt, nodeoffset, name, &proplen);
65 if (! propval) 85 if (! propval)
66 return proplen; 86 return proplen;
67 87
68 if (proplen != len) 88 if (proplen != len)
69 return -FDT_ERR_NOSPACE; 89 return -FDT_ERR_NOSPACE;
70 90
71 memcpy(propval, val, len); 91 return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name,
72 return 0; 92 strlen(name), 0,
93 val, len);
73} 94}
74 95
75static void _fdt_nop_region(void *start, int len) 96static void _fdt_nop_region(void *start, int len)
diff --git a/scripts/dtc/libfdt/libfdt.h b/scripts/dtc/libfdt/libfdt.h
index 59ca33976e56..b842b156fa17 100644
--- a/scripts/dtc/libfdt/libfdt.h
+++ b/scripts/dtc/libfdt/libfdt.h
@@ -61,7 +61,7 @@
61#define FDT_ERR_NOTFOUND 1 61#define FDT_ERR_NOTFOUND 1
62 /* FDT_ERR_NOTFOUND: The requested node or property does not exist */ 62 /* FDT_ERR_NOTFOUND: The requested node or property does not exist */
63#define FDT_ERR_EXISTS 2 63#define FDT_ERR_EXISTS 2
64 /* FDT_ERR_EXISTS: Attemped to create a node or property which 64 /* FDT_ERR_EXISTS: Attempted to create a node or property which
65 * already exists */ 65 * already exists */
66#define FDT_ERR_NOSPACE 3 66#define FDT_ERR_NOSPACE 3
67 /* FDT_ERR_NOSPACE: Operation needed to expand the device 67 /* FDT_ERR_NOSPACE: Operation needed to expand the device
@@ -79,8 +79,10 @@
79 * (e.g. missing a leading / for a function which requires an 79 * (e.g. missing a leading / for a function which requires an
80 * absolute path) */ 80 * absolute path) */
81#define FDT_ERR_BADPHANDLE 6 81#define FDT_ERR_BADPHANDLE 6
82 /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle 82 /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.
83 * value. phandle values of 0 and -1 are not permitted. */ 83 * This can be caused either by an invalid phandle property
84 * length, or the phandle value was either 0 or -1, which are
85 * not permitted. */
84#define FDT_ERR_BADSTATE 7 86#define FDT_ERR_BADSTATE 7
85 /* FDT_ERR_BADSTATE: Function was passed an incomplete device 87 /* FDT_ERR_BADSTATE: Function was passed an incomplete device
86 * tree created by the sequential-write functions, which is 88 * tree created by the sequential-write functions, which is
@@ -126,7 +128,16 @@
126 * value. For example: a property expected to contain a string list 128 * value. For example: a property expected to contain a string list
127 * is not NUL-terminated within the length of its value. */ 129 * is not NUL-terminated within the length of its value. */
128 130
129#define FDT_ERR_MAX 15 131#define FDT_ERR_BADOVERLAY 16
132 /* FDT_ERR_BADOVERLAY: The device tree overlay, while
133 * correctly structured, cannot be applied due to some
134 * unexpected or missing value, property or node. */
135
136#define FDT_ERR_NOPHANDLES 17
137 /* FDT_ERR_NOPHANDLES: The device tree doesn't have any
138 * phandle available anymore without causing an overflow */
139
140#define FDT_ERR_MAX 17
130 141
131/**********************************************************************/ 142/**********************************************************************/
132/* Low-level functions (you probably don't need these) */ 143/* Low-level functions (you probably don't need these) */
@@ -168,27 +179,55 @@ int fdt_first_subnode(const void *fdt, int offset);
168 */ 179 */
169int fdt_next_subnode(const void *fdt, int offset); 180int fdt_next_subnode(const void *fdt, int offset);
170 181
182/**
183 * fdt_for_each_subnode - iterate over all subnodes of a parent
184 *
185 * @node: child node (int, lvalue)
186 * @fdt: FDT blob (const void *)
187 * @parent: parent node (int)
188 *
189 * This is actually a wrapper around a for loop and would be used like so:
190 *
191 * fdt_for_each_subnode(node, fdt, parent) {
192 * Use node
193 * ...
194 * }
195 *
196 * if ((node < 0) && (node != -FDT_ERR_NOT_FOUND)) {
197 * Error handling
198 * }
199 *
200 * Note that this is implemented as a macro and @node is used as
201 * iterator in the loop. The parent variable be constant or even a
202 * literal.
203 *
204 */
205#define fdt_for_each_subnode(node, fdt, parent) \
206 for (node = fdt_first_subnode(fdt, parent); \
207 node >= 0; \
208 node = fdt_next_subnode(fdt, node))
209
171/**********************************************************************/ 210/**********************************************************************/
172/* General functions */ 211/* General functions */
173/**********************************************************************/ 212/**********************************************************************/
174 213
175#define fdt_get_header(fdt, field) \ 214#define fdt_get_header(fdt, field) \
176 (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field)) 215 (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
177#define fdt_magic(fdt) (fdt_get_header(fdt, magic)) 216#define fdt_magic(fdt) (fdt_get_header(fdt, magic))
178#define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize)) 217#define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
179#define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct)) 218#define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
180#define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings)) 219#define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
181#define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap)) 220#define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
182#define fdt_version(fdt) (fdt_get_header(fdt, version)) 221#define fdt_version(fdt) (fdt_get_header(fdt, version))
183#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version)) 222#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
184#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys)) 223#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
185#define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings)) 224#define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
186#define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct)) 225#define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
187 226
188#define __fdt_set_hdr(name) \ 227#define __fdt_set_hdr(name) \
189 static inline void fdt_set_##name(void *fdt, uint32_t val) \ 228 static inline void fdt_set_##name(void *fdt, uint32_t val) \
190 { \ 229 { \
191 struct fdt_header *fdth = (struct fdt_header*)fdt; \ 230 struct fdt_header *fdth = (struct fdt_header *)fdt; \
192 fdth->name = cpu_to_fdt32(val); \ 231 fdth->name = cpu_to_fdt32(val); \
193 } 232 }
194__fdt_set_hdr(magic); 233__fdt_set_hdr(magic);
@@ -259,6 +298,21 @@ int fdt_move(const void *fdt, void *buf, int bufsize);
259const char *fdt_string(const void *fdt, int stroffset); 298const char *fdt_string(const void *fdt, int stroffset);
260 299
261/** 300/**
301 * fdt_get_max_phandle - retrieves the highest phandle in a tree
302 * @fdt: pointer to the device tree blob
303 *
304 * fdt_get_max_phandle retrieves the highest phandle in the given
305 * device tree. This will ignore badly formatted phandles, or phandles
306 * with a value of 0 or -1.
307 *
308 * returns:
309 * the highest phandle on success
310 * 0, if no phandle was found in the device tree
311 * -1, if an error occurred
312 */
313uint32_t fdt_get_max_phandle(const void *fdt);
314
315/**
262 * fdt_num_mem_rsv - retrieve the number of memory reserve map entries 316 * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
263 * @fdt: pointer to the device tree blob 317 * @fdt: pointer to the device tree blob
264 * 318 *
@@ -318,8 +372,9 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
318 * returns: 372 * returns:
319 * structure block offset of the requested subnode (>=0), on success 373 * structure block offset of the requested subnode (>=0), on success
320 * -FDT_ERR_NOTFOUND, if the requested subnode does not exist 374 * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
321 * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag 375 * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
322 * -FDT_ERR_BADMAGIC, 376 * tag
377 * -FDT_ERR_BADMAGIC,
323 * -FDT_ERR_BADVERSION, 378 * -FDT_ERR_BADVERSION,
324 * -FDT_ERR_BADSTATE, 379 * -FDT_ERR_BADSTATE,
325 * -FDT_ERR_BADSTRUCTURE, 380 * -FDT_ERR_BADSTRUCTURE,
@@ -351,7 +406,8 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
351 * address). 406 * address).
352 * 407 *
353 * returns: 408 * returns:
354 * structure block offset of the node with the requested path (>=0), on success 409 * structure block offset of the node with the requested path (>=0), on
410 * success
355 * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid 411 * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
356 * -FDT_ERR_NOTFOUND, if the requested node does not exist 412 * -FDT_ERR_NOTFOUND, if the requested node does not exist
357 * -FDT_ERR_BADMAGIC, 413 * -FDT_ERR_BADMAGIC,
@@ -375,10 +431,12 @@ int fdt_path_offset(const void *fdt, const char *path);
375 * 431 *
376 * returns: 432 * returns:
377 * pointer to the node's name, on success 433 * pointer to the node's name, on success
378 * If lenp is non-NULL, *lenp contains the length of that name (>=0) 434 * If lenp is non-NULL, *lenp contains the length of that name
435 * (>=0)
379 * NULL, on error 436 * NULL, on error
380 * if lenp is non-NULL *lenp contains an error code (<0): 437 * if lenp is non-NULL *lenp contains an error code (<0):
381 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 438 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
439 * tag
382 * -FDT_ERR_BADMAGIC, 440 * -FDT_ERR_BADMAGIC,
383 * -FDT_ERR_BADVERSION, 441 * -FDT_ERR_BADVERSION,
384 * -FDT_ERR_BADSTATE, standard meanings 442 * -FDT_ERR_BADSTATE, standard meanings
@@ -427,6 +485,33 @@ int fdt_first_property_offset(const void *fdt, int nodeoffset);
427int fdt_next_property_offset(const void *fdt, int offset); 485int fdt_next_property_offset(const void *fdt, int offset);
428 486
429/** 487/**
488 * fdt_for_each_property_offset - iterate over all properties of a node
489 *
490 * @property_offset: property offset (int, lvalue)
491 * @fdt: FDT blob (const void *)
492 * @node: node offset (int)
493 *
494 * This is actually a wrapper around a for loop and would be used like so:
495 *
496 * fdt_for_each_property_offset(property, fdt, node) {
497 * Use property
498 * ...
499 * }
500 *
501 * if ((property < 0) && (property != -FDT_ERR_NOT_FOUND)) {
502 * Error handling
503 * }
504 *
505 * Note that this is implemented as a macro and property is used as
506 * iterator in the loop. The node variable can be constant or even a
507 * literal.
508 */
509#define fdt_for_each_property_offset(property, fdt, node) \
510 for (property = fdt_first_property_offset(fdt, node); \
511 property >= 0; \
512 property = fdt_next_property_offset(fdt, property))
513
514/**
430 * fdt_get_property_by_offset - retrieve the property at a given offset 515 * fdt_get_property_by_offset - retrieve the property at a given offset
431 * @fdt: pointer to the device tree blob 516 * @fdt: pointer to the device tree blob
432 * @offset: offset of the property to retrieve 517 * @offset: offset of the property to retrieve
@@ -490,7 +575,8 @@ const struct fdt_property *fdt_get_property_namelen(const void *fdt,
490 * NULL, on error 575 * NULL, on error
491 * if lenp is non-NULL, *lenp contains an error code (<0): 576 * if lenp is non-NULL, *lenp contains an error code (<0):
492 * -FDT_ERR_NOTFOUND, node does not have named property 577 * -FDT_ERR_NOTFOUND, node does not have named property
493 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 578 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
579 * tag
494 * -FDT_ERR_BADMAGIC, 580 * -FDT_ERR_BADMAGIC,
495 * -FDT_ERR_BADVERSION, 581 * -FDT_ERR_BADVERSION,
496 * -FDT_ERR_BADSTATE, 582 * -FDT_ERR_BADSTATE,
@@ -554,6 +640,13 @@ const void *fdt_getprop_by_offset(const void *fdt, int offset,
554 */ 640 */
555const void *fdt_getprop_namelen(const void *fdt, int nodeoffset, 641const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
556 const char *name, int namelen, int *lenp); 642 const char *name, int namelen, int *lenp);
643static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,
644 const char *name, int namelen,
645 int *lenp)
646{
647 return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,
648 namelen, lenp);
649}
557 650
558/** 651/**
559 * fdt_getprop - retrieve the value of a given property 652 * fdt_getprop - retrieve the value of a given property
@@ -575,7 +668,8 @@ const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
575 * NULL, on error 668 * NULL, on error
576 * if lenp is non-NULL, *lenp contains an error code (<0): 669 * if lenp is non-NULL, *lenp contains an error code (<0):
577 * -FDT_ERR_NOTFOUND, node does not have named property 670 * -FDT_ERR_NOTFOUND, node does not have named property
578 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 671 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
672 * tag
579 * -FDT_ERR_BADMAGIC, 673 * -FDT_ERR_BADMAGIC,
580 * -FDT_ERR_BADVERSION, 674 * -FDT_ERR_BADVERSION,
581 * -FDT_ERR_BADSTATE, 675 * -FDT_ERR_BADSTATE,
@@ -617,7 +711,7 @@ const char *fdt_get_alias_namelen(const void *fdt,
617 const char *name, int namelen); 711 const char *name, int namelen);
618 712
619/** 713/**
620 * fdt_get_alias - retreive the path referenced by a given alias 714 * fdt_get_alias - retrieve the path referenced by a given alias
621 * @fdt: pointer to the device tree blob 715 * @fdt: pointer to the device tree blob
622 * @name: name of the alias th look up 716 * @name: name of the alias th look up
623 * 717 *
@@ -647,7 +741,7 @@ const char *fdt_get_alias(const void *fdt, const char *name);
647 * 0, on success 741 * 0, on success
648 * buf contains the absolute path of the node at 742 * buf contains the absolute path of the node at
649 * nodeoffset, as a NUL-terminated string. 743 * nodeoffset, as a NUL-terminated string.
650 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 744 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
651 * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1) 745 * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
652 * characters and will not fit in the given buffer. 746 * characters and will not fit in the given buffer.
653 * -FDT_ERR_BADMAGIC, 747 * -FDT_ERR_BADMAGIC,
@@ -677,11 +771,11 @@ int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
677 * structure from the start to nodeoffset. 771 * structure from the start to nodeoffset.
678 * 772 *
679 * returns: 773 * returns:
680
681 * structure block offset of the node at node offset's ancestor 774 * structure block offset of the node at node offset's ancestor
682 * of depth supernodedepth (>=0), on success 775 * of depth supernodedepth (>=0), on success
683 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 776 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
684* -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset 777 * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of
778 * nodeoffset
685 * -FDT_ERR_BADMAGIC, 779 * -FDT_ERR_BADMAGIC,
686 * -FDT_ERR_BADVERSION, 780 * -FDT_ERR_BADVERSION,
687 * -FDT_ERR_BADSTATE, 781 * -FDT_ERR_BADSTATE,
@@ -703,7 +797,7 @@ int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
703 * 797 *
704 * returns: 798 * returns:
705 * depth of the node at nodeoffset (>=0), on success 799 * depth of the node at nodeoffset (>=0), on success
706 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 800 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
707 * -FDT_ERR_BADMAGIC, 801 * -FDT_ERR_BADMAGIC,
708 * -FDT_ERR_BADVERSION, 802 * -FDT_ERR_BADVERSION,
709 * -FDT_ERR_BADSTATE, 803 * -FDT_ERR_BADSTATE,
@@ -726,7 +820,7 @@ int fdt_node_depth(const void *fdt, int nodeoffset);
726 * returns: 820 * returns:
727 * structure block offset of the parent of the node at nodeoffset 821 * structure block offset of the parent of the node at nodeoffset
728 * (>=0), on success 822 * (>=0), on success
729 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 823 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
730 * -FDT_ERR_BADMAGIC, 824 * -FDT_ERR_BADMAGIC,
731 * -FDT_ERR_BADVERSION, 825 * -FDT_ERR_BADVERSION,
732 * -FDT_ERR_BADSTATE, 826 * -FDT_ERR_BADSTATE,
@@ -766,7 +860,7 @@ int fdt_parent_offset(const void *fdt, int nodeoffset);
766 * on success 860 * on success
767 * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the 861 * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
768 * tree after startoffset 862 * tree after startoffset
769 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 863 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
770 * -FDT_ERR_BADMAGIC, 864 * -FDT_ERR_BADMAGIC,
771 * -FDT_ERR_BADVERSION, 865 * -FDT_ERR_BADVERSION,
772 * -FDT_ERR_BADSTATE, 866 * -FDT_ERR_BADSTATE,
@@ -813,7 +907,7 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
813 * 1, if the node has a 'compatible' property, but it does not list 907 * 1, if the node has a 'compatible' property, but it does not list
814 * the given string 908 * the given string
815 * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property 909 * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
816 * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag 910 * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
817 * -FDT_ERR_BADMAGIC, 911 * -FDT_ERR_BADMAGIC,
818 * -FDT_ERR_BADVERSION, 912 * -FDT_ERR_BADVERSION,
819 * -FDT_ERR_BADSTATE, 913 * -FDT_ERR_BADSTATE,
@@ -850,7 +944,7 @@ int fdt_node_check_compatible(const void *fdt, int nodeoffset,
850 * on success 944 * on success
851 * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the 945 * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
852 * tree after startoffset 946 * tree after startoffset
853 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 947 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
854 * -FDT_ERR_BADMAGIC, 948 * -FDT_ERR_BADMAGIC,
855 * -FDT_ERR_BADVERSION, 949 * -FDT_ERR_BADVERSION,
856 * -FDT_ERR_BADSTATE, 950 * -FDT_ERR_BADSTATE,
@@ -960,7 +1054,8 @@ const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
960 * returns: 1054 * returns:
961 * 0 <= n < FDT_MAX_NCELLS, on success 1055 * 0 <= n < FDT_MAX_NCELLS, on success
962 * 2, if the node has no #address-cells property 1056 * 2, if the node has no #address-cells property
963 * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid #address-cells property 1057 * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
1058 * #address-cells property
964 * -FDT_ERR_BADMAGIC, 1059 * -FDT_ERR_BADMAGIC,
965 * -FDT_ERR_BADVERSION, 1060 * -FDT_ERR_BADVERSION,
966 * -FDT_ERR_BADSTATE, 1061 * -FDT_ERR_BADSTATE,
@@ -980,7 +1075,8 @@ int fdt_address_cells(const void *fdt, int nodeoffset);
980 * returns: 1075 * returns:
981 * 0 <= n < FDT_MAX_NCELLS, on success 1076 * 0 <= n < FDT_MAX_NCELLS, on success
982 * 2, if the node has no #address-cells property 1077 * 2, if the node has no #address-cells property
983 * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid #size-cells property 1078 * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
1079 * #size-cells property
984 * -FDT_ERR_BADMAGIC, 1080 * -FDT_ERR_BADMAGIC,
985 * -FDT_ERR_BADVERSION, 1081 * -FDT_ERR_BADVERSION,
986 * -FDT_ERR_BADSTATE, 1082 * -FDT_ERR_BADSTATE,
@@ -995,6 +1091,27 @@ int fdt_size_cells(const void *fdt, int nodeoffset);
995/**********************************************************************/ 1091/**********************************************************************/
996 1092
997/** 1093/**
1094 * fdt_setprop_inplace_namelen_partial - change a property's value,
1095 * but not its size
1096 * @fdt: pointer to the device tree blob
1097 * @nodeoffset: offset of the node whose property to change
1098 * @name: name of the property to change
1099 * @namelen: number of characters of name to consider
1100 * @idx: index of the property to change in the array
1101 * @val: pointer to data to replace the property value with
1102 * @len: length of the property value
1103 *
1104 * Identical to fdt_setprop_inplace(), but modifies the given property
1105 * starting from the given index, and using only the first characters
1106 * of the name. It is useful when you want to manipulate only one value of
1107 * an array and you have a string that doesn't end with \0.
1108 */
1109int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
1110 const char *name, int namelen,
1111 uint32_t idx, const void *val,
1112 int len);
1113
1114/**
998 * fdt_setprop_inplace - change a property's value, but not its size 1115 * fdt_setprop_inplace - change a property's value, but not its size
999 * @fdt: pointer to the device tree blob 1116 * @fdt: pointer to the device tree blob
1000 * @nodeoffset: offset of the node whose property to change 1117 * @nodeoffset: offset of the node whose property to change
@@ -1604,9 +1721,11 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
1604 * change the offsets of some existing nodes. 1721 * change the offsets of some existing nodes.
1605 1722
1606 * returns: 1723 * returns:
1607 * structure block offset of the created nodeequested subnode (>=0), on success 1724 * structure block offset of the created nodeequested subnode (>=0), on
1725 * success
1608 * -FDT_ERR_NOTFOUND, if the requested subnode does not exist 1726 * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
1609 * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag 1727 * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
1728 * tag
1610 * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of 1729 * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
1611 * the given name 1730 * the given name
1612 * -FDT_ERR_NOSPACE, if there is insufficient free space in the 1731 * -FDT_ERR_NOSPACE, if there is insufficient free space in the
@@ -1644,6 +1763,37 @@ int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
1644 */ 1763 */
1645int fdt_del_node(void *fdt, int nodeoffset); 1764int fdt_del_node(void *fdt, int nodeoffset);
1646 1765
1766/**
1767 * fdt_overlay_apply - Applies a DT overlay on a base DT
1768 * @fdt: pointer to the base device tree blob
1769 * @fdto: pointer to the device tree overlay blob
1770 *
1771 * fdt_overlay_apply() will apply the given device tree overlay on the
1772 * given base device tree.
1773 *
1774 * Expect the base device tree to be modified, even if the function
1775 * returns an error.
1776 *
1777 * returns:
1778 * 0, on success
1779 * -FDT_ERR_NOSPACE, there's not enough space in the base device tree
1780 * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or
1781 * properties in the base DT
1782 * -FDT_ERR_BADPHANDLE,
1783 * -FDT_ERR_BADOVERLAY,
1784 * -FDT_ERR_NOPHANDLES,
1785 * -FDT_ERR_INTERNAL,
1786 * -FDT_ERR_BADLAYOUT,
1787 * -FDT_ERR_BADMAGIC,
1788 * -FDT_ERR_BADOFFSET,
1789 * -FDT_ERR_BADPATH,
1790 * -FDT_ERR_BADVERSION,
1791 * -FDT_ERR_BADSTRUCTURE,
1792 * -FDT_ERR_BADSTATE,
1793 * -FDT_ERR_TRUNCATED, standard meanings
1794 */
1795int fdt_overlay_apply(void *fdt, void *fdto);
1796
1647/**********************************************************************/ 1797/**********************************************************************/
1648/* Debugging / informational functions */ 1798/* Debugging / informational functions */
1649/**********************************************************************/ 1799/**********************************************************************/
diff --git a/scripts/dtc/libfdt/libfdt_env.h b/scripts/dtc/libfdt/libfdt_env.h
index 9dea97dfff81..99f936dacc60 100644
--- a/scripts/dtc/libfdt/libfdt_env.h
+++ b/scripts/dtc/libfdt/libfdt_env.h
@@ -54,6 +54,7 @@
54 54
55#include <stddef.h> 55#include <stddef.h>
56#include <stdint.h> 56#include <stdint.h>
57#include <stdlib.h>
57#include <string.h> 58#include <string.h>
58 59
59#ifdef __CHECKER__ 60#ifdef __CHECKER__