[PATCH 6/6] WIP: binman: Support templates containing phandles

Simon Glass sjg at chromium.org
Fri Jul 21 18:07:06 CEST 2023


This provides support for phandles to be copied over from templates. This
is not quite safe, since if the template is instantiated twice (i.e. in
two different nodes), then duplicate phandles will be found.

This patch is provided for some initial experimentation.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 tools/binman/control.py                    |  4 ++
 tools/binman/ftest.py                      | 15 +++++++
 tools/binman/test/291_template_phandle.dts | 51 ++++++++++++++++++++++
 tools/dtoc/fdt.py                          |  1 +
 4 files changed, 71 insertions(+)
 create mode 100644 tools/binman/test/291_template_phandle.dts

diff --git a/tools/binman/control.py b/tools/binman/control.py
index 3857f50e6436..6a6d247e6969 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -567,6 +567,10 @@ def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt, use_expanded):
 
         _RemoveTemplates(node)
         dtb.Sync(True)
+
+        # Rescan the dtb to pick up the new phandles
+        dtb.Scan()
+        node = _FindBinmanNode(dtb)
         fname = tools.get_output_filename('u-boot.dtb.tmpl2')
         tools.write_file(fname, dtb.GetContents())
 
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 7ea4797ad6ac..5f3f56e07736 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -6900,6 +6900,21 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
             # Move to next
             spl_data = content[:0x18]
 
+    def testTemplatePhandle(self):
+        """Test using a template in a node containing a phandle"""
+        entry_args = {
+            'atf-bl31-path': 'bl31.elf',
+        }
+        data = self._DoReadFileDtb('291_template_phandle.dts',
+                                   entry_args=entry_args)
+        fname = tools.get_output_filename('image.bin')
+        out = tools.run('dumpimage', '-l', fname)
+
+        # We should see the FIT description and one for each of the two images
+        lines = out.splitlines()
+        descs = [line.split()[-1] for line in lines if 'escription' in line]
+        self.assertEqual(['test-desc', 'atf', 'fdt'], descs)
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/test/291_template_phandle.dts b/tools/binman/test/291_template_phandle.dts
new file mode 100644
index 000000000000..c4ec1dd41bed
--- /dev/null
+++ b/tools/binman/test/291_template_phandle.dts
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		multiple-images;
+
+		ti_spl_template: template-1 {
+			fit {
+				description = "test-desc";
+				#address-cells = <1>;
+				images {
+					atf {
+						description = "atf";
+						ti-secure {
+							type = "collection";
+							content = <&atf>;
+							keyfile = "key.pem";
+						};
+						atf: atf-bl31 {
+							description = "atf";
+						};
+					};
+				};
+			};
+		};
+
+		image {
+			insert-template = <&ti_spl_template>;
+			fit {
+				images {
+					fdt-0 {
+						description = "fdt";
+						ti-secure {
+							type = "collection";
+							content = <&foo_dtb>;
+							keyfile = "key.pem";
+						};
+						foo_dtb: blob-ext {
+							filename = "vga.bin";
+						};
+					};
+				};
+			};
+		};
+	};
+};
diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index 917088041cc4..216c068c5fb5 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -835,6 +835,7 @@ class Fdt:
 
         TODO(sjg at chromium.org): Implement the 'root' parameter
         """
+        self.phandle_to_node = {}
         self._cached_offsets = True
         self._root = self.Node(self, None, 0, '/', '/')
         self._root.Scan()
-- 
2.41.0.487.g6d72f3e995-goog



More information about the U-Boot mailing list