cmdline.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # SPDX-License-Identifier: GPL-2.0+
  2. # Copyright (c) 2016 Google, Inc
  3. # Written by Simon Glass <sjg@chromium.org>
  4. #
  5. # Command-line parser for binman
  6. #
  7. from argparse import ArgumentParser
  8. def ParseArgs(argv):
  9. """Parse the binman command-line arguments
  10. Args:
  11. argv: List of string arguments
  12. Returns:
  13. Tuple (options, args) with the command-line options and arugments.
  14. options provides access to the options (e.g. option.debug)
  15. args is a list of string arguments
  16. """
  17. if '-H' in argv:
  18. argv.append('build')
  19. epilog = '''Binman creates and manipulate images for a board from a set of binaries. Binman is
  20. controlled by a description in the board device tree.'''
  21. parser = ArgumentParser(epilog=epilog)
  22. parser.add_argument('-B', '--build-dir', type=str, default='b',
  23. help='Directory containing the build output')
  24. parser.add_argument('-D', '--debug', action='store_true',
  25. help='Enabling debugging (provides a full traceback on error)')
  26. parser.add_argument('-H', '--full-help', action='store_true',
  27. default=False, help='Display the README file')
  28. parser.add_argument('--toolpath', type=str, action='append',
  29. help='Add a path to the directories containing tools')
  30. parser.add_argument('-T', '--threads', type=int,
  31. default=None, help='Number of threads to use (0=single-thread)')
  32. parser.add_argument('--test-section-timeout', action='store_true',
  33. help='Use a zero timeout for section multi-threading (for testing)')
  34. parser.add_argument('-v', '--verbosity', default=1,
  35. type=int, help='Control verbosity: 0=silent, 1=warnings, 2=notices, '
  36. '3=info, 4=detail, 5=debug')
  37. subparsers = parser.add_subparsers(dest='cmd')
  38. subparsers.required = True
  39. build_parser = subparsers.add_parser('build', help='Build firmware image')
  40. build_parser.add_argument('-a', '--entry-arg', type=str, action='append',
  41. help='Set argument value arg=value')
  42. build_parser.add_argument('-b', '--board', type=str,
  43. help='Board name to build')
  44. build_parser.add_argument('-d', '--dt', type=str,
  45. help='Configuration file (.dtb) to use')
  46. build_parser.add_argument('--fake-dtb', action='store_true',
  47. help='Use fake device tree contents (for testing only)')
  48. build_parser.add_argument('-i', '--image', type=str, action='append',
  49. help='Image filename to build (if not specified, build all)')
  50. build_parser.add_argument('-I', '--indir', action='append',
  51. help='Add a path to the list of directories to use for input files')
  52. build_parser.add_argument('-m', '--map', action='store_true',
  53. default=False, help='Output a map file for each image')
  54. build_parser.add_argument('-M', '--allow-missing', action='store_true',
  55. default=False, help='Allow external blobs to be missing')
  56. build_parser.add_argument('-n', '--no-expanded', action='store_true',
  57. help="Don't use 'expanded' versions of entries where available; "
  58. "normally 'u-boot' becomes 'u-boot-expanded', for example")
  59. build_parser.add_argument('-O', '--outdir', type=str,
  60. action='store', help='Path to directory to use for intermediate and '
  61. 'output files')
  62. build_parser.add_argument('-p', '--preserve', action='store_true',\
  63. help='Preserve temporary output directory even if option -O is not '
  64. 'given')
  65. build_parser.add_argument('-u', '--update-fdt', action='store_true',
  66. default=False, help='Update the binman node with offset/size info')
  67. entry_parser = subparsers.add_parser('entry-docs',
  68. help='Write out entry documentation (see entries.rst)')
  69. list_parser = subparsers.add_parser('ls', help='List files in an image')
  70. list_parser.add_argument('-i', '--image', type=str, required=True,
  71. help='Image filename to list')
  72. list_parser.add_argument('paths', type=str, nargs='*',
  73. help='Paths within file to list (wildcard)')
  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. replace_parser = subparsers.add_parser('replace',
  87. help='Replace entries in an image')
  88. replace_parser.add_argument('-C', '--compressed', action='store_true',
  89. help='Input data is already compressed if needed for the entry')
  90. replace_parser.add_argument('-i', '--image', type=str, required=True,
  91. help='Image filename to extract')
  92. replace_parser.add_argument('-f', '--filename', type=str,
  93. help='Input filename to read from')
  94. replace_parser.add_argument('-F', '--fix-size', action='store_true',
  95. help="Don't allow entries to be resized")
  96. replace_parser.add_argument('-I', '--indir', type=str, default='',
  97. help='Path to directory to use for input files')
  98. replace_parser.add_argument('-m', '--map', action='store_true',
  99. default=False, help='Output a map file for the updated image')
  100. replace_parser.add_argument('paths', type=str, nargs='*',
  101. help='Paths within file to extract (wildcard)')
  102. test_parser = subparsers.add_parser('test', help='Run tests')
  103. test_parser.add_argument('-P', '--processes', type=int,
  104. help='set number of processes to use for running tests')
  105. test_parser.add_argument('-T', '--test-coverage', action='store_true',
  106. default=False, help='run tests and check for 100%% coverage')
  107. test_parser.add_argument('-X', '--test-preserve-dirs', action='store_true',
  108. help='Preserve and display test-created input directories; also '
  109. 'preserve the output directory if a single test is run (pass test '
  110. 'name at the end of the command line')
  111. test_parser.add_argument('tests', nargs='*',
  112. help='Test names to run (omit for all)')
  113. return parser.parse_args(argv)