[PATCH v2] fdt: fix phandles not copying when using templates

Anshul Dalal anshuld at ti.com
Thu Jul 9 12:24:07 CEST 2026


The phandles used inside a template were not being copied to the node
inserting the template, leading to a missing phandle error.

The following example can be used to reproduce the issue:

&binman {
  some_template: template-0 {
    ti-secure-rom {
      content = <&some_data>;
      keyfile = "some_key";
    };
    some_data: blob-ext {
      optional;
    };
  };
  output-bin {
    insert-template = <&some_template>;
  };
};

With the error 'binman: Node '/binman/output-bin/ti-secure-rom': Cannot
find node for phandle 103' observed.

Signed-off-by: Anshul Dalal <anshuld at ti.com>
---
Changes in v2:
- Add 'testTemplatePhandleCopy' binman test
- Change assignment in fdt.py from unused 'dst' to _
- Link to v1: https://patch.msgid.link/20260629-binman_template_phandle_copy_fix-v1-1-196f95a13388@ti.com
---
 tools/binman/ftest.py                           | 17 +++++++++++++++++
 tools/binman/test/fdt/template_phandle_copy.dts | 22 ++++++++++++++++++++++
 tools/dtoc/fdt.py                               |  2 +-
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index bf98b268ac15..04459aca7530 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -8552,5 +8552,22 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
         self.assertEqual(len(subnode4.props), 0,
                         "subnode shouldn't have any properties")
 
+    def testTemplatePhandleCopy(self):
+        """Test if phandles are copied properly when inserting template"""
+        _, _, _, out_dtb_fname = self._DoReadFileDtb("fdt/template_phandle_copy.dts")
+        dtb = fdt.Fdt(out_dtb_fname)
+        dtb.Scan()
+        parent = dtb.GetNode("/binman/section at 0/section at 1")
+        child = parent.FindNode("section at 2")
+        parent_phandle = child.props["parent"]
+        child_phandle = parent.props["child"]
+        self.assertEqual(
+            parent, dtb.LookupPhandle(fdt_util.fdt32_to_cpu(parent_phandle.value))
+        )
+        self.assertEqual(
+            child, dtb.LookupPhandle(fdt_util.fdt32_to_cpu(child_phandle.value))
+        )
+
+
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/test/fdt/template_phandle_copy.dts b/tools/binman/test/fdt/template_phandle_copy.dts
new file mode 100644
index 000000000000..5c6782372a48
--- /dev/null
+++ b/tools/binman/test/fdt/template_phandle_copy.dts
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman: binman {
+		some_template: template {
+			parent: section at 1 {
+				child = <&child>;
+				child: section at 2 {
+					parent = <&parent>;
+				};
+			};
+		};
+
+		section at 0 {
+			insert-template = <&some_template>;
+		};
+	};
+};
diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index 991a36b98796..cd687f2eaf2e 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -780,7 +780,7 @@ class Node:
             parent = self.GetFdt().LookupPhandle(phandle)
             tout.debug(f'adding template {parent.path} to node {self.path}')
             for node in parent.subnodes.__reversed__():
-                dst = self.copy_node(node)
+                _ = self.copy_node(node, True)
 
             tout.debug(f'merge props from {parent.path} to {self.path}')
             self.merge_props(parent, False)

---
base-commit: 63f6cc8ba618396cb9c0161bb5c6d217604ae1d0
change-id: 20260629-binman_template_phandle_copy_fix-956bc3ce48d6

Best regards,
--  
Anshul Dalal <anshuld at ti.com>



More information about the U-Boot mailing list