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 | # Command-line parser for binman |
| 6 | # |
| 7 | |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 8 | from argparse import ArgumentParser |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 9 | |
| 10 | def 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 Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 20 | 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 |
| 24 | controlled 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') |
Simon Glass | 76f496d | 2021-07-06 10:36:37 -0600 | [diff] [blame] | 35 | 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 Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 39 | 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 Glass | 7668194 | 2020-10-26 17:40:02 -0600 | [diff] [blame] | 44 | subparsers.required = True |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 45 | |
| 46 | build_parser = subparsers.add_parser('build', help='Build firmware image') |
| 47 | build_parser.add_argument('-a', '--entry-arg', type=str, action='append', |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 48 | help='Set argument value arg=value') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 49 | build_parser.add_argument('-b', '--board', type=str, |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 50 | help='Board name to build') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 51 | build_parser.add_argument('-d', '--dt', type=str, |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 52 | help='Configuration file (.dtb) to use') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 53 | build_parser.add_argument('--fake-dtb', action='store_true', |
Simon Glass | 3140201 | 2018-09-14 04:57:23 -0600 | [diff] [blame] | 54 | help='Use fake device tree contents (for testing only)') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 55 | build_parser.add_argument('-i', '--image', type=str, action='append', |
Simon Glass | 3b376c3 | 2018-09-14 04:57:12 -0600 | [diff] [blame] | 56 | help='Image filename to build (if not specified, build all)') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 57 | build_parser.add_argument('-I', '--indir', action='append', |
Simon Glass | 720d567 | 2019-07-08 13:18:31 -0600 | [diff] [blame] | 58 | 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] | 59 | build_parser.add_argument('-m', '--map', action='store_true', |
Simon Glass | 3073266 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 60 | default=False, help='Output a map file for each image') |
Simon Glass | 5d94cc6 | 2020-07-09 18:39:38 -0600 | [diff] [blame] | 61 | build_parser.add_argument('-M', '--allow-missing', action='store_true', |
| 62 | default=False, help='Allow external blobs to be missing') |
Simon Glass | ed93067 | 2021-03-18 20:25:05 +1300 | [diff] [blame] | 63 | 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 Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 66 | build_parser.add_argument('-O', '--outdir', type=str, |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 67 | action='store', help='Path to directory to use for intermediate and ' |
| 68 | 'output files') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 69 | build_parser.add_argument('-p', '--preserve', action='store_true',\ |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 70 | help='Preserve temporary output directory even if option -O is not ' |
| 71 | 'given') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 72 | build_parser.add_argument('-u', '--update-fdt', action='store_true', |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 73 | default=False, help='Update the binman node with offset/size info') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 74 | |
| 75 | entry_parser = subparsers.add_parser('entry-docs', |
Simon Glass | 0ac96b6 | 2021-03-18 20:25:15 +1300 | [diff] [blame] | 76 | help='Write out entry documentation (see entries.rst)') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 77 | |
Simon Glass | b2fd11d | 2019-07-08 14:25:48 -0600 | [diff] [blame] | 78 | list_parser = subparsers.add_parser('ls', help='List files in an image') |
| 79 | list_parser.add_argument('-i', '--image', type=str, required=True, |
| 80 | help='Image filename to list') |
| 81 | list_parser.add_argument('paths', type=str, nargs='*', |
| 82 | help='Paths within file to list (wildcard)') |
| 83 | |
Simon Glass | 980a284 | 2019-07-08 14:25:52 -0600 | [diff] [blame] | 84 | extract_parser = subparsers.add_parser('extract', |
| 85 | help='Extract files from an image') |
| 86 | extract_parser.add_argument('-i', '--image', type=str, required=True, |
| 87 | help='Image filename to extract') |
| 88 | extract_parser.add_argument('-f', '--filename', type=str, |
| 89 | help='Output filename to write to') |
| 90 | extract_parser.add_argument('-O', '--outdir', type=str, default='', |
| 91 | help='Path to directory to use for output files') |
| 92 | extract_parser.add_argument('paths', type=str, nargs='*', |
| 93 | help='Paths within file to extract (wildcard)') |
| 94 | extract_parser.add_argument('-U', '--uncompressed', action='store_true', |
| 95 | help='Output raw uncompressed data for compressed entries') |
| 96 | |
Simon Glass | 30033c2 | 2019-07-20 12:24:15 -0600 | [diff] [blame] | 97 | replace_parser = subparsers.add_parser('replace', |
| 98 | help='Replace entries in an image') |
| 99 | replace_parser.add_argument('-C', '--compressed', action='store_true', |
| 100 | help='Input data is already compressed if needed for the entry') |
| 101 | replace_parser.add_argument('-i', '--image', type=str, required=True, |
| 102 | help='Image filename to extract') |
| 103 | replace_parser.add_argument('-f', '--filename', type=str, |
| 104 | help='Input filename to read from') |
| 105 | replace_parser.add_argument('-F', '--fix-size', action='store_true', |
| 106 | help="Don't allow entries to be resized") |
| 107 | replace_parser.add_argument('-I', '--indir', type=str, default='', |
| 108 | help='Path to directory to use for input files') |
| 109 | replace_parser.add_argument('-m', '--map', action='store_true', |
| 110 | default=False, help='Output a map file for the updated image') |
| 111 | replace_parser.add_argument('paths', type=str, nargs='*', |
| 112 | help='Paths within file to extract (wildcard)') |
| 113 | |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 114 | test_parser = subparsers.add_parser('test', help='Run tests') |
| 115 | test_parser.add_argument('-P', '--processes', type=int, |
| 116 | help='set number of processes to use for running tests') |
| 117 | test_parser.add_argument('-T', '--test-coverage', action='store_true', |
| 118 | default=False, help='run tests and check for 100%% coverage') |
| 119 | test_parser.add_argument('-X', '--test-preserve-dirs', action='store_true', |
Simon Glass | 1c420c9 | 2019-07-08 13:18:49 -0600 | [diff] [blame] | 120 | help='Preserve and display test-created input directories; also ' |
| 121 | 'preserve the output directory if a single test is run (pass test ' |
| 122 | 'name at the end of the command line') |
Simon Glass | f46732a | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 123 | test_parser.add_argument('tests', nargs='*', |
| 124 | help='Test names to run (omit for all)') |
Simon Glass | 2574ef6 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 125 | |
| 126 | return parser.parse_args(argv) |