Is it possible to erase the firmware of an ESP32 from within itself? Let's try to find out.
If you want to erase the ESP32's flash content, the easiest way would be using esptool.py
with the erase_flash
parameter. But how we can do this from within the running Arduino Sketch?
Open the ESP32-SelfDestruct-Payload
project. Click on the PlatformIO Icon on the sidebar. Under General
click on Build
.
Copy the firmware.bin
file under the folder .pio/build/{BOARD}/firmware.bin
into the data
folder of the ESP32-SelfDestruct project.
Do not upload this code to your ESP32! Just build the project and move the firmware.bin
into the data
folder of the ESP32-SelfDestruct
project and read the instructions.
The green part highlights the main firmware (Stage 1) and the red part the stub firmware (Stage 2).
Offset | Before Update | After Update | After Erase |
---|---|---|---|
0x9000 | NVS (Data) | NVS (Data) | NVS (Empty) |
0xe000 | OTA |
OTA | OTA (Empty) |
0x10000 | APP0 (Firmware) | APP0 (Firmware disabled) | APP0 (Empty) |
0x150000 | APP1 (Empty) | APP1 (Stub Firmware actived) | APP1 (Stub Firmware) |
0x290000 | SPIFFS (Stub Firmware) | SPIFFS (Stub Firmware) | SPIFFS (Empty) |
- Stage 1 - https://github.com/technopolistv/ESP32-SelfDestruct/
- Stage 2 - This Project
✍️ Blog: https://www.technopolis.tv/PlatformIO-Self-destructing-Arduino-ESP32-Firmware/