Upload file system to a specific spiffs partition

If there is only one spiffs partition, then the ‘PlatformIO: Upload File System Image’ task automatically finds this partition and uploads the file system to it. But if there is more than one spiffs partition, which one will it use? Is there a way to control which one PlatformIO will flash the file system to?

In case it matters, I am using PlatformIO within Visual Studio Code, and my project is based on an ESP32.

By examining the terminal output when I run the upload file system image task, I noticed that it is calling esptool.py. I was able to run this tool manually from the terminal, and learned that I can pick which partition it uploads to by specifying the partition’s starting address. However, it would be much more convenient if there was an option in platformio.ini to specify the partition label, and have it automatically upload to that partition when I click ‘Upload File System Image’. Does this exist already?

Can you share a minimal PlatformIO project which has 2 SPIFFS partitions? Have you modified any linker settings for that? What command are you using to upload the second SPIFFS?

I didn’t have to modify any linker settings. I just created a new project with the following selections in the project wizard:
Board: Espressif ESP32 Dev Module
Framework: Arduino

I created a file named custom_partition.csv in the root folder of the project with the following contents (I have an 8MB flash chip):

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
app0,     app,  ota_0,   0x10000, 0x330000,
app1,     app,  ota_1,   0x340000,0x330000,
spiffs,   data, spiffs,  0x670000,0xC8000,
spiffs2,   data, spiffs,  0x738000,0xC8000,

My platformio.ini settings are pretty simple too:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
upload_port = COM12
board_build.partitions = partitions_custom.csv

To upload the contents of my ./data folder, I use two commands.
1) To package the contents into a spiffs.bin file:

c:\users\<username>\.platformio\packages\tool-mkspiffs\mkspiffs_espressif32_arduino.exe -c data -p 256 -b 4096 -s 819200 .pio\build\esp32dev\spiffs.bin"

2a) To upload the spiffs.bin file to the first spiffs partition:

python.exe "C:\Users\<username>\.platformio\packages\tool-esptoolpy\esptool.py" --chip esp32 --port <COM_PORT> --baud 460800 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_size detect 6750208 .pio\build\esp32dev\spiffs.bin

2b) To upload the spiffs.bin file to the second spiffs partition:

python.exe "C:\Users\<username>\.platformio\packages\tool-esptoolpy\esptool.py" --chip esp32 --port <COM_PORT> --baud 460800 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_size detect 7569408 .pio\build\esp32dev\spiffs.bin

Note that I’ve blanked-out the username and COM port number that I’m using. The only difference between the last two commands (2a vs. 2b) is the address of the partition (6750208 vs. 7569408).

I can mount both partitions at the same time using esp_vfs_spiffs_register, passing in the label of each partition and a unique base path for each. I’ve uploaded different files to each partition, and read back the contents using a modified version of the Arduino SPIFFS library to confirm that each partition received the correct data.

It’s just painful to have to manually convert each partition size and address to decimal and enter those commands into the terminal each time I want to flash data into the spiffs partitions. It would be great if there was a configuration option in platformio.ini that allowed me to map each data folder to a partition label. That way I could simply select ‘Upload file system image’ and let PlatformIO sort out the background details.

I see. I think it would be best to duplicate this info in a new feature-request issue on GitHub - platformio/platform-espressif32: Espressif 32: development platform for PlatformIO, as multi-SPIFFS partition tables don’t seem a usecase that works with PIO by default.

Because as the code is written now

It will just fetch the last valid SPIFFS partition it found while iterating through all of the partition table entries.

2 Likes

Ok, thanks for confirming that this is not yet supported. I’ll make a feature request as you suggested.

1 Like

I submitted a new feature request here:
https://github.com/platformio/platform-espressif32/issues/331

1 Like