Skip to content

Commit 7b9fbcd

Browse files
committed
devicetree: Fix DT_PROP/DT_PROP_BY_IDX for phandle(s)
DT_PROP for a phandle property should return the node that phandle points to (similar for DT_PROP_BY_IDX for phandles) and this wasn't working as the define generator didn't create the proper defines for phandle(s). Fix the generator and add some tests to make sure this continues to work correctly. Signed-off-by: Kumar Gala <[email protected]>
1 parent f6d7c38 commit 7b9fbcd

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

scripts/dts/gen_defines.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,13 @@ def phandle_macros(prop, macro):
682682

683683
if prop.type == "phandle":
684684
# A phandle is treated as a phandles with fixed length 1.
685+
ret[f"{macro}"] = f"DT_{prop.val.z_path_id}"
686+
ret[f"{macro}_IDX_0"] = f"DT_{prop.val.z_path_id}"
685687
ret[f"{macro}_IDX_0_PH"] = f"DT_{prop.val.z_path_id}"
686688
ret[f"{macro}_IDX_0_EXISTS"] = 1
687689
elif prop.type == "phandles":
688690
for i, node in enumerate(prop.val):
691+
ret[f"{macro}_IDX_{i}"] = f"DT_{node.z_path_id}"
689692
ret[f"{macro}_IDX_{i}_PH"] = f"DT_{node.z_path_id}"
690693
ret[f"{macro}_IDX_{i}_EXISTS"] = 1
691694
elif prop.type == "phandle-array":

tests/lib/devicetree/api/src/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,19 @@ static void test_phandles(void)
616616

617617
/* phandle */
618618
zassert_true(DT_NODE_HAS_PROP(TEST_PH, ph), "");
619+
zassert_true(DT_SAME_NODE(DT_PROP(TEST_PH, ph),
620+
DT_NODELABEL(test_gpio_1)), "");
621+
zassert_true(DT_SAME_NODE(DT_PROP_BY_IDX(TEST_PH, ph, 0),
622+
DT_NODELABEL(test_gpio_1)), "");
619623
/* DT_PROP_BY_PHANDLE */
620624
zassert_true(!strcmp(ph_label, "TEST_GPIO_1"), "");
621625

622626
/* phandles */
623627
zassert_true(DT_NODE_HAS_PROP(TEST_PH, phs), "");
624628
zassert_equal(ARRAY_SIZE(phs_labels), 3, "");
625629
zassert_equal(DT_PROP_LEN(TEST_PH, phs), 3, "");
630+
zassert_true(DT_SAME_NODE(DT_PROP_BY_IDX(TEST_PH, phs, 1),
631+
DT_NODELABEL(test_gpio_2)), "");
626632

627633
/* DT_PROP_BY_PHANDLE_IDX */
628634
zassert_true(!strcmp(DT_PROP_BY_PHANDLE_IDX(TEST_PH, phs, 0, label),

0 commit comments

Comments
 (0)