Makefile.projbuild 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 ?= $(call dequote,$(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. ifdef CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME
  27. ESPTOOL_WRITE_FLASH_OPTIONS := --flash_mode $(ESPFLASHMODE) --flash_freq $(ESPFLASHFREQ) --flash_size keep
  28. endif
  29. ESPTOOL_ELF2IMAGE_OPTIONS :=
  30. ifdef CONFIG_ESP32_REV_MIN
  31. ESPTOOL_ELF2IMAGE_OPTIONS += --min-rev $(CONFIG_ESP32_REV_MIN)
  32. endif
  33. ifndef CONFIG_SECURE_BOOT_ALLOW_SHORT_APP_PARTITION
  34. ifndef IS_BOOTLOADER_BUILD
  35. ifdef CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME
  36. ESPTOOL_ELF2IMAGE_OPTIONS += --secure-pad
  37. else ifdef CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME
  38. ESPTOOL_ELF2IMAGE_OPTIONS += --secure-pad-v2
  39. endif
  40. endif
  41. endif
  42. ifndef IS_BOOTLOADER_BUILD
  43. ESPTOOL_ELF2IMAGE_OPTIONS += --elf-sha256-offset 0xb0
  44. endif
  45. ifdef CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME
  46. SECURE_APPS_SIGNING_SCHEME = "1"
  47. else ifdef CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME
  48. SECURE_APPS_SIGNING_SCHEME = "2"
  49. endif
  50. ESPTOOLPY_WRITE_FLASH=$(ESPTOOLPY_SERIAL) write_flash $(if $(CONFIG_ESPTOOLPY_COMPRESSED),-z,-u) $(ESPTOOL_WRITE_FLASH_OPTIONS)
  51. ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
  52. ESPTOOLPY_WRITE_FLASH_ENCRYPT=$(ESPTOOLPY_SERIAL) write_flash --encrypt $(if $(CONFIG_ESPTOOLPY_COMPRESSED),-z,-u) $(ESPTOOL_WRITE_FLASH_OPTIONS)
  53. endif
  54. ESPTOOL_ALL_FLASH_ARGS += $(APP_OFFSET) $(APP_BIN)
  55. UF2_ADD_BINARIES += $(APP_OFFSET) $(APP_BIN)
  56. ifdef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
  57. ifndef IS_BOOTLOADER_BUILD
  58. # for locally signed secure boot image, add a signing step to get from unsigned app to signed app
  59. APP_BIN_UNSIGNED := $(APP_BIN:.bin=-unsigned.bin)
  60. $(APP_BIN): $(APP_BIN_UNSIGNED) $(SECURE_BOOT_SIGNING_KEY) $(SDKCONFIG_MAKEFILE)
  61. $(ESPSECUREPY) sign_data --version $(SECURE_APPS_SIGNING_SCHEME) --keyfile $(SECURE_BOOT_SIGNING_KEY) -o $@ $<
  62. endif
  63. endif
  64. # non-secure boot (or bootloader), both these files are the same
  65. APP_BIN_UNSIGNED ?= $(APP_BIN)
  66. $(APP_BIN_UNSIGNED): $(APP_ELF) $(ESPTOOLPY_SRC) | check_python_dependencies
  67. ifeq ("$(CONFIG_APP_BUILD_GENERATE_BINARIES)","y")
  68. $(ESPTOOLPY) elf2image $(ESPTOOL_FLASH_OPTIONS) $(ESPTOOL_ELF2IMAGE_OPTIONS) -o $@ $<
  69. else
  70. @echo "Skipping the BIN generation"
  71. endif
  72. ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
  73. encrypted-flash: all_binaries $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
  74. $(eval MONITOR_OPTS += --encrypted)
  75. @echo "Flashing binaries to serial port '$(ESPPORT)' (app at offset $(APP_OFFSET))..."
  76. ifdef CONFIG_SECURE_BOOT
  77. @echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)"
  78. endif
  79. $(ESPTOOLPY_WRITE_FLASH_ENCRYPT) $(ESPTOOL_ALL_FLASH_ARGS)
  80. else
  81. encrypted-flash:
  82. @echo "The command is supported only in FLASH ENCRYPTION DEVELOPMENT MODE"
  83. @exit 1
  84. endif
  85. flash: all_binaries $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
  86. @echo "Flashing binaries to serial port '$(ESPPORT)' (app at offset $(APP_OFFSET))..."
  87. ifdef CONFIG_SECURE_BOOT
  88. @echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)"
  89. endif
  90. $(ESPTOOLPY_WRITE_FLASH) $(ESPTOOL_ALL_FLASH_ARGS)
  91. app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
  92. @echo "Flashing app to serial port '$(ESPPORT)', offset $(APP_OFFSET)..."
  93. $(ESPTOOLPY_WRITE_FLASH) $(APP_OFFSET) $(APP_BIN)
  94. ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
  95. encrypted-app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
  96. $(eval MONITOR_OPTS += --encrypted)
  97. @echo "Flashing encrypted app binary to serial port '$(ESPPORT)' (app at offset $(APP_OFFSET))..."
  98. $(ESPTOOLPY_WRITE_FLASH_ENCRYPT) $(APP_OFFSET) $(APP_BIN)
  99. else
  100. encrypted-app-flash:
  101. @echo "The command is supported only in FLASH ENCRYPTION DEVELOPMENT MODE"
  102. @exit 1
  103. endif
  104. # Submodules normally added in component.mk, but can be added
  105. # at the project level as long as qualified path
  106. COMPONENT_SUBMODULES += $(COMPONENT_PATH)/esptool
  107. erase_flash: | check_python_dependencies
  108. @echo "Erasing entire flash..."
  109. $(ESPTOOLPY_SERIAL) erase_flash
  110. MONITORBAUD ?= $(CONFIG_ESPTOOLPY_MONITOR_BAUD)
  111. MONITOR_PYTHON := $(PYTHON)
  112. ifeq ("$(OS)","Windows_NT")
  113. # miniterm and idf_monitor both need a Windows Console PTY in order
  114. # to correctly handle user input
  115. MONITOR_PYTHON := winpty $(PYTHON)
  116. endif
  117. # note: if you want to run miniterm from command line, can simply run
  118. # miniterm.py on the console. The '$(PYTHON) -m serial.tools.miniterm'
  119. # is to allow for the $(PYTHON) variable overriding the python path.
  120. simple_monitor: $(call prereq_if_explicit,%flash) | check_python_dependencies
  121. $(MONITOR_PYTHON) -m serial.tools.miniterm --rts 0 --dtr 0 --raw '$(ESPPORT)' $(MONITORBAUD)
  122. PRINT_FILTER ?=
  123. MONITOR_CORE_DUMP_DECODE_ARG ?=
  124. MONITOR_CORE_DUMP_DECODE = $(call dequote,$(CONFIG_ESP_COREDUMP_DECODE))
  125. ifneq ("$(MONITOR_CORE_DUMP_DECODE)","")
  126. MONITOR_CORE_DUMP_DECODE_ARG = --decode-coredumps $(MONITOR_CORE_DUMP_DECODE)
  127. endif
  128. MONITOR_OPTS := --baud $(MONITORBAUD) --port '$(ESPPORT)' --toolchain-prefix $(CONFIG_SDK_TOOLPREFIX) --make "$(MAKE)" --print_filter "$(PRINT_FILTER)" $(MONITOR_CORE_DUMP_DECODE_ARG)
  129. monitor: $(call prereq_if_explicit,%flash) | check_python_dependencies
  130. $(summary) MONITOR
  131. [ -f $(APP_ELF) ] || echo "*** 'make monitor' target requires an app to be compiled and flashed first."
  132. [ -f $(APP_ELF) ] || echo "*** Run 'make flash monitor' to build, flash and monitor"
  133. [ -f $(APP_ELF) ] || echo "*** Or alternatively 'make simple_monitor' to view the serial port as-is."
  134. [ -f $(APP_ELF) ] || exit 1
  135. $(MONITOR_PYTHON) $(IDF_PATH)/tools/idf_monitor.py $(MONITOR_OPTS) $(APP_ELF)
  136. # Make supports ESP32 only
  137. UF2_CHIP_ID = "0x1c5f21b0"
  138. uf2-app: $(APP_BIN) partition_table_get_info
  139. $(PYTHON) $(IDF_PATH)/tools/mkuf2.py write \
  140. -o "$(BUILD_DIR_BASE)/uf2-app.bin" \
  141. --chip-id "$(UF2_CHIP_ID)" \
  142. $(APP_OFFSET) $(APP_BIN)
  143. uf2: all_binaries
  144. $(PYTHON) $(IDF_PATH)/tools/mkuf2.py write \
  145. -o "$(BUILD_DIR_BASE)/uf2.bin" \
  146. --chip-id "$(UF2_CHIP_ID)" \
  147. $(UF2_ADD_BINARIES)
  148. .PHONY: erase_flash