section.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # SPDX-License-Identifier: GPL-2.0+
  2. # Copyright (c) 2018 Google, Inc
  3. # Written by Simon Glass <sjg@chromium.org>
  4. #
  5. # Entry-type module for sections, which are entries which can contain other
  6. # entries.
  7. #
  8. from entry import Entry
  9. import fdt_util
  10. import tools
  11. import bsection
  12. class Entry_section(Entry):
  13. """Entry that contains other entries
  14. Properties / Entry arguments: (see binman README for more information)
  15. - size: Size of section in bytes
  16. - align-size: Align size to a particular power of two
  17. - pad-before: Add padding before the entry
  18. - pad-after: Add padding after the entry
  19. - pad-byte: Pad byte to use when padding
  20. - sort-by-offset: Reorder the entries by offset
  21. - end-at-4gb: Used to build an x86 ROM which ends at 4GB (2^32)
  22. - name-prefix: Adds a prefix to the name of every entry in the section
  23. when writing out the map
  24. A section is an entry which can contain other entries, thus allowing
  25. hierarchical images to be created. See 'Sections and hierarchical images'
  26. in the binman README for more information.
  27. """
  28. def __init__(self, section, etype, node):
  29. Entry.__init__(self, section, etype, node)
  30. self._section = bsection.Section(node.name, section, node,
  31. section._image)
  32. def GetFdtSet(self):
  33. return self._section.GetFdtSet()
  34. def ProcessFdt(self, fdt):
  35. return self._section.ProcessFdt(fdt)
  36. def ExpandEntries(self):
  37. Entry.ExpandEntries(self)
  38. self._section.ExpandEntries()
  39. def AddMissingProperties(self):
  40. Entry.AddMissingProperties(self)
  41. self._section.AddMissingProperties()
  42. def ObtainContents(self):
  43. return self._section.GetEntryContents()
  44. def GetData(self):
  45. return self._section.GetData()
  46. def GetOffsets(self):
  47. """Handle entries that want to set the offset/size of other entries
  48. This calls each entry's GetOffsets() method. If it returns a list
  49. of entries to update, it updates them.
  50. """
  51. self._section.GetEntryOffsets()
  52. return {}
  53. def Pack(self, offset):
  54. """Pack all entries into the section"""
  55. self._section.PackEntries()
  56. self._section.SetOffset(offset)
  57. self.size = self._section.GetSize()
  58. return super(Entry_section, self).Pack(offset)
  59. def SetImagePos(self, image_pos):
  60. Entry.SetImagePos(self, image_pos)
  61. self._section.SetImagePos(image_pos + self.offset)
  62. def WriteSymbols(self, section):
  63. """Write symbol values into binary files for access at run time"""
  64. self._section.WriteSymbols()
  65. def SetCalculatedProperties(self):
  66. Entry.SetCalculatedProperties(self)
  67. self._section.SetCalculatedProperties()
  68. def ProcessContents(self):
  69. self._section.ProcessEntryContents()
  70. super(Entry_section, self).ProcessContents()
  71. def CheckOffset(self):
  72. self._section.CheckEntries()
  73. def WriteMap(self, fd, indent):
  74. """Write a map of the section to a .map file
  75. Args:
  76. fd: File to write the map to
  77. """
  78. self._section.WriteMap(fd, indent)
  79. def GetEntries(self):
  80. return self._section.GetEntries()
  81. def ExpandToLimit(self, limit):
  82. super(Entry_section, self).ExpandToLimit(limit)
  83. self._section.ExpandSize(self.size)