# One time flashing requires user to run esptool.py command themselves,
# and warning is printed about inability to reflash.
+#
+# The flashing command is deliberately printed without an auto-reset
+# step, so the device doesn't immediately reset to flash itself.
bootloader: $(BOOTLOADER_BIN)
@echo $(SEPARATOR)
@echo "Bootloader built. One-time flash command is:"
- @echo "$(ESPTOOLPY_WRITE_FLASH) $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)"
+ @echo "$(subst hard_reset,no_reset,$(ESPTOOLPY_WRITE_FLASH)) $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)"
@echo $(SEPARATOR)
@echo "* IMPORTANT: After first boot, BOOTLOADER CANNOT BE RE-FLASHED on same device"
default "8MB" if ESPTOOLPY_FLASHSIZE_8MB
default "16MB" if ESPTOOLPY_FLASHSIZE_16MB
+config ESPTOOLPY_FLASHSIZE_DETECT
+ bool "Detect flash size when flashing bootloader"
+ default y
+ help
+ If this option is set, 'make flash' targets will automatically detect
+ the flash size and update the bootloader image when flashing.
+
+choice ESPTOOLPY_BEFORE
+ prompt "Before flashing"
+ default ESPTOOLPY_BEFORE_RESET
+ help
+ Configure whether esptool.py should reset the ESP32 before flashing.
+
+ Automatic resetting depends on the RTS & DTR signals being
+ wired from the serial port to the ESP32. Most USB development
+ boards do this internally.
+
+ The "Reset with ESP32R0 Windows workaround" option works
+ around an automatic reset bug in hardware, when using Windows
+ with some development boards. This fix only works if you're
+ using a silicon revision 0 ESP32.
+
+config ESPTOOLPY_BEFORE_RESET
+ bool "Reset to bootloader"
+config ESPTOOLPY_BEFORE_NORESET
+ bool "No reset"
+config ESPTOOLPY_BEFORE_ESP32R0
+ bool "Reset with ESP32R0 Windows workaround"
+endchoice
+
+config ESPTOOLPY_BEFORE
+ string
+ default "default_reset" if ESPTOOLPY_BEFORE_RESET
+ default "no_reset" if ESPTOOLPY_BEFORE_NORESET
+ default "esp32r0" if ESPTOOLPY_BEFORE_ESP32R0
+
+choice ESPTOOLPY_AFTER
+ prompt "After flashing"
+ default ESPTOOLPY_AFTER_RESET
+ help
+ Configure whether esptool.py should reset the ESP32 after flashing.
+
+ Automatic resetting depends on the RTS & DTR signals being
+ wired from the serial port to the ESP32. Most USB development
+ boards do this internally.
+
+config ESPTOOLPY_AFTER_RESET
+ bool "Reset after flashing"
+config ESPTOOLPY_AFTER_NORESET
+ bool "Stay in bootloader"
+endchoice
+
+config ESPTOOLPY_AFTER
+ string
+ default "hard_reset" if ESPTOOLPY_AFTER_RESET
+ default "no_reset" if ESPTOOLPY_AFTER_NORESET
+
endmenu
#
ESPTOOLPY_SRC := $(COMPONENT_PATH)/esptool/esptool.py
ESPTOOLPY := $(PYTHON) $(ESPTOOLPY_SRC) --chip esp32
-ESPTOOLPY_SERIAL := $(ESPTOOLPY) --port $(ESPPORT) --baud $(ESPBAUD)
+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
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
ESPTOOL_ELF2IMAGE_OPTIONS :=
-ESPTOOLPY_WRITE_FLASH=$(ESPTOOLPY_SERIAL) write_flash $(if $(CONFIG_ESPTOOLPY_COMPRESSED),-z) $(ESPTOOL_FLASH_OPTIONS)
+ESPTOOLPY_WRITE_FLASH=$(ESPTOOLPY_SERIAL) write_flash $(if $(CONFIG_ESPTOOLPY_COMPRESSED),-z) $(ESPTOOL_WRITE_FLASH_OPTIONS)
ESPTOOL_ALL_FLASH_ARGS += $(CONFIG_APP_OFFSET) $(APP_BIN)