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