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>;
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) {
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)
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;
{
const char *prop;
- prop = ofnode_get_chosen_prop(name);
+ prop = ofnode_read_chosen_string(name);
if (!prop)
return ofnode_null();
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
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);