binman: Expand docs and test for alignment

Alignment does form part of the entry once the image is written out, but
within binman the entry contents does not include the padding. Add
documentation to make this clear, as well as a test.

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

View File

@ -278,9 +278,12 @@ offset:
align:
This sets the alignment of the entry. The entry offset is adjusted
so that the entry starts on an aligned boundary within the image. For
example 'align = <16>' means that the entry will start on a 16-byte
boundary. Alignment shold be a power of 2. If 'align' is not
so that the entry starts on an aligned boundary within the containing
section or image. For example 'align = <16>' means that the entry will
start on a 16-byte boundary. This may mean that padding is added before
the entry. The padding is part of the containing section but is not
included in the entry, meaning that an empty space may be created before
the entry starts. Alignment should be a power of 2. If 'align' is not
provided, no alignment is performed.
size:
@ -308,14 +311,22 @@ pad-after:
align-size:
This sets the alignment of the entry size. For example, to ensure
that the size of an entry is a multiple of 64 bytes, set this to 64.
If 'align-size' is not provided, no alignment is performed.
While this does not affect the contents of the entry within binman
itself (the padding is performed only when its parent section is
assembled), the end result is that the entry ends with the padding
bytes, so may grow. If 'align-size' is not provided, no alignment is
performed.
align-end:
This sets the alignment of the end of an entry. Some entries require
that they end on an alignment boundary, regardless of where they
start. This does not move the start of the entry, so the contents of
the entry will still start at the beginning. But there may be padding
at the end. If 'align-end' is not provided, no alignment is performed.
This sets the alignment of the end of an entry with respect to the
containing section. Some entries require that they end on an alignment
boundary, regardless of where they start. This does not move the start
of the entry, so the contents of the entry will still start at the
beginning. But there may be padding at the end. While this does not
affect the contents of the entry within binman itself (the padding is
performed only when its parent section is assembled), the end result
is that the entry ends with the padding bytes, so may grow.
If 'align-end' is not provided, no alignment is performed.
filename:
For 'blob' types this provides the filename containing the binary to

View File

@ -48,9 +48,11 @@ class Entry(object):
uncomp_size: Size of uncompressed data in bytes, if the entry is
compressed, else None
contents_size: Size of contents in bytes, 0 by default
align: Entry start offset alignment, or None
align: Entry start offset alignment relative to the start of the
containing section, or None
align_size: Entry size alignment, or None
align_end: Entry end offset alignment, or None
align_end: Entry end offset alignment relative to the start of the
containing section, or None
pad_before: Number of pad bytes before the contents when it is placed
in the containing section, 0 if none. The pad bytes become part of
the entry.

View File

@ -785,7 +785,8 @@ class TestFunctional(unittest.TestCase):
def testPackExtra(self):
"""Test that extra packing feature works as expected"""
data = self._DoReadFile('009_pack_extra.dts')
data, _, _, out_dtb_fname = self._DoReadFileDtb('009_pack_extra.dts',
update_dtb=True)
self.assertIn('image', control.images)
image = control.images['image']
@ -844,6 +845,36 @@ class TestFunctional(unittest.TestCase):
self.CheckNoGaps(entries)
self.assertEqual(128, image.size)
dtb = fdt.Fdt(out_dtb_fname)
dtb.Scan()
props = self._GetPropTree(dtb, ['size', 'offset', 'image-pos'])
expected = {
'image-pos': 0,
'offset': 0,
'size': 128,
'u-boot:image-pos': 0,
'u-boot:offset': 0,
'u-boot:size': 3 + 5 + len(U_BOOT_DATA),
'u-boot-align-size-nop:image-pos': 12,
'u-boot-align-size-nop:offset': 12,
'u-boot-align-size-nop:size': 4,
'u-boot-align-size:image-pos': 16,
'u-boot-align-size:offset': 16,
'u-boot-align-size:size': 32,
'u-boot-align-end:image-pos': 48,
'u-boot-align-end:offset': 48,
'u-boot-align-end:size': 16,
'u-boot-align-both:image-pos': 64,
'u-boot-align-both:offset': 64,
'u-boot-align-both:size': 64,
}
self.assertEqual(expected, props)
def testPackAlignPowerOf2(self):
"""Test that invalid entry alignment is detected"""
with self.assertRaises(ValueError) as e: