Hi!
I'm using OTA with esp32 and recently I decided to implement failsafe in case of me as a programmer mess up the code and after update the new firmware doesn't connect properly to my server and as a cosequence I cannot do any more updates.
I can easily store something in nvs(or rtc noinit memory) before starting OTA and delete it after successful connection to the server(and use esp_ota_mark_app_valid_cancel_rollback), but I was wondering if there's a cleverer way to detect first boot after update?
Extra points if I can do it with minimal initialization of peripherals as early after boot as possible.
Thanks
How to detect the first boot after OTA update
Re: How to detect the first boot after OTA update
Yup, dead easy:
Firstly, enable the below config option. This means that, if you do not explicitly mark the new img as OK, it will automatically roll back upon the next boot.
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE
Then check to see if your img is pending verification:
Once you have performed your self tests, you can mark the img as good, canceling the pending rollback:
Firstly, enable the below config option. This means that, if you do not explicitly mark the new img as OK, it will automatically roll back upon the next boot.
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE
Then check to see if your img is pending verification:
Code: Select all
esp_ota_img_states_t imgState;
esp_ota_get_state_partition(esp_ota_get_running_partition(), &imgState);
if(imgState == ESP_OTA_IMG_PENDING_VERIFY) // we need to run self tests, and mark this update as OK
{
flag_runSelfTest = true;
ESP_LOGI(TAG, "New img detected. Run self test and confirm OK");
}
Code: Select all
esp_ota_mark_app_valid_cancel_rollback();
Who is online
Users browsing this forum: No registered users and 128 guests