1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2016 Google, Inc
3 # Written by Simon Glass <sjg@chromium.org>
5 # Class for an image, the output of binman
8 from __future__ import print_function
10 from collections import OrderedDict
11 from operator import attrgetter
20 """A Image, representing an output from binman
22 An image is comprised of a collection of entries each containing binary
23 data. The image size must be large enough to hold all of this data.
25 This class implements the various operations needed for images.
28 _node: Node object that contains the image definition in device tree
30 _size: Image size in bytes, or None if not known yet
31 _filename: Output filename for image
32 _sections: Sections present in this image (may be one or more)
34 def __init__(self, name, node, test=False):
38 self._filename = '%s.bin' % self._name
40 self._section = bsection.Section('main-section', self._node, True)
45 """Read properties from the image node"""
46 self._size = fdt_util.GetInt(self._node, 'size')
47 filename = fdt_util.GetString(self._node, 'filename')
49 self._filename = filename
50 self._section = bsection.Section('main-section', self._node)
52 def GetEntryContents(self):
53 """Call ObtainContents() for the section
55 self._section.GetEntryContents()
57 def GetEntryPositions(self):
58 """Handle entries that want to set the position/size of other entries
60 This calls each entry's GetPositions() method. If it returns a list
61 of entries to update, it updates them.
63 self._section.GetEntryPositions()
65 def PackEntries(self):
66 """Pack all entries into the image"""
67 self._section.PackEntries()
70 """Check that the image contents does not exceed its size, etc."""
71 self._size = self._section.CheckSize()
73 def CheckEntries(self):
74 """Check that entries do not overlap or extend outside the image"""
75 self._section.CheckEntries()
77 def ProcessEntryContents(self):
78 """Call the ProcessContents() method for each entry
80 This is intended to adjust the contents as needed by the entry type.
82 self._section.ProcessEntryContents()
84 def WriteSymbols(self):
85 """Write symbol values into binary files for access at run time"""
86 self._section.WriteSymbols()
89 """Write the image to a file"""
90 fname = tools.GetOutputFilename(self._filename)
91 with open(fname, 'wb') as fd:
92 self._section.BuildSection(fd, 0)
95 return self._section.GetEntries()