Skip to content

Commit 3b64e71

Browse files
ulfalizergalak
authored andcommitted
scripts/dts: Simplify extract/interrupts.py and add some helpers
- Have get_parent_path() return None for the root ('/'). This is handy when looping over path components. - Move _find_parent_irq_node() out of the class, call it parent_irq_node(), and use get_parent_path() in it. - Add a global err() function for reporting errors. Use it if a node unexpectedly has no interrupt-parent. Previously, this would give a Python error instead. Signed-off-by: Ulf Magnusson <[email protected]>
1 parent a3d3aa5 commit 3b64e71

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

scripts/dts/extract/globals.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# SPDX-License-Identifier: Apache-2.0
66
#
77

8+
import sys
9+
810
from collections import defaultdict
911

1012
# globals
@@ -187,7 +189,10 @@ def node_label(node_path):
187189

188190

189191
def get_parent_path(node_path):
190-
# Turns /foo/bar into /foo
192+
# Turns /foo/bar into /foo. Returns None for /.
193+
194+
if node_path == '/':
195+
return None
191196

192197
return '/'.join(node_path.split('/')[:-1]) or '/'
193198

@@ -467,3 +472,10 @@ def extract_cells(node_path, prop, prop_values, names, index,
467472
prop_alias)
468473

469474
insert_defs(node_path, prop_def, prop_alias)
475+
476+
477+
def err(msg):
478+
# General error reporting helper. Prints a message to stderr and exits with
479+
# status 1.
480+
481+
sys.exit("error: " + msg)

scripts/dts/extract/interrupts.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@
1111
# @brief Manage interrupts directives.
1212
#
1313
class DTInterrupts(DTDirective):
14-
def _find_parent_irq_node(self, node_path):
15-
address = ''
16-
17-
for comp in node_path.split('/')[1:]:
18-
address += '/' + comp
19-
if 'interrupt-parent' in reduced[address]['props']:
20-
interrupt_parent = reduced[address]['props'][
21-
'interrupt-parent']
22-
23-
return phandles[interrupt_parent]
24-
2514
##
2615
# @brief Extract interrupts
2716
#
@@ -40,7 +29,9 @@ def extract(self, node_path, prop, names, def_label):
4029
except:
4130
props = [node['props'].get(prop)]
4231

43-
irq_parent = self._find_parent_irq_node(node_path)
32+
irq_parent = parent_irq_node(node_path)
33+
if not irq_parent:
34+
err(node_path + " has no interrupt-parent")
4435

4536
l_base = def_label.split('/')
4637
index = 0
@@ -88,6 +79,17 @@ def extract(self, node_path, prop, names, def_label):
8879
index += 1
8980
insert_defs(node_path, prop_def, prop_alias)
9081

82+
83+
def parent_irq_node(node_path):
84+
while node_path:
85+
if 'interrupt-parent' in reduced[node_path]['props']:
86+
return phandles[reduced[node_path]['props']['interrupt-parent']]
87+
88+
node_path = get_parent_path(node_path)
89+
90+
return None
91+
92+
9193
##
9294
# @brief Management information for interrupts.
9395
interrupts = DTInterrupts()

0 commit comments

Comments
 (0)