Page 1 of 1

How to erase the application directly from... itself?

Posted: Tue Nov 26, 2019 10:18 am
by delamoure
Hi there.
Friends, can anybody advice me how to do the application that is able to erase itself in the ESP32-WROOM-32 flash memory, or (and this is better) can bring the ESP32-WROOM-32 to the its default factory state.
I don't ask for a solution, but asking for the advice how is better to do that. And is it possible at all?

Re: How to erase the application directly from... itself?

Posted: Wed Nov 27, 2019 7:56 am
by ESP_Sprite
That's a bit of a strange question; what's your end goal with this?

Re: How to erase the application directly from... itself?

Posted: Wed Nov 27, 2019 9:06 am
by delamoure
Why is strange? The goal of this is quite simple.
On some assembled devices I run my own test software. But my customer wants to get the devices (esp32 firmware) in the state like "from factory".
I don't want to disassemble all mechanical parts and erase esp32 by pc connection, because is better to push some key and erase all to the initial state using my firmware. And also don't want to discuss with my customer.
Seems like SPI Flash API is enough for this task. Am I right?

Re: How to erase the application directly from... itself?

Posted: Thu Nov 28, 2019 4:36 am
by ESP_Sprite
Well, it's a bit strange that your customers insist on a certain firmware in the flash, especially because 'from the factory' code isn't always useful or up-to-date. Anyway, you could try to use the SPI flash routines, but note that there is a pretty large chance that will fail: the ESP32 executes code directly from flash (via XIP) and erasing the flash would erase your running program as well. You can try to work around this by putting relevant routines in IRAM instead, but I'm not sure if it's possible to put enough code in IRAM to do what you need to do.

Re: How to erase the application directly from... itself?

Posted: Thu Nov 28, 2019 8:50 am
by delamoure
Can you please tell me, Core 0 is APP_CPU or PRO_CPU?

Re: How to erase the application directly from... itself?

Posted: Thu Nov 28, 2019 9:10 am
by WiFive
Flash erase commands are already in iram and chip erase is a single command so I don't see why not. It doesn't get you back to factory firmware though. Also doesn't really make sense that the customer will then have to disassemble the devices to flash them.

Re: How to erase the application directly from... itself?

Posted: Thu Nov 28, 2019 11:55 am
by chegewara
Maybe its some misunderstanding here, what exactly "factory reset" means? Is it reset to state esp32 module is leaving factory or your device is leaving factory and is sent to client?

Re: How to erase the application directly from... itself?

Posted: Thu Nov 28, 2019 12:02 pm
by delamoure
The buffers are disabled for both cores. Interrupts also disabled. I working from IRAM now. Most of all I'll try to easy write to the SPI via registers. Because spi_flash functions are not working now for some reason. As for customers... When we have "stupid" task we have to do it like any other task. Thanks alot for answers :)

p.s. Now the task is to erase application in the ESP32 flash.