Skip to content

Commit 15db98a

Browse files
mbolivar-nordiccfriedt
authored andcommitted
dtlib: allow dangling aliases with DT(..., force=True)
As a first step towards being more forgiving on invalid inputs, allow string-valued aliases properties that do not point to valid nodes when the user requests permissiveness. Signed-off-by: Martí Bolívar <[email protected]>
1 parent 176225d commit 15db98a

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,8 +1684,15 @@ def _register_aliases(self):
16841684
_err("/aliases: alias property name '{}' should include "
16851685
"only characters from [0-9a-z-]".format(prop.name))
16861686

1687-
# Property.to_path() already checks that the node exists
1688-
alias2node[prop.name] = prop.to_path()
1687+
# Property.to_path() checks that the node exists, has
1688+
# the right type, etc. Swallow errors for invalid
1689+
# aliases with self._force.
1690+
try:
1691+
alias2node[prop.name] = prop.to_path()
1692+
except DTError:
1693+
if self._force:
1694+
continue
1695+
raise
16891696

16901697
self.alias2node = alias2node
16911698

scripts/dts/python-devicetree/tests/test_dtlib.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
# - to run a particular test function or functions, use
2525
# '-k test_function_pattern_goes_here'
2626

27-
def parse(dts, include_path=()):
28-
'''Parse a DTS string 'dts', using the given include path.'''
27+
def parse(dts, include_path=(), **kwargs):
28+
'''Parse a DTS string 'dts', using the given include path.
29+
30+
Any kwargs are passed on to DT().'''
2931

3032
fd, path = tempfile.mkstemp(prefix='pytest-', suffix='.dts')
3133
try:
3234
os.write(fd, dts.encode('utf-8'))
33-
return dtlib.DT(path, include_path)
35+
return dtlib.DT(path, include_path, **kwargs)
3436
finally:
3537
os.close(fd)
3638
os.unlink(path)
@@ -2250,3 +2252,13 @@ def test_misc():
22502252
/ {
22512253
};
22522254
""")
2255+
2256+
def test_dangling_alias():
2257+
dt = parse('''
2258+
/dts-v1/;
2259+
2260+
/ {
2261+
aliases { foo = "/missing"; };
2262+
};
2263+
''', force=True)
2264+
assert dt.get_node('/aliases').props['foo'].to_string() == '/missing'

0 commit comments

Comments
 (0)