dm: core: Add ofnode_get_chosen_prop()

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@chromium.org>
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index a04afd4..347ea79 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@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 4fc29a7..f55ef15 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -427,20 +427,25 @@
 		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 8007483..b5a50e8 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -521,6 +521,18 @@
 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
  *
  * This looks for a property within the /chosen node and returns its value,
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index f1e4ed7..1c49eaf 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -88,7 +88,9 @@
 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 @@
 	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);