2018-09-14 10:57:19 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
|
|
|
# Copyright 2018 Google, Inc
|
|
|
|
# Written by Simon Glass <sjg@chromium.org>
|
|
|
|
#
|
|
|
|
# Holds and modifies the state information held by binman
|
|
|
|
#
|
|
|
|
|
2021-07-06 16:36:41 +00:00
|
|
|
from collections import defaultdict
|
2018-09-14 10:57:31 +00:00
|
|
|
import hashlib
|
2018-09-14 10:57:19 +00:00
|
|
|
import re
|
2021-07-06 16:36:41 +00:00
|
|
|
import time
|
2021-07-06 16:36:37 +00:00
|
|
|
import threading
|
2018-09-14 10:57:19 +00:00
|
|
|
|
2020-04-18 00:09:03 +00:00
|
|
|
from dtoc import fdt
|
2018-09-14 10:57:19 +00:00
|
|
|
import os
|
2023-02-24 01:18:04 +00:00
|
|
|
from u_boot_pylib import tools
|
|
|
|
from u_boot_pylib import tout
|
2018-09-14 10:57:19 +00:00
|
|
|
|
2021-11-23 18:03:42 +00:00
|
|
|
OUR_PATH = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
2021-03-18 07:25:00 +00:00
|
|
|
# Map an dtb etype to its expected filename
|
|
|
|
DTB_TYPE_FNAME = {
|
|
|
|
'u-boot-spl-dtb': 'spl/u-boot-spl.dtb',
|
|
|
|
'u-boot-tpl-dtb': 'tpl/u-boot-tpl.dtb',
|
2022-02-28 14:16:54 +00:00
|
|
|
'u-boot-vpl-dtb': 'vpl/u-boot-vpl.dtb',
|
2021-03-18 07:25:00 +00:00
|
|
|
}
|
|
|
|
|
2019-07-20 18:23:32 +00:00
|
|
|
# Records the device-tree files known to binman, keyed by entry type (e.g.
|
|
|
|
# 'u-boot-spl-dtb'). These are the output FDT files, which can be updated by
|
|
|
|
# binman. They have been copied to <xxx>.out files.
|
|
|
|
#
|
2021-03-18 07:25:01 +00:00
|
|
|
# key: entry type (e.g. 'u-boot-dtb)
|
2019-07-20 18:23:32 +00:00
|
|
|
# value: tuple:
|
|
|
|
# Fdt object
|
|
|
|
# Filename
|
2019-07-20 18:23:43 +00:00
|
|
|
output_fdt_info = {}
|
2018-09-14 10:57:19 +00:00
|
|
|
|
2019-07-20 18:23:50 +00:00
|
|
|
# Prefix to add to an fdtmap path to turn it into a path to the /binman node
|
|
|
|
fdt_path_prefix = ''
|
|
|
|
|
2018-09-14 10:57:19 +00:00
|
|
|
# Arguments passed to binman to provide arguments to entries
|
|
|
|
entry_args = {}
|
|
|
|
|
2018-09-14 10:57:22 +00:00
|
|
|
# True to use fake device-tree files for testing (see U_BOOT_DTB_DATA in
|
|
|
|
# ftest.py)
|
2018-09-14 10:57:23 +00:00
|
|
|
use_fake_dtb = False
|
2018-09-14 10:57:22 +00:00
|
|
|
|
2018-09-14 10:57:20 +00:00
|
|
|
# The DTB which contains the full image information
|
|
|
|
main_dtb = None
|
|
|
|
|
2019-07-08 20:25:36 +00:00
|
|
|
# Allow entries to expand after they have been packed. This is detected and
|
|
|
|
# forces a re-pack. If not allowed, any attempted expansion causes an error in
|
|
|
|
# Entry.ProcessContentsUpdate()
|
|
|
|
allow_entry_expansion = True
|
|
|
|
|
2019-07-20 18:23:58 +00:00
|
|
|
# Don't allow entries to contract after they have been packed. Instead just
|
|
|
|
# leave some wasted space. If allowed, this is detected and forces a re-pack,
|
|
|
|
# but may result in entries that oscillate in size, thus causing a pack error.
|
|
|
|
# An example is a compressed device tree where the original offset values
|
|
|
|
# result in a larger compressed size than the new ones, but then after updating
|
|
|
|
# to the new ones, the compressed size increases, etc.
|
|
|
|
allow_entry_contraction = False
|
|
|
|
|
2021-07-06 16:36:37 +00:00
|
|
|
# Number of threads to use for binman (None means machine-dependent)
|
|
|
|
num_threads = None
|
|
|
|
|
2021-07-06 16:36:41 +00:00
|
|
|
|
|
|
|
class Timing:
|
|
|
|
"""Holds information about an operation that is being timed
|
|
|
|
|
|
|
|
Properties:
|
|
|
|
name: Operation name (only one of each name is stored)
|
|
|
|
start: Start time of operation in seconds (None if not start)
|
|
|
|
accum:: Amount of time spent on this operation so far, in seconds
|
|
|
|
"""
|
|
|
|
def __init__(self, name):
|
|
|
|
self.name = name
|
|
|
|
self.start = None # cause an error if TimingStart() is not called
|
|
|
|
self.accum = 0.0
|
|
|
|
|
|
|
|
|
|
|
|
# Holds timing info for each name:
|
|
|
|
# key: name of Timing info (Timing.name)
|
|
|
|
# value: Timing object
|
|
|
|
timing_info = {}
|
|
|
|
|
|
|
|
|
2019-07-20 18:23:32 +00:00
|
|
|
def GetFdtForEtype(etype):
|
|
|
|
"""Get the Fdt object for a particular device-tree entry
|
2018-09-14 10:57:19 +00:00
|
|
|
|
|
|
|
Binman keeps track of at least one device-tree file called u-boot.dtb but
|
|
|
|
can also have others (e.g. for SPL). This function looks up the given
|
2019-07-20 18:23:32 +00:00
|
|
|
entry and returns the associated Fdt object.
|
2018-09-14 10:57:19 +00:00
|
|
|
|
|
|
|
Args:
|
2019-07-20 18:23:32 +00:00
|
|
|
etype: Entry type of device tree (e.g. 'u-boot-dtb')
|
2018-09-14 10:57:19 +00:00
|
|
|
|
|
|
|
Returns:
|
2019-07-20 18:23:32 +00:00
|
|
|
Fdt object associated with the entry type
|
2018-09-14 10:57:19 +00:00
|
|
|
"""
|
2019-07-20 18:23:43 +00:00
|
|
|
value = output_fdt_info.get(etype);
|
2019-07-20 18:23:42 +00:00
|
|
|
if not value:
|
|
|
|
return None
|
|
|
|
return value[0]
|
2018-09-14 10:57:19 +00:00
|
|
|
|
2019-07-20 18:23:32 +00:00
|
|
|
def GetFdtPath(etype):
|
2018-09-14 10:57:19 +00:00
|
|
|
"""Get the full pathname of a particular Fdt object
|
|
|
|
|
2019-07-20 18:23:30 +00:00
|
|
|
Similar to GetFdtForEtype() but returns the pathname associated with the
|
|
|
|
Fdt.
|
2018-09-14 10:57:19 +00:00
|
|
|
|
|
|
|
Args:
|
2019-07-20 18:23:32 +00:00
|
|
|
etype: Entry type of device tree (e.g. 'u-boot-dtb')
|
2018-09-14 10:57:19 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
Full path name to the associated Fdt
|
|
|
|
"""
|
2019-07-20 18:23:43 +00:00
|
|
|
return output_fdt_info[etype][0]._fname
|
2018-09-14 10:57:19 +00:00
|
|
|
|
2019-07-20 18:23:32 +00:00
|
|
|
def GetFdtContents(etype='u-boot-dtb'):
|
2018-09-14 10:57:24 +00:00
|
|
|
"""Looks up the FDT pathname and contents
|
|
|
|
|
|
|
|
This is used to obtain the Fdt pathname and contents when needed by an
|
|
|
|
entry. It supports a 'fake' dtb, allowing tests to substitute test data for
|
|
|
|
the real dtb.
|
|
|
|
|
|
|
|
Args:
|
2019-07-20 18:23:32 +00:00
|
|
|
etype: Entry type to look up (e.g. 'u-boot.dtb').
|
2018-09-14 10:57:24 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
tuple:
|
|
|
|
pathname to Fdt
|
|
|
|
Fdt data (as bytes)
|
|
|
|
"""
|
2019-07-20 18:23:43 +00:00
|
|
|
if etype not in output_fdt_info:
|
2019-07-20 18:23:42 +00:00
|
|
|
return None, None
|
|
|
|
if not use_fake_dtb:
|
2019-07-20 18:23:32 +00:00
|
|
|
pathname = GetFdtPath(etype)
|
|
|
|
data = GetFdtForEtype(etype).GetContents()
|
2018-09-14 10:57:24 +00:00
|
|
|
else:
|
2019-07-20 18:23:43 +00:00
|
|
|
fname = output_fdt_info[etype][1]
|
2022-01-29 21:14:04 +00:00
|
|
|
pathname = tools.get_input_filename(fname)
|
|
|
|
data = tools.read_file(pathname)
|
2018-09-14 10:57:24 +00:00
|
|
|
return pathname, data
|
|
|
|
|
2019-07-20 18:24:08 +00:00
|
|
|
def UpdateFdtContents(etype, data):
|
|
|
|
"""Update the contents of a particular device tree
|
|
|
|
|
|
|
|
The device tree is updated and written back to its file. This affects what
|
|
|
|
is returned from future called to GetFdtContents(), etc.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
etype: Entry type (e.g. 'u-boot-dtb')
|
|
|
|
data: Data to replace the DTB with
|
|
|
|
"""
|
2021-03-18 07:25:01 +00:00
|
|
|
dtb, fname = output_fdt_info[etype]
|
2019-07-20 18:24:08 +00:00
|
|
|
dtb_fname = dtb.GetFilename()
|
2022-01-29 21:14:04 +00:00
|
|
|
tools.write_file(dtb_fname, data)
|
2019-07-20 18:24:08 +00:00
|
|
|
dtb = fdt.FdtScan(dtb_fname)
|
2021-03-18 07:25:01 +00:00
|
|
|
output_fdt_info[etype] = [dtb, fname]
|
2019-07-20 18:24:08 +00:00
|
|
|
|
2018-09-14 10:57:19 +00:00
|
|
|
def SetEntryArgs(args):
|
|
|
|
"""Set the value of the entry args
|
|
|
|
|
|
|
|
This sets up the entry_args dict which is used to supply entry arguments to
|
|
|
|
entries.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
args: List of entry arguments, each in the format "name=value"
|
|
|
|
"""
|
|
|
|
global entry_args
|
|
|
|
|
|
|
|
entry_args = {}
|
2022-01-29 21:14:15 +00:00
|
|
|
tout.debug('Processing entry args:')
|
2018-09-14 10:57:19 +00:00
|
|
|
if args:
|
|
|
|
for arg in args:
|
|
|
|
m = re.match('([^=]*)=(.*)', arg)
|
|
|
|
if not m:
|
|
|
|
raise ValueError("Invalid entry arguemnt '%s'" % arg)
|
2021-03-18 07:25:07 +00:00
|
|
|
name, value = m.groups()
|
2022-01-29 21:14:15 +00:00
|
|
|
tout.debug(' %20s = %s' % (name, value))
|
2021-03-18 07:25:07 +00:00
|
|
|
entry_args[name] = value
|
2022-01-29 21:14:15 +00:00
|
|
|
tout.debug('Processing entry args done')
|
2018-09-14 10:57:19 +00:00
|
|
|
|
|
|
|
def GetEntryArg(name):
|
|
|
|
"""Get the value of an entry argument
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: Name of argument to retrieve
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
String value of argument
|
|
|
|
"""
|
|
|
|
return entry_args.get(name)
|
2018-09-14 10:57:20 +00:00
|
|
|
|
2021-03-18 07:25:07 +00:00
|
|
|
def GetEntryArgBool(name):
|
|
|
|
"""Get the value of an entry argument as a boolean
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: Name of argument to retrieve
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
False if the entry argument is consider False (empty, '0' or 'n'), else
|
|
|
|
True
|
|
|
|
"""
|
|
|
|
val = GetEntryArg(name)
|
|
|
|
return val and val not in ['n', '0']
|
|
|
|
|
2018-09-14 10:57:22 +00:00
|
|
|
def Prepare(images, dtb):
|
2018-09-14 10:57:20 +00:00
|
|
|
"""Get device tree files ready for use
|
|
|
|
|
2019-07-20 18:23:29 +00:00
|
|
|
This sets up a set of device tree files that can be retrieved by
|
|
|
|
GetAllFdts(). This includes U-Boot proper and any SPL device trees.
|
2018-09-14 10:57:20 +00:00
|
|
|
|
|
|
|
Args:
|
2018-09-14 10:57:22 +00:00
|
|
|
images: List of images being used
|
2018-09-14 10:57:20 +00:00
|
|
|
dtb: Main dtb
|
|
|
|
"""
|
2019-07-20 18:23:50 +00:00
|
|
|
global output_fdt_info, main_dtb, fdt_path_prefix
|
2018-09-14 10:57:20 +00:00
|
|
|
# Import these here in case libfdt.py is not available, in which case
|
|
|
|
# the above help option still works.
|
2020-04-18 00:09:03 +00:00
|
|
|
from dtoc import fdt
|
|
|
|
from dtoc import fdt_util
|
2018-09-14 10:57:20 +00:00
|
|
|
|
|
|
|
# If we are updating the DTBs we need to put these updated versions
|
|
|
|
# where Entry_blob_dtb can find them. We can ignore 'u-boot.dtb'
|
|
|
|
# since it is assumed to be the one passed in with options.dt, and
|
|
|
|
# was handled just above.
|
|
|
|
main_dtb = dtb
|
2019-07-20 18:23:43 +00:00
|
|
|
output_fdt_info.clear()
|
2019-07-20 18:23:50 +00:00
|
|
|
fdt_path_prefix = ''
|
2021-03-18 07:25:01 +00:00
|
|
|
output_fdt_info['u-boot-dtb'] = [dtb, 'u-boot.dtb']
|
2021-03-18 07:25:00 +00:00
|
|
|
if use_fake_dtb:
|
|
|
|
for etype, fname in DTB_TYPE_FNAME.items():
|
2021-03-18 07:25:01 +00:00
|
|
|
output_fdt_info[etype] = [dtb, fname]
|
2021-03-18 07:25:00 +00:00
|
|
|
else:
|
2019-07-20 18:23:34 +00:00
|
|
|
fdt_set = {}
|
binman: Use standard filenames for SPL/TPL devicetree
At present, before any entry expansion is done (such as a 'files' entry
expanding out to individual entries for each file it contains), we check
the binman definition (i.e. '/binman' node) to find out what devicetree
files are used in the images.
This is a pain, since the definition may change during expansion. For
example if there is no u-boot-spl-dtb entry in the definition at the start,
we assume that the SPL devicetree is not used. But if an entry later
expands to include this, then we don't notice.
In fact the flexibility provided by the current approach of checking the
definition is not really useful. We know that we can have SPL and TPL
devicetrees. We know the pathname to each, so we can simply check if the
files are present. If they are present, we can prepare them and update
them regardless of whether they are actually used. If they are not present,
we cannot prepare/update them anyway, i.e. an error will be generated.
Simplify state.Prepare() so it uses a hard-coded list of devicetree files.
Note that state.PrepareFromLoadedData() is left untouched, since in that
case we have a complete definition from the loaded file, but cannot of
course rely on the devicetree files that created it still being present.
So in that case we still check the image defitions.
Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-18 07:25:03 +00:00
|
|
|
for etype, fname in DTB_TYPE_FNAME.items():
|
2022-01-29 21:14:04 +00:00
|
|
|
infile = tools.get_input_filename(fname, allow_missing=True)
|
binman: Use standard filenames for SPL/TPL devicetree
At present, before any entry expansion is done (such as a 'files' entry
expanding out to individual entries for each file it contains), we check
the binman definition (i.e. '/binman' node) to find out what devicetree
files are used in the images.
This is a pain, since the definition may change during expansion. For
example if there is no u-boot-spl-dtb entry in the definition at the start,
we assume that the SPL devicetree is not used. But if an entry later
expands to include this, then we don't notice.
In fact the flexibility provided by the current approach of checking the
definition is not really useful. We know that we can have SPL and TPL
devicetrees. We know the pathname to each, so we can simply check if the
files are present. If they are present, we can prepare them and update
them regardless of whether they are actually used. If they are not present,
we cannot prepare/update them anyway, i.e. an error will be generated.
Simplify state.Prepare() so it uses a hard-coded list of devicetree files.
Note that state.PrepareFromLoadedData() is left untouched, since in that
case we have a complete definition from the loaded file, but cannot of
course rely on the devicetree files that created it still being present.
So in that case we still check the image defitions.
Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-18 07:25:03 +00:00
|
|
|
if infile and os.path.exists(infile):
|
|
|
|
fname_dtb = fdt_util.EnsureCompiled(infile)
|
2022-01-29 21:14:04 +00:00
|
|
|
out_fname = tools.get_output_filename('%s.out' %
|
binman: Use standard filenames for SPL/TPL devicetree
At present, before any entry expansion is done (such as a 'files' entry
expanding out to individual entries for each file it contains), we check
the binman definition (i.e. '/binman' node) to find out what devicetree
files are used in the images.
This is a pain, since the definition may change during expansion. For
example if there is no u-boot-spl-dtb entry in the definition at the start,
we assume that the SPL devicetree is not used. But if an entry later
expands to include this, then we don't notice.
In fact the flexibility provided by the current approach of checking the
definition is not really useful. We know that we can have SPL and TPL
devicetrees. We know the pathname to each, so we can simply check if the
files are present. If they are present, we can prepare them and update
them regardless of whether they are actually used. If they are not present,
we cannot prepare/update them anyway, i.e. an error will be generated.
Simplify state.Prepare() so it uses a hard-coded list of devicetree files.
Note that state.PrepareFromLoadedData() is left untouched, since in that
case we have a complete definition from the loaded file, but cannot of
course rely on the devicetree files that created it still being present.
So in that case we still check the image defitions.
Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-18 07:25:03 +00:00
|
|
|
os.path.split(fname)[1])
|
2022-01-29 21:14:04 +00:00
|
|
|
tools.write_file(out_fname, tools.read_file(fname_dtb))
|
binman: Use standard filenames for SPL/TPL devicetree
At present, before any entry expansion is done (such as a 'files' entry
expanding out to individual entries for each file it contains), we check
the binman definition (i.e. '/binman' node) to find out what devicetree
files are used in the images.
This is a pain, since the definition may change during expansion. For
example if there is no u-boot-spl-dtb entry in the definition at the start,
we assume that the SPL devicetree is not used. But if an entry later
expands to include this, then we don't notice.
In fact the flexibility provided by the current approach of checking the
definition is not really useful. We know that we can have SPL and TPL
devicetrees. We know the pathname to each, so we can simply check if the
files are present. If they are present, we can prepare them and update
them regardless of whether they are actually used. If they are not present,
we cannot prepare/update them anyway, i.e. an error will be generated.
Simplify state.Prepare() so it uses a hard-coded list of devicetree files.
Note that state.PrepareFromLoadedData() is left untouched, since in that
case we have a complete definition from the loaded file, but cannot of
course rely on the devicetree files that created it still being present.
So in that case we still check the image defitions.
Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-18 07:25:03 +00:00
|
|
|
other_dtb = fdt.FdtScan(out_fname)
|
|
|
|
output_fdt_info[etype] = [other_dtb, out_fname]
|
|
|
|
|
2018-09-14 10:57:20 +00:00
|
|
|
|
2019-07-20 18:23:50 +00:00
|
|
|
def PrepareFromLoadedData(image):
|
|
|
|
"""Get device tree files ready for use with a loaded image
|
|
|
|
|
|
|
|
Loaded images are different from images that are being created by binman,
|
|
|
|
since there is generally already an fdtmap and we read the description from
|
|
|
|
that. This provides the position and size of every entry in the image with
|
|
|
|
no calculation required.
|
|
|
|
|
|
|
|
This function uses the same output_fdt_info[] as Prepare(). It finds the
|
|
|
|
device tree files, adds a reference to the fdtmap and sets the FDT path
|
|
|
|
prefix to translate from the fdtmap (where the root node is the image node)
|
|
|
|
to the normal device tree (where the image node is under a /binman node).
|
|
|
|
|
|
|
|
Args:
|
|
|
|
images: List of images being used
|
|
|
|
"""
|
|
|
|
global output_fdt_info, main_dtb, fdt_path_prefix
|
|
|
|
|
2022-01-29 21:14:15 +00:00
|
|
|
tout.info('Preparing device trees')
|
2019-07-20 18:23:50 +00:00
|
|
|
output_fdt_info.clear()
|
|
|
|
fdt_path_prefix = ''
|
2021-03-18 07:25:01 +00:00
|
|
|
output_fdt_info['fdtmap'] = [image.fdtmap_dtb, 'u-boot.dtb']
|
2019-07-20 18:23:50 +00:00
|
|
|
main_dtb = None
|
2022-01-29 21:14:15 +00:00
|
|
|
tout.info(" Found device tree type 'fdtmap' '%s'" % image.fdtmap_dtb.name)
|
2019-07-20 18:23:50 +00:00
|
|
|
for etype, value in image.GetFdts().items():
|
|
|
|
entry, fname = value
|
2022-01-29 21:14:04 +00:00
|
|
|
out_fname = tools.get_output_filename('%s.dtb' % entry.etype)
|
2022-01-29 21:14:15 +00:00
|
|
|
tout.info(" Found device tree type '%s' at '%s' path '%s'" %
|
2019-07-20 18:23:50 +00:00
|
|
|
(etype, out_fname, entry.GetPath()))
|
|
|
|
entry._filename = entry.GetDefaultFilename()
|
|
|
|
data = entry.ReadData()
|
|
|
|
|
2022-01-29 21:14:04 +00:00
|
|
|
tools.write_file(out_fname, data)
|
2019-07-20 18:23:50 +00:00
|
|
|
dtb = fdt.Fdt(out_fname)
|
|
|
|
dtb.Scan()
|
|
|
|
image_node = dtb.GetNode('/binman')
|
|
|
|
if 'multiple-images' in image_node.props:
|
|
|
|
image_node = dtb.GetNode('/binman/%s' % image.image_node)
|
|
|
|
fdt_path_prefix = image_node.path
|
2021-03-18 07:25:01 +00:00
|
|
|
output_fdt_info[etype] = [dtb, None]
|
2022-01-29 21:14:15 +00:00
|
|
|
tout.info(" FDT path prefix '%s'" % fdt_path_prefix)
|
2019-07-20 18:23:50 +00:00
|
|
|
|
|
|
|
|
2019-07-20 18:23:29 +00:00
|
|
|
def GetAllFdts():
|
2018-09-14 10:57:20 +00:00
|
|
|
"""Yield all device tree files being used by binman
|
|
|
|
|
|
|
|
Yields:
|
2022-02-28 14:16:54 +00:00
|
|
|
Device trees being used (U-Boot proper, SPL, TPL, VPL)
|
2018-09-14 10:57:20 +00:00
|
|
|
"""
|
2019-07-20 18:23:50 +00:00
|
|
|
if main_dtb:
|
|
|
|
yield main_dtb
|
2019-07-20 18:23:43 +00:00
|
|
|
for etype in output_fdt_info:
|
|
|
|
dtb = output_fdt_info[etype][0]
|
2019-07-20 18:23:33 +00:00
|
|
|
if dtb != main_dtb:
|
|
|
|
yield dtb
|
2018-09-14 10:57:20 +00:00
|
|
|
|
2019-07-20 18:23:51 +00:00
|
|
|
def GetUpdateNodes(node, for_repack=False):
|
2018-09-14 10:57:21 +00:00
|
|
|
"""Yield all the nodes that need to be updated in all device trees
|
|
|
|
|
|
|
|
The property referenced by this node is added to any device trees which
|
2023-02-19 22:02:03 +00:00
|
|
|
have the given node. Due to removable of unwanted nodes, SPL and TPL may
|
2018-09-14 10:57:21 +00:00
|
|
|
not have this node.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
node: Node object in the main device tree to look up
|
2019-07-20 18:23:51 +00:00
|
|
|
for_repack: True if we want only nodes which need 'repack' properties
|
|
|
|
added to them (e.g. 'orig-offset'), False to return all nodes. We
|
|
|
|
don't add repack properties to SPL/TPL device trees.
|
2018-09-14 10:57:21 +00:00
|
|
|
|
|
|
|
Yields:
|
|
|
|
Node objects in each device tree that is in use (U-Boot proper, which
|
|
|
|
is node, SPL and TPL)
|
|
|
|
"""
|
|
|
|
yield node
|
2021-03-18 07:25:01 +00:00
|
|
|
for entry_type, (dtb, fname) in output_fdt_info.items():
|
2018-09-14 10:57:24 +00:00
|
|
|
if dtb != node.GetFdt():
|
2021-03-18 07:25:01 +00:00
|
|
|
if for_repack and entry_type != 'u-boot-dtb':
|
2019-07-20 18:23:51 +00:00
|
|
|
continue
|
2019-07-20 18:23:50 +00:00
|
|
|
other_node = dtb.GetNode(fdt_path_prefix + node.path)
|
2018-09-14 10:57:24 +00:00
|
|
|
if other_node:
|
|
|
|
yield other_node
|
2018-09-14 10:57:21 +00:00
|
|
|
|
2019-07-20 18:23:51 +00:00
|
|
|
def AddZeroProp(node, prop, for_repack=False):
|
2018-09-14 10:57:21 +00:00
|
|
|
"""Add a new property to affected device trees with an integer value of 0.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
prop_name: Name of property
|
2019-07-20 18:23:51 +00:00
|
|
|
for_repack: True is this property is only needed for repacking
|
2018-09-14 10:57:21 +00:00
|
|
|
"""
|
2019-07-20 18:23:51 +00:00
|
|
|
for n in GetUpdateNodes(node, for_repack):
|
2018-09-14 10:57:21 +00:00
|
|
|
n.AddZeroProp(prop)
|
|
|
|
|
2018-09-14 10:57:28 +00:00
|
|
|
def AddSubnode(node, name):
|
|
|
|
"""Add a new subnode to a node in affected device trees
|
|
|
|
|
|
|
|
Args:
|
|
|
|
node: Node to add to
|
|
|
|
name: name of node to add
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
New subnode that was created in main tree
|
|
|
|
"""
|
|
|
|
first = None
|
|
|
|
for n in GetUpdateNodes(node):
|
|
|
|
subnode = n.AddSubnode(name)
|
|
|
|
if not first:
|
|
|
|
first = subnode
|
|
|
|
return first
|
|
|
|
|
|
|
|
def AddString(node, prop, value):
|
|
|
|
"""Add a new string property to affected device trees
|
|
|
|
|
|
|
|
Args:
|
|
|
|
prop_name: Name of property
|
|
|
|
value: String value (which will be \0-terminated in the DT)
|
|
|
|
"""
|
|
|
|
for n in GetUpdateNodes(node):
|
|
|
|
n.AddString(prop, value)
|
|
|
|
|
2021-01-07 04:35:18 +00:00
|
|
|
def AddInt(node, prop, value):
|
|
|
|
"""Add a new string property to affected device trees
|
|
|
|
|
|
|
|
Args:
|
|
|
|
prop_name: Name of property
|
|
|
|
val: Integer value of property
|
|
|
|
"""
|
|
|
|
for n in GetUpdateNodes(node):
|
|
|
|
n.AddInt(prop, value)
|
|
|
|
|
2019-07-20 18:23:51 +00:00
|
|
|
def SetInt(node, prop, value, for_repack=False):
|
2018-09-14 10:57:21 +00:00
|
|
|
"""Update an integer property in affected device trees with an integer value
|
|
|
|
|
|
|
|
This is not allowed to change the size of the FDT.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
prop_name: Name of property
|
2019-07-20 18:23:51 +00:00
|
|
|
for_repack: True is this property is only needed for repacking
|
2018-09-14 10:57:21 +00:00
|
|
|
"""
|
2019-07-20 18:23:51 +00:00
|
|
|
for n in GetUpdateNodes(node, for_repack):
|
2023-07-18 13:24:09 +00:00
|
|
|
tout.debug("File %s: Update node '%s' prop '%s' to %#x" %
|
|
|
|
(n.GetFdt().name, n.path, prop, value))
|
2018-09-14 10:57:21 +00:00
|
|
|
n.SetInt(prop, value)
|
2018-09-14 10:57:31 +00:00
|
|
|
|
|
|
|
def CheckAddHashProp(node):
|
|
|
|
hash_node = node.FindNode('hash')
|
|
|
|
if hash_node:
|
|
|
|
algo = hash_node.props.get('algo')
|
|
|
|
if not algo:
|
|
|
|
return "Missing 'algo' property for hash node"
|
|
|
|
if algo.value == 'sha256':
|
|
|
|
size = 32
|
|
|
|
else:
|
2022-02-08 17:59:44 +00:00
|
|
|
return "Unknown hash algorithm '%s'" % algo.value
|
2018-09-14 10:57:31 +00:00
|
|
|
for n in GetUpdateNodes(hash_node):
|
|
|
|
n.AddEmptyProp('value', size)
|
|
|
|
|
|
|
|
def CheckSetHashValue(node, get_data_func):
|
|
|
|
hash_node = node.FindNode('hash')
|
|
|
|
if hash_node:
|
|
|
|
algo = hash_node.props.get('algo').value
|
|
|
|
if algo == 'sha256':
|
|
|
|
m = hashlib.sha256()
|
|
|
|
m.update(get_data_func())
|
|
|
|
data = m.digest()
|
|
|
|
for n in GetUpdateNodes(hash_node):
|
|
|
|
n.SetData('value', data)
|
2019-07-08 20:25:36 +00:00
|
|
|
|
|
|
|
def SetAllowEntryExpansion(allow):
|
|
|
|
"""Set whether post-pack expansion of entries is allowed
|
|
|
|
|
|
|
|
Args:
|
|
|
|
allow: True to allow expansion, False to raise an exception
|
|
|
|
"""
|
|
|
|
global allow_entry_expansion
|
|
|
|
|
|
|
|
allow_entry_expansion = allow
|
|
|
|
|
|
|
|
def AllowEntryExpansion():
|
|
|
|
"""Check whether post-pack expansion of entries is allowed
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
True if expansion should be allowed, False if an exception should be
|
|
|
|
raised
|
|
|
|
"""
|
|
|
|
return allow_entry_expansion
|
2019-07-20 18:23:58 +00:00
|
|
|
|
|
|
|
def SetAllowEntryContraction(allow):
|
|
|
|
"""Set whether post-pack contraction of entries is allowed
|
|
|
|
|
|
|
|
Args:
|
|
|
|
allow: True to allow contraction, False to raise an exception
|
|
|
|
"""
|
|
|
|
global allow_entry_contraction
|
|
|
|
|
|
|
|
allow_entry_contraction = allow
|
|
|
|
|
|
|
|
def AllowEntryContraction():
|
|
|
|
"""Check whether post-pack contraction of entries is allowed
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
True if contraction should be allowed, False if an exception should be
|
|
|
|
raised
|
|
|
|
"""
|
|
|
|
return allow_entry_contraction
|
2021-07-06 16:36:37 +00:00
|
|
|
|
|
|
|
def SetThreads(threads):
|
|
|
|
"""Set the number of threads to use when building sections
|
|
|
|
|
|
|
|
Args:
|
|
|
|
threads: Number of threads to use (None for default, 0 for
|
|
|
|
single-threaded)
|
|
|
|
"""
|
|
|
|
global num_threads
|
|
|
|
|
|
|
|
num_threads = threads
|
|
|
|
|
|
|
|
def GetThreads():
|
|
|
|
"""Get the number of threads to use when building sections
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Number of threads to use (None for default, 0 for single-threaded)
|
|
|
|
"""
|
|
|
|
return num_threads
|
2021-07-06 16:36:41 +00:00
|
|
|
|
|
|
|
def GetTiming(name):
|
|
|
|
"""Get the timing info for a particular operation
|
|
|
|
|
|
|
|
The object is created if it does not already exist.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: Operation name to get
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Timing object for the current thread
|
|
|
|
"""
|
|
|
|
threaded_name = '%s:%d' % (name, threading.get_ident())
|
|
|
|
timing = timing_info.get(threaded_name)
|
|
|
|
if not timing:
|
|
|
|
timing = Timing(threaded_name)
|
|
|
|
timing_info[threaded_name] = timing
|
|
|
|
return timing
|
|
|
|
|
|
|
|
def TimingStart(name):
|
|
|
|
"""Start the timer for an operation
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: Operation name to start
|
|
|
|
"""
|
|
|
|
timing = GetTiming(name)
|
|
|
|
timing.start = time.monotonic()
|
|
|
|
|
|
|
|
def TimingAccum(name):
|
|
|
|
"""Stop and accumlate the time for an operation
|
|
|
|
|
|
|
|
This measures the time since the last TimingStart() and adds that to the
|
|
|
|
accumulated time.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: Operation name to start
|
|
|
|
"""
|
|
|
|
timing = GetTiming(name)
|
|
|
|
timing.accum += time.monotonic() - timing.start
|
|
|
|
|
|
|
|
def TimingShow():
|
|
|
|
"""Show all timing information"""
|
|
|
|
duration = defaultdict(float)
|
|
|
|
for threaded_name, timing in timing_info.items():
|
|
|
|
name = threaded_name.split(':')[0]
|
|
|
|
duration[name] += timing.accum
|
|
|
|
|
|
|
|
for name, seconds in duration.items():
|
|
|
|
print('%10s: %10.1fms' % (name, seconds * 1000))
|
2021-11-23 18:03:42 +00:00
|
|
|
|
|
|
|
def GetVersion(path=OUR_PATH):
|
|
|
|
"""Get the version string for binman
|
|
|
|
|
|
|
|
Args:
|
|
|
|
path: Path to 'version' file
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
str: String version, e.g. 'v2021.10'
|
|
|
|
"""
|
|
|
|
version_fname = os.path.join(path, 'version')
|
|
|
|
if os.path.exists(version_fname):
|
2022-01-29 21:14:04 +00:00
|
|
|
version = tools.read_file(version_fname, binary=False)
|
2021-11-23 18:03:42 +00:00
|
|
|
else:
|
|
|
|
version = '(unreleased)'
|
|
|
|
return version
|