dfu_ext.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from idf_py_actions.tools import is_target_supported, ensure_build_directory, run_target
  2. from idf_py_actions.errors import FatalError
  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_flash_target(target_name, ctx, args):
  9. ensure_build_directory(args, ctx.info_name)
  10. try:
  11. run_target(target_name, args)
  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. 'options': [
  24. {
  25. 'names': ['--part-size'],
  26. 'help': 'Large files are split up into smaller partitions in order to avoid timeout during '
  27. 'erasing flash. This option allows to overwrite the default partition size of '
  28. 'mkdfu.py.'
  29. }
  30. ],
  31. },
  32. 'dfu-flash': {
  33. 'callback': dfu_flash_target,
  34. 'short_help': 'Flash the DFU binary',
  35. 'order_dependencies': ['dfu'],
  36. },
  37. }
  38. }
  39. return dfu_actions if is_target_supported(project_path, SUPPORTED_TARGETS) else {}