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.