dm: core: Support writing a boolean

Add functions to write a boolean property. This involves deleting it if
the value is false.

Add a new ofnode_has_property() as well. Add a comment about the behaviour
of of_read_property() when the property value is empty.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2023-09-26 08:14:44 -06:00
committed by Tom Rini
parent 62b1db3377
commit d9216c8683
3 changed files with 90 additions and 3 deletions

View File

@@ -1480,3 +1480,28 @@ static int dm_test_oftree_to_fdt(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_oftree_to_fdt, UT_TESTF_SCAN_FDT);
/* test ofnode_read_bool() and ofnode_write_bool() */
static int dm_test_bool(struct unit_test_state *uts)
{
const char *propname = "missing-bool-value";
ofnode node;
node = ofnode_path("/a-test");
ut_assert(ofnode_read_bool(node, "bool-value"));
ut_assert(!ofnode_read_bool(node, propname));
ut_assert(!ofnode_has_property(node, propname));
ut_assertok(ofnode_write_bool(node, propname, true));
ut_assert(ofnode_read_bool(node, propname));
ut_assert(ofnode_has_property(node, propname));
ut_assert(ofnode_read_bool(node, "bool-value"));
ut_assertok(ofnode_write_bool(node, propname, false));
ut_assert(!ofnode_read_bool(node, propname));
ut_assert(!ofnode_has_property(node, propname));
ut_assert(ofnode_read_bool(node, "bool-value"));
return 0;
}
DM_TEST(dm_test_bool, UT_TESTF_SCAN_FDT);