SPIFFS and ESP-07: Data corruption


Since some time (platformio 4), I experience errors when uploading SPIFFS image (pio run --target uploadfs) to ESP-07. However, SPIFFS files seem to be readable by the ESP application (at least some small files). But when writing to SPIFFS from the application the file is corrupted.

The problem occures with all my ESP-07 (=1MB flash size), but not with other modules (ESP12 / standard Wemos D1 Mini (4MB flash size)).

Has anyone experienced similar problems?

Possible causes could be:

  • The complete batch of my ESP-07 has a broken flash (real flash size < 1 MB).
  • There is a regression in the SPIFFS filesystem sources that corrupt data when writing to small SPIFFS partition (=64KB)
  • There is something wrong with the linker scripts. (That’s why I ask here in the platformio forum)

Some details:

pio run --target=uploadfs:

Configuring flash size...
Auto-detected Flash size: 1MB
Compressed 65536 bytes to 185...
Wrote 65536 bytes (185 compressed) at 0x000eb000 in 0.0 seconds (effective 25971.4 kbit/s)...

A fatal error occurred: Timed out waiting for packet header
*** [uploadfs] Error 2

–> After this, the SPIFFS file are readable. However, they are very small (two config files less < 1KB) and I haven’t tested larger files yet.

For testing writing to SPIFFS I use a very simple function:

const char *filename = "/config.txt";

void testSPIFFSWrite() {
  File file = SPIFFS.open(filename, "w");
  if (!file) {

After this, the SPIFFS file is corrupted and reading it (immediatly after writing or after reset) results in reading many 0-Bytes. Other files on SPIFFS (that were uploaded by platformio) are still readable.

So I think the wear leveling function of SPIFFS writes to a locations that is somehow invalid.

My immediate thought on this is it’s probably a question worth asking on the esp8266/Arduino issue tracker also, as PlatformIO uses their linker scripts, etc… so it’s just as likely it’s a regression introduced with the recent SPIFFs/LittleFS changes as some incompatibility with PlatformIO. Have you tried reverting to an earlier espressif8266 platform to see if it’s related to a specific version of the core?

What is the exact platformio.ini? Do you set a custom linker script?

I used:

build_flags = -Wl,-Teagle.flash.1m64.ld

and I also tried

build_flags = -Wl,-Teagle.flash.512k32.ld

Interestingly, if I set the flash size to 512k32.ld the SPIFFs FSInfo still shows a available file system size auf around 56kb.

Complete platformio.ini:

platform = espressif8266
board = esp07
framework = arduino
build_flags = -Wl,-Teagle.flash.1m64.ld
#build_flags = -Wl,-Teagle.flash.512k32.ld

I opened an issue at esp8266/Arduino: SPIFFS Data corruption with ESP-07 (1 MB flash size) · Issue #6641 · esp8266/Arduino · GitHub

1 Like

It looks like you also got some bites from the regulars there… so there is hope :slight_smile: Thanks for the update! :wink:

It seems that using latest git of Arduino Core for ESP8266 solves this issue for me (see SPIFFS Data corruption with ESP-07 (1 MB flash size) · Issue #6641 · esp8266/Arduino · GitHub).

That brings me to the question, how can I use latest framework from git with platformio?

Using platform = https://github.com/platformio/platform-espressif8266.git is not sufficient?

This is documented as a platform_packages example: Redirecting...


Thanks. So, writing to SPIFFS work fine now.

However, there is still the error when uploading SPIFFS (pio -t uploadfs)

The uploaded file still can be read, but I think there is something wrong with flash?!

Can or cannot be read? What’s the output?

There is an error message (time-out while validating), but the file in SPIFFS can be read.

But I did not tried larger files yet.