aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Przywara <andre.przywara@arm.com>2020-03-30 23:21:13 +0100
committerAndre Przywara <andre.przywara@arm.com>2020-04-28 15:56:31 +0100
commit6e3a89f449fa5b4c0153990a64124211197f426a (patch)
treeacc0b6019bead030186f72bb7ed8250e809a4c4d
parent455a6f3b146353cedc6e97d675168a9b1cdd4f5d (diff)
downloadtrusted-firmware-a-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>
-rw-r--r--common/fdt_wrappers.c31
-rw-r--r--include/common/fdt_wrappers.h4
-rw-r--r--plat/arm/board/fvp/fconf/fconf_hw_config_getter.c4
-rw-r--r--plat/arm/board/fvp/jmptbl.i1
-rw-r--r--plat/arm/board/juno/jmptbl.i1
-rw-r--r--plat/arm/common/fconf/arm_fconf_io.c3
-rw-r--r--plat/arm/common/fconf/arm_fconf_sp.c4
7 files changed, 24 insertions, 24 deletions
diff --git a/common/fdt_wrappers.c b/common/fdt_wrappers.c
index ca5b4556d3..5afa14271a 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;
diff --git a/include/common/fdt_wrappers.h b/include/common/fdt_wrappers.h
index f467958b7f..e3158f1c59 100644
--- a/include/common/fdt_wrappers.h
+++ b/include/common/fdt_wrappers.h
@@ -14,8 +14,8 @@
int fdtw_read_cells(const void *dtb, int node, const char *prop,
unsigned int cells, void *value);
-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);
int fdtw_read_string(const void *dtb, int node, const char *prop,
char *str, size_t size);
int fdtw_write_inplace_cells(void *dtb, int node, const char *prop,
diff --git a/plat/arm/board/fvp/fconf/fconf_hw_config_getter.c b/plat/arm/board/fvp/fconf/fconf_hw_config_getter.c
index 2952cde80d..bac1f1587a 100644
--- a/plat/arm/board/fvp/fconf/fconf_hw_config_getter.c
+++ b/plat/arm/board/fvp/fconf/fconf_hw_config_getter.c
@@ -18,7 +18,7 @@ int fconf_populate_gicv3_config(uintptr_t config)
{
int err;
int node;
- int addr[20];
+ uint32_t addr[20];
/* Necessary to work with libfdt APIs */
const void *hw_config_dtb = (const void *)config;
@@ -42,7 +42,7 @@ int fconf_populate_gicv3_config(uintptr_t config)
<0x0 0x2c02f000 0 0x2000>; // GICV
*/
- err = fdtw_read_array(hw_config_dtb, node, "reg", 20, &addr);
+ err = fdt_read_uint32_array(hw_config_dtb, node, "reg", 20, addr);
if (err < 0) {
ERROR("FCONF: Failed to read reg property of GIC node\n");
}
diff --git a/plat/arm/board/fvp/jmptbl.i b/plat/arm/board/fvp/jmptbl.i
index 0c93d0aab8..6469e29951 100644
--- a/plat/arm/board/fvp/jmptbl.i
+++ b/plat/arm/board/fvp/jmptbl.i
@@ -15,6 +15,7 @@
# fdt fdt_getprop_namelen patch
rom rom_lib_init
+fdt fdt_getprop
fdt fdt_getprop_namelen
fdt fdt_setprop_inplace
fdt fdt_check_header
diff --git a/plat/arm/board/juno/jmptbl.i b/plat/arm/board/juno/jmptbl.i
index b1b9ed463e..66d6e4592c 100644
--- a/plat/arm/board/juno/jmptbl.i
+++ b/plat/arm/board/juno/jmptbl.i
@@ -15,6 +15,7 @@
# fdt fdt_getprop_namelen patch
rom rom_lib_init
+fdt fdt_getprop
fdt fdt_getprop_namelen
fdt fdt_setprop_inplace
fdt fdt_check_header
diff --git a/plat/arm/common/fconf/arm_fconf_io.c b/plat/arm/common/fconf/arm_fconf_io.c
index 6ebc467ed6..26e51b2a30 100644
--- a/plat/arm/common/fconf/arm_fconf_io.c
+++ b/plat/arm/common/fconf/arm_fconf_io.c
@@ -241,7 +241,8 @@ int fconf_populate_arm_io_policies(uintptr_t config)
/* Locate the uuid cells and read the value for all the load info uuid */
for (i = 0; i < FCONF_ARM_IO_UUID_NUMBER; i++) {
uuid_ptr = pool_alloc(&fconf_arm_uuids_pool);
- err = fdtw_read_array(dtb, node, load_info[i].name, 4, &uuid_helper.word);
+ err = fdt_read_uint32_array(dtb, node, load_info[i].name,
+ 4, uuid_helper.word);
if (err < 0) {
WARN("FCONF: Read cell failed for %s\n", load_info[i].name);
return err;
diff --git a/plat/arm/common/fconf/arm_fconf_sp.c b/plat/arm/common/fconf/arm_fconf_sp.c
index 9b6fa9b1f9..c46ecb1140 100644
--- a/plat/arm/common/fconf/arm_fconf_sp.c
+++ b/plat/arm/common/fconf/arm_fconf_sp.c
@@ -44,8 +44,8 @@ int fconf_populate_arm_sp(uintptr_t config)
}
fdt_for_each_subnode(sp_node, dtb, node) {
- err = fdtw_read_array(dtb, sp_node, "uuid", 4,
- &uuid_helper.word);
+ err = fdt_read_uint32_array(dtb, sp_node, "uuid", 4,
+ uuid_helper.word);
if (err < 0) {
ERROR("FCONF: cannot read SP uuid\n");
return -1;