Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set boot partition when writing to flash? #1266

Open
trullock opened this issue Dec 28, 2023 · 4 comments
Open

How to set boot partition when writing to flash? #1266

trullock opened this issue Dec 28, 2023 · 4 comments
Labels

Comments

@trullock
Copy link

trullock commented Dec 28, 2023

My device has a factory app partition and two OTA partitions. My partition table looks like this:

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
factory,  app,  factory, 0x10000, 0x200000,
app0,     app,  ota_0,   0x210000,0x200000,
app1,     app,  ota_1,   0x410000,0x200000,
spiffs,   data, spiffs,  0x620000,0x4E0000,
coredump, data, coredump,0xFF0000,0x10000,

Repeatedly flashing new firmware versions works fine:

"C:\.platformio\penv\Scripts\python.exe" "C:\.platformio\packages\tool-esptoolpy\esptool.py" --chip esp32 --port "COM10" --baud 460800 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size 16MB 0x1000 bootloader.bin 0x8000 partitions.bin 0xe000 boot_app0.bin 0x10000 firmware.bin

When I use in-app functionality to upload a new firmware OTA and set the boot partition using esp_ota_set_boot_partition this works fine.

Repeated successive OTA updates also work fine, switching back and forth between ota_0 and ota_1.

If however I then flash a new version via UART using the esptool.py, the flash appears to succeed but the active boot partition isn't updated, meaning it boots back to the latest OTA partition.

What can I do about this?

My expectation would be that esptool.py sets the active boot partition to whereever you're flashing to. For backwards compat I suppose this can be off by default, but regarless, a switch to control this or other command would be great.

Thanks

@Jason2866
Copy link
Contributor

esptool.py does not set anything regarding boot partitions.

@trullock
Copy link
Author

@Jason2866 so is there a way to set the active partition from the CLI?

@Jason2866
Copy link
Contributor

Jason2866 commented Dec 29, 2023

Not an existing easy way. You have to read and modify the otadata partition
See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html
"The bootloader consults this data in order to know which app to execute. If "ota data" is empty, it will execute the factory app."

Edit: There is a Python tool https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/ota.html#python-api

https://github.com/espressif/esp-idf/blob/master/components/app_update/otatool.py

Should be possible to embed into Platformio

Copy link

stale bot commented Mar 17, 2024

This issue has been automatically marked as stale because it has not had recent activity. Please provide more details or it will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants