Page 1 of 1

esp_ota_begin() hangs

Posted: Fri Jan 28, 2022 9:42 pm
by Sunny.Russ58
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?

Re: esp_ota_begin() hangs

Posted: Sun Jan 30, 2022 12:25 am
by Craige Hales
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);
    }

Re: esp_ota_begin() hangs

Posted: Tue Feb 08, 2022 2:53 pm
by Sunny.Russ58
I was able to get it all to work as expected, by pinning the task and disabling I2C.

Re: esp_ota_begin() hangs

Posted: Wed Dec 21, 2022 9:45 pm
by mcavalcanti
I having the same problems. Could you provide more information about the solution that you found?