Fix bootloader's OTA partition selection after some OTA flashing #955
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
With default two OTA partitions, according to the algorithm of esp_rewrite_ota_data(...) in latest esp_ota_ops.c, boot partition should be alternated after every OTA flashing. The problem happens after third one.
Initial (flash via USB-UART)
After first OTA
After second OTA
After third OTA (wrong behavior)
In boot process after third OTA, app boot from OTA slot 1 actually. As there are only two (slot 0 and 1) OTA partitions, OTA slot 2 (i.e. third OTA parttiion) not exists. Nevertheless, bootloader automatically fallbacks to earlier partition (slot 1).
This problem can be reproduced with offical OTA excample too.
After third OTA, bootloader repeatedly boot from OTA slot 1 (second OTA partition) only. It refuses further OTA flashed onto OTA slot 0.
This happens because get_selected_boot_partition(...) returns auto-incremented ota_seq based value, NOT OTA app partition index, and it is passed to
index_to_partition(...)
viaload_boot_image(...)
without special care.Consequently, developers cannot try updated program via OTA after second one.
Solution
To fix this, referring the algorithm of esp_rewrite_ota_data(...) in esp_ota_ops.c, I modified
index_to_partition(...)
to point latest (most recently flashed) OTA slot correctly.In my opinion, modifying
get_selected_boot_partition(...)
(around here) is not good idea in terms of fallback ordering of partitions.