From 50f9b3c2cade9e48ddcc8bda94dc372266fc85ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Wed, 23 Mar 2022 13:41:09 -0700 Subject: [PATCH] gen_defines: add _CHILD_IDX macros for nodes with parents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These expose every node's index in its parent's list of children to C. The root node has no parent, so no _CHILD_IDX macro is generated for it. Keep macros.bnf up to date with the new generated macros. Signed-off-by: Martí Bolívar --- doc/guides/dts/macros.bnf | 2 ++ scripts/dts/gen_defines.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/doc/guides/dts/macros.bnf b/doc/guides/dts/macros.bnf index 504b357a3be..5309cf1f81b 100644 --- a/doc/guides/dts/macros.bnf +++ b/doc/guides/dts/macros.bnf @@ -67,6 +67,8 @@ node-macro =/ %s"DT_N" path-id %s"_FOREACH_CHILD_VARGS" ; over each child node with status "okay". node-macro =/ %s"DT_N" path-id %s"_FOREACH_CHILD_STATUS_OKAY" node-macro =/ %s"DT_N" path-id %s"_FOREACH_CHILD_STATUS_OKAY_VARGS" +; The node's zero-based index in the list of it's parent's child nodes. +node-macro =/ %s"DT_N" path-id %s"_CHILD_IDX" ; The node's status macro; dt-name in this case is something like "okay" ; or "disabled". node-macro =/ %s"DT_N" path-id %s"_STATUS_" dt-name diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py index 5c3b950a9a8..f8d72ede78f 100755 --- a/scripts/dts/gen_defines.py +++ b/scripts/dts/gen_defines.py @@ -132,6 +132,10 @@ def main(): out_dt_define(f"{node.z_path_id}_PARENT", f"DT_{node.parent.z_path_id}") + out_comment(f"Node's index in its parent's list of children:") + out_dt_define(f"{node.z_path_id}_CHILD_IDX", + node.parent.child_index(node)) + write_children(node) write_dep_info(node) write_idents_and_existence(node)