提交 bd933bfd 编写于 作者: S Simon Glass

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: NSimon Glass <sjg@chromium.org>
上级 1aada631
......@@ -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>;
......
......@@ -427,20 +427,25 @@ ofnode ofnode_path(const char *path)
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();
......
......@@ -520,6 +520,18 @@ int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
*/
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
*
......
......@@ -88,7 +88,9 @@ DM_TEST(dm_test_ofnode_read, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
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 @@ static int dm_test_ofnode_read_chosen(struct unit_test_state *uts)
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);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册