blob: 6390917e5083e40a4e3294e5d36ec300d2057fe9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glass2574ef62016-11-25 20:15:51 -07002# Copyright (c) 2016 Google, Inc
3#
Simon Glass2574ef62016-11-25 20:15:51 -07004# Base class for all entries
5#
6
Simon Glass91710b32018-07-17 13:25:32 -06007from collections import namedtuple
Simon Glass7ccca832019-10-31 07:42:59 -06008import importlib
Simon Glass691198c2018-06-01 09:38:15 -06009import os
Simon Glass7a602fd2022-01-12 13:10:36 -070010import pathlib
Simon Glass691198c2018-06-01 09:38:15 -060011import sys
Simon Glass7d3e4072022-08-07 09:46:46 -060012import time
Simon Glass29aa7362018-09-14 04:57:19 -060013
Simon Glass4eae9252022-01-09 20:13:50 -070014from binman import bintool
Simon Glass6fc079e2022-10-20 18:22:46 -060015from binman import elf
Simon Glassc585dd42020-04-17 18:09:03 -060016from dtoc import fdt_util
Simon Glass131444f2023-02-23 18:18:04 -070017from u_boot_pylib import tools
18from u_boot_pylib.tools import to_hex, to_hex_size
19from u_boot_pylib import tout
Simon Glass2574ef62016-11-25 20:15:51 -070020
21modules = {}
22
Simon Glass2a0fa982022-02-11 13:23:21 -070023# This is imported if needed
24state = None
Simon Glass91710b32018-07-17 13:25:32 -060025
26# An argument which can be passed to entries on the command line, in lieu of
27# device-tree properties.
28EntryArg = namedtuple('EntryArg', ['name', 'datatype'])
29
Simon Glass6b156f82019-07-08 14:25:43 -060030# Information about an entry for use when displaying summaries
31EntryInfo = namedtuple('EntryInfo', ['indent', 'name', 'etype', 'size',
32 'image_pos', 'uncomp_size', 'offset',
33 'entry'])
Simon Glass91710b32018-07-17 13:25:32 -060034
Simon Glass2574ef62016-11-25 20:15:51 -070035class Entry(object):
Simon Glassad5a7712018-06-01 09:38:14 -060036 """An Entry in the section
Simon Glass2574ef62016-11-25 20:15:51 -070037
38 An entry corresponds to a single node in the device-tree description
Simon Glassad5a7712018-06-01 09:38:14 -060039 of the section. Each entry ends up being a part of the final section.
Simon Glass2574ef62016-11-25 20:15:51 -070040 Entries can be placed either right next to each other, or with padding
41 between them. The type of the entry determines the data that is in it.
42
43 This class is not used by itself. All entry objects are subclasses of
44 Entry.
45
46 Attributes:
Simon Glass3a9a2b82018-07-17 13:25:28 -060047 section: Section object containing this entry
Simon Glass2574ef62016-11-25 20:15:51 -070048 node: The node that created this entry
Simon Glasse8561af2018-08-01 15:22:37 -060049 offset: Offset of entry within the section, None if not known yet (in
50 which case it will be calculated by Pack())
Simon Glass2574ef62016-11-25 20:15:51 -070051 size: Entry size in bytes, None if not known
Samuel Hollande2574022023-01-21 17:25:16 -060052 min_size: Minimum entry size in bytes
Simon Glass1fdb4872019-10-31 07:43:02 -060053 pre_reset_size: size as it was before ResetForPack(). This allows us to
54 keep track of the size we started with and detect size changes
Simon Glassaa2fcf92019-07-08 14:25:30 -060055 uncomp_size: Size of uncompressed data in bytes, if the entry is
56 compressed, else None
Simon Glass2574ef62016-11-25 20:15:51 -070057 contents_size: Size of contents in bytes, 0 by default
Simon Glassafb9caa2020-10-26 17:40:10 -060058 align: Entry start offset alignment relative to the start of the
59 containing section, or None
Simon Glass2574ef62016-11-25 20:15:51 -070060 align_size: Entry size alignment, or None
Simon Glassafb9caa2020-10-26 17:40:10 -060061 align_end: Entry end offset alignment relative to the start of the
62 containing section, or None
Simon Glassd12599d2020-10-26 17:40:09 -060063 pad_before: Number of pad bytes before the contents when it is placed
64 in the containing section, 0 if none. The pad bytes become part of
65 the entry.
66 pad_after: Number of pad bytes after the contents when it is placed in
67 the containing section, 0 if none. The pad bytes become part of
68 the entry.
69 data: Contents of entry (string of bytes). This does not include
Simon Glass789b34402020-10-26 17:40:15 -060070 padding created by pad_before or pad_after. If the entry is
71 compressed, this contains the compressed data.
72 uncomp_data: Original uncompressed data, if this entry is compressed,
73 else None
Simon Glassaa2fcf92019-07-08 14:25:30 -060074 compress: Compression algoithm used (e.g. 'lz4'), 'none' if none
Simon Glasse61b6f62019-07-08 14:25:37 -060075 orig_offset: Original offset value read from node
76 orig_size: Original size value read from node
Simon Glass63328f12023-01-07 14:07:15 -070077 missing: True if this entry is missing its contents. Note that if it is
78 optional, this entry will not appear in the list generated by
79 entry.CheckMissing() since it is considered OK for it to be missing.
Simon Glassb8f90372020-09-01 05:13:57 -060080 allow_missing: Allow children of this entry to be missing (used by
81 subclasses such as Entry_section)
Heiko Thiery6d451362022-01-06 11:49:41 +010082 allow_fake: Allow creating a dummy fake file if the blob file is not
83 available. This is mainly used for testing.
Simon Glassb8f90372020-09-01 05:13:57 -060084 external: True if this entry contains an external binary blob
Simon Glass4eae9252022-01-09 20:13:50 -070085 bintools: Bintools used by this entry (only populated for Image)
Simon Glass66152ce2022-01-09 20:14:09 -070086 missing_bintools: List of missing bintools for this entry
Alper Nebi Yasak1e4ffd82022-02-09 22:02:35 +030087 update_hash: True if this entry's "hash" subnode should be
88 updated with a hash of the entry contents
Stefan Herbrechtsmeiera6e0b502022-08-19 16:25:30 +020089 comp_bintool: Bintools used for compress and decompress data
Simon Glass7d3e4072022-08-07 09:46:46 -060090 fake_fname: Fake filename, if one was created, else None
Yannic Moog319dc292025-06-13 14:02:40 +020091 faked (bool): True if the entry is absent and faked
Simon Glass0cf5bce2022-08-13 11:40:44 -060092 required_props (dict of str): Properties which must be present. This can
93 be added to by subclasses
Simon Glass6fc079e2022-10-20 18:22:46 -060094 elf_fname (str): Filename of the ELF file, if this entry holds an ELF
95 file, or is a binary file produced from an ELF file
96 auto_write_symbols (bool): True to write ELF symbols into this entry's
97 contents
Simon Glass1e9e61c2023-01-07 14:07:12 -070098 absent (bool): True if this entry is absent. This can be controlled by
99 the entry itself, allowing it to vanish in certain circumstances.
100 An absent entry is removed during processing so that it does not
101 appear in the map
Simon Glass63328f12023-01-07 14:07:15 -0700102 optional (bool): True if this entry contains an optional external blob
Simon Glassf1ee03b2023-01-11 16:10:16 -0700103 overlap (bool): True if this entry overlaps with others
Simon Glasscda991e2023-02-12 17:11:15 -0700104 preserve (bool): True if this entry should be preserved when updating
105 firmware. This means that it will not be changed by the update.
106 This is just a signal: enforcement of this is up to the updater.
107 This flag does not automatically propagate down to child entries.
Simon Glass49b77e82023-03-02 17:02:44 -0700108 build_done (bool): Indicates that the entry data has been built and does
109 not need to be done again. This is only used with 'binman replace',
110 to stop sections from being rebuilt if their entries have not been
111 replaced
Simon Glass4b0f4142024-08-26 13:11:40 -0600112 symbols_base (int): Use this value as the assumed load address of the
113 target entry, when calculating the symbol value. If None, this is
114 0 for blobs and the image-start address for ELF files
Simon Glass2574ef62016-11-25 20:15:51 -0700115 """
Simon Glass7d3e4072022-08-07 09:46:46 -0600116 fake_dir = None
117
Simon Glass6fc079e2022-10-20 18:22:46 -0600118 def __init__(self, section, etype, node, name_prefix='',
119 auto_write_symbols=False):
Simon Glassb9ba4e02019-08-24 07:22:44 -0600120 # Put this here to allow entry-docs and help to work without libfdt
121 global state
Simon Glassc585dd42020-04-17 18:09:03 -0600122 from binman import state
Simon Glassb9ba4e02019-08-24 07:22:44 -0600123
Simon Glassad5a7712018-06-01 09:38:14 -0600124 self.section = section
Simon Glass2574ef62016-11-25 20:15:51 -0700125 self.etype = etype
126 self._node = node
Simon Glass3b78d532018-06-01 09:38:21 -0600127 self.name = node and (name_prefix + node.name) or 'none'
Simon Glasse8561af2018-08-01 15:22:37 -0600128 self.offset = None
Simon Glass2574ef62016-11-25 20:15:51 -0700129 self.size = None
Samuel Hollande2574022023-01-21 17:25:16 -0600130 self.min_size = 0
Simon Glass1fdb4872019-10-31 07:43:02 -0600131 self.pre_reset_size = None
Simon Glassaa2fcf92019-07-08 14:25:30 -0600132 self.uncomp_size = None
Simon Glass5c350162018-07-17 13:25:47 -0600133 self.data = None
Simon Glass789b34402020-10-26 17:40:15 -0600134 self.uncomp_data = None
Simon Glass2574ef62016-11-25 20:15:51 -0700135 self.contents_size = 0
136 self.align = None
137 self.align_size = None
138 self.align_end = None
139 self.pad_before = 0
140 self.pad_after = 0
Simon Glasse8561af2018-08-01 15:22:37 -0600141 self.offset_unset = False
Simon Glass9dcc8612018-08-01 15:22:42 -0600142 self.image_pos = None
Simon Glassdd156a42022-03-05 20:18:59 -0700143 self.extend_size = False
Simon Glassaa2fcf92019-07-08 14:25:30 -0600144 self.compress = 'none'
Simon Glassa003cd32020-07-09 18:39:40 -0600145 self.missing = False
Heiko Thiery6d451362022-01-06 11:49:41 +0100146 self.faked = False
Simon Glassb8f90372020-09-01 05:13:57 -0600147 self.external = False
148 self.allow_missing = False
Heiko Thiery6d451362022-01-06 11:49:41 +0100149 self.allow_fake = False
Simon Glass4eae9252022-01-09 20:13:50 -0700150 self.bintools = {}
Simon Glass66152ce2022-01-09 20:14:09 -0700151 self.missing_bintools = []
Alper Nebi Yasak1e4ffd82022-02-09 22:02:35 +0300152 self.update_hash = True
Simon Glass7d3e4072022-08-07 09:46:46 -0600153 self.fake_fname = None
Simon Glass0cf5bce2022-08-13 11:40:44 -0600154 self.required_props = []
Stefan Herbrechtsmeiera6e0b502022-08-19 16:25:30 +0200155 self.comp_bintool = None
Simon Glass6fc079e2022-10-20 18:22:46 -0600156 self.elf_fname = None
157 self.auto_write_symbols = auto_write_symbols
Simon Glass1e9e61c2023-01-07 14:07:12 -0700158 self.absent = False
Simon Glass63328f12023-01-07 14:07:15 -0700159 self.optional = False
Simon Glassf1ee03b2023-01-11 16:10:16 -0700160 self.overlap = False
Simon Glasse0035c92023-01-11 16:10:17 -0700161 self.elf_base_sym = None
Simon Glass49e9c002023-01-11 16:10:19 -0700162 self.offset_from_elf = None
Simon Glasscda991e2023-02-12 17:11:15 -0700163 self.preserve = False
Simon Glass49b77e82023-03-02 17:02:44 -0700164 self.build_done = False
Simon Glass4abf7842023-07-18 07:23:54 -0600165 self.no_write_symbols = False
Simon Glass4b0f4142024-08-26 13:11:40 -0600166 self.symbols_base = None
Simon Glass2574ef62016-11-25 20:15:51 -0700167
168 @staticmethod
Simon Glassb9028bc2021-11-23 21:09:49 -0700169 def FindEntryClass(etype, expanded):
Simon Glass969616c2018-07-17 13:25:36 -0600170 """Look up the entry class for a node.
Simon Glass2574ef62016-11-25 20:15:51 -0700171
172 Args:
Simon Glass969616c2018-07-17 13:25:36 -0600173 node_node: Path name of Node object containing information about
174 the entry to create (used for errors)
175 etype: Entry type to use
Simon Glass2f859412021-03-18 20:25:04 +1300176 expanded: Use the expanded version of etype
Simon Glass2574ef62016-11-25 20:15:51 -0700177
178 Returns:
Simon Glass2f859412021-03-18 20:25:04 +1300179 The entry class object if found, else None if not found and expanded
Simon Glassb9028bc2021-11-23 21:09:49 -0700180 is True, else a tuple:
181 module name that could not be found
182 exception received
Simon Glass2574ef62016-11-25 20:15:51 -0700183 """
Simon Glasse76a3e62018-06-01 09:38:11 -0600184 # Convert something like 'u-boot@0' to 'u_boot' since we are only
185 # interested in the type.
Simon Glass2574ef62016-11-25 20:15:51 -0700186 module_name = etype.replace('-', '_')
Simon Glass2f859412021-03-18 20:25:04 +1300187
Simon Glasse76a3e62018-06-01 09:38:11 -0600188 if '@' in module_name:
189 module_name = module_name.split('@')[0]
Simon Glass2f859412021-03-18 20:25:04 +1300190 if expanded:
191 module_name += '_expanded'
Simon Glass2574ef62016-11-25 20:15:51 -0700192 module = modules.get(module_name)
193
Simon Glass691198c2018-06-01 09:38:15 -0600194 # Also allow entry-type modules to be brought in from the etype directory.
195
Simon Glass2574ef62016-11-25 20:15:51 -0700196 # Import the module if we have not already done so.
197 if not module:
198 try:
Simon Glassc585dd42020-04-17 18:09:03 -0600199 module = importlib.import_module('binman.etype.' + module_name)
Simon Glass969616c2018-07-17 13:25:36 -0600200 except ImportError as e:
Simon Glass2f859412021-03-18 20:25:04 +1300201 if expanded:
202 return None
Simon Glassb9028bc2021-11-23 21:09:49 -0700203 return module_name, e
Simon Glass2574ef62016-11-25 20:15:51 -0700204 modules[module_name] = module
205
Simon Glass969616c2018-07-17 13:25:36 -0600206 # Look up the expected class name
207 return getattr(module, 'Entry_%s' % module_name)
208
209 @staticmethod
Simon Glassb9028bc2021-11-23 21:09:49 -0700210 def Lookup(node_path, etype, expanded, missing_etype=False):
211 """Look up the entry class for a node.
212
213 Args:
214 node_node (str): Path name of Node object containing information
215 about the entry to create (used for errors)
216 etype (str): Entry type to use
217 expanded (bool): Use the expanded version of etype
218 missing_etype (bool): True to default to a blob etype if the
219 requested etype is not found
220
221 Returns:
222 The entry class object if found, else None if not found and expanded
223 is True
224
225 Raise:
226 ValueError if expanded is False and the class is not found
227 """
228 # Convert something like 'u-boot@0' to 'u_boot' since we are only
229 # interested in the type.
230 cls = Entry.FindEntryClass(etype, expanded)
231 if cls is None:
232 return None
233 elif isinstance(cls, tuple):
234 if missing_etype:
235 cls = Entry.FindEntryClass('blob', False)
236 if isinstance(cls, tuple): # This should not fail
237 module_name, e = cls
238 raise ValueError(
239 "Unknown entry type '%s' in node '%s' (expected etype/%s.py, error '%s'" %
240 (etype, node_path, module_name, e))
241 return cls
242
243 @staticmethod
244 def Create(section, node, etype=None, expanded=False, missing_etype=False):
Simon Glass969616c2018-07-17 13:25:36 -0600245 """Create a new entry for a node.
246
247 Args:
Simon Glassb9028bc2021-11-23 21:09:49 -0700248 section (entry_Section): Section object containing this node
249 node (Node): Node object containing information about the entry to
250 create
251 etype (str): Entry type to use, or None to work it out (used for
252 tests)
253 expanded (bool): Use the expanded version of etype
254 missing_etype (bool): True to default to a blob etype if the
255 requested etype is not found
Simon Glass969616c2018-07-17 13:25:36 -0600256
257 Returns:
258 A new Entry object of the correct type (a subclass of Entry)
259 """
260 if not etype:
261 etype = fdt_util.GetString(node, 'type', node.name)
Simon Glassb9028bc2021-11-23 21:09:49 -0700262 obj = Entry.Lookup(node.path, etype, expanded, missing_etype)
Simon Glass2f859412021-03-18 20:25:04 +1300263 if obj and expanded:
264 # Check whether to use the expanded entry
265 new_etype = etype + '-expanded'
Simon Glass7098b7f2021-03-21 18:24:30 +1300266 can_expand = not fdt_util.GetBool(node, 'no-expanded')
267 if can_expand and obj.UseExpanded(node, etype, new_etype):
Simon Glass2f859412021-03-18 20:25:04 +1300268 etype = new_etype
269 else:
270 obj = None
271 if not obj:
Simon Glassb9028bc2021-11-23 21:09:49 -0700272 obj = Entry.Lookup(node.path, etype, False, missing_etype)
Simon Glass969616c2018-07-17 13:25:36 -0600273
Simon Glass2574ef62016-11-25 20:15:51 -0700274 # Call its constructor to get the object we want.
Simon Glassad5a7712018-06-01 09:38:14 -0600275 return obj(section, etype, node)
Simon Glass2574ef62016-11-25 20:15:51 -0700276
277 def ReadNode(self):
278 """Read entry information from the node
279
Simon Glass2c360cf2019-07-20 12:23:45 -0600280 This must be called as the first thing after the Entry is created.
281
Simon Glass2574ef62016-11-25 20:15:51 -0700282 This reads all the fields we recognise from the node, ready for use.
283 """
Simon Glass0cf5bce2022-08-13 11:40:44 -0600284 self.ensure_props()
Simon Glass24b97442018-07-17 13:25:51 -0600285 if 'pos' in self._node.props:
286 self.Raise("Please use 'offset' instead of 'pos'")
Simon Glassdd156a42022-03-05 20:18:59 -0700287 if 'expand-size' in self._node.props:
288 self.Raise("Please use 'extend-size' instead of 'expand-size'")
Simon Glasse8561af2018-08-01 15:22:37 -0600289 self.offset = fdt_util.GetInt(self._node, 'offset')
Simon Glass2574ef62016-11-25 20:15:51 -0700290 self.size = fdt_util.GetInt(self._node, 'size')
Samuel Hollande2574022023-01-21 17:25:16 -0600291 self.min_size = fdt_util.GetInt(self._node, 'min-size', 0)
Simon Glassfb30e292019-07-20 12:23:51 -0600292 self.orig_offset = fdt_util.GetInt(self._node, 'orig-offset')
293 self.orig_size = fdt_util.GetInt(self._node, 'orig-size')
294 if self.GetImage().copy_to_orig:
295 self.orig_offset = self.offset
296 self.orig_size = self.size
Simon Glasse61b6f62019-07-08 14:25:37 -0600297
Simon Glassb8424fa2019-07-08 14:25:46 -0600298 # These should not be set in input files, but are set in an FDT map,
299 # which is also read by this code.
300 self.image_pos = fdt_util.GetInt(self._node, 'image-pos')
301 self.uncomp_size = fdt_util.GetInt(self._node, 'uncomp-size')
302
Simon Glass2574ef62016-11-25 20:15:51 -0700303 self.align = fdt_util.GetInt(self._node, 'align')
Simon Glass80025522022-01-29 14:14:04 -0700304 if tools.not_power_of_two(self.align):
Simon Glass2574ef62016-11-25 20:15:51 -0700305 raise ValueError("Node '%s': Alignment %s must be a power of two" %
306 (self._node.path, self.align))
Simon Glassf427c5f2021-03-21 18:24:33 +1300307 if self.section and self.align is None:
308 self.align = self.section.align_default
Simon Glass2574ef62016-11-25 20:15:51 -0700309 self.pad_before = fdt_util.GetInt(self._node, 'pad-before', 0)
310 self.pad_after = fdt_util.GetInt(self._node, 'pad-after', 0)
311 self.align_size = fdt_util.GetInt(self._node, 'align-size')
Simon Glass80025522022-01-29 14:14:04 -0700312 if tools.not_power_of_two(self.align_size):
Simon Glass39dd2152019-07-08 14:25:47 -0600313 self.Raise("Alignment size %s must be a power of two" %
314 self.align_size)
Simon Glass2574ef62016-11-25 20:15:51 -0700315 self.align_end = fdt_util.GetInt(self._node, 'align-end')
Simon Glasse8561af2018-08-01 15:22:37 -0600316 self.offset_unset = fdt_util.GetBool(self._node, 'offset-unset')
Simon Glassdd156a42022-03-05 20:18:59 -0700317 self.extend_size = fdt_util.GetBool(self._node, 'extend-size')
Simon Glassa820af72020-09-06 10:39:09 -0600318 self.missing_msg = fdt_util.GetString(self._node, 'missing-msg')
Simon Glass63328f12023-01-07 14:07:15 -0700319 self.optional = fdt_util.GetBool(self._node, 'optional')
Simon Glassf1ee03b2023-01-11 16:10:16 -0700320 self.overlap = fdt_util.GetBool(self._node, 'overlap')
321 if self.overlap:
322 self.required_props += ['offset', 'size']
Simon Glassa360b8f2024-06-23 11:55:06 -0600323 self.assume_size = fdt_util.GetInt(self._node, 'assume-size', 0)
Simon Glass2574ef62016-11-25 20:15:51 -0700324
Simon Glassa1301a22020-10-26 17:40:06 -0600325 # This is only supported by blobs and sections at present
326 self.compress = fdt_util.GetString(self._node, 'compress', 'none')
Simon Glass49e9c002023-01-11 16:10:19 -0700327 self.offset_from_elf = fdt_util.GetPhandleNameOffset(self._node,
328 'offset-from-elf')
Simon Glassa1301a22020-10-26 17:40:06 -0600329
Simon Glasscda991e2023-02-12 17:11:15 -0700330 self.preserve = fdt_util.GetBool(self._node, 'preserve')
Simon Glass4abf7842023-07-18 07:23:54 -0600331 self.no_write_symbols = fdt_util.GetBool(self._node, 'no-write-symbols')
Simon Glass4b0f4142024-08-26 13:11:40 -0600332 self.symbols_base = fdt_util.GetInt(self._node, 'symbols-base')
Simon Glasscda991e2023-02-12 17:11:15 -0700333
Simon Glass3732ec32018-09-14 04:57:18 -0600334 def GetDefaultFilename(self):
335 return None
336
Simon Glass267112e2019-07-20 12:23:28 -0600337 def GetFdts(self):
338 """Get the device trees used by this entry
Simon Glass0c9d5b52018-09-14 04:57:22 -0600339
340 Returns:
Simon Glass267112e2019-07-20 12:23:28 -0600341 Empty dict, if this entry is not a .dtb, otherwise:
342 Dict:
343 key: Filename from this entry (without the path)
Simon Glass684a4f12019-07-20 12:23:31 -0600344 value: Tuple:
Simon Glass8235dd82021-03-18 20:25:02 +1300345 Entry object for this dtb
Simon Glass684a4f12019-07-20 12:23:31 -0600346 Filename of file containing this dtb
Simon Glass0c9d5b52018-09-14 04:57:22 -0600347 """
Simon Glass267112e2019-07-20 12:23:28 -0600348 return {}
Simon Glass0c9d5b52018-09-14 04:57:22 -0600349
Simon Glassf86ddad2022-03-05 20:19:00 -0700350 def gen_entries(self):
351 """Allow entries to generate other entries
Simon Glassfcb2a7c2021-03-18 20:24:52 +1300352
353 Some entries generate subnodes automatically, from which sub-entries
354 are then created. This method allows those to be added to the binman
355 definition for the current image. An entry which implements this method
356 should call state.AddSubnode() to add a subnode and can add properties
357 with state.AddString(), etc.
358
359 An example is 'files', which produces a section containing a list of
360 files.
361 """
Simon Glassac6328c2018-09-14 04:57:28 -0600362 pass
363
Simon Glassacd6c6e2020-10-26 17:40:17 -0600364 def AddMissingProperties(self, have_image_pos):
365 """Add new properties to the device tree as needed for this entry
366
367 Args:
368 have_image_pos: True if this entry has an image position. This can
369 be False if its parent section is compressed, since compression
370 groups all entries together into a compressed block of data,
371 obscuring the start of each individual child entry
372 """
373 for prop in ['offset', 'size']:
Simon Glasse22f8fa2018-07-06 10:27:41 -0600374 if not prop in self._node.props:
Simon Glassc8135dc2018-09-14 04:57:21 -0600375 state.AddZeroProp(self._node, prop)
Simon Glassacd6c6e2020-10-26 17:40:17 -0600376 if have_image_pos and 'image-pos' not in self._node.props:
377 state.AddZeroProp(self._node, 'image-pos')
Simon Glassfb30e292019-07-20 12:23:51 -0600378 if self.GetImage().allow_repack:
379 if self.orig_offset is not None:
380 state.AddZeroProp(self._node, 'orig-offset', True)
381 if self.orig_size is not None:
382 state.AddZeroProp(self._node, 'orig-size', True)
383
Simon Glassaa2fcf92019-07-08 14:25:30 -0600384 if self.compress != 'none':
385 state.AddZeroProp(self._node, 'uncomp-size')
Alper Nebi Yasak1e4ffd82022-02-09 22:02:35 +0300386
387 if self.update_hash:
388 err = state.CheckAddHashProp(self._node)
389 if err:
390 self.Raise(err)
Simon Glasse22f8fa2018-07-06 10:27:41 -0600391
392 def SetCalculatedProperties(self):
393 """Set the value of device-tree properties calculated by binman"""
Simon Glassc8135dc2018-09-14 04:57:21 -0600394 state.SetInt(self._node, 'offset', self.offset)
395 state.SetInt(self._node, 'size', self.size)
Simon Glassacd6c6e2020-10-26 17:40:17 -0600396 if self.image_pos is not None:
Simon Glassed836ac2025-02-26 09:26:17 -0700397 state.SetInt(self._node, 'image-pos', self.image_pos)
Simon Glassfb30e292019-07-20 12:23:51 -0600398 if self.GetImage().allow_repack:
399 if self.orig_offset is not None:
400 state.SetInt(self._node, 'orig-offset', self.orig_offset, True)
401 if self.orig_size is not None:
402 state.SetInt(self._node, 'orig-size', self.orig_size, True)
Simon Glassaa2fcf92019-07-08 14:25:30 -0600403 if self.uncomp_size is not None:
404 state.SetInt(self._node, 'uncomp-size', self.uncomp_size)
Alper Nebi Yasak1e4ffd82022-02-09 22:02:35 +0300405
406 if self.update_hash:
407 state.CheckSetHashValue(self._node, self.GetData)
Simon Glasse22f8fa2018-07-06 10:27:41 -0600408
Simon Glass92307732018-07-06 10:27:40 -0600409 def ProcessFdt(self, fdt):
Simon Glasse219aa42018-09-14 04:57:24 -0600410 """Allow entries to adjust the device tree
411
412 Some entries need to adjust the device tree for their purposes. This
413 may involve adding or deleting properties.
414
415 Returns:
416 True if processing is complete
417 False if processing could not be completed due to a dependency.
418 This will cause the entry to be retried after others have been
419 called
420 """
Simon Glass92307732018-07-06 10:27:40 -0600421 return True
422
Simon Glass3b78d532018-06-01 09:38:21 -0600423 def SetPrefix(self, prefix):
424 """Set the name prefix for a node
425
426 Args:
427 prefix: Prefix to set, or '' to not use a prefix
428 """
429 if prefix:
430 self.name = prefix + self.name
431
Simon Glass2e1169f2018-07-06 10:27:19 -0600432 def SetContents(self, data):
433 """Set the contents of an entry
434
435 This sets both the data and content_size properties
436
437 Args:
Simon Glassd17dfea2019-07-08 14:25:33 -0600438 data: Data to set to the contents (bytes)
Simon Glass2e1169f2018-07-06 10:27:19 -0600439 """
440 self.data = data
441 self.contents_size = len(self.data)
442
443 def ProcessContentsUpdate(self, data):
Simon Glassd17dfea2019-07-08 14:25:33 -0600444 """Update the contents of an entry, after the size is fixed
Simon Glass2e1169f2018-07-06 10:27:19 -0600445
Simon Glassec849852019-07-08 14:25:35 -0600446 This checks that the new data is the same size as the old. If the size
447 has changed, this triggers a re-run of the packing algorithm.
Simon Glass2e1169f2018-07-06 10:27:19 -0600448
449 Args:
Simon Glassd17dfea2019-07-08 14:25:33 -0600450 data: Data to set to the contents (bytes)
Simon Glass2e1169f2018-07-06 10:27:19 -0600451
452 Raises:
453 ValueError if the new data size is not the same as the old
454 """
Simon Glassec849852019-07-08 14:25:35 -0600455 size_ok = True
Simon Glasse61b6f62019-07-08 14:25:37 -0600456 new_size = len(data)
Simon Glass9d8ee322019-07-20 12:23:58 -0600457 if state.AllowEntryExpansion() and new_size > self.contents_size:
458 # self.data will indicate the new size needed
459 size_ok = False
460 elif state.AllowEntryContraction() and new_size < self.contents_size:
461 size_ok = False
462
463 # If not allowed to change, try to deal with it or give up
464 if size_ok:
Simon Glasse61b6f62019-07-08 14:25:37 -0600465 if new_size > self.contents_size:
Simon Glass9d8ee322019-07-20 12:23:58 -0600466 self.Raise('Cannot update entry size from %d to %d' %
467 (self.contents_size, new_size))
468
469 # Don't let the data shrink. Pad it if necessary
470 if size_ok and new_size < self.contents_size:
Simon Glass80025522022-01-29 14:14:04 -0700471 data += tools.get_bytes(0, self.contents_size - new_size)
Simon Glass9d8ee322019-07-20 12:23:58 -0600472
473 if not size_ok:
Simon Glass011f1b32022-01-29 14:14:15 -0700474 tout.debug("Entry '%s' size change from %s to %s" % (
Simon Glass80025522022-01-29 14:14:04 -0700475 self._node.path, to_hex(self.contents_size),
476 to_hex(new_size)))
Simon Glass2e1169f2018-07-06 10:27:19 -0600477 self.SetContents(data)
Simon Glassec849852019-07-08 14:25:35 -0600478 return size_ok
Simon Glass2e1169f2018-07-06 10:27:19 -0600479
Simon Glassfc5a1682022-03-05 20:19:05 -0700480 def ObtainContents(self, skip_entry=None, fake_size=0):
Simon Glass2574ef62016-11-25 20:15:51 -0700481 """Figure out the contents of an entry.
482
Simon Glass0b25b432023-07-18 07:23:57 -0600483 For missing blobs (where allow-missing is enabled), the contents are set
484 to b'' and self.missing is set to True.
485
Simon Glassfc5a1682022-03-05 20:19:05 -0700486 Args:
487 skip_entry (Entry): Entry to skip when obtaining section contents
488 fake_size (int): Size of fake file to create if needed
489
Simon Glass2574ef62016-11-25 20:15:51 -0700490 Returns:
491 True if the contents were found, False if another call is needed
Simon Glassa4948b22023-01-11 16:10:14 -0700492 after the other entries are processed, None if there is no contents
Simon Glass2574ef62016-11-25 20:15:51 -0700493 """
494 # No contents by default: subclasses can implement this
495 return True
496
Simon Glasse61b6f62019-07-08 14:25:37 -0600497 def ResetForPack(self):
498 """Reset offset/size fields so that packing can be done again"""
Simon Glassb6dff4c2019-07-20 12:23:36 -0600499 self.Detail('ResetForPack: offset %s->%s, size %s->%s' %
Simon Glass80025522022-01-29 14:14:04 -0700500 (to_hex(self.offset), to_hex(self.orig_offset),
501 to_hex(self.size), to_hex(self.orig_size)))
Simon Glass1fdb4872019-10-31 07:43:02 -0600502 self.pre_reset_size = self.size
Simon Glasse61b6f62019-07-08 14:25:37 -0600503 self.offset = self.orig_offset
504 self.size = self.orig_size
505
Simon Glasse8561af2018-08-01 15:22:37 -0600506 def Pack(self, offset):
Simon Glassad5a7712018-06-01 09:38:14 -0600507 """Figure out how to pack the entry into the section
Simon Glass2574ef62016-11-25 20:15:51 -0700508
509 Most of the time the entries are not fully specified. There may be
510 an alignment but no size. In that case we take the size from the
511 contents of the entry.
512
Simon Glasse8561af2018-08-01 15:22:37 -0600513 If an entry has no hard-coded offset, it will be placed at @offset.
Simon Glass2574ef62016-11-25 20:15:51 -0700514
Simon Glasse8561af2018-08-01 15:22:37 -0600515 Once this function is complete, both the offset and size of the
Simon Glass2574ef62016-11-25 20:15:51 -0700516 entry will be know.
517
518 Args:
Simon Glasse8561af2018-08-01 15:22:37 -0600519 Current section offset pointer
Simon Glass2574ef62016-11-25 20:15:51 -0700520
521 Returns:
Simon Glasse8561af2018-08-01 15:22:37 -0600522 New section offset pointer (after this entry)
Simon Glass2574ef62016-11-25 20:15:51 -0700523 """
Simon Glassb6dff4c2019-07-20 12:23:36 -0600524 self.Detail('Packing: offset=%s, size=%s, content_size=%x' %
Simon Glass80025522022-01-29 14:14:04 -0700525 (to_hex(self.offset), to_hex(self.size),
Simon Glassb6dff4c2019-07-20 12:23:36 -0600526 self.contents_size))
Simon Glasse8561af2018-08-01 15:22:37 -0600527 if self.offset is None:
528 if self.offset_unset:
529 self.Raise('No offset set with offset-unset: should another '
530 'entry provide this correct offset?')
Simon Glass49e9c002023-01-11 16:10:19 -0700531 elif self.offset_from_elf:
532 self.offset = self.lookup_offset()
533 else:
534 self.offset = tools.align(offset, self.align)
Simon Glass2574ef62016-11-25 20:15:51 -0700535 needed = self.pad_before + self.contents_size + self.pad_after
Samuel Hollande2574022023-01-21 17:25:16 -0600536 needed = max(needed, self.min_size)
Simon Glass80025522022-01-29 14:14:04 -0700537 needed = tools.align(needed, self.align_size)
Simon Glass2574ef62016-11-25 20:15:51 -0700538 size = self.size
539 if not size:
540 size = needed
Simon Glasse8561af2018-08-01 15:22:37 -0600541 new_offset = self.offset + size
Simon Glass80025522022-01-29 14:14:04 -0700542 aligned_offset = tools.align(new_offset, self.align_end)
Simon Glasse8561af2018-08-01 15:22:37 -0600543 if aligned_offset != new_offset:
544 size = aligned_offset - self.offset
545 new_offset = aligned_offset
Simon Glass2574ef62016-11-25 20:15:51 -0700546
547 if not self.size:
548 self.size = size
549
550 if self.size < needed:
551 self.Raise("Entry contents size is %#x (%d) but entry size is "
552 "%#x (%d)" % (needed, needed, self.size, self.size))
553 # Check that the alignment is correct. It could be wrong if the
Simon Glasse8561af2018-08-01 15:22:37 -0600554 # and offset or size values were provided (i.e. not calculated), but
Simon Glass2574ef62016-11-25 20:15:51 -0700555 # conflict with the provided alignment values
Simon Glass80025522022-01-29 14:14:04 -0700556 if self.size != tools.align(self.size, self.align_size):
Simon Glass2574ef62016-11-25 20:15:51 -0700557 self.Raise("Size %#x (%d) does not match align-size %#x (%d)" %
558 (self.size, self.size, self.align_size, self.align_size))
Simon Glass80025522022-01-29 14:14:04 -0700559 if self.offset != tools.align(self.offset, self.align):
Simon Glasse8561af2018-08-01 15:22:37 -0600560 self.Raise("Offset %#x (%d) does not match align %#x (%d)" %
561 (self.offset, self.offset, self.align, self.align))
Simon Glassb6dff4c2019-07-20 12:23:36 -0600562 self.Detail(' - packed: offset=%#x, size=%#x, content_size=%#x, next_offset=%x' %
563 (self.offset, self.size, self.contents_size, new_offset))
Simon Glass2574ef62016-11-25 20:15:51 -0700564
Simon Glasse8561af2018-08-01 15:22:37 -0600565 return new_offset
Simon Glass2574ef62016-11-25 20:15:51 -0700566
567 def Raise(self, msg):
568 """Convenience function to raise an error referencing a node"""
569 raise ValueError("Node '%s': %s" % (self._node.path, msg))
570
Simon Glasse1915782021-03-21 18:24:31 +1300571 def Info(self, msg):
572 """Convenience function to log info referencing a node"""
573 tag = "Info '%s'" % self._node.path
Simon Glass011f1b32022-01-29 14:14:15 -0700574 tout.detail('%30s: %s' % (tag, msg))
Simon Glasse1915782021-03-21 18:24:31 +1300575
Simon Glassb6dff4c2019-07-20 12:23:36 -0600576 def Detail(self, msg):
577 """Convenience function to log detail referencing a node"""
578 tag = "Node '%s'" % self._node.path
Simon Glass011f1b32022-01-29 14:14:15 -0700579 tout.detail('%30s: %s' % (tag, msg))
Simon Glassb6dff4c2019-07-20 12:23:36 -0600580
Simon Glass91710b32018-07-17 13:25:32 -0600581 def GetEntryArgsOrProps(self, props, required=False):
582 """Return the values of a set of properties
583
Simon Glasseb64f5d2024-08-26 13:11:31 -0600584 Looks up the named entryargs and returns the value for each. If any
585 required ones are missing, the error is reported to the user.
586
Simon Glass91710b32018-07-17 13:25:32 -0600587 Args:
Simon Glasseb64f5d2024-08-26 13:11:31 -0600588 props (list of EntryArg): List of entry arguments to look up
589 required (bool): True if these entry arguments are required
590
591 Returns:
592 list of values: one for each item in props, the type is determined
593 by the EntryArg's 'datatype' property (str or int)
Simon Glass91710b32018-07-17 13:25:32 -0600594
595 Raises:
596 ValueError if a property is not found
597 """
598 values = []
599 missing = []
600 for prop in props:
601 python_prop = prop.name.replace('-', '_')
602 if hasattr(self, python_prop):
603 value = getattr(self, python_prop)
604 else:
605 value = None
606 if value is None:
607 value = self.GetArg(prop.name, prop.datatype)
608 if value is None and required:
609 missing.append(prop.name)
610 values.append(value)
611 if missing:
Simon Glass3fb25402021-01-06 21:35:16 -0700612 self.GetImage().MissingArgs(self, missing)
Simon Glass91710b32018-07-17 13:25:32 -0600613 return values
614
Simon Glass2574ef62016-11-25 20:15:51 -0700615 def GetPath(self):
616 """Get the path of a node
617
618 Returns:
619 Full path of the node for this entry
620 """
621 return self._node.path
622
Simon Glass27a7f772021-03-21 18:24:32 +1300623 def GetData(self, required=True):
Simon Glass72eeff12020-10-26 17:40:16 -0600624 """Get the contents of an entry
625
Simon Glass27a7f772021-03-21 18:24:32 +1300626 Args:
627 required: True if the data must be present, False if it is OK to
628 return None
629
Simon Glass72eeff12020-10-26 17:40:16 -0600630 Returns:
631 bytes content of the entry, excluding any padding. If the entry is
Simon Glass02997652023-01-11 16:10:13 -0700632 compressed, the compressed data is returned. If the entry data
Simon Glassa4948b22023-01-11 16:10:14 -0700633 is not yet available, False can be returned. If the entry data
634 is null, then None is returned.
Simon Glass72eeff12020-10-26 17:40:16 -0600635 """
Simon Glass80025522022-01-29 14:14:04 -0700636 self.Detail('GetData: size %s' % to_hex_size(self.data))
Simon Glass2574ef62016-11-25 20:15:51 -0700637 return self.data
638
Simon Glasse17220f2020-11-02 12:55:43 -0700639 def GetPaddedData(self, data=None):
640 """Get the data for an entry including any padding
641
642 Gets the entry data and uses its section's pad-byte value to add padding
643 before and after as defined by the pad-before and pad-after properties.
644
645 This does not consider alignment.
646
647 Returns:
648 Contents of the entry along with any pad bytes before and
649 after it (bytes)
650 """
651 if data is None:
652 data = self.GetData()
653 return self.section.GetPaddedDataForEntry(self, data)
654
Simon Glasse8561af2018-08-01 15:22:37 -0600655 def GetOffsets(self):
Simon Glass224bc662019-07-08 13:18:30 -0600656 """Get the offsets for siblings
657
658 Some entry types can contain information about the position or size of
659 other entries. An example of this is the Intel Flash Descriptor, which
660 knows where the Intel Management Engine section should go.
661
662 If this entry knows about the position of other entries, it can specify
663 this by returning values here
664
665 Returns:
666 Dict:
667 key: Entry type
668 value: List containing position and size of the given entry
Simon Glassed365eb2019-07-08 13:18:39 -0600669 type. Either can be None if not known
Simon Glass224bc662019-07-08 13:18:30 -0600670 """
Simon Glass2574ef62016-11-25 20:15:51 -0700671 return {}
672
Simon Glassed365eb2019-07-08 13:18:39 -0600673 def SetOffsetSize(self, offset, size):
674 """Set the offset and/or size of an entry
675
676 Args:
677 offset: New offset, or None to leave alone
678 size: New size, or None to leave alone
679 """
680 if offset is not None:
681 self.offset = offset
682 if size is not None:
683 self.size = size
Simon Glass2574ef62016-11-25 20:15:51 -0700684
Simon Glass9dcc8612018-08-01 15:22:42 -0600685 def SetImagePos(self, image_pos):
686 """Set the position in the image
687
688 Args:
689 image_pos: Position of this entry in the image
690 """
691 self.image_pos = image_pos + self.offset
692
Simon Glass2574ef62016-11-25 20:15:51 -0700693 def ProcessContents(self):
Simon Glassec849852019-07-08 14:25:35 -0600694 """Do any post-packing updates of entry contents
695
696 This function should call ProcessContentsUpdate() to update the entry
697 contents, if necessary, returning its return value here.
698
699 Args:
700 data: Data to set to the contents (bytes)
701
702 Returns:
703 True if the new data size is OK, False if expansion is needed
704
705 Raises:
706 ValueError if the new data size is not the same as the old and
707 state.AllowEntryExpansion() is False
708 """
709 return True
Simon Glass4ca8e042017-11-13 18:55:01 -0700710
Simon Glass8a6f56e2018-06-01 09:38:13 -0600711 def WriteSymbols(self, section):
Simon Glass4ca8e042017-11-13 18:55:01 -0700712 """Write symbol values into binary files for access at run time
713
Simon Glass56112842024-08-26 13:11:41 -0600714 As a special case, if symbols_base is not specified and this is an
715 end-at-4gb image, a symbols_base of 0 is used
716
Simon Glass4ca8e042017-11-13 18:55:01 -0700717 Args:
Simon Glass8a6f56e2018-06-01 09:38:13 -0600718 section: Section containing the entry
Simon Glass4ca8e042017-11-13 18:55:01 -0700719 """
Simon Glass4abf7842023-07-18 07:23:54 -0600720 if self.auto_write_symbols and not self.no_write_symbols:
Simon Glass37f85de2022-10-20 18:22:47 -0600721 # Check if we are writing symbols into an ELF file
722 is_elf = self.GetDefaultFilename() == self.elf_fname
Simon Glass56112842024-08-26 13:11:41 -0600723
724 symbols_base = self.symbols_base
Simon Glass52565dc2025-02-26 09:26:16 -0700725 if symbols_base is None and self.GetImage()._end_at_4gb:
Simon Glass56112842024-08-26 13:11:41 -0600726 symbols_base = 0
727
Simon Glass37f85de2022-10-20 18:22:47 -0600728 elf.LookupAndWriteSymbols(self.elf_fname, self, section.GetImage(),
Simon Glass56112842024-08-26 13:11:41 -0600729 is_elf, self.elf_base_sym, symbols_base)
Simon Glassa91e1152018-06-01 09:38:16 -0600730
Simon Glass55f68072020-10-26 17:40:18 -0600731 def CheckEntries(self):
Simon Glasse8561af2018-08-01 15:22:37 -0600732 """Check that the entry offsets are correct
Simon Glassa91e1152018-06-01 09:38:16 -0600733
Simon Glasse8561af2018-08-01 15:22:37 -0600734 This is used for entries which have extra offset requirements (other
Simon Glassa91e1152018-06-01 09:38:16 -0600735 than having to be fully inside their section). Sub-classes can implement
736 this function and raise if there is a problem.
737 """
738 pass
Simon Glass30732662018-06-01 09:38:20 -0600739
Simon Glass3a9a2b82018-07-17 13:25:28 -0600740 @staticmethod
Simon Glasscd817d52018-09-14 04:57:36 -0600741 def GetStr(value):
742 if value is None:
743 return '<none> '
744 return '%08x' % value
745
746 @staticmethod
Simon Glass7eca7922018-07-17 13:25:49 -0600747 def WriteMapLine(fd, indent, name, offset, size, image_pos):
Simon Glasscd817d52018-09-14 04:57:36 -0600748 print('%s %s%s %s %s' % (Entry.GetStr(image_pos), ' ' * indent,
749 Entry.GetStr(offset), Entry.GetStr(size),
750 name), file=fd)
Simon Glass3a9a2b82018-07-17 13:25:28 -0600751
Simon Glass30732662018-06-01 09:38:20 -0600752 def WriteMap(self, fd, indent):
753 """Write a map of the entry to a .map file
754
755 Args:
756 fd: File to write the map to
757 indent: Curent indent level of map (0=none, 1=one level, etc.)
758 """
Simon Glass7eca7922018-07-17 13:25:49 -0600759 self.WriteMapLine(fd, indent, self.name, self.offset, self.size,
760 self.image_pos)
Simon Glass91710b32018-07-17 13:25:32 -0600761
Simon Glassbd5cd882022-08-13 11:40:50 -0600762 # pylint: disable=assignment-from-none
Simon Glass704784b2018-07-17 13:25:38 -0600763 def GetEntries(self):
764 """Return a list of entries contained by this entry
765
766 Returns:
767 List of entries, or None if none. A normal entry has no entries
768 within it so will return None
769 """
770 return None
771
Simon Glassbd5cd882022-08-13 11:40:50 -0600772 def FindEntryByNode(self, find_node):
773 """Find a node in an entry, searching all subentries
774
775 This does a recursive search.
776
777 Args:
778 find_node (fdt.Node): Node to find
779
780 Returns:
781 Entry: entry, if found, else None
782 """
783 entries = self.GetEntries()
784 if entries:
785 for entry in entries.values():
786 if entry._node == find_node:
787 return entry
788 found = entry.FindEntryByNode(find_node)
789 if found:
790 return found
791
792 return None
793
Simon Glass91710b32018-07-17 13:25:32 -0600794 def GetArg(self, name, datatype=str):
795 """Get the value of an entry argument or device-tree-node property
796
797 Some node properties can be provided as arguments to binman. First check
798 the entry arguments, and fall back to the device tree if not found
799
800 Args:
801 name: Argument name
802 datatype: Data type (str or int)
803
804 Returns:
805 Value of argument as a string or int, or None if no value
806
807 Raises:
808 ValueError if the argument cannot be converted to in
809 """
Simon Glass29aa7362018-09-14 04:57:19 -0600810 value = state.GetEntryArg(name)
Simon Glass91710b32018-07-17 13:25:32 -0600811 if value is not None:
812 if datatype == int:
813 try:
814 value = int(value)
815 except ValueError:
816 self.Raise("Cannot convert entry arg '%s' (value '%s') to integer" %
817 (name, value))
818 elif datatype == str:
819 pass
820 else:
821 raise ValueError("GetArg() internal error: Unknown data type '%s'" %
822 datatype)
823 else:
824 value = fdt_util.GetDatatype(self._node, name, datatype)
825 return value
Simon Glass969616c2018-07-17 13:25:36 -0600826
827 @staticmethod
828 def WriteDocs(modules, test_missing=None):
829 """Write out documentation about the various entry types to stdout
830
831 Args:
832 modules: List of modules to include
833 test_missing: Used for testing. This is a module to report
834 as missing
835 """
836 print('''Binman Entry Documentation
Simon Glassc4f8c282024-06-23 11:55:05 -0600837==========================
Simon Glass969616c2018-07-17 13:25:36 -0600838
839This file describes the entry types supported by binman. These entry types can
840be placed in an image one by one to build up a final firmware image. It is
841fairly easy to create new entry types. Just add a new file to the 'etype'
842directory. You can use the existing entries as examples.
843
844Note that some entries are subclasses of others, using and extending their
845features to produce new behaviours.
846
847
848''')
849 modules = sorted(modules)
850
851 # Don't show the test entry
852 if '_testing' in modules:
853 modules.remove('_testing')
854 missing = []
855 for name in modules:
Simon Glass2f859412021-03-18 20:25:04 +1300856 module = Entry.Lookup('WriteDocs', name, False)
Simon Glass969616c2018-07-17 13:25:36 -0600857 docs = getattr(module, '__doc__')
858 if test_missing == name:
859 docs = None
860 if docs:
861 lines = docs.splitlines()
862 first_line = lines[0]
863 rest = [line[4:] for line in lines[1:]]
864 hdr = 'Entry: %s: %s' % (name.replace('_', '-'), first_line)
Simon Glassa7c97782022-08-07 16:33:25 -0600865
866 # Create a reference for use by rST docs
867 ref_name = f'etype_{module.__name__[6:]}'.lower()
868 print('.. _%s:' % ref_name)
869 print()
Simon Glass969616c2018-07-17 13:25:36 -0600870 print(hdr)
871 print('-' * len(hdr))
872 print('\n'.join(rest))
873 print()
874 print()
875 else:
876 missing.append(name)
877
878 if missing:
879 raise ValueError('Documentation is missing for modules: %s' %
880 ', '.join(missing))
Simon Glass639505b2018-09-14 04:57:11 -0600881
882 def GetUniqueName(self):
883 """Get a unique name for a node
884
885 Returns:
886 String containing a unique name for a node, consisting of the name
887 of all ancestors (starting from within the 'binman' node) separated
888 by a dot ('.'). This can be useful for generating unique filesnames
889 in the output directory.
890 """
891 name = self.name
892 node = self._node
893 while node.parent:
894 node = node.parent
Alper Nebi Yasak5cff63f2022-03-27 18:31:44 +0300895 if node.name in ('binman', '/'):
Simon Glass639505b2018-09-14 04:57:11 -0600896 break
897 name = '%s.%s' % (node.name, name)
898 return name
Simon Glassfa79a812018-09-14 04:57:29 -0600899
Simon Glassdd156a42022-03-05 20:18:59 -0700900 def extend_to_limit(self, limit):
901 """Extend an entry so that it ends at the given offset limit"""
Simon Glassfa79a812018-09-14 04:57:29 -0600902 if self.offset + self.size < limit:
903 self.size = limit - self.offset
904 # Request the contents again, since changing the size requires that
905 # the data grows. This should not fail, but check it to be sure.
906 if not self.ObtainContents():
907 self.Raise('Cannot obtain contents when expanding entry')
Simon Glassc4056b82019-07-08 13:18:38 -0600908
909 def HasSibling(self, name):
910 """Check if there is a sibling of a given name
911
912 Returns:
913 True if there is an entry with this name in the the same section,
914 else False
915 """
916 return name in self.section.GetEntries()
Simon Glasscec34ba2019-07-08 14:25:28 -0600917
918 def GetSiblingImagePos(self, name):
919 """Return the image position of the given sibling
920
921 Returns:
922 Image position of sibling, or None if the sibling has no position,
923 or False if there is no such sibling
924 """
925 if not self.HasSibling(name):
926 return False
927 return self.section.GetEntries()[name].image_pos
Simon Glass6b156f82019-07-08 14:25:43 -0600928
929 @staticmethod
930 def AddEntryInfo(entries, indent, name, etype, size, image_pos,
931 uncomp_size, offset, entry):
932 """Add a new entry to the entries list
933
934 Args:
935 entries: List (of EntryInfo objects) to add to
936 indent: Current indent level to add to list
937 name: Entry name (string)
938 etype: Entry type (string)
939 size: Entry size in bytes (int)
940 image_pos: Position within image in bytes (int)
941 uncomp_size: Uncompressed size if the entry uses compression, else
942 None
943 offset: Entry offset within parent in bytes (int)
944 entry: Entry object
945 """
946 entries.append(EntryInfo(indent, name, etype, size, image_pos,
947 uncomp_size, offset, entry))
948
949 def ListEntries(self, entries, indent):
950 """Add files in this entry to the list of entries
951
952 This can be overridden by subclasses which need different behaviour.
953
954 Args:
955 entries: List (of EntryInfo objects) to add to
956 indent: Current indent level to add to list
957 """
958 self.AddEntryInfo(entries, indent, self.name, self.etype, self.size,
959 self.image_pos, self.uncomp_size, self.offset, self)
Simon Glass4c613bf2019-07-08 14:25:50 -0600960
Simon Glass637958f2021-11-23 21:09:50 -0700961 def ReadData(self, decomp=True, alt_format=None):
Simon Glass4c613bf2019-07-08 14:25:50 -0600962 """Read the data for an entry from the image
963
964 This is used when the image has been read in and we want to extract the
965 data for a particular entry from that image.
966
967 Args:
968 decomp: True to decompress any compressed data before returning it;
969 False to return the raw, uncompressed data
970
971 Returns:
972 Entry data (bytes)
973 """
974 # Use True here so that we get an uncompressed section to work from,
975 # although compressed sections are currently not supported
Simon Glass011f1b32022-01-29 14:14:15 -0700976 tout.debug("ReadChildData section '%s', entry '%s'" %
Simon Glass4d8151f2019-09-25 08:56:21 -0600977 (self.section.GetPath(), self.GetPath()))
Simon Glass637958f2021-11-23 21:09:50 -0700978 data = self.section.ReadChildData(self, decomp, alt_format)
Simon Glass0cd8ace2019-07-20 12:24:04 -0600979 return data
Simon Glassaf8c45c2019-07-20 12:23:41 -0600980
Simon Glass637958f2021-11-23 21:09:50 -0700981 def ReadChildData(self, child, decomp=True, alt_format=None):
Simon Glass4d8151f2019-09-25 08:56:21 -0600982 """Read the data for a particular child entry
Simon Glass23f00472019-09-25 08:56:20 -0600983
984 This reads data from the parent and extracts the piece that relates to
985 the given child.
986
987 Args:
Simon Glass637958f2021-11-23 21:09:50 -0700988 child (Entry): Child entry to read data for (must be valid)
989 decomp (bool): True to decompress any compressed data before
990 returning it; False to return the raw, uncompressed data
991 alt_format (str): Alternative format to read in, or None
Simon Glass23f00472019-09-25 08:56:20 -0600992
993 Returns:
994 Data for the child (bytes)
995 """
996 pass
997
Simon Glassaf8c45c2019-07-20 12:23:41 -0600998 def LoadData(self, decomp=True):
999 data = self.ReadData(decomp)
Simon Glass072959a2019-07-20 12:23:50 -06001000 self.contents_size = len(data)
Simon Glassaf8c45c2019-07-20 12:23:41 -06001001 self.ProcessContentsUpdate(data)
1002 self.Detail('Loaded data size %x' % len(data))
Simon Glass990b1742019-07-20 12:23:46 -06001003
Simon Glass637958f2021-11-23 21:09:50 -07001004 def GetAltFormat(self, data, alt_format):
1005 """Read the data for an extry in an alternative format
1006
1007 Supported formats are list in the documentation for each entry. An
1008 example is fdtmap which provides .
1009
1010 Args:
1011 data (bytes): Data to convert (this should have been produced by the
1012 entry)
1013 alt_format (str): Format to use
1014
1015 """
1016 pass
1017
Simon Glass990b1742019-07-20 12:23:46 -06001018 def GetImage(self):
1019 """Get the image containing this entry
1020
1021 Returns:
1022 Image object containing this entry
1023 """
1024 return self.section.GetImage()
Simon Glass072959a2019-07-20 12:23:50 -06001025
1026 def WriteData(self, data, decomp=True):
1027 """Write the data to an entry in the image
1028
1029 This is used when the image has been read in and we want to replace the
1030 data for a particular entry in that image.
1031
1032 The image must be re-packed and written out afterwards.
1033
1034 Args:
1035 data: Data to replace it with
1036 decomp: True to compress the data if needed, False if data is
1037 already compressed so should be used as is
1038
1039 Returns:
1040 True if the data did not result in a resize of this entry, False if
1041 the entry must be resized
1042 """
Simon Glass1fdb4872019-10-31 07:43:02 -06001043 if self.size is not None:
1044 self.contents_size = self.size
1045 else:
1046 self.contents_size = self.pre_reset_size
Simon Glass072959a2019-07-20 12:23:50 -06001047 ok = self.ProcessContentsUpdate(data)
Simon Glass49b77e82023-03-02 17:02:44 -07001048 self.build_done = False
Simon Glass072959a2019-07-20 12:23:50 -06001049 self.Detail('WriteData: size=%x, ok=%s' % (len(data), ok))
Simon Glassd34af7a2019-07-20 12:24:05 -06001050 section_ok = self.section.WriteChildData(self)
1051 return ok and section_ok
1052
1053 def WriteChildData(self, child):
1054 """Handle writing the data in a child entry
1055
1056 This should be called on the child's parent section after the child's
Simon Glasse796f242021-11-23 11:03:44 -07001057 data has been updated. It should update any data structures needed to
1058 validate that the update is successful.
Simon Glassd34af7a2019-07-20 12:24:05 -06001059
1060 This base-class implementation does nothing, since the base Entry object
1061 does not have any children.
1062
1063 Args:
1064 child: Child Entry that was written
1065
1066 Returns:
1067 True if the section could be updated successfully, False if the
Simon Glasse796f242021-11-23 11:03:44 -07001068 data is such that the section could not update
Simon Glassd34af7a2019-07-20 12:24:05 -06001069 """
Simon Glass49b77e82023-03-02 17:02:44 -07001070 self.build_done = False
1071 entry = self.section
1072
1073 # Now we must rebuild all sections above this one
1074 while entry and entry != entry.section:
1075 self.build_done = False
1076 entry = entry.section
1077
Simon Glassd34af7a2019-07-20 12:24:05 -06001078 return True
Simon Glass11453762019-07-20 12:23:55 -06001079
1080 def GetSiblingOrder(self):
1081 """Get the relative order of an entry amoung its siblings
1082
1083 Returns:
1084 'start' if this entry is first among siblings, 'end' if last,
1085 otherwise None
1086 """
1087 entries = list(self.section.GetEntries().values())
1088 if entries:
1089 if self == entries[0]:
1090 return 'start'
1091 elif self == entries[-1]:
1092 return 'end'
1093 return 'middle'
Simon Glass5d94cc62020-07-09 18:39:38 -06001094
1095 def SetAllowMissing(self, allow_missing):
1096 """Set whether a section allows missing external blobs
1097
1098 Args:
1099 allow_missing: True if allowed, False if not allowed
1100 """
1101 # This is meaningless for anything other than sections
1102 pass
Simon Glassa003cd32020-07-09 18:39:40 -06001103
Heiko Thiery6d451362022-01-06 11:49:41 +01001104 def SetAllowFakeBlob(self, allow_fake):
1105 """Set whether a section allows to create a fake blob
1106
1107 Args:
1108 allow_fake: True if allowed, False if not allowed
1109 """
Simon Glassceb5f912022-01-09 20:13:46 -07001110 self.allow_fake = allow_fake
Heiko Thiery6d451362022-01-06 11:49:41 +01001111
Simon Glassa003cd32020-07-09 18:39:40 -06001112 def CheckMissing(self, missing_list):
Simon Glass63328f12023-01-07 14:07:15 -07001113 """Check if the entry has missing external blobs
Simon Glassa003cd32020-07-09 18:39:40 -06001114
Simon Glass63328f12023-01-07 14:07:15 -07001115 If there are missing (non-optional) blobs, the entries are added to the
1116 list
Simon Glassa003cd32020-07-09 18:39:40 -06001117
1118 Args:
1119 missing_list: List of Entry objects to be added to
1120 """
Simon Glass63328f12023-01-07 14:07:15 -07001121 if self.missing and not self.optional:
Simon Glassa003cd32020-07-09 18:39:40 -06001122 missing_list.append(self)
Simon Glassb8f90372020-09-01 05:13:57 -06001123
Yannic Moog319dc292025-06-13 14:02:40 +02001124 def check_fake_fname(self, fname: str, size: int = 0) -> str:
Simon Glass7a602fd2022-01-12 13:10:36 -07001125 """If the file is missing and the entry allows fake blobs, fake it
1126
1127 Sets self.faked to True if faked
1128
1129 Args:
1130 fname (str): Filename to check
Simon Glass8c0533b2022-03-05 20:19:04 -07001131 size (int): Size of fake file to create
Simon Glass7a602fd2022-01-12 13:10:36 -07001132
1133 Returns:
Yannic Moog319dc292025-06-13 14:02:40 +02001134 fname (str): Filename of faked file
Simon Glass7a602fd2022-01-12 13:10:36 -07001135 """
1136 if self.allow_fake and not pathlib.Path(fname).is_file():
Simon Glass7d3e4072022-08-07 09:46:46 -06001137 if not self.fake_fname:
1138 outfname = os.path.join(self.fake_dir, os.path.basename(fname))
1139 with open(outfname, "wb") as out:
1140 out.truncate(size)
1141 tout.info(f"Entry '{self._node.path}': Faked blob '{outfname}'")
1142 self.fake_fname = outfname
Simon Glass7a602fd2022-01-12 13:10:36 -07001143 self.faked = True
Yannic Moog319dc292025-06-13 14:02:40 +02001144 return self.fake_fname
1145 return fname
Simon Glass7a602fd2022-01-12 13:10:36 -07001146
Heiko Thiery6d451362022-01-06 11:49:41 +01001147 def CheckFakedBlobs(self, faked_blobs_list):
1148 """Check if any entries in this section have faked external blobs
1149
1150 If there are faked blobs, the entries are added to the list
1151
1152 Args:
Jonas Karlmanf2c52eb2023-02-19 22:02:04 +00001153 faked_blobs_list: List of Entry objects to be added to
Heiko Thiery6d451362022-01-06 11:49:41 +01001154 """
1155 # This is meaningless for anything other than blobs
1156 pass
1157
Simon Glass63328f12023-01-07 14:07:15 -07001158 def CheckOptional(self, optional_list):
1159 """Check if the entry has missing but optional external blobs
1160
1161 If there are missing (optional) blobs, the entries are added to the list
1162
1163 Args:
1164 optional_list (list): List of Entry objects to be added to
1165 """
1166 if self.missing and self.optional:
1167 optional_list.append(self)
1168
Simon Glassb8f90372020-09-01 05:13:57 -06001169 def GetAllowMissing(self):
1170 """Get whether a section allows missing external blobs
1171
1172 Returns:
1173 True if allowed, False if not allowed
1174 """
1175 return self.allow_missing
Simon Glassa820af72020-09-06 10:39:09 -06001176
Simon Glass66152ce2022-01-09 20:14:09 -07001177 def record_missing_bintool(self, bintool):
1178 """Record a missing bintool that was needed to produce this entry
1179
1180 Args:
1181 bintool (Bintool): Bintool that was missing
1182 """
Stefan Herbrechtsmeier486b9442022-08-19 16:25:19 +02001183 if bintool not in self.missing_bintools:
1184 self.missing_bintools.append(bintool)
Simon Glass66152ce2022-01-09 20:14:09 -07001185
1186 def check_missing_bintools(self, missing_list):
1187 """Check if any entries in this section have missing bintools
1188
1189 If there are missing bintools, these are added to the list
1190
1191 Args:
1192 missing_list: List of Bintool objects to be added to
1193 """
Stefan Herbrechtsmeier486b9442022-08-19 16:25:19 +02001194 for bintool in self.missing_bintools:
1195 if bintool not in missing_list:
1196 missing_list.append(bintool)
1197
Simon Glass66152ce2022-01-09 20:14:09 -07001198
Simon Glassa820af72020-09-06 10:39:09 -06001199 def GetHelpTags(self):
1200 """Get the tags use for missing-blob help
1201
1202 Returns:
1203 list of possible tags, most desirable first
1204 """
1205 return list(filter(None, [self.missing_msg, self.name, self.etype]))
Simon Glassa1301a22020-10-26 17:40:06 -06001206
1207 def CompressData(self, indata):
1208 """Compress data according to the entry's compression method
1209
1210 Args:
1211 indata: Data to compress
1212
1213 Returns:
Stefan Herbrechtsmeierb2f8d612022-08-19 16:25:27 +02001214 Compressed data
Simon Glassa1301a22020-10-26 17:40:06 -06001215 """
Simon Glass789b34402020-10-26 17:40:15 -06001216 self.uncomp_data = indata
Simon Glassa1301a22020-10-26 17:40:06 -06001217 if self.compress != 'none':
1218 self.uncomp_size = len(indata)
Stefan Herbrechtsmeier94813a02022-08-19 16:25:31 +02001219 if self.comp_bintool.is_present():
1220 data = self.comp_bintool.compress(indata)
Simon Glassd3cd5cc2024-07-20 11:49:37 +01001221 uniq = self.GetUniqueName()
1222 fname = tools.get_output_filename(f'comp.{uniq}')
1223 tools.write_file(fname, data)
Stefan Herbrechtsmeier94813a02022-08-19 16:25:31 +02001224 else:
1225 self.record_missing_bintool(self.comp_bintool)
1226 data = tools.get_bytes(0, 1024)
Stefan Herbrechtsmeiera6e0b502022-08-19 16:25:30 +02001227 else:
1228 data = indata
Simon Glassa1301a22020-10-26 17:40:06 -06001229 return data
Simon Glass2f859412021-03-18 20:25:04 +13001230
Stefan Herbrechtsmeier7f128a72022-08-19 16:25:24 +02001231 def DecompressData(self, indata):
1232 """Decompress data according to the entry's compression method
1233
1234 Args:
1235 indata: Data to decompress
1236
1237 Returns:
1238 Decompressed data
1239 """
Stefan Herbrechtsmeier7f128a72022-08-19 16:25:24 +02001240 if self.compress != 'none':
Stefan Herbrechtsmeier94813a02022-08-19 16:25:31 +02001241 if self.comp_bintool.is_present():
1242 data = self.comp_bintool.decompress(indata)
1243 self.uncomp_size = len(data)
1244 else:
1245 self.record_missing_bintool(self.comp_bintool)
1246 data = tools.get_bytes(0, 1024)
Stefan Herbrechtsmeiera6e0b502022-08-19 16:25:30 +02001247 else:
1248 data = indata
Stefan Herbrechtsmeier7f128a72022-08-19 16:25:24 +02001249 self.uncomp_data = data
1250 return data
1251
Simon Glass2f859412021-03-18 20:25:04 +13001252 @classmethod
1253 def UseExpanded(cls, node, etype, new_etype):
1254 """Check whether to use an expanded entry type
1255
1256 This is called by Entry.Create() when it finds an expanded version of
1257 an entry type (e.g. 'u-boot-expanded'). If this method returns True then
1258 it will be used (e.g. in place of 'u-boot'). If it returns False, it is
1259 ignored.
1260
1261 Args:
1262 node: Node object containing information about the entry to
1263 create
1264 etype: Original entry type being used
1265 new_etype: New entry type proposed
1266
1267 Returns:
1268 True to use this entry type, False to use the original one
1269 """
Simon Glass011f1b32022-01-29 14:14:15 -07001270 tout.info("Node '%s': etype '%s': %s selected" %
Simon Glass2f859412021-03-18 20:25:04 +13001271 (node.path, etype, new_etype))
1272 return True
Simon Glass637958f2021-11-23 21:09:50 -07001273
1274 def CheckAltFormats(self, alt_formats):
1275 """Add any alternative formats supported by this entry type
1276
1277 Args:
1278 alt_formats (dict): Dict to add alt_formats to:
1279 key: Name of alt format
1280 value: Help text
1281 """
1282 pass
Simon Glass4eae9252022-01-09 20:13:50 -07001283
Simon Glassfff147a2022-03-05 20:19:02 -07001284 def AddBintools(self, btools):
Simon Glass4eae9252022-01-09 20:13:50 -07001285 """Add the bintools used by this entry type
1286
1287 Args:
Simon Glassfff147a2022-03-05 20:19:02 -07001288 btools (dict of Bintool):
Stefan Herbrechtsmeiera6e0b502022-08-19 16:25:30 +02001289
1290 Raise:
1291 ValueError if compression algorithm is not supported
Simon Glass4eae9252022-01-09 20:13:50 -07001292 """
Stefan Herbrechtsmeiera6e0b502022-08-19 16:25:30 +02001293 algo = self.compress
1294 if algo != 'none':
Stefan Herbrechtsmeiera5e4dcb2022-08-19 16:25:38 +02001295 algos = ['bzip2', 'gzip', 'lz4', 'lzma', 'lzo', 'xz', 'zstd']
Stefan Herbrechtsmeiera6e0b502022-08-19 16:25:30 +02001296 if algo not in algos:
1297 raise ValueError("Unknown algorithm '%s'" % algo)
Stefan Herbrechtsmeier9087fc52022-08-19 16:25:36 +02001298 names = {'lzma': 'lzma_alone', 'lzo': 'lzop'}
Stefan Herbrechtsmeiera6e0b502022-08-19 16:25:30 +02001299 name = names.get(self.compress, self.compress)
1300 self.comp_bintool = self.AddBintool(btools, name)
Simon Glass4eae9252022-01-09 20:13:50 -07001301
1302 @classmethod
1303 def AddBintool(self, tools, name):
1304 """Add a new bintool to the tools used by this etype
1305
1306 Args:
1307 name: Name of the tool
1308 """
1309 btool = bintool.Bintool.create(name)
1310 tools[name] = btool
1311 return btool
Alper Nebi Yasak1e4ffd82022-02-09 22:02:35 +03001312
1313 def SetUpdateHash(self, update_hash):
1314 """Set whether this entry's "hash" subnode should be updated
1315
1316 Args:
1317 update_hash: True if hash should be updated, False if not
1318 """
1319 self.update_hash = update_hash
Simon Glass6fba35c2022-02-08 11:50:00 -07001320
Simon Glassfc5a1682022-03-05 20:19:05 -07001321 def collect_contents_to_file(self, entries, prefix, fake_size=0):
Simon Glass6fba35c2022-02-08 11:50:00 -07001322 """Put the contents of a list of entries into a file
1323
1324 Args:
1325 entries (list of Entry): Entries to collect
1326 prefix (str): Filename prefix of file to write to
Simon Glassfc5a1682022-03-05 20:19:05 -07001327 fake_size (int): Size of fake file to create if needed
Simon Glass6fba35c2022-02-08 11:50:00 -07001328
1329 If any entry does not have contents yet, this function returns False
1330 for the data.
1331
1332 Returns:
1333 Tuple:
Simon Glass43a98cc2022-03-05 20:18:58 -07001334 bytes: Concatenated data from all the entries (or None)
1335 str: Filename of file written (or None if no data)
1336 str: Unique portion of filename (or None if no data)
Simon Glass6fba35c2022-02-08 11:50:00 -07001337 """
1338 data = b''
1339 for entry in entries:
Simon Glass6fba35c2022-02-08 11:50:00 -07001340 data += entry.GetData()
1341 uniq = self.GetUniqueName()
1342 fname = tools.get_output_filename(f'{prefix}.{uniq}')
1343 tools.write_file(fname, data)
1344 return data, fname, uniq
Simon Glass7d3e4072022-08-07 09:46:46 -06001345
1346 @classmethod
1347 def create_fake_dir(cls):
1348 """Create the directory for fake files"""
1349 cls.fake_dir = tools.get_output_filename('binman-fake')
1350 if not os.path.exists(cls.fake_dir):
1351 os.mkdir(cls.fake_dir)
1352 tout.notice(f"Fake-blob dir is '{cls.fake_dir}'")
Simon Glass0cf5bce2022-08-13 11:40:44 -06001353
1354 def ensure_props(self):
1355 """Raise an exception if properties are missing
1356
1357 Args:
1358 prop_list (list of str): List of properties to check for
1359
1360 Raises:
1361 ValueError: Any property is missing
1362 """
1363 not_present = []
1364 for prop in self.required_props:
1365 if not prop in self._node.props:
1366 not_present.append(prop)
1367 if not_present:
1368 self.Raise(f"'{self.etype}' entry is missing properties: {' '.join(not_present)}")
Simon Glass1e9e61c2023-01-07 14:07:12 -07001369
1370 def mark_absent(self, msg):
1371 tout.info("Entry '%s' marked absent: %s" % (self._node.path, msg))
1372 self.absent = True
Simon Glassad5cfe12023-01-07 14:07:14 -07001373
1374 def read_elf_segments(self):
1375 """Read segments from an entry that can generate an ELF file
1376
1377 Returns:
1378 tuple:
1379 list of segments, each:
1380 int: Segment number (0 = first)
1381 int: Start address of segment in memory
1382 bytes: Contents of segment
1383 int: entry address of ELF file
1384 """
1385 return None
Simon Glass49e9c002023-01-11 16:10:19 -07001386
1387 def lookup_offset(self):
1388 node, sym_name, offset = self.offset_from_elf
1389 entry = self.section.FindEntryByNode(node)
1390 if not entry:
1391 self.Raise("Cannot find entry for node '%s'" % node.name)
1392 if not entry.elf_fname:
1393 entry.Raise("Need elf-fname property '%s'" % node.name)
1394 val = elf.GetSymbolOffset(entry.elf_fname, sym_name,
1395 entry.elf_base_sym)
1396 return val + offset
Simon Glass49b77e82023-03-02 17:02:44 -07001397
1398 def mark_build_done(self):
1399 """Mark an entry as already built"""
1400 self.build_done = True
1401 entries = self.GetEntries()
1402 if entries:
1403 for entry in entries.values():
1404 entry.mark_build_done()
Ivan Mikhaylov3cfcaa4d2023-03-08 01:13:40 +00001405
1406 def UpdateSignatures(self, privatekey_fname, algo, input_fname):
1407 self.Raise('Updating signatures is not supported with this entry type')
Simon Glass7b72c912024-07-20 11:49:44 +01001408
1409 def FdtContents(self, fdt_etype):
1410 """Get the contents of an FDT for a particular phase
1411
1412 Args:
1413 fdt_etype (str): Filename of the phase of the FDT to return, e.g.
1414 'u-boot-tpl-dtb'
1415
1416 Returns:
Simon Glassf3598922024-07-20 11:49:45 +01001417 tuple:
1418 fname (str): Filename of .dtb
1419 bytes: Contents of FDT (possibly run through fdtgrep)
Simon Glass7b72c912024-07-20 11:49:44 +01001420 """
1421 return self.section.FdtContents(fdt_etype)