ESP_EERPOM - what happens if the device loses power while writing?

For the ESP_EEPROM library, if an ESP8266 loses power during a commit() operation, what is the state of the information stored in flash?

Presumably in the case where the entire sector is being erased, a power loss during erase most likely results in a garbage state that may be hard to detect.

My reading of the code is that the new data is written to the flash, then the bitmap index is updated. So, if the power is lost while the new data is being written, the index will still point to the previous valid data. If power is lost while writing the bitmap (index), that could result in a garbage index, making it impossible (or at least difficult) to tell where the last valid data is stored.

Is this a correct analysis?

It appears that spiffs is not safe if power is lost at a bad time · Issue #1868 · nodemcu/nodemcu-firmware · GitHub

Let's face it, no form of storage is immune from problems if power is lost unexpectedly

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.