[PATCH 2/5] fdtdec: introduce fdtdec_get_config_property

Rasmus Villemoes rasmus.villemoes at prevas.dk
Tue Nov 10 21:26:00 CET 2020


Add a wrapper for retrieving a given property from the /config node as
a (blob, length) pair. A later patch will need the length of the
property and thus cannot just use fdtdec_get_config_string(). Rewrite
that to use the new wrapper.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes at prevas.dk>
---
 include/fdtdec.h | 14 ++++++++++++++
 lib/fdtdec.c     | 27 +++++++++++++--------------
 2 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/include/fdtdec.h b/include/fdtdec.h
index a037f6ed9c..ff1453a100 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -747,6 +747,20 @@ int fdtdec_get_bool(const void *blob, int node, const char *prop_name);
  */
 int fdtdec_get_child_count(const void *blob, int node);
 
+/**
+ * Look in the FDT for a config item with the given name and a pointer
+ * to its value.
+ *
+ * @param blob          FDT blob
+ * @param prop_name     property name to look up
+ * @param lenp          if non-NULL and the property is found, *lenp is
+ *                      set to the length of the property value
+ *
+ * @returns property value, NULL on error.
+ */
+const void *fdtdec_get_config_property(const void *blob, const char *prop_name,
+		int *lenp);
+
 /**
  * Look in the FDT for a config item with the given name and return its value
  * as a 32-bit integer. The property must have at least 4 bytes of data. The
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 25a71bc8f9..2442470af8 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -853,6 +853,18 @@ const u8 *fdtdec_locate_byte_array(const void *blob, int node,
 	return cell;
 }
 
+const void *fdtdec_get_config_property(const void *blob, const char *prop_name,
+				       int *len)
+{
+	int config_node;
+
+	debug("%s: %s\n", __func__, prop_name);
+	config_node = fdt_path_offset(blob, "/config");
+	if (config_node < 0)
+		return NULL;
+	return fdt_getprop(blob, config_node, prop_name, len);
+}
+
 int fdtdec_get_config_int(const void *blob, const char *prop_name,
 			  int default_val)
 {
@@ -881,20 +893,7 @@ int fdtdec_get_config_bool(const void *blob, const char *prop_name)
 
 const char *fdtdec_get_config_string(const void *blob, const char *prop_name)
 {
-	const char *nodep;
-	int nodeoffset;
-	int len;
-
-	debug("%s: %s\n", __func__, prop_name);
-	nodeoffset = fdt_path_offset(blob, "/config");
-	if (nodeoffset < 0)
-		return NULL;
-
-	nodep = fdt_getprop(blob, nodeoffset, prop_name, &len);
-	if (!nodep)
-		return NULL;
-
-	return nodep;
+	return fdtdec_get_config_property(blob, prop_name, NULL);
 }
 
 u64 fdtdec_get_number(const fdt32_t *ptr, unsigned int cells)
-- 
2.23.0



More information about the U-Boot mailing list