Page 1 of 1

OTA: can't start loaded firmware. Advices needed.

Posted: Mon Mar 28, 2022 11:34 pm
by newsettler_AI
Hi, I'm trying to go through OTA process and stuck. Probably I miss something and cant figure out what exactly :?
IDF v4.4 (release) is using if this matters.
My partition table is default from sdkconfig: one factory (1M), two OTA (each 1M too).

So, here is my steps.
My "core" project (where all OTA stuff is included) flashed on factory partition.
Its running successfully.
Its loading new OTA binary and save too (I've checked with flash dump, new bin file saved on OTA_0 partition correctly)
Rebooting and...

Code: Select all

I (494) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (505) main: Running partition type 0 subtype 0 (offset 0x00010000)
E (515) main: esp_ota_get_state_partition failed! err code [0x106]
then it continues execution of "core" project.
0x106 code stands for:

Code: Select all

#define ESP_ERR_NOT_SUPPORTED       0x106   /*!< Operation or feature not supported */
Here is piece of code in "core" project:

Code: Select all

const esp_partition_t *partition = esp_ota_get_running_partition();

ESP_LOGI(TAG, "Running partition type %d subtype %d (offset 0x%08x)",
    		     partition->type, partition->subtype, partition->address);
    		     
esp_ota_img_states_t ota_state;
esp_err_t ret = esp_ota_get_state_partition(partition, &ota_state);

if (ret == ESP_OK)
{
    ...
    // do all stuff here from example
    ...
}
else
{
    ESP_LOGE(TAG, "esp_ota_get_state_partition failed! err code [0x%X]", ret);
}
I thought something is wrong with special partition "ota_data", but its seems fine. Al least its not empty :)
ota_data.jpg
ota_data.jpg (65.14 KiB) Viewed 2880 times
So...

1. Can firmware be completely different at factory, OTA_0, OTA_1 partitions?
I mean, what if I just compile "hello_world" example and load its binary over the air once? Can OTA_0 get ESP_OTA_IMG_VALID state in this case?
This is what I'm actually trying to do in all described above.

2. Can I just load any suitable by size firmware to OTA_0 and OTA_1 without project preparation?
For example, do I need add some ota-specific code at the top of new firmware (checking partitions, build with some special sdkconfig etc...)?

3. Seems its possible to make OTA updates only in case firmware binary is less then ~1.3M.
In other words, need free size on flash equal of my firmware x3.
Does it make sense to keep relatively small app with OTA-only stuff as bare updater? And when I want update over the air:
  • erase ota_data partition
  • ESP should load as "factory"
  • make update over the air
  • check and run "big" firmware that is located in OTA partition.
Maybe there are some good practices for this situation, when firmware is about 1.8MB? (except buying modules with bigger than 4MB flash size :D )

Hope for help with this questions, thanks in advance!

Re: OTA: can't start loaded firmware. Advices needed.

Posted: Tue Mar 29, 2022 1:21 am
by boarchuz
esp_ota_get_state_partition will return ESP_ERR_NOT_SUPPORTED for the factory app partition as it can't be in any OTA state. Increasing bootloader logging might shed some light on why OTA0 is not booting if you expect it to.

1. Yes
2. Yes
3. Yes, see the factory reset config option

Re: OTA: can't start loaded firmware. Advices needed.

Posted: Tue Mar 29, 2022 2:32 pm
by newsettler_AI
boarchuz wrote: Increasing bootloader logging might shed some light on why OTA0 is not booting if you expect it to.
Thanks for hint, log said that OTA0 have status ABORTED.

So, I start digging in problem and found what was the reason of such behavior.

In DOCS it says:
ESP_OTA_IMG_ABORTED state is set if there was no confirmation of the application operability and occurs reboots (if CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE option is enabled).

In sdkconfing of "core" project this setting was enabled:
sdkconf.jpg
sdkconf.jpg (91.01 KiB) Viewed 2734 times

This mean, in my "hello_world" I have to add modification! At least call once

Code: Select all

esp_ota_mark_app_valid_cancel_rollback();

When I disabled in "core" project rollback support option (as shown on screen), I was able to load via air pure "hello world" (without any additions of ota-specific code) and run it successfully.