summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAntonio Nino Diaz <antonio.ninodiaz@arm.com>2018-06-26 10:34:10 +0100
committerAntonio Nino Diaz <antonio.ninodiaz@arm.com>2018-11-02 14:55:49 +0000
commit73f1ac6c8ee4a688ed8e1fddc040b882171d3453 (patch)
tree4bb7528bcce07f431582ac5c0e1fb8fbcac90890 /common
parent2747362062d4286e47cb13dbdfddfebc6d355dca (diff)
Introduce fdtw_read_array() helper
fdtw_read_cells() can only read one or two cells, sometimes it may be needed to read more cells from one property. Change-Id: Ie70dc76d1540cd6a04787cde7cccb4d1bafc7282 Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
Diffstat (limited to 'common')
-rw-r--r--common/fdt_wrappers.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/common/fdt_wrappers.c b/common/fdt_wrappers.c
index 1715a6f0..31dafb2e 100644
--- a/common/fdt_wrappers.c
+++ b/common/fdt_wrappers.c
@@ -40,7 +40,6 @@ int fdtw_read_cells(const void *dtb, int node, const char *prop,
return -1;
}
-
/* Verify that property length accords with cell length */
if (NCELLS((unsigned int)value_len) != cells) {
WARN("Property length mismatch\n");
@@ -63,6 +62,45 @@ 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.
+ */
+int fdtw_read_array(const void *dtb, int node, const char *prop,
+ unsigned int cells, void *value)
+{
+ const uint32_t *value_ptr;
+ int value_len;
+
+ assert(dtb != NULL);
+ assert(prop != 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;
+ }
+
+ /* Verify that property length accords with cell length */
+ if (NCELLS((unsigned int)value_len) != cells) {
+ WARN("Property length mismatch\n");
+ return -1;
+ }
+
+ uint32_t *dst = value;
+
+ for (unsigned int i = 0U; i < cells; i++) {
+ dst[i] = fdt32_to_cpu(value_ptr[i]);
+ }
+
+ return 0;
+}
+
+/*
* Read string from a given property of the given node. Up to 'size - 1'
* characters are read, and a NUL terminator is added. Returns 0 on success,
* and -1 upon error.