| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */ |
|---|
| 1 | 2 | #ifndef LIBFDT_H |
|---|
| 2 | 3 | #define LIBFDT_H |
|---|
| 3 | 4 | /* |
|---|
| 4 | 5 | * libfdt - Flat Device Tree manipulation |
|---|
| 5 | 6 | * Copyright (C) 2006 David Gibson, IBM Corporation. |
|---|
| 6 | | - * |
|---|
| 7 | | - * libfdt is dual licensed: you can use it either under the terms of |
|---|
| 8 | | - * the GPL, or the BSD license, at your option. |
|---|
| 9 | | - * |
|---|
| 10 | | - * a) This library is free software; you can redistribute it and/or |
|---|
| 11 | | - * modify it under the terms of the GNU General Public License as |
|---|
| 12 | | - * published by the Free Software Foundation; either version 2 of the |
|---|
| 13 | | - * License, or (at your option) any later version. |
|---|
| 14 | | - * |
|---|
| 15 | | - * This library is distributed in the hope that it will be useful, |
|---|
| 16 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 18 | | - * GNU General Public License for more details. |
|---|
| 19 | | - * |
|---|
| 20 | | - * You should have received a copy of the GNU General Public |
|---|
| 21 | | - * License along with this library; if not, write to the Free |
|---|
| 22 | | - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
|---|
| 23 | | - * MA 02110-1301 USA |
|---|
| 24 | | - * |
|---|
| 25 | | - * Alternatively, |
|---|
| 26 | | - * |
|---|
| 27 | | - * b) Redistribution and use in source and binary forms, with or |
|---|
| 28 | | - * without modification, are permitted provided that the following |
|---|
| 29 | | - * conditions are met: |
|---|
| 30 | | - * |
|---|
| 31 | | - * 1. Redistributions of source code must retain the above |
|---|
| 32 | | - * copyright notice, this list of conditions and the following |
|---|
| 33 | | - * disclaimer. |
|---|
| 34 | | - * 2. Redistributions in binary form must reproduce the above |
|---|
| 35 | | - * copyright notice, this list of conditions and the following |
|---|
| 36 | | - * disclaimer in the documentation and/or other materials |
|---|
| 37 | | - * provided with the distribution. |
|---|
| 38 | | - * |
|---|
| 39 | | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|---|
| 40 | | - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|---|
| 41 | | - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|---|
| 42 | | - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|---|
| 43 | | - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|---|
| 44 | | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|---|
| 45 | | - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|---|
| 46 | | - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|---|
| 47 | | - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|---|
| 48 | | - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|---|
| 49 | | - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|---|
| 50 | | - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|---|
| 51 | | - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 52 | 7 | */ |
|---|
| 53 | 8 | |
|---|
| 54 | 9 | #include "libfdt_env.h" |
|---|
| 55 | 10 | #include "fdt.h" |
|---|
| 11 | + |
|---|
| 12 | +#ifdef __cplusplus |
|---|
| 13 | +extern "C" { |
|---|
| 14 | +#endif |
|---|
| 56 | 15 | |
|---|
| 57 | 16 | #define FDT_FIRST_SUPPORTED_VERSION 0x02 |
|---|
| 58 | 17 | #define FDT_LAST_SUPPORTED_VERSION 0x11 |
|---|
| .. | .. |
|---|
| 90 | 49 | |
|---|
| 91 | 50 | /* Error codes: codes for bad device tree blobs */ |
|---|
| 92 | 51 | #define FDT_ERR_TRUNCATED 8 |
|---|
| 93 | | - /* FDT_ERR_TRUNCATED: Structure block of the given device tree |
|---|
| 94 | | - * ends without an FDT_END tag. */ |
|---|
| 52 | + /* FDT_ERR_TRUNCATED: FDT or a sub-block is improperly |
|---|
| 53 | + * terminated (overflows, goes outside allowed bounds, or |
|---|
| 54 | + * isn't properly terminated). */ |
|---|
| 95 | 55 | #define FDT_ERR_BADMAGIC 9 |
|---|
| 96 | 56 | /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a |
|---|
| 97 | 57 | * device tree at all - it is missing the flattened device |
|---|
| .. | .. |
|---|
| 137 | 97 | /* FDT_ERR_NOPHANDLES: The device tree doesn't have any |
|---|
| 138 | 98 | * phandle available anymore without causing an overflow */ |
|---|
| 139 | 99 | |
|---|
| 140 | | -#define FDT_ERR_MAX 17 |
|---|
| 100 | +#define FDT_ERR_BADFLAGS 18 |
|---|
| 101 | + /* FDT_ERR_BADFLAGS: The function was passed a flags field that |
|---|
| 102 | + * contains invalid flags or an invalid combination of flags. */ |
|---|
| 103 | + |
|---|
| 104 | +#define FDT_ERR_MAX 18 |
|---|
| 105 | + |
|---|
| 106 | +/* constants */ |
|---|
| 107 | +#define FDT_MAX_PHANDLE 0xfffffffe |
|---|
| 108 | + /* Valid values for phandles range from 1 to 2^32-2. */ |
|---|
| 141 | 109 | |
|---|
| 142 | 110 | /**********************************************************************/ |
|---|
| 143 | 111 | /* Low-level functions (you probably don't need these) */ |
|---|
| .. | .. |
|---|
| 152 | 120 | } |
|---|
| 153 | 121 | |
|---|
| 154 | 122 | uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset); |
|---|
| 123 | + |
|---|
| 124 | +/* |
|---|
| 125 | + * Alignment helpers: |
|---|
| 126 | + * These helpers access words from a device tree blob. They're |
|---|
| 127 | + * built to work even with unaligned pointers on platforms (ike |
|---|
| 128 | + * ARM) that don't like unaligned loads and stores |
|---|
| 129 | + */ |
|---|
| 130 | + |
|---|
| 131 | +static inline uint32_t fdt32_ld(const fdt32_t *p) |
|---|
| 132 | +{ |
|---|
| 133 | + const uint8_t *bp = (const uint8_t *)p; |
|---|
| 134 | + |
|---|
| 135 | + return ((uint32_t)bp[0] << 24) |
|---|
| 136 | + | ((uint32_t)bp[1] << 16) |
|---|
| 137 | + | ((uint32_t)bp[2] << 8) |
|---|
| 138 | + | bp[3]; |
|---|
| 139 | +} |
|---|
| 140 | + |
|---|
| 141 | +static inline void fdt32_st(void *property, uint32_t value) |
|---|
| 142 | +{ |
|---|
| 143 | + uint8_t *bp = (uint8_t *)property; |
|---|
| 144 | + |
|---|
| 145 | + bp[0] = value >> 24; |
|---|
| 146 | + bp[1] = (value >> 16) & 0xff; |
|---|
| 147 | + bp[2] = (value >> 8) & 0xff; |
|---|
| 148 | + bp[3] = value & 0xff; |
|---|
| 149 | +} |
|---|
| 150 | + |
|---|
| 151 | +static inline uint64_t fdt64_ld(const fdt64_t *p) |
|---|
| 152 | +{ |
|---|
| 153 | + const uint8_t *bp = (const uint8_t *)p; |
|---|
| 154 | + |
|---|
| 155 | + return ((uint64_t)bp[0] << 56) |
|---|
| 156 | + | ((uint64_t)bp[1] << 48) |
|---|
| 157 | + | ((uint64_t)bp[2] << 40) |
|---|
| 158 | + | ((uint64_t)bp[3] << 32) |
|---|
| 159 | + | ((uint64_t)bp[4] << 24) |
|---|
| 160 | + | ((uint64_t)bp[5] << 16) |
|---|
| 161 | + | ((uint64_t)bp[6] << 8) |
|---|
| 162 | + | bp[7]; |
|---|
| 163 | +} |
|---|
| 164 | + |
|---|
| 165 | +static inline void fdt64_st(void *property, uint64_t value) |
|---|
| 166 | +{ |
|---|
| 167 | + uint8_t *bp = (uint8_t *)property; |
|---|
| 168 | + |
|---|
| 169 | + bp[0] = value >> 56; |
|---|
| 170 | + bp[1] = (value >> 48) & 0xff; |
|---|
| 171 | + bp[2] = (value >> 40) & 0xff; |
|---|
| 172 | + bp[3] = (value >> 32) & 0xff; |
|---|
| 173 | + bp[4] = (value >> 24) & 0xff; |
|---|
| 174 | + bp[5] = (value >> 16) & 0xff; |
|---|
| 175 | + bp[6] = (value >> 8) & 0xff; |
|---|
| 176 | + bp[7] = value & 0xff; |
|---|
| 177 | +} |
|---|
| 155 | 178 | |
|---|
| 156 | 179 | /**********************************************************************/ |
|---|
| 157 | 180 | /* Traversal functions */ |
|---|
| .. | .. |
|---|
| 195 | 218 | * ... |
|---|
| 196 | 219 | * } |
|---|
| 197 | 220 | * |
|---|
| 198 | | - * if ((node < 0) && (node != -FDT_ERR_NOT_FOUND)) { |
|---|
| 221 | + * if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) { |
|---|
| 199 | 222 | * Error handling |
|---|
| 200 | 223 | * } |
|---|
| 201 | 224 | * |
|---|
| .. | .. |
|---|
| 213 | 236 | /* General functions */ |
|---|
| 214 | 237 | /**********************************************************************/ |
|---|
| 215 | 238 | #define fdt_get_header(fdt, field) \ |
|---|
| 216 | | - (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field)) |
|---|
| 239 | + (fdt32_ld(&((const struct fdt_header *)(fdt))->field)) |
|---|
| 217 | 240 | #define fdt_magic(fdt) (fdt_get_header(fdt, magic)) |
|---|
| 218 | 241 | #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize)) |
|---|
| 219 | 242 | #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct)) |
|---|
| .. | .. |
|---|
| 244 | 267 | #undef fdt_set_hdr_ |
|---|
| 245 | 268 | |
|---|
| 246 | 269 | /** |
|---|
| 247 | | - * fdt_check_header - sanity check a device tree or possible device tree |
|---|
| 270 | + * fdt_header_size - return the size of the tree's header |
|---|
| 271 | + * @fdt: pointer to a flattened device tree |
|---|
| 272 | + */ |
|---|
| 273 | +size_t fdt_header_size(const void *fdt); |
|---|
| 274 | + |
|---|
| 275 | +/** |
|---|
| 276 | + * fdt_header_size_ - internal function which takes a version number |
|---|
| 277 | + */ |
|---|
| 278 | +size_t fdt_header_size_(uint32_t version); |
|---|
| 279 | + |
|---|
| 280 | +/** |
|---|
| 281 | + * fdt_check_header - sanity check a device tree header |
|---|
| 282 | + |
|---|
| 248 | 283 | * @fdt: pointer to data which might be a flattened device tree |
|---|
| 249 | 284 | * |
|---|
| 250 | 285 | * fdt_check_header() checks that the given buffer contains what |
|---|
| 251 | | - * appears to be a flattened device tree with sane information in its |
|---|
| 252 | | - * header. |
|---|
| 286 | + * appears to be a flattened device tree, and that the header contains |
|---|
| 287 | + * valid information (to the extent that can be determined from the |
|---|
| 288 | + * header alone). |
|---|
| 253 | 289 | * |
|---|
| 254 | 290 | * returns: |
|---|
| 255 | 291 | * 0, if the buffer appears to contain a valid device tree |
|---|
| 256 | 292 | * -FDT_ERR_BADMAGIC, |
|---|
| 257 | 293 | * -FDT_ERR_BADVERSION, |
|---|
| 258 | | - * -FDT_ERR_BADSTATE, standard meanings, as above |
|---|
| 294 | + * -FDT_ERR_BADSTATE, |
|---|
| 295 | + * -FDT_ERR_TRUNCATED, standard meanings, as above |
|---|
| 259 | 296 | */ |
|---|
| 260 | 297 | int fdt_check_header(const void *fdt); |
|---|
| 261 | 298 | |
|---|
| .. | .. |
|---|
| 284 | 321 | /* Read-only functions */ |
|---|
| 285 | 322 | /**********************************************************************/ |
|---|
| 286 | 323 | |
|---|
| 324 | +int fdt_check_full(const void *fdt, size_t bufsize); |
|---|
| 325 | + |
|---|
| 326 | +/** |
|---|
| 327 | + * fdt_get_string - retrieve a string from the strings block of a device tree |
|---|
| 328 | + * @fdt: pointer to the device tree blob |
|---|
| 329 | + * @stroffset: offset of the string within the strings block (native endian) |
|---|
| 330 | + * @lenp: optional pointer to return the string's length |
|---|
| 331 | + * |
|---|
| 332 | + * fdt_get_string() retrieves a pointer to a single string from the |
|---|
| 333 | + * strings block of the device tree blob at fdt, and optionally also |
|---|
| 334 | + * returns the string's length in *lenp. |
|---|
| 335 | + * |
|---|
| 336 | + * returns: |
|---|
| 337 | + * a pointer to the string, on success |
|---|
| 338 | + * NULL, if stroffset is out of bounds, or doesn't point to a valid string |
|---|
| 339 | + */ |
|---|
| 340 | +const char *fdt_get_string(const void *fdt, int stroffset, int *lenp); |
|---|
| 341 | + |
|---|
| 287 | 342 | /** |
|---|
| 288 | 343 | * fdt_string - retrieve a string from the strings block of a device tree |
|---|
| 289 | 344 | * @fdt: pointer to the device tree blob |
|---|
| .. | .. |
|---|
| 294 | 349 | * |
|---|
| 295 | 350 | * returns: |
|---|
| 296 | 351 | * a pointer to the string, on success |
|---|
| 297 | | - * NULL, if stroffset is out of bounds |
|---|
| 352 | + * NULL, if stroffset is out of bounds, or doesn't point to a valid string |
|---|
| 298 | 353 | */ |
|---|
| 299 | 354 | const char *fdt_string(const void *fdt, int stroffset); |
|---|
| 355 | + |
|---|
| 356 | +/** |
|---|
| 357 | + * fdt_find_max_phandle - find and return the highest phandle in a tree |
|---|
| 358 | + * @fdt: pointer to the device tree blob |
|---|
| 359 | + * @phandle: return location for the highest phandle value found in the tree |
|---|
| 360 | + * |
|---|
| 361 | + * fdt_find_max_phandle() finds the highest phandle value in the given device |
|---|
| 362 | + * tree. The value returned in @phandle is only valid if the function returns |
|---|
| 363 | + * success. |
|---|
| 364 | + * |
|---|
| 365 | + * returns: |
|---|
| 366 | + * 0 on success or a negative error code on failure |
|---|
| 367 | + */ |
|---|
| 368 | +int fdt_find_max_phandle(const void *fdt, uint32_t *phandle); |
|---|
| 300 | 369 | |
|---|
| 301 | 370 | /** |
|---|
| 302 | 371 | * fdt_get_max_phandle - retrieves the highest phandle in a tree |
|---|
| .. | .. |
|---|
| 306 | 375 | * device tree. This will ignore badly formatted phandles, or phandles |
|---|
| 307 | 376 | * with a value of 0 or -1. |
|---|
| 308 | 377 | * |
|---|
| 378 | + * This function is deprecated in favour of fdt_find_max_phandle(). |
|---|
| 379 | + * |
|---|
| 309 | 380 | * returns: |
|---|
| 310 | 381 | * the highest phandle on success |
|---|
| 311 | 382 | * 0, if no phandle was found in the device tree |
|---|
| 312 | 383 | * -1, if an error occurred |
|---|
| 313 | 384 | */ |
|---|
| 314 | | -uint32_t fdt_get_max_phandle(const void *fdt); |
|---|
| 385 | +static inline uint32_t fdt_get_max_phandle(const void *fdt) |
|---|
| 386 | +{ |
|---|
| 387 | + uint32_t phandle; |
|---|
| 388 | + int err; |
|---|
| 389 | + |
|---|
| 390 | + err = fdt_find_max_phandle(fdt, &phandle); |
|---|
| 391 | + if (err < 0) |
|---|
| 392 | + return (uint32_t)-1; |
|---|
| 393 | + |
|---|
| 394 | + return phandle; |
|---|
| 395 | +} |
|---|
| 396 | + |
|---|
| 397 | +/** |
|---|
| 398 | + * fdt_generate_phandle - return a new, unused phandle for a device tree blob |
|---|
| 399 | + * @fdt: pointer to the device tree blob |
|---|
| 400 | + * @phandle: return location for the new phandle |
|---|
| 401 | + * |
|---|
| 402 | + * Walks the device tree blob and looks for the highest phandle value. On |
|---|
| 403 | + * success, the new, unused phandle value (one higher than the previously |
|---|
| 404 | + * highest phandle value in the device tree blob) will be returned in the |
|---|
| 405 | + * @phandle parameter. |
|---|
| 406 | + * |
|---|
| 407 | + * Returns: |
|---|
| 408 | + * 0 on success or a negative error-code on failure |
|---|
| 409 | + */ |
|---|
| 410 | +int fdt_generate_phandle(const void *fdt, uint32_t *phandle); |
|---|
| 315 | 411 | |
|---|
| 316 | 412 | /** |
|---|
| 317 | 413 | * fdt_num_mem_rsv - retrieve the number of memory reserve map entries |
|---|
| .. | .. |
|---|
| 503 | 599 | * ... |
|---|
| 504 | 600 | * } |
|---|
| 505 | 601 | * |
|---|
| 506 | | - * if ((property < 0) && (property != -FDT_ERR_NOT_FOUND)) { |
|---|
| 602 | + * if ((property < 0) && (property != -FDT_ERR_NOTFOUND)) { |
|---|
| 507 | 603 | * Error handling |
|---|
| 508 | 604 | * } |
|---|
| 509 | 605 | * |
|---|
| .. | .. |
|---|
| 606 | 702 | /** |
|---|
| 607 | 703 | * fdt_getprop_by_offset - retrieve the value of a property at a given offset |
|---|
| 608 | 704 | * @fdt: pointer to the device tree blob |
|---|
| 609 | | - * @ffset: offset of the property to read |
|---|
| 705 | + * @offset: offset of the property to read |
|---|
| 610 | 706 | * @namep: pointer to a string variable (will be overwritten) or NULL |
|---|
| 611 | 707 | * @lenp: pointer to an integer variable (will be overwritten) or NULL |
|---|
| 612 | 708 | * |
|---|
| .. | .. |
|---|
| 1090 | 1186 | * |
|---|
| 1091 | 1187 | * returns: |
|---|
| 1092 | 1188 | * 0 <= n < FDT_MAX_NCELLS, on success |
|---|
| 1093 | | - * 2, if the node has no #address-cells property |
|---|
| 1189 | + * 1, if the node has no #size-cells property |
|---|
| 1094 | 1190 | * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid |
|---|
| 1095 | 1191 | * #size-cells property |
|---|
| 1096 | 1192 | * -FDT_ERR_BADMAGIC, |
|---|
| .. | .. |
|---|
| 1297 | 1393 | /* Sequential write functions */ |
|---|
| 1298 | 1394 | /**********************************************************************/ |
|---|
| 1299 | 1395 | |
|---|
| 1396 | +/* fdt_create_with_flags flags */ |
|---|
| 1397 | +#define FDT_CREATE_FLAG_NO_NAME_DEDUP 0x1 |
|---|
| 1398 | + /* FDT_CREATE_FLAG_NO_NAME_DEDUP: Do not try to de-duplicate property |
|---|
| 1399 | + * names in the fdt. This can result in faster creation times, but |
|---|
| 1400 | + * a larger fdt. */ |
|---|
| 1401 | + |
|---|
| 1402 | +#define FDT_CREATE_FLAGS_ALL (FDT_CREATE_FLAG_NO_NAME_DEDUP) |
|---|
| 1403 | + |
|---|
| 1404 | +/** |
|---|
| 1405 | + * fdt_create_with_flags - begin creation of a new fdt |
|---|
| 1406 | + * @fdt: pointer to memory allocated where fdt will be created |
|---|
| 1407 | + * @bufsize: size of the memory space at fdt |
|---|
| 1408 | + * @flags: a valid combination of FDT_CREATE_FLAG_ flags, or 0. |
|---|
| 1409 | + * |
|---|
| 1410 | + * fdt_create_with_flags() begins the process of creating a new fdt with |
|---|
| 1411 | + * the sequential write interface. |
|---|
| 1412 | + * |
|---|
| 1413 | + * fdt creation process must end with fdt_finished() to produce a valid fdt. |
|---|
| 1414 | + * |
|---|
| 1415 | + * returns: |
|---|
| 1416 | + * 0, on success |
|---|
| 1417 | + * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt |
|---|
| 1418 | + * -FDT_ERR_BADFLAGS, flags is not valid |
|---|
| 1419 | + */ |
|---|
| 1420 | +int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags); |
|---|
| 1421 | + |
|---|
| 1422 | +/** |
|---|
| 1423 | + * fdt_create - begin creation of a new fdt |
|---|
| 1424 | + * @fdt: pointer to memory allocated where fdt will be created |
|---|
| 1425 | + * @bufsize: size of the memory space at fdt |
|---|
| 1426 | + * |
|---|
| 1427 | + * fdt_create() is equivalent to fdt_create_with_flags() with flags=0. |
|---|
| 1428 | + * |
|---|
| 1429 | + * returns: |
|---|
| 1430 | + * 0, on success |
|---|
| 1431 | + * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt |
|---|
| 1432 | + */ |
|---|
| 1300 | 1433 | int fdt_create(void *buf, int bufsize); |
|---|
| 1434 | + |
|---|
| 1301 | 1435 | int fdt_resize(void *fdt, void *buf, int bufsize); |
|---|
| 1302 | 1436 | int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size); |
|---|
| 1303 | 1437 | int fdt_finish_reservemap(void *fdt); |
|---|
| .. | .. |
|---|
| 1313 | 1447 | fdt64_t tmp = cpu_to_fdt64(val); |
|---|
| 1314 | 1448 | return fdt_property(fdt, name, &tmp, sizeof(tmp)); |
|---|
| 1315 | 1449 | } |
|---|
| 1450 | + |
|---|
| 1451 | +#ifndef SWIG /* Not available in Python */ |
|---|
| 1316 | 1452 | static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val) |
|---|
| 1317 | 1453 | { |
|---|
| 1318 | 1454 | return fdt_property_u32(fdt, name, val); |
|---|
| 1319 | 1455 | } |
|---|
| 1456 | +#endif |
|---|
| 1320 | 1457 | |
|---|
| 1321 | 1458 | /** |
|---|
| 1322 | 1459 | * fdt_property_placeholder - add a new property and return a ptr to its value |
|---|
| .. | .. |
|---|
| 1766 | 1903 | fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) |
|---|
| 1767 | 1904 | |
|---|
| 1768 | 1905 | /** |
|---|
| 1906 | + * fdt_appendprop_addrrange - append a address range property |
|---|
| 1907 | + * @fdt: pointer to the device tree blob |
|---|
| 1908 | + * @parent: offset of the parent node |
|---|
| 1909 | + * @nodeoffset: offset of the node to add a property at |
|---|
| 1910 | + * @name: name of property |
|---|
| 1911 | + * @addr: start address of a given range |
|---|
| 1912 | + * @size: size of a given range |
|---|
| 1913 | + * |
|---|
| 1914 | + * fdt_appendprop_addrrange() appends an address range value (start |
|---|
| 1915 | + * address and size) to the value of the named property in the given |
|---|
| 1916 | + * node, or creates a new property with that value if it does not |
|---|
| 1917 | + * already exist. |
|---|
| 1918 | + * If "name" is not specified, a default "reg" is used. |
|---|
| 1919 | + * Cell sizes are determined by parent's #address-cells and #size-cells. |
|---|
| 1920 | + * |
|---|
| 1921 | + * This function may insert data into the blob, and will therefore |
|---|
| 1922 | + * change the offsets of some existing nodes. |
|---|
| 1923 | + * |
|---|
| 1924 | + * returns: |
|---|
| 1925 | + * 0, on success |
|---|
| 1926 | + * -FDT_ERR_BADLAYOUT, |
|---|
| 1927 | + * -FDT_ERR_BADMAGIC, |
|---|
| 1928 | + * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid |
|---|
| 1929 | + * #address-cells property |
|---|
| 1930 | + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
|---|
| 1931 | + * -FDT_ERR_BADSTATE, |
|---|
| 1932 | + * -FDT_ERR_BADSTRUCTURE, |
|---|
| 1933 | + * -FDT_ERR_BADVERSION, |
|---|
| 1934 | + * -FDT_ERR_BADVALUE, addr or size doesn't fit to respective cells size |
|---|
| 1935 | + * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to |
|---|
| 1936 | + * contain a new property |
|---|
| 1937 | + * -FDT_ERR_TRUNCATED, standard meanings |
|---|
| 1938 | + */ |
|---|
| 1939 | +int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset, |
|---|
| 1940 | + const char *name, uint64_t addr, uint64_t size); |
|---|
| 1941 | + |
|---|
| 1942 | +/** |
|---|
| 1769 | 1943 | * fdt_delprop - delete a property |
|---|
| 1770 | 1944 | * @fdt: pointer to the device tree blob |
|---|
| 1771 | 1945 | * @nodeoffset: offset of the node whose property to nop |
|---|
| .. | .. |
|---|
| 1899 | 2073 | |
|---|
| 1900 | 2074 | const char *fdt_strerror(int errval); |
|---|
| 1901 | 2075 | |
|---|
| 2076 | +#ifdef __cplusplus |
|---|
| 2077 | +} |
|---|
| 2078 | +#endif |
|---|
| 2079 | + |
|---|
| 1902 | 2080 | #endif /* LIBFDT_H */ |
|---|