Просмотр исходного кода

Merge branch 'feature/erase_flash' into 'master'

Build system: Add `make erase_flash` target



See merge request !328

Ivan Grokhotkov 9 лет назад
Родитель
Сommit
a760eb3980

+ 6 - 0
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.

+ 1 - 1
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

+ 7 - 2
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

+ 1 - 0
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

+ 2 - 1
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"