[U-Boot] [PATCH 01/13] fdt: Add a function to look up a /chosen property

Simon Glass sjg at chromium.org
Sat Aug 29 17:10:10 CEST 2015


It is sometimes useful to find a property in the chosen node. Add a function
for this.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 include/fdtdec.h | 11 ++++++++++-
 lib/fdtdec.c     | 15 ++++++++++-----
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/include/fdtdec.h b/include/fdtdec.h
index 0cb6fa0..2049d12 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -534,7 +534,16 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int node,
 			 int *seqp);
 
 /**
- * Get the offset of the given chosen node
+ * Get a property from the /chosen node
+ *
+ * @param blob		Device tree blob (if NULL, then NULL is returned)
+ * @param name		Property name to look up
+ * @return Value of property, or NULL if it does not exist
+ */
+const char *fdtdec_get_chosen_prop(const void *blob, const char *name);
+
+/**
+ * Get the offset of the given /chosen node
  *
  * This looks up a property in /chosen containing the path to another node,
  * then finds the offset of that node.
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 81b54f8..38888de 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -529,16 +529,21 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
 	return -ENOENT;
 }
 
-int fdtdec_get_chosen_node(const void *blob, const char *name)
+const char *fdtdec_get_chosen_prop(const void *blob, const char *name)
 {
-	const char *prop;
 	int chosen_node;
-	int len;
 
 	if (!blob)
-		return -FDT_ERR_NOTFOUND;
+		return NULL;
 	chosen_node = fdt_path_offset(blob, "/chosen");
-	prop = fdt_getprop(blob, chosen_node, name, &len);
+	return fdt_getprop(blob, chosen_node, name, NULL);
+}
+
+int fdtdec_get_chosen_node(const void *blob, const char *name)
+{
+	const char *prop;
+
+	prop = fdtdec_get_chosen_prop(blob, name);
 	if (!prop)
 		return -FDT_ERR_NOTFOUND;
 	return fdt_path_offset(blob, prop);
-- 
2.5.0.457.gab17608



More information about the U-Boot mailing list