encryptionflashesp32bootloaderguid-partition-table

when I try to enable flash encryption in esp32, the bootloader size is large . But I'm unable to find bootloader field in partition table


Error: Bootloader binary size 0x7780 bytes is too large for partition table offset 0x8000. Bootloader binary can be maximum 0x7000 (28672) bytes unless the partition table offset is increased in the Partition Table section of the project configuration menu.

Enabling flash encryption in esp32 firmware.


Solution

  • Short answer:

    1. Change CONFIG_PARTITION_TABLE_OFFSET to a higher value (e.g. using idf.py menuconfig). Default is 0x8000. I would set it to 0x1F000 to reserve 0x17000 more bytes for the bootloader (for a total of 120 KiB).
    2. Change the project's partition table so the first entry is your chosen CONFIG_PARTITION_TABLE_OFFSET + 0x1000. Default is 0x9000. I would set it to 0x20000 to match the previous change.

      You would want to review and update the locations and sizes of all partitions that follow, not just the first one.

    Long answer

    There are 3 "hidden partitions" before the partition table visible in your partitions.csv. By default they are:

    #     Start |   Length         | Partition
    # ----------+------------------+----------------------
    #    0x0000 |   0x1000  (4 KB) | (hidden) Secure boot IV and app image signature
    #    0x1000 |   0x7000 (28 KB) | (hidden) Bootloader
    #    0x8000 |   0x1000  (4 KB) | (hidden) Partition table
    # ----------+--------------------+----------------------
    

    The "visible partitions" declared in partitions.csv start where this table ends, 0x9000 by default.

    You can change the offset of the partition table using config key CONFIG_PARTITION_TABLE_OFFSET which moves the partition "Partition table" to a new address. Doing that leaves more space for the bootloader.

    Obviously, all the visible partitions in partitions.csv move forward by the same amount.

    See an example partition table for a 16 MiB Flash below.

    This leaves 120 KiB of space for the bootloader. Followed by semi-mandatory OTA data, PHY partitions. A big 884 KiB NVS partition. Finally two OTA partitions, ~7.6 MiB each.

    1. Set CONFIG_PARTITION_TABLE_OFFSET to 0x1F000
    2. Update partitions.csv to following:
    #     Start |   Length           | Partition
    # ----------+--------------------+----------------------
    #    0x0000 |   0x1000    (4 KB) | (hidden) Secure boot IV and app image signature
    #    0x1000 |  0x1E000  (120 KB) | (hidden) Bootloader
    #   0x1F000 |   0x1000    (4 KB) | (hidden) Partition table
    # ----------+--------------------+----------------------
    
    otadata,  data, ota,       0x20000,   0x2000,
    phy_init, data, phy,       0x22000,   0x1000,
    nvs,      data, nvs,       0x23000,  0xDD000,
    app0,     app,  ota_0,    0x100000, 0x780000,
    app1,     app,  ota_1,    0x880000, 0x780000,