dfu_ext.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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, part_size):
  6. ensure_build_directory(args, ctx.info_name)
  7. run_target(target_name, args, {'ESP_DFU_PART_SIZE': part_size} if part_size else {})
  8. def dfu_list_target(target_name, ctx, args):
  9. ensure_build_directory(args, ctx.info_name)
  10. run_target(target_name, args)
  11. def dfu_flash_target(target_name, ctx, args, path):
  12. ensure_build_directory(args, ctx.info_name)
  13. try:
  14. run_target(target_name, args, {'ESP_DFU_PATH': path})
  15. except FatalError:
  16. # Cannot capture the error from dfu-util here so the best advise is:
  17. print('Please have a look at the "Device Firmware Upgrade through USB" chapter in API Guides of the '
  18. 'ESP-IDF documentation for solving common dfu-util issues.')
  19. raise
  20. dfu_actions = {
  21. 'actions': {
  22. 'dfu': {
  23. 'callback': dfu_target,
  24. 'short_help': 'Build the DFU binary',
  25. 'dependencies': ['all'],
  26. 'options': [
  27. {
  28. 'names': ['--part-size'],
  29. 'help': 'Large files are split up into smaller partitions in order to avoid timeout during '
  30. 'erasing flash. This option allows to overwrite the default partition size of '
  31. 'mkdfu.py.'
  32. }
  33. ],
  34. },
  35. 'dfu-list': {
  36. 'callback': dfu_list_target,
  37. 'short_help': 'List DFU capable devices',
  38. 'dependencies': [],
  39. },
  40. 'dfu-flash': {
  41. 'callback': dfu_flash_target,
  42. 'short_help': 'Flash the DFU binary',
  43. 'order_dependencies': ['dfu'],
  44. 'options': [
  45. {
  46. 'names': ['--path'],
  47. 'default': '',
  48. 'help': 'Specify path to DFU device. The default empty path works if there is just one '
  49. 'ESP device with the same product identifier. See the device list for paths '
  50. 'of available devices.'
  51. }
  52. ],
  53. },
  54. }
  55. }
  56. return dfu_actions if is_target_supported(project_path, SUPPORTED_TARGETS) else {}