esp-idf/components/esptool_py/Makefile.projbuild

184 wiersze
7.3 KiB
Makefile

# Component support for esptool.py. Doesn't do much by itself,
# components have their own flash targets that can use these variables.
ESPPORT ?= $(call dequote,$(CONFIG_ESPTOOLPY_PORT))
ESPBAUD ?= $(CONFIG_ESPTOOLPY_BAUD)
ESPFLASHMODE ?= $(CONFIG_ESPTOOLPY_FLASHMODE)
ESPFLASHFREQ ?= $(CONFIG_ESPTOOLPY_FLASHFREQ)
ESPFLASHSIZE ?= $(CONFIG_ESPTOOLPY_FLASHSIZE)
CONFIG_ESPTOOLPY_COMPRESSED ?=
PYTHON ?= $(call dequote,$(CONFIG_SDK_PYTHON))
# two commands that can be used from other components
# to invoke esptool.py (with or without serial port args)
#
ESPTOOLPY_SRC := $(COMPONENT_PATH)/esptool/esptool.py
ESPTOOLPY := $(PYTHON) $(ESPTOOLPY_SRC) --chip esp32
ESPTOOLPY_SERIAL := $(ESPTOOLPY) --port '$(ESPPORT)' --baud $(ESPBAUD) --before $(CONFIG_ESPTOOLPY_BEFORE) --after $(CONFIG_ESPTOOLPY_AFTER)
# Supporting esptool command line tools
ESPEFUSEPY := $(PYTHON) $(COMPONENT_PATH)/esptool/espefuse.py
ESPSECUREPY := $(PYTHON) $(COMPONENT_PATH)/esptool/espsecure.py
export ESPSECUREPY # is used in bootloader_support component
ESPTOOL_FLASH_OPTIONS := --flash_mode $(ESPFLASHMODE) --flash_freq $(ESPFLASHFREQ) --flash_size $(ESPFLASHSIZE)
ifdef CONFIG_ESPTOOLPY_FLASHSIZE_DETECT
ESPTOOL_WRITE_FLASH_OPTIONS := --flash_mode $(ESPFLASHMODE) --flash_freq $(ESPFLASHFREQ) --flash_size detect
else
ESPTOOL_WRITE_FLASH_OPTIONS := $(ESPTOOL_FLASH_OPTIONS)
endif
ifdef CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME
ESPTOOL_WRITE_FLASH_OPTIONS := --flash_mode $(ESPFLASHMODE) --flash_freq $(ESPFLASHFREQ) --flash_size keep
endif
ESPTOOL_ELF2IMAGE_OPTIONS :=
ifdef CONFIG_ESP32_REV_MIN
ESPTOOL_ELF2IMAGE_OPTIONS += --min-rev $(CONFIG_ESP32_REV_MIN)
endif
ifndef CONFIG_SECURE_BOOT_ALLOW_SHORT_APP_PARTITION
ifndef IS_BOOTLOADER_BUILD
ifdef CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME
ESPTOOL_ELF2IMAGE_OPTIONS += --secure-pad
else ifdef CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME
ESPTOOL_ELF2IMAGE_OPTIONS += --secure-pad-v2
endif
endif
endif
ifndef IS_BOOTLOADER_BUILD
ESPTOOL_ELF2IMAGE_OPTIONS += --elf-sha256-offset 0xb0
endif
ifdef CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME
SECURE_APPS_SIGNING_SCHEME = "1"
else ifdef CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME
SECURE_APPS_SIGNING_SCHEME = "2"
endif
ESPTOOLPY_WRITE_FLASH=$(ESPTOOLPY_SERIAL) write_flash $(if $(CONFIG_ESPTOOLPY_COMPRESSED),-z,-u) $(ESPTOOL_WRITE_FLASH_OPTIONS)
ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
ESPTOOLPY_WRITE_FLASH_ENCRYPT=$(ESPTOOLPY_SERIAL) write_flash --encrypt $(if $(CONFIG_ESPTOOLPY_COMPRESSED),-z,-u) $(ESPTOOL_WRITE_FLASH_OPTIONS)
endif
ESPTOOL_ALL_FLASH_ARGS += $(APP_OFFSET) $(APP_BIN)
UF2_ADD_BINARIES += $(APP_OFFSET) $(APP_BIN)
ifdef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
ifndef IS_BOOTLOADER_BUILD
# for locally signed secure boot image, add a signing step to get from unsigned app to signed app
APP_BIN_UNSIGNED := $(APP_BIN:.bin=-unsigned.bin)
$(APP_BIN): $(APP_BIN_UNSIGNED) $(SECURE_BOOT_SIGNING_KEY) $(SDKCONFIG_MAKEFILE)
$(ESPSECUREPY) sign_data --version $(SECURE_APPS_SIGNING_SCHEME) --keyfile $(SECURE_BOOT_SIGNING_KEY) -o $@ $<
endif
endif
# non-secure boot (or bootloader), both these files are the same
APP_BIN_UNSIGNED ?= $(APP_BIN)
$(APP_BIN_UNSIGNED): $(APP_ELF) $(ESPTOOLPY_SRC) | check_python_dependencies
ifeq ("$(CONFIG_APP_BUILD_GENERATE_BINARIES)","y")
$(ESPTOOLPY) elf2image $(ESPTOOL_FLASH_OPTIONS) $(ESPTOOL_ELF2IMAGE_OPTIONS) -o $@ $<
else
@echo "Skipping the BIN generation"
endif
ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
encrypted-flash: all_binaries $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
$(eval MONITOR_OPTS += --encrypted)
@echo "Flashing binaries to serial port '$(ESPPORT)' (app at offset $(APP_OFFSET))..."
ifdef CONFIG_SECURE_BOOT
@echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)"
endif
$(ESPTOOLPY_WRITE_FLASH_ENCRYPT) $(ESPTOOL_ALL_FLASH_ARGS)
else
encrypted-flash:
@echo "The command is supported only in FLASH ENCRYPTION DEVELOPMENT MODE"
@exit 1
endif
flash: all_binaries $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
@echo "Flashing binaries to serial port '$(ESPPORT)' (app at offset $(APP_OFFSET))..."
ifdef CONFIG_SECURE_BOOT
@echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)"
endif
$(ESPTOOLPY_WRITE_FLASH) $(ESPTOOL_ALL_FLASH_ARGS)
app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
@echo "Flashing app to serial port '$(ESPPORT)', offset $(APP_OFFSET)..."
$(ESPTOOLPY_WRITE_FLASH) $(APP_OFFSET) $(APP_BIN)
ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
encrypted-app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies
$(eval MONITOR_OPTS += --encrypted)
@echo "Flashing encrypted app binary to serial port '$(ESPPORT)' (app at offset $(APP_OFFSET))..."
$(ESPTOOLPY_WRITE_FLASH_ENCRYPT) $(APP_OFFSET) $(APP_BIN)
else
encrypted-app-flash:
@echo "The command is supported only in FLASH ENCRYPTION DEVELOPMENT MODE"
@exit 1
endif
# Submodules normally added in component.mk, but can be added
# at the project level as long as qualified path
COMPONENT_SUBMODULES += $(COMPONENT_PATH)/esptool
erase_flash: | check_python_dependencies
@echo "Erasing entire flash..."
$(ESPTOOLPY_SERIAL) erase_flash
MONITORBAUD ?= $(CONFIG_ESPTOOLPY_MONITOR_BAUD)
MONITOR_PYTHON := $(PYTHON)
ifeq ("$(OS)","Windows_NT")
# miniterm and idf_monitor both need a Windows Console PTY in order
# to correctly handle user input
MONITOR_PYTHON := winpty $(PYTHON)
endif
# note: if you want to run miniterm from command line, can simply run
# miniterm.py on the console. The '$(PYTHON) -m serial.tools.miniterm'
# is to allow for the $(PYTHON) variable overriding the python path.
simple_monitor: $(call prereq_if_explicit,%flash) | check_python_dependencies
$(MONITOR_PYTHON) -m serial.tools.miniterm --rts 0 --dtr 0 --raw '$(ESPPORT)' $(MONITORBAUD)
PRINT_FILTER ?=
MONITOR_CORE_DUMP_DECODE_ARG ?=
MONITOR_CORE_DUMP_DECODE = $(call dequote,$(CONFIG_ESP_COREDUMP_DECODE))
ifneq ("$(MONITOR_CORE_DUMP_DECODE)","")
MONITOR_CORE_DUMP_DECODE_ARG = --decode-coredumps $(MONITOR_CORE_DUMP_DECODE)
endif
MONITOR_OPTS := --baud $(MONITORBAUD) --port '$(ESPPORT)' --toolchain-prefix $(CONFIG_SDK_TOOLPREFIX) --make "$(MAKE)" --print_filter "$(PRINT_FILTER)" $(MONITOR_CORE_DUMP_DECODE_ARG)
monitor: $(call prereq_if_explicit,%flash) | check_python_dependencies
$(summary) MONITOR
[ -f $(APP_ELF) ] || echo "*** 'make monitor' target requires an app to be compiled and flashed first."
[ -f $(APP_ELF) ] || echo "*** Run 'make flash monitor' to build, flash and monitor"
[ -f $(APP_ELF) ] || echo "*** Or alternatively 'make simple_monitor' to view the serial port as-is."
[ -f $(APP_ELF) ] || exit 1
$(MONITOR_PYTHON) $(IDF_PATH)/tools/idf_monitor.py $(MONITOR_OPTS) $(APP_ELF)
# Make supports ESP32 only
UF2_CHIP_ID = "0x1c5f21b0"
uf2-app: $(APP_BIN) partition_table_get_info
$(PYTHON) $(IDF_PATH)/tools/mkuf2.py write \
-o "$(BUILD_DIR_BASE)/uf2-app.bin" \
--chip-id "$(UF2_CHIP_ID)" \
$(APP_OFFSET) $(APP_BIN)
uf2: all_binaries
$(PYTHON) $(IDF_PATH)/tools/mkuf2.py write \
-o "$(BUILD_DIR_BASE)/uf2.bin" \
--chip-id "$(UF2_CHIP_ID)" \
$(UF2_ADD_BINARIES)
.PHONY: erase_flash