diff mbox series

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

Message ID 20200619211140.5081-3-walter.lozano@collabora.com
State RFC
Delegated to: Tom Rini
Headers show
Series drivers: footprint reduction proposal | expand

Commit Message

Walter Lozano June 19, 2020, 9:11 p.m. UTC
This patch introduce a test for deleting DTB nodes using Python library.

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

Comments

Simon Glass July 6, 2020, 7:21 p.m. UTC | #1
Hi Walter,

On Fri, 19 Jun 2020 at 15:12, Walter Lozano <walter.lozano@collabora.com> wrote:
>
> This patch introduce a test for deleting DTB nodes using Python library.
>
> Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
> ---
>  tools/dtoc/dtb_platdata.py | 28 ++++++++++++++++++++++++++++
>  tools/dtoc/fdt.py          |  3 +++
>  2 files changed, 31 insertions(+)

This test should go in test_dtoc.py

Regards,
Simon
Walter Lozano July 7, 2020, 1:44 p.m. UTC | #2
Hi Simon,

On 6/7/20 16:21, Simon Glass wrote:
> Hi Walter,
>
> On Fri, 19 Jun 2020 at 15:12, Walter Lozano <walter.lozano@collabora.com> wrote:
>> This patch introduce a test for deleting DTB nodes using Python library.
>>
>> Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
>> ---
>>   tools/dtoc/dtb_platdata.py | 28 ++++++++++++++++++++++++++++
>>   tools/dtoc/fdt.py          |  3 +++
>>   2 files changed, 31 insertions(+)
> This test should go in test_dtoc.py

Thanks for checking this series. Yes, you areĀ  right, this was an early 
version in order to check with you and Tom if the idea makes any sense.

Regards,

Walter
diff mbox series

Patch

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.