[PATCH v2 23/32] dm: core: Support writing a 64-bit value
Simon Glass
sjg at chromium.org
Thu Sep 21 03:57:12 CEST 2023
Add support for writing a single 64-bit value into a property.
Repurpose the existing tests to handle this case too.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
(no changes since v1)
drivers/core/ofnode.c | 17 ++++++++++++++++-
include/dm/ofnode.h | 10 ++++++++++
test/dm/ofnode.c | 15 +++++++++++++--
3 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 0229695dba1f..2ef4114cb6f8 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -1621,7 +1621,22 @@ int ofnode_write_u32(ofnode node, const char *propname, u32 value)
return -ENOMEM;
*val = cpu_to_fdt32(value);
- return ofnode_write_prop(node, propname, val, sizeof(value), false);
+ return ofnode_write_prop(node, propname, val, sizeof(value), true);
+}
+
+int ofnode_write_u64(ofnode node, const char *propname, u64 value)
+{
+ fdt64_t *val;
+
+ assert(ofnode_valid(node));
+
+ log_debug("%s = %llx", propname, (unsigned long long)value);
+ val = malloc(sizeof(*val));
+ if (!val)
+ return -ENOMEM;
+ *val = cpu_to_fdt64(value);
+
+ return ofnode_write_prop(node, propname, val, sizeof(value), true);
}
int ofnode_write_bool(ofnode node, const char *propname, bool value)
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 58c6849534ea..726d8f82ddf2 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -1460,6 +1460,16 @@ int ofnode_write_string(ofnode node, const char *propname, const char *value);
*/
int ofnode_write_u32(ofnode node, const char *propname, u32 value);
+/**
+ * ofnode_write_u64() - Set an integer property of an ofnode
+ *
+ * @node: The node for whose string property should be set
+ * @propname: The name of the string property to set
+ * @value: The new value of the 64-bit integer property
+ * Return: 0 if successful, -ve on error
+ */
+int ofnode_write_u64(ofnode node, const char *propname, u64 value);
+
/**
* ofnode_write_bool() - Set a boolean property of an ofnode
*
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index af844a50308e..5e63efdfa891 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -990,7 +990,8 @@ static int dm_test_ofnode_u32_array(struct unit_test_state *uts)
}
DM_TEST(dm_test_ofnode_u32_array, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
-static int dm_test_ofnode_read_u64(struct unit_test_state *uts)
+/* test ofnode_read_u64() and ofnode_write_u64() */
+static int dm_test_ofnode_u64(struct unit_test_state *uts)
{
ofnode node;
u64 val;
@@ -999,6 +1000,10 @@ static int dm_test_ofnode_read_u64(struct unit_test_state *uts)
ut_assert(ofnode_valid(node));
ut_assertok(ofnode_read_u64(node, "int64-value", &val));
ut_asserteq_64(0x1111222233334444, val);
+ ut_assertok(ofnode_write_u64(node, "new-int64-value", 0x9876543210));
+ ut_assertok(ofnode_read_u64(node, "new-int64-value", &val));
+ ut_asserteq_64(0x9876543210, val);
+
ut_asserteq(-EINVAL, ofnode_read_u64(node, "missing", &val));
ut_assertok(ofnode_read_u64_index(node, "int64-array", 0, &val));
@@ -1009,9 +1014,15 @@ static int dm_test_ofnode_read_u64(struct unit_test_state *uts)
ofnode_read_u64_index(node, "int64-array", 2, &val));
ut_asserteq(-EINVAL, ofnode_read_u64_index(node, "missing", 0, &val));
+ ut_assertok(ofnode_write_u64(node, "int64-array", 0x9876543210));
+ ut_assertok(ofnode_read_u64_index(node, "int64-array", 0, &val));
+ ut_asserteq_64(0x9876543210, val);
+ ut_asserteq(-EOVERFLOW,
+ ofnode_read_u64_index(node, "int64-array", 1, &val));
+
return 0;
}
-DM_TEST(dm_test_ofnode_read_u64, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_u64, UT_TESTF_SCAN_FDT);
static int dm_test_ofnode_add_subnode(struct unit_test_state *uts)
{
--
2.42.0.515.g380fc7ccd1-goog
More information about the U-Boot
mailing list