Making a file system on ESP32-WROOVR-32U flash

I am using an ESP32-WROOM-32U module with 16MB flash. I have been able to make a 12MG partition on the flash called fs_ext but I have been unable to mount a file system on it. The goal is to have a 12MB file system that survives OTA reflashes and reboots, so user data is preserved.

The partition was made with entries in mos.yml. Here is the partition table:

[Apr 13 23:04:26.809] e[0;32mI (65) boot: ## Label            Usage          Type ST Offset   Length   Flagse[0m
[Apr 13 23:04:26.809] e[0;32mI (73) boot:  0 nvs              WiFi data        01 02 00009000 00004000 00000000e[0m
[Apr 13 23:04:26.809] e[0;32mI (82) boot:  1 otadata          OTA data         01 00 0000d000 00002000 00000000e[0m
[Apr 13 23:04:26.820] e[0;32mI (90) boot:  2 app_0            OTA app          00 10 00010000 00180000 00000000e[0m
[Apr 13 23:04:26.825] e[0;32mI (98) boot:  3 fs_0             FS               01 82 00190000 00040000 00000000e[0m
[Apr 13 23:04:26.836] e[0;32mI (106) boot:  4 app_1            OTA app          00 11 001d0000 00180000 00000000e[0m
[Apr 13 23:04:26.842] e[0;32mI (115) boot:  5 fs_1             FS               01 82 00350000 00040000 00000000e[0m
[Apr 13 23:04:26.853] e[0;32mI (123) boot:  6 fs_ext           FS               01 82 00390000 00c00000 00000000e[0m
[Apr 13 23:04:26.859] e[0;32mI (131) boot: End of partition tablee[0m

Here are the entries I made in mos.yml to try and create the file system:

config_schema:
- ["fstab.fs_ext.dev", "data"]
- ["fstab.fs_ext.type", "LFS"]
- ["fstab.fs_ext.opts", '{"bs": 4096}']
- ["fstab.fs_ext.path", "/data"]
- ["fstab.fs_ext.create", true]

Here is the code I usd to test it:

  // Use POSIX and C standard library functions to work with files.
  // First create a file.
  LOG(LL_INFO, ("%s", "Opening file"));
  FILE* f = fopen("/data/hello.txt", "w");
  if (f == NULL)
  {
    LOG(LL_INFO, ("%s","Failed to open file for writing"));
    return;
  }
  fprintf(f, "Hello World!\n");
  fclose(f);
  LOG(LL_INFO, ("%s","File written"));

The code just fails to open the file. If someone could let me know what I messed up I would appreciate it, thanks…

Your config_schema for fstab is not correct.

  - ["fstab.fs0.dev", "fs_ext"]
  - ["fstab.fs0.type", "LFS"]
  - ["fstab.fs0.opts", '{"bs": 4096}']
  - ["fstab.fs0.path", "/data"]
  - ["fstab.fs0.create", true] 

Thanks @nliviu I have it working now. But, is there a way to make this partition and file system (and it’s contents) persist across reboots?

It persists between reboots, after OTA, but not after flash.

Okay thanks again, I’ll keep testing. I appreciate your help.

How are you getting the 12MB partition?

I have

build_vars:
  ESP_IDF_EXTRA_PARTITION: data,data,spiffs,,400K

config_schema:
  - ["fstab.fs0.dev", "data"]
  - ["fstab.fs0.type", "LFS"]
  - ["fstab.fs0.opts", '{"bs": 4096}']
  - ["fstab.fs0.path", "/mnt"]
  - ["fstab.fs0.create", true]

which works fine, although whenever I try to change 400K to something larger the build fails, including 12288K

You need to inform esp-idf that you have a 16MB flash

build_vars:
  ESP_IDF_SDKCONFIG_OPTS: >
    ${build_vars.ESP_IDF_SDKCONFIG_OPTS} 
      CONFIG_ESPTOOLPY_FLASHSIZE_4MB=
      CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
      CONFIG_ESPTOOLPY_FLASHSIZE=16MB
  ESP_IDF_EXTRA_PARTITION: fs_ext,data,spiffs,,12288K

config_schema:
 - ["fstab.fs0.dev", "fs_ext"]
 - ["fstab.fs0.type", "LFS"]
 - ["fstab.fs0.opts", '{"bs": 4096}']
 - ["fstab.fs0.path", "/data"]
 - ["fstab.fs0.create", true]

This worked for me some time ago.

And don’t forget to add the lfs and fstab libraries:

  - location: https://github.com/mongoose-os-libs/fstab
  - location: https://github.com/mongoose-os-libs/vfs-fs-lfs

awesome thx! got it

I also tried to set the standard file system to be larger, as here, although that didn’t seem to work…

Another example