blob: 2229316f10e48d46e85e5be3ccab223fc282eaca [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glassbf7fd502016-11-25 20:15:51 -07002# Copyright (c) 2016 Google, Inc
3# Written by Simon Glass <sjg@chromium.org>
4#
Simon Glass650e5de2021-11-23 11:03:41 -07005
6"""Command-line parser for binman"""
Simon Glassbf7fd502016-11-25 20:15:51 -07007
Simon Glassc475dec2021-11-23 11:03:42 -07008import argparse
Simon Glass53cd5d92019-07-08 14:25:29 -06009from argparse import ArgumentParser
Simon Glassc475dec2021-11-23 11:03:42 -070010import state
Simon Glassbf7fd502016-11-25 20:15:51 -070011
Simon Glass650e5de2021-11-23 11:03:41 -070012def make_extract_parser(subparsers):
13 """make_extract_parser: Make a subparser for the 'extract' command
14
15 Args:
16 subparsers (ArgumentParser): parser to add this one to
17 """
18 extract_parser = subparsers.add_parser('extract',
19 help='Extract files from an image')
20 extract_parser.add_argument('-i', '--image', type=str, required=True,
21 help='Image filename to extract')
22 extract_parser.add_argument('-f', '--filename', type=str,
23 help='Output filename to write to')
24 extract_parser.add_argument('-O', '--outdir', type=str, default='',
25 help='Path to directory to use for output files')
26 extract_parser.add_argument('paths', type=str, nargs='*',
27 help='Paths within file to extract (wildcard)')
28 extract_parser.add_argument('-U', '--uncompressed', action='store_true',
29 help='Output raw uncompressed data for compressed entries')
30
Simon Glassc475dec2021-11-23 11:03:42 -070031
32#pylint: disable=R0903
33class BinmanVersion(argparse.Action):
34 """Handles the -V option to binman
35
36 This reads the version information from a file called 'version' in the same
37 directory as this file.
38
39 If not present it assumes this is running from the U-Boot tree and collects
40 the version from the Makefile.
41
42 The format of the version information is three VAR = VALUE lines, for
43 example:
44
45 VERSION = 2022
46 PATCHLEVEL = 01
47 EXTRAVERSION = -rc2
48 """
49 def __init__(self, nargs=0, **kwargs):
50 super().__init__(nargs=nargs, **kwargs)
51
52 def __call__(self, parser, namespace, values, option_string=None):
53 parser._print_message(f'Binman {state.GetVersion()}\n')
54 parser.exit()
55
56
Simon Glassbf7fd502016-11-25 20:15:51 -070057def ParseArgs(argv):
58 """Parse the binman command-line arguments
59
60 Args:
Simon Glass650e5de2021-11-23 11:03:41 -070061 argv (list of str): List of string arguments
62
Simon Glassbf7fd502016-11-25 20:15:51 -070063 Returns:
Simon Glass650e5de2021-11-23 11:03:41 -070064 tuple: (options, args) with the command-line options and arugments.
Simon Glassbf7fd502016-11-25 20:15:51 -070065 options provides access to the options (e.g. option.debug)
66 args is a list of string arguments
67 """
Simon Glass53cd5d92019-07-08 14:25:29 -060068 if '-H' in argv:
69 argv.append('build')
70
71 epilog = '''Binman creates and manipulate images for a board from a set of binaries. Binman is
72controlled by a description in the board device tree.'''
73
74 parser = ArgumentParser(epilog=epilog)
75 parser.add_argument('-B', '--build-dir', type=str, default='b',
76 help='Directory containing the build output')
77 parser.add_argument('-D', '--debug', action='store_true',
78 help='Enabling debugging (provides a full traceback on error)')
79 parser.add_argument('-H', '--full-help', action='store_true',
Simon Glassbf7fd502016-11-25 20:15:51 -070080 default=False, help='Display the README file')
Simon Glass53cd5d92019-07-08 14:25:29 -060081 parser.add_argument('--toolpath', type=str, action='append',
82 help='Add a path to the directories containing tools')
Simon Glassc69d19c2021-07-06 10:36:37 -060083 parser.add_argument('-T', '--threads', type=int,
84 default=None, help='Number of threads to use (0=single-thread)')
85 parser.add_argument('--test-section-timeout', action='store_true',
86 help='Use a zero timeout for section multi-threading (for testing)')
Simon Glass53cd5d92019-07-08 14:25:29 -060087 parser.add_argument('-v', '--verbosity', default=1,
88 type=int, help='Control verbosity: 0=silent, 1=warnings, 2=notices, '
89 '3=info, 4=detail, 5=debug')
Simon Glassc475dec2021-11-23 11:03:42 -070090 parser.add_argument('-V', '--version', nargs=0, action=BinmanVersion)
Simon Glass53cd5d92019-07-08 14:25:29 -060091
92 subparsers = parser.add_subparsers(dest='cmd')
Simon Glass680e3c62020-10-26 17:40:02 -060093 subparsers.required = True
Simon Glass53cd5d92019-07-08 14:25:29 -060094
95 build_parser = subparsers.add_parser('build', help='Build firmware image')
96 build_parser.add_argument('-a', '--entry-arg', type=str, action='append',
97 help='Set argument value arg=value')
98 build_parser.add_argument('-b', '--board', type=str,
99 help='Board name to build')
100 build_parser.add_argument('-d', '--dt', type=str,
101 help='Configuration file (.dtb) to use')
102 build_parser.add_argument('--fake-dtb', action='store_true',
103 help='Use fake device tree contents (for testing only)')
104 build_parser.add_argument('-i', '--image', type=str, action='append',
105 help='Image filename to build (if not specified, build all)')
106 build_parser.add_argument('-I', '--indir', action='append',
107 help='Add a path to the list of directories to use for input files')
108 build_parser.add_argument('-m', '--map', action='store_true',
Simon Glass3b0c3822018-06-01 09:38:20 -0600109 default=False, help='Output a map file for each image')
Simon Glass4f9f1052020-07-09 18:39:38 -0600110 build_parser.add_argument('-M', '--allow-missing', action='store_true',
111 default=False, help='Allow external blobs to be missing')
Simon Glass63aeaeb2021-03-18 20:25:05 +1300112 build_parser.add_argument('-n', '--no-expanded', action='store_true',
113 help="Don't use 'expanded' versions of entries where available; "
114 "normally 'u-boot' becomes 'u-boot-expanded', for example")
Simon Glass53cd5d92019-07-08 14:25:29 -0600115 build_parser.add_argument('-O', '--outdir', type=str,
Simon Glassbf7fd502016-11-25 20:15:51 -0700116 action='store', help='Path to directory to use for intermediate and '
117 'output files')
Simon Glass53cd5d92019-07-08 14:25:29 -0600118 build_parser.add_argument('-p', '--preserve', action='store_true',\
Simon Glassbf7fd502016-11-25 20:15:51 -0700119 help='Preserve temporary output directory even if option -O is not '
120 'given')
Simon Glass53cd5d92019-07-08 14:25:29 -0600121 build_parser.add_argument('-u', '--update-fdt', action='store_true',
Simon Glass3ab95982018-08-01 15:22:37 -0600122 default=False, help='Update the binman node with offset/size info')
Simon Glass0427bed2021-11-03 21:09:18 -0600123 build_parser.add_argument('--update-fdt-in-elf', type=str,
124 help='Update an ELF file with the output dtb: infile,outfile,begin_sym,end_sym')
Simon Glass53cd5d92019-07-08 14:25:29 -0600125
Simon Glass650e5de2021-11-23 11:03:41 -0700126 subparsers.add_parser(
127 'entry-docs', help='Write out entry documentation (see entries.rst)')
Simon Glass53cd5d92019-07-08 14:25:29 -0600128
Simon Glass61f564d2019-07-08 14:25:48 -0600129 list_parser = subparsers.add_parser('ls', help='List files in an image')
130 list_parser.add_argument('-i', '--image', type=str, required=True,
131 help='Image filename to list')
132 list_parser.add_argument('paths', type=str, nargs='*',
133 help='Paths within file to list (wildcard)')
134
Simon Glass650e5de2021-11-23 11:03:41 -0700135 make_extract_parser(subparsers)
Simon Glass71ce0ba2019-07-08 14:25:52 -0600136
Simon Glassa6cb9952019-07-20 12:24:15 -0600137 replace_parser = subparsers.add_parser('replace',
138 help='Replace entries in an image')
139 replace_parser.add_argument('-C', '--compressed', action='store_true',
140 help='Input data is already compressed if needed for the entry')
141 replace_parser.add_argument('-i', '--image', type=str, required=True,
Jan Kiszka89cc0522021-11-11 08:13:30 +0100142 help='Image filename to update')
Simon Glassa6cb9952019-07-20 12:24:15 -0600143 replace_parser.add_argument('-f', '--filename', type=str,
144 help='Input filename to read from')
145 replace_parser.add_argument('-F', '--fix-size', action='store_true',
146 help="Don't allow entries to be resized")
147 replace_parser.add_argument('-I', '--indir', type=str, default='',
148 help='Path to directory to use for input files')
149 replace_parser.add_argument('-m', '--map', action='store_true',
150 default=False, help='Output a map file for the updated image')
151 replace_parser.add_argument('paths', type=str, nargs='*',
Jan Kiszka89cc0522021-11-11 08:13:30 +0100152 help='Paths within file to replace (wildcard)')
Simon Glassa6cb9952019-07-20 12:24:15 -0600153
Simon Glass53cd5d92019-07-08 14:25:29 -0600154 test_parser = subparsers.add_parser('test', help='Run tests')
155 test_parser.add_argument('-P', '--processes', type=int,
156 help='set number of processes to use for running tests')
157 test_parser.add_argument('-T', '--test-coverage', action='store_true',
158 default=False, help='run tests and check for 100%% coverage')
159 test_parser.add_argument('-X', '--test-preserve-dirs', action='store_true',
Simon Glassd5164a72019-07-08 13:18:49 -0600160 help='Preserve and display test-created input directories; also '
161 'preserve the output directory if a single test is run (pass test '
162 'name at the end of the command line')
Simon Glass53cd5d92019-07-08 14:25:29 -0600163 test_parser.add_argument('tests', nargs='*',
164 help='Test names to run (omit for all)')
Simon Glassbf7fd502016-11-25 20:15:51 -0700165
166 return parser.parse_args(argv)