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?
First build
the ESP32-SelfDestruct-Payload project and copy the firmware.bin
into the data
folder of this project. Rename firmware.bin
into stub.bin
.
Open the ESP32-SelfDestruct
project. Click on the PlatformIO Icon on the sidebar.
Under Platform
click first on Erase Flash
, then on Build Filesystem Image
and finally on Upload Filesystem Image
.
Now you can upload the Stage 1 Firmware on your ESP32. Under General
click on Upload and Monitor
.
The Self-destruction function gets triggered, if you connect a wire from GND
to PIN 32
. You can use a green and red LED to indicate the different stages.
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 - This Project
- Stage 2 - https://github.com/technopolistv/ESP32-SelfDestruct-Payload/
✍️ Blog: https://www.technopolis.tv/PlatformIO-Self-destructing-Arduino-ESP32-Firmware/