scripts: devicetree.py: get alternate labels from dt
Allow use of new element of dtc grammar called overriding nodes:
i2cexp: &i2c2 {};
It allows a node to assign an alternate label to a node that
could be generic and used for adapter boards.
This commit is a derivative of a dtc commit from dtc v1.4.2 [1]
[1] https://bit.ly/2GFLLOa
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
diff --git a/scripts/dts/devicetree.py b/scripts/dts/devicetree.py
index 3b57d6a..521a3ad 100755
--- a/scripts/dts/devicetree.py
+++ b/scripts/dts/devicetree.py
@@ -48,15 +48,23 @@
addr = None
if ':' in line:
- label, name = line.split(':')
+ if len(line.split(':')) == 3:
+ alt_label, label, name = line.split(':')
+ else:
+ label, name = line.split(':')
+ alt_label = None
else:
name = line
label = None
+ alt_label = None
if addr is None:
- return label, name.strip(), None, None
+ return label, name.strip(), None, None, None
- return label, name.strip(), addr, int(addr, 16)
+ if alt_label is None:
+ return label, name.strip(), addr, int(addr, 16), None
+
+ return label, name.strip(), addr, int(addr, 16), alt_label
def parse_values_internal(value, start, end, separator):
out = []
@@ -142,7 +150,7 @@
return '%s@%s' % (name, addr.strip())
def parse_node(line, fd):
- label, name, addr, numeric_addr = parse_node_name(line)
+ label, name, addr, numeric_addr, alt_label = parse_node_name(line)
node = {
'label': label,
@@ -152,6 +160,9 @@
'props': {},
'name': build_node_name(name, addr)
}
+ if alt_label:
+ node['alt_name'] = alt_label
+
while True:
line = fd.readline()
if not line: