Customizing ESP32 flash partitions table

Let's start with a little on the ESP32 partitions. If you have worked with the ESP8266 before, you already know that ESP8266 flash required files such as boot.bin, user1.bin and blank.bin, etc. All of them were stored in specific locations depending on the flash memory size. The locations and size of the BINs could be set in the LD (linker script) files.

This has changed and become a litle more convenient in the ESP32. You can now change the offsets and locations of your flash partitions using the menuconfig, which can be accessed using $make menuconfig command.

When to edit partition table?

You will have to edit the partition table when your app tends to exceed the maximum size of the default ESP-IDF partition sizes. For example, in the single non-OTA factory app configuration mode, the partition table allows the user app to take up 1MB of flash space, starting from 0x10000.

What if you have an application that takes up more than 1MB of space? One such example is the IoTBits AudioBit driver example code, which contains audio data of about 1MB. If you try to run an app of >1MB, you will get the following error:

(1693) esp_image: Image length 1291856 doesn't fit in partition length 1048576
(1710) boot: Factory app partition is not bootable
(1727) boot: No bootable app partitions in the partition table

So how do you increase a partition size to fit in a larger app BIN?

Editing ESP32 partitions table

You can edit the partition table by changing into your project directory and running menuconfig using

$ make menuconfig

When into menuconfig, select

Partition Table --> Custom partition table CSV

Specify partitions.csv as the partitions CSV and leave app offset unchanged if you have no good reason to change it:

ESP32 partitions table edit CSV

Make sure to save this new sdkconfig before your exit menuconfig.

We are using the AudioBit driver code, which stores a lot of audio data for digital audio playback and the app BIN needs over 1MB space in the flash.

We will now extend the app partition size by specifiying our needs in the partitions.csv file. Start from using the default partitions CSV for the ESP-IDF. Attached below is the partitions CSV for ESP-IDF 3:

ESP32 flash partition CSV (default 4MB flash with ESP-IDF 3)

Opening the CSV file in notepad will tell you what is fairly obvious:

esp32 partitions CSV

So we have the factor app partitions which starts at 0x10000 and is of 1M size. You can now edit that and also add new partitions if you need to.

We made it 2M for the AudioBit driver application because that would easily fit in the code and audio data as well. This partition.csv file should then be saved in the project directory. After that, you may use

$ make

as always to compile your project and generate the BIN files for flashing on to ESP32.
Surely, you could go around storing data in a separate partition (which would make sense in OTA type firmware if your data does not need to change).

 

Learnt something new?

Did the above article help? Please SUBSCRIBE to our blog for more articles like this!
Stuck developing ESP8266 or ESP32 hardware/firmware? We can help you out! Feel free to contact us for consulting help.

Leave a Reply