binman: Move section padding to the parent

Each section is padded up to its size, if the contents are not large
enough. Move this logic from _BuildSectionData() to
GetPaddedDataForEntry() so that all the padding is in one place.

With this, the testDual test is working again, so enable it.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2020-10-26 17:40:13 -06:00
parent 4a655c9bd7
commit d1d3ad7d1f
2 changed files with 12 additions and 12 deletions

View File

@ -159,17 +159,23 @@ class Entry_section(Entry):
Contents of the entry along with any pad bytes before and Contents of the entry along with any pad bytes before and
after it (bytes) after it (bytes)
""" """
pad_byte = (entry._pad_byte if isinstance(entry, Entry_section)
else self._pad_byte)
data = b'' data = b''
# Handle padding before the entry # Handle padding before the entry
if entry.pad_before: if entry.pad_before:
data += tools.GetBytes(self._pad_byte, entry.pad_before) data += tools.GetBytes(pad_byte, entry.pad_before)
# Add in the actual entry data # Add in the actual entry data
data += entry.GetData() data += entry.GetData()
# Handle padding after the entry # Handle padding after the entry
if entry.pad_after: if entry.pad_after:
data += tools.GetBytes(self._pad_byte, entry.pad_after) data += tools.GetBytes(pad_byte, entry.pad_after)
if entry.size:
data += tools.GetBytes(pad_byte, entry.size - len(data))
self.Detail('GetPaddedDataForEntry: size %s' % ToHexSize(self.data)) self.Detail('GetPaddedDataForEntry: size %s' % ToHexSize(self.data))
@ -198,9 +204,6 @@ class Entry_section(Entry):
# Add in the actual entry data # Add in the actual entry data
section_data += data section_data += data
if self.size:
section_data += tools.GetBytes(self._pad_byte,
self.size - len(section_data))
self.Detail('GetData: %d entries, total size %#x' % self.Detail('GetData: %d entries, total size %#x' %
(len(self._entries), len(section_data))) (len(self._entries), len(section_data)))
return self.CompressData(section_data) return self.CompressData(section_data)
@ -219,9 +222,8 @@ class Entry_section(Entry):
Contents of the section along with any pad bytes before and Contents of the section along with any pad bytes before and
after it (bytes) after it (bytes)
""" """
if self.section: section = self.section or self
return super().GetPaddedData() return section.GetPaddedDataForEntry(self)
return self.GetData()
def GetData(self): def GetData(self):
return self._BuildSectionData() return self._BuildSectionData()

View File

@ -708,7 +708,6 @@ class TestFunctional(unittest.TestCase):
"""Test a simple binman run with debugging enabled""" """Test a simple binman run with debugging enabled"""
self._DoTestFile('005_simple.dts', debug=True) self._DoTestFile('005_simple.dts', debug=True)
@unittest.skip('Disable for now until padding of images is supported')
def testDual(self): def testDual(self):
"""Test that we can handle creating two images """Test that we can handle creating two images
@ -3872,9 +3871,7 @@ class TestFunctional(unittest.TestCase):
before = tools.GetBytes(0, 8) before = tools.GetBytes(0, 8)
after = tools.GetBytes(0, 4) after = tools.GetBytes(0, 4)
all = before + U_BOOT_DATA + after all = before + U_BOOT_DATA + after
self.assertEqual(all, data)
# This is not correct, but it is what binman currently produces
self.assertEqual(before + U_BOOT_DATA + tools.GetBytes(0, 16), data)
image = control.images['image'] image = control.images['image']
entries = image.GetEntries() entries = image.GetEntries()
@ -3882,6 +3879,7 @@ class TestFunctional(unittest.TestCase):
self.assertEqual(0, section.offset) self.assertEqual(0, section.offset)
self.assertEqual(len(all), section.size) self.assertEqual(len(all), section.size)
self.assertIsNone(section.data) self.assertIsNone(section.data)
self.assertEqual(all, section.GetPaddedData())
entry = section.GetEntries()['u-boot'] entry = section.GetEntries()['u-boot']
self.assertEqual(16, entry.offset) self.assertEqual(16, entry.offset)