binman: Support obtaining section contents immediately
Generally the content of sections is not built until the final assembly
of the image. This is partly to avoid wasting time, since the entries
within sections may change multiple times as binman works through its
various stages. This works quite well since sections exist in a strict
hierarchy, so they can be processed in a depth-first manner.
However the 'collection' entry type does not have this luxury. If it
contains a section within its 'content' list, then it must produce the
section contents, if available. That section is typically a sibling
node, i.e. not part oc the collection's hierarchy.
Add a new 'required' argument to section.GetData() to support this. When
required is True, any referenced sections are immediately built. If this
is not possible (because one of the subentries does not have its data yet)
then an error is produced.
The test for this uses a 'collection' entry type, referencing a section as
its first member. This forces a call to _BuildSectionData() with required
set to False, at first, then True later, when the image is assembled.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index fdd4f4d..043b1b0 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -4484,5 +4484,18 @@
tools.GetBytes(0xfe, 3) + U_BOOT_DTB_DATA,
data)
+ def testCollectionSection(self):
+ """Test a collection where a section must be built first"""
+ # Sections never have their contents when GetData() is called, but when
+ # _BuildSectionData() is called with required=True, a section will force
+ # building the contents, producing an error is anything is still
+ # missing.
+ data = self._DoReadFile('199_collection_section.dts')
+ section = U_BOOT_NODTB_DATA + U_BOOT_DTB_DATA
+ self.assertEqual(section + U_BOOT_DATA + tools.GetBytes(0xff, 2) +
+ section + tools.GetBytes(0xfe, 3) + U_BOOT_DATA,
+ data)
+
+
if __name__ == "__main__":
unittest.main()