How to generate SPIFFS image externally?

#1

Hello,

We would like to generate spiffs image for ESP8266 out of mos build. We tried to use spiffsgen.py from ESP-IDF and https://github.com/igrr/mkspiffs but in both casess mount failed.

We need it for device manufacturing - firmware will be the same for every device but filesystem must differ (will contain diffrent keys and configuration). How can we achieve that?

Thanks in advance.

1 Like
#2

We have managed it with following command:

docker run -v $(pwd):/mnt/data -t mgos/esp8266-build:2.2.1-1.5.0-r4 mkspiffs -s 262144 /mnt/data/fs -f /mnt/data/fs.bin

Is this the correct approach? I am asking because I think it is common to build firmware and filesystem separatley (exclusively) in the production. Please correct me if I am wrong.

#3

@Martin_Zdila, Could I ask you how do you flash/mount externally generated filesystem image? I am also working with ESP8266 and found guide only for ESP32
Here is my assumption - is it correct:

  1. mkspiffs used to generate the image
  2. esptool write_flash 0x300000 to flash filesystem image
  3. mos mount - to mount the image

In my case the above steps do not work:

python spiffsgen.py --page-size 128 0x40000 data data.img

esptool --port COM7 --baud 921600 write_flash 0x300000 data.img

mos call FS.Mount '{"path":"/http","dev_name":"sfl0","dev_type":"sysflash","fs_type":"SPIFFS","fs_opts":"{\"addr\":3145728,\"size\":262144‬,\"bs\":4096,\"ps\":128,\"es\":4096}"}'
Error: /go/src/github.com/mongoose-os/mos/mos/dev/dev_conn_impl.go:171: remote error 500: mount failed

Thanks a loot for response

#4

Try \"offset\":3145728 instead of \"addr\":3145728.

#5

Here is a working example using auto mount (ESP8266):

  • add the files in extra-fs
  • create the image: docker run -v $(pwd):$(pwd) -t mgos/esp8266-build:2.2.1-1.5.0-r5 mkspiffs -s 262144 -p 128 $(pwd)/extra-fs -f $(pwd)/extra.bin (Thank you @Martin_Zdila )
  • copy the image in the sources: directory.
  • add in mos.yml
config_schema:
  - ["devtab.dev0.name", "data"]
  - ["devtab.dev0.type", "part"]
  - ["devtab.dev0.opts", '{"dev": "sfl0", "offset": 0x300000, "size": 0x40000}']
  - ["fstab.fs0.dev", "data"]
  - ["fstab.fs0.type", "SPIFFS"]
  - ["fstab.fs0.opts", '{"bs": 4096, "ps": 128, "es": 4096}']
  - ["fstab.fs0.path", "/html"]
  - ["fstab.fs0.created", true]

libs:
# other libs
  - origin: https://github.com/mongoose-os-libs/vfs-dev-part
  - origin: https://github.com/mongoose-os-libs/fstab
    

build_vars:
  APP_EXTRA_FW_PARTS: fs_data:type=fs,src=src/extra.bin,addr=0x300000
  • build and flash

Output:

mgos_vfs_dev.c:73       data: part ({"dev": "sfl0", "offset": 0x300000, "size": 0x40000}), size 262144
mgos_vfs.c:147          /html: SPIFFS @ data, opts {"bs": 4096, "ps": 128, "es": 4096}
mgos_vfs.c:320          /html: size 236529, used: 3198, free: 233331