[U-Boot] [PATCH 17/29] dtoc: Fix Fdt.GetNode() to handle a missing node
Simon Glass
sjg at chromium.org
Wed Jun 6 00:46:53 UTC 2018
At present the algortihm is not correct since it will return the root node
if the requested node is not found and there are no slashes in the
requested node name. Fix this and add a test.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
tools/dtoc/fdt.py | 5 ++++-
tools/dtoc/test_fdt.py | 4 ++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index 2d7b6328f11..fc8aeb81de5 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -324,7 +324,10 @@ class Fdt:
Node object, or None if not found
"""
node = self._root
- for part in path.split('/')[1:]:
+ parts = path.split('/')
+ if len(parts) < 2:
+ return None
+ for part in parts[1:]:
node = node._FindNode(part)
if not node:
return None
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index cd86144896f..78afb33b056 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -77,6 +77,7 @@ class TestFdt(unittest.TestCase):
node = self.dtb.GetNode('/i2c at 0/pmic at 9')
self.assertTrue(isinstance(node, fdt.Node))
self.assertEqual('pmic at 9', node.name)
+ self.assertEqual(None, self.dtb.GetNode('/i2c at 0/pmic at 9/missing'))
def testFlush(self):
"""Check that we can flush the device tree out to its file"""
@@ -177,6 +178,9 @@ class TestProp(unittest.TestCase):
self.node = self.dtb.GetNode('/spl-test')
self.fdt = self.dtb.GetFdtObj()
+ def testMissingNode(self):
+ self.assertEqual(None, self.dtb.GetNode('missing'))
+
def testPhandle(self):
dtb = fdt.FdtScan('tools/dtoc/dtoc_test_phandle.dts')
node = dtb.GetNode('/phandle-source')
--
2.17.1.1185.g55be947832-goog
More information about the U-Boot
mailing list