[PATCH 08/24] dtoc: Allow deleting nodes and adding them in the same sync

Simon Glass sjg at chromium.org
Tue Feb 8 19:49:52 CET 2022


This does not work at present, since the current algorithm assumes that
either there are no nodes or all nodes have an offset. If a node is new,
but an old node is still in the tree, then syncing fails due to this
assumption.

Fix it and add a test.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 tools/dtoc/fdt.py      |  2 ++
 tools/dtoc/test_fdt.py | 11 +++++++++++
 2 files changed, 13 insertions(+)

diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index 8108a86c09..98d6e636ea 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -356,6 +356,8 @@ class Node:
 
         offset = fdt_obj.first_subnode(self._offset, QUIET_NOTFOUND)
         for subnode in self.subnodes:
+            if subnode._offset is None:
+                continue
             if subnode.name != fdt_obj.get_name(offset):
                 raise ValueError('Internal error, node name mismatch %s != %s' %
                                  (subnode.name, fdt_obj.get_name(offset)))
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index 22e23c40f5..c8fe5fc1de 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -272,6 +272,17 @@ class TestNode(unittest.TestCase):
 
         self.dtb.Sync(auto_resize=True)
 
+    def testAddOneNode(self):
+        """Testing deleting and adding a subnode before syncing"""
+        subnode = self.node.AddSubnode('subnode')
+        self.node.AddSubnode('subnode2')
+        self.dtb.Sync(auto_resize=True)
+
+        # Delete a node and add a new one
+        subnode.Delete()
+        self.node.AddSubnode('subnode3')
+        self.dtb.Sync()
+
     def testRefreshNameMismatch(self):
         """Test name mismatch when syncing nodes and properties"""
         prop = self.node.AddInt('integer-a', 12)
-- 
2.35.0.263.gb82422642f-goog



More information about the U-Boot mailing list