dfu_ext.py 2.9 KB

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