platform-espressif8266: mkspiffs crashes when invoked with negative size parameter

As detailed in https://community.platformio.org/t/building-uploading-spiffs-fails-error-3/11160/6?u=maxgerhardt, for the platformio.ini:

[env:d1_mini_pro]
platform = espressif8266
board = d1_mini_pro
framework = arduino

and creating a data/ folder with one sample file inside it, the pio run -t uploadfs task will fail with a fatal error when creating the 14MB SPIFFS section, as dictated by the linker file,

"mkspiffs" -c data -p 256 -b 8192 -s -2121728 .pio\build\d1_mini_pro\spiffs.bin
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Because it cannot allocate -2121728 bytes. The error lies within the correction code for the SPIFFS_START and SPIFFS_END variables which is done in this code

https://github.com/platformio/platform-espressif8266/blob/b866c2952d4224f4e114e50144257acaf469839e/builder/main.py#L88-L111

The code transforms the original values

k = SPIFFS_START, value = 0x40400000
k = SPIFFS_END, value = 0x411fa000

to

SPIFFS_END is -0x6000
SPIFFS_START is 0x200000
Diff is -0x206000

thus yielding a negative length for the SPIFFS section. This error seems to occur for large 16MB / 128MBit flash chips. There might be other cases in which this correction logic is wrong?

When esptool flash starts at 0 as the comment says, why not subtract the start address of the flash, 0x40200000, from both addresses? I don’t understand the correction logic at the moment.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 13
  • Comments: 15

Most upvoted comments

I changed the bitmask from 0xFFFFFF to 0x1FFFFFF in %USERPROFILE%\.platformio\platforms\espressif8266\builder\main.py

     elif env[k] < 0x411FB000: 
         _value = env[k] & 0x1FFFFFF 

This issue is not SPIFFS specific, it happens with LittleFS as well and still exists, see https://github.com/platformio/platform-espressif8266/blob/master/builder/main.py#L92-L115

@valeros any chance to get that fixed soon?

Confirm that I also get this bug with d1 mini pro - 128mbit flash

Pretending the mini pro only has 64mbit of flash works board_build.ldscript = eagle.flash.8m7m.ld