"esp_ota_set_boot_partition()" triggers WDT during image validation

Pascon
Posts: 2
Joined: Sun Oct 15, 2023 10:19 am

"esp_ota_set_boot_partition()" triggers WDT during image validation

Postby Pascon » Sun Oct 15, 2023 10:34 am

Hi to all.
On an Esp32s3 devkit c1 I'm running an http server wich hosts a small webpage, inspired to the "file_serving" example, which allows me to upload a new firmware into memory. However, no matter what I try (enlarging/reducing partition, smaller flash size, etc...) it always triggers the Task watchdog timer while updating.
I've been tinkering for some time with this issue and I've just found out that the update is halting right after calling "image_validate()", giving the following output:

Code: Select all

I (31654) esp_image: segment 0: paddr=00110020 vaddr=3c090020 size=26ae8h (158440) map
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x8 (TG1WDT_SYS_RST),boot:0x28 (SPI_FAST_FLASH_BOOT)
Saved PC:0x42002f67
0x42002f67: panic_handler at C:/ESP-IDF/esp-idf-v5.1.1/components/esp_system/port/panic_handler.c:145 (discriminator 3)

SPIWP:0xee
mode:DOUT, clock div:1
load:0x3fce3818,len:0x16e8
load:0x403c9700,len:0x4
load:0x403c9704,len:0xc00
load:0x403cc700,len:0x2ed0
entry 0x403c9908
I (31) boot: ESP-IDF v5.1.1-dirty 2nd stage bootloader
I (31) boot: compile time Oct 15 2023 11:04:46
I (32) boot: Multicore bootloader
I (35) boot: chip revision: v0.2
I (39) boot.esp32s3: Boot SPI Speed : 80MHz
I (44) boot.esp32s3: SPI Mode       : DOUT
I (49) boot.esp32s3: SPI Flash Size : 8MB
W (53) boot.esp32s3: PRO CPU has been reset by WDT.
W (59) boot.esp32s3: APP CPU has been reset by WDT.
If I understand well, there may be something wrong with the header of the application, since it is stuck on the segment 0.
I tried commenting the code in "esp_ota_set_boot_partition()" (inside "esp-idf-v5.1.1\components\app_update\esp_ota_ops.c") which calls "image_validate()", and the ota update succeded.
Is there anyone that could help me?

Thanks in advance,
Pascon.

ESP_Mahavir
Posts: 190
Joined: Wed Jan 24, 2018 6:51 am

Re: "esp_ota_set_boot_partition()" triggers WDT during image validation

Postby ESP_Mahavir » Mon Oct 16, 2023 9:12 am

Hello,

It is difficult to comment on your problem without looking at the code. But as I understand, you would like to achieve OTA updates over HTTP server, we have an example for this hosted here: https://github.com/hmalpani/HTTP_Server_OTA

Hopefully this should help you to figure out the problem.

Thanks.

Pascon
Posts: 2
Joined: Sun Oct 15, 2023 10:19 am

Re: "esp_ota_set_boot_partition()" triggers WDT during image validation

Postby Pascon » Mon Oct 16, 2023 1:27 pm

Hi,
thanks for the reply, the code I use, if I remember well, is taken from that example, here it is:

Code: Select all

esp_err_t fw_upload_post(httpd_req_t *req)
{
	//set info flag
	ota_in_progress = true;

	esp_ota_handle_t ota_handle = 0;
	const esp_partition_t* update_partition = esp_ota_get_next_update_partition(NULL);
	ESP_LOGI("OTA", "Partition is %li", update_partition->address);
	esp_err_t err = ESP_OK;
	if (update_partition != NULL)
	{
		 err = esp_ota_begin(update_partition, OTA_WITH_SEQUENTIAL_WRITES, &ota_handle);
		 ESP_LOGI("OTA", "Receiving firmware...");
		 char buf[4096];
		 int received;

		 int remaining = req->content_len;
		 int size = remaining;

		 while (remaining > 0) {

			 ESP_LOGI(TAG, "Remaining size : %d", remaining);
			 upload_perc = (uint16_t)(((uint32_t)(size-remaining)*100)/size);
			 ESP_LOGI(TAG, "Completed : %d", upload_perc);

		     /* Receive the file part by part into a buffer */
		     if ((received = httpd_req_recv(req, buf, MIN(remaining, SCRATCH_BUFSIZE))) <= 0) {
		    	 if (received == HTTPD_SOCK_ERR_TIMEOUT) {
		    		 /* Retry if timeout occurred */
		    		 continue;
		         }

		    	 ESP_LOGE("OTA", "Firmware reception failed!");
		         /* Respond with 500 Internal Server Error */
		         httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to receive file");
		         esp_ota_abort(ota_handle);
		         return ESP_FAIL;
		     }

		     //Write on memory
		     err = esp_ota_write(ota_handle, (const void *)buf, received);
		     if (err != ESP_OK)
		     {
		    	 ESP_LOGE("OTA", "OTA failed due to errors while writing in memory");
		    	 esp_ota_abort(ota_handle);
		    	 return ESP_FAIL;
		     }
		     remaining -= received;
		     vTaskDelay(1);
		 }

		 /* Redirect on home page */
		 httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "File uploaded successfully");

		 ESP_LOGI("OTA", "Firmware reception complete");
		 ESP_LOGI("OTA", "Begin update sequence");

		 //Set new boot partition
		 err = esp_ota_set_boot_partition(update_partition);
		 if (err == ESP_OK)
		 {
			 ESP_LOGI("OTA", "New firmware ready to boot. Restarting...");
			 esp_restart();
		 }
		 else
		 {
			 ESP_LOGE("OTA", "Boot partition setup error. Abort OTA now");
			 esp_ota_abort(ota_handle);
		 }
	}
	return ESP_OK;
}

httpd_uri_t fw_upload_req =
{
	.uri = "/upload/app-image.bin",
	.method = HTTP_POST,
	.handler = fw_upload_post,
	.user_ctx = NULL,
};

hmalpani
Posts: 11
Joined: Tue May 02, 2023 9:22 am

Re: "esp_ota_set_boot_partition()" triggers WDT during image validation

Postby hmalpani » Fri Oct 20, 2023 9:03 am

Hello @Pascon

I tried the above shared HTTP_Server_OTA example with the uri handler shared by you. I was able to perform OTA successfully. Can you please share a minimal code to reproduce this issus. Please also share the sdkconfig you are using which reproduces this issue.

Can you please also share the debug logs when you get this error. You can enable debug logs in menuconfig.

Thanks.

Who is online

Users browsing this forum: MicroController and 232 guests