ESP32

ESP32: how to read and write the partition table of an ESP device?

Written by

in

To communicate with an ESP32 the ESP-IDF (Espressif IoT Development Framework) can be used. This framework provides a collection of useful scripts to communicate with your ESP device. The framework is supported on Windows, Linux and macOS.

You can download the ESP-IDF repository and extract the contents into a folder.

Note that you need to have Python 3 installed. For example by using brew install python on macOS. In addition, the esptool library is required by running pip install esptool in your terminal.

Reading the Partition Table

The partition table is located at 0x8000 (32768) on older, and on 0x9000 (36384) on newer systems. Its length is always 0xc00 (3072) bytes.

With the esptool.py, this can be read out, for example by the command

python $(IDF_PATH)/components/esptool_py/esptool/esptool.py read_flash 0x9000 0xc00 partitions.img

To create a “human” readable csv file, you can use the gen_esp32part.py tool:

python $(IDF_PATH)/components/partition_table/gen_esp32part.py partitions.img > partitions.csv

In my case, the partition table looks as follows:

preview of the ptable.csv file

Writing the Partition Table

When using an IDE like PlatformIO, the flashing of the partition table is part of the build process. For this, just add the following line to your platformio.ini:

board_build.partitions = partitions.csv

The Manual Way

First, you have to generate the partition table binaries. This can be done with idf.py:

python $(IDF_PATH)/components/partition_table/gen_esp32part.py partitions.csv partitions.bin

After this you can use esptool.py (which we already used for reading) for writing:

python $(IDF_PATH)/components/esptool_py/esptool/esptool.py write_flash -z 0x9000 partitions.bin

More details about Partition Tables, how to create custom tables, handle different partition types and the flashing precedure are listed on the official Espressif documentation.

Foto von Vishnu Mohanan auf Unsplash


Comments

3 responses to “ESP32: how to read and write the partition table of an ESP device?”

  1. HI Mathias, your title is “ESP32: how to READ and WRITE the partition table of an ESP device?” but you only explain how to READ!!!! Have you fallen asleep during the writing of this long article?

    1. Mathias Lipowski Avatar
      Mathias Lipowski

      I updated the post. No, I didn’t fall asleep 😉 The write process was just not that spectacular when using PlatformIO as IDE. In this case, everything was less complicated.

  2. You did the read, where is the write?

Leave a Reply

Your email address will not be published. Required fields are marked *