[U-Boot,17/53] dtoc: Update Fdt.GetNode() to handle the root node
diff mbox series

Message ID 20190720182416.183626-18-sjg@chromium.org
State Accepted
Commit e44bc831e262c2ca7f307ad12074c2eb9adab615
Delegated to: Simon Glass
Headers show
Series
  • binman: Support replacing entries in an existing image
Related show

Commit Message

Simon Glass July 20, 2019, 6:23 p.m. UTC
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      | 2 ++
 tools/dtoc/test_fdt.py | 5 +++++
 2 files changed, 7 insertions(+)

Comments

Simon Glass July 29, 2019, 9:22 p.m. UTC | #1
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      | 2 ++
 tools/dtoc/test_fdt.py | 5 +++++
 2 files changed, 7 insertions(+)

Applied to u-boot-dm, thanks!

Patch
diff mbox series

diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index b341ef3f83b..cd7673c7da0 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -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:
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index c25248ca1f9..ed2d982a8fc 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -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