Makefile.projbuild 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # Component support for esptool.py. Doesn't do much by itself,
  2. # components have their own flash targets that can use these variables.
  3. ESPPORT ?= $(CONFIG_ESPTOOLPY_PORT)
  4. ESPBAUD ?= $(CONFIG_ESPTOOLPY_BAUD)
  5. ESPFLASHMODE ?= $(CONFIG_ESPTOOLPY_FLASHMODE)
  6. ESPFLASHFREQ ?= $(CONFIG_ESPTOOLPY_FLASHFREQ)
  7. ESPFLASHSIZE ?= $(CONFIG_ESPTOOLPY_FLASHSIZE)
  8. CONFIG_ESPTOOLPY_COMPRESSED ?=
  9. PYTHON ?= $(call dequote,$(CONFIG_SDK_PYTHON))
  10. # two commands that can be used from other components
  11. # to invoke esptool.py (with or without serial port args)
  12. #
  13. ESPTOOLPY_SRC := $(COMPONENT_PATH)/esptool/esptool.py
  14. ESPTOOLPY := $(PYTHON) $(ESPTOOLPY_SRC) --chip esp32
  15. ESPTOOLPY_SERIAL := $(ESPTOOLPY) --port $(ESPPORT) --baud $(ESPBAUD) --before $(CONFIG_ESPTOOLPY_BEFORE) --after $(CONFIG_ESPTOOLPY_AFTER)
  16. # Supporting esptool command line tools
  17. ESPEFUSEPY := $(PYTHON) $(COMPONENT_PATH)/esptool/espefuse.py
  18. ESPSECUREPY := $(PYTHON) $(COMPONENT_PATH)/esptool/espsecure.py
  19. export ESPSECUREPY # is used in bootloader_support component
  20. ESPTOOL_FLASH_OPTIONS := --flash_mode $(ESPFLASHMODE) --flash_freq $(ESPFLASHFREQ) --flash_size $(ESPFLASHSIZE)
  21. ifdef CONFIG_ESPTOOLPY_FLASHSIZE_DETECT
  22. ESPTOOL_WRITE_FLASH_OPTIONS := --flash_mode $(ESPFLASHMODE) --flash_freq $(ESPFLASHFREQ) --flash_size detect
  23. else
  24. ESPTOOL_WRITE_FLASH_OPTIONS := $(ESPTOOL_FLASH_OPTIONS)
  25. endif
  26. ESPTOOL_ELF2IMAGE_OPTIONS :=
  27. ifdef CONFIG_ESP32_REV_MIN
  28. ESPTOOL_ELF2IMAGE_OPTIONS += --min-rev $(CONFIG_ESP32_REV_MIN)
  29. endif
  30. ifdef CONFIG_SECURE_BOOT_ENABLED
  31. ifndef CONFIG_SECURE_BOOT_ALLOW_SHORT_APP_PARTITION
  32. ifndef IS_BOOTLOADER_BUILD
  33. ESPTOOL_ELF2IMAGE_OPTIONS += --secure-pad
  34. endif
  35. endif
  36. endif
  37. ifndef IS_BOOTLOADER_BUILD
  38. ESPTOOL_ELF2IMAGE_OPTIONS += --elf-sha256-offset 0xb0
  39. endif
  40. ESPTOOLPY_WRITE_FLASH=$(ESPTOOLPY_SERIAL) write_flash $(if $(CONFIG_ESPTOOLPY_COMPRESSED),-z,-u) $(ESPTOOL_WRITE_FLASH_OPTIONS)
  41. ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
  42. ESPTOOLPY_WRITE_FLASH_ENCRYPT=$(ESPTOOLPY_SERIAL) write_flash --encrypt $(if $(CONFIG_ESPTOOLPY_COMPRESSED),-z,-u) $(ESPTOOL_WRITE_FLASH_OPTIONS)
  43. endif
  44. ESPTOOL_ALL_FLASH_ARGS += $(APP_OFFSET) $(APP_BIN)
  45. ifdef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
  46. ifndef IS_BOOTLOADER_BUILD
  47. # for locally signed secure boot image, add a signing step to get from unsigned app to signed app
  48. APP_BIN_UNSIGNED := $(APP_BIN:.bin=-unsigned.bin)
  49. $(APP_BIN): $(APP_BIN_UNSIGNED) $(SECURE_BOOT_SIGNING_KEY) $(SDKCONFIG_MAKEFILE)
  50. $(ESPSECUREPY) sign_data --keyfile $(SECURE_BOOT_SIGNING_KEY) -o $@ $<
  51. endif
  52. endif
  53. # non-secure boot (or bootloader), both these files are the same
  54. APP_BIN_UNSIGNED ?= $(APP_BIN)
  55. $(APP_BIN_UNSIGNED): $(APP_ELF) $(ESPTOOLPY_SRC) | check_python_dependencies
  56. $(ESPTOOLPY) elf2image $(ESPTOOL_FLASH_OPTIONS) $(ESPTOOL_ELF2IMAGE_OPTIONS) -o $@ $<
  57. ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
  58. encrypted-flash: all_binaries $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
  59. $(eval MONITOR_OPTS += --encrypted)
  60. @echo "Flashing binaries to serial port $(ESPPORT) (app at offset $(APP_OFFSET))..."
  61. ifdef CONFIG_SECURE_BOOT_ENABLED
  62. @echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)"
  63. endif
  64. $(ESPTOOLPY_WRITE_FLASH_ENCRYPT) $(ESPTOOL_ALL_FLASH_ARGS)
  65. else
  66. encrypted-flash:
  67. @echo "The command is supported only in FLASH ENCRYPTION DEVELOPMENT MODE"
  68. @exit 1
  69. endif
  70. flash: all_binaries $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
  71. @echo "Flashing binaries to serial port $(ESPPORT) (app at offset $(APP_OFFSET))..."
  72. ifdef CONFIG_SECURE_BOOT_ENABLED
  73. @echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)"
  74. endif
  75. $(ESPTOOLPY_WRITE_FLASH) $(ESPTOOL_ALL_FLASH_ARGS)
  76. app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
  77. @echo "Flashing app to serial port $(ESPPORT), offset $(APP_OFFSET)..."
  78. $(ESPTOOLPY_WRITE_FLASH) $(APP_OFFSET) $(APP_BIN)
  79. ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
  80. encrypted-app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
  81. $(eval MONITOR_OPTS += --encrypted)
  82. @echo "Flashing encrypted app binary to serial port $(ESPPORT) (app at offset $(APP_OFFSET))..."
  83. $(ESPTOOLPY_WRITE_FLASH_ENCRYPT) $(APP_OFFSET) $(APP_BIN)
  84. else
  85. encrypted-app-flash:
  86. @echo "The command is supported only in FLASH ENCRYPTION DEVELOPMENT MODE"
  87. @exit 1
  88. endif
  89. # Submodules normally added in component.mk, but can be added
  90. # at the project level as long as qualified path
  91. COMPONENT_SUBMODULES += $(COMPONENT_PATH)/esptool
  92. erase_flash: | check_python_dependencies
  93. @echo "Erasing entire flash..."
  94. $(ESPTOOLPY_SERIAL) erase_flash
  95. MONITORBAUD ?= $(CONFIG_ESPTOOLPY_MONITOR_BAUD)
  96. MONITOR_PYTHON := $(PYTHON)
  97. ifeq ("$(OS)","Windows_NT")
  98. # miniterm and idf_monitor both need a Windows Console PTY in order
  99. # to correctly handle user input
  100. MONITOR_PYTHON := winpty $(PYTHON)
  101. endif
  102. # note: if you want to run miniterm from command line, can simply run
  103. # miniterm.py on the console. The '$(PYTHON) -m serial.tools.miniterm'
  104. # is to allow for the $(PYTHON) variable overriding the python path.
  105. simple_monitor: $(call prereq_if_explicit,%flash) | check_python_dependencies
  106. $(MONITOR_PYTHON) -m serial.tools.miniterm --rts 0 --dtr 0 --raw $(ESPPORT) $(MONITORBAUD)
  107. PRINT_FILTER ?=
  108. MONITOR_OPTS := --baud $(MONITORBAUD) --port $(ESPPORT) --toolchain-prefix $(CONFIG_SDK_TOOLPREFIX) --make "$(MAKE)" --print_filter "$(PRINT_FILTER)"
  109. monitor: $(call prereq_if_explicit,%flash) | check_python_dependencies
  110. $(summary) MONITOR
  111. [ -f $(APP_ELF) ] || echo "*** 'make monitor' target requires an app to be compiled and flashed first."
  112. [ -f $(APP_ELF) ] || echo "*** Run 'make flash monitor' to build, flash and monitor"
  113. [ -f $(APP_ELF) ] || echo "*** Or alternatively 'make simple_monitor' to view the serial port as-is."
  114. [ -f $(APP_ELF) ] || exit 1
  115. $(MONITOR_PYTHON) $(IDF_PATH)/tools/idf_monitor.py $(MONITOR_OPTS) $(APP_ELF)
  116. .PHONY: erase_flash