From patchwork Fri Jun 19 21:11:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Walter Lozano X-Patchwork-Id: 242717 List-Id: U-Boot discussion From: walter.lozano at collabora.com (Walter Lozano) Date: Fri, 19 Jun 2020 18:11:38 -0300 Subject: [RFC 2/4] dtoc: add initial support for deleting DTB nodes In-Reply-To: <20200619211140.5081-1-walter.lozano@collabora.com> References: <20200619211140.5081-1-walter.lozano@collabora.com> Message-ID: <20200619211140.5081-3-walter.lozano@collabora.com> This patch introduce a test for deleting DTB nodes using Python library. Signed-off-by: Walter Lozano --- 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.