Skip to content

Commit 63486f3

Browse files
committed
edtlib: always insert root node to the graph
When we have an empty Devicetree, ie, ``` /dts-v1/; / { }; ``` The node's dep_ordinal is never initialized because the node graph is empty. This ends up with invalid ordinal tokens (-1) in devicetree_generated.h which in turn produce some cryptic compiler errors, see e.g. ``` error: pasting "dts_ord_" and "-" does not give a valid preprocessing token 95 | #define Z_DEVICE_DT_DEV_ID(node_id) _CONCAT(dts_ord_, DT_DEP_ORD(node_id)) ... include/zephyr/devicetree.h:2498:41: note: in expansion of macro 'DT_FOREACH_OKAY_HELPER' 2498 | #define DT_FOREACH_STATUS_OKAY_NODE(fn) DT_FOREACH_OKAY_HELPER(fn) | ^~~~~~~~~~~~~~~~~~~~~~ include/zephyr/device.h:1022:1: note: in expansion of macro 'DT_FOREACH_STATUS_OKAY_NODE' 1022 | DT_FOREACH_STATUS_OKAY_NODE(Z_MAYBE_DEVICE_DECLARE_INTERNAL) ``` (devicetree_generated.h) ``` ... #define DT_N_ORD -1 #define DT_N_ORD_STR_SORTABLE 000-1 ... ``` This patch makes sure root node is always inserted (without any target) so that it gets initialized later. Discovered as part of #63696 Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent 8c6a3db commit 63486f3

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

scripts/dts/python-devicetree/src/devicetree/edtlib.py

+4
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,10 @@ def _init_graph(self) -> None:
20612061
# first time the scc_order property is read.
20622062

20632063
for node in self.nodes:
2064+
# Always insert root node
2065+
if not node.parent:
2066+
self._graph.add_node(node)
2067+
20642068
# A Node always depends on its parent.
20652069
for child in node.children.values():
20662070
self._graph.add_edge(child, node)

scripts/dts/python-devicetree/src/devicetree/grutils.py

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ def __init__(self, root=None):
2626
self.__reverse_map = collections.defaultdict(set)
2727
self.__nodes = set()
2828

29+
def add_node(self, node):
30+
"""
31+
Add a node without any target to the graph.
32+
"""
33+
self.__nodes.add(node)
34+
2935
def add_edge(self, source, target):
3036
"""
3137
Add a directed edge from the C{source} to the C{target}.

0 commit comments

Comments
 (0)