tools: binman: control.py: Delete template nodes after parsing

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>
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 1a92a99..948fcc0 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -7990,5 +7990,12 @@
         """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()