Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 2 | # Copyright (c) 2016 Google, Inc |
| 3 | # Written by Simon Glass <sjg@chromium.org> |
| 4 | # |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 5 | |
Simon Glass | 33046a3 | 2021-11-23 11:03:41 -0700 | [diff] [blame] | 6 | """Command-line parser for binman""" |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 7 | |
Simon Glass | 88e04da | 2021-11-23 11:03:42 -0700 | [diff] [blame] | 8 | import argparse |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 9 | from argparse import ArgumentParser |
Simon Glass | 2a0fa98 | 2022-02-11 13:23:21 -0700 | [diff] [blame] | 10 | from binman import state |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 11 | |
Simon Glass | 33046a3 | 2021-11-23 11:03:41 -0700 | [diff] [blame] | 12 | def 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') |
Simon Glass | 637958f | 2021-11-23 21:09:50 -0700 | [diff] [blame] | 20 | extract_parser.add_argument('-F', '--format', type=str, |
| 21 | help='Select an alternative format for extracted data') |
Simon Glass | 33046a3 | 2021-11-23 11:03:41 -0700 | [diff] [blame] | 22 | extract_parser.add_argument('-i', '--image', type=str, required=True, |
| 23 | help='Image filename to extract') |
| 24 | extract_parser.add_argument('-f', '--filename', type=str, |
| 25 | help='Output filename to write to') |
| 26 | extract_parser.add_argument('-O', '--outdir', type=str, default='', |
| 27 | help='Path to directory to use for output files') |
| 28 | extract_parser.add_argument('paths', type=str, nargs='*', |
| 29 | help='Paths within file to extract (wildcard)') |
| 30 | extract_parser.add_argument('-U', '--uncompressed', action='store_true', |
| 31 | help='Output raw uncompressed data for compressed entries') |
| 32 | |
Simon Glass | 88e04da | 2021-11-23 11:03:42 -0700 | [diff] [blame] | 33 | |
| 34 | #pylint: disable=R0903 |
| 35 | class BinmanVersion(argparse.Action): |
| 36 | """Handles the -V option to binman |
| 37 | |
| 38 | This reads the version information from a file called 'version' in the same |
| 39 | directory as this file. |
| 40 | |
| 41 | If not present it assumes this is running from the U-Boot tree and collects |
| 42 | the version from the Makefile. |
| 43 | |
| 44 | The format of the version information is three VAR = VALUE lines, for |
| 45 | example: |
| 46 | |
| 47 | VERSION = 2022 |
| 48 | PATCHLEVEL = 01 |
| 49 | EXTRAVERSION = -rc2 |
| 50 | """ |
| 51 | def __init__(self, nargs=0, **kwargs): |
| 52 | super().__init__(nargs=nargs, **kwargs) |
| 53 | |
| 54 | def __call__(self, parser, namespace, values, option_string=None): |
| 55 | parser._print_message(f'Binman {state.GetVersion()}\n') |
| 56 | parser.exit() |
| 57 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 58 | |
| 59 | def ParseArgs(argv): |
| 60 | """Parse the binman command-line arguments |
| 61 | |
| 62 | Args: |
Simon Glass | 33046a3 | 2021-11-23 11:03:41 -0700 | [diff] [blame] | 63 | argv (list of str): List of string arguments |
| 64 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 65 | Returns: |
Simon Glass | 33046a3 | 2021-11-23 11:03:41 -0700 | [diff] [blame] | 66 | tuple: (options, args) with the command-line options and arugments. |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 67 | options provides access to the options (e.g. option.debug) |
| 68 | args is a list of string arguments |
| 69 | """ |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 70 | if '-H' in argv: |
| 71 | argv.append('build') |
| 72 | |
| 73 | epilog = '''Binman creates and manipulate images for a board from a set of binaries. Binman is |
| 74 | controlled by a description in the board device tree.''' |
| 75 | |
| 76 | parser = ArgumentParser(epilog=epilog) |
| 77 | parser.add_argument('-B', '--build-dir', type=str, default='b', |
| 78 | help='Directory containing the build output') |
| 79 | parser.add_argument('-D', '--debug', action='store_true', |
| 80 | help='Enabling debugging (provides a full traceback on error)') |
| 81 | parser.add_argument('-H', '--full-help', action='store_true', |
| 82 | default=False, help='Display the README file') |
| 83 | parser.add_argument('--toolpath', type=str, action='append', |
| 84 | help='Add a path to the directories containing tools') |
Simon Glass | 76f496d | 2021-07-06 10:36:37 -0600 | [diff] [blame] | 85 | parser.add_argument('-T', '--threads', type=int, |
| 86 | default=None, help='Number of threads to use (0=single-thread)') |
| 87 | parser.add_argument('--test-section-timeout', action='store_true', |
| 88 | help='Use a zero timeout for section multi-threading (for testing)') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 89 | parser.add_argument('-v', '--verbosity', default=1, |
| 90 | type=int, help='Control verbosity: 0=silent, 1=warnings, 2=notices, ' |
| 91 | '3=info, 4=detail, 5=debug') |
Simon Glass | 88e04da | 2021-11-23 11:03:42 -0700 | [diff] [blame] | 92 | parser.add_argument('-V', '--version', nargs=0, action=BinmanVersion) |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 93 | |
| 94 | subparsers = parser.add_subparsers(dest='cmd') |
Simon Glass | 7668194 | 2020-10-26 17:40:02 -0600 | [diff] [blame] | 95 | subparsers.required = True |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 96 | |
| 97 | build_parser = subparsers.add_parser('build', help='Build firmware image') |
| 98 | build_parser.add_argument('-a', '--entry-arg', type=str, action='append', |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 99 | help='Set argument value arg=value') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 100 | build_parser.add_argument('-b', '--board', type=str, |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 101 | help='Board name to build') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 102 | build_parser.add_argument('-d', '--dt', type=str, |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 103 | help='Configuration file (.dtb) to use') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 104 | build_parser.add_argument('--fake-dtb', action='store_true', |
Simon Glass | 3140201 | 2018-09-14 04:57:23 -0600 | [diff] [blame] | 105 | help='Use fake device tree contents (for testing only)') |
Heiko Thiery | 6d45136 | 2022-01-06 11:49:41 +0100 | [diff] [blame] | 106 | build_parser.add_argument('--fake-ext-blobs', action='store_true', |
| 107 | help='Create fake ext blobs with dummy content (for testing only)') |
Simon Glass | 66152ce | 2022-01-09 20:14:09 -0700 | [diff] [blame] | 108 | build_parser.add_argument('--force-missing-bintools', type=str, |
| 109 | help='Comma-separated list of bintools to consider missing (for testing)') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 110 | build_parser.add_argument('-i', '--image', type=str, action='append', |
Simon Glass | 3b376c3 | 2018-09-14 04:57:12 -0600 | [diff] [blame] | 111 | help='Image filename to build (if not specified, build all)') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 112 | build_parser.add_argument('-I', '--indir', action='append', |
Simon Glass | 720d567 | 2019-07-08 13:18:31 -0600 | [diff] [blame] | 113 | help='Add a path to the list of directories to use for input files') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 114 | build_parser.add_argument('-m', '--map', action='store_true', |
Simon Glass | 3073266 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 115 | default=False, help='Output a map file for each image') |
Simon Glass | 5d94cc6 | 2020-07-09 18:39:38 -0600 | [diff] [blame] | 116 | build_parser.add_argument('-M', '--allow-missing', action='store_true', |
Simon Glass | 6bce5dc | 2022-11-09 19:14:42 -0700 | [diff] [blame] | 117 | default=False, help='Allow external blobs and bintools to be missing') |
Simon Glass | ed93067 | 2021-03-18 20:25:05 +1300 | [diff] [blame] | 118 | build_parser.add_argument('-n', '--no-expanded', action='store_true', |
| 119 | help="Don't use 'expanded' versions of entries where available; " |
| 120 | "normally 'u-boot' becomes 'u-boot-expanded', for example") |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 121 | build_parser.add_argument('-O', '--outdir', type=str, |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 122 | action='store', help='Path to directory to use for intermediate and ' |
| 123 | 'output files') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 124 | build_parser.add_argument('-p', '--preserve', action='store_true',\ |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 125 | help='Preserve temporary output directory even if option -O is not ' |
| 126 | 'given') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 127 | build_parser.add_argument('-u', '--update-fdt', action='store_true', |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 128 | default=False, help='Update the binman node with offset/size info') |
Simon Glass | adfb849 | 2021-11-03 21:09:18 -0600 | [diff] [blame] | 129 | build_parser.add_argument('--update-fdt-in-elf', type=str, |
| 130 | help='Update an ELF file with the output dtb: infile,outfile,begin_sym,end_sym') |
Simon Glass | 6bce5dc | 2022-11-09 19:14:42 -0700 | [diff] [blame] | 131 | build_parser.add_argument( |
| 132 | '-W', '--ignore-missing', action='store_true', default=False, |
| 133 | help='Return success even if there are missing blobs/bintools (requires -M)') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 134 | |
Simon Glass | 33046a3 | 2021-11-23 11:03:41 -0700 | [diff] [blame] | 135 | subparsers.add_parser( |
Simon Glass | 620c446 | 2022-01-09 20:14:11 -0700 | [diff] [blame] | 136 | 'bintool-docs', help='Write out bintool documentation (see bintool.rst)') |
| 137 | |
| 138 | subparsers.add_parser( |
Simon Glass | 33046a3 | 2021-11-23 11:03:41 -0700 | [diff] [blame] | 139 | 'entry-docs', help='Write out entry documentation (see entries.rst)') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 140 | |
Simon Glass | b2fd11d | 2019-07-08 14:25:48 -0600 | [diff] [blame] | 141 | list_parser = subparsers.add_parser('ls', help='List files in an image') |
| 142 | list_parser.add_argument('-i', '--image', type=str, required=True, |
| 143 | help='Image filename to list') |
| 144 | list_parser.add_argument('paths', type=str, nargs='*', |
| 145 | help='Paths within file to list (wildcard)') |
| 146 | |
Simon Glass | 33046a3 | 2021-11-23 11:03:41 -0700 | [diff] [blame] | 147 | make_extract_parser(subparsers) |
Simon Glass | 980a284 | 2019-07-08 14:25:52 -0600 | [diff] [blame] | 148 | |
Simon Glass | 30033c2 | 2019-07-20 12:24:15 -0600 | [diff] [blame] | 149 | replace_parser = subparsers.add_parser('replace', |
| 150 | help='Replace entries in an image') |
| 151 | replace_parser.add_argument('-C', '--compressed', action='store_true', |
| 152 | help='Input data is already compressed if needed for the entry') |
| 153 | replace_parser.add_argument('-i', '--image', type=str, required=True, |
Jan Kiszka | 8ea4443 | 2021-11-11 08:13:30 +0100 | [diff] [blame] | 154 | help='Image filename to update') |
Simon Glass | 30033c2 | 2019-07-20 12:24:15 -0600 | [diff] [blame] | 155 | replace_parser.add_argument('-f', '--filename', type=str, |
| 156 | help='Input filename to read from') |
| 157 | replace_parser.add_argument('-F', '--fix-size', action='store_true', |
| 158 | help="Don't allow entries to be resized") |
| 159 | replace_parser.add_argument('-I', '--indir', type=str, default='', |
| 160 | help='Path to directory to use for input files') |
| 161 | replace_parser.add_argument('-m', '--map', action='store_true', |
| 162 | default=False, help='Output a map file for the updated image') |
| 163 | replace_parser.add_argument('paths', type=str, nargs='*', |
Jan Kiszka | 8ea4443 | 2021-11-11 08:13:30 +0100 | [diff] [blame] | 164 | help='Paths within file to replace (wildcard)') |
Simon Glass | 30033c2 | 2019-07-20 12:24:15 -0600 | [diff] [blame] | 165 | |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 166 | test_parser = subparsers.add_parser('test', help='Run tests') |
| 167 | test_parser.add_argument('-P', '--processes', type=int, |
| 168 | help='set number of processes to use for running tests') |
| 169 | test_parser.add_argument('-T', '--test-coverage', action='store_true', |
| 170 | default=False, help='run tests and check for 100%% coverage') |
| 171 | test_parser.add_argument('-X', '--test-preserve-dirs', action='store_true', |
Simon Glass | 1c420c9 | 2019-07-08 13:18:49 -0600 | [diff] [blame] | 172 | help='Preserve and display test-created input directories; also ' |
| 173 | 'preserve the output directory if a single test is run (pass test ' |
| 174 | 'name at the end of the command line') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 175 | test_parser.add_argument('tests', nargs='*', |
| 176 | help='Test names to run (omit for all)') |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 177 | |
Simon Glass | 4eae925 | 2022-01-09 20:13:50 -0700 | [diff] [blame] | 178 | tool_parser = subparsers.add_parser('tool', help='Check bintools') |
| 179 | tool_parser.add_argument('-l', '--list', action='store_true', |
| 180 | help='List all known bintools') |
| 181 | tool_parser.add_argument('-f', '--fetch', action='store_true', |
| 182 | help='fetch a bintool from a known location (or: all/missing)') |
| 183 | tool_parser.add_argument('bintools', type=str, nargs='*') |
| 184 | |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 185 | return parser.parse_args(argv) |