u_boot_spl_bss_pad.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. from binman import elf
  10. from binman.entry import Entry
  11. from binman.etype.blob import Entry_blob
  12. from patman import tools
  13. class Entry_u_boot_spl_bss_pad(Entry_blob):
  14. """U-Boot SPL binary padded with a BSS region
  15. Properties / Entry arguments:
  16. None
  17. This holds the padding added after the SPL binary to cover the BSS (Block
  18. Started by Symbol) region. This region holds the various variables used by
  19. SPL. It is set to 0 by SPL when it starts up. If you want to append data to
  20. the SPL image (such as a device tree file), you must pad out the BSS region
  21. to avoid the data overlapping with U-Boot variables. This entry is useful in
  22. that case. It automatically pads out the entry size to cover both the code,
  23. data and BSS.
  24. The contents of this entry will a certain number of zero bytes, determined
  25. by __bss_size
  26. The ELF file 'spl/u-boot-spl' must also be available for this to work, since
  27. binman uses that to look up the BSS address.
  28. """
  29. def __init__(self, section, etype, node):
  30. super().__init__(section, etype, node)
  31. def ObtainContents(self):
  32. fname = tools.GetInputFilename('spl/u-boot-spl')
  33. bss_size = elf.GetSymbolAddress(fname, '__bss_size')
  34. if not bss_size:
  35. self.Raise('Expected __bss_size symbol in spl/u-boot-spl')
  36. self.SetContents(tools.GetBytes(0, bss_size))
  37. return True