2018-05-06 21:58:06 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2016-11-26 03:15:51 +00:00
|
|
|
# Copyright (c) 2016 Google, Inc
|
|
|
|
#
|
|
|
|
# Base class for all entries
|
|
|
|
#
|
|
|
|
|
2018-07-17 19:25:32 +00:00
|
|
|
from collections import namedtuple
|
2019-10-31 13:42:59 +00:00
|
|
|
import importlib
|
2018-06-01 15:38:15 +00:00
|
|
|
import os
|
2022-01-12 20:10:36 +00:00
|
|
|
import pathlib
|
2018-06-01 15:38:15 +00:00
|
|
|
import sys
|
2022-08-07 15:46:46 +00:00
|
|
|
import time
|
2018-09-14 10:57:19 +00:00
|
|
|
|
2022-01-10 03:13:50 +00:00
|
|
|
from binman import bintool
|
2022-01-10 03:14:03 +00:00
|
|
|
from binman import comp_util
|
2020-04-18 00:09:03 +00:00
|
|
|
from dtoc import fdt_util
|
2020-04-18 00:09:04 +00:00
|
|
|
from patman import tools
|
2022-01-29 21:14:04 +00:00
|
|
|
from patman.tools import to_hex, to_hex_size
|
2020-04-18 00:09:04 +00:00
|
|
|
from patman import tout
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
modules = {}
|
|
|
|
|
2022-02-11 20:23:21 +00:00
|
|
|
# This is imported if needed
|
|
|
|
state = None
|
2018-07-17 19:25:32 +00:00
|
|
|
|
|
|
|
# An argument which can be passed to entries on the command line, in lieu of
|
|
|
|
# device-tree properties.
|
|
|
|
EntryArg = namedtuple('EntryArg', ['name', 'datatype'])
|
|
|
|
|
2019-07-08 20:25:43 +00:00
|
|
|
# Information about an entry for use when displaying summaries
|
|
|
|
EntryInfo = namedtuple('EntryInfo', ['indent', 'name', 'etype', 'size',
|
|
|
|
'image_pos', 'uncomp_size', 'offset',
|
|
|
|
'entry'])
|
2018-07-17 19:25:32 +00:00
|
|
|
|
2016-11-26 03:15:51 +00:00
|
|
|
class Entry(object):
|
2018-06-01 15:38:14 +00:00
|
|
|
"""An Entry in the section
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
An entry corresponds to a single node in the device-tree description
|
2018-06-01 15:38:14 +00:00
|
|
|
of the section. Each entry ends up being a part of the final section.
|
2016-11-26 03:15:51 +00:00
|
|
|
Entries can be placed either right next to each other, or with padding
|
|
|
|
between them. The type of the entry determines the data that is in it.
|
|
|
|
|
|
|
|
This class is not used by itself. All entry objects are subclasses of
|
|
|
|
Entry.
|
|
|
|
|
|
|
|
Attributes:
|
2018-07-17 19:25:28 +00:00
|
|
|
section: Section object containing this entry
|
2016-11-26 03:15:51 +00:00
|
|
|
node: The node that created this entry
|
2018-08-01 21:22:37 +00:00
|
|
|
offset: Offset of entry within the section, None if not known yet (in
|
|
|
|
which case it will be calculated by Pack())
|
2016-11-26 03:15:51 +00:00
|
|
|
size: Entry size in bytes, None if not known
|
2019-10-31 13:43:02 +00:00
|
|
|
pre_reset_size: size as it was before ResetForPack(). This allows us to
|
|
|
|
keep track of the size we started with and detect size changes
|
2019-07-08 20:25:30 +00:00
|
|
|
uncomp_size: Size of uncompressed data in bytes, if the entry is
|
|
|
|
compressed, else None
|
2016-11-26 03:15:51 +00:00
|
|
|
contents_size: Size of contents in bytes, 0 by default
|
2020-10-26 23:40:10 +00:00
|
|
|
align: Entry start offset alignment relative to the start of the
|
|
|
|
containing section, or None
|
2016-11-26 03:15:51 +00:00
|
|
|
align_size: Entry size alignment, or None
|
2020-10-26 23:40:10 +00:00
|
|
|
align_end: Entry end offset alignment relative to the start of the
|
|
|
|
containing section, or None
|
2020-10-26 23:40:09 +00:00
|
|
|
pad_before: Number of pad bytes before the contents when it is placed
|
|
|
|
in the containing section, 0 if none. The pad bytes become part of
|
|
|
|
the entry.
|
|
|
|
pad_after: Number of pad bytes after the contents when it is placed in
|
|
|
|
the containing section, 0 if none. The pad bytes become part of
|
|
|
|
the entry.
|
|
|
|
data: Contents of entry (string of bytes). This does not include
|
2020-10-26 23:40:15 +00:00
|
|
|
padding created by pad_before or pad_after. If the entry is
|
|
|
|
compressed, this contains the compressed data.
|
|
|
|
uncomp_data: Original uncompressed data, if this entry is compressed,
|
|
|
|
else None
|
2019-07-08 20:25:30 +00:00
|
|
|
compress: Compression algoithm used (e.g. 'lz4'), 'none' if none
|
2019-07-08 20:25:37 +00:00
|
|
|
orig_offset: Original offset value read from node
|
|
|
|
orig_size: Original size value read from node
|
2020-09-01 11:13:57 +00:00
|
|
|
missing: True if this entry is missing its contents
|
|
|
|
allow_missing: Allow children of this entry to be missing (used by
|
|
|
|
subclasses such as Entry_section)
|
2022-01-06 10:49:41 +00:00
|
|
|
allow_fake: Allow creating a dummy fake file if the blob file is not
|
|
|
|
available. This is mainly used for testing.
|
2020-09-01 11:13:57 +00:00
|
|
|
external: True if this entry contains an external binary blob
|
2022-01-10 03:13:50 +00:00
|
|
|
bintools: Bintools used by this entry (only populated for Image)
|
2022-01-10 03:14:09 +00:00
|
|
|
missing_bintools: List of missing bintools for this entry
|
2022-02-09 19:02:35 +00:00
|
|
|
update_hash: True if this entry's "hash" subnode should be
|
|
|
|
updated with a hash of the entry contents
|
2022-08-07 15:46:46 +00:00
|
|
|
fake_fname: Fake filename, if one was created, else None
|
2022-08-13 17:40:44 +00:00
|
|
|
required_props (dict of str): Properties which must be present. This can
|
|
|
|
be added to by subclasses
|
2016-11-26 03:15:51 +00:00
|
|
|
"""
|
2022-08-07 15:46:46 +00:00
|
|
|
fake_dir = None
|
|
|
|
|
2019-07-20 18:23:45 +00:00
|
|
|
def __init__(self, section, etype, node, name_prefix=''):
|
2019-08-24 13:22:44 +00:00
|
|
|
# Put this here to allow entry-docs and help to work without libfdt
|
|
|
|
global state
|
2020-04-18 00:09:03 +00:00
|
|
|
from binman import state
|
2019-08-24 13:22:44 +00:00
|
|
|
|
2018-06-01 15:38:14 +00:00
|
|
|
self.section = section
|
2016-11-26 03:15:51 +00:00
|
|
|
self.etype = etype
|
|
|
|
self._node = node
|
2018-06-01 15:38:21 +00:00
|
|
|
self.name = node and (name_prefix + node.name) or 'none'
|
2018-08-01 21:22:37 +00:00
|
|
|
self.offset = None
|
2016-11-26 03:15:51 +00:00
|
|
|
self.size = None
|
2019-10-31 13:43:02 +00:00
|
|
|
self.pre_reset_size = None
|
2019-07-08 20:25:30 +00:00
|
|
|
self.uncomp_size = None
|
2018-07-17 19:25:47 +00:00
|
|
|
self.data = None
|
2020-10-26 23:40:15 +00:00
|
|
|
self.uncomp_data = None
|
2016-11-26 03:15:51 +00:00
|
|
|
self.contents_size = 0
|
|
|
|
self.align = None
|
|
|
|
self.align_size = None
|
|
|
|
self.align_end = None
|
|
|
|
self.pad_before = 0
|
|
|
|
self.pad_after = 0
|
2018-08-01 21:22:37 +00:00
|
|
|
self.offset_unset = False
|
2018-08-01 21:22:42 +00:00
|
|
|
self.image_pos = None
|
2022-03-06 03:18:59 +00:00
|
|
|
self.extend_size = False
|
2019-07-08 20:25:30 +00:00
|
|
|
self.compress = 'none'
|
2020-07-10 00:39:40 +00:00
|
|
|
self.missing = False
|
2022-01-06 10:49:41 +00:00
|
|
|
self.faked = False
|
2020-09-01 11:13:57 +00:00
|
|
|
self.external = False
|
|
|
|
self.allow_missing = False
|
2022-01-06 10:49:41 +00:00
|
|
|
self.allow_fake = False
|
2022-01-10 03:13:50 +00:00
|
|
|
self.bintools = {}
|
2022-01-10 03:14:09 +00:00
|
|
|
self.missing_bintools = []
|
2022-02-09 19:02:35 +00:00
|
|
|
self.update_hash = True
|
2022-08-07 15:46:46 +00:00
|
|
|
self.fake_fname = None
|
2022-08-13 17:40:44 +00:00
|
|
|
self.required_props = []
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2021-11-24 04:09:49 +00:00
|
|
|
def FindEntryClass(etype, expanded):
|
2018-07-17 19:25:36 +00:00
|
|
|
"""Look up the entry class for a node.
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
Args:
|
2018-07-17 19:25:36 +00:00
|
|
|
node_node: Path name of Node object containing information about
|
|
|
|
the entry to create (used for errors)
|
|
|
|
etype: Entry type to use
|
2021-03-18 07:25:04 +00:00
|
|
|
expanded: Use the expanded version of etype
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
Returns:
|
2021-03-18 07:25:04 +00:00
|
|
|
The entry class object if found, else None if not found and expanded
|
2021-11-24 04:09:49 +00:00
|
|
|
is True, else a tuple:
|
|
|
|
module name that could not be found
|
|
|
|
exception received
|
2016-11-26 03:15:51 +00:00
|
|
|
"""
|
2018-06-01 15:38:11 +00:00
|
|
|
# Convert something like 'u-boot@0' to 'u_boot' since we are only
|
|
|
|
# interested in the type.
|
2016-11-26 03:15:51 +00:00
|
|
|
module_name = etype.replace('-', '_')
|
2021-03-18 07:25:04 +00:00
|
|
|
|
2018-06-01 15:38:11 +00:00
|
|
|
if '@' in module_name:
|
|
|
|
module_name = module_name.split('@')[0]
|
2021-03-18 07:25:04 +00:00
|
|
|
if expanded:
|
|
|
|
module_name += '_expanded'
|
2016-11-26 03:15:51 +00:00
|
|
|
module = modules.get(module_name)
|
|
|
|
|
2018-06-01 15:38:15 +00:00
|
|
|
# Also allow entry-type modules to be brought in from the etype directory.
|
|
|
|
|
2016-11-26 03:15:51 +00:00
|
|
|
# Import the module if we have not already done so.
|
|
|
|
if not module:
|
|
|
|
try:
|
2020-04-18 00:09:03 +00:00
|
|
|
module = importlib.import_module('binman.etype.' + module_name)
|
2018-07-17 19:25:36 +00:00
|
|
|
except ImportError as e:
|
2021-03-18 07:25:04 +00:00
|
|
|
if expanded:
|
|
|
|
return None
|
2021-11-24 04:09:49 +00:00
|
|
|
return module_name, e
|
2016-11-26 03:15:51 +00:00
|
|
|
modules[module_name] = module
|
|
|
|
|
2018-07-17 19:25:36 +00:00
|
|
|
# Look up the expected class name
|
|
|
|
return getattr(module, 'Entry_%s' % module_name)
|
|
|
|
|
|
|
|
@staticmethod
|
2021-11-24 04:09:49 +00:00
|
|
|
def Lookup(node_path, etype, expanded, missing_etype=False):
|
|
|
|
"""Look up the entry class for a node.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
node_node (str): Path name of Node object containing information
|
|
|
|
about the entry to create (used for errors)
|
|
|
|
etype (str): Entry type to use
|
|
|
|
expanded (bool): Use the expanded version of etype
|
|
|
|
missing_etype (bool): True to default to a blob etype if the
|
|
|
|
requested etype is not found
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The entry class object if found, else None if not found and expanded
|
|
|
|
is True
|
|
|
|
|
|
|
|
Raise:
|
|
|
|
ValueError if expanded is False and the class is not found
|
|
|
|
"""
|
|
|
|
# Convert something like 'u-boot@0' to 'u_boot' since we are only
|
|
|
|
# interested in the type.
|
|
|
|
cls = Entry.FindEntryClass(etype, expanded)
|
|
|
|
if cls is None:
|
|
|
|
return None
|
|
|
|
elif isinstance(cls, tuple):
|
|
|
|
if missing_etype:
|
|
|
|
cls = Entry.FindEntryClass('blob', False)
|
|
|
|
if isinstance(cls, tuple): # This should not fail
|
|
|
|
module_name, e = cls
|
|
|
|
raise ValueError(
|
|
|
|
"Unknown entry type '%s' in node '%s' (expected etype/%s.py, error '%s'" %
|
|
|
|
(etype, node_path, module_name, e))
|
|
|
|
return cls
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def Create(section, node, etype=None, expanded=False, missing_etype=False):
|
2018-07-17 19:25:36 +00:00
|
|
|
"""Create a new entry for a node.
|
|
|
|
|
|
|
|
Args:
|
2021-11-24 04:09:49 +00:00
|
|
|
section (entry_Section): Section object containing this node
|
|
|
|
node (Node): Node object containing information about the entry to
|
|
|
|
create
|
|
|
|
etype (str): Entry type to use, or None to work it out (used for
|
|
|
|
tests)
|
|
|
|
expanded (bool): Use the expanded version of etype
|
|
|
|
missing_etype (bool): True to default to a blob etype if the
|
|
|
|
requested etype is not found
|
2018-07-17 19:25:36 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
A new Entry object of the correct type (a subclass of Entry)
|
|
|
|
"""
|
|
|
|
if not etype:
|
|
|
|
etype = fdt_util.GetString(node, 'type', node.name)
|
2021-11-24 04:09:49 +00:00
|
|
|
obj = Entry.Lookup(node.path, etype, expanded, missing_etype)
|
2021-03-18 07:25:04 +00:00
|
|
|
if obj and expanded:
|
|
|
|
# Check whether to use the expanded entry
|
|
|
|
new_etype = etype + '-expanded'
|
2021-03-21 05:24:30 +00:00
|
|
|
can_expand = not fdt_util.GetBool(node, 'no-expanded')
|
|
|
|
if can_expand and obj.UseExpanded(node, etype, new_etype):
|
2021-03-18 07:25:04 +00:00
|
|
|
etype = new_etype
|
|
|
|
else:
|
|
|
|
obj = None
|
|
|
|
if not obj:
|
2021-11-24 04:09:49 +00:00
|
|
|
obj = Entry.Lookup(node.path, etype, False, missing_etype)
|
2018-07-17 19:25:36 +00:00
|
|
|
|
2016-11-26 03:15:51 +00:00
|
|
|
# Call its constructor to get the object we want.
|
2018-06-01 15:38:14 +00:00
|
|
|
return obj(section, etype, node)
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
def ReadNode(self):
|
|
|
|
"""Read entry information from the node
|
|
|
|
|
2019-07-20 18:23:45 +00:00
|
|
|
This must be called as the first thing after the Entry is created.
|
|
|
|
|
2016-11-26 03:15:51 +00:00
|
|
|
This reads all the fields we recognise from the node, ready for use.
|
|
|
|
"""
|
2022-08-13 17:40:44 +00:00
|
|
|
self.ensure_props()
|
2018-07-17 19:25:51 +00:00
|
|
|
if 'pos' in self._node.props:
|
|
|
|
self.Raise("Please use 'offset' instead of 'pos'")
|
2022-03-06 03:18:59 +00:00
|
|
|
if 'expand-size' in self._node.props:
|
|
|
|
self.Raise("Please use 'extend-size' instead of 'expand-size'")
|
2018-08-01 21:22:37 +00:00
|
|
|
self.offset = fdt_util.GetInt(self._node, 'offset')
|
2016-11-26 03:15:51 +00:00
|
|
|
self.size = fdt_util.GetInt(self._node, 'size')
|
2019-07-20 18:23:51 +00:00
|
|
|
self.orig_offset = fdt_util.GetInt(self._node, 'orig-offset')
|
|
|
|
self.orig_size = fdt_util.GetInt(self._node, 'orig-size')
|
|
|
|
if self.GetImage().copy_to_orig:
|
|
|
|
self.orig_offset = self.offset
|
|
|
|
self.orig_size = self.size
|
2019-07-08 20:25:37 +00:00
|
|
|
|
2019-07-08 20:25:46 +00:00
|
|
|
# These should not be set in input files, but are set in an FDT map,
|
|
|
|
# which is also read by this code.
|
|
|
|
self.image_pos = fdt_util.GetInt(self._node, 'image-pos')
|
|
|
|
self.uncomp_size = fdt_util.GetInt(self._node, 'uncomp-size')
|
|
|
|
|
2016-11-26 03:15:51 +00:00
|
|
|
self.align = fdt_util.GetInt(self._node, 'align')
|
2022-01-29 21:14:04 +00:00
|
|
|
if tools.not_power_of_two(self.align):
|
2016-11-26 03:15:51 +00:00
|
|
|
raise ValueError("Node '%s': Alignment %s must be a power of two" %
|
|
|
|
(self._node.path, self.align))
|
2021-03-21 05:24:33 +00:00
|
|
|
if self.section and self.align is None:
|
|
|
|
self.align = self.section.align_default
|
2016-11-26 03:15:51 +00:00
|
|
|
self.pad_before = fdt_util.GetInt(self._node, 'pad-before', 0)
|
|
|
|
self.pad_after = fdt_util.GetInt(self._node, 'pad-after', 0)
|
|
|
|
self.align_size = fdt_util.GetInt(self._node, 'align-size')
|
2022-01-29 21:14:04 +00:00
|
|
|
if tools.not_power_of_two(self.align_size):
|
2019-07-08 20:25:47 +00:00
|
|
|
self.Raise("Alignment size %s must be a power of two" %
|
|
|
|
self.align_size)
|
2016-11-26 03:15:51 +00:00
|
|
|
self.align_end = fdt_util.GetInt(self._node, 'align-end')
|
2018-08-01 21:22:37 +00:00
|
|
|
self.offset_unset = fdt_util.GetBool(self._node, 'offset-unset')
|
2022-03-06 03:18:59 +00:00
|
|
|
self.extend_size = fdt_util.GetBool(self._node, 'extend-size')
|
2020-09-06 16:39:09 +00:00
|
|
|
self.missing_msg = fdt_util.GetString(self._node, 'missing-msg')
|
2016-11-26 03:15:51 +00:00
|
|
|
|
2020-10-26 23:40:06 +00:00
|
|
|
# This is only supported by blobs and sections at present
|
|
|
|
self.compress = fdt_util.GetString(self._node, 'compress', 'none')
|
|
|
|
|
2018-09-14 10:57:18 +00:00
|
|
|
def GetDefaultFilename(self):
|
|
|
|
return None
|
|
|
|
|
2019-07-20 18:23:28 +00:00
|
|
|
def GetFdts(self):
|
|
|
|
"""Get the device trees used by this entry
|
2018-09-14 10:57:22 +00:00
|
|
|
|
|
|
|
Returns:
|
2019-07-20 18:23:28 +00:00
|
|
|
Empty dict, if this entry is not a .dtb, otherwise:
|
|
|
|
Dict:
|
|
|
|
key: Filename from this entry (without the path)
|
2019-07-20 18:23:31 +00:00
|
|
|
value: Tuple:
|
2021-03-18 07:25:02 +00:00
|
|
|
Entry object for this dtb
|
2019-07-20 18:23:31 +00:00
|
|
|
Filename of file containing this dtb
|
2018-09-14 10:57:22 +00:00
|
|
|
"""
|
2019-07-20 18:23:28 +00:00
|
|
|
return {}
|
2018-09-14 10:57:22 +00:00
|
|
|
|
2022-03-06 03:19:00 +00:00
|
|
|
def gen_entries(self):
|
|
|
|
"""Allow entries to generate other entries
|
2021-03-18 07:24:52 +00:00
|
|
|
|
|
|
|
Some entries generate subnodes automatically, from which sub-entries
|
|
|
|
are then created. This method allows those to be added to the binman
|
|
|
|
definition for the current image. An entry which implements this method
|
|
|
|
should call state.AddSubnode() to add a subnode and can add properties
|
|
|
|
with state.AddString(), etc.
|
|
|
|
|
|
|
|
An example is 'files', which produces a section containing a list of
|
|
|
|
files.
|
|
|
|
"""
|
2018-09-14 10:57:28 +00:00
|
|
|
pass
|
|
|
|
|
2020-10-26 23:40:17 +00:00
|
|
|
def AddMissingProperties(self, have_image_pos):
|
|
|
|
"""Add new properties to the device tree as needed for this entry
|
|
|
|
|
|
|
|
Args:
|
|
|
|
have_image_pos: True if this entry has an image position. This can
|
|
|
|
be False if its parent section is compressed, since compression
|
|
|
|
groups all entries together into a compressed block of data,
|
|
|
|
obscuring the start of each individual child entry
|
|
|
|
"""
|
|
|
|
for prop in ['offset', 'size']:
|
2018-07-06 16:27:41 +00:00
|
|
|
if not prop in self._node.props:
|
2018-09-14 10:57:21 +00:00
|
|
|
state.AddZeroProp(self._node, prop)
|
2020-10-26 23:40:17 +00:00
|
|
|
if have_image_pos and 'image-pos' not in self._node.props:
|
|
|
|
state.AddZeroProp(self._node, 'image-pos')
|
2019-07-20 18:23:51 +00:00
|
|
|
if self.GetImage().allow_repack:
|
|
|
|
if self.orig_offset is not None:
|
|
|
|
state.AddZeroProp(self._node, 'orig-offset', True)
|
|
|
|
if self.orig_size is not None:
|
|
|
|
state.AddZeroProp(self._node, 'orig-size', True)
|
|
|
|
|
2019-07-08 20:25:30 +00:00
|
|
|
if self.compress != 'none':
|
|
|
|
state.AddZeroProp(self._node, 'uncomp-size')
|
2022-02-09 19:02:35 +00:00
|
|
|
|
|
|
|
if self.update_hash:
|
|
|
|
err = state.CheckAddHashProp(self._node)
|
|
|
|
if err:
|
|
|
|
self.Raise(err)
|
2018-07-06 16:27:41 +00:00
|
|
|
|
|
|
|
def SetCalculatedProperties(self):
|
|
|
|
"""Set the value of device-tree properties calculated by binman"""
|
2018-09-14 10:57:21 +00:00
|
|
|
state.SetInt(self._node, 'offset', self.offset)
|
|
|
|
state.SetInt(self._node, 'size', self.size)
|
2019-07-08 20:25:47 +00:00
|
|
|
base = self.section.GetRootSkipAtStart() if self.section else 0
|
2020-10-26 23:40:17 +00:00
|
|
|
if self.image_pos is not None:
|
2020-11-02 19:55:44 +00:00
|
|
|
state.SetInt(self._node, 'image-pos', self.image_pos - base)
|
2019-07-20 18:23:51 +00:00
|
|
|
if self.GetImage().allow_repack:
|
|
|
|
if self.orig_offset is not None:
|
|
|
|
state.SetInt(self._node, 'orig-offset', self.orig_offset, True)
|
|
|
|
if self.orig_size is not None:
|
|
|
|
state.SetInt(self._node, 'orig-size', self.orig_size, True)
|
2019-07-08 20:25:30 +00:00
|
|
|
if self.uncomp_size is not None:
|
|
|
|
state.SetInt(self._node, 'uncomp-size', self.uncomp_size)
|
2022-02-09 19:02:35 +00:00
|
|
|
|
|
|
|
if self.update_hash:
|
|
|
|
state.CheckSetHashValue(self._node, self.GetData)
|
2018-07-06 16:27:41 +00:00
|
|
|
|
2018-07-06 16:27:40 +00:00
|
|
|
def ProcessFdt(self, fdt):
|
2018-09-14 10:57:24 +00:00
|
|
|
"""Allow entries to adjust the device tree
|
|
|
|
|
|
|
|
Some entries need to adjust the device tree for their purposes. This
|
|
|
|
may involve adding or deleting properties.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
True if processing is complete
|
|
|
|
False if processing could not be completed due to a dependency.
|
|
|
|
This will cause the entry to be retried after others have been
|
|
|
|
called
|
|
|
|
"""
|
2018-07-06 16:27:40 +00:00
|
|
|
return True
|
|
|
|
|
2018-06-01 15:38:21 +00:00
|
|
|
def SetPrefix(self, prefix):
|
|
|
|
"""Set the name prefix for a node
|
|
|
|
|
|
|
|
Args:
|
|
|
|
prefix: Prefix to set, or '' to not use a prefix
|
|
|
|
"""
|
|
|
|
if prefix:
|
|
|
|
self.name = prefix + self.name
|
|
|
|
|
2018-07-06 16:27:19 +00:00
|
|
|
def SetContents(self, data):
|
|
|
|
"""Set the contents of an entry
|
|
|
|
|
|
|
|
This sets both the data and content_size properties
|
|
|
|
|
|
|
|
Args:
|
2019-07-08 20:25:33 +00:00
|
|
|
data: Data to set to the contents (bytes)
|
2018-07-06 16:27:19 +00:00
|
|
|
"""
|
|
|
|
self.data = data
|
|
|
|
self.contents_size = len(self.data)
|
|
|
|
|
|
|
|
def ProcessContentsUpdate(self, data):
|
2019-07-08 20:25:33 +00:00
|
|
|
"""Update the contents of an entry, after the size is fixed
|
2018-07-06 16:27:19 +00:00
|
|
|
|
2019-07-08 20:25:35 +00:00
|
|
|
This checks that the new data is the same size as the old. If the size
|
|
|
|
has changed, this triggers a re-run of the packing algorithm.
|
2018-07-06 16:27:19 +00:00
|
|
|
|
|
|
|
Args:
|
2019-07-08 20:25:33 +00:00
|
|
|
data: Data to set to the contents (bytes)
|
2018-07-06 16:27:19 +00:00
|
|
|
|
|
|
|
Raises:
|
|
|
|
ValueError if the new data size is not the same as the old
|
|
|
|
"""
|
2019-07-08 20:25:35 +00:00
|
|
|
size_ok = True
|
2019-07-08 20:25:37 +00:00
|
|
|
new_size = len(data)
|
2019-07-20 18:23:58 +00:00
|
|
|
if state.AllowEntryExpansion() and new_size > self.contents_size:
|
|
|
|
# self.data will indicate the new size needed
|
|
|
|
size_ok = False
|
|
|
|
elif state.AllowEntryContraction() and new_size < self.contents_size:
|
|
|
|
size_ok = False
|
|
|
|
|
|
|
|
# If not allowed to change, try to deal with it or give up
|
|
|
|
if size_ok:
|
2019-07-08 20:25:37 +00:00
|
|
|
if new_size > self.contents_size:
|
2019-07-20 18:23:58 +00:00
|
|
|
self.Raise('Cannot update entry size from %d to %d' %
|
|
|
|
(self.contents_size, new_size))
|
|
|
|
|
|
|
|
# Don't let the data shrink. Pad it if necessary
|
|
|
|
if size_ok and new_size < self.contents_size:
|
2022-01-29 21:14:04 +00:00
|
|
|
data += tools.get_bytes(0, self.contents_size - new_size)
|
2019-07-20 18:23:58 +00:00
|
|
|
|
|
|
|
if not size_ok:
|
2022-01-29 21:14:15 +00:00
|
|
|
tout.debug("Entry '%s' size change from %s to %s" % (
|
2022-01-29 21:14:04 +00:00
|
|
|
self._node.path, to_hex(self.contents_size),
|
|
|
|
to_hex(new_size)))
|
2018-07-06 16:27:19 +00:00
|
|
|
self.SetContents(data)
|
2019-07-08 20:25:35 +00:00
|
|
|
return size_ok
|
2018-07-06 16:27:19 +00:00
|
|
|
|
2022-03-06 03:19:05 +00:00
|
|
|
def ObtainContents(self, skip_entry=None, fake_size=0):
|
2016-11-26 03:15:51 +00:00
|
|
|
"""Figure out the contents of an entry.
|
|
|
|
|
2022-03-06 03:19:05 +00:00
|
|
|
Args:
|
|
|
|
skip_entry (Entry): Entry to skip when obtaining section contents
|
|
|
|
fake_size (int): Size of fake file to create if needed
|
|
|
|
|
2016-11-26 03:15:51 +00:00
|
|
|
Returns:
|
|
|
|
True if the contents were found, False if another call is needed
|
|
|
|
after the other entries are processed.
|
|
|
|
"""
|
|
|
|
# No contents by default: subclasses can implement this
|
|
|
|
return True
|
|
|
|
|
2019-07-08 20:25:37 +00:00
|
|
|
def ResetForPack(self):
|
|
|
|
"""Reset offset/size fields so that packing can be done again"""
|
2019-07-20 18:23:36 +00:00
|
|
|
self.Detail('ResetForPack: offset %s->%s, size %s->%s' %
|
2022-01-29 21:14:04 +00:00
|
|
|
(to_hex(self.offset), to_hex(self.orig_offset),
|
|
|
|
to_hex(self.size), to_hex(self.orig_size)))
|
2019-10-31 13:43:02 +00:00
|
|
|
self.pre_reset_size = self.size
|
2019-07-08 20:25:37 +00:00
|
|
|
self.offset = self.orig_offset
|
|
|
|
self.size = self.orig_size
|
|
|
|
|
2018-08-01 21:22:37 +00:00
|
|
|
def Pack(self, offset):
|
2018-06-01 15:38:14 +00:00
|
|
|
"""Figure out how to pack the entry into the section
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
Most of the time the entries are not fully specified. There may be
|
|
|
|
an alignment but no size. In that case we take the size from the
|
|
|
|
contents of the entry.
|
|
|
|
|
2018-08-01 21:22:37 +00:00
|
|
|
If an entry has no hard-coded offset, it will be placed at @offset.
|
2016-11-26 03:15:51 +00:00
|
|
|
|
2018-08-01 21:22:37 +00:00
|
|
|
Once this function is complete, both the offset and size of the
|
2016-11-26 03:15:51 +00:00
|
|
|
entry will be know.
|
|
|
|
|
|
|
|
Args:
|
2018-08-01 21:22:37 +00:00
|
|
|
Current section offset pointer
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
Returns:
|
2018-08-01 21:22:37 +00:00
|
|
|
New section offset pointer (after this entry)
|
2016-11-26 03:15:51 +00:00
|
|
|
"""
|
2019-07-20 18:23:36 +00:00
|
|
|
self.Detail('Packing: offset=%s, size=%s, content_size=%x' %
|
2022-01-29 21:14:04 +00:00
|
|
|
(to_hex(self.offset), to_hex(self.size),
|
2019-07-20 18:23:36 +00:00
|
|
|
self.contents_size))
|
2018-08-01 21:22:37 +00:00
|
|
|
if self.offset is None:
|
|
|
|
if self.offset_unset:
|
|
|
|
self.Raise('No offset set with offset-unset: should another '
|
|
|
|
'entry provide this correct offset?')
|
2022-01-29 21:14:04 +00:00
|
|
|
self.offset = tools.align(offset, self.align)
|
2016-11-26 03:15:51 +00:00
|
|
|
needed = self.pad_before + self.contents_size + self.pad_after
|
2022-01-29 21:14:04 +00:00
|
|
|
needed = tools.align(needed, self.align_size)
|
2016-11-26 03:15:51 +00:00
|
|
|
size = self.size
|
|
|
|
if not size:
|
|
|
|
size = needed
|
2018-08-01 21:22:37 +00:00
|
|
|
new_offset = self.offset + size
|
2022-01-29 21:14:04 +00:00
|
|
|
aligned_offset = tools.align(new_offset, self.align_end)
|
2018-08-01 21:22:37 +00:00
|
|
|
if aligned_offset != new_offset:
|
|
|
|
size = aligned_offset - self.offset
|
|
|
|
new_offset = aligned_offset
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
if not self.size:
|
|
|
|
self.size = size
|
|
|
|
|
|
|
|
if self.size < needed:
|
|
|
|
self.Raise("Entry contents size is %#x (%d) but entry size is "
|
|
|
|
"%#x (%d)" % (needed, needed, self.size, self.size))
|
|
|
|
# Check that the alignment is correct. It could be wrong if the
|
2018-08-01 21:22:37 +00:00
|
|
|
# and offset or size values were provided (i.e. not calculated), but
|
2016-11-26 03:15:51 +00:00
|
|
|
# conflict with the provided alignment values
|
2022-01-29 21:14:04 +00:00
|
|
|
if self.size != tools.align(self.size, self.align_size):
|
2016-11-26 03:15:51 +00:00
|
|
|
self.Raise("Size %#x (%d) does not match align-size %#x (%d)" %
|
|
|
|
(self.size, self.size, self.align_size, self.align_size))
|
2022-01-29 21:14:04 +00:00
|
|
|
if self.offset != tools.align(self.offset, self.align):
|
2018-08-01 21:22:37 +00:00
|
|
|
self.Raise("Offset %#x (%d) does not match align %#x (%d)" %
|
|
|
|
(self.offset, self.offset, self.align, self.align))
|
2019-07-20 18:23:36 +00:00
|
|
|
self.Detail(' - packed: offset=%#x, size=%#x, content_size=%#x, next_offset=%x' %
|
|
|
|
(self.offset, self.size, self.contents_size, new_offset))
|
2016-11-26 03:15:51 +00:00
|
|
|
|
2018-08-01 21:22:37 +00:00
|
|
|
return new_offset
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
def Raise(self, msg):
|
|
|
|
"""Convenience function to raise an error referencing a node"""
|
|
|
|
raise ValueError("Node '%s': %s" % (self._node.path, msg))
|
|
|
|
|
2021-03-21 05:24:31 +00:00
|
|
|
def Info(self, msg):
|
|
|
|
"""Convenience function to log info referencing a node"""
|
|
|
|
tag = "Info '%s'" % self._node.path
|
2022-01-29 21:14:15 +00:00
|
|
|
tout.detail('%30s: %s' % (tag, msg))
|
2021-03-21 05:24:31 +00:00
|
|
|
|
2019-07-20 18:23:36 +00:00
|
|
|
def Detail(self, msg):
|
|
|
|
"""Convenience function to log detail referencing a node"""
|
|
|
|
tag = "Node '%s'" % self._node.path
|
2022-01-29 21:14:15 +00:00
|
|
|
tout.detail('%30s: %s' % (tag, msg))
|
2019-07-20 18:23:36 +00:00
|
|
|
|
2018-07-17 19:25:32 +00:00
|
|
|
def GetEntryArgsOrProps(self, props, required=False):
|
|
|
|
"""Return the values of a set of properties
|
|
|
|
|
|
|
|
Args:
|
|
|
|
props: List of EntryArg objects
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
ValueError if a property is not found
|
|
|
|
"""
|
|
|
|
values = []
|
|
|
|
missing = []
|
|
|
|
for prop in props:
|
|
|
|
python_prop = prop.name.replace('-', '_')
|
|
|
|
if hasattr(self, python_prop):
|
|
|
|
value = getattr(self, python_prop)
|
|
|
|
else:
|
|
|
|
value = None
|
|
|
|
if value is None:
|
|
|
|
value = self.GetArg(prop.name, prop.datatype)
|
|
|
|
if value is None and required:
|
|
|
|
missing.append(prop.name)
|
|
|
|
values.append(value)
|
|
|
|
if missing:
|
2021-01-07 04:35:16 +00:00
|
|
|
self.GetImage().MissingArgs(self, missing)
|
2018-07-17 19:25:32 +00:00
|
|
|
return values
|
|
|
|
|
2016-11-26 03:15:51 +00:00
|
|
|
def GetPath(self):
|
|
|
|
"""Get the path of a node
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Full path of the node for this entry
|
|
|
|
"""
|
|
|
|
return self._node.path
|
|
|
|
|
binman: Support obtaining section contents immediately
Generally the content of sections is not built until the final assembly
of the image. This is partly to avoid wasting time, since the entries
within sections may change multiple times as binman works through its
various stages. This works quite well since sections exist in a strict
hierarchy, so they can be processed in a depth-first manner.
However the 'collection' entry type does not have this luxury. If it
contains a section within its 'content' list, then it must produce the
section contents, if available. That section is typically a sibling
node, i.e. not part oc the collection's hierarchy.
Add a new 'required' argument to section.GetData() to support this. When
required is True, any referenced sections are immediately built. If this
is not possible (because one of the subentries does not have its data yet)
then an error is produced.
The test for this uses a 'collection' entry type, referencing a section as
its first member. This forces a call to _BuildSectionData() with required
set to False, at first, then True later, when the image is assembled.
Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-21 05:24:32 +00:00
|
|
|
def GetData(self, required=True):
|
2020-10-26 23:40:16 +00:00
|
|
|
"""Get the contents of an entry
|
|
|
|
|
binman: Support obtaining section contents immediately
Generally the content of sections is not built until the final assembly
of the image. This is partly to avoid wasting time, since the entries
within sections may change multiple times as binman works through its
various stages. This works quite well since sections exist in a strict
hierarchy, so they can be processed in a depth-first manner.
However the 'collection' entry type does not have this luxury. If it
contains a section within its 'content' list, then it must produce the
section contents, if available. That section is typically a sibling
node, i.e. not part oc the collection's hierarchy.
Add a new 'required' argument to section.GetData() to support this. When
required is True, any referenced sections are immediately built. If this
is not possible (because one of the subentries does not have its data yet)
then an error is produced.
The test for this uses a 'collection' entry type, referencing a section as
its first member. This forces a call to _BuildSectionData() with required
set to False, at first, then True later, when the image is assembled.
Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-21 05:24:32 +00:00
|
|
|
Args:
|
|
|
|
required: True if the data must be present, False if it is OK to
|
|
|
|
return None
|
|
|
|
|
2020-10-26 23:40:16 +00:00
|
|
|
Returns:
|
|
|
|
bytes content of the entry, excluding any padding. If the entry is
|
|
|
|
compressed, the compressed data is returned
|
|
|
|
"""
|
2022-01-29 21:14:04 +00:00
|
|
|
self.Detail('GetData: size %s' % to_hex_size(self.data))
|
2016-11-26 03:15:51 +00:00
|
|
|
return self.data
|
|
|
|
|
2020-11-02 19:55:43 +00:00
|
|
|
def GetPaddedData(self, data=None):
|
|
|
|
"""Get the data for an entry including any padding
|
|
|
|
|
|
|
|
Gets the entry data and uses its section's pad-byte value to add padding
|
|
|
|
before and after as defined by the pad-before and pad-after properties.
|
|
|
|
|
|
|
|
This does not consider alignment.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Contents of the entry along with any pad bytes before and
|
|
|
|
after it (bytes)
|
|
|
|
"""
|
|
|
|
if data is None:
|
|
|
|
data = self.GetData()
|
|
|
|
return self.section.GetPaddedDataForEntry(self, data)
|
|
|
|
|
2018-08-01 21:22:37 +00:00
|
|
|
def GetOffsets(self):
|
2019-07-08 19:18:30 +00:00
|
|
|
"""Get the offsets for siblings
|
|
|
|
|
|
|
|
Some entry types can contain information about the position or size of
|
|
|
|
other entries. An example of this is the Intel Flash Descriptor, which
|
|
|
|
knows where the Intel Management Engine section should go.
|
|
|
|
|
|
|
|
If this entry knows about the position of other entries, it can specify
|
|
|
|
this by returning values here
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Dict:
|
|
|
|
key: Entry type
|
|
|
|
value: List containing position and size of the given entry
|
2019-07-08 19:18:39 +00:00
|
|
|
type. Either can be None if not known
|
2019-07-08 19:18:30 +00:00
|
|
|
"""
|
2016-11-26 03:15:51 +00:00
|
|
|
return {}
|
|
|
|
|
2019-07-08 19:18:39 +00:00
|
|
|
def SetOffsetSize(self, offset, size):
|
|
|
|
"""Set the offset and/or size of an entry
|
|
|
|
|
|
|
|
Args:
|
|
|
|
offset: New offset, or None to leave alone
|
|
|
|
size: New size, or None to leave alone
|
|
|
|
"""
|
|
|
|
if offset is not None:
|
|
|
|
self.offset = offset
|
|
|
|
if size is not None:
|
|
|
|
self.size = size
|
2016-11-26 03:15:51 +00:00
|
|
|
|
2018-08-01 21:22:42 +00:00
|
|
|
def SetImagePos(self, image_pos):
|
|
|
|
"""Set the position in the image
|
|
|
|
|
|
|
|
Args:
|
|
|
|
image_pos: Position of this entry in the image
|
|
|
|
"""
|
|
|
|
self.image_pos = image_pos + self.offset
|
|
|
|
|
2016-11-26 03:15:51 +00:00
|
|
|
def ProcessContents(self):
|
2019-07-08 20:25:35 +00:00
|
|
|
"""Do any post-packing updates of entry contents
|
|
|
|
|
|
|
|
This function should call ProcessContentsUpdate() to update the entry
|
|
|
|
contents, if necessary, returning its return value here.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
data: Data to set to the contents (bytes)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
True if the new data size is OK, False if expansion is needed
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
ValueError if the new data size is not the same as the old and
|
|
|
|
state.AllowEntryExpansion() is False
|
|
|
|
"""
|
|
|
|
return True
|
binman: Support accessing binman tables at run time
Binman construct images consisting of multiple binary files. These files
sometimes need to know (at run timme) where their peers are located. For
example, SPL may want to know where U-Boot is located in the image, so
that it can jump to U-Boot correctly on boot.
In general the positions where the binaries end up after binman has
finished packing them cannot be known at compile time. One reason for
this is that binman does not know the size of the binaries until
everything is compiled, linked and converted to binaries with objcopy.
To make this work, we add a feature to binman which checks each binary
for symbol names starting with '_binman'. These are then decoded to figure
out which entry and property they refer to. Then binman writes the value
of this symbol into the appropriate binary. With this, the symbol will
have the correct value at run time.
Macros are used to make this easier to use. As an example, this declares
a symbol that will access the 'u-boot-spl' entry to find the 'pos' value
(i.e. the position of SPL in the image):
binman_sym_declare(unsigned long, u_boot_spl, pos);
This converts to a symbol called '_binman_u_boot_spl_prop_pos' in any
binary that includes it. Binman then updates the value in that binary,
ensuring that it can be accessed at runtime with:
ulong u_boot_pos = binman_sym(ulong, u_boot_spl, pos);
This assigns the variable u_boot_pos to the position of SPL in the image.
Signed-off-by: Simon Glass <sjg@chromium.org>
2017-11-14 01:55:01 +00:00
|
|
|
|
2018-06-01 15:38:13 +00:00
|
|
|
def WriteSymbols(self, section):
|
binman: Support accessing binman tables at run time
Binman construct images consisting of multiple binary files. These files
sometimes need to know (at run timme) where their peers are located. For
example, SPL may want to know where U-Boot is located in the image, so
that it can jump to U-Boot correctly on boot.
In general the positions where the binaries end up after binman has
finished packing them cannot be known at compile time. One reason for
this is that binman does not know the size of the binaries until
everything is compiled, linked and converted to binaries with objcopy.
To make this work, we add a feature to binman which checks each binary
for symbol names starting with '_binman'. These are then decoded to figure
out which entry and property they refer to. Then binman writes the value
of this symbol into the appropriate binary. With this, the symbol will
have the correct value at run time.
Macros are used to make this easier to use. As an example, this declares
a symbol that will access the 'u-boot-spl' entry to find the 'pos' value
(i.e. the position of SPL in the image):
binman_sym_declare(unsigned long, u_boot_spl, pos);
This converts to a symbol called '_binman_u_boot_spl_prop_pos' in any
binary that includes it. Binman then updates the value in that binary,
ensuring that it can be accessed at runtime with:
ulong u_boot_pos = binman_sym(ulong, u_boot_spl, pos);
This assigns the variable u_boot_pos to the position of SPL in the image.
Signed-off-by: Simon Glass <sjg@chromium.org>
2017-11-14 01:55:01 +00:00
|
|
|
"""Write symbol values into binary files for access at run time
|
|
|
|
|
|
|
|
Args:
|
2018-06-01 15:38:13 +00:00
|
|
|
section: Section containing the entry
|
binman: Support accessing binman tables at run time
Binman construct images consisting of multiple binary files. These files
sometimes need to know (at run timme) where their peers are located. For
example, SPL may want to know where U-Boot is located in the image, so
that it can jump to U-Boot correctly on boot.
In general the positions where the binaries end up after binman has
finished packing them cannot be known at compile time. One reason for
this is that binman does not know the size of the binaries until
everything is compiled, linked and converted to binaries with objcopy.
To make this work, we add a feature to binman which checks each binary
for symbol names starting with '_binman'. These are then decoded to figure
out which entry and property they refer to. Then binman writes the value
of this symbol into the appropriate binary. With this, the symbol will
have the correct value at run time.
Macros are used to make this easier to use. As an example, this declares
a symbol that will access the 'u-boot-spl' entry to find the 'pos' value
(i.e. the position of SPL in the image):
binman_sym_declare(unsigned long, u_boot_spl, pos);
This converts to a symbol called '_binman_u_boot_spl_prop_pos' in any
binary that includes it. Binman then updates the value in that binary,
ensuring that it can be accessed at runtime with:
ulong u_boot_pos = binman_sym(ulong, u_boot_spl, pos);
This assigns the variable u_boot_pos to the position of SPL in the image.
Signed-off-by: Simon Glass <sjg@chromium.org>
2017-11-14 01:55:01 +00:00
|
|
|
"""
|
|
|
|
pass
|
2018-06-01 15:38:16 +00:00
|
|
|
|
2020-10-26 23:40:18 +00:00
|
|
|
def CheckEntries(self):
|
2018-08-01 21:22:37 +00:00
|
|
|
"""Check that the entry offsets are correct
|
2018-06-01 15:38:16 +00:00
|
|
|
|
2018-08-01 21:22:37 +00:00
|
|
|
This is used for entries which have extra offset requirements (other
|
2018-06-01 15:38:16 +00:00
|
|
|
than having to be fully inside their section). Sub-classes can implement
|
|
|
|
this function and raise if there is a problem.
|
|
|
|
"""
|
|
|
|
pass
|
2018-06-01 15:38:20 +00:00
|
|
|
|
2018-09-14 10:57:36 +00:00
|
|
|
@staticmethod
|
|
|
|
def GetStr(value):
|
|
|
|
if value is None:
|
|
|
|
return '<none> '
|
|
|
|
return '%08x' % value
|
|
|
|
|
2018-07-17 19:25:28 +00:00
|
|
|
@staticmethod
|
2018-07-17 19:25:49 +00:00
|
|
|
def WriteMapLine(fd, indent, name, offset, size, image_pos):
|
2018-09-14 10:57:36 +00:00
|
|
|
print('%s %s%s %s %s' % (Entry.GetStr(image_pos), ' ' * indent,
|
|
|
|
Entry.GetStr(offset), Entry.GetStr(size),
|
|
|
|
name), file=fd)
|
2018-07-17 19:25:28 +00:00
|
|
|
|
2018-06-01 15:38:20 +00:00
|
|
|
def WriteMap(self, fd, indent):
|
|
|
|
"""Write a map of the entry to a .map file
|
|
|
|
|
|
|
|
Args:
|
|
|
|
fd: File to write the map to
|
|
|
|
indent: Curent indent level of map (0=none, 1=one level, etc.)
|
|
|
|
"""
|
2018-07-17 19:25:49 +00:00
|
|
|
self.WriteMapLine(fd, indent, self.name, self.offset, self.size,
|
|
|
|
self.image_pos)
|
2018-07-17 19:25:32 +00:00
|
|
|
|
2022-08-13 17:40:50 +00:00
|
|
|
# pylint: disable=assignment-from-none
|
2018-07-17 19:25:38 +00:00
|
|
|
def GetEntries(self):
|
|
|
|
"""Return a list of entries contained by this entry
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
List of entries, or None if none. A normal entry has no entries
|
|
|
|
within it so will return None
|
|
|
|
"""
|
|
|
|
return None
|
|
|
|
|
2022-08-13 17:40:50 +00:00
|
|
|
def FindEntryByNode(self, find_node):
|
|
|
|
"""Find a node in an entry, searching all subentries
|
|
|
|
|
|
|
|
This does a recursive search.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
find_node (fdt.Node): Node to find
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Entry: entry, if found, else None
|
|
|
|
"""
|
|
|
|
entries = self.GetEntries()
|
|
|
|
if entries:
|
|
|
|
for entry in entries.values():
|
|
|
|
if entry._node == find_node:
|
|
|
|
return entry
|
|
|
|
found = entry.FindEntryByNode(find_node)
|
|
|
|
if found:
|
|
|
|
return found
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
2018-07-17 19:25:32 +00:00
|
|
|
def GetArg(self, name, datatype=str):
|
|
|
|
"""Get the value of an entry argument or device-tree-node property
|
|
|
|
|
|
|
|
Some node properties can be provided as arguments to binman. First check
|
|
|
|
the entry arguments, and fall back to the device tree if not found
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: Argument name
|
|
|
|
datatype: Data type (str or int)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Value of argument as a string or int, or None if no value
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
ValueError if the argument cannot be converted to in
|
|
|
|
"""
|
2018-09-14 10:57:19 +00:00
|
|
|
value = state.GetEntryArg(name)
|
2018-07-17 19:25:32 +00:00
|
|
|
if value is not None:
|
|
|
|
if datatype == int:
|
|
|
|
try:
|
|
|
|
value = int(value)
|
|
|
|
except ValueError:
|
|
|
|
self.Raise("Cannot convert entry arg '%s' (value '%s') to integer" %
|
|
|
|
(name, value))
|
|
|
|
elif datatype == str:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise ValueError("GetArg() internal error: Unknown data type '%s'" %
|
|
|
|
datatype)
|
|
|
|
else:
|
|
|
|
value = fdt_util.GetDatatype(self._node, name, datatype)
|
|
|
|
return value
|
2018-07-17 19:25:36 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def WriteDocs(modules, test_missing=None):
|
|
|
|
"""Write out documentation about the various entry types to stdout
|
|
|
|
|
|
|
|
Args:
|
|
|
|
modules: List of modules to include
|
|
|
|
test_missing: Used for testing. This is a module to report
|
|
|
|
as missing
|
|
|
|
"""
|
|
|
|
print('''Binman Entry Documentation
|
|
|
|
===========================
|
|
|
|
|
|
|
|
This file describes the entry types supported by binman. These entry types can
|
|
|
|
be placed in an image one by one to build up a final firmware image. It is
|
|
|
|
fairly easy to create new entry types. Just add a new file to the 'etype'
|
|
|
|
directory. You can use the existing entries as examples.
|
|
|
|
|
|
|
|
Note that some entries are subclasses of others, using and extending their
|
|
|
|
features to produce new behaviours.
|
|
|
|
|
|
|
|
|
|
|
|
''')
|
|
|
|
modules = sorted(modules)
|
|
|
|
|
|
|
|
# Don't show the test entry
|
|
|
|
if '_testing' in modules:
|
|
|
|
modules.remove('_testing')
|
|
|
|
missing = []
|
|
|
|
for name in modules:
|
2021-03-18 07:25:04 +00:00
|
|
|
module = Entry.Lookup('WriteDocs', name, False)
|
2018-07-17 19:25:36 +00:00
|
|
|
docs = getattr(module, '__doc__')
|
|
|
|
if test_missing == name:
|
|
|
|
docs = None
|
|
|
|
if docs:
|
|
|
|
lines = docs.splitlines()
|
|
|
|
first_line = lines[0]
|
|
|
|
rest = [line[4:] for line in lines[1:]]
|
|
|
|
hdr = 'Entry: %s: %s' % (name.replace('_', '-'), first_line)
|
2022-08-07 22:33:25 +00:00
|
|
|
|
|
|
|
# Create a reference for use by rST docs
|
|
|
|
ref_name = f'etype_{module.__name__[6:]}'.lower()
|
|
|
|
print('.. _%s:' % ref_name)
|
|
|
|
print()
|
2018-07-17 19:25:36 +00:00
|
|
|
print(hdr)
|
|
|
|
print('-' * len(hdr))
|
|
|
|
print('\n'.join(rest))
|
|
|
|
print()
|
|
|
|
print()
|
|
|
|
else:
|
|
|
|
missing.append(name)
|
|
|
|
|
|
|
|
if missing:
|
|
|
|
raise ValueError('Documentation is missing for modules: %s' %
|
|
|
|
', '.join(missing))
|
2018-09-14 10:57:11 +00:00
|
|
|
|
|
|
|
def GetUniqueName(self):
|
|
|
|
"""Get a unique name for a node
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
String containing a unique name for a node, consisting of the name
|
|
|
|
of all ancestors (starting from within the 'binman' node) separated
|
|
|
|
by a dot ('.'). This can be useful for generating unique filesnames
|
|
|
|
in the output directory.
|
|
|
|
"""
|
|
|
|
name = self.name
|
|
|
|
node = self._node
|
|
|
|
while node.parent:
|
|
|
|
node = node.parent
|
2022-03-27 15:31:44 +00:00
|
|
|
if node.name in ('binman', '/'):
|
2018-09-14 10:57:11 +00:00
|
|
|
break
|
|
|
|
name = '%s.%s' % (node.name, name)
|
|
|
|
return name
|
2018-09-14 10:57:29 +00:00
|
|
|
|
2022-03-06 03:18:59 +00:00
|
|
|
def extend_to_limit(self, limit):
|
|
|
|
"""Extend an entry so that it ends at the given offset limit"""
|
2018-09-14 10:57:29 +00:00
|
|
|
if self.offset + self.size < limit:
|
|
|
|
self.size = limit - self.offset
|
|
|
|
# Request the contents again, since changing the size requires that
|
|
|
|
# the data grows. This should not fail, but check it to be sure.
|
|
|
|
if not self.ObtainContents():
|
|
|
|
self.Raise('Cannot obtain contents when expanding entry')
|
2019-07-08 19:18:38 +00:00
|
|
|
|
|
|
|
def HasSibling(self, name):
|
|
|
|
"""Check if there is a sibling of a given name
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
True if there is an entry with this name in the the same section,
|
|
|
|
else False
|
|
|
|
"""
|
|
|
|
return name in self.section.GetEntries()
|
2019-07-08 20:25:28 +00:00
|
|
|
|
|
|
|
def GetSiblingImagePos(self, name):
|
|
|
|
"""Return the image position of the given sibling
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Image position of sibling, or None if the sibling has no position,
|
|
|
|
or False if there is no such sibling
|
|
|
|
"""
|
|
|
|
if not self.HasSibling(name):
|
|
|
|
return False
|
|
|
|
return self.section.GetEntries()[name].image_pos
|
2019-07-08 20:25:43 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def AddEntryInfo(entries, indent, name, etype, size, image_pos,
|
|
|
|
uncomp_size, offset, entry):
|
|
|
|
"""Add a new entry to the entries list
|
|
|
|
|
|
|
|
Args:
|
|
|
|
entries: List (of EntryInfo objects) to add to
|
|
|
|
indent: Current indent level to add to list
|
|
|
|
name: Entry name (string)
|
|
|
|
etype: Entry type (string)
|
|
|
|
size: Entry size in bytes (int)
|
|
|
|
image_pos: Position within image in bytes (int)
|
|
|
|
uncomp_size: Uncompressed size if the entry uses compression, else
|
|
|
|
None
|
|
|
|
offset: Entry offset within parent in bytes (int)
|
|
|
|
entry: Entry object
|
|
|
|
"""
|
|
|
|
entries.append(EntryInfo(indent, name, etype, size, image_pos,
|
|
|
|
uncomp_size, offset, entry))
|
|
|
|
|
|
|
|
def ListEntries(self, entries, indent):
|
|
|
|
"""Add files in this entry to the list of entries
|
|
|
|
|
|
|
|
This can be overridden by subclasses which need different behaviour.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
entries: List (of EntryInfo objects) to add to
|
|
|
|
indent: Current indent level to add to list
|
|
|
|
"""
|
|
|
|
self.AddEntryInfo(entries, indent, self.name, self.etype, self.size,
|
|
|
|
self.image_pos, self.uncomp_size, self.offset, self)
|
2019-07-08 20:25:50 +00:00
|
|
|
|
2021-11-24 04:09:50 +00:00
|
|
|
def ReadData(self, decomp=True, alt_format=None):
|
2019-07-08 20:25:50 +00:00
|
|
|
"""Read the data for an entry from the image
|
|
|
|
|
|
|
|
This is used when the image has been read in and we want to extract the
|
|
|
|
data for a particular entry from that image.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
decomp: True to decompress any compressed data before returning it;
|
|
|
|
False to return the raw, uncompressed data
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Entry data (bytes)
|
|
|
|
"""
|
|
|
|
# Use True here so that we get an uncompressed section to work from,
|
|
|
|
# although compressed sections are currently not supported
|
2022-01-29 21:14:15 +00:00
|
|
|
tout.debug("ReadChildData section '%s', entry '%s'" %
|
2019-09-25 14:56:21 +00:00
|
|
|
(self.section.GetPath(), self.GetPath()))
|
2021-11-24 04:09:50 +00:00
|
|
|
data = self.section.ReadChildData(self, decomp, alt_format)
|
2019-07-20 18:24:04 +00:00
|
|
|
return data
|
2019-07-20 18:23:41 +00:00
|
|
|
|
2021-11-24 04:09:50 +00:00
|
|
|
def ReadChildData(self, child, decomp=True, alt_format=None):
|
2019-09-25 14:56:21 +00:00
|
|
|
"""Read the data for a particular child entry
|
2019-09-25 14:56:20 +00:00
|
|
|
|
|
|
|
This reads data from the parent and extracts the piece that relates to
|
|
|
|
the given child.
|
|
|
|
|
|
|
|
Args:
|
2021-11-24 04:09:50 +00:00
|
|
|
child (Entry): Child entry to read data for (must be valid)
|
|
|
|
decomp (bool): True to decompress any compressed data before
|
|
|
|
returning it; False to return the raw, uncompressed data
|
|
|
|
alt_format (str): Alternative format to read in, or None
|
2019-09-25 14:56:20 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
Data for the child (bytes)
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2019-07-20 18:23:41 +00:00
|
|
|
def LoadData(self, decomp=True):
|
|
|
|
data = self.ReadData(decomp)
|
2019-07-20 18:23:50 +00:00
|
|
|
self.contents_size = len(data)
|
2019-07-20 18:23:41 +00:00
|
|
|
self.ProcessContentsUpdate(data)
|
|
|
|
self.Detail('Loaded data size %x' % len(data))
|
2019-07-20 18:23:46 +00:00
|
|
|
|
2021-11-24 04:09:50 +00:00
|
|
|
def GetAltFormat(self, data, alt_format):
|
|
|
|
"""Read the data for an extry in an alternative format
|
|
|
|
|
|
|
|
Supported formats are list in the documentation for each entry. An
|
|
|
|
example is fdtmap which provides .
|
|
|
|
|
|
|
|
Args:
|
|
|
|
data (bytes): Data to convert (this should have been produced by the
|
|
|
|
entry)
|
|
|
|
alt_format (str): Format to use
|
|
|
|
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2019-07-20 18:23:46 +00:00
|
|
|
def GetImage(self):
|
|
|
|
"""Get the image containing this entry
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Image object containing this entry
|
|
|
|
"""
|
|
|
|
return self.section.GetImage()
|
2019-07-20 18:23:50 +00:00
|
|
|
|
|
|
|
def WriteData(self, data, decomp=True):
|
|
|
|
"""Write the data to an entry in the image
|
|
|
|
|
|
|
|
This is used when the image has been read in and we want to replace the
|
|
|
|
data for a particular entry in that image.
|
|
|
|
|
|
|
|
The image must be re-packed and written out afterwards.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
data: Data to replace it with
|
|
|
|
decomp: True to compress the data if needed, False if data is
|
|
|
|
already compressed so should be used as is
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
True if the data did not result in a resize of this entry, False if
|
|
|
|
the entry must be resized
|
|
|
|
"""
|
2019-10-31 13:43:02 +00:00
|
|
|
if self.size is not None:
|
|
|
|
self.contents_size = self.size
|
|
|
|
else:
|
|
|
|
self.contents_size = self.pre_reset_size
|
2019-07-20 18:23:50 +00:00
|
|
|
ok = self.ProcessContentsUpdate(data)
|
|
|
|
self.Detail('WriteData: size=%x, ok=%s' % (len(data), ok))
|
2019-07-20 18:24:05 +00:00
|
|
|
section_ok = self.section.WriteChildData(self)
|
|
|
|
return ok and section_ok
|
|
|
|
|
|
|
|
def WriteChildData(self, child):
|
|
|
|
"""Handle writing the data in a child entry
|
|
|
|
|
|
|
|
This should be called on the child's parent section after the child's
|
2021-11-23 18:03:44 +00:00
|
|
|
data has been updated. It should update any data structures needed to
|
|
|
|
validate that the update is successful.
|
2019-07-20 18:24:05 +00:00
|
|
|
|
|
|
|
This base-class implementation does nothing, since the base Entry object
|
|
|
|
does not have any children.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
child: Child Entry that was written
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
True if the section could be updated successfully, False if the
|
2021-11-23 18:03:44 +00:00
|
|
|
data is such that the section could not update
|
2019-07-20 18:24:05 +00:00
|
|
|
"""
|
|
|
|
return True
|
2019-07-20 18:23:55 +00:00
|
|
|
|
|
|
|
def GetSiblingOrder(self):
|
|
|
|
"""Get the relative order of an entry amoung its siblings
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
'start' if this entry is first among siblings, 'end' if last,
|
|
|
|
otherwise None
|
|
|
|
"""
|
|
|
|
entries = list(self.section.GetEntries().values())
|
|
|
|
if entries:
|
|
|
|
if self == entries[0]:
|
|
|
|
return 'start'
|
|
|
|
elif self == entries[-1]:
|
|
|
|
return 'end'
|
|
|
|
return 'middle'
|
2020-07-10 00:39:38 +00:00
|
|
|
|
|
|
|
def SetAllowMissing(self, allow_missing):
|
|
|
|
"""Set whether a section allows missing external blobs
|
|
|
|
|
|
|
|
Args:
|
|
|
|
allow_missing: True if allowed, False if not allowed
|
|
|
|
"""
|
|
|
|
# This is meaningless for anything other than sections
|
|
|
|
pass
|
2020-07-10 00:39:40 +00:00
|
|
|
|
2022-01-06 10:49:41 +00:00
|
|
|
def SetAllowFakeBlob(self, allow_fake):
|
|
|
|
"""Set whether a section allows to create a fake blob
|
|
|
|
|
|
|
|
Args:
|
|
|
|
allow_fake: True if allowed, False if not allowed
|
|
|
|
"""
|
2022-01-10 03:13:46 +00:00
|
|
|
self.allow_fake = allow_fake
|
2022-01-06 10:49:41 +00:00
|
|
|
|
2020-07-10 00:39:40 +00:00
|
|
|
def CheckMissing(self, missing_list):
|
|
|
|
"""Check if any entries in this section have missing external blobs
|
|
|
|
|
|
|
|
If there are missing blobs, the entries are added to the list
|
|
|
|
|
|
|
|
Args:
|
|
|
|
missing_list: List of Entry objects to be added to
|
|
|
|
"""
|
|
|
|
if self.missing:
|
|
|
|
missing_list.append(self)
|
2020-09-01 11:13:57 +00:00
|
|
|
|
2022-03-06 03:19:04 +00:00
|
|
|
def check_fake_fname(self, fname, size=0):
|
2022-01-12 20:10:36 +00:00
|
|
|
"""If the file is missing and the entry allows fake blobs, fake it
|
|
|
|
|
|
|
|
Sets self.faked to True if faked
|
|
|
|
|
|
|
|
Args:
|
|
|
|
fname (str): Filename to check
|
2022-03-06 03:19:04 +00:00
|
|
|
size (int): Size of fake file to create
|
2022-01-12 20:10:36 +00:00
|
|
|
|
|
|
|
Returns:
|
2022-03-06 03:19:03 +00:00
|
|
|
tuple:
|
|
|
|
fname (str): Filename of faked file
|
|
|
|
bool: True if the blob was faked, False if not
|
2022-01-12 20:10:36 +00:00
|
|
|
"""
|
|
|
|
if self.allow_fake and not pathlib.Path(fname).is_file():
|
2022-08-07 15:46:46 +00:00
|
|
|
if not self.fake_fname:
|
|
|
|
outfname = os.path.join(self.fake_dir, os.path.basename(fname))
|
|
|
|
with open(outfname, "wb") as out:
|
|
|
|
out.truncate(size)
|
|
|
|
tout.info(f"Entry '{self._node.path}': Faked blob '{outfname}'")
|
|
|
|
self.fake_fname = outfname
|
2022-01-12 20:10:36 +00:00
|
|
|
self.faked = True
|
2022-08-07 15:46:46 +00:00
|
|
|
return self.fake_fname, True
|
2022-03-06 03:19:03 +00:00
|
|
|
return fname, False
|
2022-01-12 20:10:36 +00:00
|
|
|
|
2022-01-06 10:49:41 +00:00
|
|
|
def CheckFakedBlobs(self, faked_blobs_list):
|
|
|
|
"""Check if any entries in this section have faked external blobs
|
|
|
|
|
|
|
|
If there are faked blobs, the entries are added to the list
|
|
|
|
|
|
|
|
Args:
|
|
|
|
fake_blobs_list: List of Entry objects to be added to
|
|
|
|
"""
|
|
|
|
# This is meaningless for anything other than blobs
|
|
|
|
pass
|
|
|
|
|
2020-09-01 11:13:57 +00:00
|
|
|
def GetAllowMissing(self):
|
|
|
|
"""Get whether a section allows missing external blobs
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
True if allowed, False if not allowed
|
|
|
|
"""
|
|
|
|
return self.allow_missing
|
2020-09-06 16:39:09 +00:00
|
|
|
|
2022-01-10 03:14:09 +00:00
|
|
|
def record_missing_bintool(self, bintool):
|
|
|
|
"""Record a missing bintool that was needed to produce this entry
|
|
|
|
|
|
|
|
Args:
|
|
|
|
bintool (Bintool): Bintool that was missing
|
|
|
|
"""
|
|
|
|
self.missing_bintools.append(bintool)
|
|
|
|
|
|
|
|
def check_missing_bintools(self, missing_list):
|
|
|
|
"""Check if any entries in this section have missing bintools
|
|
|
|
|
|
|
|
If there are missing bintools, these are added to the list
|
|
|
|
|
|
|
|
Args:
|
|
|
|
missing_list: List of Bintool objects to be added to
|
|
|
|
"""
|
|
|
|
missing_list += self.missing_bintools
|
|
|
|
|
2020-09-06 16:39:09 +00:00
|
|
|
def GetHelpTags(self):
|
|
|
|
"""Get the tags use for missing-blob help
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
list of possible tags, most desirable first
|
|
|
|
"""
|
|
|
|
return list(filter(None, [self.missing_msg, self.name, self.etype]))
|
2020-10-26 23:40:06 +00:00
|
|
|
|
|
|
|
def CompressData(self, indata):
|
|
|
|
"""Compress data according to the entry's compression method
|
|
|
|
|
|
|
|
Args:
|
|
|
|
indata: Data to compress
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Compressed data (first word is the compressed size)
|
|
|
|
"""
|
2020-10-26 23:40:15 +00:00
|
|
|
self.uncomp_data = indata
|
2020-10-26 23:40:06 +00:00
|
|
|
if self.compress != 'none':
|
|
|
|
self.uncomp_size = len(indata)
|
2022-01-10 03:14:04 +00:00
|
|
|
data = comp_util.compress(indata, self.compress)
|
2020-10-26 23:40:06 +00:00
|
|
|
return data
|
2021-03-18 07:25:04 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def UseExpanded(cls, node, etype, new_etype):
|
|
|
|
"""Check whether to use an expanded entry type
|
|
|
|
|
|
|
|
This is called by Entry.Create() when it finds an expanded version of
|
|
|
|
an entry type (e.g. 'u-boot-expanded'). If this method returns True then
|
|
|
|
it will be used (e.g. in place of 'u-boot'). If it returns False, it is
|
|
|
|
ignored.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
node: Node object containing information about the entry to
|
|
|
|
create
|
|
|
|
etype: Original entry type being used
|
|
|
|
new_etype: New entry type proposed
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
True to use this entry type, False to use the original one
|
|
|
|
"""
|
2022-01-29 21:14:15 +00:00
|
|
|
tout.info("Node '%s': etype '%s': %s selected" %
|
2021-03-18 07:25:04 +00:00
|
|
|
(node.path, etype, new_etype))
|
|
|
|
return True
|
2021-11-24 04:09:50 +00:00
|
|
|
|
|
|
|
def CheckAltFormats(self, alt_formats):
|
|
|
|
"""Add any alternative formats supported by this entry type
|
|
|
|
|
|
|
|
Args:
|
|
|
|
alt_formats (dict): Dict to add alt_formats to:
|
|
|
|
key: Name of alt format
|
|
|
|
value: Help text
|
|
|
|
"""
|
|
|
|
pass
|
2022-01-10 03:13:50 +00:00
|
|
|
|
2022-03-06 03:19:02 +00:00
|
|
|
def AddBintools(self, btools):
|
2022-01-10 03:13:50 +00:00
|
|
|
"""Add the bintools used by this entry type
|
|
|
|
|
|
|
|
Args:
|
2022-03-06 03:19:02 +00:00
|
|
|
btools (dict of Bintool):
|
2022-01-10 03:13:50 +00:00
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def AddBintool(self, tools, name):
|
|
|
|
"""Add a new bintool to the tools used by this etype
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: Name of the tool
|
|
|
|
"""
|
|
|
|
btool = bintool.Bintool.create(name)
|
|
|
|
tools[name] = btool
|
|
|
|
return btool
|
2022-02-09 19:02:35 +00:00
|
|
|
|
|
|
|
def SetUpdateHash(self, update_hash):
|
|
|
|
"""Set whether this entry's "hash" subnode should be updated
|
|
|
|
|
|
|
|
Args:
|
|
|
|
update_hash: True if hash should be updated, False if not
|
|
|
|
"""
|
|
|
|
self.update_hash = update_hash
|
2022-02-08 18:50:00 +00:00
|
|
|
|
2022-03-06 03:19:05 +00:00
|
|
|
def collect_contents_to_file(self, entries, prefix, fake_size=0):
|
2022-02-08 18:50:00 +00:00
|
|
|
"""Put the contents of a list of entries into a file
|
|
|
|
|
|
|
|
Args:
|
|
|
|
entries (list of Entry): Entries to collect
|
|
|
|
prefix (str): Filename prefix of file to write to
|
2022-03-06 03:19:05 +00:00
|
|
|
fake_size (int): Size of fake file to create if needed
|
2022-02-08 18:50:00 +00:00
|
|
|
|
|
|
|
If any entry does not have contents yet, this function returns False
|
|
|
|
for the data.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Tuple:
|
2022-03-06 03:18:58 +00:00
|
|
|
bytes: Concatenated data from all the entries (or None)
|
|
|
|
str: Filename of file written (or None if no data)
|
|
|
|
str: Unique portion of filename (or None if no data)
|
2022-02-08 18:50:00 +00:00
|
|
|
"""
|
|
|
|
data = b''
|
|
|
|
for entry in entries:
|
|
|
|
# First get the input data and put it in a file. If not available,
|
|
|
|
# try later.
|
2022-03-06 03:19:05 +00:00
|
|
|
if not entry.ObtainContents(fake_size=fake_size):
|
2022-03-06 03:18:58 +00:00
|
|
|
return None, None, None
|
2022-02-08 18:50:00 +00:00
|
|
|
data += entry.GetData()
|
|
|
|
uniq = self.GetUniqueName()
|
|
|
|
fname = tools.get_output_filename(f'{prefix}.{uniq}')
|
|
|
|
tools.write_file(fname, data)
|
|
|
|
return data, fname, uniq
|
2022-08-07 15:46:46 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def create_fake_dir(cls):
|
|
|
|
"""Create the directory for fake files"""
|
|
|
|
cls.fake_dir = tools.get_output_filename('binman-fake')
|
|
|
|
if not os.path.exists(cls.fake_dir):
|
|
|
|
os.mkdir(cls.fake_dir)
|
|
|
|
tout.notice(f"Fake-blob dir is '{cls.fake_dir}'")
|
2022-08-13 17:40:44 +00:00
|
|
|
|
|
|
|
def ensure_props(self):
|
|
|
|
"""Raise an exception if properties are missing
|
|
|
|
|
|
|
|
Args:
|
|
|
|
prop_list (list of str): List of properties to check for
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
ValueError: Any property is missing
|
|
|
|
"""
|
|
|
|
not_present = []
|
|
|
|
for prop in self.required_props:
|
|
|
|
if not prop in self._node.props:
|
|
|
|
not_present.append(prop)
|
|
|
|
if not_present:
|
|
|
|
self.Raise(f"'{self.etype}' entry is missing properties: {' '.join(not_present)}")
|