Dynamically resizing SPIFFS partition to "largest possible"
Posted: Fri Aug 11, 2023 6:30 am
Hi! I'm a developer of an ESP32 ESP-IDF + Arduino project. Our project ships source or binaries (for user convenience) for a wide variety of configurations, including different Espressif parts, board configurations, and supported pinouts. The current issue is boards that differ only by flash memory sizes.
We're currently shipping multiple binaries and build configurations for different partition table configurations from various partition_table.csv files. This is inefficient and difficult to maintain. We'd like to be able to ship a single binary that can be dynamically updated on first boot or upon update to add or change partitions.
We propose to read the partition table at startup, stash the contents of SPIFFS, erase the sector containing the partition table, do the math to add crash and grow/change the filesystem tables to use all the storage, ]and then write the new partition table back to flash and restore it. The SPIFFS partition is always at the end, so growing it and adding a crashdump partition seems likely to work. We'd not change the partition tables if there were not all true. We're aware that this is a risky operation, but we're confident that we can make it safe by desk-checking the code path and regenerating the checksum, though we haven't yet found info on that.
Are there any best practices for safely adding or changing partitions? Is there a Partition Table Write API? Are there any other risks that we should be aware of?
We're currently shipping multiple binaries and build configurations for different partition table configurations from various partition_table.csv files. This is inefficient and difficult to maintain. We'd like to be able to ship a single binary that can be dynamically updated on first boot or upon update to add or change partitions.
We propose to read the partition table at startup, stash the contents of SPIFFS, erase the sector containing the partition table, do the math to add crash and grow/change the filesystem tables to use all the storage, ]and then write the new partition table back to flash and restore it. The SPIFFS partition is always at the end, so growing it and adding a crashdump partition seems likely to work. We'd not change the partition tables if there were not all true. We're aware that this is a risky operation, but we're confident that we can make it safe by desk-checking the code path and regenerating the checksum, though we haven't yet found info on that.
Are there any best practices for safely adding or changing partitions? Is there a Partition Table Write API? Are there any other risks that we should be aware of?