浏览代码

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>
Simon Glass 4 年之前
父节点
当前提交
14ca9f7f5a

+ 2 - 0
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>;

+ 1 - 1
board/theobroma-systems/puma_rk3399/puma-rk3399.c

@@ -49,7 +49,7 @@ static void setup_iodomain(void)
 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) {

+ 1 - 1
board/xilinx/common/board.c

@@ -22,7 +22,7 @@ int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
 		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)

+ 2 - 2
drivers/core/ofnode.c

@@ -419,7 +419,7 @@ ofnode ofnode_path(const char *path)
 		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 @@ ofnode ofnode_get_chosen_node(const char *name)
 {
 	const char *prop;
 
-	prop = ofnode_get_chosen_prop(name);
+	prop = ofnode_read_chosen_string(name);
 	if (!prop)
 		return ofnode_null();
 

+ 5 - 4
include/dm/ofnode.h

@@ -510,14 +510,15 @@ int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
 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

+ 21 - 0
test/dm/ofnode.c

@@ -58,3 +58,24 @@ static int dm_test_ofnode_fmap(struct unit_test_state *uts)
 	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);