Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | bf7fd50 | 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 | bf7fd50 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 5 | # Command-line parser for binman |
| 6 | # |
| 7 | |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 8 | from argparse import ArgumentParser |
Simon Glass | bf7fd50 | 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 | 53cd5d9 | 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', |
Simon Glass | bf7fd50 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 32 | default=False, help='Display the README file') |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 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') |
| 40 | |
| 41 | build_parser = subparsers.add_parser('build', help='Build firmware image') |
| 42 | build_parser.add_argument('-a', '--entry-arg', type=str, action='append', |
| 43 | help='Set argument value arg=value') |
| 44 | build_parser.add_argument('-b', '--board', type=str, |
| 45 | help='Board name to build') |
| 46 | build_parser.add_argument('-d', '--dt', type=str, |
| 47 | help='Configuration file (.dtb) to use') |
| 48 | build_parser.add_argument('--fake-dtb', action='store_true', |
| 49 | help='Use fake device tree contents (for testing only)') |
| 50 | build_parser.add_argument('-i', '--image', type=str, action='append', |
| 51 | help='Image filename to build (if not specified, build all)') |
| 52 | build_parser.add_argument('-I', '--indir', action='append', |
| 53 | help='Add a path to the list of directories to use for input files') |
| 54 | build_parser.add_argument('-m', '--map', action='store_true', |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 55 | default=False, help='Output a map file for each image') |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 56 | build_parser.add_argument('-O', '--outdir', type=str, |
Simon Glass | bf7fd50 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 57 | action='store', help='Path to directory to use for intermediate and ' |
| 58 | 'output files') |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 59 | build_parser.add_argument('-p', '--preserve', action='store_true',\ |
Simon Glass | bf7fd50 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 60 | help='Preserve temporary output directory even if option -O is not ' |
| 61 | 'given') |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 62 | build_parser.add_argument('-u', '--update-fdt', action='store_true', |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 63 | default=False, help='Update the binman node with offset/size info') |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 64 | |
| 65 | entry_parser = subparsers.add_parser('entry-docs', |
| 66 | help='Write out entry documentation (see README.entries)') |
| 67 | |
Simon Glass | 61f564d | 2019-07-08 14:25:48 -0600 | [diff] [blame] | 68 | list_parser = subparsers.add_parser('ls', help='List files in an image') |
| 69 | list_parser.add_argument('-i', '--image', type=str, required=True, |
| 70 | help='Image filename to list') |
| 71 | list_parser.add_argument('paths', type=str, nargs='*', |
| 72 | help='Paths within file to list (wildcard)') |
| 73 | |
Simon Glass | 71ce0ba | 2019-07-08 14:25:52 -0600 | [diff] [blame] | 74 | extract_parser = subparsers.add_parser('extract', |
| 75 | help='Extract files from an image') |
| 76 | extract_parser.add_argument('-i', '--image', type=str, required=True, |
| 77 | help='Image filename to extract') |
| 78 | extract_parser.add_argument('-f', '--filename', type=str, |
| 79 | help='Output filename to write to') |
| 80 | extract_parser.add_argument('-O', '--outdir', type=str, default='', |
| 81 | help='Path to directory to use for output files') |
| 82 | extract_parser.add_argument('paths', type=str, nargs='*', |
| 83 | help='Paths within file to extract (wildcard)') |
| 84 | extract_parser.add_argument('-U', '--uncompressed', action='store_true', |
| 85 | help='Output raw uncompressed data for compressed entries') |
| 86 | |
Simon Glass | a6cb995 | 2019-07-20 12:24:15 -0600 | [diff] [blame] | 87 | replace_parser = subparsers.add_parser('replace', |
| 88 | help='Replace entries in an image') |
| 89 | replace_parser.add_argument('-C', '--compressed', action='store_true', |
| 90 | help='Input data is already compressed if needed for the entry') |
| 91 | replace_parser.add_argument('-i', '--image', type=str, required=True, |
| 92 | help='Image filename to extract') |
| 93 | replace_parser.add_argument('-f', '--filename', type=str, |
| 94 | help='Input filename to read from') |
| 95 | replace_parser.add_argument('-F', '--fix-size', action='store_true', |
| 96 | help="Don't allow entries to be resized") |
| 97 | replace_parser.add_argument('-I', '--indir', type=str, default='', |
| 98 | help='Path to directory to use for input files') |
| 99 | replace_parser.add_argument('-m', '--map', action='store_true', |
| 100 | default=False, help='Output a map file for the updated image') |
| 101 | replace_parser.add_argument('paths', type=str, nargs='*', |
| 102 | help='Paths within file to extract (wildcard)') |
| 103 | |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 104 | test_parser = subparsers.add_parser('test', help='Run tests') |
| 105 | test_parser.add_argument('-P', '--processes', type=int, |
| 106 | help='set number of processes to use for running tests') |
| 107 | test_parser.add_argument('-T', '--test-coverage', action='store_true', |
| 108 | default=False, help='run tests and check for 100%% coverage') |
| 109 | test_parser.add_argument('-X', '--test-preserve-dirs', action='store_true', |
Simon Glass | d5164a7 | 2019-07-08 13:18:49 -0600 | [diff] [blame] | 110 | help='Preserve and display test-created input directories; also ' |
| 111 | 'preserve the output directory if a single test is run (pass test ' |
| 112 | 'name at the end of the command line') |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 113 | test_parser.add_argument('tests', nargs='*', |
| 114 | help='Test names to run (omit for all)') |
Simon Glass | bf7fd50 | 2016-11-25 20:15:51 -0700 | [diff] [blame] | 115 | |
| 116 | return parser.parse_args(argv) |