diff --git a/common/fdt_wrappers.c b/common/fdt_wrappers.c index ca5b455..5afa142 100644 --- a/common/fdt_wrappers.c +++ b/common/fdt_wrappers.c @@ -65,38 +65,35 @@ /* * 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 f467958..e3158f1 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 2952cde..bac1f15 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 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 @@ <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 0c93d0a..6469e29 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 b1b9ed4..66d6e45 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 6ebc467..26e51b2 100644 --- a/plat/arm/common/fconf/arm_fconf_io.c +++ b/plat/arm/common/fconf/arm_fconf_io.c @@ -241,7 +241,8 @@ /* 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 9b6fa9b..c46ecb1 100644 --- a/plat/arm/common/fconf/arm_fconf_sp.c +++ b/plat/arm/common/fconf/arm_fconf_sp.c @@ -44,8 +44,8 @@ } 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;