dfu_ext.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from idf_py_actions.errors import FatalError
  2. from idf_py_actions.tools import ensure_build_directory, is_target_supported, run_target
  3. def action_extensions(base_actions, project_path):
  4. SUPPORTED_TARGETS = ['esp32s2']
  5. def dfu_target(target_name, ctx, args):
  6. ensure_build_directory(args, ctx.info_name)
  7. run_target(target_name, args)
  8. def dfu_flash_target(target_name, ctx, args, path):
  9. ensure_build_directory(args, ctx.info_name)
  10. try:
  11. run_target(target_name, args, {'ESP_DFU_PATH': path})
  12. except FatalError:
  13. # Cannot capture the error from dfu-util here so the best advise is:
  14. print('Please have a look at the "Device Firmware Upgrade through USB" chapter in API Guides of the '
  15. 'ESP-IDF documentation for solving common dfu-util issues.')
  16. raise
  17. dfu_actions = {
  18. 'actions': {
  19. 'dfu': {
  20. 'callback': dfu_target,
  21. 'short_help': 'Build the DFU binary',
  22. 'dependencies': ['all'],
  23. },
  24. 'dfu-list': {
  25. 'callback': dfu_target,
  26. 'short_help': 'List DFU capable devices',
  27. 'dependencies': [],
  28. },
  29. 'dfu-flash': {
  30. 'callback': dfu_flash_target,
  31. 'short_help': 'Flash the DFU binary',
  32. 'order_dependencies': ['dfu'],
  33. 'options': [
  34. {
  35. 'names': ['--path'],
  36. 'default': '',
  37. 'help': 'Specify path to DFU device. The default empty path works if there is just one '
  38. 'ESP device with the same product identificator. See the device list for paths '
  39. 'of available devices.'
  40. }
  41. ],
  42. },
  43. }
  44. }
  45. return dfu_actions if is_target_supported(project_path, SUPPORTED_TARGETS) else {}