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 | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 7 | from collections import namedtuple |
Simon Glass | 7ccca83 | 2019-10-31 07:42:59 -0600 | [diff] [blame] | 8 | import importlib |
Simon Glass | 691198c | 2018-06-01 09:38:15 -0600 | [diff] [blame] | 9 | import os |
Simon Glass | 7a602fd | 2022-01-12 13:10:36 -0700 | [diff] [blame] | 10 | import pathlib |
Simon Glass | 691198c | 2018-06-01 09:38:15 -0600 | [diff] [blame] | 11 | import sys |
Simon Glass | 29aa736 | 2018-09-14 04:57:19 -0600 | [diff] [blame] | 12 | |
Simon Glass | 4eae925 | 2022-01-09 20:13:50 -0700 | [diff] [blame] | 13 | from binman import bintool |
Simon Glass | 3ac7d83 | 2022-01-09 20:14:03 -0700 | [diff] [blame] | 14 | from binman import comp_util |
Simon Glass | c585dd4 | 2020-04-17 18:09:03 -0600 | [diff] [blame] | 15 | from dtoc import fdt_util |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 16 | from patman import tools |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 17 | from patman.tools import to_hex, to_hex_size |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 18 | from patman import tout |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 19 | |
| 20 | modules = {} |
| 21 | |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 22 | |
| 23 | # An argument which can be passed to entries on the command line, in lieu of |
| 24 | # device-tree properties. |
| 25 | EntryArg = namedtuple('EntryArg', ['name', 'datatype']) |
| 26 | |
Simon Glass | 6b156f8 | 2019-07-08 14:25:43 -0600 | [diff] [blame] | 27 | # Information about an entry for use when displaying summaries |
| 28 | EntryInfo = namedtuple('EntryInfo', ['indent', 'name', 'etype', 'size', |
| 29 | 'image_pos', 'uncomp_size', 'offset', |
| 30 | 'entry']) |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 31 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 32 | class Entry(object): |
Simon Glass | ad5a771 | 2018-06-01 09:38:14 -0600 | [diff] [blame] | 33 | """An Entry in the section |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 34 | |
| 35 | An entry corresponds to a single node in the device-tree description |
Simon Glass | ad5a771 | 2018-06-01 09:38:14 -0600 | [diff] [blame] | 36 | 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] | 37 | Entries can be placed either right next to each other, or with padding |
| 38 | between them. The type of the entry determines the data that is in it. |
| 39 | |
| 40 | This class is not used by itself. All entry objects are subclasses of |
| 41 | Entry. |
| 42 | |
| 43 | Attributes: |
Simon Glass | 3a9a2b8 | 2018-07-17 13:25:28 -0600 | [diff] [blame] | 44 | section: Section object containing this entry |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 45 | node: The node that created this entry |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 46 | offset: Offset of entry within the section, None if not known yet (in |
| 47 | which case it will be calculated by Pack()) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 48 | size: Entry size in bytes, None if not known |
Simon Glass | 1fdb487 | 2019-10-31 07:43:02 -0600 | [diff] [blame] | 49 | pre_reset_size: size as it was before ResetForPack(). This allows us to |
| 50 | keep track of the size we started with and detect size changes |
Simon Glass | aa2fcf9 | 2019-07-08 14:25:30 -0600 | [diff] [blame] | 51 | uncomp_size: Size of uncompressed data in bytes, if the entry is |
| 52 | compressed, else None |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 53 | contents_size: Size of contents in bytes, 0 by default |
Simon Glass | afb9caa | 2020-10-26 17:40:10 -0600 | [diff] [blame] | 54 | align: Entry start offset alignment relative to the start of the |
| 55 | containing section, or None |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 56 | align_size: Entry size alignment, or None |
Simon Glass | afb9caa | 2020-10-26 17:40:10 -0600 | [diff] [blame] | 57 | align_end: Entry end offset alignment relative to the start of the |
| 58 | containing section, or None |
Simon Glass | d12599d | 2020-10-26 17:40:09 -0600 | [diff] [blame] | 59 | pad_before: Number of pad bytes before the contents when it is placed |
| 60 | in the containing section, 0 if none. The pad bytes become part of |
| 61 | the entry. |
| 62 | pad_after: Number of pad bytes after the contents when it is placed in |
| 63 | the containing section, 0 if none. The pad bytes become part of |
| 64 | the entry. |
| 65 | data: Contents of entry (string of bytes). This does not include |
Simon Glass | 789b3440 | 2020-10-26 17:40:15 -0600 | [diff] [blame] | 66 | padding created by pad_before or pad_after. If the entry is |
| 67 | compressed, this contains the compressed data. |
| 68 | uncomp_data: Original uncompressed data, if this entry is compressed, |
| 69 | else None |
Simon Glass | aa2fcf9 | 2019-07-08 14:25:30 -0600 | [diff] [blame] | 70 | compress: Compression algoithm used (e.g. 'lz4'), 'none' if none |
Simon Glass | e61b6f6 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 71 | orig_offset: Original offset value read from node |
| 72 | orig_size: Original size value read from node |
Simon Glass | b8f9037 | 2020-09-01 05:13:57 -0600 | [diff] [blame] | 73 | missing: True if this entry is missing its contents |
| 74 | allow_missing: Allow children of this entry to be missing (used by |
| 75 | subclasses such as Entry_section) |
Heiko Thiery | 6d45136 | 2022-01-06 11:49:41 +0100 | [diff] [blame] | 76 | allow_fake: Allow creating a dummy fake file if the blob file is not |
| 77 | available. This is mainly used for testing. |
Simon Glass | b8f9037 | 2020-09-01 05:13:57 -0600 | [diff] [blame] | 78 | external: True if this entry contains an external binary blob |
Simon Glass | 4eae925 | 2022-01-09 20:13:50 -0700 | [diff] [blame] | 79 | bintools: Bintools used by this entry (only populated for Image) |
Simon Glass | 66152ce | 2022-01-09 20:14:09 -0700 | [diff] [blame] | 80 | missing_bintools: List of missing bintools for this entry |
Alper Nebi Yasak | 1e4ffd8 | 2022-02-09 22:02:35 +0300 | [diff] [blame^] | 81 | update_hash: True if this entry's "hash" subnode should be |
| 82 | updated with a hash of the entry contents |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 83 | """ |
Simon Glass | 2c360cf | 2019-07-20 12:23:45 -0600 | [diff] [blame] | 84 | def __init__(self, section, etype, node, name_prefix=''): |
Simon Glass | b9ba4e0 | 2019-08-24 07:22:44 -0600 | [diff] [blame] | 85 | # Put this here to allow entry-docs and help to work without libfdt |
| 86 | global state |
Simon Glass | c585dd4 | 2020-04-17 18:09:03 -0600 | [diff] [blame] | 87 | from binman import state |
Simon Glass | b9ba4e0 | 2019-08-24 07:22:44 -0600 | [diff] [blame] | 88 | |
Simon Glass | ad5a771 | 2018-06-01 09:38:14 -0600 | [diff] [blame] | 89 | self.section = section |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 90 | self.etype = etype |
| 91 | self._node = node |
Simon Glass | 3b78d53 | 2018-06-01 09:38:21 -0600 | [diff] [blame] | 92 | self.name = node and (name_prefix + node.name) or 'none' |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 93 | self.offset = None |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 94 | self.size = None |
Simon Glass | 1fdb487 | 2019-10-31 07:43:02 -0600 | [diff] [blame] | 95 | self.pre_reset_size = None |
Simon Glass | aa2fcf9 | 2019-07-08 14:25:30 -0600 | [diff] [blame] | 96 | self.uncomp_size = None |
Simon Glass | 5c35016 | 2018-07-17 13:25:47 -0600 | [diff] [blame] | 97 | self.data = None |
Simon Glass | 789b3440 | 2020-10-26 17:40:15 -0600 | [diff] [blame] | 98 | self.uncomp_data = None |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 99 | self.contents_size = 0 |
| 100 | self.align = None |
| 101 | self.align_size = None |
| 102 | self.align_end = None |
| 103 | self.pad_before = 0 |
| 104 | self.pad_after = 0 |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 105 | self.offset_unset = False |
Simon Glass | 9dcc861 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 106 | self.image_pos = None |
Simon Glass | 9ed7170 | 2021-11-23 11:03:43 -0700 | [diff] [blame] | 107 | self.expand_size = False |
Simon Glass | aa2fcf9 | 2019-07-08 14:25:30 -0600 | [diff] [blame] | 108 | self.compress = 'none' |
Simon Glass | a003cd3 | 2020-07-09 18:39:40 -0600 | [diff] [blame] | 109 | self.missing = False |
Heiko Thiery | 6d45136 | 2022-01-06 11:49:41 +0100 | [diff] [blame] | 110 | self.faked = False |
Simon Glass | b8f9037 | 2020-09-01 05:13:57 -0600 | [diff] [blame] | 111 | self.external = False |
| 112 | self.allow_missing = False |
Heiko Thiery | 6d45136 | 2022-01-06 11:49:41 +0100 | [diff] [blame] | 113 | self.allow_fake = False |
Simon Glass | 4eae925 | 2022-01-09 20:13:50 -0700 | [diff] [blame] | 114 | self.bintools = {} |
Simon Glass | 66152ce | 2022-01-09 20:14:09 -0700 | [diff] [blame] | 115 | self.missing_bintools = [] |
Alper Nebi Yasak | 1e4ffd8 | 2022-02-09 22:02:35 +0300 | [diff] [blame^] | 116 | self.update_hash = True |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 117 | |
| 118 | @staticmethod |
Simon Glass | b9028bc | 2021-11-23 21:09:49 -0700 | [diff] [blame] | 119 | def FindEntryClass(etype, expanded): |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 120 | """Look up the entry class for a node. |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 121 | |
| 122 | Args: |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 123 | node_node: Path name of Node object containing information about |
| 124 | the entry to create (used for errors) |
| 125 | etype: Entry type to use |
Simon Glass | 2f85941 | 2021-03-18 20:25:04 +1300 | [diff] [blame] | 126 | expanded: Use the expanded version of etype |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 127 | |
| 128 | Returns: |
Simon Glass | 2f85941 | 2021-03-18 20:25:04 +1300 | [diff] [blame] | 129 | The entry class object if found, else None if not found and expanded |
Simon Glass | b9028bc | 2021-11-23 21:09:49 -0700 | [diff] [blame] | 130 | is True, else a tuple: |
| 131 | module name that could not be found |
| 132 | exception received |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 133 | """ |
Simon Glass | e76a3e6 | 2018-06-01 09:38:11 -0600 | [diff] [blame] | 134 | # Convert something like 'u-boot@0' to 'u_boot' since we are only |
| 135 | # interested in the type. |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 136 | module_name = etype.replace('-', '_') |
Simon Glass | 2f85941 | 2021-03-18 20:25:04 +1300 | [diff] [blame] | 137 | |
Simon Glass | e76a3e6 | 2018-06-01 09:38:11 -0600 | [diff] [blame] | 138 | if '@' in module_name: |
| 139 | module_name = module_name.split('@')[0] |
Simon Glass | 2f85941 | 2021-03-18 20:25:04 +1300 | [diff] [blame] | 140 | if expanded: |
| 141 | module_name += '_expanded' |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 142 | module = modules.get(module_name) |
| 143 | |
Simon Glass | 691198c | 2018-06-01 09:38:15 -0600 | [diff] [blame] | 144 | # Also allow entry-type modules to be brought in from the etype directory. |
| 145 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 146 | # Import the module if we have not already done so. |
| 147 | if not module: |
| 148 | try: |
Simon Glass | c585dd4 | 2020-04-17 18:09:03 -0600 | [diff] [blame] | 149 | module = importlib.import_module('binman.etype.' + module_name) |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 150 | except ImportError as e: |
Simon Glass | 2f85941 | 2021-03-18 20:25:04 +1300 | [diff] [blame] | 151 | if expanded: |
| 152 | return None |
Simon Glass | b9028bc | 2021-11-23 21:09:49 -0700 | [diff] [blame] | 153 | return module_name, e |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 154 | modules[module_name] = module |
| 155 | |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 156 | # Look up the expected class name |
| 157 | return getattr(module, 'Entry_%s' % module_name) |
| 158 | |
| 159 | @staticmethod |
Simon Glass | b9028bc | 2021-11-23 21:09:49 -0700 | [diff] [blame] | 160 | def Lookup(node_path, etype, expanded, missing_etype=False): |
| 161 | """Look up the entry class for a node. |
| 162 | |
| 163 | Args: |
| 164 | node_node (str): Path name of Node object containing information |
| 165 | about the entry to create (used for errors) |
| 166 | etype (str): Entry type to use |
| 167 | expanded (bool): Use the expanded version of etype |
| 168 | missing_etype (bool): True to default to a blob etype if the |
| 169 | requested etype is not found |
| 170 | |
| 171 | Returns: |
| 172 | The entry class object if found, else None if not found and expanded |
| 173 | is True |
| 174 | |
| 175 | Raise: |
| 176 | ValueError if expanded is False and the class is not found |
| 177 | """ |
| 178 | # Convert something like 'u-boot@0' to 'u_boot' since we are only |
| 179 | # interested in the type. |
| 180 | cls = Entry.FindEntryClass(etype, expanded) |
| 181 | if cls is None: |
| 182 | return None |
| 183 | elif isinstance(cls, tuple): |
| 184 | if missing_etype: |
| 185 | cls = Entry.FindEntryClass('blob', False) |
| 186 | if isinstance(cls, tuple): # This should not fail |
| 187 | module_name, e = cls |
| 188 | raise ValueError( |
| 189 | "Unknown entry type '%s' in node '%s' (expected etype/%s.py, error '%s'" % |
| 190 | (etype, node_path, module_name, e)) |
| 191 | return cls |
| 192 | |
| 193 | @staticmethod |
| 194 | def Create(section, node, etype=None, expanded=False, missing_etype=False): |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 195 | """Create a new entry for a node. |
| 196 | |
| 197 | Args: |
Simon Glass | b9028bc | 2021-11-23 21:09:49 -0700 | [diff] [blame] | 198 | section (entry_Section): Section object containing this node |
| 199 | node (Node): Node object containing information about the entry to |
| 200 | create |
| 201 | etype (str): Entry type to use, or None to work it out (used for |
| 202 | tests) |
| 203 | expanded (bool): Use the expanded version of etype |
| 204 | missing_etype (bool): True to default to a blob etype if the |
| 205 | requested etype is not found |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 206 | |
| 207 | Returns: |
| 208 | A new Entry object of the correct type (a subclass of Entry) |
| 209 | """ |
| 210 | if not etype: |
| 211 | etype = fdt_util.GetString(node, 'type', node.name) |
Simon Glass | b9028bc | 2021-11-23 21:09:49 -0700 | [diff] [blame] | 212 | obj = Entry.Lookup(node.path, etype, expanded, missing_etype) |
Simon Glass | 2f85941 | 2021-03-18 20:25:04 +1300 | [diff] [blame] | 213 | if obj and expanded: |
| 214 | # Check whether to use the expanded entry |
| 215 | new_etype = etype + '-expanded' |
Simon Glass | 7098b7f | 2021-03-21 18:24:30 +1300 | [diff] [blame] | 216 | can_expand = not fdt_util.GetBool(node, 'no-expanded') |
| 217 | if can_expand and obj.UseExpanded(node, etype, new_etype): |
Simon Glass | 2f85941 | 2021-03-18 20:25:04 +1300 | [diff] [blame] | 218 | etype = new_etype |
| 219 | else: |
| 220 | obj = None |
| 221 | if not obj: |
Simon Glass | b9028bc | 2021-11-23 21:09:49 -0700 | [diff] [blame] | 222 | obj = Entry.Lookup(node.path, etype, False, missing_etype) |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 223 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 224 | # Call its constructor to get the object we want. |
Simon Glass | ad5a771 | 2018-06-01 09:38:14 -0600 | [diff] [blame] | 225 | return obj(section, etype, node) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 226 | |
| 227 | def ReadNode(self): |
| 228 | """Read entry information from the node |
| 229 | |
Simon Glass | 2c360cf | 2019-07-20 12:23:45 -0600 | [diff] [blame] | 230 | This must be called as the first thing after the Entry is created. |
| 231 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 232 | This reads all the fields we recognise from the node, ready for use. |
| 233 | """ |
Simon Glass | 24b9744 | 2018-07-17 13:25:51 -0600 | [diff] [blame] | 234 | if 'pos' in self._node.props: |
| 235 | self.Raise("Please use 'offset' instead of 'pos'") |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 236 | self.offset = fdt_util.GetInt(self._node, 'offset') |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 237 | self.size = fdt_util.GetInt(self._node, 'size') |
Simon Glass | fb30e29 | 2019-07-20 12:23:51 -0600 | [diff] [blame] | 238 | self.orig_offset = fdt_util.GetInt(self._node, 'orig-offset') |
| 239 | self.orig_size = fdt_util.GetInt(self._node, 'orig-size') |
| 240 | if self.GetImage().copy_to_orig: |
| 241 | self.orig_offset = self.offset |
| 242 | self.orig_size = self.size |
Simon Glass | e61b6f6 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 243 | |
Simon Glass | b8424fa | 2019-07-08 14:25:46 -0600 | [diff] [blame] | 244 | # These should not be set in input files, but are set in an FDT map, |
| 245 | # which is also read by this code. |
| 246 | self.image_pos = fdt_util.GetInt(self._node, 'image-pos') |
| 247 | self.uncomp_size = fdt_util.GetInt(self._node, 'uncomp-size') |
| 248 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 249 | self.align = fdt_util.GetInt(self._node, 'align') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 250 | if tools.not_power_of_two(self.align): |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 251 | raise ValueError("Node '%s': Alignment %s must be a power of two" % |
| 252 | (self._node.path, self.align)) |
Simon Glass | f427c5f | 2021-03-21 18:24:33 +1300 | [diff] [blame] | 253 | if self.section and self.align is None: |
| 254 | self.align = self.section.align_default |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 255 | self.pad_before = fdt_util.GetInt(self._node, 'pad-before', 0) |
| 256 | self.pad_after = fdt_util.GetInt(self._node, 'pad-after', 0) |
| 257 | self.align_size = fdt_util.GetInt(self._node, 'align-size') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 258 | if tools.not_power_of_two(self.align_size): |
Simon Glass | 39dd215 | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 259 | self.Raise("Alignment size %s must be a power of two" % |
| 260 | self.align_size) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 261 | self.align_end = fdt_util.GetInt(self._node, 'align-end') |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 262 | self.offset_unset = fdt_util.GetBool(self._node, 'offset-unset') |
Simon Glass | fa79a81 | 2018-09-14 04:57:29 -0600 | [diff] [blame] | 263 | self.expand_size = fdt_util.GetBool(self._node, 'expand-size') |
Simon Glass | a820af7 | 2020-09-06 10:39:09 -0600 | [diff] [blame] | 264 | self.missing_msg = fdt_util.GetString(self._node, 'missing-msg') |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 265 | |
Simon Glass | a1301a2 | 2020-10-26 17:40:06 -0600 | [diff] [blame] | 266 | # This is only supported by blobs and sections at present |
| 267 | self.compress = fdt_util.GetString(self._node, 'compress', 'none') |
| 268 | |
Simon Glass | 3732ec3 | 2018-09-14 04:57:18 -0600 | [diff] [blame] | 269 | def GetDefaultFilename(self): |
| 270 | return None |
| 271 | |
Simon Glass | 267112e | 2019-07-20 12:23:28 -0600 | [diff] [blame] | 272 | def GetFdts(self): |
| 273 | """Get the device trees used by this entry |
Simon Glass | 0c9d5b5 | 2018-09-14 04:57:22 -0600 | [diff] [blame] | 274 | |
| 275 | Returns: |
Simon Glass | 267112e | 2019-07-20 12:23:28 -0600 | [diff] [blame] | 276 | Empty dict, if this entry is not a .dtb, otherwise: |
| 277 | Dict: |
| 278 | key: Filename from this entry (without the path) |
Simon Glass | 684a4f1 | 2019-07-20 12:23:31 -0600 | [diff] [blame] | 279 | value: Tuple: |
Simon Glass | 8235dd8 | 2021-03-18 20:25:02 +1300 | [diff] [blame] | 280 | Entry object for this dtb |
Simon Glass | 684a4f1 | 2019-07-20 12:23:31 -0600 | [diff] [blame] | 281 | Filename of file containing this dtb |
Simon Glass | 0c9d5b5 | 2018-09-14 04:57:22 -0600 | [diff] [blame] | 282 | """ |
Simon Glass | 267112e | 2019-07-20 12:23:28 -0600 | [diff] [blame] | 283 | return {} |
Simon Glass | 0c9d5b5 | 2018-09-14 04:57:22 -0600 | [diff] [blame] | 284 | |
Simon Glass | ac6328c | 2018-09-14 04:57:28 -0600 | [diff] [blame] | 285 | def ExpandEntries(self): |
Simon Glass | fcb2a7c | 2021-03-18 20:24:52 +1300 | [diff] [blame] | 286 | """Expand out entries which produce other entries |
| 287 | |
| 288 | Some entries generate subnodes automatically, from which sub-entries |
| 289 | are then created. This method allows those to be added to the binman |
| 290 | definition for the current image. An entry which implements this method |
| 291 | should call state.AddSubnode() to add a subnode and can add properties |
| 292 | with state.AddString(), etc. |
| 293 | |
| 294 | An example is 'files', which produces a section containing a list of |
| 295 | files. |
| 296 | """ |
Simon Glass | ac6328c | 2018-09-14 04:57:28 -0600 | [diff] [blame] | 297 | pass |
| 298 | |
Simon Glass | acd6c6e | 2020-10-26 17:40:17 -0600 | [diff] [blame] | 299 | def AddMissingProperties(self, have_image_pos): |
| 300 | """Add new properties to the device tree as needed for this entry |
| 301 | |
| 302 | Args: |
| 303 | have_image_pos: True if this entry has an image position. This can |
| 304 | be False if its parent section is compressed, since compression |
| 305 | groups all entries together into a compressed block of data, |
| 306 | obscuring the start of each individual child entry |
| 307 | """ |
| 308 | for prop in ['offset', 'size']: |
Simon Glass | e22f8fa | 2018-07-06 10:27:41 -0600 | [diff] [blame] | 309 | if not prop in self._node.props: |
Simon Glass | c8135dc | 2018-09-14 04:57:21 -0600 | [diff] [blame] | 310 | state.AddZeroProp(self._node, prop) |
Simon Glass | acd6c6e | 2020-10-26 17:40:17 -0600 | [diff] [blame] | 311 | if have_image_pos and 'image-pos' not in self._node.props: |
| 312 | state.AddZeroProp(self._node, 'image-pos') |
Simon Glass | fb30e29 | 2019-07-20 12:23:51 -0600 | [diff] [blame] | 313 | if self.GetImage().allow_repack: |
| 314 | if self.orig_offset is not None: |
| 315 | state.AddZeroProp(self._node, 'orig-offset', True) |
| 316 | if self.orig_size is not None: |
| 317 | state.AddZeroProp(self._node, 'orig-size', True) |
| 318 | |
Simon Glass | aa2fcf9 | 2019-07-08 14:25:30 -0600 | [diff] [blame] | 319 | if self.compress != 'none': |
| 320 | state.AddZeroProp(self._node, 'uncomp-size') |
Alper Nebi Yasak | 1e4ffd8 | 2022-02-09 22:02:35 +0300 | [diff] [blame^] | 321 | |
| 322 | if self.update_hash: |
| 323 | err = state.CheckAddHashProp(self._node) |
| 324 | if err: |
| 325 | self.Raise(err) |
Simon Glass | e22f8fa | 2018-07-06 10:27:41 -0600 | [diff] [blame] | 326 | |
| 327 | def SetCalculatedProperties(self): |
| 328 | """Set the value of device-tree properties calculated by binman""" |
Simon Glass | c8135dc | 2018-09-14 04:57:21 -0600 | [diff] [blame] | 329 | state.SetInt(self._node, 'offset', self.offset) |
| 330 | state.SetInt(self._node, 'size', self.size) |
Simon Glass | 39dd215 | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 331 | base = self.section.GetRootSkipAtStart() if self.section else 0 |
Simon Glass | acd6c6e | 2020-10-26 17:40:17 -0600 | [diff] [blame] | 332 | if self.image_pos is not None: |
Simon Glass | eb943b1 | 2020-11-02 12:55:44 -0700 | [diff] [blame] | 333 | state.SetInt(self._node, 'image-pos', self.image_pos - base) |
Simon Glass | fb30e29 | 2019-07-20 12:23:51 -0600 | [diff] [blame] | 334 | if self.GetImage().allow_repack: |
| 335 | if self.orig_offset is not None: |
| 336 | state.SetInt(self._node, 'orig-offset', self.orig_offset, True) |
| 337 | if self.orig_size is not None: |
| 338 | state.SetInt(self._node, 'orig-size', self.orig_size, True) |
Simon Glass | aa2fcf9 | 2019-07-08 14:25:30 -0600 | [diff] [blame] | 339 | if self.uncomp_size is not None: |
| 340 | state.SetInt(self._node, 'uncomp-size', self.uncomp_size) |
Alper Nebi Yasak | 1e4ffd8 | 2022-02-09 22:02:35 +0300 | [diff] [blame^] | 341 | |
| 342 | if self.update_hash: |
| 343 | state.CheckSetHashValue(self._node, self.GetData) |
Simon Glass | e22f8fa | 2018-07-06 10:27:41 -0600 | [diff] [blame] | 344 | |
Simon Glass | 9230773 | 2018-07-06 10:27:40 -0600 | [diff] [blame] | 345 | def ProcessFdt(self, fdt): |
Simon Glass | e219aa4 | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 346 | """Allow entries to adjust the device tree |
| 347 | |
| 348 | Some entries need to adjust the device tree for their purposes. This |
| 349 | may involve adding or deleting properties. |
| 350 | |
| 351 | Returns: |
| 352 | True if processing is complete |
| 353 | False if processing could not be completed due to a dependency. |
| 354 | This will cause the entry to be retried after others have been |
| 355 | called |
| 356 | """ |
Simon Glass | 9230773 | 2018-07-06 10:27:40 -0600 | [diff] [blame] | 357 | return True |
| 358 | |
Simon Glass | 3b78d53 | 2018-06-01 09:38:21 -0600 | [diff] [blame] | 359 | def SetPrefix(self, prefix): |
| 360 | """Set the name prefix for a node |
| 361 | |
| 362 | Args: |
| 363 | prefix: Prefix to set, or '' to not use a prefix |
| 364 | """ |
| 365 | if prefix: |
| 366 | self.name = prefix + self.name |
| 367 | |
Simon Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 368 | def SetContents(self, data): |
| 369 | """Set the contents of an entry |
| 370 | |
| 371 | This sets both the data and content_size properties |
| 372 | |
| 373 | Args: |
Simon Glass | d17dfea | 2019-07-08 14:25:33 -0600 | [diff] [blame] | 374 | data: Data to set to the contents (bytes) |
Simon Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 375 | """ |
| 376 | self.data = data |
| 377 | self.contents_size = len(self.data) |
| 378 | |
| 379 | def ProcessContentsUpdate(self, data): |
Simon Glass | d17dfea | 2019-07-08 14:25:33 -0600 | [diff] [blame] | 380 | """Update the contents of an entry, after the size is fixed |
Simon Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 381 | |
Simon Glass | ec84985 | 2019-07-08 14:25:35 -0600 | [diff] [blame] | 382 | This checks that the new data is the same size as the old. If the size |
| 383 | has changed, this triggers a re-run of the packing algorithm. |
Simon Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 384 | |
| 385 | Args: |
Simon Glass | d17dfea | 2019-07-08 14:25:33 -0600 | [diff] [blame] | 386 | data: Data to set to the contents (bytes) |
Simon Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 387 | |
| 388 | Raises: |
| 389 | ValueError if the new data size is not the same as the old |
| 390 | """ |
Simon Glass | ec84985 | 2019-07-08 14:25:35 -0600 | [diff] [blame] | 391 | size_ok = True |
Simon Glass | e61b6f6 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 392 | new_size = len(data) |
Simon Glass | 9d8ee32 | 2019-07-20 12:23:58 -0600 | [diff] [blame] | 393 | if state.AllowEntryExpansion() and new_size > self.contents_size: |
| 394 | # self.data will indicate the new size needed |
| 395 | size_ok = False |
| 396 | elif state.AllowEntryContraction() and new_size < self.contents_size: |
| 397 | size_ok = False |
| 398 | |
| 399 | # If not allowed to change, try to deal with it or give up |
| 400 | if size_ok: |
Simon Glass | e61b6f6 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 401 | if new_size > self.contents_size: |
Simon Glass | 9d8ee32 | 2019-07-20 12:23:58 -0600 | [diff] [blame] | 402 | self.Raise('Cannot update entry size from %d to %d' % |
| 403 | (self.contents_size, new_size)) |
| 404 | |
| 405 | # Don't let the data shrink. Pad it if necessary |
| 406 | if size_ok and new_size < self.contents_size: |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 407 | data += tools.get_bytes(0, self.contents_size - new_size) |
Simon Glass | 9d8ee32 | 2019-07-20 12:23:58 -0600 | [diff] [blame] | 408 | |
| 409 | if not size_ok: |
Simon Glass | 011f1b3 | 2022-01-29 14:14:15 -0700 | [diff] [blame] | 410 | tout.debug("Entry '%s' size change from %s to %s" % ( |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 411 | self._node.path, to_hex(self.contents_size), |
| 412 | to_hex(new_size))) |
Simon Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 413 | self.SetContents(data) |
Simon Glass | ec84985 | 2019-07-08 14:25:35 -0600 | [diff] [blame] | 414 | return size_ok |
Simon Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 415 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 416 | def ObtainContents(self): |
| 417 | """Figure out the contents of an entry. |
| 418 | |
| 419 | Returns: |
| 420 | True if the contents were found, False if another call is needed |
| 421 | after the other entries are processed. |
| 422 | """ |
| 423 | # No contents by default: subclasses can implement this |
| 424 | return True |
| 425 | |
Simon Glass | e61b6f6 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 426 | def ResetForPack(self): |
| 427 | """Reset offset/size fields so that packing can be done again""" |
Simon Glass | b6dff4c | 2019-07-20 12:23:36 -0600 | [diff] [blame] | 428 | self.Detail('ResetForPack: offset %s->%s, size %s->%s' % |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 429 | (to_hex(self.offset), to_hex(self.orig_offset), |
| 430 | to_hex(self.size), to_hex(self.orig_size))) |
Simon Glass | 1fdb487 | 2019-10-31 07:43:02 -0600 | [diff] [blame] | 431 | self.pre_reset_size = self.size |
Simon Glass | e61b6f6 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 432 | self.offset = self.orig_offset |
| 433 | self.size = self.orig_size |
| 434 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 435 | def Pack(self, offset): |
Simon Glass | ad5a771 | 2018-06-01 09:38:14 -0600 | [diff] [blame] | 436 | """Figure out how to pack the entry into the section |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 437 | |
| 438 | Most of the time the entries are not fully specified. There may be |
| 439 | an alignment but no size. In that case we take the size from the |
| 440 | contents of the entry. |
| 441 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 442 | 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] | 443 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 444 | Once this function is complete, both the offset and size of the |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 445 | entry will be know. |
| 446 | |
| 447 | Args: |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 448 | Current section offset pointer |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 449 | |
| 450 | Returns: |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 451 | New section offset pointer (after this entry) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 452 | """ |
Simon Glass | b6dff4c | 2019-07-20 12:23:36 -0600 | [diff] [blame] | 453 | self.Detail('Packing: offset=%s, size=%s, content_size=%x' % |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 454 | (to_hex(self.offset), to_hex(self.size), |
Simon Glass | b6dff4c | 2019-07-20 12:23:36 -0600 | [diff] [blame] | 455 | self.contents_size)) |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 456 | if self.offset is None: |
| 457 | if self.offset_unset: |
| 458 | self.Raise('No offset set with offset-unset: should another ' |
| 459 | 'entry provide this correct offset?') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 460 | self.offset = tools.align(offset, self.align) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 461 | needed = self.pad_before + self.contents_size + self.pad_after |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 462 | needed = tools.align(needed, self.align_size) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 463 | size = self.size |
| 464 | if not size: |
| 465 | size = needed |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 466 | new_offset = self.offset + size |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 467 | aligned_offset = tools.align(new_offset, self.align_end) |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 468 | if aligned_offset != new_offset: |
| 469 | size = aligned_offset - self.offset |
| 470 | new_offset = aligned_offset |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 471 | |
| 472 | if not self.size: |
| 473 | self.size = size |
| 474 | |
| 475 | if self.size < needed: |
| 476 | self.Raise("Entry contents size is %#x (%d) but entry size is " |
| 477 | "%#x (%d)" % (needed, needed, self.size, self.size)) |
| 478 | # Check that the alignment is correct. It could be wrong if the |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 479 | # and offset or size values were provided (i.e. not calculated), but |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 480 | # conflict with the provided alignment values |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 481 | if self.size != tools.align(self.size, self.align_size): |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 482 | self.Raise("Size %#x (%d) does not match align-size %#x (%d)" % |
| 483 | (self.size, self.size, self.align_size, self.align_size)) |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 484 | if self.offset != tools.align(self.offset, self.align): |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 485 | self.Raise("Offset %#x (%d) does not match align %#x (%d)" % |
| 486 | (self.offset, self.offset, self.align, self.align)) |
Simon Glass | b6dff4c | 2019-07-20 12:23:36 -0600 | [diff] [blame] | 487 | self.Detail(' - packed: offset=%#x, size=%#x, content_size=%#x, next_offset=%x' % |
| 488 | (self.offset, self.size, self.contents_size, new_offset)) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 489 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 490 | return new_offset |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 491 | |
| 492 | def Raise(self, msg): |
| 493 | """Convenience function to raise an error referencing a node""" |
| 494 | raise ValueError("Node '%s': %s" % (self._node.path, msg)) |
| 495 | |
Simon Glass | e191578 | 2021-03-21 18:24:31 +1300 | [diff] [blame] | 496 | def Info(self, msg): |
| 497 | """Convenience function to log info referencing a node""" |
| 498 | tag = "Info '%s'" % self._node.path |
Simon Glass | 011f1b3 | 2022-01-29 14:14:15 -0700 | [diff] [blame] | 499 | tout.detail('%30s: %s' % (tag, msg)) |
Simon Glass | e191578 | 2021-03-21 18:24:31 +1300 | [diff] [blame] | 500 | |
Simon Glass | b6dff4c | 2019-07-20 12:23:36 -0600 | [diff] [blame] | 501 | def Detail(self, msg): |
| 502 | """Convenience function to log detail referencing a node""" |
| 503 | tag = "Node '%s'" % self._node.path |
Simon Glass | 011f1b3 | 2022-01-29 14:14:15 -0700 | [diff] [blame] | 504 | tout.detail('%30s: %s' % (tag, msg)) |
Simon Glass | b6dff4c | 2019-07-20 12:23:36 -0600 | [diff] [blame] | 505 | |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 506 | def GetEntryArgsOrProps(self, props, required=False): |
| 507 | """Return the values of a set of properties |
| 508 | |
| 509 | Args: |
| 510 | props: List of EntryArg objects |
| 511 | |
| 512 | Raises: |
| 513 | ValueError if a property is not found |
| 514 | """ |
| 515 | values = [] |
| 516 | missing = [] |
| 517 | for prop in props: |
| 518 | python_prop = prop.name.replace('-', '_') |
| 519 | if hasattr(self, python_prop): |
| 520 | value = getattr(self, python_prop) |
| 521 | else: |
| 522 | value = None |
| 523 | if value is None: |
| 524 | value = self.GetArg(prop.name, prop.datatype) |
| 525 | if value is None and required: |
| 526 | missing.append(prop.name) |
| 527 | values.append(value) |
| 528 | if missing: |
Simon Glass | 3fb2540 | 2021-01-06 21:35:16 -0700 | [diff] [blame] | 529 | self.GetImage().MissingArgs(self, missing) |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 530 | return values |
| 531 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 532 | def GetPath(self): |
| 533 | """Get the path of a node |
| 534 | |
| 535 | Returns: |
| 536 | Full path of the node for this entry |
| 537 | """ |
| 538 | return self._node.path |
| 539 | |
Simon Glass | 27a7f77 | 2021-03-21 18:24:32 +1300 | [diff] [blame] | 540 | def GetData(self, required=True): |
Simon Glass | 72eeff1 | 2020-10-26 17:40:16 -0600 | [diff] [blame] | 541 | """Get the contents of an entry |
| 542 | |
Simon Glass | 27a7f77 | 2021-03-21 18:24:32 +1300 | [diff] [blame] | 543 | Args: |
| 544 | required: True if the data must be present, False if it is OK to |
| 545 | return None |
| 546 | |
Simon Glass | 72eeff1 | 2020-10-26 17:40:16 -0600 | [diff] [blame] | 547 | Returns: |
| 548 | bytes content of the entry, excluding any padding. If the entry is |
| 549 | compressed, the compressed data is returned |
| 550 | """ |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 551 | self.Detail('GetData: size %s' % to_hex_size(self.data)) |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 552 | return self.data |
| 553 | |
Simon Glass | e17220f | 2020-11-02 12:55:43 -0700 | [diff] [blame] | 554 | def GetPaddedData(self, data=None): |
| 555 | """Get the data for an entry including any padding |
| 556 | |
| 557 | Gets the entry data and uses its section's pad-byte value to add padding |
| 558 | before and after as defined by the pad-before and pad-after properties. |
| 559 | |
| 560 | This does not consider alignment. |
| 561 | |
| 562 | Returns: |
| 563 | Contents of the entry along with any pad bytes before and |
| 564 | after it (bytes) |
| 565 | """ |
| 566 | if data is None: |
| 567 | data = self.GetData() |
| 568 | return self.section.GetPaddedDataForEntry(self, data) |
| 569 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 570 | def GetOffsets(self): |
Simon Glass | 224bc66 | 2019-07-08 13:18:30 -0600 | [diff] [blame] | 571 | """Get the offsets for siblings |
| 572 | |
| 573 | Some entry types can contain information about the position or size of |
| 574 | other entries. An example of this is the Intel Flash Descriptor, which |
| 575 | knows where the Intel Management Engine section should go. |
| 576 | |
| 577 | If this entry knows about the position of other entries, it can specify |
| 578 | this by returning values here |
| 579 | |
| 580 | Returns: |
| 581 | Dict: |
| 582 | key: Entry type |
| 583 | value: List containing position and size of the given entry |
Simon Glass | ed365eb | 2019-07-08 13:18:39 -0600 | [diff] [blame] | 584 | type. Either can be None if not known |
Simon Glass | 224bc66 | 2019-07-08 13:18:30 -0600 | [diff] [blame] | 585 | """ |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 586 | return {} |
| 587 | |
Simon Glass | ed365eb | 2019-07-08 13:18:39 -0600 | [diff] [blame] | 588 | def SetOffsetSize(self, offset, size): |
| 589 | """Set the offset and/or size of an entry |
| 590 | |
| 591 | Args: |
| 592 | offset: New offset, or None to leave alone |
| 593 | size: New size, or None to leave alone |
| 594 | """ |
| 595 | if offset is not None: |
| 596 | self.offset = offset |
| 597 | if size is not None: |
| 598 | self.size = size |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 599 | |
Simon Glass | 9dcc861 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 600 | def SetImagePos(self, image_pos): |
| 601 | """Set the position in the image |
| 602 | |
| 603 | Args: |
| 604 | image_pos: Position of this entry in the image |
| 605 | """ |
| 606 | self.image_pos = image_pos + self.offset |
| 607 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 608 | def ProcessContents(self): |
Simon Glass | ec84985 | 2019-07-08 14:25:35 -0600 | [diff] [blame] | 609 | """Do any post-packing updates of entry contents |
| 610 | |
| 611 | This function should call ProcessContentsUpdate() to update the entry |
| 612 | contents, if necessary, returning its return value here. |
| 613 | |
| 614 | Args: |
| 615 | data: Data to set to the contents (bytes) |
| 616 | |
| 617 | Returns: |
| 618 | True if the new data size is OK, False if expansion is needed |
| 619 | |
| 620 | Raises: |
| 621 | ValueError if the new data size is not the same as the old and |
| 622 | state.AllowEntryExpansion() is False |
| 623 | """ |
| 624 | return True |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 625 | |
Simon Glass | 8a6f56e | 2018-06-01 09:38:13 -0600 | [diff] [blame] | 626 | def WriteSymbols(self, section): |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 627 | """Write symbol values into binary files for access at run time |
| 628 | |
| 629 | Args: |
Simon Glass | 8a6f56e | 2018-06-01 09:38:13 -0600 | [diff] [blame] | 630 | section: Section containing the entry |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 631 | """ |
| 632 | pass |
Simon Glass | a91e115 | 2018-06-01 09:38:16 -0600 | [diff] [blame] | 633 | |
Simon Glass | 55f6807 | 2020-10-26 17:40:18 -0600 | [diff] [blame] | 634 | def CheckEntries(self): |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 635 | """Check that the entry offsets are correct |
Simon Glass | a91e115 | 2018-06-01 09:38:16 -0600 | [diff] [blame] | 636 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 637 | This is used for entries which have extra offset requirements (other |
Simon Glass | a91e115 | 2018-06-01 09:38:16 -0600 | [diff] [blame] | 638 | than having to be fully inside their section). Sub-classes can implement |
| 639 | this function and raise if there is a problem. |
| 640 | """ |
| 641 | pass |
Simon Glass | 3073266 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 642 | |
Simon Glass | 3a9a2b8 | 2018-07-17 13:25:28 -0600 | [diff] [blame] | 643 | @staticmethod |
Simon Glass | cd817d5 | 2018-09-14 04:57:36 -0600 | [diff] [blame] | 644 | def GetStr(value): |
| 645 | if value is None: |
| 646 | return '<none> ' |
| 647 | return '%08x' % value |
| 648 | |
| 649 | @staticmethod |
Simon Glass | 7eca792 | 2018-07-17 13:25:49 -0600 | [diff] [blame] | 650 | def WriteMapLine(fd, indent, name, offset, size, image_pos): |
Simon Glass | cd817d5 | 2018-09-14 04:57:36 -0600 | [diff] [blame] | 651 | print('%s %s%s %s %s' % (Entry.GetStr(image_pos), ' ' * indent, |
| 652 | Entry.GetStr(offset), Entry.GetStr(size), |
| 653 | name), file=fd) |
Simon Glass | 3a9a2b8 | 2018-07-17 13:25:28 -0600 | [diff] [blame] | 654 | |
Simon Glass | 3073266 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 655 | def WriteMap(self, fd, indent): |
| 656 | """Write a map of the entry to a .map file |
| 657 | |
| 658 | Args: |
| 659 | fd: File to write the map to |
| 660 | indent: Curent indent level of map (0=none, 1=one level, etc.) |
| 661 | """ |
Simon Glass | 7eca792 | 2018-07-17 13:25:49 -0600 | [diff] [blame] | 662 | self.WriteMapLine(fd, indent, self.name, self.offset, self.size, |
| 663 | self.image_pos) |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 664 | |
Simon Glass | 704784b | 2018-07-17 13:25:38 -0600 | [diff] [blame] | 665 | def GetEntries(self): |
| 666 | """Return a list of entries contained by this entry |
| 667 | |
| 668 | Returns: |
| 669 | List of entries, or None if none. A normal entry has no entries |
| 670 | within it so will return None |
| 671 | """ |
| 672 | return None |
| 673 | |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 674 | def GetArg(self, name, datatype=str): |
| 675 | """Get the value of an entry argument or device-tree-node property |
| 676 | |
| 677 | Some node properties can be provided as arguments to binman. First check |
| 678 | the entry arguments, and fall back to the device tree if not found |
| 679 | |
| 680 | Args: |
| 681 | name: Argument name |
| 682 | datatype: Data type (str or int) |
| 683 | |
| 684 | Returns: |
| 685 | Value of argument as a string or int, or None if no value |
| 686 | |
| 687 | Raises: |
| 688 | ValueError if the argument cannot be converted to in |
| 689 | """ |
Simon Glass | 29aa736 | 2018-09-14 04:57:19 -0600 | [diff] [blame] | 690 | value = state.GetEntryArg(name) |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 691 | if value is not None: |
| 692 | if datatype == int: |
| 693 | try: |
| 694 | value = int(value) |
| 695 | except ValueError: |
| 696 | self.Raise("Cannot convert entry arg '%s' (value '%s') to integer" % |
| 697 | (name, value)) |
| 698 | elif datatype == str: |
| 699 | pass |
| 700 | else: |
| 701 | raise ValueError("GetArg() internal error: Unknown data type '%s'" % |
| 702 | datatype) |
| 703 | else: |
| 704 | value = fdt_util.GetDatatype(self._node, name, datatype) |
| 705 | return value |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 706 | |
| 707 | @staticmethod |
| 708 | def WriteDocs(modules, test_missing=None): |
| 709 | """Write out documentation about the various entry types to stdout |
| 710 | |
| 711 | Args: |
| 712 | modules: List of modules to include |
| 713 | test_missing: Used for testing. This is a module to report |
| 714 | as missing |
| 715 | """ |
| 716 | print('''Binman Entry Documentation |
| 717 | =========================== |
| 718 | |
| 719 | This file describes the entry types supported by binman. These entry types can |
| 720 | be placed in an image one by one to build up a final firmware image. It is |
| 721 | fairly easy to create new entry types. Just add a new file to the 'etype' |
| 722 | directory. You can use the existing entries as examples. |
| 723 | |
| 724 | Note that some entries are subclasses of others, using and extending their |
| 725 | features to produce new behaviours. |
| 726 | |
| 727 | |
| 728 | ''') |
| 729 | modules = sorted(modules) |
| 730 | |
| 731 | # Don't show the test entry |
| 732 | if '_testing' in modules: |
| 733 | modules.remove('_testing') |
| 734 | missing = [] |
| 735 | for name in modules: |
Simon Glass | 2f85941 | 2021-03-18 20:25:04 +1300 | [diff] [blame] | 736 | module = Entry.Lookup('WriteDocs', name, False) |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 737 | docs = getattr(module, '__doc__') |
| 738 | if test_missing == name: |
| 739 | docs = None |
| 740 | if docs: |
| 741 | lines = docs.splitlines() |
| 742 | first_line = lines[0] |
| 743 | rest = [line[4:] for line in lines[1:]] |
| 744 | hdr = 'Entry: %s: %s' % (name.replace('_', '-'), first_line) |
| 745 | print(hdr) |
| 746 | print('-' * len(hdr)) |
| 747 | print('\n'.join(rest)) |
| 748 | print() |
| 749 | print() |
| 750 | else: |
| 751 | missing.append(name) |
| 752 | |
| 753 | if missing: |
| 754 | raise ValueError('Documentation is missing for modules: %s' % |
| 755 | ', '.join(missing)) |
Simon Glass | 639505b | 2018-09-14 04:57:11 -0600 | [diff] [blame] | 756 | |
| 757 | def GetUniqueName(self): |
| 758 | """Get a unique name for a node |
| 759 | |
| 760 | Returns: |
| 761 | String containing a unique name for a node, consisting of the name |
| 762 | of all ancestors (starting from within the 'binman' node) separated |
| 763 | by a dot ('.'). This can be useful for generating unique filesnames |
| 764 | in the output directory. |
| 765 | """ |
| 766 | name = self.name |
| 767 | node = self._node |
| 768 | while node.parent: |
| 769 | node = node.parent |
| 770 | if node.name == 'binman': |
| 771 | break |
| 772 | name = '%s.%s' % (node.name, name) |
| 773 | return name |
Simon Glass | fa79a81 | 2018-09-14 04:57:29 -0600 | [diff] [blame] | 774 | |
| 775 | def ExpandToLimit(self, limit): |
| 776 | """Expand an entry so that it ends at the given offset limit""" |
| 777 | if self.offset + self.size < limit: |
| 778 | self.size = limit - self.offset |
| 779 | # Request the contents again, since changing the size requires that |
| 780 | # the data grows. This should not fail, but check it to be sure. |
| 781 | if not self.ObtainContents(): |
| 782 | self.Raise('Cannot obtain contents when expanding entry') |
Simon Glass | c4056b8 | 2019-07-08 13:18:38 -0600 | [diff] [blame] | 783 | |
| 784 | def HasSibling(self, name): |
| 785 | """Check if there is a sibling of a given name |
| 786 | |
| 787 | Returns: |
| 788 | True if there is an entry with this name in the the same section, |
| 789 | else False |
| 790 | """ |
| 791 | return name in self.section.GetEntries() |
Simon Glass | cec34ba | 2019-07-08 14:25:28 -0600 | [diff] [blame] | 792 | |
| 793 | def GetSiblingImagePos(self, name): |
| 794 | """Return the image position of the given sibling |
| 795 | |
| 796 | Returns: |
| 797 | Image position of sibling, or None if the sibling has no position, |
| 798 | or False if there is no such sibling |
| 799 | """ |
| 800 | if not self.HasSibling(name): |
| 801 | return False |
| 802 | return self.section.GetEntries()[name].image_pos |
Simon Glass | 6b156f8 | 2019-07-08 14:25:43 -0600 | [diff] [blame] | 803 | |
| 804 | @staticmethod |
| 805 | def AddEntryInfo(entries, indent, name, etype, size, image_pos, |
| 806 | uncomp_size, offset, entry): |
| 807 | """Add a new entry to the entries list |
| 808 | |
| 809 | Args: |
| 810 | entries: List (of EntryInfo objects) to add to |
| 811 | indent: Current indent level to add to list |
| 812 | name: Entry name (string) |
| 813 | etype: Entry type (string) |
| 814 | size: Entry size in bytes (int) |
| 815 | image_pos: Position within image in bytes (int) |
| 816 | uncomp_size: Uncompressed size if the entry uses compression, else |
| 817 | None |
| 818 | offset: Entry offset within parent in bytes (int) |
| 819 | entry: Entry object |
| 820 | """ |
| 821 | entries.append(EntryInfo(indent, name, etype, size, image_pos, |
| 822 | uncomp_size, offset, entry)) |
| 823 | |
| 824 | def ListEntries(self, entries, indent): |
| 825 | """Add files in this entry to the list of entries |
| 826 | |
| 827 | This can be overridden by subclasses which need different behaviour. |
| 828 | |
| 829 | Args: |
| 830 | entries: List (of EntryInfo objects) to add to |
| 831 | indent: Current indent level to add to list |
| 832 | """ |
| 833 | self.AddEntryInfo(entries, indent, self.name, self.etype, self.size, |
| 834 | self.image_pos, self.uncomp_size, self.offset, self) |
Simon Glass | 4c613bf | 2019-07-08 14:25:50 -0600 | [diff] [blame] | 835 | |
Simon Glass | 637958f | 2021-11-23 21:09:50 -0700 | [diff] [blame] | 836 | def ReadData(self, decomp=True, alt_format=None): |
Simon Glass | 4c613bf | 2019-07-08 14:25:50 -0600 | [diff] [blame] | 837 | """Read the data for an entry from the image |
| 838 | |
| 839 | This is used when the image has been read in and we want to extract the |
| 840 | data for a particular entry from that image. |
| 841 | |
| 842 | Args: |
| 843 | decomp: True to decompress any compressed data before returning it; |
| 844 | False to return the raw, uncompressed data |
| 845 | |
| 846 | Returns: |
| 847 | Entry data (bytes) |
| 848 | """ |
| 849 | # Use True here so that we get an uncompressed section to work from, |
| 850 | # although compressed sections are currently not supported |
Simon Glass | 011f1b3 | 2022-01-29 14:14:15 -0700 | [diff] [blame] | 851 | tout.debug("ReadChildData section '%s', entry '%s'" % |
Simon Glass | 4d8151f | 2019-09-25 08:56:21 -0600 | [diff] [blame] | 852 | (self.section.GetPath(), self.GetPath())) |
Simon Glass | 637958f | 2021-11-23 21:09:50 -0700 | [diff] [blame] | 853 | data = self.section.ReadChildData(self, decomp, alt_format) |
Simon Glass | 0cd8ace | 2019-07-20 12:24:04 -0600 | [diff] [blame] | 854 | return data |
Simon Glass | af8c45c | 2019-07-20 12:23:41 -0600 | [diff] [blame] | 855 | |
Simon Glass | 637958f | 2021-11-23 21:09:50 -0700 | [diff] [blame] | 856 | def ReadChildData(self, child, decomp=True, alt_format=None): |
Simon Glass | 4d8151f | 2019-09-25 08:56:21 -0600 | [diff] [blame] | 857 | """Read the data for a particular child entry |
Simon Glass | 23f0047 | 2019-09-25 08:56:20 -0600 | [diff] [blame] | 858 | |
| 859 | This reads data from the parent and extracts the piece that relates to |
| 860 | the given child. |
| 861 | |
| 862 | Args: |
Simon Glass | 637958f | 2021-11-23 21:09:50 -0700 | [diff] [blame] | 863 | child (Entry): Child entry to read data for (must be valid) |
| 864 | decomp (bool): True to decompress any compressed data before |
| 865 | returning it; False to return the raw, uncompressed data |
| 866 | alt_format (str): Alternative format to read in, or None |
Simon Glass | 23f0047 | 2019-09-25 08:56:20 -0600 | [diff] [blame] | 867 | |
| 868 | Returns: |
| 869 | Data for the child (bytes) |
| 870 | """ |
| 871 | pass |
| 872 | |
Simon Glass | af8c45c | 2019-07-20 12:23:41 -0600 | [diff] [blame] | 873 | def LoadData(self, decomp=True): |
| 874 | data = self.ReadData(decomp) |
Simon Glass | 072959a | 2019-07-20 12:23:50 -0600 | [diff] [blame] | 875 | self.contents_size = len(data) |
Simon Glass | af8c45c | 2019-07-20 12:23:41 -0600 | [diff] [blame] | 876 | self.ProcessContentsUpdate(data) |
| 877 | self.Detail('Loaded data size %x' % len(data)) |
Simon Glass | 990b174 | 2019-07-20 12:23:46 -0600 | [diff] [blame] | 878 | |
Simon Glass | 637958f | 2021-11-23 21:09:50 -0700 | [diff] [blame] | 879 | def GetAltFormat(self, data, alt_format): |
| 880 | """Read the data for an extry in an alternative format |
| 881 | |
| 882 | Supported formats are list in the documentation for each entry. An |
| 883 | example is fdtmap which provides . |
| 884 | |
| 885 | Args: |
| 886 | data (bytes): Data to convert (this should have been produced by the |
| 887 | entry) |
| 888 | alt_format (str): Format to use |
| 889 | |
| 890 | """ |
| 891 | pass |
| 892 | |
Simon Glass | 990b174 | 2019-07-20 12:23:46 -0600 | [diff] [blame] | 893 | def GetImage(self): |
| 894 | """Get the image containing this entry |
| 895 | |
| 896 | Returns: |
| 897 | Image object containing this entry |
| 898 | """ |
| 899 | return self.section.GetImage() |
Simon Glass | 072959a | 2019-07-20 12:23:50 -0600 | [diff] [blame] | 900 | |
| 901 | def WriteData(self, data, decomp=True): |
| 902 | """Write the data to an entry in the image |
| 903 | |
| 904 | This is used when the image has been read in and we want to replace the |
| 905 | data for a particular entry in that image. |
| 906 | |
| 907 | The image must be re-packed and written out afterwards. |
| 908 | |
| 909 | Args: |
| 910 | data: Data to replace it with |
| 911 | decomp: True to compress the data if needed, False if data is |
| 912 | already compressed so should be used as is |
| 913 | |
| 914 | Returns: |
| 915 | True if the data did not result in a resize of this entry, False if |
| 916 | the entry must be resized |
| 917 | """ |
Simon Glass | 1fdb487 | 2019-10-31 07:43:02 -0600 | [diff] [blame] | 918 | if self.size is not None: |
| 919 | self.contents_size = self.size |
| 920 | else: |
| 921 | self.contents_size = self.pre_reset_size |
Simon Glass | 072959a | 2019-07-20 12:23:50 -0600 | [diff] [blame] | 922 | ok = self.ProcessContentsUpdate(data) |
| 923 | self.Detail('WriteData: size=%x, ok=%s' % (len(data), ok)) |
Simon Glass | d34af7a | 2019-07-20 12:24:05 -0600 | [diff] [blame] | 924 | section_ok = self.section.WriteChildData(self) |
| 925 | return ok and section_ok |
| 926 | |
| 927 | def WriteChildData(self, child): |
| 928 | """Handle writing the data in a child entry |
| 929 | |
| 930 | This should be called on the child's parent section after the child's |
Simon Glass | e796f24 | 2021-11-23 11:03:44 -0700 | [diff] [blame] | 931 | data has been updated. It should update any data structures needed to |
| 932 | validate that the update is successful. |
Simon Glass | d34af7a | 2019-07-20 12:24:05 -0600 | [diff] [blame] | 933 | |
| 934 | This base-class implementation does nothing, since the base Entry object |
| 935 | does not have any children. |
| 936 | |
| 937 | Args: |
| 938 | child: Child Entry that was written |
| 939 | |
| 940 | Returns: |
| 941 | True if the section could be updated successfully, False if the |
Simon Glass | e796f24 | 2021-11-23 11:03:44 -0700 | [diff] [blame] | 942 | data is such that the section could not update |
Simon Glass | d34af7a | 2019-07-20 12:24:05 -0600 | [diff] [blame] | 943 | """ |
| 944 | return True |
Simon Glass | 1145376 | 2019-07-20 12:23:55 -0600 | [diff] [blame] | 945 | |
| 946 | def GetSiblingOrder(self): |
| 947 | """Get the relative order of an entry amoung its siblings |
| 948 | |
| 949 | Returns: |
| 950 | 'start' if this entry is first among siblings, 'end' if last, |
| 951 | otherwise None |
| 952 | """ |
| 953 | entries = list(self.section.GetEntries().values()) |
| 954 | if entries: |
| 955 | if self == entries[0]: |
| 956 | return 'start' |
| 957 | elif self == entries[-1]: |
| 958 | return 'end' |
| 959 | return 'middle' |
Simon Glass | 5d94cc6 | 2020-07-09 18:39:38 -0600 | [diff] [blame] | 960 | |
| 961 | def SetAllowMissing(self, allow_missing): |
| 962 | """Set whether a section allows missing external blobs |
| 963 | |
| 964 | Args: |
| 965 | allow_missing: True if allowed, False if not allowed |
| 966 | """ |
| 967 | # This is meaningless for anything other than sections |
| 968 | pass |
Simon Glass | a003cd3 | 2020-07-09 18:39:40 -0600 | [diff] [blame] | 969 | |
Heiko Thiery | 6d45136 | 2022-01-06 11:49:41 +0100 | [diff] [blame] | 970 | def SetAllowFakeBlob(self, allow_fake): |
| 971 | """Set whether a section allows to create a fake blob |
| 972 | |
| 973 | Args: |
| 974 | allow_fake: True if allowed, False if not allowed |
| 975 | """ |
Simon Glass | ceb5f91 | 2022-01-09 20:13:46 -0700 | [diff] [blame] | 976 | self.allow_fake = allow_fake |
Heiko Thiery | 6d45136 | 2022-01-06 11:49:41 +0100 | [diff] [blame] | 977 | |
Simon Glass | a003cd3 | 2020-07-09 18:39:40 -0600 | [diff] [blame] | 978 | def CheckMissing(self, missing_list): |
| 979 | """Check if any entries in this section have missing external blobs |
| 980 | |
| 981 | If there are missing blobs, the entries are added to the list |
| 982 | |
| 983 | Args: |
| 984 | missing_list: List of Entry objects to be added to |
| 985 | """ |
| 986 | if self.missing: |
| 987 | missing_list.append(self) |
Simon Glass | b8f9037 | 2020-09-01 05:13:57 -0600 | [diff] [blame] | 988 | |
Simon Glass | 7a602fd | 2022-01-12 13:10:36 -0700 | [diff] [blame] | 989 | def check_fake_fname(self, fname): |
| 990 | """If the file is missing and the entry allows fake blobs, fake it |
| 991 | |
| 992 | Sets self.faked to True if faked |
| 993 | |
| 994 | Args: |
| 995 | fname (str): Filename to check |
| 996 | |
| 997 | Returns: |
| 998 | fname (str): Filename of faked file |
| 999 | """ |
| 1000 | if self.allow_fake and not pathlib.Path(fname).is_file(): |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1001 | outfname = tools.get_output_filename(os.path.basename(fname)) |
Simon Glass | 7a602fd | 2022-01-12 13:10:36 -0700 | [diff] [blame] | 1002 | with open(outfname, "wb") as out: |
| 1003 | out.truncate(1024) |
| 1004 | self.faked = True |
| 1005 | return outfname |
| 1006 | return fname |
| 1007 | |
Heiko Thiery | 6d45136 | 2022-01-06 11:49:41 +0100 | [diff] [blame] | 1008 | def CheckFakedBlobs(self, faked_blobs_list): |
| 1009 | """Check if any entries in this section have faked external blobs |
| 1010 | |
| 1011 | If there are faked blobs, the entries are added to the list |
| 1012 | |
| 1013 | Args: |
| 1014 | fake_blobs_list: List of Entry objects to be added to |
| 1015 | """ |
| 1016 | # This is meaningless for anything other than blobs |
| 1017 | pass |
| 1018 | |
Simon Glass | b8f9037 | 2020-09-01 05:13:57 -0600 | [diff] [blame] | 1019 | def GetAllowMissing(self): |
| 1020 | """Get whether a section allows missing external blobs |
| 1021 | |
| 1022 | Returns: |
| 1023 | True if allowed, False if not allowed |
| 1024 | """ |
| 1025 | return self.allow_missing |
Simon Glass | a820af7 | 2020-09-06 10:39:09 -0600 | [diff] [blame] | 1026 | |
Simon Glass | 66152ce | 2022-01-09 20:14:09 -0700 | [diff] [blame] | 1027 | def record_missing_bintool(self, bintool): |
| 1028 | """Record a missing bintool that was needed to produce this entry |
| 1029 | |
| 1030 | Args: |
| 1031 | bintool (Bintool): Bintool that was missing |
| 1032 | """ |
| 1033 | self.missing_bintools.append(bintool) |
| 1034 | |
| 1035 | def check_missing_bintools(self, missing_list): |
| 1036 | """Check if any entries in this section have missing bintools |
| 1037 | |
| 1038 | If there are missing bintools, these are added to the list |
| 1039 | |
| 1040 | Args: |
| 1041 | missing_list: List of Bintool objects to be added to |
| 1042 | """ |
| 1043 | missing_list += self.missing_bintools |
| 1044 | |
Simon Glass | a820af7 | 2020-09-06 10:39:09 -0600 | [diff] [blame] | 1045 | def GetHelpTags(self): |
| 1046 | """Get the tags use for missing-blob help |
| 1047 | |
| 1048 | Returns: |
| 1049 | list of possible tags, most desirable first |
| 1050 | """ |
| 1051 | return list(filter(None, [self.missing_msg, self.name, self.etype])) |
Simon Glass | a1301a2 | 2020-10-26 17:40:06 -0600 | [diff] [blame] | 1052 | |
| 1053 | def CompressData(self, indata): |
| 1054 | """Compress data according to the entry's compression method |
| 1055 | |
| 1056 | Args: |
| 1057 | indata: Data to compress |
| 1058 | |
| 1059 | Returns: |
| 1060 | Compressed data (first word is the compressed size) |
| 1061 | """ |
Simon Glass | 789b3440 | 2020-10-26 17:40:15 -0600 | [diff] [blame] | 1062 | self.uncomp_data = indata |
Simon Glass | a1301a2 | 2020-10-26 17:40:06 -0600 | [diff] [blame] | 1063 | if self.compress != 'none': |
| 1064 | self.uncomp_size = len(indata) |
Simon Glass | dd5c14ec | 2022-01-09 20:14:04 -0700 | [diff] [blame] | 1065 | data = comp_util.compress(indata, self.compress) |
Simon Glass | a1301a2 | 2020-10-26 17:40:06 -0600 | [diff] [blame] | 1066 | return data |
Simon Glass | 2f85941 | 2021-03-18 20:25:04 +1300 | [diff] [blame] | 1067 | |
| 1068 | @classmethod |
| 1069 | def UseExpanded(cls, node, etype, new_etype): |
| 1070 | """Check whether to use an expanded entry type |
| 1071 | |
| 1072 | This is called by Entry.Create() when it finds an expanded version of |
| 1073 | an entry type (e.g. 'u-boot-expanded'). If this method returns True then |
| 1074 | it will be used (e.g. in place of 'u-boot'). If it returns False, it is |
| 1075 | ignored. |
| 1076 | |
| 1077 | Args: |
| 1078 | node: Node object containing information about the entry to |
| 1079 | create |
| 1080 | etype: Original entry type being used |
| 1081 | new_etype: New entry type proposed |
| 1082 | |
| 1083 | Returns: |
| 1084 | True to use this entry type, False to use the original one |
| 1085 | """ |
Simon Glass | 011f1b3 | 2022-01-29 14:14:15 -0700 | [diff] [blame] | 1086 | tout.info("Node '%s': etype '%s': %s selected" % |
Simon Glass | 2f85941 | 2021-03-18 20:25:04 +1300 | [diff] [blame] | 1087 | (node.path, etype, new_etype)) |
| 1088 | return True |
Simon Glass | 637958f | 2021-11-23 21:09:50 -0700 | [diff] [blame] | 1089 | |
| 1090 | def CheckAltFormats(self, alt_formats): |
| 1091 | """Add any alternative formats supported by this entry type |
| 1092 | |
| 1093 | Args: |
| 1094 | alt_formats (dict): Dict to add alt_formats to: |
| 1095 | key: Name of alt format |
| 1096 | value: Help text |
| 1097 | """ |
| 1098 | pass |
Simon Glass | 4eae925 | 2022-01-09 20:13:50 -0700 | [diff] [blame] | 1099 | |
| 1100 | def AddBintools(self, tools): |
| 1101 | """Add the bintools used by this entry type |
| 1102 | |
| 1103 | Args: |
| 1104 | tools (dict of Bintool): |
| 1105 | """ |
| 1106 | pass |
| 1107 | |
| 1108 | @classmethod |
| 1109 | def AddBintool(self, tools, name): |
| 1110 | """Add a new bintool to the tools used by this etype |
| 1111 | |
| 1112 | Args: |
| 1113 | name: Name of the tool |
| 1114 | """ |
| 1115 | btool = bintool.Bintool.create(name) |
| 1116 | tools[name] = btool |
| 1117 | return btool |
Alper Nebi Yasak | 1e4ffd8 | 2022-02-09 22:02:35 +0300 | [diff] [blame^] | 1118 | |
| 1119 | def SetUpdateHash(self, update_hash): |
| 1120 | """Set whether this entry's "hash" subnode should be updated |
| 1121 | |
| 1122 | Args: |
| 1123 | update_hash: True if hash should be updated, False if not |
| 1124 | """ |
| 1125 | self.update_hash = update_hash |