ESP32forth: transfering files to and from the SPIFFS partition
esp32forth esp32 spiffsOne of the things that annoyed me when using ESP32forth is that with recent versions of the ArduinoIDE (2.x) it is no longer possible to use plugins for uploading additional files to the SPIFFS partition of the ESP32.
There is a workaround solution for ESP32forth that allows a user to copy-paste code into the terminal, which is then stored on the filesystem - but that didn’t convince me.
So I spent the last two days tinkering with mkspiffs and esptool.py and finally found a way to not only upload files to the SPIFFS partition but also for dumping files from that partition back to your computer. All from the command line, no ArduinoIDE and plugins required (see below).
The procedure described below also has the advantage of allowing the transfer of binary files (e.g. a bitmap image) to and from the SPIFFS filesystem. I have successfully tested this with the 7.0.7.21 version of ESP32forth as well as with the ESP32forthStation image.
Prerequisites:
Install esptool.py (usually available via your Linux / BSD package manager)
Get mkspiffs ( https://github.com/igrr/mkspiffs.git )
-
In file include/spiffs_config.h on line 181 set SPIFFS_OBJ_META_LEN to 4:
#define SPIFFS_OBJ_META_LEN (4)
-
compile mkspiffs and install it in your $PATH (e.g. /usr/local/bin).
(Optional) Get gen_esp32part.py Python script:
https://github.com/espressif/esp-idf/blob/master/components/partition_table/gen_esp32part.py
(Optional) Dump ESP32 partition information:
- esptool.py –port /dev/<ESP32_serial_device> read_flash 0x8000 0xc00 ptable.img
- gen_esp32part.py ptable.img
Build SPIFFS image and flash to ESP32:
This procedure will first create a SPIFFS file system image spiffs.bin, containing all the files that are located in <some_directory> and then flash that image to the ESP32 SPIFFS partition. Here are the commands:
- mkspiffs -c <some_directory> -b 4096 -p 256 -s 0x1e0000 spiffs.bin
- esptool.py --port /dev/<ESP32_serial_device> --chip esp32 write_flash -z 0x210000 spiffs.bin
Dump SPIFFS partition from ESP32 to disk:
This procedure will dump the contents of the SPIFFS partition from the ESP32 to an image file data.img and then extract the individual files from that image to <some_directory>. Here are the commands:
- esptool.py --port /dev/<ESP32_serial_device> --baud 921600 read_flash 0x210000 0x1e0000 data.img
- mkspiffs -u <some_directory> data.img