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-06-01 15:38:20 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2018-07-17 19:25:32 +00:00
|
|
|
from collections import namedtuple
|
|
|
|
|
2016-11-26 03:15:51 +00:00
|
|
|
# importlib was introduced in Python 2.7 but there was a report of it not
|
|
|
|
# working in 2.7.12, so we work around this:
|
|
|
|
# http://lists.denx.de/pipermail/u-boot/2016-October/269729.html
|
|
|
|
try:
|
|
|
|
import importlib
|
|
|
|
have_importlib = True
|
|
|
|
except:
|
|
|
|
have_importlib = False
|
|
|
|
|
2018-06-01 15:38:15 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2018-09-14 10:57:19 +00:00
|
|
|
|
|
|
|
import fdt_util
|
|
|
|
import state
|
2016-11-26 03:15:51 +00:00
|
|
|
import tools
|
2019-07-08 20:25:49 +00:00
|
|
|
import tout
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
modules = {}
|
|
|
|
|
2018-06-01 15:38:15 +00:00
|
|
|
our_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
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-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
|
2018-08-01 21:22:37 +00:00
|
|
|
align: Entry start offset alignment, or None
|
2016-11-26 03:15:51 +00:00
|
|
|
align_size: Entry size alignment, or None
|
2018-08-01 21:22:37 +00:00
|
|
|
align_end: Entry end offset alignment, or None
|
2016-11-26 03:15:51 +00:00
|
|
|
pad_before: Number of pad bytes before the contents, 0 if none
|
|
|
|
pad_after: Number of pad bytes after the contents, 0 if none
|
|
|
|
data: Contents of entry (string of bytes)
|
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
|
2016-11-26 03:15:51 +00:00
|
|
|
"""
|
2018-06-01 15:38:21 +00:00
|
|
|
def __init__(self, section, etype, node, read_node=True, name_prefix=''):
|
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-07-08 20:25:30 +00:00
|
|
|
self.uncomp_size = None
|
2018-07-17 19:25:47 +00:00
|
|
|
self.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
|
2018-09-14 10:57:29 +00:00
|
|
|
self._expand_size = False
|
2019-07-08 20:25:30 +00:00
|
|
|
self.compress = 'none'
|
2016-11-26 03:15:51 +00:00
|
|
|
if read_node:
|
|
|
|
self.ReadNode()
|
|
|
|
|
|
|
|
@staticmethod
|
2019-07-08 20:25:31 +00:00
|
|
|
def Lookup(node_path, etype):
|
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
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
Returns:
|
2018-07-17 19:25:36 +00:00
|
|
|
The entry class object if found, else None
|
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('-', '_')
|
2018-06-01 15:38:11 +00:00
|
|
|
if '@' in module_name:
|
|
|
|
module_name = module_name.split('@')[0]
|
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:
|
2018-06-01 15:38:15 +00:00
|
|
|
old_path = sys.path
|
|
|
|
sys.path.insert(0, os.path.join(our_path, 'etype'))
|
2016-11-26 03:15:51 +00:00
|
|
|
try:
|
|
|
|
if have_importlib:
|
|
|
|
module = importlib.import_module(module_name)
|
|
|
|
else:
|
|
|
|
module = __import__(module_name)
|
2018-07-17 19:25:36 +00:00
|
|
|
except ImportError as e:
|
|
|
|
raise ValueError("Unknown entry type '%s' in node '%s' (expected etype/%s.py, error '%s'" %
|
|
|
|
(etype, node_path, module_name, e))
|
2018-06-01 15:38:15 +00:00
|
|
|
finally:
|
|
|
|
sys.path = old_path
|
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
|
|
|
|
def Create(section, node, etype=None):
|
|
|
|
"""Create a new entry for a node.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
section: Section object containing this node
|
|
|
|
node: Node object containing information about the entry to
|
|
|
|
create
|
|
|
|
etype: Entry type to use, or None to work it out (used for tests)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A new Entry object of the correct type (a subclass of Entry)
|
|
|
|
"""
|
|
|
|
if not etype:
|
|
|
|
etype = fdt_util.GetString(node, 'type', node.name)
|
2019-07-08 20:25:31 +00:00
|
|
|
obj = Entry.Lookup(node.path, 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
|
|
|
|
|
|
|
|
This reads all the fields we recognise from the node, ready for use.
|
|
|
|
"""
|
2018-07-17 19:25:51 +00:00
|
|
|
if 'pos' in self._node.props:
|
|
|
|
self.Raise("Please use 'offset' instead of 'pos'")
|
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-08 20:25:37 +00:00
|
|
|
self.orig_offset = self.offset
|
|
|
|
self.orig_size = self.size
|
|
|
|
|
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')
|
|
|
|
if tools.NotPowerOfTwo(self.align):
|
|
|
|
raise ValueError("Node '%s': Alignment %s must be a power of two" %
|
|
|
|
(self._node.path, self.align))
|
|
|
|
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')
|
|
|
|
if tools.NotPowerOfTwo(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')
|
2018-09-14 10:57:29 +00:00
|
|
|
self.expand_size = fdt_util.GetBool(self._node, 'expand-size')
|
2016-11-26 03:15:51 +00:00
|
|
|
|
2018-09-14 10:57:18 +00:00
|
|
|
def GetDefaultFilename(self):
|
|
|
|
return None
|
|
|
|
|
2018-09-14 10:57:22 +00:00
|
|
|
def GetFdtSet(self):
|
|
|
|
"""Get the set of device trees used by this entry
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Set containing the filename from this entry, if it is a .dtb, else
|
|
|
|
an empty set
|
|
|
|
"""
|
2019-05-14 21:53:39 +00:00
|
|
|
return set()
|
2018-09-14 10:57:22 +00:00
|
|
|
|
2018-09-14 10:57:28 +00:00
|
|
|
def ExpandEntries(self):
|
|
|
|
pass
|
|
|
|
|
2018-07-06 16:27:41 +00:00
|
|
|
def AddMissingProperties(self):
|
|
|
|
"""Add new properties to the device tree as needed for this entry"""
|
2018-08-01 21:22:42 +00:00
|
|
|
for prop in ['offset', 'size', 'image-pos']:
|
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)
|
2019-07-08 20:25:30 +00:00
|
|
|
if self.compress != 'none':
|
|
|
|
state.AddZeroProp(self._node, 'uncomp-size')
|
2018-09-14 10:57:31 +00:00
|
|
|
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
|
|
|
|
state.SetInt(self._node, 'image-pos', self.image_pos - base)
|
2019-07-08 20:25:30 +00:00
|
|
|
if self.uncomp_size is not None:
|
|
|
|
state.SetInt(self._node, 'uncomp-size', self.uncomp_size)
|
2018-09-14 10:57:31 +00:00
|
|
|
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)
|
|
|
|
if state.AllowEntryExpansion():
|
|
|
|
if new_size > self.contents_size:
|
2019-07-08 20:25:49 +00:00
|
|
|
tout.Debug("Entry '%s' size change from %#x to %#x" % (
|
2019-07-08 20:25:37 +00:00
|
|
|
self._node.path, self.contents_size, new_size))
|
|
|
|
# self.data will indicate the new size needed
|
|
|
|
size_ok = False
|
|
|
|
elif new_size != self.contents_size:
|
2018-07-06 16:27:19 +00:00
|
|
|
self.Raise('Cannot update entry size from %d to %d' %
|
2019-07-08 20:25:37 +00:00
|
|
|
(self.contents_size, 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
|
|
|
|
2016-11-26 03:15:51 +00:00
|
|
|
def ObtainContents(self):
|
|
|
|
"""Figure out the contents of an entry.
|
|
|
|
|
|
|
|
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"""
|
|
|
|
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
|
|
|
"""
|
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?')
|
|
|
|
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
|
|
|
|
needed = tools.Align(needed, self.align_size)
|
|
|
|
size = self.size
|
|
|
|
if not size:
|
|
|
|
size = needed
|
2018-08-01 21:22:37 +00:00
|
|
|
new_offset = self.offset + size
|
|
|
|
aligned_offset = tools.Align(new_offset, self.align_end)
|
|
|
|
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
|
|
|
|
if self.size != tools.Align(self.size, self.align_size):
|
|
|
|
self.Raise("Size %#x (%d) does not match align-size %#x (%d)" %
|
|
|
|
(self.size, self.size, self.align_size, self.align_size))
|
2018-08-01 21:22:37 +00:00
|
|
|
if self.offset != tools.Align(self.offset, self.align):
|
|
|
|
self.Raise("Offset %#x (%d) does not match align %#x (%d)" %
|
|
|
|
(self.offset, self.offset, self.align, self.align))
|
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))
|
|
|
|
|
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:
|
|
|
|
self.Raise('Missing required properties/entry args: %s' %
|
|
|
|
(', '.join(missing)))
|
|
|
|
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
|
|
|
|
|
|
|
|
def GetData(self):
|
|
|
|
return 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
|
|
|
|
2018-08-01 21:22:37 +00:00
|
|
|
def CheckOffset(self):
|
|
|
|
"""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
|
|
|
|
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
|
|
|
|
|
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:
|
2019-07-08 20:25:32 +00:00
|
|
|
if name.startswith('__'):
|
|
|
|
continue
|
2019-07-08 20:25:31 +00:00
|
|
|
module = Entry.Lookup(name, name)
|
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)
|
|
|
|
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
|
|
|
|
if node.name == 'binman':
|
|
|
|
break
|
|
|
|
name = '%s.%s' % (node.name, name)
|
|
|
|
return name
|
2018-09-14 10:57:29 +00:00
|
|
|
|
|
|
|
def ExpandToLimit(self, limit):
|
|
|
|
"""Expand an entry so that it ends at the given offset limit"""
|
|
|
|
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
|
|
|
|
|
|
|
def ReadData(self, decomp=True):
|
|
|
|
"""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
|
|
|
|
data = self.section.ReadData(True)
|
|
|
|
tout.Info('%s: Reading data from offset %#x-%#x, size %#x (avail %#x)' %
|
|
|
|
(self.GetPath(), self.offset, self.offset + self.size,
|
|
|
|
self.size, len(data)))
|
|
|
|
return data[self.offset:self.offset + self.size]
|