aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass2020-01-27 08:49:46 -0700
committerSimon Glass2020-02-05 19:33:45 -0700
commitbd933bfd834364bca6cc6f3a62e4255090a5bec1 (patch)
treeaade4618c7168efe95a72e4466350513ce1549fd
parent1aada6313ca9b9e9123a4118c78558ef413e1039 (diff)
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: Simon Glass <sjg@chromium.org>
-rw-r--r--arch/sandbox/dts/test.dts1
-rw-r--r--drivers/core/ofnode.c11
-rw-r--r--include/dm/ofnode.h12
-rw-r--r--test/dm/ofnode.c8
4 files changed, 29 insertions, 3 deletions
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index a04afd4076b..347ea79077d 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -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>;
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 4fc29a7c432..f55ef15cee3 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -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();
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 80074836809..b5a50e88499 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -521,6 +521,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
*
* This looks for a property within the /chosen node and returns its value,
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index f1e4ed75db0..1c49eaf38bf 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -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);