[PATCH 15/25] binman: Set section contents in GetData()

Simon Glass sjg at chromium.org
Mon Oct 19 04:41:28 CEST 2020


Section contents is not set up when ObtainContents() is called, since
packing often changes the layout of the contents. Ensure that the contents
are correctly recorded by making this function regenerate the section. It
is normally only called by the parent section (when packing) or by the
top-level image code, when writing out the image. So the performance
impact is fairly small.

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

 tools/binman/entry.py         |  6 ++++++
 tools/binman/etype/section.py | 14 +++++++++++++-
 tools/binman/ftest.py         |  2 ++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index d701eaff8fd..01a5fde84ed 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -437,6 +437,12 @@ class Entry(object):
         return self._node.path
 
     def GetData(self):
+        """Get the contents of an entry
+
+        Returns:
+            bytes content of the entry, excluding any padding. If the entry is
+                compressed, the compressed data is returned
+        """
         self.Detail('GetData: size %s' % ToHexSize(self.data))
         return self.data
 
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index c423a22c80f..6e6f6749727 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -226,7 +226,19 @@ class Entry_section(Entry):
         return section.GetPaddedDataForEntry(self)
 
     def GetData(self):
-        return self._BuildSectionData()
+        """Get the contents of an entry
+
+        This builds the contents of the section, stores this as the contents of
+        the section and returns it
+
+        Returns:
+            bytes content of the section, made up for all all of its subentries.
+            This excludes any padding. If the section is compressed, the
+            compressed data is returned
+        """
+        data = self._BuildSectionData()
+        self.SetContents(data)
+        return data
 
     def GetOffsets(self):
         """Handle entries that want to set the offset/size of other entries
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 7360e2ebaba..bcd4482717a 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -1820,6 +1820,8 @@ class TestFunctional(unittest.TestCase):
         orig = self._decompress(entry.data)
         self.assertEqual(orig, entry.uncomp_data)
 
+        self.assertEqual(image.data, entry.data)
+
         expected = {
             'blob:uncomp-size': len(COMPRESS_DATA),
             'blob:size': len(data),
-- 
2.29.0.rc1.297.gfa9743e501-goog



More information about the U-Boot mailing list