blob: 00bb1d190a97841406584a8d22ef8753d891903b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glassbf7fd502016-11-25 20:15:51 -07002# Copyright (c) 2016 Google, Inc
3#
Simon Glassbf7fd502016-11-25 20:15:51 -07004# Base class for all entries
5#
6
Simon Glass3b0c3822018-06-01 09:38:20 -06007from __future__ import print_function
8
Simon Glass53af22a2018-07-17 13:25:32 -06009from collections import namedtuple
10
Simon Glassbf7fd502016-11-25 20:15:51 -070011# importlib was introduced in Python 2.7 but there was a report of it not
12# working in 2.7.12, so we work around this:
13# http://lists.denx.de/pipermail/u-boot/2016-October/269729.html
14try:
15 import importlib
16 have_importlib = True
17except:
18 have_importlib = False
19
Simon Glassbadf0ec2018-06-01 09:38:15 -060020import os
21import sys
Simon Glassc55a50f2018-09-14 04:57:19 -060022
23import fdt_util
24import state
Simon Glassbf7fd502016-11-25 20:15:51 -070025import tools
26
27modules = {}
28
Simon Glassbadf0ec2018-06-01 09:38:15 -060029our_path = os.path.dirname(os.path.realpath(__file__))
30
Simon Glass53af22a2018-07-17 13:25:32 -060031
32# An argument which can be passed to entries on the command line, in lieu of
33# device-tree properties.
34EntryArg = namedtuple('EntryArg', ['name', 'datatype'])
35
36
Simon Glassbf7fd502016-11-25 20:15:51 -070037class Entry(object):
Simon Glass25ac0e62018-06-01 09:38:14 -060038 """An Entry in the section
Simon Glassbf7fd502016-11-25 20:15:51 -070039
40 An entry corresponds to a single node in the device-tree description
Simon Glass25ac0e62018-06-01 09:38:14 -060041 of the section. Each entry ends up being a part of the final section.
Simon Glassbf7fd502016-11-25 20:15:51 -070042 Entries can be placed either right next to each other, or with padding
43 between them. The type of the entry determines the data that is in it.
44
45 This class is not used by itself. All entry objects are subclasses of
46 Entry.
47
48 Attributes:
Simon Glass8122f392018-07-17 13:25:28 -060049 section: Section object containing this entry
Simon Glassbf7fd502016-11-25 20:15:51 -070050 node: The node that created this entry
Simon Glass3ab95982018-08-01 15:22:37 -060051 offset: Offset of entry within the section, None if not known yet (in
52 which case it will be calculated by Pack())
Simon Glassbf7fd502016-11-25 20:15:51 -070053 size: Entry size in bytes, None if not known
Simon Glass8287ee82019-07-08 14:25:30 -060054 uncomp_size: Size of uncompressed data in bytes, if the entry is
55 compressed, else None
Simon Glassbf7fd502016-11-25 20:15:51 -070056 contents_size: Size of contents in bytes, 0 by default
Simon Glass3ab95982018-08-01 15:22:37 -060057 align: Entry start offset alignment, or None
Simon Glassbf7fd502016-11-25 20:15:51 -070058 align_size: Entry size alignment, or None
Simon Glass3ab95982018-08-01 15:22:37 -060059 align_end: Entry end offset alignment, or None
Simon Glassbf7fd502016-11-25 20:15:51 -070060 pad_before: Number of pad bytes before the contents, 0 if none
61 pad_after: Number of pad bytes after the contents, 0 if none
62 data: Contents of entry (string of bytes)
Simon Glass8287ee82019-07-08 14:25:30 -060063 compress: Compression algoithm used (e.g. 'lz4'), 'none' if none
Simon Glassbf7fd502016-11-25 20:15:51 -070064 """
Simon Glassc8d48ef2018-06-01 09:38:21 -060065 def __init__(self, section, etype, node, read_node=True, name_prefix=''):
Simon Glass25ac0e62018-06-01 09:38:14 -060066 self.section = section
Simon Glassbf7fd502016-11-25 20:15:51 -070067 self.etype = etype
68 self._node = node
Simon Glassc8d48ef2018-06-01 09:38:21 -060069 self.name = node and (name_prefix + node.name) or 'none'
Simon Glass3ab95982018-08-01 15:22:37 -060070 self.offset = None
Simon Glassbf7fd502016-11-25 20:15:51 -070071 self.size = None
Simon Glass8287ee82019-07-08 14:25:30 -060072 self.uncomp_size = None
Simon Glass24d0d3c2018-07-17 13:25:47 -060073 self.data = None
Simon Glassbf7fd502016-11-25 20:15:51 -070074 self.contents_size = 0
75 self.align = None
76 self.align_size = None
77 self.align_end = None
78 self.pad_before = 0
79 self.pad_after = 0
Simon Glass3ab95982018-08-01 15:22:37 -060080 self.offset_unset = False
Simon Glassdbf6be92018-08-01 15:22:42 -060081 self.image_pos = None
Simon Glassba64a0b2018-09-14 04:57:29 -060082 self._expand_size = False
Simon Glass8287ee82019-07-08 14:25:30 -060083 self.compress = 'none'
Simon Glassbf7fd502016-11-25 20:15:51 -070084 if read_node:
85 self.ReadNode()
86
87 @staticmethod
Simon Glassc073ced2019-07-08 14:25:31 -060088 def Lookup(node_path, etype):
Simon Glassfd8d1f72018-07-17 13:25:36 -060089 """Look up the entry class for a node.
Simon Glassbf7fd502016-11-25 20:15:51 -070090
91 Args:
Simon Glassfd8d1f72018-07-17 13:25:36 -060092 node_node: Path name of Node object containing information about
93 the entry to create (used for errors)
94 etype: Entry type to use
Simon Glassbf7fd502016-11-25 20:15:51 -070095
96 Returns:
Simon Glassfd8d1f72018-07-17 13:25:36 -060097 The entry class object if found, else None
Simon Glassbf7fd502016-11-25 20:15:51 -070098 """
Simon Glassdd57c132018-06-01 09:38:11 -060099 # Convert something like 'u-boot@0' to 'u_boot' since we are only
100 # interested in the type.
Simon Glassbf7fd502016-11-25 20:15:51 -0700101 module_name = etype.replace('-', '_')
Simon Glassdd57c132018-06-01 09:38:11 -0600102 if '@' in module_name:
103 module_name = module_name.split('@')[0]
Simon Glassbf7fd502016-11-25 20:15:51 -0700104 module = modules.get(module_name)
105
Simon Glassbadf0ec2018-06-01 09:38:15 -0600106 # Also allow entry-type modules to be brought in from the etype directory.
107
Simon Glassbf7fd502016-11-25 20:15:51 -0700108 # Import the module if we have not already done so.
109 if not module:
Simon Glassbadf0ec2018-06-01 09:38:15 -0600110 old_path = sys.path
111 sys.path.insert(0, os.path.join(our_path, 'etype'))
Simon Glassbf7fd502016-11-25 20:15:51 -0700112 try:
113 if have_importlib:
114 module = importlib.import_module(module_name)
115 else:
116 module = __import__(module_name)
Simon Glassfd8d1f72018-07-17 13:25:36 -0600117 except ImportError as e:
118 raise ValueError("Unknown entry type '%s' in node '%s' (expected etype/%s.py, error '%s'" %
119 (etype, node_path, module_name, e))
Simon Glassbadf0ec2018-06-01 09:38:15 -0600120 finally:
121 sys.path = old_path
Simon Glassbf7fd502016-11-25 20:15:51 -0700122 modules[module_name] = module
123
Simon Glassfd8d1f72018-07-17 13:25:36 -0600124 # Look up the expected class name
125 return getattr(module, 'Entry_%s' % module_name)
126
127 @staticmethod
128 def Create(section, node, etype=None):
129 """Create a new entry for a node.
130
131 Args:
132 section: Section object containing this node
133 node: Node object containing information about the entry to
134 create
135 etype: Entry type to use, or None to work it out (used for tests)
136
137 Returns:
138 A new Entry object of the correct type (a subclass of Entry)
139 """
140 if not etype:
141 etype = fdt_util.GetString(node, 'type', node.name)
Simon Glassc073ced2019-07-08 14:25:31 -0600142 obj = Entry.Lookup(node.path, etype)
Simon Glassfd8d1f72018-07-17 13:25:36 -0600143
Simon Glassbf7fd502016-11-25 20:15:51 -0700144 # Call its constructor to get the object we want.
Simon Glass25ac0e62018-06-01 09:38:14 -0600145 return obj(section, etype, node)
Simon Glassbf7fd502016-11-25 20:15:51 -0700146
147 def ReadNode(self):
148 """Read entry information from the node
149
150 This reads all the fields we recognise from the node, ready for use.
151 """
Simon Glass15a587c2018-07-17 13:25:51 -0600152 if 'pos' in self._node.props:
153 self.Raise("Please use 'offset' instead of 'pos'")
Simon Glass3ab95982018-08-01 15:22:37 -0600154 self.offset = fdt_util.GetInt(self._node, 'offset')
Simon Glassbf7fd502016-11-25 20:15:51 -0700155 self.size = fdt_util.GetInt(self._node, 'size')
156 self.align = fdt_util.GetInt(self._node, 'align')
157 if tools.NotPowerOfTwo(self.align):
158 raise ValueError("Node '%s': Alignment %s must be a power of two" %
159 (self._node.path, self.align))
160 self.pad_before = fdt_util.GetInt(self._node, 'pad-before', 0)
161 self.pad_after = fdt_util.GetInt(self._node, 'pad-after', 0)
162 self.align_size = fdt_util.GetInt(self._node, 'align-size')
163 if tools.NotPowerOfTwo(self.align_size):
164 raise ValueError("Node '%s': Alignment size %s must be a power "
165 "of two" % (self._node.path, self.align_size))
166 self.align_end = fdt_util.GetInt(self._node, 'align-end')
Simon Glass3ab95982018-08-01 15:22:37 -0600167 self.offset_unset = fdt_util.GetBool(self._node, 'offset-unset')
Simon Glassba64a0b2018-09-14 04:57:29 -0600168 self.expand_size = fdt_util.GetBool(self._node, 'expand-size')
Simon Glassbf7fd502016-11-25 20:15:51 -0700169
Simon Glass6c234bf2018-09-14 04:57:18 -0600170 def GetDefaultFilename(self):
171 return None
172
Simon Glass539aece2018-09-14 04:57:22 -0600173 def GetFdtSet(self):
174 """Get the set of device trees used by this entry
175
176 Returns:
177 Set containing the filename from this entry, if it is a .dtb, else
178 an empty set
179 """
180 fname = self.GetDefaultFilename()
181 # It would be better to use isinstance(self, Entry_blob_dtb) here but
182 # we cannot access Entry_blob_dtb
183 if fname and fname.endswith('.dtb'):
Simon Glassd141f6c2019-05-14 15:53:39 -0600184 return set([fname])
185 return set()
Simon Glass539aece2018-09-14 04:57:22 -0600186
Simon Glass0a98b282018-09-14 04:57:28 -0600187 def ExpandEntries(self):
188 pass
189
Simon Glass078ab1a2018-07-06 10:27:41 -0600190 def AddMissingProperties(self):
191 """Add new properties to the device tree as needed for this entry"""
Simon Glassdbf6be92018-08-01 15:22:42 -0600192 for prop in ['offset', 'size', 'image-pos']:
Simon Glass078ab1a2018-07-06 10:27:41 -0600193 if not prop in self._node.props:
Simon Glassf46621d2018-09-14 04:57:21 -0600194 state.AddZeroProp(self._node, prop)
Simon Glass8287ee82019-07-08 14:25:30 -0600195 if self.compress != 'none':
196 state.AddZeroProp(self._node, 'uncomp-size')
Simon Glasse0e5df92018-09-14 04:57:31 -0600197 err = state.CheckAddHashProp(self._node)
198 if err:
199 self.Raise(err)
Simon Glass078ab1a2018-07-06 10:27:41 -0600200
201 def SetCalculatedProperties(self):
202 """Set the value of device-tree properties calculated by binman"""
Simon Glassf46621d2018-09-14 04:57:21 -0600203 state.SetInt(self._node, 'offset', self.offset)
204 state.SetInt(self._node, 'size', self.size)
Simon Glassf8f8df62018-09-14 04:57:34 -0600205 state.SetInt(self._node, 'image-pos',
206 self.image_pos - self.section.GetRootSkipAtStart())
Simon Glass8287ee82019-07-08 14:25:30 -0600207 if self.uncomp_size is not None:
208 state.SetInt(self._node, 'uncomp-size', self.uncomp_size)
Simon Glasse0e5df92018-09-14 04:57:31 -0600209 state.CheckSetHashValue(self._node, self.GetData)
Simon Glass078ab1a2018-07-06 10:27:41 -0600210
Simon Glassecab8972018-07-06 10:27:40 -0600211 def ProcessFdt(self, fdt):
Simon Glass6ed45ba2018-09-14 04:57:24 -0600212 """Allow entries to adjust the device tree
213
214 Some entries need to adjust the device tree for their purposes. This
215 may involve adding or deleting properties.
216
217 Returns:
218 True if processing is complete
219 False if processing could not be completed due to a dependency.
220 This will cause the entry to be retried after others have been
221 called
222 """
Simon Glassecab8972018-07-06 10:27:40 -0600223 return True
224
Simon Glassc8d48ef2018-06-01 09:38:21 -0600225 def SetPrefix(self, prefix):
226 """Set the name prefix for a node
227
228 Args:
229 prefix: Prefix to set, or '' to not use a prefix
230 """
231 if prefix:
232 self.name = prefix + self.name
233
Simon Glass5c890232018-07-06 10:27:19 -0600234 def SetContents(self, data):
235 """Set the contents of an entry
236
237 This sets both the data and content_size properties
238
239 Args:
240 data: Data to set to the contents (string)
241 """
242 self.data = data
243 self.contents_size = len(self.data)
244
245 def ProcessContentsUpdate(self, data):
246 """Update the contens of an entry, after the size is fixed
247
248 This checks that the new data is the same size as the old.
249
250 Args:
251 data: Data to set to the contents (string)
252
253 Raises:
254 ValueError if the new data size is not the same as the old
255 """
256 if len(data) != self.contents_size:
257 self.Raise('Cannot update entry size from %d to %d' %
258 (len(data), self.contents_size))
259 self.SetContents(data)
260
Simon Glassbf7fd502016-11-25 20:15:51 -0700261 def ObtainContents(self):
262 """Figure out the contents of an entry.
263
264 Returns:
265 True if the contents were found, False if another call is needed
266 after the other entries are processed.
267 """
268 # No contents by default: subclasses can implement this
269 return True
270
Simon Glass3ab95982018-08-01 15:22:37 -0600271 def Pack(self, offset):
Simon Glass25ac0e62018-06-01 09:38:14 -0600272 """Figure out how to pack the entry into the section
Simon Glassbf7fd502016-11-25 20:15:51 -0700273
274 Most of the time the entries are not fully specified. There may be
275 an alignment but no size. In that case we take the size from the
276 contents of the entry.
277
Simon Glass3ab95982018-08-01 15:22:37 -0600278 If an entry has no hard-coded offset, it will be placed at @offset.
Simon Glassbf7fd502016-11-25 20:15:51 -0700279
Simon Glass3ab95982018-08-01 15:22:37 -0600280 Once this function is complete, both the offset and size of the
Simon Glassbf7fd502016-11-25 20:15:51 -0700281 entry will be know.
282
283 Args:
Simon Glass3ab95982018-08-01 15:22:37 -0600284 Current section offset pointer
Simon Glassbf7fd502016-11-25 20:15:51 -0700285
286 Returns:
Simon Glass3ab95982018-08-01 15:22:37 -0600287 New section offset pointer (after this entry)
Simon Glassbf7fd502016-11-25 20:15:51 -0700288 """
Simon Glass3ab95982018-08-01 15:22:37 -0600289 if self.offset is None:
290 if self.offset_unset:
291 self.Raise('No offset set with offset-unset: should another '
292 'entry provide this correct offset?')
293 self.offset = tools.Align(offset, self.align)
Simon Glassbf7fd502016-11-25 20:15:51 -0700294 needed = self.pad_before + self.contents_size + self.pad_after
295 needed = tools.Align(needed, self.align_size)
296 size = self.size
297 if not size:
298 size = needed
Simon Glass3ab95982018-08-01 15:22:37 -0600299 new_offset = self.offset + size
300 aligned_offset = tools.Align(new_offset, self.align_end)
301 if aligned_offset != new_offset:
302 size = aligned_offset - self.offset
303 new_offset = aligned_offset
Simon Glassbf7fd502016-11-25 20:15:51 -0700304
305 if not self.size:
306 self.size = size
307
308 if self.size < needed:
309 self.Raise("Entry contents size is %#x (%d) but entry size is "
310 "%#x (%d)" % (needed, needed, self.size, self.size))
311 # Check that the alignment is correct. It could be wrong if the
Simon Glass3ab95982018-08-01 15:22:37 -0600312 # and offset or size values were provided (i.e. not calculated), but
Simon Glassbf7fd502016-11-25 20:15:51 -0700313 # conflict with the provided alignment values
314 if self.size != tools.Align(self.size, self.align_size):
315 self.Raise("Size %#x (%d) does not match align-size %#x (%d)" %
316 (self.size, self.size, self.align_size, self.align_size))
Simon Glass3ab95982018-08-01 15:22:37 -0600317 if self.offset != tools.Align(self.offset, self.align):
318 self.Raise("Offset %#x (%d) does not match align %#x (%d)" %
319 (self.offset, self.offset, self.align, self.align))
Simon Glassbf7fd502016-11-25 20:15:51 -0700320
Simon Glass3ab95982018-08-01 15:22:37 -0600321 return new_offset
Simon Glassbf7fd502016-11-25 20:15:51 -0700322
323 def Raise(self, msg):
324 """Convenience function to raise an error referencing a node"""
325 raise ValueError("Node '%s': %s" % (self._node.path, msg))
326
Simon Glass53af22a2018-07-17 13:25:32 -0600327 def GetEntryArgsOrProps(self, props, required=False):
328 """Return the values of a set of properties
329
330 Args:
331 props: List of EntryArg objects
332
333 Raises:
334 ValueError if a property is not found
335 """
336 values = []
337 missing = []
338 for prop in props:
339 python_prop = prop.name.replace('-', '_')
340 if hasattr(self, python_prop):
341 value = getattr(self, python_prop)
342 else:
343 value = None
344 if value is None:
345 value = self.GetArg(prop.name, prop.datatype)
346 if value is None and required:
347 missing.append(prop.name)
348 values.append(value)
349 if missing:
350 self.Raise('Missing required properties/entry args: %s' %
351 (', '.join(missing)))
352 return values
353
Simon Glassbf7fd502016-11-25 20:15:51 -0700354 def GetPath(self):
355 """Get the path of a node
356
357 Returns:
358 Full path of the node for this entry
359 """
360 return self._node.path
361
362 def GetData(self):
363 return self.data
364
Simon Glass3ab95982018-08-01 15:22:37 -0600365 def GetOffsets(self):
Simon Glassed7dd5e2019-07-08 13:18:30 -0600366 """Get the offsets for siblings
367
368 Some entry types can contain information about the position or size of
369 other entries. An example of this is the Intel Flash Descriptor, which
370 knows where the Intel Management Engine section should go.
371
372 If this entry knows about the position of other entries, it can specify
373 this by returning values here
374
375 Returns:
376 Dict:
377 key: Entry type
378 value: List containing position and size of the given entry
Simon Glasscf549042019-07-08 13:18:39 -0600379 type. Either can be None if not known
Simon Glassed7dd5e2019-07-08 13:18:30 -0600380 """
Simon Glassbf7fd502016-11-25 20:15:51 -0700381 return {}
382
Simon Glasscf549042019-07-08 13:18:39 -0600383 def SetOffsetSize(self, offset, size):
384 """Set the offset and/or size of an entry
385
386 Args:
387 offset: New offset, or None to leave alone
388 size: New size, or None to leave alone
389 """
390 if offset is not None:
391 self.offset = offset
392 if size is not None:
393 self.size = size
Simon Glassbf7fd502016-11-25 20:15:51 -0700394
Simon Glassdbf6be92018-08-01 15:22:42 -0600395 def SetImagePos(self, image_pos):
396 """Set the position in the image
397
398 Args:
399 image_pos: Position of this entry in the image
400 """
401 self.image_pos = image_pos + self.offset
402
Simon Glassbf7fd502016-11-25 20:15:51 -0700403 def ProcessContents(self):
404 pass
Simon Glass19790632017-11-13 18:55:01 -0700405
Simon Glassf55382b2018-06-01 09:38:13 -0600406 def WriteSymbols(self, section):
Simon Glass19790632017-11-13 18:55:01 -0700407 """Write symbol values into binary files for access at run time
408
409 Args:
Simon Glassf55382b2018-06-01 09:38:13 -0600410 section: Section containing the entry
Simon Glass19790632017-11-13 18:55:01 -0700411 """
412 pass
Simon Glass18546952018-06-01 09:38:16 -0600413
Simon Glass3ab95982018-08-01 15:22:37 -0600414 def CheckOffset(self):
415 """Check that the entry offsets are correct
Simon Glass18546952018-06-01 09:38:16 -0600416
Simon Glass3ab95982018-08-01 15:22:37 -0600417 This is used for entries which have extra offset requirements (other
Simon Glass18546952018-06-01 09:38:16 -0600418 than having to be fully inside their section). Sub-classes can implement
419 this function and raise if there is a problem.
420 """
421 pass
Simon Glass3b0c3822018-06-01 09:38:20 -0600422
Simon Glass8122f392018-07-17 13:25:28 -0600423 @staticmethod
Simon Glass163ed6c2018-09-14 04:57:36 -0600424 def GetStr(value):
425 if value is None:
426 return '<none> '
427 return '%08x' % value
428
429 @staticmethod
Simon Glass1be70d22018-07-17 13:25:49 -0600430 def WriteMapLine(fd, indent, name, offset, size, image_pos):
Simon Glass163ed6c2018-09-14 04:57:36 -0600431 print('%s %s%s %s %s' % (Entry.GetStr(image_pos), ' ' * indent,
432 Entry.GetStr(offset), Entry.GetStr(size),
433 name), file=fd)
Simon Glass8122f392018-07-17 13:25:28 -0600434
Simon Glass3b0c3822018-06-01 09:38:20 -0600435 def WriteMap(self, fd, indent):
436 """Write a map of the entry to a .map file
437
438 Args:
439 fd: File to write the map to
440 indent: Curent indent level of map (0=none, 1=one level, etc.)
441 """
Simon Glass1be70d22018-07-17 13:25:49 -0600442 self.WriteMapLine(fd, indent, self.name, self.offset, self.size,
443 self.image_pos)
Simon Glass53af22a2018-07-17 13:25:32 -0600444
Simon Glass11e36cc2018-07-17 13:25:38 -0600445 def GetEntries(self):
446 """Return a list of entries contained by this entry
447
448 Returns:
449 List of entries, or None if none. A normal entry has no entries
450 within it so will return None
451 """
452 return None
453
Simon Glass53af22a2018-07-17 13:25:32 -0600454 def GetArg(self, name, datatype=str):
455 """Get the value of an entry argument or device-tree-node property
456
457 Some node properties can be provided as arguments to binman. First check
458 the entry arguments, and fall back to the device tree if not found
459
460 Args:
461 name: Argument name
462 datatype: Data type (str or int)
463
464 Returns:
465 Value of argument as a string or int, or None if no value
466
467 Raises:
468 ValueError if the argument cannot be converted to in
469 """
Simon Glassc55a50f2018-09-14 04:57:19 -0600470 value = state.GetEntryArg(name)
Simon Glass53af22a2018-07-17 13:25:32 -0600471 if value is not None:
472 if datatype == int:
473 try:
474 value = int(value)
475 except ValueError:
476 self.Raise("Cannot convert entry arg '%s' (value '%s') to integer" %
477 (name, value))
478 elif datatype == str:
479 pass
480 else:
481 raise ValueError("GetArg() internal error: Unknown data type '%s'" %
482 datatype)
483 else:
484 value = fdt_util.GetDatatype(self._node, name, datatype)
485 return value
Simon Glassfd8d1f72018-07-17 13:25:36 -0600486
487 @staticmethod
488 def WriteDocs(modules, test_missing=None):
489 """Write out documentation about the various entry types to stdout
490
491 Args:
492 modules: List of modules to include
493 test_missing: Used for testing. This is a module to report
494 as missing
495 """
496 print('''Binman Entry Documentation
497===========================
498
499This file describes the entry types supported by binman. These entry types can
500be placed in an image one by one to build up a final firmware image. It is
501fairly easy to create new entry types. Just add a new file to the 'etype'
502directory. You can use the existing entries as examples.
503
504Note that some entries are subclasses of others, using and extending their
505features to produce new behaviours.
506
507
508''')
509 modules = sorted(modules)
510
511 # Don't show the test entry
512 if '_testing' in modules:
513 modules.remove('_testing')
514 missing = []
515 for name in modules:
Simon Glassc073ced2019-07-08 14:25:31 -0600516 module = Entry.Lookup(name, name)
Simon Glassfd8d1f72018-07-17 13:25:36 -0600517 docs = getattr(module, '__doc__')
518 if test_missing == name:
519 docs = None
520 if docs:
521 lines = docs.splitlines()
522 first_line = lines[0]
523 rest = [line[4:] for line in lines[1:]]
524 hdr = 'Entry: %s: %s' % (name.replace('_', '-'), first_line)
525 print(hdr)
526 print('-' * len(hdr))
527 print('\n'.join(rest))
528 print()
529 print()
530 else:
531 missing.append(name)
532
533 if missing:
534 raise ValueError('Documentation is missing for modules: %s' %
535 ', '.join(missing))
Simon Glassa326b492018-09-14 04:57:11 -0600536
537 def GetUniqueName(self):
538 """Get a unique name for a node
539
540 Returns:
541 String containing a unique name for a node, consisting of the name
542 of all ancestors (starting from within the 'binman' node) separated
543 by a dot ('.'). This can be useful for generating unique filesnames
544 in the output directory.
545 """
546 name = self.name
547 node = self._node
548 while node.parent:
549 node = node.parent
550 if node.name == 'binman':
551 break
552 name = '%s.%s' % (node.name, name)
553 return name
Simon Glassba64a0b2018-09-14 04:57:29 -0600554
555 def ExpandToLimit(self, limit):
556 """Expand an entry so that it ends at the given offset limit"""
557 if self.offset + self.size < limit:
558 self.size = limit - self.offset
559 # Request the contents again, since changing the size requires that
560 # the data grows. This should not fail, but check it to be sure.
561 if not self.ObtainContents():
562 self.Raise('Cannot obtain contents when expanding entry')
Simon Glassfa1c9372019-07-08 13:18:38 -0600563
564 def HasSibling(self, name):
565 """Check if there is a sibling of a given name
566
567 Returns:
568 True if there is an entry with this name in the the same section,
569 else False
570 """
571 return name in self.section.GetEntries()
Simon Glasscf228942019-07-08 14:25:28 -0600572
573 def GetSiblingImagePos(self, name):
574 """Return the image position of the given sibling
575
576 Returns:
577 Image position of sibling, or None if the sibling has no position,
578 or False if there is no such sibling
579 """
580 if not self.HasSibling(name):
581 return False
582 return self.section.GetEntries()[name].image_pos