Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 2 | # Copyright (c) 2016 Google, Inc |
| 3 | # |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 4 | # Base class for all entries |
| 5 | # |
| 6 | |
Simon Glass | 3073266 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 7 | from __future__ import print_function |
| 8 | |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 9 | from collections import namedtuple |
| 10 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 11 | # importlib was introduced in Python 2.7 but there was a report of it not |
| 12 | # working in 2.7.12, so we work around this: |
| 13 | # http://lists.denx.de/pipermail/u-boot/2016-October/269729.html |
| 14 | try: |
| 15 | import importlib |
| 16 | have_importlib = True |
| 17 | except: |
| 18 | have_importlib = False |
| 19 | |
Simon Glass | 691198c | 2018-06-01 09:38:15 -0600 | [diff] [blame] | 20 | import os |
| 21 | import sys |
Simon Glass | 29aa736 | 2018-09-14 04:57:19 -0600 | [diff] [blame] | 22 | |
| 23 | import fdt_util |
| 24 | import state |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 25 | import tools |
Simon Glass | b6dff4c | 2019-07-20 12:23:36 -0600 | [diff] [blame] | 26 | from tools import ToHex, ToHexSize |
Simon Glass | 233a26a9 | 2019-07-08 14:25:49 -0600 | [diff] [blame] | 27 | import tout |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 28 | |
| 29 | modules = {} |
| 30 | |
Simon Glass | 691198c | 2018-06-01 09:38:15 -0600 | [diff] [blame] | 31 | our_path = os.path.dirname(os.path.realpath(__file__)) |
| 32 | |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 33 | |
| 34 | # An argument which can be passed to entries on the command line, in lieu of |
| 35 | # device-tree properties. |
| 36 | EntryArg = namedtuple('EntryArg', ['name', 'datatype']) |
| 37 | |
Simon Glass | 6b156f8 | 2019-07-08 14:25:43 -0600 | [diff] [blame] | 38 | # Information about an entry for use when displaying summaries |
| 39 | EntryInfo = namedtuple('EntryInfo', ['indent', 'name', 'etype', 'size', |
| 40 | 'image_pos', 'uncomp_size', 'offset', |
| 41 | 'entry']) |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 42 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 43 | class Entry(object): |
Simon Glass | ad5a771 | 2018-06-01 09:38:14 -0600 | [diff] [blame] | 44 | """An Entry in the section |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 45 | |
| 46 | An entry corresponds to a single node in the device-tree description |
Simon Glass | ad5a771 | 2018-06-01 09:38:14 -0600 | [diff] [blame] | 47 | of the section. Each entry ends up being a part of the final section. |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 48 | Entries can be placed either right next to each other, or with padding |
| 49 | between them. The type of the entry determines the data that is in it. |
| 50 | |
| 51 | This class is not used by itself. All entry objects are subclasses of |
| 52 | Entry. |
| 53 | |
| 54 | Attributes: |
Simon Glass | 3a9a2b8 | 2018-07-17 13:25:28 -0600 | [diff] [blame] | 55 | section: Section object containing this entry |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 56 | node: The node that created this entry |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 57 | offset: Offset of entry within the section, None if not known yet (in |
| 58 | which case it will be calculated by Pack()) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 59 | size: Entry size in bytes, None if not known |
Simon Glass | aa2fcf9 | 2019-07-08 14:25:30 -0600 | [diff] [blame] | 60 | uncomp_size: Size of uncompressed data in bytes, if the entry is |
| 61 | compressed, else None |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 62 | contents_size: Size of contents in bytes, 0 by default |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 63 | align: Entry start offset alignment, or None |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 64 | align_size: Entry size alignment, or None |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 65 | align_end: Entry end offset alignment, or None |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 66 | pad_before: Number of pad bytes before the contents, 0 if none |
| 67 | pad_after: Number of pad bytes after the contents, 0 if none |
| 68 | data: Contents of entry (string of bytes) |
Simon Glass | aa2fcf9 | 2019-07-08 14:25:30 -0600 | [diff] [blame] | 69 | compress: Compression algoithm used (e.g. 'lz4'), 'none' if none |
Simon Glass | e61b6f6 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 70 | orig_offset: Original offset value read from node |
| 71 | orig_size: Original size value read from node |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 72 | """ |
Simon Glass | 2c360cf | 2019-07-20 12:23:45 -0600 | [diff] [blame] | 73 | def __init__(self, section, etype, node, name_prefix=''): |
Simon Glass | ad5a771 | 2018-06-01 09:38:14 -0600 | [diff] [blame] | 74 | self.section = section |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 75 | self.etype = etype |
| 76 | self._node = node |
Simon Glass | 3b78d53 | 2018-06-01 09:38:21 -0600 | [diff] [blame] | 77 | self.name = node and (name_prefix + node.name) or 'none' |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 78 | self.offset = None |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 79 | self.size = None |
Simon Glass | aa2fcf9 | 2019-07-08 14:25:30 -0600 | [diff] [blame] | 80 | self.uncomp_size = None |
Simon Glass | 5c35016 | 2018-07-17 13:25:47 -0600 | [diff] [blame] | 81 | self.data = None |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 82 | self.contents_size = 0 |
| 83 | self.align = None |
| 84 | self.align_size = None |
| 85 | self.align_end = None |
| 86 | self.pad_before = 0 |
| 87 | self.pad_after = 0 |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 88 | self.offset_unset = False |
Simon Glass | 9dcc861 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 89 | self.image_pos = None |
Simon Glass | fa79a81 | 2018-09-14 04:57:29 -0600 | [diff] [blame] | 90 | self._expand_size = False |
Simon Glass | aa2fcf9 | 2019-07-08 14:25:30 -0600 | [diff] [blame] | 91 | self.compress = 'none' |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 92 | |
| 93 | @staticmethod |
Simon Glass | 7550293 | 2019-07-08 14:25:31 -0600 | [diff] [blame] | 94 | def Lookup(node_path, etype): |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 95 | """Look up the entry class for a node. |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 96 | |
| 97 | Args: |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 98 | node_node: Path name of Node object containing information about |
| 99 | the entry to create (used for errors) |
| 100 | etype: Entry type to use |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 101 | |
| 102 | Returns: |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 103 | The entry class object if found, else None |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 104 | """ |
Simon Glass | e76a3e6 | 2018-06-01 09:38:11 -0600 | [diff] [blame] | 105 | # Convert something like 'u-boot@0' to 'u_boot' since we are only |
| 106 | # interested in the type. |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 107 | module_name = etype.replace('-', '_') |
Simon Glass | e76a3e6 | 2018-06-01 09:38:11 -0600 | [diff] [blame] | 108 | if '@' in module_name: |
| 109 | module_name = module_name.split('@')[0] |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 110 | module = modules.get(module_name) |
| 111 | |
Simon Glass | 691198c | 2018-06-01 09:38:15 -0600 | [diff] [blame] | 112 | # Also allow entry-type modules to be brought in from the etype directory. |
| 113 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 114 | # Import the module if we have not already done so. |
| 115 | if not module: |
Simon Glass | 691198c | 2018-06-01 09:38:15 -0600 | [diff] [blame] | 116 | old_path = sys.path |
| 117 | sys.path.insert(0, os.path.join(our_path, 'etype')) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 118 | try: |
| 119 | if have_importlib: |
| 120 | module = importlib.import_module(module_name) |
| 121 | else: |
| 122 | module = __import__(module_name) |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 123 | except ImportError as e: |
| 124 | raise ValueError("Unknown entry type '%s' in node '%s' (expected etype/%s.py, error '%s'" % |
| 125 | (etype, node_path, module_name, e)) |
Simon Glass | 691198c | 2018-06-01 09:38:15 -0600 | [diff] [blame] | 126 | finally: |
| 127 | sys.path = old_path |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 128 | modules[module_name] = module |
| 129 | |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 130 | # Look up the expected class name |
| 131 | return getattr(module, 'Entry_%s' % module_name) |
| 132 | |
| 133 | @staticmethod |
| 134 | def Create(section, node, etype=None): |
| 135 | """Create a new entry for a node. |
| 136 | |
| 137 | Args: |
| 138 | section: Section object containing this node |
| 139 | node: Node object containing information about the entry to |
| 140 | create |
| 141 | etype: Entry type to use, or None to work it out (used for tests) |
| 142 | |
| 143 | Returns: |
| 144 | A new Entry object of the correct type (a subclass of Entry) |
| 145 | """ |
| 146 | if not etype: |
| 147 | etype = fdt_util.GetString(node, 'type', node.name) |
Simon Glass | 7550293 | 2019-07-08 14:25:31 -0600 | [diff] [blame] | 148 | obj = Entry.Lookup(node.path, etype) |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 149 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 150 | # Call its constructor to get the object we want. |
Simon Glass | ad5a771 | 2018-06-01 09:38:14 -0600 | [diff] [blame] | 151 | return obj(section, etype, node) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 152 | |
| 153 | def ReadNode(self): |
| 154 | """Read entry information from the node |
| 155 | |
Simon Glass | 2c360cf | 2019-07-20 12:23:45 -0600 | [diff] [blame] | 156 | This must be called as the first thing after the Entry is created. |
| 157 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 158 | This reads all the fields we recognise from the node, ready for use. |
| 159 | """ |
Simon Glass | 24b9744 | 2018-07-17 13:25:51 -0600 | [diff] [blame] | 160 | if 'pos' in self._node.props: |
| 161 | self.Raise("Please use 'offset' instead of 'pos'") |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 162 | self.offset = fdt_util.GetInt(self._node, 'offset') |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 163 | self.size = fdt_util.GetInt(self._node, 'size') |
Simon Glass | e61b6f6 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 164 | self.orig_offset = self.offset |
| 165 | self.orig_size = self.size |
| 166 | |
Simon Glass | b8424fa | 2019-07-08 14:25:46 -0600 | [diff] [blame] | 167 | # These should not be set in input files, but are set in an FDT map, |
| 168 | # which is also read by this code. |
| 169 | self.image_pos = fdt_util.GetInt(self._node, 'image-pos') |
| 170 | self.uncomp_size = fdt_util.GetInt(self._node, 'uncomp-size') |
| 171 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 172 | self.align = fdt_util.GetInt(self._node, 'align') |
| 173 | if tools.NotPowerOfTwo(self.align): |
| 174 | raise ValueError("Node '%s': Alignment %s must be a power of two" % |
| 175 | (self._node.path, self.align)) |
| 176 | self.pad_before = fdt_util.GetInt(self._node, 'pad-before', 0) |
| 177 | self.pad_after = fdt_util.GetInt(self._node, 'pad-after', 0) |
| 178 | self.align_size = fdt_util.GetInt(self._node, 'align-size') |
| 179 | if tools.NotPowerOfTwo(self.align_size): |
Simon Glass | 39dd215 | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 180 | self.Raise("Alignment size %s must be a power of two" % |
| 181 | self.align_size) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 182 | self.align_end = fdt_util.GetInt(self._node, 'align-end') |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 183 | self.offset_unset = fdt_util.GetBool(self._node, 'offset-unset') |
Simon Glass | fa79a81 | 2018-09-14 04:57:29 -0600 | [diff] [blame] | 184 | self.expand_size = fdt_util.GetBool(self._node, 'expand-size') |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 185 | |
Simon Glass | 3732ec3 | 2018-09-14 04:57:18 -0600 | [diff] [blame] | 186 | def GetDefaultFilename(self): |
| 187 | return None |
| 188 | |
Simon Glass | 267112e | 2019-07-20 12:23:28 -0600 | [diff] [blame] | 189 | def GetFdts(self): |
| 190 | """Get the device trees used by this entry |
Simon Glass | 0c9d5b5 | 2018-09-14 04:57:22 -0600 | [diff] [blame] | 191 | |
| 192 | Returns: |
Simon Glass | 267112e | 2019-07-20 12:23:28 -0600 | [diff] [blame] | 193 | Empty dict, if this entry is not a .dtb, otherwise: |
| 194 | Dict: |
| 195 | key: Filename from this entry (without the path) |
Simon Glass | 684a4f1 | 2019-07-20 12:23:31 -0600 | [diff] [blame] | 196 | value: Tuple: |
| 197 | Fdt object for this dtb, or None if not available |
| 198 | Filename of file containing this dtb |
Simon Glass | 0c9d5b5 | 2018-09-14 04:57:22 -0600 | [diff] [blame] | 199 | """ |
Simon Glass | 267112e | 2019-07-20 12:23:28 -0600 | [diff] [blame] | 200 | return {} |
Simon Glass | 0c9d5b5 | 2018-09-14 04:57:22 -0600 | [diff] [blame] | 201 | |
Simon Glass | ac6328c | 2018-09-14 04:57:28 -0600 | [diff] [blame] | 202 | def ExpandEntries(self): |
| 203 | pass |
| 204 | |
Simon Glass | e22f8fa | 2018-07-06 10:27:41 -0600 | [diff] [blame] | 205 | def AddMissingProperties(self): |
| 206 | """Add new properties to the device tree as needed for this entry""" |
Simon Glass | 9dcc861 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 207 | for prop in ['offset', 'size', 'image-pos']: |
Simon Glass | e22f8fa | 2018-07-06 10:27:41 -0600 | [diff] [blame] | 208 | if not prop in self._node.props: |
Simon Glass | c8135dc | 2018-09-14 04:57:21 -0600 | [diff] [blame] | 209 | state.AddZeroProp(self._node, prop) |
Simon Glass | aa2fcf9 | 2019-07-08 14:25:30 -0600 | [diff] [blame] | 210 | if self.compress != 'none': |
| 211 | state.AddZeroProp(self._node, 'uncomp-size') |
Simon Glass | ae7cf03 | 2018-09-14 04:57:31 -0600 | [diff] [blame] | 212 | err = state.CheckAddHashProp(self._node) |
| 213 | if err: |
| 214 | self.Raise(err) |
Simon Glass | e22f8fa | 2018-07-06 10:27:41 -0600 | [diff] [blame] | 215 | |
| 216 | def SetCalculatedProperties(self): |
| 217 | """Set the value of device-tree properties calculated by binman""" |
Simon Glass | c8135dc | 2018-09-14 04:57:21 -0600 | [diff] [blame] | 218 | state.SetInt(self._node, 'offset', self.offset) |
| 219 | state.SetInt(self._node, 'size', self.size) |
Simon Glass | 39dd215 | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 220 | base = self.section.GetRootSkipAtStart() if self.section else 0 |
| 221 | state.SetInt(self._node, 'image-pos', self.image_pos - base) |
Simon Glass | aa2fcf9 | 2019-07-08 14:25:30 -0600 | [diff] [blame] | 222 | if self.uncomp_size is not None: |
| 223 | state.SetInt(self._node, 'uncomp-size', self.uncomp_size) |
Simon Glass | ae7cf03 | 2018-09-14 04:57:31 -0600 | [diff] [blame] | 224 | state.CheckSetHashValue(self._node, self.GetData) |
Simon Glass | e22f8fa | 2018-07-06 10:27:41 -0600 | [diff] [blame] | 225 | |
Simon Glass | 9230773 | 2018-07-06 10:27:40 -0600 | [diff] [blame] | 226 | def ProcessFdt(self, fdt): |
Simon Glass | e219aa4 | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 227 | """Allow entries to adjust the device tree |
| 228 | |
| 229 | Some entries need to adjust the device tree for their purposes. This |
| 230 | may involve adding or deleting properties. |
| 231 | |
| 232 | Returns: |
| 233 | True if processing is complete |
| 234 | False if processing could not be completed due to a dependency. |
| 235 | This will cause the entry to be retried after others have been |
| 236 | called |
| 237 | """ |
Simon Glass | 9230773 | 2018-07-06 10:27:40 -0600 | [diff] [blame] | 238 | return True |
| 239 | |
Simon Glass | 3b78d53 | 2018-06-01 09:38:21 -0600 | [diff] [blame] | 240 | def SetPrefix(self, prefix): |
| 241 | """Set the name prefix for a node |
| 242 | |
| 243 | Args: |
| 244 | prefix: Prefix to set, or '' to not use a prefix |
| 245 | """ |
| 246 | if prefix: |
| 247 | self.name = prefix + self.name |
| 248 | |
Simon Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 249 | def SetContents(self, data): |
| 250 | """Set the contents of an entry |
| 251 | |
| 252 | This sets both the data and content_size properties |
| 253 | |
| 254 | Args: |
Simon Glass | d17dfea | 2019-07-08 14:25:33 -0600 | [diff] [blame] | 255 | data: Data to set to the contents (bytes) |
Simon Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 256 | """ |
| 257 | self.data = data |
| 258 | self.contents_size = len(self.data) |
| 259 | |
| 260 | def ProcessContentsUpdate(self, data): |
Simon Glass | d17dfea | 2019-07-08 14:25:33 -0600 | [diff] [blame] | 261 | """Update the contents of an entry, after the size is fixed |
Simon Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 262 | |
Simon Glass | ec84985 | 2019-07-08 14:25:35 -0600 | [diff] [blame] | 263 | This checks that the new data is the same size as the old. If the size |
| 264 | has changed, this triggers a re-run of the packing algorithm. |
Simon Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 265 | |
| 266 | Args: |
Simon Glass | d17dfea | 2019-07-08 14:25:33 -0600 | [diff] [blame] | 267 | data: Data to set to the contents (bytes) |
Simon Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 268 | |
| 269 | Raises: |
| 270 | ValueError if the new data size is not the same as the old |
| 271 | """ |
Simon Glass | ec84985 | 2019-07-08 14:25:35 -0600 | [diff] [blame] | 272 | size_ok = True |
Simon Glass | e61b6f6 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 273 | new_size = len(data) |
| 274 | if state.AllowEntryExpansion(): |
| 275 | if new_size > self.contents_size: |
Simon Glass | b6dff4c | 2019-07-20 12:23:36 -0600 | [diff] [blame] | 276 | tout.Debug("Entry '%s' size change from %s to %s" % ( |
| 277 | self._node.path, ToHex(self.contents_size), |
| 278 | ToHex(new_size))) |
Simon Glass | e61b6f6 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 279 | # self.data will indicate the new size needed |
| 280 | size_ok = False |
| 281 | elif new_size != self.contents_size: |
Simon Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 282 | self.Raise('Cannot update entry size from %d to %d' % |
Simon Glass | e61b6f6 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 283 | (self.contents_size, new_size)) |
Simon Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 284 | self.SetContents(data) |
Simon Glass | ec84985 | 2019-07-08 14:25:35 -0600 | [diff] [blame] | 285 | return size_ok |
Simon Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 286 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 287 | def ObtainContents(self): |
| 288 | """Figure out the contents of an entry. |
| 289 | |
| 290 | Returns: |
| 291 | True if the contents were found, False if another call is needed |
| 292 | after the other entries are processed. |
| 293 | """ |
| 294 | # No contents by default: subclasses can implement this |
| 295 | return True |
| 296 | |
Simon Glass | e61b6f6 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 297 | def ResetForPack(self): |
| 298 | """Reset offset/size fields so that packing can be done again""" |
Simon Glass | b6dff4c | 2019-07-20 12:23:36 -0600 | [diff] [blame] | 299 | self.Detail('ResetForPack: offset %s->%s, size %s->%s' % |
| 300 | (ToHex(self.offset), ToHex(self.orig_offset), |
| 301 | ToHex(self.size), ToHex(self.orig_size))) |
Simon Glass | e61b6f6 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 302 | self.offset = self.orig_offset |
| 303 | self.size = self.orig_size |
| 304 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 305 | def Pack(self, offset): |
Simon Glass | ad5a771 | 2018-06-01 09:38:14 -0600 | [diff] [blame] | 306 | """Figure out how to pack the entry into the section |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 307 | |
| 308 | Most of the time the entries are not fully specified. There may be |
| 309 | an alignment but no size. In that case we take the size from the |
| 310 | contents of the entry. |
| 311 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 312 | If an entry has no hard-coded offset, it will be placed at @offset. |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 313 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 314 | Once this function is complete, both the offset and size of the |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 315 | entry will be know. |
| 316 | |
| 317 | Args: |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 318 | Current section offset pointer |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 319 | |
| 320 | Returns: |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 321 | New section offset pointer (after this entry) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 322 | """ |
Simon Glass | b6dff4c | 2019-07-20 12:23:36 -0600 | [diff] [blame] | 323 | self.Detail('Packing: offset=%s, size=%s, content_size=%x' % |
| 324 | (ToHex(self.offset), ToHex(self.size), |
| 325 | self.contents_size)) |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 326 | if self.offset is None: |
| 327 | if self.offset_unset: |
| 328 | self.Raise('No offset set with offset-unset: should another ' |
| 329 | 'entry provide this correct offset?') |
| 330 | self.offset = tools.Align(offset, self.align) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 331 | needed = self.pad_before + self.contents_size + self.pad_after |
| 332 | needed = tools.Align(needed, self.align_size) |
| 333 | size = self.size |
| 334 | if not size: |
| 335 | size = needed |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 336 | new_offset = self.offset + size |
| 337 | aligned_offset = tools.Align(new_offset, self.align_end) |
| 338 | if aligned_offset != new_offset: |
| 339 | size = aligned_offset - self.offset |
| 340 | new_offset = aligned_offset |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 341 | |
| 342 | if not self.size: |
| 343 | self.size = size |
| 344 | |
| 345 | if self.size < needed: |
| 346 | self.Raise("Entry contents size is %#x (%d) but entry size is " |
| 347 | "%#x (%d)" % (needed, needed, self.size, self.size)) |
| 348 | # Check that the alignment is correct. It could be wrong if the |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 349 | # and offset or size values were provided (i.e. not calculated), but |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 350 | # conflict with the provided alignment values |
| 351 | if self.size != tools.Align(self.size, self.align_size): |
| 352 | self.Raise("Size %#x (%d) does not match align-size %#x (%d)" % |
| 353 | (self.size, self.size, self.align_size, self.align_size)) |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 354 | if self.offset != tools.Align(self.offset, self.align): |
| 355 | self.Raise("Offset %#x (%d) does not match align %#x (%d)" % |
| 356 | (self.offset, self.offset, self.align, self.align)) |
Simon Glass | b6dff4c | 2019-07-20 12:23:36 -0600 | [diff] [blame] | 357 | self.Detail(' - packed: offset=%#x, size=%#x, content_size=%#x, next_offset=%x' % |
| 358 | (self.offset, self.size, self.contents_size, new_offset)) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 359 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 360 | return new_offset |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 361 | |
| 362 | def Raise(self, msg): |
| 363 | """Convenience function to raise an error referencing a node""" |
| 364 | raise ValueError("Node '%s': %s" % (self._node.path, msg)) |
| 365 | |
Simon Glass | b6dff4c | 2019-07-20 12:23:36 -0600 | [diff] [blame] | 366 | def Detail(self, msg): |
| 367 | """Convenience function to log detail referencing a node""" |
| 368 | tag = "Node '%s'" % self._node.path |
| 369 | tout.Detail('%30s: %s' % (tag, msg)) |
| 370 | |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 371 | def GetEntryArgsOrProps(self, props, required=False): |
| 372 | """Return the values of a set of properties |
| 373 | |
| 374 | Args: |
| 375 | props: List of EntryArg objects |
| 376 | |
| 377 | Raises: |
| 378 | ValueError if a property is not found |
| 379 | """ |
| 380 | values = [] |
| 381 | missing = [] |
| 382 | for prop in props: |
| 383 | python_prop = prop.name.replace('-', '_') |
| 384 | if hasattr(self, python_prop): |
| 385 | value = getattr(self, python_prop) |
| 386 | else: |
| 387 | value = None |
| 388 | if value is None: |
| 389 | value = self.GetArg(prop.name, prop.datatype) |
| 390 | if value is None and required: |
| 391 | missing.append(prop.name) |
| 392 | values.append(value) |
| 393 | if missing: |
| 394 | self.Raise('Missing required properties/entry args: %s' % |
| 395 | (', '.join(missing))) |
| 396 | return values |
| 397 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 398 | def GetPath(self): |
| 399 | """Get the path of a node |
| 400 | |
| 401 | Returns: |
| 402 | Full path of the node for this entry |
| 403 | """ |
| 404 | return self._node.path |
| 405 | |
| 406 | def GetData(self): |
Simon Glass | b6dff4c | 2019-07-20 12:23:36 -0600 | [diff] [blame] | 407 | self.Detail('GetData: size %s' % ToHexSize(self.data)) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 408 | return self.data |
| 409 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 410 | def GetOffsets(self): |
Simon Glass | 224bc66 | 2019-07-08 13:18:30 -0600 | [diff] [blame] | 411 | """Get the offsets for siblings |
| 412 | |
| 413 | Some entry types can contain information about the position or size of |
| 414 | other entries. An example of this is the Intel Flash Descriptor, which |
| 415 | knows where the Intel Management Engine section should go. |
| 416 | |
| 417 | If this entry knows about the position of other entries, it can specify |
| 418 | this by returning values here |
| 419 | |
| 420 | Returns: |
| 421 | Dict: |
| 422 | key: Entry type |
| 423 | value: List containing position and size of the given entry |
Simon Glass | ed365eb | 2019-07-08 13:18:39 -0600 | [diff] [blame] | 424 | type. Either can be None if not known |
Simon Glass | 224bc66 | 2019-07-08 13:18:30 -0600 | [diff] [blame] | 425 | """ |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 426 | return {} |
| 427 | |
Simon Glass | ed365eb | 2019-07-08 13:18:39 -0600 | [diff] [blame] | 428 | def SetOffsetSize(self, offset, size): |
| 429 | """Set the offset and/or size of an entry |
| 430 | |
| 431 | Args: |
| 432 | offset: New offset, or None to leave alone |
| 433 | size: New size, or None to leave alone |
| 434 | """ |
| 435 | if offset is not None: |
| 436 | self.offset = offset |
| 437 | if size is not None: |
| 438 | self.size = size |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 439 | |
Simon Glass | 9dcc861 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 440 | def SetImagePos(self, image_pos): |
| 441 | """Set the position in the image |
| 442 | |
| 443 | Args: |
| 444 | image_pos: Position of this entry in the image |
| 445 | """ |
| 446 | self.image_pos = image_pos + self.offset |
| 447 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 448 | def ProcessContents(self): |
Simon Glass | ec84985 | 2019-07-08 14:25:35 -0600 | [diff] [blame] | 449 | """Do any post-packing updates of entry contents |
| 450 | |
| 451 | This function should call ProcessContentsUpdate() to update the entry |
| 452 | contents, if necessary, returning its return value here. |
| 453 | |
| 454 | Args: |
| 455 | data: Data to set to the contents (bytes) |
| 456 | |
| 457 | Returns: |
| 458 | True if the new data size is OK, False if expansion is needed |
| 459 | |
| 460 | Raises: |
| 461 | ValueError if the new data size is not the same as the old and |
| 462 | state.AllowEntryExpansion() is False |
| 463 | """ |
| 464 | return True |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 465 | |
Simon Glass | 8a6f56e | 2018-06-01 09:38:13 -0600 | [diff] [blame] | 466 | def WriteSymbols(self, section): |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 467 | """Write symbol values into binary files for access at run time |
| 468 | |
| 469 | Args: |
Simon Glass | 8a6f56e | 2018-06-01 09:38:13 -0600 | [diff] [blame] | 470 | section: Section containing the entry |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 471 | """ |
| 472 | pass |
Simon Glass | a91e115 | 2018-06-01 09:38:16 -0600 | [diff] [blame] | 473 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 474 | def CheckOffset(self): |
| 475 | """Check that the entry offsets are correct |
Simon Glass | a91e115 | 2018-06-01 09:38:16 -0600 | [diff] [blame] | 476 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 477 | This is used for entries which have extra offset requirements (other |
Simon Glass | a91e115 | 2018-06-01 09:38:16 -0600 | [diff] [blame] | 478 | than having to be fully inside their section). Sub-classes can implement |
| 479 | this function and raise if there is a problem. |
| 480 | """ |
| 481 | pass |
Simon Glass | 3073266 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 482 | |
Simon Glass | 3a9a2b8 | 2018-07-17 13:25:28 -0600 | [diff] [blame] | 483 | @staticmethod |
Simon Glass | cd817d5 | 2018-09-14 04:57:36 -0600 | [diff] [blame] | 484 | def GetStr(value): |
| 485 | if value is None: |
| 486 | return '<none> ' |
| 487 | return '%08x' % value |
| 488 | |
| 489 | @staticmethod |
Simon Glass | 7eca792 | 2018-07-17 13:25:49 -0600 | [diff] [blame] | 490 | def WriteMapLine(fd, indent, name, offset, size, image_pos): |
Simon Glass | cd817d5 | 2018-09-14 04:57:36 -0600 | [diff] [blame] | 491 | print('%s %s%s %s %s' % (Entry.GetStr(image_pos), ' ' * indent, |
| 492 | Entry.GetStr(offset), Entry.GetStr(size), |
| 493 | name), file=fd) |
Simon Glass | 3a9a2b8 | 2018-07-17 13:25:28 -0600 | [diff] [blame] | 494 | |
Simon Glass | 3073266 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 495 | def WriteMap(self, fd, indent): |
| 496 | """Write a map of the entry to a .map file |
| 497 | |
| 498 | Args: |
| 499 | fd: File to write the map to |
| 500 | indent: Curent indent level of map (0=none, 1=one level, etc.) |
| 501 | """ |
Simon Glass | 7eca792 | 2018-07-17 13:25:49 -0600 | [diff] [blame] | 502 | self.WriteMapLine(fd, indent, self.name, self.offset, self.size, |
| 503 | self.image_pos) |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 504 | |
Simon Glass | 704784b | 2018-07-17 13:25:38 -0600 | [diff] [blame] | 505 | def GetEntries(self): |
| 506 | """Return a list of entries contained by this entry |
| 507 | |
| 508 | Returns: |
| 509 | List of entries, or None if none. A normal entry has no entries |
| 510 | within it so will return None |
| 511 | """ |
| 512 | return None |
| 513 | |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 514 | def GetArg(self, name, datatype=str): |
| 515 | """Get the value of an entry argument or device-tree-node property |
| 516 | |
| 517 | Some node properties can be provided as arguments to binman. First check |
| 518 | the entry arguments, and fall back to the device tree if not found |
| 519 | |
| 520 | Args: |
| 521 | name: Argument name |
| 522 | datatype: Data type (str or int) |
| 523 | |
| 524 | Returns: |
| 525 | Value of argument as a string or int, or None if no value |
| 526 | |
| 527 | Raises: |
| 528 | ValueError if the argument cannot be converted to in |
| 529 | """ |
Simon Glass | 29aa736 | 2018-09-14 04:57:19 -0600 | [diff] [blame] | 530 | value = state.GetEntryArg(name) |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 531 | if value is not None: |
| 532 | if datatype == int: |
| 533 | try: |
| 534 | value = int(value) |
| 535 | except ValueError: |
| 536 | self.Raise("Cannot convert entry arg '%s' (value '%s') to integer" % |
| 537 | (name, value)) |
| 538 | elif datatype == str: |
| 539 | pass |
| 540 | else: |
| 541 | raise ValueError("GetArg() internal error: Unknown data type '%s'" % |
| 542 | datatype) |
| 543 | else: |
| 544 | value = fdt_util.GetDatatype(self._node, name, datatype) |
| 545 | return value |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 546 | |
| 547 | @staticmethod |
| 548 | def WriteDocs(modules, test_missing=None): |
| 549 | """Write out documentation about the various entry types to stdout |
| 550 | |
| 551 | Args: |
| 552 | modules: List of modules to include |
| 553 | test_missing: Used for testing. This is a module to report |
| 554 | as missing |
| 555 | """ |
| 556 | print('''Binman Entry Documentation |
| 557 | =========================== |
| 558 | |
| 559 | This file describes the entry types supported by binman. These entry types can |
| 560 | be placed in an image one by one to build up a final firmware image. It is |
| 561 | fairly easy to create new entry types. Just add a new file to the 'etype' |
| 562 | directory. You can use the existing entries as examples. |
| 563 | |
| 564 | Note that some entries are subclasses of others, using and extending their |
| 565 | features to produce new behaviours. |
| 566 | |
| 567 | |
| 568 | ''') |
| 569 | modules = sorted(modules) |
| 570 | |
| 571 | # Don't show the test entry |
| 572 | if '_testing' in modules: |
| 573 | modules.remove('_testing') |
| 574 | missing = [] |
| 575 | for name in modules: |
Simon Glass | 0baeab7 | 2019-07-08 14:25:32 -0600 | [diff] [blame] | 576 | if name.startswith('__'): |
| 577 | continue |
Simon Glass | 7550293 | 2019-07-08 14:25:31 -0600 | [diff] [blame] | 578 | module = Entry.Lookup(name, name) |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 579 | docs = getattr(module, '__doc__') |
| 580 | if test_missing == name: |
| 581 | docs = None |
| 582 | if docs: |
| 583 | lines = docs.splitlines() |
| 584 | first_line = lines[0] |
| 585 | rest = [line[4:] for line in lines[1:]] |
| 586 | hdr = 'Entry: %s: %s' % (name.replace('_', '-'), first_line) |
| 587 | print(hdr) |
| 588 | print('-' * len(hdr)) |
| 589 | print('\n'.join(rest)) |
| 590 | print() |
| 591 | print() |
| 592 | else: |
| 593 | missing.append(name) |
| 594 | |
| 595 | if missing: |
| 596 | raise ValueError('Documentation is missing for modules: %s' % |
| 597 | ', '.join(missing)) |
Simon Glass | 639505b | 2018-09-14 04:57:11 -0600 | [diff] [blame] | 598 | |
| 599 | def GetUniqueName(self): |
| 600 | """Get a unique name for a node |
| 601 | |
| 602 | Returns: |
| 603 | String containing a unique name for a node, consisting of the name |
| 604 | of all ancestors (starting from within the 'binman' node) separated |
| 605 | by a dot ('.'). This can be useful for generating unique filesnames |
| 606 | in the output directory. |
| 607 | """ |
| 608 | name = self.name |
| 609 | node = self._node |
| 610 | while node.parent: |
| 611 | node = node.parent |
| 612 | if node.name == 'binman': |
| 613 | break |
| 614 | name = '%s.%s' % (node.name, name) |
| 615 | return name |
Simon Glass | fa79a81 | 2018-09-14 04:57:29 -0600 | [diff] [blame] | 616 | |
| 617 | def ExpandToLimit(self, limit): |
| 618 | """Expand an entry so that it ends at the given offset limit""" |
| 619 | if self.offset + self.size < limit: |
| 620 | self.size = limit - self.offset |
| 621 | # Request the contents again, since changing the size requires that |
| 622 | # the data grows. This should not fail, but check it to be sure. |
| 623 | if not self.ObtainContents(): |
| 624 | self.Raise('Cannot obtain contents when expanding entry') |
Simon Glass | c4056b8 | 2019-07-08 13:18:38 -0600 | [diff] [blame] | 625 | |
| 626 | def HasSibling(self, name): |
| 627 | """Check if there is a sibling of a given name |
| 628 | |
| 629 | Returns: |
| 630 | True if there is an entry with this name in the the same section, |
| 631 | else False |
| 632 | """ |
| 633 | return name in self.section.GetEntries() |
Simon Glass | cec34ba | 2019-07-08 14:25:28 -0600 | [diff] [blame] | 634 | |
| 635 | def GetSiblingImagePos(self, name): |
| 636 | """Return the image position of the given sibling |
| 637 | |
| 638 | Returns: |
| 639 | Image position of sibling, or None if the sibling has no position, |
| 640 | or False if there is no such sibling |
| 641 | """ |
| 642 | if not self.HasSibling(name): |
| 643 | return False |
| 644 | return self.section.GetEntries()[name].image_pos |
Simon Glass | 6b156f8 | 2019-07-08 14:25:43 -0600 | [diff] [blame] | 645 | |
| 646 | @staticmethod |
| 647 | def AddEntryInfo(entries, indent, name, etype, size, image_pos, |
| 648 | uncomp_size, offset, entry): |
| 649 | """Add a new entry to the entries list |
| 650 | |
| 651 | Args: |
| 652 | entries: List (of EntryInfo objects) to add to |
| 653 | indent: Current indent level to add to list |
| 654 | name: Entry name (string) |
| 655 | etype: Entry type (string) |
| 656 | size: Entry size in bytes (int) |
| 657 | image_pos: Position within image in bytes (int) |
| 658 | uncomp_size: Uncompressed size if the entry uses compression, else |
| 659 | None |
| 660 | offset: Entry offset within parent in bytes (int) |
| 661 | entry: Entry object |
| 662 | """ |
| 663 | entries.append(EntryInfo(indent, name, etype, size, image_pos, |
| 664 | uncomp_size, offset, entry)) |
| 665 | |
| 666 | def ListEntries(self, entries, indent): |
| 667 | """Add files in this entry to the list of entries |
| 668 | |
| 669 | This can be overridden by subclasses which need different behaviour. |
| 670 | |
| 671 | Args: |
| 672 | entries: List (of EntryInfo objects) to add to |
| 673 | indent: Current indent level to add to list |
| 674 | """ |
| 675 | self.AddEntryInfo(entries, indent, self.name, self.etype, self.size, |
| 676 | self.image_pos, self.uncomp_size, self.offset, self) |
Simon Glass | 4c613bf | 2019-07-08 14:25:50 -0600 | [diff] [blame] | 677 | |
| 678 | def ReadData(self, decomp=True): |
| 679 | """Read the data for an entry from the image |
| 680 | |
| 681 | This is used when the image has been read in and we want to extract the |
| 682 | data for a particular entry from that image. |
| 683 | |
| 684 | Args: |
| 685 | decomp: True to decompress any compressed data before returning it; |
| 686 | False to return the raw, uncompressed data |
| 687 | |
| 688 | Returns: |
| 689 | Entry data (bytes) |
| 690 | """ |
| 691 | # Use True here so that we get an uncompressed section to work from, |
| 692 | # although compressed sections are currently not supported |
| 693 | data = self.section.ReadData(True) |
| 694 | tout.Info('%s: Reading data from offset %#x-%#x, size %#x (avail %#x)' % |
| 695 | (self.GetPath(), self.offset, self.offset + self.size, |
| 696 | self.size, len(data))) |
| 697 | return data[self.offset:self.offset + self.size] |
Simon Glass | af8c45c | 2019-07-20 12:23:41 -0600 | [diff] [blame] | 698 | |
| 699 | def LoadData(self, decomp=True): |
| 700 | data = self.ReadData(decomp) |
Simon Glass | 072959a | 2019-07-20 12:23:50 -0600 | [diff] [blame^] | 701 | self.contents_size = len(data) |
Simon Glass | af8c45c | 2019-07-20 12:23:41 -0600 | [diff] [blame] | 702 | self.ProcessContentsUpdate(data) |
| 703 | self.Detail('Loaded data size %x' % len(data)) |
Simon Glass | 990b174 | 2019-07-20 12:23:46 -0600 | [diff] [blame] | 704 | |
| 705 | def GetImage(self): |
| 706 | """Get the image containing this entry |
| 707 | |
| 708 | Returns: |
| 709 | Image object containing this entry |
| 710 | """ |
| 711 | return self.section.GetImage() |
Simon Glass | 072959a | 2019-07-20 12:23:50 -0600 | [diff] [blame^] | 712 | |
| 713 | def WriteData(self, data, decomp=True): |
| 714 | """Write the data to an entry in the image |
| 715 | |
| 716 | This is used when the image has been read in and we want to replace the |
| 717 | data for a particular entry in that image. |
| 718 | |
| 719 | The image must be re-packed and written out afterwards. |
| 720 | |
| 721 | Args: |
| 722 | data: Data to replace it with |
| 723 | decomp: True to compress the data if needed, False if data is |
| 724 | already compressed so should be used as is |
| 725 | |
| 726 | Returns: |
| 727 | True if the data did not result in a resize of this entry, False if |
| 728 | the entry must be resized |
| 729 | """ |
| 730 | self.contents_size = self.size |
| 731 | ok = self.ProcessContentsUpdate(data) |
| 732 | self.Detail('WriteData: size=%x, ok=%s' % (len(data), ok)) |
| 733 | return ok |