How is ESP flash memory laid out/used

I’ve been messing around with some functions that write to the file system and have run out of memory. I’ve been trying to work out if there is some option available to extend the available memory in ‘/’, and am a little lost.

This I’ve read:


  • I’ve seen RAM which gets use during device operation, again I don’t understand how this is allocated or where its defined.

  • When I build my app with verbose logging I see the commands of interest:

Generating esp32.project.ld
LD /home/Code/mongoose/build/objs/mongoose.elf v3.0
    App size: 1074192 of 1572864 (68%)
  • So I guess this tells me I have some room in the app area
MKFS  /usr/local/bin/mkspiffs8 262144 {bs:4096,ps:256,es:4096} /home/Code/mongoose/build/objs/fs -> /home/Code/mongoose/build/objs/fw_temp/fs.img
FS params: size=262144, bs=4096, ps=256, es=4096
       Adding abc.dif
       . (lots of stuff)
       Adding ca.pem: 31787\
     FS stats : space total=233681, used=172939, free=60742
  • And this tells me the place I write stuff to is mostly used up already.

I guess I want to know if there is any “free” memory that I can somehow add to this MKFS command that is run during build so I can have more memory available in ‘/’

Maybe this can help.

ESP32 flash layout. The variables are defined here.

Exactly what I was looking for, thanks @nliviu!

Couple of things that still confuse me:

  1. Why is there ‘spare memory’ by default on ESP32? Here you mention in that post the maximum fs_* size is MGOS_ROOT_FS_SIZE=458752. Why would this not be the default?
  2. What is the impact of adjusting these variables on OTA-able firmware? I’ve reduced APP_SLOT_SIZE and increased MGOS_ROOT_FS_SIZE in increments of 4096 and built new firmware, but I’m not able to OTA
* Done waiting for 100-continue
* Mark bundle as not supporting multiuse
< HTTP/1.1 500 Internal Server Error
< Server: Mongoose/6.18
< Content-Type: text/plain
< Connection: close
-1 File is too big

* we are done reading and this is set to close, stop send
* Closing connection 0

That was the developers’ decision.

After adjusting these variables one needs to flash the new firmware. OTA update cannot change the flash memory layout.

Ouch. Wish I had discovered that a little while back. Thanks for confirming @nliviu

I guess maybe I could try do some bs with RPC commands to create FS on my remote devices, then package up OTA like I saw here. Might give it a shot