OldBikerPete wrote:Great. Thank you for the answers.
Responding to answers in the order they were given.
if I do esptool.py erase_flash, will it erase ALL the flash, including the Arduino bootloader?
But the D1 mini has 1024Kb program flash. Where will the WiFi config be stored in that case? Still in the last 0x4000 bytes of program flash? IE at address 0xFc000 ? What sector number would that be?
Yes, erase_flash will blow away the entire flash.
The esp8266 SDK (which the arduino framework is based on, will always write its own configuration to the last 0x4000 of the actual flash chip itself. (Wifi config starts at 0x2000 before the end.) However, it doesn't actually calculate the flash chip size and then subtract 0x4000. Instead it reads a certain location on the flash where the size itself has been written. If this hasn't been written it assumes it's a 512KB flash, and therefore the location is 0x7c000-0x7ffff.
So, if the D1-mini flash has been properly prepared as a 4MB flash (all my d1-minis are 4MB) the location will be 0x3fc000-0x3fc000.
If you don't want to completely erase the flash, what I'd do is read the most likely locations using esptool.py:
esptool.py read_flash 0x7c000 0x4000 flash.bin
And then use hexedit (on linux, something else on windows) to look inside flash.bin and see if it's the right location. Remember wifi starts at 0x2000 in.
The most likely locations for SDK info are 0x7c000, 0xfc000 and 0x3fc000. (Or 0x7e000, 0xfe000, 0x3fe000 for the wifi stuff specifically.)
As the other poster says you can then clear this with spi_flash_erase_sector(location / 0x1000); (This erases a sector, so 0x1000 bytes.)
esp8266 otb-iot documentation - https://otb-iot.readthedocs.io/
esp8266 related blog - http://www.packom.net/