flash.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. """Compile and flash QMK Firmware
  2. You can compile a keymap already in the repo or using a QMK Configurator export.
  3. A bootloader must be specified.
  4. """
  5. from argcomplete.completers import FilesCompleter
  6. from milc import cli
  7. import qmk.path
  8. from qmk.decorators import automagic_keyboard, automagic_keymap
  9. from qmk.commands import do_compile
  10. from qmk.keyboard import keyboard_completer, is_keyboard_target
  11. def print_bootloader_help():
  12. """Prints the available bootloaders listed in docs.qmk.fm.
  13. """
  14. cli.log.info('Here are the available bootloaders:')
  15. cli.echo('\tdfu')
  16. cli.echo('\tdfu-ee')
  17. cli.echo('\tdfu-split-left')
  18. cli.echo('\tdfu-split-right')
  19. cli.echo('\tavrdude')
  20. cli.echo('\tBootloadHID')
  21. cli.echo('\tdfu-util')
  22. cli.echo('\tdfu-util-split-left')
  23. cli.echo('\tdfu-util-split-right')
  24. cli.echo('\tst-link-cli')
  25. cli.echo('\tst-flash')
  26. cli.echo('For more info, visit https://docs.qmk.fm/#/flashing')
  27. @cli.argument('filename', nargs='?', arg_only=True, type=qmk.path.FileType('r'), completer=FilesCompleter('.json'), help='The configurator export JSON to compile.')
  28. @cli.argument('-b', '--bootloaders', action='store_true', help='List the available bootloaders.')
  29. @cli.argument('-bl', '--bootloader', default='flash', help='The flash command, corresponding to qmk\'s make options of bootloaders.')
  30. @cli.argument('-km', '--keymap', help='The keymap to build a firmware for. Use this if you dont have a configurator file. Ignored when a configurator file is supplied.')
  31. @cli.argument('-kb', '--keyboard', type=is_keyboard_target, completer=keyboard_completer, help='The keyboard to build a firmware for. Use this if you dont have a configurator file. Ignored when a configurator file is supplied.')
  32. @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.")
  33. @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs; 0 means unlimited.")
  34. @cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.")
  35. @cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.")
  36. @cli.subcommand('QMK Flash.')
  37. @automagic_keyboard
  38. @automagic_keymap
  39. def flash(cli):
  40. """Compile and or flash QMK Firmware or keyboard/layout
  41. If a Configurator JSON export is supplied this command will create a new keymap. Keymap and Keyboard arguments
  42. will be ignored.
  43. If no file is supplied, keymap and keyboard are expected.
  44. If bootloader is omitted the make system will use the configured bootloader for that keyboard.
  45. """
  46. if cli.args.bootloaders:
  47. # Provide usage and list bootloaders
  48. cli.print_usage()
  49. print_bootloader_help()
  50. return False
  51. return do_compile(cli.config.flash.keyboard, cli.config.flash.keymap, cli.config.flash.parallel, cli.config.flash.bootloader)