1# SPDX-License-Identifier: GPL-2.0+
2# Copyright (c) 2016 Google, Inc
3# Written by Simon Glass <sjg@chromium.org>
4#
5# Entry-type module for BSS padding for spl/u-boot-spl.bin. This padding
6# can be added after the SPL binary to ensure that anything concatenated
7# to it will appear to SPL to be at the end of BSS rather than the start.
8#
9
10import command
11import elf
12from entry import Entry
13from blob import Entry_blob
14import tools
15
16class Entry_u_boot_spl_bss_pad(Entry_blob):
17    """U-Boot SPL binary padded with a BSS region
18
19    Properties / Entry arguments:
20        None
21
22    This is similar to u_boot_spl except that padding is added after the SPL
23    binary to cover the BSS (Block Started by Symbol) region. This region holds
24    the various used by SPL. It is set to 0 by SPL when it starts up. If you
25    want to append data to the SPL image (such as a device tree file), you must
26    pad out the BSS region to avoid the data overlapping with U-Boot variables.
27    This entry is useful in that case. It automatically pads out the entry size
28    to cover both the code, data and BSS.
29
30    The ELF file 'spl/u-boot-spl' must also be available for this to work, since
31    binman uses that to look up the BSS address.
32    """
33    def __init__(self, section, etype, node):
34        Entry_blob.__init__(self, section, etype, node)
35
36    def ObtainContents(self):
37        fname = tools.GetInputFilename('spl/u-boot-spl')
38        bss_size = elf.GetSymbolAddress(fname, '__bss_size')
39        if not bss_size:
40            self.Raise('Expected __bss_size symbol in spl/u-boot-spl')
41        self.SetContents(chr(0) * bss_size)
42        return True
43