[ESP32] [Partition Table]

When compiling the ESP32 project, the build was successful, but the following problems were encountered while downloading:

After the instructions of the great god, it was found that the compiled bootloader.bin was too large: the newly compiled bootloader.bin 29K. The default download address is:

0x1000: bootloader.bin
0x8000: partition-table.bin
0x10000: user.bin

Calculate 0x8000-0x1000 = 0x7000 = 7 * 16 ^ 3 = 28672 <29K = 29000.
Solution:
idf.py menuconfig-> Bootloader config-> Bootloader log verbosity —> No output
recompile, the size of bootloader.bin is reduced to 20K, the download is successful.


Take this opportunity to learn under ESP32 the partition table .

ESP32 requires an external flash to configure and store user code. Take the GD25Q32C used on the official website ESP32-WROVER-B module as an example: 32Mbit / 4MB, its sector structure is as follows:

a total of 1024 sectors, each sector 16 ^ 3 = 4096 (4KB), so a total of 4MB.

Note: Be sure to erase (0xFF) before writing to Flash before writing (0x00);


Overview of partition table:

Taking partitions_two_ota_coredump as an example, its partition on 4MB flash is as follows:

Each ESP32 flash contains multiple applications and various types of data. By default, ESP32 flashes a partition table at flash offset address 0x8000, and its length is 0xC00 (up to 95 partition table entries can be saved). The MD5 checksum of the table is also saved after the partition table data, which is used to verify the integrity of the partition table. In addition, if the chip enables the secure boot function, the signature information will also be saved after the partition table.

Each entry of the partition table contains: Name (label), Type (app, data, etc.), SubType, and offset address, size, Flags in flash:

  • Name field : It can be any name, but it cannot exceed 16 characters (the content after it will be truncated);

  • Type field : It can be specified as app (0) or data (1), or the number 0-254 (0x00-0xFE) can be used directly. 0x00-0x3F is reserved for the core functions of esp-idf and must not be used. note. The bootloader will ignore other partition types except app (0) or data (1);

  • SubType : 8 bits long, the content is related to the specific Type (app or data):

    1> When Type is app, the SubType field can be specified as factory (0), ota_0 (0x10)… ota_15 (0x1F) or test (0x20). Factory (0) is the default app partition, and the bootloader will load the application by default; when
    2> Type is data, the SubType field can be specified as ota (0), phy (1), nvs (2), or nvs_keys (4). ota (0) is the OTA data partition, which is used to store the information of the currently selected OTA application. The size of this partition needs to be set to 0x2000. The phy (1) partition is used to store PHY initialization data, so as to ensure that the PHY can be configured for each device separately, instead of having to use the unified PHY initialization data in the firmware. nvs (2) is a partition specifically for non-volatile storage (NVS) API. nvs_keys (4) is the NVS key partition.

  • Offset field : The offset address starts immediately after the previous partition. If it is the first partition, it starts immediately following the partition table. The offset address of the app partition must be aligned with 0x10000 (64K). If you want to allow the partitions in the partition table to use any starting offset, you need to leave the offset fields of all partitions in the partition table (CSV file) blank.

  • Size field : The size of the partition. The default is a hexadecimal number prefixed with 0x, which supports multiples of K or M (representing 1024 and 1024 * 1024 bytes, respectively).

  • Flags field : Currently only encrypted flags are supported. If the Flags field is set to encrypted and the Flash Encryption function is enabled, the partition will be encrypted. The app partition will always be encrypted, regardless of whether the Flags field is set.


Generate binary partition table

Use the partition_table / gen_esp32part.py tool to convert between csv and binary files:

1> Manually convert the csv file to a binary file:

$ python gen_esp32part.py input_partitions.csv binary_partitions.bin

2> Manually convert binary files to csv files:

$ python gen_esp32part.py binary_partitions.bin input_partitions.csv

MD5 check

Some older versions of the bootloader do not support MD5 verification.
If it is found MD5 checksum error: invalid magic number 0xebeb, you can:
. 1) gen_esp32part.py of the md5sum---disable
2) idf.py menuconfig -> the Partition the Table -> AN MD5 Checksum for the Generate The Partition Table
off correction MD5 Test.


Programming and erasing of partition table:

Use the esptool.py tool to program the partition table:

$ idf.py partition_table-flash

note:

1) Using the $ idf.py flash command will burn everything, including the partition table.
2) The update of the partition table will not erase the data previously stored according to the partition table. At this time, you can use the $ idf.py erase_flash or $ esptool erase_flash command to erase all the contents of the flash.

Published 30 original articles · won 12 · views 8261

Guess you like

Origin blog.csdn.net/syjie19900426/article/details/104055412