diff options
author | Andre Przywara <andre.przywara@arm.com> | 2020-03-30 23:21:13 +0100 |
---|---|---|
committer | Andre Przywara <andre.przywara@arm.com> | 2020-04-28 15:56:31 +0100 |
commit | 6e3a89f449fa5b4c0153990a64124211197f426a (patch) | |
tree | acc0b6019bead030186f72bb7ed8250e809a4c4d /common | |
parent | 455a6f3b146353cedc6e97d675168a9b1cdd4f5d (diff) | |
download | arm-trusted-firmware-6e3a89f449fa5b4c0153990a64124211197f426a.tar.gz |
fdt/wrappers: Generalise fdtw_read_array()
Currently our fdtw_read_array() implementation requires the length of
the property to exactly match the requested size, which makes it less
flexible for parsing generic device trees.
Also the name is slightly misleading, since we treat the cells of the
array as 32 bit unsigned integers, performing the endianess conversion.
To fix those issues and align the code more with other DT users (Linux
kernel or U-Boot), rename the function to "fdt_read_uint32_array", and
relax the length check to only check if the property covers at least the
number of cells we request.
This also changes the variable names to be more in-line with other DT
users, and switches to the proper data types.
This makes this function more useful in later patches.
Change-Id: Id86f4f588ffcb5106d4476763ecdfe35a735fa6c
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Diffstat (limited to 'common')
-rw-r--r-- | common/fdt_wrappers.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/common/fdt_wrappers.c b/common/fdt_wrappers.c index ca5b4556d..5afa14271 100644 --- a/common/fdt_wrappers.c +++ b/common/fdt_wrappers.c @@ -65,38 +65,35 @@ int fdtw_read_cells(const void *dtb, int node, const char *prop, /* * Read cells from a given property of the given node. Any number of 32-bit - * cells of the property can be read. The fdt pointer is updated. Returns 0 on - * success, and -1 on error. + * cells of the property can be read. Returns 0 on success, or a negative + * FDT error value otherwise. */ -int fdtw_read_array(const void *dtb, int node, const char *prop, - unsigned int cells, void *value) +int fdt_read_uint32_array(const void *dtb, int node, const char *prop_name, + unsigned int cells, uint32_t *value) { - const uint32_t *value_ptr; + const fdt32_t *prop; int value_len; assert(dtb != NULL); - assert(prop != NULL); + assert(prop_name != NULL); assert(value != NULL); assert(node >= 0); /* Access property and obtain its length (in bytes) */ - value_ptr = fdt_getprop_namelen(dtb, node, prop, (int)strlen(prop), - &value_len); - if (value_ptr == NULL) { - WARN("Couldn't find property %s in dtb\n", prop); - return -1; + prop = fdt_getprop(dtb, node, prop_name, &value_len); + if (prop == NULL) { + WARN("Couldn't find property %s in dtb\n", prop_name); + return -FDT_ERR_NOTFOUND; } - /* Verify that property length accords with cell length */ - if (NCELLS((unsigned int)value_len) != cells) { + /* Verify that property length can fill the entire array. */ + if (NCELLS((unsigned int)value_len) < cells) { WARN("Property length mismatch\n"); - return -1; + return -FDT_ERR_BADVALUE; } - uint32_t *dst = value; - for (unsigned int i = 0U; i < cells; i++) { - dst[i] = fdt32_to_cpu(value_ptr[i]); + value[i] = fdt32_to_cpu(prop[i]); } return 0; |