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
|
|
|
|
# Written by Simon Glass <sjg@chromium.org>
|
|
|
|
#
|
|
|
|
|
2021-11-23 18:03:41 +00:00
|
|
|
"""Command-line parser for binman"""
|
2016-11-26 03:15:51 +00:00
|
|
|
|
2021-11-23 18:03:42 +00:00
|
|
|
import argparse
|
2019-07-08 20:25:29 +00:00
|
|
|
from argparse import ArgumentParser
|
2023-02-22 19:14:49 +00:00
|
|
|
import os
|
2022-02-11 20:23:21 +00:00
|
|
|
from binman import state
|
2023-02-24 01:18:19 +00:00
|
|
|
import os
|
|
|
|
import pathlib
|
|
|
|
|
|
|
|
BINMAN_DIR = pathlib.Path(__file__).parent
|
|
|
|
HAS_TESTS = (BINMAN_DIR / "ftest.py").exists()
|
2016-11-26 03:15:51 +00:00
|
|
|
|
2021-11-23 18:03:41 +00:00
|
|
|
def make_extract_parser(subparsers):
|
|
|
|
"""make_extract_parser: Make a subparser for the 'extract' command
|
|
|
|
|
|
|
|
Args:
|
|
|
|
subparsers (ArgumentParser): parser to add this one to
|
|
|
|
"""
|
|
|
|
extract_parser = subparsers.add_parser('extract',
|
|
|
|
help='Extract files from an image')
|
2021-11-24 04:09:50 +00:00
|
|
|
extract_parser.add_argument('-F', '--format', type=str,
|
|
|
|
help='Select an alternative format for extracted data')
|
2021-11-23 18:03:41 +00:00
|
|
|
extract_parser.add_argument('-i', '--image', type=str, required=True,
|
|
|
|
help='Image filename to extract')
|
|
|
|
extract_parser.add_argument('-f', '--filename', type=str,
|
|
|
|
help='Output filename to write to')
|
|
|
|
extract_parser.add_argument('-O', '--outdir', type=str, default='',
|
|
|
|
help='Path to directory to use for output files')
|
|
|
|
extract_parser.add_argument('paths', type=str, nargs='*',
|
|
|
|
help='Paths within file to extract (wildcard)')
|
|
|
|
extract_parser.add_argument('-U', '--uncompressed', action='store_true',
|
|
|
|
help='Output raw uncompressed data for compressed entries')
|
|
|
|
|
2021-11-23 18:03:42 +00:00
|
|
|
|
|
|
|
#pylint: disable=R0903
|
|
|
|
class BinmanVersion(argparse.Action):
|
|
|
|
"""Handles the -V option to binman
|
|
|
|
|
|
|
|
This reads the version information from a file called 'version' in the same
|
|
|
|
directory as this file.
|
|
|
|
|
|
|
|
If not present it assumes this is running from the U-Boot tree and collects
|
|
|
|
the version from the Makefile.
|
|
|
|
|
|
|
|
The format of the version information is three VAR = VALUE lines, for
|
|
|
|
example:
|
|
|
|
|
|
|
|
VERSION = 2022
|
|
|
|
PATCHLEVEL = 01
|
|
|
|
EXTRAVERSION = -rc2
|
|
|
|
"""
|
|
|
|
def __init__(self, nargs=0, **kwargs):
|
|
|
|
super().__init__(nargs=nargs, **kwargs)
|
|
|
|
|
|
|
|
def __call__(self, parser, namespace, values, option_string=None):
|
|
|
|
parser._print_message(f'Binman {state.GetVersion()}\n')
|
|
|
|
parser.exit()
|
|
|
|
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
def ParseArgs(argv):
|
|
|
|
"""Parse the binman command-line arguments
|
|
|
|
|
|
|
|
Args:
|
2021-11-23 18:03:41 +00:00
|
|
|
argv (list of str): List of string arguments
|
|
|
|
|
2016-11-26 03:15:51 +00:00
|
|
|
Returns:
|
2021-11-23 18:03:41 +00:00
|
|
|
tuple: (options, args) with the command-line options and arugments.
|
2016-11-26 03:15:51 +00:00
|
|
|
options provides access to the options (e.g. option.debug)
|
|
|
|
args is a list of string arguments
|
|
|
|
"""
|
2023-03-03 00:02:42 +00:00
|
|
|
def _AddPreserve(pars):
|
|
|
|
pars.add_argument('-O', '--outdir', type=str,
|
|
|
|
action='store', help='Path to directory to use for intermediate '
|
|
|
|
'and output files')
|
|
|
|
pars.add_argument('-p', '--preserve', action='store_true',\
|
|
|
|
help='Preserve temporary output directory even if option -O is not '
|
|
|
|
'given')
|
|
|
|
|
2019-07-08 20:25:29 +00:00
|
|
|
if '-H' in argv:
|
|
|
|
argv.append('build')
|
|
|
|
|
|
|
|
epilog = '''Binman creates and manipulate images for a board from a set of binaries. Binman is
|
|
|
|
controlled by a description in the board device tree.'''
|
|
|
|
|
|
|
|
parser = ArgumentParser(epilog=epilog)
|
|
|
|
parser.add_argument('-B', '--build-dir', type=str, default='b',
|
|
|
|
help='Directory containing the build output')
|
|
|
|
parser.add_argument('-D', '--debug', action='store_true',
|
|
|
|
help='Enabling debugging (provides a full traceback on error)')
|
|
|
|
parser.add_argument('-H', '--full-help', action='store_true',
|
|
|
|
default=False, help='Display the README file')
|
2023-02-22 19:14:49 +00:00
|
|
|
parser.add_argument('--tooldir', type=str,
|
2023-04-19 21:21:14 +00:00
|
|
|
default=os.path.join(os.path.expanduser('~/.binman-tools')),
|
2023-02-22 19:14:49 +00:00
|
|
|
help='Set the directory to store tools')
|
2019-07-08 20:25:29 +00:00
|
|
|
parser.add_argument('--toolpath', type=str, action='append',
|
2023-02-22 19:14:49 +00:00
|
|
|
help='Add a path to the list of directories containing tools')
|
2021-07-06 16:36:37 +00:00
|
|
|
parser.add_argument('-T', '--threads', type=int,
|
|
|
|
default=None, help='Number of threads to use (0=single-thread)')
|
|
|
|
parser.add_argument('--test-section-timeout', action='store_true',
|
|
|
|
help='Use a zero timeout for section multi-threading (for testing)')
|
2019-07-08 20:25:29 +00:00
|
|
|
parser.add_argument('-v', '--verbosity', default=1,
|
|
|
|
type=int, help='Control verbosity: 0=silent, 1=warnings, 2=notices, '
|
|
|
|
'3=info, 4=detail, 5=debug')
|
2021-11-23 18:03:42 +00:00
|
|
|
parser.add_argument('-V', '--version', nargs=0, action=BinmanVersion)
|
2019-07-08 20:25:29 +00:00
|
|
|
|
|
|
|
subparsers = parser.add_subparsers(dest='cmd')
|
2020-10-26 23:40:02 +00:00
|
|
|
subparsers.required = True
|
2019-07-08 20:25:29 +00:00
|
|
|
|
|
|
|
build_parser = subparsers.add_parser('build', help='Build firmware image')
|
|
|
|
build_parser.add_argument('-a', '--entry-arg', type=str, action='append',
|
2018-07-17 19:25:32 +00:00
|
|
|
help='Set argument value arg=value')
|
2019-07-08 20:25:29 +00:00
|
|
|
build_parser.add_argument('-b', '--board', type=str,
|
2016-11-26 03:15:51 +00:00
|
|
|
help='Board name to build')
|
2019-07-08 20:25:29 +00:00
|
|
|
build_parser.add_argument('-d', '--dt', type=str,
|
2016-11-26 03:15:51 +00:00
|
|
|
help='Configuration file (.dtb) to use')
|
2019-07-08 20:25:29 +00:00
|
|
|
build_parser.add_argument('--fake-dtb', action='store_true',
|
2018-09-14 10:57:23 +00:00
|
|
|
help='Use fake device tree contents (for testing only)')
|
2022-01-06 10:49:41 +00:00
|
|
|
build_parser.add_argument('--fake-ext-blobs', action='store_true',
|
|
|
|
help='Create fake ext blobs with dummy content (for testing only)')
|
2022-01-10 03:14:09 +00:00
|
|
|
build_parser.add_argument('--force-missing-bintools', type=str,
|
|
|
|
help='Comma-separated list of bintools to consider missing (for testing)')
|
2019-07-08 20:25:29 +00:00
|
|
|
build_parser.add_argument('-i', '--image', type=str, action='append',
|
2018-09-14 10:57:12 +00:00
|
|
|
help='Image filename to build (if not specified, build all)')
|
2019-07-08 20:25:29 +00:00
|
|
|
build_parser.add_argument('-I', '--indir', action='append',
|
2019-07-08 19:18:31 +00:00
|
|
|
help='Add a path to the list of directories to use for input files')
|
2019-07-08 20:25:29 +00:00
|
|
|
build_parser.add_argument('-m', '--map', action='store_true',
|
2018-06-01 15:38:20 +00:00
|
|
|
default=False, help='Output a map file for each image')
|
2020-07-10 00:39:38 +00:00
|
|
|
build_parser.add_argument('-M', '--allow-missing', action='store_true',
|
2022-11-10 02:14:42 +00:00
|
|
|
default=False, help='Allow external blobs and bintools to be missing')
|
2021-03-18 07:25:05 +00:00
|
|
|
build_parser.add_argument('-n', '--no-expanded', action='store_true',
|
|
|
|
help="Don't use 'expanded' versions of entries where available; "
|
|
|
|
"normally 'u-boot' becomes 'u-boot-expanded', for example")
|
2023-03-03 00:02:42 +00:00
|
|
|
_AddPreserve(build_parser)
|
2019-07-08 20:25:29 +00:00
|
|
|
build_parser.add_argument('-u', '--update-fdt', action='store_true',
|
2018-08-01 21:22:37 +00:00
|
|
|
default=False, help='Update the binman node with offset/size info')
|
2021-11-04 03:09:18 +00:00
|
|
|
build_parser.add_argument('--update-fdt-in-elf', type=str,
|
|
|
|
help='Update an ELF file with the output dtb: infile,outfile,begin_sym,end_sym')
|
2022-11-10 02:14:42 +00:00
|
|
|
build_parser.add_argument(
|
|
|
|
'-W', '--ignore-missing', action='store_true', default=False,
|
|
|
|
help='Return success even if there are missing blobs/bintools (requires -M)')
|
2019-07-08 20:25:29 +00:00
|
|
|
|
2022-01-10 03:14:11 +00:00
|
|
|
subparsers.add_parser(
|
|
|
|
'bintool-docs', help='Write out bintool documentation (see bintool.rst)')
|
|
|
|
|
2021-11-23 18:03:41 +00:00
|
|
|
subparsers.add_parser(
|
|
|
|
'entry-docs', help='Write out entry documentation (see entries.rst)')
|
2019-07-08 20:25:29 +00:00
|
|
|
|
2019-07-08 20:25:48 +00:00
|
|
|
list_parser = subparsers.add_parser('ls', help='List files in an image')
|
|
|
|
list_parser.add_argument('-i', '--image', type=str, required=True,
|
|
|
|
help='Image filename to list')
|
|
|
|
list_parser.add_argument('paths', type=str, nargs='*',
|
|
|
|
help='Paths within file to list (wildcard)')
|
|
|
|
|
2021-11-23 18:03:41 +00:00
|
|
|
make_extract_parser(subparsers)
|
2019-07-08 20:25:52 +00:00
|
|
|
|
2019-07-20 18:24:15 +00:00
|
|
|
replace_parser = subparsers.add_parser('replace',
|
|
|
|
help='Replace entries in an image')
|
|
|
|
replace_parser.add_argument('-C', '--compressed', action='store_true',
|
|
|
|
help='Input data is already compressed if needed for the entry')
|
|
|
|
replace_parser.add_argument('-i', '--image', type=str, required=True,
|
2021-11-11 07:13:30 +00:00
|
|
|
help='Image filename to update')
|
2019-07-20 18:24:15 +00:00
|
|
|
replace_parser.add_argument('-f', '--filename', type=str,
|
|
|
|
help='Input filename to read from')
|
|
|
|
replace_parser.add_argument('-F', '--fix-size', action='store_true',
|
|
|
|
help="Don't allow entries to be resized")
|
|
|
|
replace_parser.add_argument('-I', '--indir', type=str, default='',
|
|
|
|
help='Path to directory to use for input files')
|
|
|
|
replace_parser.add_argument('-m', '--map', action='store_true',
|
|
|
|
default=False, help='Output a map file for the updated image')
|
2023-03-03 00:02:42 +00:00
|
|
|
_AddPreserve(replace_parser)
|
2019-07-20 18:24:15 +00:00
|
|
|
replace_parser.add_argument('paths', type=str, nargs='*',
|
2021-11-11 07:13:30 +00:00
|
|
|
help='Paths within file to replace (wildcard)')
|
2019-07-20 18:24:15 +00:00
|
|
|
|
2023-03-08 01:13:39 +00:00
|
|
|
sign_parser = subparsers.add_parser('sign',
|
|
|
|
help='Sign entries in image')
|
|
|
|
sign_parser.add_argument('-a', '--algo', type=str, required=True,
|
|
|
|
help='Hash algorithm e.g. sha256,rsa4096')
|
|
|
|
sign_parser.add_argument('-f', '--file', type=str, required=False,
|
|
|
|
help='Input filename to sign')
|
|
|
|
sign_parser.add_argument('-i', '--image', type=str, required=True,
|
|
|
|
help='Image filename to update')
|
|
|
|
sign_parser.add_argument('-k', '--key', type=str, required=True,
|
|
|
|
help='Private key file for signing')
|
|
|
|
sign_parser.add_argument('paths', type=str, nargs='*',
|
|
|
|
help='Paths within file to sign (wildcard)')
|
|
|
|
|
2023-02-24 01:18:19 +00:00
|
|
|
if HAS_TESTS:
|
|
|
|
test_parser = subparsers.add_parser('test', help='Run tests')
|
|
|
|
test_parser.add_argument('-P', '--processes', type=int,
|
|
|
|
help='set number of processes to use for running tests')
|
|
|
|
test_parser.add_argument('-T', '--test-coverage', action='store_true',
|
|
|
|
default=False, help='run tests and check for 100%% coverage')
|
|
|
|
test_parser.add_argument(
|
|
|
|
'-X', '--test-preserve-dirs', action='store_true',
|
|
|
|
help='Preserve and display test-created input directories; also '
|
|
|
|
'preserve the output directory if a single test is run (pass '
|
|
|
|
'test name at the end of the command line')
|
|
|
|
test_parser.add_argument('tests', nargs='*',
|
|
|
|
help='Test names to run (omit for all)')
|
2016-11-26 03:15:51 +00:00
|
|
|
|
2022-01-10 03:13:50 +00:00
|
|
|
tool_parser = subparsers.add_parser('tool', help='Check bintools')
|
|
|
|
tool_parser.add_argument('-l', '--list', action='store_true',
|
|
|
|
help='List all known bintools')
|
2023-02-24 01:18:19 +00:00
|
|
|
tool_parser.add_argument(
|
|
|
|
'-f', '--fetch', action='store_true',
|
|
|
|
help='fetch a bintool from a known location (or: all/missing)')
|
2022-01-10 03:13:50 +00:00
|
|
|
tool_parser.add_argument('bintools', type=str, nargs='*')
|
|
|
|
|
2016-11-26 03:15:51 +00:00
|
|
|
return parser.parse_args(argv)
|