summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-01-10 06:13:50 +0300
committerSimon Glass <sjg@chromium.org>2022-01-25 22:36:11 +0300
commit386c63cfad30901055a7d41173c2a99d268b6b0d (patch)
tree9382d73ce342712062c012ee88cf812b6d4b69e9
parent252de6b1f7189062d984b72149ea4d3123a63d8d (diff)
downloadu-boot-386c63cfad30901055a7d41173c2a99d268b6b0d.tar.xz
binman: Plumb in support for bintools
Support collecting the available bintools needed by an image, by scanning the entries in the image. Also add a command-line interface to access the basic bintool features, such as listing the bintools and fetching them if needed. Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--tools/binman/cmdline.py7
-rw-r--r--tools/binman/control.py17
-rw-r--r--tools/binman/entry.py22
-rw-r--r--tools/binman/etype/section.py4
-rw-r--r--tools/binman/ftest.py1
-rw-r--r--tools/binman/image.py14
6 files changed, 64 insertions, 1 deletions
diff --git a/tools/binman/cmdline.py b/tools/binman/cmdline.py
index 6c68595461..92cc14b6fc 100644
--- a/tools/binman/cmdline.py
+++ b/tools/binman/cmdline.py
@@ -167,4 +167,11 @@ controlled by a description in the board device tree.'''
test_parser.add_argument('tests', nargs='*',
help='Test names to run (omit for all)')
+ tool_parser = subparsers.add_parser('tool', help='Check bintools')
+ tool_parser.add_argument('-l', '--list', action='store_true',
+ help='List all known bintools')
+ tool_parser.add_argument('-f', '--fetch', action='store_true',
+ help='fetch a bintool from a known location (or: all/missing)')
+ tool_parser.add_argument('bintools', type=str, nargs='*')
+
return parser.parse_args(argv)
diff --git a/tools/binman/control.py b/tools/binman/control.py
index e0d2b3879d..5b10f19236 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -14,6 +14,7 @@ import re
import sys
from patman import tools
+from binman import bintool
from binman import cbfs_util
from binman import elf
from patman import command
@@ -487,6 +488,7 @@ def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt, use_expanded):
# without changing the device-tree size, thus ensuring that our
# entry offsets remain the same.
for image in images.values():
+ image.CollectBintools()
image.ExpandEntries()
if update_fdt:
image.AddMissingProperties(True)
@@ -606,7 +608,7 @@ def Binman(args):
from binman.image import Image
from binman import state
- if args.cmd in ['ls', 'extract', 'replace']:
+ if args.cmd in ['ls', 'extract', 'replace', 'tool']:
try:
tout.Init(args.verbosity)
tools.PrepareOutputDir(None)
@@ -621,6 +623,19 @@ def Binman(args):
ReplaceEntries(args.image, args.filename, args.indir, args.paths,
do_compress=not args.compressed,
allow_resize=not args.fix_size, write_map=args.map)
+
+ if args.cmd == 'tool':
+ tools.SetToolPaths(args.toolpath)
+ if args.list:
+ bintool.Bintool.list_all()
+ elif args.fetch:
+ if not args.bintools:
+ raise ValueError(
+ "Please specify bintools to fetch or 'all' or 'missing'")
+ bintool.Bintool.fetch_tools(bintool.FETCH_ANY,
+ args.bintools)
+ else:
+ raise ValueError("Invalid arguments to 'tool' subcommand")
except:
raise
finally:
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index e4a1f2d5d5..9cd900670e 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -10,6 +10,7 @@ import os
import pathlib
import sys
+from binman import bintool
from dtoc import fdt_util
from patman import tools
from patman.tools import ToHex, ToHexSize
@@ -74,6 +75,7 @@ class Entry(object):
allow_fake: Allow creating a dummy fake file if the blob file is not
available. This is mainly used for testing.
external: True if this entry contains an external binary blob
+ bintools: Bintools used by this entry (only populated for Image)
"""
def __init__(self, section, etype, node, name_prefix=''):
# Put this here to allow entry-docs and help to work without libfdt
@@ -105,6 +107,7 @@ class Entry(object):
self.external = False
self.allow_missing = False
self.allow_fake = False
+ self.bintools = {}
@staticmethod
def FindEntryClass(etype, expanded):
@@ -1065,3 +1068,22 @@ features to produce new behaviours.
value: Help text
"""
pass
+
+ def AddBintools(self, tools):
+ """Add the bintools used by this entry type
+
+ Args:
+ tools (dict of Bintool):
+ """
+ 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
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index fdd4cbb21a..221a64cd03 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -880,3 +880,7 @@ class Entry_section(Entry):
def CheckAltFormats(self, alt_formats):
for entry in self._entries.values():
entry.CheckAltFormats(alt_formats)
+
+ def AddBintools(self, tools):
+ for entry in self._entries.values():
+ entry.AddBintools(tools)
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index ac6aabbf9c..179326c42a 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -18,6 +18,7 @@ import sys
import tempfile
import unittest
+from binman import bintool
from binman import cbfs_util
from binman import cmdline
from binman import control
diff --git a/tools/binman/image.py b/tools/binman/image.py
index f0a7d65299..0f0c1d29e8 100644
--- a/tools/binman/image.py
+++ b/tools/binman/image.py
@@ -82,6 +82,7 @@ class Image(section.Entry_section):
self.missing_etype = missing_etype
self.use_expanded = use_expanded
self.test_section_timeout = False
+ self.bintools = {}
if not test:
self.ReadNode()
@@ -394,3 +395,16 @@ class Image(section.Entry_section):
self._CollectEntries(entries, entries_by_name, self)
return self.LookupSymbol(sym_name, optional, msg, base_addr,
entries_by_name)
+
+ def CollectBintools(self):
+ """Collect all the bintools used by this image
+
+ Returns:
+ Dict of bintools:
+ key: name of tool
+ value: Bintool object
+ """
+ bintools = {}
+ super().AddBintools(bintools)
+ self.bintools = bintools
+ return bintools