diff options
author | Simon Glass | 2021-03-21 18:24:33 +1300 |
---|---|---|
committer | Simon Glass | 2021-03-27 16:26:48 +1300 |
commit | 5ff9fedc9bc02e01d73d57e9c7d7eac9fd6320d4 (patch) | |
tree | 0fc99fe53f99d7f97011a990ddf452454ad7b15b /tools | |
parent | 631f752de5b8dccbf9a0d4824213e9e6e0d96167 (diff) |
binman: Support default alignment for sections
Sometimes it is useful to specify the default alignment for all entries
in a section, such as when word-alignment is necessary, for example. It
is tedious and error-prone to specify this individually for each section.
Add a property to control this for a section.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/binman/binman.rst | 7 | ||||
-rw-r--r-- | tools/binman/entries.rst | 2 | ||||
-rw-r--r-- | tools/binman/entry.py | 2 | ||||
-rw-r--r-- | tools/binman/etype/cbfs.py | 1 | ||||
-rw-r--r-- | tools/binman/etype/mkimage.py | 1 | ||||
-rw-r--r-- | tools/binman/etype/section.py | 3 | ||||
-rw-r--r-- | tools/binman/ftest.py | 12 | ||||
-rw-r--r-- | tools/binman/test/200_align_default.dts | 30 |
8 files changed, 58 insertions, 0 deletions
diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst index 28cb2e7a9c9..1aa2459d50c 100644 --- a/tools/binman/binman.rst +++ b/tools/binman/binman.rst @@ -562,6 +562,13 @@ skip-at-start: 'end-at-4gb' property is not applicable where CONFIG_SYS_TEXT_BASE + Image size != 4gb. +align-default: + Specifies the default alignment for entries in this section, if they do + not specify an alignment. Note that this only applies to top-level entries + in the section (direct subentries), not any subentries of those entries. + This means that each section must specify its own default alignment, if + required. + Examples of the above options can be found in the tests. See the tools/binman/test directory. diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst index d5f8d95dc19..a91211e93ed 100644 --- a/tools/binman/entries.rst +++ b/tools/binman/entries.rst @@ -796,6 +796,8 @@ Properties / Entry arguments: (see binman README for more information): file, since the first 16 bytes are skipped when writing. name-prefix: Adds a prefix to the name of every entry in the section when writing out the map + align_default: Default alignment for this section, if no alignment is + given in the entry Properties: allow_missing: True if this section permits external blobs to be diff --git a/tools/binman/entry.py b/tools/binman/entry.py index b7b9791b10d..70222718ea9 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -201,6 +201,8 @@ class Entry(object): if tools.NotPowerOfTwo(self.align): raise ValueError("Node '%s': Alignment %s must be a power of two" % (self._node.path, self.align)) + if self.section and self.align is None: + self.align = self.section.align_default self.pad_before = fdt_util.GetInt(self._node, 'pad-before', 0) self.pad_after = fdt_util.GetInt(self._node, 'pad-after', 0) self.align_size = fdt_util.GetInt(self._node, 'align-size') diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py index 1daddeb8229..44db7b9bb20 100644 --- a/tools/binman/etype/cbfs.py +++ b/tools/binman/etype/cbfs.py @@ -169,6 +169,7 @@ class Entry_cbfs(Entry): super().__init__(section, etype, node) self._cbfs_arg = fdt_util.GetString(node, 'cbfs-arch', 'x86') + self.align_default = None self._cbfs_entries = OrderedDict() self._ReadSubnodes() self.reader = None diff --git a/tools/binman/etype/mkimage.py b/tools/binman/etype/mkimage.py index e9f82729ab4..e49977522e3 100644 --- a/tools/binman/etype/mkimage.py +++ b/tools/binman/etype/mkimage.py @@ -36,6 +36,7 @@ class Entry_mkimage(Entry): super().__init__(section, etype, node) self._args = fdt_util.GetString(self._node, 'args').split(' ') self._mkimage_entries = OrderedDict() + self.align_default = None self._ReadSubnodes() def ObtainContents(self): diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index d4a097b94bf..c3bac026c14 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -36,6 +36,8 @@ class Entry_section(Entry): file, since the first 16 bytes are skipped when writing. name-prefix: Adds a prefix to the name of every entry in the section when writing out the map + align_default: Default alignment for this section, if no alignment is + given in the entry Properties: allow_missing: True if this section permits external blobs to be @@ -76,6 +78,7 @@ class Entry_section(Entry): if self._skip_at_start is None: self._skip_at_start = 0 self._name_prefix = fdt_util.GetString(self._node, 'name-prefix') + self.align_default = fdt_util.GetInt(self._node, 'align-default', 0) filename = fdt_util.GetString(self._node, 'filename') if filename: self._filename = filename diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 043b1b037c4..89fe6612e1b 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -4496,6 +4496,18 @@ class TestFunctional(unittest.TestCase): section + tools.GetBytes(0xfe, 3) + U_BOOT_DATA, data) + def testAlignDefault(self): + """Test that default alignment works on sections""" + data = self._DoReadFile('200_align_default.dts') + expected = (U_BOOT_DATA + tools.GetBytes(0, 8 - len(U_BOOT_DATA)) + + U_BOOT_DATA) + # Special alignment for section + expected += tools.GetBytes(0, 32 - len(expected)) + # No alignment within the nested section + expected += U_BOOT_DATA + U_BOOT_NODTB_DATA; + # Now the final piece, which should be default-aligned + expected += tools.GetBytes(0, 88 - len(expected)) + U_BOOT_NODTB_DATA + self.assertEqual(expected, data) if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/200_align_default.dts b/tools/binman/test/200_align_default.dts new file mode 100644 index 00000000000..1b155770d4c --- /dev/null +++ b/tools/binman/test/200_align_default.dts @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + align-default = <8>; + u-boot { + }; + + u-boot-align { + type = "u-boot"; + }; + + section { + align = <32>; + u-boot { + }; + + u-boot-nodtb { + }; + }; + + u-boot-nodtb { + }; + }; +}; |