diff --git a/scripts/dts/python-devicetree/src/devicetree/dtlib.py b/scripts/dts/python-devicetree/src/devicetree/dtlib.py index c9084f08c1e..9d5f32cf711 100644 --- a/scripts/dts/python-devicetree/src/devicetree/dtlib.py +++ b/scripts/dts/python-devicetree/src/devicetree/dtlib.py @@ -1684,8 +1684,15 @@ class DT: _err("/aliases: alias property name '{}' should include " "only characters from [0-9a-z-]".format(prop.name)) - # Property.to_path() already checks that the node exists - alias2node[prop.name] = prop.to_path() + # Property.to_path() checks that the node exists, has + # the right type, etc. Swallow errors for invalid + # aliases with self._force. + try: + alias2node[prop.name] = prop.to_path() + except DTError: + if self._force: + continue + raise self.alias2node = alias2node diff --git a/scripts/dts/python-devicetree/tests/test_dtlib.py b/scripts/dts/python-devicetree/tests/test_dtlib.py index c6a07765608..13e5544da6a 100644 --- a/scripts/dts/python-devicetree/tests/test_dtlib.py +++ b/scripts/dts/python-devicetree/tests/test_dtlib.py @@ -24,13 +24,15 @@ from devicetree import dtlib # - to run a particular test function or functions, use # '-k test_function_pattern_goes_here' -def parse(dts, include_path=()): - '''Parse a DTS string 'dts', using the given include path.''' +def parse(dts, include_path=(), **kwargs): + '''Parse a DTS string 'dts', using the given include path. + + Any kwargs are passed on to DT().''' fd, path = tempfile.mkstemp(prefix='pytest-', suffix='.dts') try: os.write(fd, dts.encode('utf-8')) - return dtlib.DT(path, include_path) + return dtlib.DT(path, include_path, **kwargs) finally: os.close(fd) os.unlink(path) @@ -2250,3 +2252,13 @@ l1: l2: &foo { / { }; """) + +def test_dangling_alias(): + dt = parse(''' +/dts-v1/; + +/ { + aliases { foo = "/missing"; }; +}; +''', force=True) + assert dt.get_node('/aliases').props['foo'].to_string() == '/missing'