blob: 95f9ba27fbd80257fa614ee9ca20bf13bbeac59a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glass2574ef62016-11-25 20:15:51 -07002# Copyright (c) 2016 Google, Inc
3# Written by Simon Glass <sjg@chromium.org>
4#
Simon Glass2574ef62016-11-25 20:15:51 -07005# Command-line parser for binman
6#
7
Simon Glassf46732a2019-07-08 14:25:29 -06008from argparse import ArgumentParser
Simon Glass2574ef62016-11-25 20:15:51 -07009
10def ParseArgs(argv):
11 """Parse the binman command-line arguments
12
13 Args:
14 argv: List of string arguments
15 Returns:
16 Tuple (options, args) with the command-line options and arugments.
17 options provides access to the options (e.g. option.debug)
18 args is a list of string arguments
19 """
Simon Glassf46732a2019-07-08 14:25:29 -060020 if '-H' in argv:
21 argv.append('build')
22
23 epilog = '''Binman creates and manipulate images for a board from a set of binaries. Binman is
24controlled by a description in the board device tree.'''
25
26 parser = ArgumentParser(epilog=epilog)
27 parser.add_argument('-B', '--build-dir', type=str, default='b',
28 help='Directory containing the build output')
29 parser.add_argument('-D', '--debug', action='store_true',
30 help='Enabling debugging (provides a full traceback on error)')
31 parser.add_argument('-H', '--full-help', action='store_true',
32 default=False, help='Display the README file')
33 parser.add_argument('--toolpath', type=str, action='append',
34 help='Add a path to the directories containing tools')
35 parser.add_argument('-v', '--verbosity', default=1,
36 type=int, help='Control verbosity: 0=silent, 1=warnings, 2=notices, '
37 '3=info, 4=detail, 5=debug')
38
39 subparsers = parser.add_subparsers(dest='cmd')
Simon Glass76681942020-10-26 17:40:02 -060040 subparsers.required = True
Simon Glassf46732a2019-07-08 14:25:29 -060041
42 build_parser = subparsers.add_parser('build', help='Build firmware image')
43 build_parser.add_argument('-a', '--entry-arg', type=str, action='append',
Simon Glass91710b32018-07-17 13:25:32 -060044 help='Set argument value arg=value')
Simon Glassf46732a2019-07-08 14:25:29 -060045 build_parser.add_argument('-b', '--board', type=str,
Simon Glass2574ef62016-11-25 20:15:51 -070046 help='Board name to build')
Simon Glassf46732a2019-07-08 14:25:29 -060047 build_parser.add_argument('-d', '--dt', type=str,
Simon Glass2574ef62016-11-25 20:15:51 -070048 help='Configuration file (.dtb) to use')
Simon Glassf46732a2019-07-08 14:25:29 -060049 build_parser.add_argument('--fake-dtb', action='store_true',
Simon Glass31402012018-09-14 04:57:23 -060050 help='Use fake device tree contents (for testing only)')
Simon Glassf46732a2019-07-08 14:25:29 -060051 build_parser.add_argument('-i', '--image', type=str, action='append',
Simon Glass3b376c32018-09-14 04:57:12 -060052 help='Image filename to build (if not specified, build all)')
Simon Glassf46732a2019-07-08 14:25:29 -060053 build_parser.add_argument('-I', '--indir', action='append',
Simon Glass720d5672019-07-08 13:18:31 -060054 help='Add a path to the list of directories to use for input files')
Simon Glassf46732a2019-07-08 14:25:29 -060055 build_parser.add_argument('-m', '--map', action='store_true',
Simon Glass30732662018-06-01 09:38:20 -060056 default=False, help='Output a map file for each image')
Simon Glass5d94cc62020-07-09 18:39:38 -060057 build_parser.add_argument('-M', '--allow-missing', action='store_true',
58 default=False, help='Allow external blobs to be missing')
Simon Glassed930672021-03-18 20:25:05 +130059 build_parser.add_argument('-n', '--no-expanded', action='store_true',
60 help="Don't use 'expanded' versions of entries where available; "
61 "normally 'u-boot' becomes 'u-boot-expanded', for example")
Simon Glassf46732a2019-07-08 14:25:29 -060062 build_parser.add_argument('-O', '--outdir', type=str,
Simon Glass2574ef62016-11-25 20:15:51 -070063 action='store', help='Path to directory to use for intermediate and '
64 'output files')
Simon Glassf46732a2019-07-08 14:25:29 -060065 build_parser.add_argument('-p', '--preserve', action='store_true',\
Simon Glass2574ef62016-11-25 20:15:51 -070066 help='Preserve temporary output directory even if option -O is not '
67 'given')
Simon Glassf46732a2019-07-08 14:25:29 -060068 build_parser.add_argument('-u', '--update-fdt', action='store_true',
Simon Glasse8561af2018-08-01 15:22:37 -060069 default=False, help='Update the binman node with offset/size info')
Simon Glassf46732a2019-07-08 14:25:29 -060070
71 entry_parser = subparsers.add_parser('entry-docs',
Simon Glass0ac96b62021-03-18 20:25:15 +130072 help='Write out entry documentation (see entries.rst)')
Simon Glassf46732a2019-07-08 14:25:29 -060073
Simon Glassb2fd11d2019-07-08 14:25:48 -060074 list_parser = subparsers.add_parser('ls', help='List files in an image')
75 list_parser.add_argument('-i', '--image', type=str, required=True,
76 help='Image filename to list')
77 list_parser.add_argument('paths', type=str, nargs='*',
78 help='Paths within file to list (wildcard)')
79
Simon Glass980a2842019-07-08 14:25:52 -060080 extract_parser = subparsers.add_parser('extract',
81 help='Extract files from an image')
82 extract_parser.add_argument('-i', '--image', type=str, required=True,
83 help='Image filename to extract')
84 extract_parser.add_argument('-f', '--filename', type=str,
85 help='Output filename to write to')
86 extract_parser.add_argument('-O', '--outdir', type=str, default='',
87 help='Path to directory to use for output files')
88 extract_parser.add_argument('paths', type=str, nargs='*',
89 help='Paths within file to extract (wildcard)')
90 extract_parser.add_argument('-U', '--uncompressed', action='store_true',
91 help='Output raw uncompressed data for compressed entries')
92
Simon Glass30033c22019-07-20 12:24:15 -060093 replace_parser = subparsers.add_parser('replace',
94 help='Replace entries in an image')
95 replace_parser.add_argument('-C', '--compressed', action='store_true',
96 help='Input data is already compressed if needed for the entry')
97 replace_parser.add_argument('-i', '--image', type=str, required=True,
98 help='Image filename to extract')
99 replace_parser.add_argument('-f', '--filename', type=str,
100 help='Input filename to read from')
101 replace_parser.add_argument('-F', '--fix-size', action='store_true',
102 help="Don't allow entries to be resized")
103 replace_parser.add_argument('-I', '--indir', type=str, default='',
104 help='Path to directory to use for input files')
105 replace_parser.add_argument('-m', '--map', action='store_true',
106 default=False, help='Output a map file for the updated image')
107 replace_parser.add_argument('paths', type=str, nargs='*',
108 help='Paths within file to extract (wildcard)')
109
Simon Glassf46732a2019-07-08 14:25:29 -0600110 test_parser = subparsers.add_parser('test', help='Run tests')
111 test_parser.add_argument('-P', '--processes', type=int,
112 help='set number of processes to use for running tests')
113 test_parser.add_argument('-T', '--test-coverage', action='store_true',
114 default=False, help='run tests and check for 100%% coverage')
115 test_parser.add_argument('-X', '--test-preserve-dirs', action='store_true',
Simon Glass1c420c92019-07-08 13:18:49 -0600116 help='Preserve and display test-created input directories; also '
117 'preserve the output directory if a single test is run (pass test '
118 'name at the end of the command line')
Simon Glassf46732a2019-07-08 14:25:29 -0600119 test_parser.add_argument('tests', nargs='*',
120 help='Test names to run (omit for all)')
Simon Glass2574ef62016-11-25 20:15:51 -0700121
122 return parser.parse_args(argv)