Prebake vfs partition
Hello, I'm compiling micropython v1.18.0 in the port ESP32 with my scripts as frozen codes, but I need to store some data files (for example html files) in the vfs partition for scripts to work normally. I've tried to use rshell to copy the files after the firmware has been written in the flash, but it is slow and sometimes fails becuase the main program start to execute and then reset the board because it doesn't find the required files. So, there is a way to prebake (or prefilled) the vfs partition when the micropython firmware is built, so the firmware already has my scripts and the required data files?
Micropython fails to update the partition table when it creates a flash filesystem at boot
Port, board and/or hardware
MicroPython v1.27.0 on 2025-12-09; ESP32C3 module with ESP32C3 (ESP-ROM:esp32c3-api1-20210207 Build:Feb 7 2021)
MicroPython version
MicroPython v1.27.0 on 2025-12-09; ESP32C3 module with ESP32C3
Reproduction
- Erase flash
- Install MicroPython v1.27.0
- Boot the device into the Micropython REPL
- At this point, Micropython has created a littlefs filesystem in the unused flash space.
- Disconnect the device.
- Connect the device to https://thelastoutpostworkshop.github.io/ESPConnect/ or similar so you can inspect the flash partitions.
- Download the partition table and "unused" partitions. Inspect them with a binary editor.
- Note that the "unused" partition actually contains a littlefs filesystem, but that filesystem is not listed in the partition table. This is a bug.
Expected behaviour
The formerly unused flash partition should be listed in the partition table as containing a littlefs filesystem.
Observed behaviour
The partition table does not include the littlefs filesystem.
Additional Information
Maybe you consider the partition table to be unnecessary, since the MicroPython application knows about the filesystem and "owns" the entire device. But that seems risky to folks who use low-level tools to debug devices.
https://github.com/micropython/micropython/tree/master/ports/esp32#partition-table-and-filesystem-size has a relevant comment. It hints that it doesn't update the partition table when creating the filesystem. However, it doesn't say why:
Partition table and filesystem size
ESP32 firmware contains a bootloader, partition table and main application firmware, which are all stored in (external) SPI flash. The user filesystem is also stored in the same SPI flash. By default, MicroPython does not have a fixed entry in the ESP32 partition table for the filesystem. Instead it will automatically determine the size of the SPI flash upon boot, and then -- so long as there is no existing partition called "vfs" or "ffat" -- it will create a partition for the filesystem called "vfs" which takes all of the remaining flash between the end of the last defined partition up until the end of flash.This means that firmware built for, say, a 4MiB flash will work on any device that has at least 4MiB flash. The user "vfs" filesystem will then take up as much space as possible.
This auto-detection behaviour can be overridden: if the ESP32 partition table does contain an entry called "vfs" or "ffat" then these are used for the user filesystem and no automatic "vfs" partition is added. This is useful in cases where only the MicroPython ESP32 application is flashed to the device (and not the bootloader or partition table), eg when deploying .uf2 files.
The file https://github.com/micropython/micropython/blob/master/ports/esp32/esp32_partition.c contains esp32_partition_make_new(), which updates the partition table. However, it appears that MicroPython doesn't call that function when it creates a filesystem during initial boot. In fact, I can't find any evidence that esp32_partition_make_new() is ever called anywhere. That smells like a MicroPython bug to me.
Code of Conduct
Yes, I agree