esp_ota_begin() hangs

Sunny.Russ58
Posts: 3
Joined: Fri Jan 28, 2022 4:28 pm

esp_ota_begin() hangs

Postby Sunny.Russ58 » Fri Jan 28, 2022 9:42 pm

I am attempting write to a .BIN to an OTA partition. If I call esp_ota_begin() with the actual size of the .BIN, it never returns. I would assume that the erase internal to esp_ota_begin() hangs. If I call esp_ota_begin() with OTA_WITH_SEQUENTIAL_WRITES, esp_ota_begin() returns, but a after a few calls to esp_ota_write(), eventually esp_ota_write() does not return.

I would suspect that internally the call to spi_bus_lock_acquire_start() is where the code is actually hanging.

I would suspect that I am not using the API correctly. For example, the task performing the OTA update needs to be pinned to a core and I have not done that. Another example would be, during an OTA update you can't access the I2C bus, I have not limited I2C access.

I am using ESP-IDF 4.3 with a WROVER-IB 4MB flash, processor revision 1.

Strangely enough, the watch dog timers don't kick in and restart the processor. So, I suspect the processor is still alive enough to keep hitting the watch dog.

Any thoughts as to what I should try?

Craige Hales
Posts: 94
Joined: Tue Sep 07, 2021 12:07 pm

Re: esp_ota_begin() hangs

Postby Craige Hales » Sun Jan 30, 2022 12:25 am

I'm using this with good results

Code: Select all

        otaPartition = esp_ota_get_next_update_partition(NULL);
        rc = esp_ota_begin(otaPartition, OTA_SIZE_UNKNOWN, &otaHandle);  // we know the size, but unknown erases all
then, in the receive loop,

Code: Select all

            rc = esp_ota_write(otaHandle, buf, received);
finally

Code: Select all

        if(!badUpdate){
            rc = esp_ota_end(otaHandle);
            printf("esp_ota_end = %d\n",rc);
            if(rc==ESP_OK){
                rc =  esp_ota_set_boot_partition(otaPartition);
                printf("esp_ota_set_boot_partition = %d\n",rc);
                ESP_LOGI(TAG, "OTA reception complete");
                printf("NOT restarting new executable...\n");
                //esp_restart(); // a graceful shutdown spews more messages to the console for several seconds
                httpd_resp_set_status(req, "303 See Other");
                httpd_resp_set_hdr(req, "Location", "/reboot.html");
                httpd_resp_sendstr(req, "Update installed, please reboot.");
                return ESP_OK;
            }
            else {
                badUpdate=true;
                httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "OTA invalid, esp_ota_end did not accept it.");
                return ESP_OK;
            }
        }

elsewhere, after a good startup sequence,

Code: Select all

    esp_ota_img_states_t otaState;
    error = esp_ota_get_state_partition(running, &otaState);
...much startup stuff...
    if(otaState==ESP_OTA_IMG_PENDING_VERIFY){ // unclear if this needlessly rewrites spi memory.
        error = esp_ota_mark_app_valid_cancel_rollback(); // a lot of stuff just worked, must be OK?
        printf("esp_ota_mark_app_valid_cancel_rollback=%d\n",error);
    }
Craige

Sunny.Russ58
Posts: 3
Joined: Fri Jan 28, 2022 4:28 pm

Re: esp_ota_begin() hangs

Postby Sunny.Russ58 » Tue Feb 08, 2022 2:53 pm

I was able to get it all to work as expected, by pinning the task and disabling I2C.

mcavalcanti
Posts: 1
Joined: Wed Dec 21, 2022 9:42 pm

Re: esp_ota_begin() hangs

Postby mcavalcanti » Wed Dec 21, 2022 9:45 pm

I having the same problems. Could you provide more information about the solution that you found?

Who is online

Users browsing this forum: No registered users and 144 guests