[PATCH 11/21] dm: core: Add ofnode_get_chosen_prop()

Simon Glass sjg at chromium.org
Mon Jan 27 16:49:46 CET 2020


Add a function to read a property from the chosen node, providing access
to its length. Update ofnode_get_chosen_string() to make use of it.

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

 arch/sandbox/dts/test.dts |  1 +
 drivers/core/ofnode.c     | 11 ++++++++---
 include/dm/ofnode.h       | 12 ++++++++++++
 test/dm/ofnode.c          |  8 ++++++++
 4 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index a04afd4076..347ea79077 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -815,6 +815,7 @@
 		#size-cells = <1>;
 		setting = "sunrise ohoka";
 		other-node = "/some-bus/c-test at 5";
+		int-values = <0x1937 72993>;
 		chosen-test {
 			compatible = "denx,u-boot-fdt-test";
 			reg = <9 1>;
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 4fc29a7c43..f55ef15cee 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -427,20 +427,25 @@ ofnode ofnode_path(const char *path)
 		return offset_to_ofnode(fdt_path_offset(gd->fdt_blob, path));
 }
 
-const char *ofnode_read_chosen_string(const char *name)
+const void *ofnode_read_chosen_prop(const char *propname, int *sizep)
 {
 	ofnode chosen_node;
 
 	chosen_node = ofnode_path("/chosen");
 
-	return ofnode_read_string(chosen_node, name);
+	return ofnode_read_prop(chosen_node, propname, sizep);
+}
+
+const char *ofnode_read_chosen_string(const char *propname)
+{
+	return ofnode_read_chosen_prop(propname, NULL);
 }
 
 ofnode ofnode_get_chosen_node(const char *name)
 {
 	const char *prop;
 
-	prop = ofnode_read_chosen_string(name);
+	prop = ofnode_read_chosen_prop(name, NULL);
 	if (!prop)
 		return ofnode_null();
 
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 8007483680..b5a50e8849 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -520,6 +520,18 @@ int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
  */
 ofnode ofnode_path(const char *path);
 
+/**
+ * ofnode_read_chosen_prop() - get the value of a chosen property
+ *
+ * This looks for a property within the /chosen node and returns its value
+ *
+ * @propname: Property name to look for
+ * @sizep: Returns size of property, or FDT_ERR_... error code if function
+ *	returns NULL
+ * @return property value if found, else NULL
+ */
+const void *ofnode_read_chosen_prop(const char *propname, int *sizep);
+
 /**
  * ofnode_read_chosen_string() - get the string value of a chosen property
  *
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index f1e4ed75db..1c49eaf38b 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -88,7 +88,9 @@ DM_TEST(dm_test_ofnode_read, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 static int dm_test_ofnode_read_chosen(struct unit_test_state *uts)
 {
 	const char *str;
+	const u32 *val;
 	ofnode node;
+	int size;
 
 	str = ofnode_read_chosen_string("setting");
 	ut_assertnonnull(str);
@@ -102,6 +104,12 @@ static int dm_test_ofnode_read_chosen(struct unit_test_state *uts)
 	node = ofnode_get_chosen_node("setting");
 	ut_assert(!ofnode_valid(node));
 
+	val = ofnode_read_chosen_prop("int-values", &size);
+	ut_assertnonnull(val);
+	ut_asserteq(8, size);
+	ut_asserteq(0x1937, fdt32_to_cpu(val[0]));
+	ut_asserteq(72993, fdt32_to_cpu(val[1]));
+
 	return 0;
 }
 DM_TEST(dm_test_ofnode_read_chosen, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.25.0.341.g760bfbb309-goog



More information about the U-Boot mailing list