Commit a9f04d49e519383f98689d603facdee227a2f94d
1 parent
768e0f52f2
Exists in
v2017.01-smarct4x
and in
37 other branches
fdt: Add a function to decode a variable-sized u32 array
Sometimes an array can be of variable size up to a maximum. Add a helper function to decode this. Signed-off-by: Simon Glass <sjg@chromium.org>
Showing 2 changed files with 36 additions and 0 deletions Side-by-side Diff
include/fdtdec.h
... | ... | @@ -445,6 +445,22 @@ |
445 | 445 | u32 *array, int count); |
446 | 446 | |
447 | 447 | /** |
448 | + * Look up a property in a node and return its contents in an integer | |
449 | + * array of given length. The property must exist but may have less data that | |
450 | + * expected (4*count bytes). It may have more, but this will be ignored. | |
451 | + * | |
452 | + * @param blob FDT blob | |
453 | + * @param node node to examine | |
454 | + * @param prop_name name of property to find | |
455 | + * @param array array to fill with data | |
456 | + * @param count number of array elements | |
457 | + * @return number of array elements if ok, or -FDT_ERR_NOTFOUND if the | |
458 | + * property is not found | |
459 | + */ | |
460 | +int fdtdec_get_int_array_count(const void *blob, int node, | |
461 | + const char *prop_name, u32 *array, int count); | |
462 | + | |
463 | +/** | |
448 | 464 | * Look up a property in a node and return a pointer to its contents as a |
449 | 465 | * unsigned int array of given length. The property must have at least enough |
450 | 466 | * data for the array ('count' cells). It may have more, but this will be |
lib/fdtdec.c
... | ... | @@ -485,6 +485,26 @@ |
485 | 485 | return err; |
486 | 486 | } |
487 | 487 | |
488 | +int fdtdec_get_int_array_count(const void *blob, int node, | |
489 | + const char *prop_name, u32 *array, int count) | |
490 | +{ | |
491 | + const u32 *cell; | |
492 | + int len, elems; | |
493 | + int i; | |
494 | + | |
495 | + debug("%s: %s\n", __func__, prop_name); | |
496 | + cell = fdt_getprop(blob, node, prop_name, &len); | |
497 | + if (!cell) | |
498 | + return -FDT_ERR_NOTFOUND; | |
499 | + elems = len / sizeof(u32); | |
500 | + if (count > elems) | |
501 | + count = elems; | |
502 | + for (i = 0; i < count; i++) | |
503 | + array[i] = fdt32_to_cpu(cell[i]); | |
504 | + | |
505 | + return count; | |
506 | +} | |
507 | + | |
488 | 508 | const u32 *fdtdec_locate_array(const void *blob, int node, |
489 | 509 | const char *prop_name, int count) |
490 | 510 | { |