Makefile.projbuild 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. ifdef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
  56. ifndef IS_BOOTLOADER_BUILD
  57. # for locally signed secure boot image, add a signing step to get from unsigned app to signed app
  58. APP_BIN_UNSIGNED := $(APP_BIN:.bin=-unsigned.bin)
  59. $(APP_BIN): $(APP_BIN_UNSIGNED) $(SECURE_BOOT_SIGNING_KEY) $(SDKCONFIG_MAKEFILE)
  60. $(ESPSECUREPY) sign_data --version $(SECURE_APPS_SIGNING_SCHEME) --keyfile $(SECURE_BOOT_SIGNING_KEY) -o $@ $<
  61. endif
  62. endif
  63. # non-secure boot (or bootloader), both these files are the same
  64. APP_BIN_UNSIGNED ?= $(APP_BIN)
  65. $(APP_BIN_UNSIGNED): $(APP_ELF) $(ESPTOOLPY_SRC) | check_python_dependencies
  66. ifeq ("$(CONFIG_APP_BUILD_GENERATE_BINARIES)","y")
  67. $(ESPTOOLPY) elf2image $(ESPTOOL_FLASH_OPTIONS) $(ESPTOOL_ELF2IMAGE_OPTIONS) -o $@ $<
  68. else
  69. @echo "Skipping the BIN generation"
  70. endif
  71. ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
  72. encrypted-flash: all_binaries $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
  73. $(eval MONITOR_OPTS += --encrypted)
  74. @echo "Flashing binaries to serial port '$(ESPPORT)' (app at offset $(APP_OFFSET))..."
  75. ifdef CONFIG_SECURE_BOOT
  76. @echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)"
  77. endif
  78. $(ESPTOOLPY_WRITE_FLASH_ENCRYPT) $(ESPTOOL_ALL_FLASH_ARGS)
  79. else
  80. encrypted-flash:
  81. @echo "The command is supported only in FLASH ENCRYPTION DEVELOPMENT MODE"
  82. @exit 1
  83. endif
  84. flash: all_binaries $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
  85. @echo "Flashing binaries to serial port '$(ESPPORT)' (app at offset $(APP_OFFSET))..."
  86. ifdef CONFIG_SECURE_BOOT
  87. @echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)"
  88. endif
  89. $(ESPTOOLPY_WRITE_FLASH) $(ESPTOOL_ALL_FLASH_ARGS)
  90. app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
  91. @echo "Flashing app to serial port '$(ESPPORT)', offset $(APP_OFFSET)..."
  92. $(ESPTOOLPY_WRITE_FLASH) $(APP_OFFSET) $(APP_BIN)
  93. ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
  94. encrypted-app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
  95. $(eval MONITOR_OPTS += --encrypted)
  96. @echo "Flashing encrypted app binary to serial port '$(ESPPORT)' (app at offset $(APP_OFFSET))..."
  97. $(ESPTOOLPY_WRITE_FLASH_ENCRYPT) $(APP_OFFSET) $(APP_BIN)
  98. else
  99. encrypted-app-flash:
  100. @echo "The command is supported only in FLASH ENCRYPTION DEVELOPMENT MODE"
  101. @exit 1
  102. endif
  103. # Submodules normally added in component.mk, but can be added
  104. # at the project level as long as qualified path
  105. COMPONENT_SUBMODULES += $(COMPONENT_PATH)/esptool
  106. erase_flash: | check_python_dependencies
  107. @echo "Erasing entire flash..."
  108. $(ESPTOOLPY_SERIAL) erase_flash
  109. MONITORBAUD ?= $(CONFIG_ESPTOOLPY_MONITOR_BAUD)
  110. MONITOR_PYTHON := $(PYTHON)
  111. ifeq ("$(OS)","Windows_NT")
  112. # miniterm and idf_monitor both need a Windows Console PTY in order
  113. # to correctly handle user input
  114. MONITOR_PYTHON := winpty $(PYTHON)
  115. endif
  116. # note: if you want to run miniterm from command line, can simply run
  117. # miniterm.py on the console. The '$(PYTHON) -m serial.tools.miniterm'
  118. # is to allow for the $(PYTHON) variable overriding the python path.
  119. simple_monitor: $(call prereq_if_explicit,%flash) | check_python_dependencies
  120. $(MONITOR_PYTHON) -m serial.tools.miniterm --rts 0 --dtr 0 --raw '$(ESPPORT)' $(MONITORBAUD)
  121. PRINT_FILTER ?=
  122. MONITOR_CORE_DUMP_DECODE_ARG ?=
  123. MONITOR_CORE_DUMP_DECODE = $(call dequote,$(CONFIG_ESP32_CORE_DUMP_DECODE))
  124. ifneq ("$(MONITOR_CORE_DUMP_DECODE)","")
  125. MONITOR_CORE_DUMP_DECODE_ARG = --decode-coredumps $(MONITOR_CORE_DUMP_DECODE)
  126. endif
  127. MONITOR_OPTS := --baud $(MONITORBAUD) --port '$(ESPPORT)' --toolchain-prefix $(CONFIG_SDK_TOOLPREFIX) --make "$(MAKE)" --print_filter "$(PRINT_FILTER)" $(MONITOR_CORE_DUMP_DECODE_ARG)
  128. monitor: $(call prereq_if_explicit,%flash) | check_python_dependencies
  129. $(summary) MONITOR
  130. [ -f $(APP_ELF) ] || echo "*** 'make monitor' target requires an app to be compiled and flashed first."
  131. [ -f $(APP_ELF) ] || echo "*** Run 'make flash monitor' to build, flash and monitor"
  132. [ -f $(APP_ELF) ] || echo "*** Or alternatively 'make simple_monitor' to view the serial port as-is."
  133. [ -f $(APP_ELF) ] || exit 1
  134. $(MONITOR_PYTHON) $(IDF_PATH)/tools/idf_monitor.py $(MONITOR_OPTS) $(APP_ELF)
  135. .PHONY: erase_flash