summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAntonio Nino Diaz <antonio.ninodiaz@arm.com>2018-06-26 10:34:07 +0100
committerAntonio Nino Diaz <antonio.ninodiaz@arm.com>2018-11-02 14:55:16 +0000
commit2747362062d4286e47cb13dbdfddfebc6d355dca (patch)
treeedcb28c46dfa4db10774c3df7d13ec6fda865ecb /common
parentb4cf974a3256275fe2c03d8eaaf07a5e5b337cfc (diff)
Introduce new fdt helper to read string properties
Introduced fdtw_read_string() to read string properties. Change-Id: I854eef0390632cf2eaddd2dce60cdb98c117de43 Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
Diffstat (limited to 'common')
-rw-r--r--common/fdt_wrappers.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/common/fdt_wrappers.c b/common/fdt_wrappers.c
index 1a726a8a..1715a6f0 100644
--- a/common/fdt_wrappers.c
+++ b/common/fdt_wrappers.c
@@ -10,6 +10,7 @@
#include <debug.h>
#include <fdt_wrappers.h>
#include <libfdt.h>
+#include <string.h>
/*
* Read cells from a given property of the given node. At most 2 cells of the
@@ -62,6 +63,38 @@ int fdtw_read_cells(const void *dtb, int node, const char *prop,
}
/*
+ * 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.
+ */
+int fdtw_read_string(const void *dtb, int node, const char *prop,
+ char *str, size_t size)
+{
+ const char *ptr;
+ size_t len;
+
+ assert(dtb != NULL);
+ assert(node >= 0);
+ assert(prop != NULL);
+ assert(str != NULL);
+ assert(size > 0U);
+
+ ptr = fdt_getprop_namelen(dtb, node, prop, (int)strlen(prop), NULL);
+ if (ptr == NULL) {
+ WARN("Couldn't find property %s in dtb\n", prop);
+ return -1;
+ }
+
+ len = strlcpy(str, ptr, size);
+ if (len >= size) {
+ WARN("String of property %s in dtb has been truncated\n", prop);
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
* Write cells in place to a given property of the given node. At most 2 cells
* of the property are written. Returns 0 on success, and -1 upon error.
*/