dm: core: Rename ofnode_get_chosen_prop()

This function is actually intended to read a string rather than a
property. All of its current callers use it that way. Also there is no way
to return the length of the property from this function.

Rename it to better indicate its purpose, using ofnode_read as the prefix
since this matches most other functions.

Also add some tests which are missing for these functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index e529c54..a04afd4 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -813,6 +813,8 @@
 	chosen {
 		#address-cells = <1>;
 		#size-cells = <1>;
+		setting = "sunrise ohoka";
+		other-node = "/some-bus/c-test@5";
 		chosen-test {
 			compatible = "denx,u-boot-fdt-test";
 			reg = <9 1>;
diff --git a/board/theobroma-systems/puma_rk3399/puma-rk3399.c b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
index 9887d20..7ff4766 100644
--- a/board/theobroma-systems/puma_rk3399/puma-rk3399.c
+++ b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
@@ -49,7 +49,7 @@
 static int setup_boottargets(void)
 {
 	const char *boot_device =
-		ofnode_get_chosen_prop("u-boot,spl-boot-device");
+		ofnode_read_chosen_string("u-boot,spl-boot-device");
 	char *env_default, *env;
 
 	if (!boot_device) {
diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
index ae5fe27..f87e2e9 100644
--- a/board/xilinx/common/board.c
+++ b/board/xilinx/common/board.c
@@ -22,7 +22,7 @@
 		return -ENODEV;
 
 	debug("%s: Path to EEPROM %s\n", __func__,
-	      ofnode_get_chosen_prop("xlnx,eeprom"));
+	      ofnode_read_chosen_string("xlnx,eeprom"));
 
 	ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev);
 	if (ret)
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 8f0eab2..011b43b 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -419,7 +419,7 @@
 		return offset_to_ofnode(fdt_path_offset(gd->fdt_blob, path));
 }
 
-const char *ofnode_get_chosen_prop(const char *name)
+const char *ofnode_read_chosen_string(const char *name)
 {
 	ofnode chosen_node;
 
@@ -432,7 +432,7 @@
 {
 	const char *prop;
 
-	prop = ofnode_get_chosen_prop(name);
+	prop = ofnode_read_chosen_string(name);
 	if (!prop)
 		return ofnode_null();
 
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 62ba0c1..9e76ae8 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -510,14 +510,15 @@
 ofnode ofnode_path(const char *path);
 
 /**
- * ofnode_get_chosen_prop() - get the value of a chosen property
+ * 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
+ * This looks for a property within the /chosen node and returns its value,
+ * checking that it is a valid nul-terminated string
  *
  * @propname: Property name to look for
- * @return property value if found, else NULL
+ * @return string value if found, else NULL
  */
-const char *ofnode_get_chosen_prop(const char *propname);
+const char *ofnode_read_chosen_string(const char *propname);
 
 /**
  * ofnode_get_chosen_node() - get a referenced node from the chosen node
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index 745de50..633a3a9 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -58,3 +58,24 @@
 	return 0;
 }
 DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+static int dm_test_ofnode_read_chosen(struct unit_test_state *uts)
+{
+	const char *str;
+	ofnode node;
+
+	str = ofnode_read_chosen_string("setting");
+	ut_assertnonnull(str);
+	ut_asserteq_str("sunrise ohoka", str);
+	ut_asserteq_ptr(NULL, ofnode_read_chosen_string("no-setting"));
+
+	node = ofnode_get_chosen_node("other-node");
+	ut_assert(ofnode_valid(node));
+	ut_asserteq_str("c-test@5", ofnode_get_name(node));
+
+	node = ofnode_get_chosen_node("setting");
+	ut_assert(!ofnode_valid(node));
+
+	return 0;
+}
+DM_TEST(dm_test_ofnode_read_chosen, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);