diff --git a/README.md b/README.md index c01e314f11..f3007fdb88 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,12 @@ In both cases the factory app is flashed at offset 0x10000. If you `make partiti For more details about partition tables and how to create custom variations, view the `docs/partition-tables.rst` file. +# Erasing Flash + +The `make flash` target does not erase the entire flash contents. However it is sometimes useful to set the device back to a totally erased state, particularly when making partition table changes or OTA app updates. To erase the entire flash, run `make erase_flash`. + +This can be combined with other targets, ie `make erase_flash flash` will erase everything and then re-flash the new app, bootloader and partition table. + # Resources * The [docs directory of the esp-idf repository](docs) contains source of [esp-idf](http://esp-idf.readthedocs.io/) documentation. diff --git a/components/bootloader/Makefile.projbuild b/components/bootloader/Makefile.projbuild index 3f83803ad5..becb2003a8 100644 --- a/components/bootloader/Makefile.projbuild +++ b/components/bootloader/Makefile.projbuild @@ -43,7 +43,7 @@ bootloader: $(BOOTLOADER_BIN) ESPTOOL_ALL_FLASH_ARGS += $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN) -bootloader-flash: $(BOOTLOADER_BIN) +bootloader-flash: $(BOOTLOADER_BIN) | erase_flash $(ESPTOOLPY_WRITE_FLASH) 0x1000 $^ else ifdef CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH diff --git a/components/esptool_py/Makefile.projbuild b/components/esptool_py/Makefile.projbuild index 54221f1795..460fb64a0f 100644 --- a/components/esptool_py/Makefile.projbuild +++ b/components/esptool_py/Makefile.projbuild @@ -43,17 +43,22 @@ APP_BIN_UNSIGNED ?= $(APP_BIN) $(APP_BIN_UNSIGNED): $(APP_ELF) $(ESPTOOLPY_SRC) $(ESPTOOLPY) elf2image $(ESPTOOL_FLASH_OPTIONS) $(ESPTOOL_ELF2IMAGE_OPTIONS) -o $@ $< -flash: all_binaries $(ESPTOOLPY_SRC) +flash: all_binaries $(ESPTOOLPY_SRC) | erase_flash @echo "Flashing binaries to serial port $(ESPPORT) (app at offset $(CONFIG_APP_OFFSET))..." ifdef CONFIG_SECURE_BOOT_ENABLED @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) +app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) | erase_flash @echo "Flashing app to serial port $(ESPPORT), offset $(CONFIG_APP_OFFSET)..." $(ESPTOOLPY_WRITE_FLASH) $(CONFIG_APP_OFFSET) $(APP_BIN) # Submodules normally added in component.mk, but can be added # at the project level as long as qualified path COMPONENT_SUBMODULES += $(COMPONENT_PATH)/esptool + +.PHONY: erase_flash +erase_flash: + @echo "Erasing entire flash..." + $(ESPTOOLPY_SERIAL) erase_flash diff --git a/docs/partition-tables.rst b/docs/partition-tables.rst index 55b8870857..d45a540c66 100644 --- a/docs/partition-tables.rst +++ b/docs/partition-tables.rst @@ -125,5 +125,6 @@ Flashing the partition table A manual flashing command is also printed as part of ``make partition_table``. +Note that updating the partition table doesn't erase data that may have been stored according to the old partition table. You can use ``make erase_flash`` (or ``esptool.py erase_flash``) to erase the entire flash contents. .. _secure boot: security/secure-boot.rst diff --git a/make/project.mk b/make/project.mk index 0548002277..1ffda9baea 100644 --- a/make/project.mk +++ b/make/project.mk @@ -26,9 +26,10 @@ help: @echo "make defconfig - Set defaults for all new configuration options" @echo "" @echo "make all - Build app, bootloader, partition table" - @echo "make flash - Flash all components to a fresh chip" + @echo "make flash - Flash app, bootloader, partition table to a chip" @echo "make clean - Remove all build output" @echo "make size - Display the memory footprint of the app" + @echo "make erase_flash - Erase entire flash contents" @echo "" @echo "make app - Build just the app" @echo "make app-flash - Flash just the app"