blob: e73ff78095628d4ea53602981a59aa0d33d1057a [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 Glassbf7fd502016-11-25 20:15:51 -07005# Command-line parser for binman
6#
7
Simon Glass53cd5d92019-07-08 14:25:29 -06008from argparse import ArgumentParser
Simon Glassbf7fd502016-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 Glass53cd5d92019-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',
Simon Glassbf7fd502016-11-25 20:15:51 -070032 default=False, help='Display the README file')
Simon Glass53cd5d92019-07-08 14:25:29 -060033 parser.add_argument('--toolpath', type=str, action='append',
34 help='Add a path to the directories containing tools')
Simon Glassc69d19c2021-07-06 10:36:37 -060035 parser.add_argument('-T', '--threads', type=int,
36 default=None, help='Number of threads to use (0=single-thread)')
37 parser.add_argument('--test-section-timeout', action='store_true',
38 help='Use a zero timeout for section multi-threading (for testing)')
Simon Glass53cd5d92019-07-08 14:25:29 -060039 parser.add_argument('-v', '--verbosity', default=1,
40 type=int, help='Control verbosity: 0=silent, 1=warnings, 2=notices, '
41 '3=info, 4=detail, 5=debug')
42
43 subparsers = parser.add_subparsers(dest='cmd')
Simon Glass680e3c62020-10-26 17:40:02 -060044 subparsers.required = True
Simon Glass53cd5d92019-07-08 14:25:29 -060045
46 build_parser = subparsers.add_parser('build', help='Build firmware image')
47 build_parser.add_argument('-a', '--entry-arg', type=str, action='append',
48 help='Set argument value arg=value')
49 build_parser.add_argument('-b', '--board', type=str,
50 help='Board name to build')
51 build_parser.add_argument('-d', '--dt', type=str,
52 help='Configuration file (.dtb) to use')
53 build_parser.add_argument('--fake-dtb', action='store_true',
54 help='Use fake device tree contents (for testing only)')
55 build_parser.add_argument('-i', '--image', type=str, action='append',
56 help='Image filename to build (if not specified, build all)')
57 build_parser.add_argument('-I', '--indir', action='append',
58 help='Add a path to the list of directories to use for input files')
59 build_parser.add_argument('-m', '--map', action='store_true',
Simon Glass3b0c3822018-06-01 09:38:20 -060060 default=False, help='Output a map file for each image')
Simon Glass4f9f1052020-07-09 18:39:38 -060061 build_parser.add_argument('-M', '--allow-missing', action='store_true',
62 default=False, help='Allow external blobs to be missing')
Simon Glass63aeaeb2021-03-18 20:25:05 +130063 build_parser.add_argument('-n', '--no-expanded', action='store_true',
64 help="Don't use 'expanded' versions of entries where available; "
65 "normally 'u-boot' becomes 'u-boot-expanded', for example")
Simon Glass53cd5d92019-07-08 14:25:29 -060066 build_parser.add_argument('-O', '--outdir', type=str,
Simon Glassbf7fd502016-11-25 20:15:51 -070067 action='store', help='Path to directory to use for intermediate and '
68 'output files')
Simon Glass53cd5d92019-07-08 14:25:29 -060069 build_parser.add_argument('-p', '--preserve', action='store_true',\
Simon Glassbf7fd502016-11-25 20:15:51 -070070 help='Preserve temporary output directory even if option -O is not '
71 'given')
Simon Glass53cd5d92019-07-08 14:25:29 -060072 build_parser.add_argument('-u', '--update-fdt', action='store_true',
Simon Glass3ab95982018-08-01 15:22:37 -060073 default=False, help='Update the binman node with offset/size info')
Simon Glass0427bed2021-11-03 21:09:18 -060074 build_parser.add_argument('--update-fdt-in-elf', type=str,
75 help='Update an ELF file with the output dtb: infile,outfile,begin_sym,end_sym')
Simon Glass53cd5d92019-07-08 14:25:29 -060076
77 entry_parser = subparsers.add_parser('entry-docs',
Simon Glass6bc43092021-03-18 20:25:15 +130078 help='Write out entry documentation (see entries.rst)')
Simon Glass53cd5d92019-07-08 14:25:29 -060079
Simon Glass61f564d2019-07-08 14:25:48 -060080 list_parser = subparsers.add_parser('ls', help='List files in an image')
81 list_parser.add_argument('-i', '--image', type=str, required=True,
82 help='Image filename to list')
83 list_parser.add_argument('paths', type=str, nargs='*',
84 help='Paths within file to list (wildcard)')
85
Simon Glass71ce0ba2019-07-08 14:25:52 -060086 extract_parser = subparsers.add_parser('extract',
87 help='Extract files from an image')
88 extract_parser.add_argument('-i', '--image', type=str, required=True,
89 help='Image filename to extract')
90 extract_parser.add_argument('-f', '--filename', type=str,
91 help='Output filename to write to')
92 extract_parser.add_argument('-O', '--outdir', type=str, default='',
93 help='Path to directory to use for output files')
94 extract_parser.add_argument('paths', type=str, nargs='*',
95 help='Paths within file to extract (wildcard)')
96 extract_parser.add_argument('-U', '--uncompressed', action='store_true',
97 help='Output raw uncompressed data for compressed entries')
98
Simon Glassa6cb9952019-07-20 12:24:15 -060099 replace_parser = subparsers.add_parser('replace',
100 help='Replace entries in an image')
101 replace_parser.add_argument('-C', '--compressed', action='store_true',
102 help='Input data is already compressed if needed for the entry')
103 replace_parser.add_argument('-i', '--image', type=str, required=True,
Jan Kiszka89cc0522021-11-11 08:13:30 +0100104 help='Image filename to update')
Simon Glassa6cb9952019-07-20 12:24:15 -0600105 replace_parser.add_argument('-f', '--filename', type=str,
106 help='Input filename to read from')
107 replace_parser.add_argument('-F', '--fix-size', action='store_true',
108 help="Don't allow entries to be resized")
109 replace_parser.add_argument('-I', '--indir', type=str, default='',
110 help='Path to directory to use for input files')
111 replace_parser.add_argument('-m', '--map', action='store_true',
112 default=False, help='Output a map file for the updated image')
113 replace_parser.add_argument('paths', type=str, nargs='*',
Jan Kiszka89cc0522021-11-11 08:13:30 +0100114 help='Paths within file to replace (wildcard)')
Simon Glassa6cb9952019-07-20 12:24:15 -0600115
Simon Glass53cd5d92019-07-08 14:25:29 -0600116 test_parser = subparsers.add_parser('test', help='Run tests')
117 test_parser.add_argument('-P', '--processes', type=int,
118 help='set number of processes to use for running tests')
119 test_parser.add_argument('-T', '--test-coverage', action='store_true',
120 default=False, help='run tests and check for 100%% coverage')
121 test_parser.add_argument('-X', '--test-preserve-dirs', action='store_true',
Simon Glassd5164a72019-07-08 13:18:49 -0600122 help='Preserve and display test-created input directories; also '
123 'preserve the output directory if a single test is run (pass test '
124 'name at the end of the command line')
Simon Glass53cd5d92019-07-08 14:25:29 -0600125 test_parser.add_argument('tests', nargs='*',
126 help='Test names to run (omit for all)')
Simon Glassbf7fd502016-11-25 20:15:51 -0700127
128 return parser.parse_args(argv)