diff mbox series

[v5,18/20] binman: Support templates at any level

Message ID 20230718132453.626947-19-sjg@chromium.org
State Accepted
Commit 696f2b73d6ccffe23d5c295308817ca8d2bebc92
Delegated to: Simon Glass
Headers show
Series binman: Simple templating feature and mkimage conversion | expand

Commit Message

Simon Glass July 18, 2023, 1:24 p.m. UTC
Allow templates to be used inside a section, not just in the top-level
/binman node.

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

(no changes since v1)

 tools/binman/control.py                    |  5 ++-
 tools/binman/ftest.py                      |  8 ++++
 tools/binman/test/289_template_section.dts | 52 ++++++++++++++++++++++
 3 files changed, 63 insertions(+), 2 deletions(-)
 create mode 100644 tools/binman/test/289_template_section.dts

Comments

Simon Glass July 23, 2023, 1:23 p.m. UTC | #1
Allow templates to be used inside a section, not just in the top-level
/binman node.

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

(no changes since v1)

 tools/binman/control.py                    |  5 ++-
 tools/binman/ftest.py                      |  8 ++++
 tools/binman/test/289_template_section.dts | 52 ++++++++++++++++++++++
 3 files changed, 63 insertions(+), 2 deletions(-)
 create mode 100644 tools/binman/test/289_template_section.dts

Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/tools/binman/control.py b/tools/binman/control.py
index f92c152285ce..25e66814837d 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -493,8 +493,8 @@  def _ProcessTemplates(parent):
     Processing involves copying each subnode of the template node into the
     target node.
 
-    For now this is not done recursively, so templates must be at the top level
-    of the binman image.
+    This is done recursively, so templates can be at any level of the binman
+    image, e.g. inside a section.
 
     See 'Templates' in the Binman documnentation for details.
     """
@@ -502,6 +502,7 @@  def _ProcessTemplates(parent):
         tmpl = fdt_util.GetPhandleList(node, 'insert-template')
         if tmpl:
             node.copy_subnodes_from_phandles(tmpl)
+        _ProcessTemplates(node)
 
 def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt, use_expanded):
     """Prepare the images to be processed and select the device tree
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index dfca6316624c..e96223cbd892 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -6812,6 +6812,14 @@  fdt         fdtmap                Extract the devicetree blob from the fdtmap
         tools.write_file(fname, fit_data)
         out = tools.run('dumpimage', '-l', fname)
 
+    def testTemplateSection(self):
+        """Test using a template in a section (not at top level)"""
+        TestFunctional._MakeInputFile('vga2.bin', b'#' + VGA_DATA)
+        data = self._DoReadFile('289_template_section.dts')
+        first = U_BOOT_DATA + VGA_DATA + U_BOOT_DTB_DATA
+        second = U_BOOT_DATA + b'#' + VGA_DATA + U_BOOT_DTB_DATA
+        self.assertEqual(U_BOOT_IMG_DATA + first + second + first, data)
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/test/289_template_section.dts b/tools/binman/test/289_template_section.dts
new file mode 100644
index 000000000000..8a744a0cf686
--- /dev/null
+++ b/tools/binman/test/289_template_section.dts
@@ -0,0 +1,52 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		u-boot-img {
+		};
+
+		common_part: template {
+			u-boot {
+			};
+
+			intel-vga {
+				filename = "vga.bin";
+			};
+		};
+
+		first {
+			type = "section";
+			insert-template = <&common_part>;
+
+			u-boot-dtb {
+			};
+		};
+
+		section {
+			second {
+				type = "section";
+				insert-template = <&common_part>;
+
+				u-boot-dtb {
+				};
+
+				intel-vga {
+					filename = "vga2.bin";
+				};
+			};
+		};
+
+		second {
+			type = "section";
+			insert-template = <&common_part>;
+
+			u-boot-dtb {
+			};
+		};
+	};
+};