dtoc: Update Fdt.GetNode() to handle the root node
authorSimon Glass <sjg@chromium.org>
Sat, 20 Jul 2019 18:23:39 +0000 (12:23 -0600)
committerSimon Glass <sjg@chromium.org>
Mon, 29 Jul 2019 15:38:05 +0000 (09:38 -0600)
This function currently fails if the root node is requested. Requesting
the root node is sometimes useful, so fix the bug.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/dtoc/fdt.py
tools/dtoc/test_fdt.py

index b341ef3f83b24e4d9c6344a70ed321433da41db4..cd7673c7da0d8432072c907c0bd772d7500bdc84 100644 (file)
@@ -574,6 +574,8 @@ class Fdt:
         parts = path.split('/')
         if len(parts) < 2:
             return None
+        if len(parts) == 2 and parts[1] == '':
+            return node
         for part in parts[1:]:
             node = node.FindNode(part)
             if not node:
index c25248ca1f9ed1ec140d286d7ee4a1e3e0d5e015..ed2d982a8fc8bc9c4ec6717a4773834745734259 100755 (executable)
@@ -77,11 +77,16 @@ class TestFdt(unittest.TestCase):
         """Test the GetNode() method"""
         node = self.dtb.GetNode('/spl-test')
         self.assertTrue(isinstance(node, fdt.Node))
+
         node = self.dtb.GetNode('/i2c@0/pmic@9')
         self.assertTrue(isinstance(node, fdt.Node))
         self.assertEqual('pmic@9', node.name)
         self.assertIsNone(self.dtb.GetNode('/i2c@0/pmic@9/missing'))
 
+        node = self.dtb.GetNode('/')
+        self.assertTrue(isinstance(node, fdt.Node))
+        self.assertEqual(0, node.Offset())
+
     def testFlush(self):
         """Check that we can flush the device tree out to its file"""
         fname = self.dtb._fname