
Provide a way to specify a phandle list of nodes which are to be inserted into an existing node.
Signed-off-by: Simon Glass sjg@chromium.org ---
tools/dtoc/fdt.py | 16 ++++++++++++++++ tools/dtoc/test/dtoc_test_simple.dts | 10 ++++++++-- tools/dtoc/test_fdt.py | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index fcf229f83036..4ff55a47b6f1 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -657,6 +657,22 @@ class Node: for node in src.subnodes: dst.copy_node(node)
+ def copy_subnodes_from_phandles(self, phandle_list): + """Copy subnodes of a list of nodes into another node + + Args: + phandle_list (list of int): List of phandles of nodes to copy + + For each node in the phandle list, its subnodes and their properties are + copied recursively. Note that it does not copy the node itself, nor its + properties. + """ + for phandle in phandle_list: + parent = self.GetFdt().LookupPhandle(phandle) + tout.debug(f'adding template {parent.path} to node {self.path}') + for node in parent.subnodes: + self.copy_node(node) +
class Fdt: """Provides simple access to a flat device tree blob using libfdts. diff --git a/tools/dtoc/test/dtoc_test_simple.dts b/tools/dtoc/test/dtoc_test_simple.dts index c51f1a5908ce..f7ad445574d2 100644 --- a/tools/dtoc/test/dtoc_test_simple.dts +++ b/tools/dtoc/test/dtoc_test_simple.dts @@ -50,7 +50,7 @@ }; };
- i2c@0 { + i2c: i2c@0 { compatible = "sandbox,i2c"; bootph-all; #address-cells = <1>; @@ -63,10 +63,16 @@ }; };
- orig-node { + orig: orig-node { orig = <1 23 4>; args = "-n first", "second", "-p", "123,456", "-x"; args2 = "a space", "there"; args3 = "-n first second -p 123,456 -x"; + + copy-list = <&i2c &orig>; + + subnode { + a-prop; + }; }; }; diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index 5d9d99eb384b..6d96270d539e 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -349,6 +349,24 @@ class TestNode(unittest.TestCase):
self.dtb.Sync(auto_resize=True)
+ def test_copy_subnodes_from_phandles(self): + """Test copy_node() function""" + pmic = self.dtb.GetNode('/spl-test3/i2c@0/pmic@9') + self.assertIsNone(pmic) + + orig = self.dtb.GetNode('/orig-node') + node_list = fdt_util.GetPhandleList(orig, 'copy-list') + + dst = self.dtb.GetNode('/spl-test3') + dst.copy_subnodes_from_phandles(node_list) + + pmic = self.dtb.GetNode('/spl-test3/pmic@9') + self.assertTrue(pmic) + + subn = self.dtb.GetNode('/spl-test3/subnode') + self.assertTrue(subn) + self.assertEqual({'a-prop'}, subn.props.keys()) +
class TestProp(unittest.TestCase): """Test operation of the Prop class"""