question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

partition table offset for flashing is apparently wrong

See original GitHub issue

From my understanding, the partition table on ESP32 is supposed to be 0x8000 based on the documentation:

A single ESP32’s flash can contain multiple apps, as well as many different kinds of data (calibration data, filesystems, parameter storage, etc). For this reason a partition table is flashed to offset 0x8000 in the flash.

In build/main.py:119 and the following cases for each framework, the flash address for partition table is 0x4000.

When flashing in verbose I can see the line calling esptool:

pio run -v -t upload
[...]
"/usr/bin/python2" "/home/bleader/.platformio/packages/tool-esptoolpy/esptool.py" --chip esp32 --port "/dev/ttyUSB0" --baud 115200 write_flash -z --flash_mode dio --flash_freq 80m 0x1000 "/home/bleader/.platformio/packages/framework-arduinoespressif32/tools/sdk/bin/bootloader.bin" 0x4000 "/home/bleader/.platformio/packages/framework-arduinoespressif32/tools/sdk/bin/partitions_singleapp.bin" 0x10000 .pioenvs/esp32dev/firmware.bin
[...]

This leads to something like:

user code not found

I say something like because my following attempt was to flash manually calling the same line, but using 0x8000 for partition table:

"/usr/bin/python2" "/home/bleader/.platformio/packages/tool-esptoolpy/esptool.py" --chip esp32 --port "/dev/ttyUSB0" --baud 115200 write_flash -z --flash_mode dio --flash_freq 80m 0x1000 "/home/bleader/.platformio/packages/framework-arduinoespressif32/tools/sdk/bin/bootloader.bin" 0x8000 "/home/bleader/.platformio/packages/framework-arduinoespressif32/tools/sdk/bin/partitions_singleapp.bin" 0x10000 .pioenvs/esp32dev/firmware.bin

This worked, but now, when flashing using pio run -t upload partition table do not change, and the one at 0x8000 isn’t erased, so code is still executed fine.

So any module with a matching partition table data written at 0x8000 won’t exhibit the issue anymore. Which makes this a pretty low priority issue I guess, and explains why it wasn’t seen before, I just faced it as I used a brand new dev board directly with platformio command line without any other test prior to it.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
valeroscommented, Sep 17, 2020

Hi @svofski ! I’ve added a way to override the default offsets. Here is an example with a custom value for partition table

[env:esp32dev]
; Only available in the dev branch
platform = https://github.com/platformio/platform-espressif32
framework = espidf
board = esp32dev
board_upload.partitions_offset = 0x9000

If there is no custom value is platformio.ini, then we fall back to the value specified in the sdk configuration. Would be great if you could retest with the upstream version of the platform. Thanks!

0reactions
svofskicommented, Sep 11, 2020

To someone stumbling upon this while frustrated by the partition table offset issue, add this clumsy script the project dir and add a line to platformio.ini like so

[env:esp32]
...
extra_scripts = fix_partitions_offset.py
Import('env')

import json
from os.path import join, isfile

def get_sdk_configuration():
    config_path = join(env.subst("$BUILD_DIR"), "config", "sdkconfig.json")
    if not isfile(config_path):
        print('Warning: Could not find "sdkconfig.json" file\n')

    try:
        with open(config_path, "r") as fp:
            return json.load(fp)
    except:
        return {}

sdk_config = get_sdk_configuration()

offset = sdk_config.get("PARTITION_TABLE_OFFSET", 0x8000)
print(f'--- PARTITION_TABLE_OFFSET = 0x{offset:04x} -----------------')
flags = env['UPLOADERFLAGS']
for i in range(1,len(flags)):
    if flags[i].endswith('partitions.bin'):
        flags[i-1] = '{:#04x}'.format(offset)

This however would be a trivial fix here, where all information is already loaded, you just need to replace the hardcoded address: https://github.com/platformio/platform-espressif32/blob/19cb8eb6d4c8ee4a52a5e8cc3884e93e768ad97c/builder/frameworks/espidf.py#L1069

Thanks for your attention!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Partition Error on Boot - ESP32 Forum
This indicates that the bootloader tried to boot the app at offset 0x50000 (ota_0) and found an invalid "magic byte" header. Is there...
Read more >
Partition Tables - ESP32 - — ESP-IDF Programming Guide ...
For this reason a partition table is flashed to (default offset) 0x8000 in the flash. The partition table length is 0xC00 bytes, as...
Read more >
How to get the full capacity of an 8MB or 16MB flash chip?
So, I make partitions.csv read like this for the 8MB flash chip: Code: Select all # Name, Type, SubType, Offset, Size, Flags nvs,...
Read more >
Nand partitioning in u-boot - Stack Overflow
For flash devices, either NAND or NOR, there is no partition table on the device itself. That is, you can't read the device...
Read more >
[INFO] ANDROID DEVICE PARTITIONS and FILESYSTEMS
GUID Partition Table (GPT) was introduced with UEFI booting system ... If MODEMST1 or MODEMST2 are erased (by wrong factory flashing say) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found