Building & Uploading SPIFFS fails Error 3

Hey,
iam having some troubles uploading my spiffs image.

Its a plain html file inside the data dir.

terminate called after throwing an instance of 'std::bad_alloc'
what():  std::bad_alloc
*** [.pio\build\d1_mini_pro\spiffs.bin] Error 3

runing the task in verbose mode tells me that it trys to run mkspiffs with the argument -s beeing a negative number

"mkspiffs" -c data -p 256 -b 8192 -s -2121728 .pio\build\d1_mini_pro\spiffs.bin

my platformio.ini
[env:d1_mini_pro]
platform = espressif8266
board = d1_mini_pro
build_flags = -Wl,-Teagle.flash.16m14m.ld
framework = arduino
monitor_speed = 115200

Can you upload your project to github for reproduction?

its just a plain hello world targeting the d1 mini pro. When i use the standart d1 mini upload is just fine

Not quiet sure why you’d need this because the d1_mini_pro.json already defines the right linker script

But I’ll look into it. Maybe it has a signed overflow when trying to compute the size.

1 Like

i had this in the cfg because it used the 4mb flash for the chip. Also you highlighted the d1 mini, iam using the d1 mini pro

The above link is to the d1_mini_pro.json. The used variant is the same (pinout), but flash sizes are different.

The related python commands are

But the “SPIFFS_END” value overflows a 32-bit integer, so if you print the values using

def __fetch_spiffs_size(target, source, env):
    fetch_spiffs_size(env)
    print("SPIFFS_END is " + hex(env["SPIFFS_END"]))
    print("SPIFFS_START is " + hex(env["SPIFFS_START"]))
    print("Diff is " + hex( env["SPIFFS_END"] - env["SPIFFS_START"]))

    return (target, source)

you get

SPIFFS_END is -0x6000
SPIFFS_START is 0x200000
Diff is -0x206000
"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

Further debugging pins the problem down in fetch_spiffs_size()

    # esptool flash starts from 0
    for k in ("SPIFFS_START", "SPIFFS_END"):
        print("k = %s, value = %s" % (k, hex(env[k])))
        _value = 0
        if env[k] < 0x40300000:
            _value = env[k] & 0xFFFFF
        elif env[k] < 0x411FB000:
            _value = env[k] & 0xFFFFFF
            _value -= 0x200000  # correction
        else:
            _value = env[k] & 0xFFFFFF
            _value += 0xE00000  # correction

        env[k] = _value

Seems to give the correct values

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

(segment as approx 14MB long as linkerfile says)

But are then the SPIFFS_END value seems to be wrongly corrected for the esptool program to (0x411fa000 & 0xFFFFFF) - 0x200000 = -0x6000

So I really have no idea where the magic numbers and corrections above are coming from except for that the SPI flash starts at 0x40200000 in the memory map.

@ivankravets @valeros This looks like a bug in the esp8266 main.py for large 16MB flash chips, please have a look. What doesn’t simply

env[k] = env[k] - 0x40200000

work? That does produce the correct commandline "mkspiffs" -c data -p 256 -b 8192 -s 14655488 .pio\build\d1_mini_pro\spiffs.bin and doesn’t crash anymore

1 Like

I get the same error attempting to upload to a d1_mini_pro but loads if I set the board to d1_mini. Any fixes available yet?

Issue mkspiffs crashes when invoked with negative size parameter · Issue #190 · platformio/platform-espressif8266 · GitHub was created, awaiting response.

1 Like

Thanks. I don’t understand the address calculation logic either.

has this bug appeared again or just never been solved? im building for wemos d1 mini pro with this platformio.ini

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:d1_mini_pro]
platform = espressif8266
board = d1_mini_pro
framework = arduino
monitor_speed = 115200
board_build.filesystem = littlefs

when i run

platformio run --target buildfs --environment d1_mini_pro --verbose

it runs the command

"mklittlefs" -c data -p 256 -b 8192 -s -2121728 .pio/build/d1_mini_pro/littlefs.bin

which produces a 4GB image!

i was looking at the dates of this thread and its from four years ago and i was puzzled that this is still an issue?

is there a workaround? my wemos has 16M flash.

Having exactly the same problem with the D1 mini pro. It generates an image of 4GB!!