devicetree: gen_defines: adjust z_path_id for /
The root node's z_path_id value for the duration of this script
doesn't match the value DT_ROOT is defined to in devicetree.h.
I didn't notice this because the root node's compatible doesn't have a
matching binding in practice, so no macros are generated for it, but
we're about to start looking at node parents explicitly and this is an
issue for that. Fix it so the root node's z_path_id is "N", since
DT_ROOT is the token "DT_N".
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py
index a5ef1f3..5a3315b 100755
--- a/scripts/dts/gen_defines.py
+++ b/scripts/dts/gen_defines.py
@@ -48,8 +48,7 @@
write_top_comment(edt)
for node in sorted(edt.nodes, key=lambda node: node.dep_ordinal):
- node.z_path_id = "N_" + "_".join(
- f"S_{str2ident(name)}" for name in node.path[1:].split("/"))
+ node.z_path_id = node_z_path_id(node)
write_node_comment(node)
if not node.enabled:
@@ -68,6 +67,24 @@
write_global_compat_info(edt)
+def node_z_path_id(node):
+ # Return the node specific bit of the node's path identifier:
+ #
+ # - the root node's path "/" has path identifier "N"
+ # - "/foo" has "N_S_foo"
+ # - "/foo/bar" has "N_S_foo_S_bar"
+ # - "/foo/bar@123" has "N_S_foo_S_bar_123"
+ #
+ # This is used throughout this file to generate macros related to
+ # the node.
+
+ components = ["N"]
+ if node.parent is not None:
+ components.extend(f"S_{str2ident(component)}" for component in
+ node.path.split("/")[1:])
+
+ return "_".join(components)
+
def parse_args():
# Returns parsed command-line arguments