]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
tools: binman: control.py: Delete template nodes after parsing
authorNeha Malcom Francis <n-francis@ti.com>
Mon, 17 Mar 2025 04:54:20 +0000 (10:24 +0530)
committerTom Rini <trini@konsulko.com>
Thu, 3 Apr 2025 17:37:45 +0000 (11:37 -0600)
Dynamically going through the subnode array and deleting leads to
templates being skipped from deletion when templates are consecutive in
the subnode list. Prevent this from happening by first parsing the DT
and then deleting the nodes. Add a testcase as well for this cornercase.

Signed-off-by: Neha Malcom Francis <n-francis@ti.com>
tools/binman/control.py
tools/binman/ftest.py
tools/binman/test/346_remove_template.dts [new file with mode: 0644]

index e73c598298cef76cfdf4f0f8a021feac1e7b825a..81f61e3e152a9eab558cfc9667131a38082b61a1 100644 (file)
@@ -522,9 +522,13 @@ def _ProcessTemplates(parent):
 def _RemoveTemplates(parent):
     """Remove any templates in the binman description
     """
+    del_nodes = []
     for node in parent.subnodes:
         if node.name.startswith('template'):
-            node.Delete()
+            del_nodes.append(node)
+
+    for node in del_nodes:
+        node.Delete()
 
 def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt, use_expanded, indir):
     """Prepare the images to be processed and select the device tree
index 1a92a99b5117cbff74a85da1b57b81e8aaa09cac..948fcc02259ae61d8f7ff8d4ec8b867c7f513bbf 100644 (file)
@@ -7990,5 +7990,12 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
         """Test an image with an FIT with multiple FDT images using NAME"""
         self.CheckFitFdt('345_fit_fdt_name.dts', use_seq_num=False)
 
+    def testRemoveTemplate(self):
+        """Test whether template is removed"""
+        TestFunctional._MakeInputFile('my-blob.bin', b'blob')
+        TestFunctional._MakeInputFile('my-blob2.bin', b'other')
+        self._DoTestFile('346_remove_template.dts',
+                         force_missing_bintools='openssl',)
+
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/test/346_remove_template.dts b/tools/binman/test/346_remove_template.dts
new file mode 100644 (file)
index 0000000..e05229f
--- /dev/null
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+/ {
+    binman: binman {
+               multiple-images;
+
+               template_1: template-1 {
+                       section {
+                               phandle1: my-blob.bin {
+                                       filename = "my-blob.bin";
+                                       type = "blob-ext";
+                               };
+                       };
+               };
+               template_2: template-2 {
+                       section {
+                               ti-secure {
+                                       content = <&phandle2>;
+                                       keyfile = "key.pem";
+                               };
+                               phandle2: my-blob.bin {
+                                       filename = "my-blob.bin";
+                                       type = "blob-ext";
+                               };
+                       };
+               };
+               template_3: template-3 {
+                       section {
+                               phandle3: my-blob.bin {
+                                       filename = "my-blob.bin";
+                                       type = "blob-ext";
+                               };
+                       };
+               };
+
+               file1 {
+                       insert-template = <&template_1>;
+               };
+
+               file2 {
+                       insert-template = <&template_2>;
+               };
+
+               file3 {
+                       insert-template = <&template_3>;
+               };
+       };
+};