From: Simon Glass Date: Mon, 27 Jan 2020 15:49:43 +0000 (-0700) Subject: dm: core: Rename ofnode_get_chosen_prop() X-Git-Tag: v2020.04-rc2~2^2~54 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=14ca9f7f5abf7b94d71cfd466fb339bf64f58bda;p=oweals%2Fu-boot.git 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 --- diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index e529c54d8d..a04afd4076 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 9887d20207..7ff4766947 100644 --- a/board/theobroma-systems/puma_rk3399/puma-rk3399.c +++ b/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) { diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c index ae5fe2729f..f87e2e9105 100644 --- a/board/xilinx/common/board.c +++ b/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) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 8f0eab2ca6..011b43bc02 100644 --- a/drivers/core/ofnode.c +++ b/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(); diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 62ba0c13ea..9e76ae8407 100644 --- a/include/dm/ofnode.h +++ b/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 diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 745de50c7b..633a3a9e9a 100644 --- a/test/dm/ofnode.c +++ b/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);