[RFC 2/4] dtoc: add initial support for deleting DTB nodes

Walter Lozano walter.lozano at collabora.com
Fri Jun 19 23:11:38 CEST 2020


This patch introduce a test for deleting DTB nodes using Python library.

Signed-off-by: Walter Lozano <walter.lozano at collabora.com>
---
 tools/dtoc/dtb_platdata.py | 28 ++++++++++++++++++++++++++++
 tools/dtoc/fdt.py          |  3 +++
 2 files changed, 31 insertions(+)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 1df13b2cd2..d3fb4dcbf2 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -831,6 +831,30 @@ class DtbPlatdata(object):
 
         return
 
+    def test_del_node(self):
+        """Test the support of node deletion'
+
+        This function tests the support of node removal by deleting a specific
+        node name
+        """
+        for n in self._fdt.GetRoot().subnodes:
+            print('Name', n.name)
+            #print('Props', n.props)
+            if n.name == 'board-detect':
+                n.DelNode()
+                #self._fdt.GetRoot().subnodes.remove(n)
+        self._fdt.Scan()
+        print('')
+        for n in self._fdt.GetRoot().subnodes:
+            print('Name', n.name)
+            #print('Props', n.props)
+            if n.name == 'serial':
+                self._fdt.GetRoot().subnodes.remove(n)
+
+        self._fdt.Pack()
+        self._fdt.Flush()
+        self._fdt.Sync()
+
 def run_steps(args, dtb_file, config_file, include_disabled, output):
     """Run all the steps of the dtoc tool
 
@@ -848,6 +872,8 @@ def run_steps(args, dtb_file, config_file, include_disabled, output):
     skip_scan = False
     if args == ['shrink']:
         skip_scan = True
+    if args == ['test_del_node']:
+        skip_scan = True
 
     plat = DtbPlatdata(dtb_file, config_file, include_disabled)
     plat.scan_drivers()
@@ -867,6 +893,8 @@ def run_steps(args, dtb_file, config_file, include_disabled, output):
             plat.generate_tables()
         elif cmd == 'shrink':
             plat.shrink()
+        elif cmd == 'test_del_node':
+            plat.test_del_node()
         else:
             raise ValueError("Unknown command '%s': (use: struct, platdata)" %
                              cmd)
diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index 3d4bc3b2ef..b3b626cd4d 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -502,6 +502,9 @@ class Node:
         for prop in prop_list:
             prop.Sync(auto_resize)
 
+    def DelNode(self):
+        fdt_obj = self._fdt._fdt_obj
+        fdt_obj.del_node(self._offset)
 
 class Fdt:
     """Provides simple access to a flat device tree blob using libfdts.
-- 
2.20.1



More information about the U-Boot mailing list