ESP32 OTA failed saying image is corrupted

sduddell6
Posts: 1
Joined: Tue Feb 01, 2022 11:29 am

ESP32 OTA failed saying image is corrupted

Postby sduddell6 » Thu Feb 10, 2022 7:22 am

I'm trying to implement rainmaker based OTA. OTA URL is successfully received from dashboard, but OTA image validation is failing.
Logs below:

Code: Select all

␛[0;32mI (23979) esp_rmaker_ota_using_topics: File Size: 1249600␛[0m
␛[0;32mI (24619) esp_rmaker_ota: Triggered OTA callback function␛[0m
␛[0;33mW (24619) esp_rmaker_ota: Starting OTA. This may take time.␛[0m
␛[0;33mW (25009) HTTP_CLIENT: HTTP GET Status = 200, content_length = 553␛[0m
␛[0;32mI (25009) HTTP_CLIENT: Connected to URL, cleaning up...␛[0m
␛[0;32mI (25009) HTTP_CLIENT: HTTP_EVENT_DISCONNECTED␛[0m
␛[0;32mI (28279) esp_https_ota: Starting OTA...␛[0m
␛[0;32mI (28279) esp_https_ota: Writing to partition subtype 17 at offset 0x1b0000␛[0m
␛[0;32mI (28279) esp_https_ota: Alloc size: 1024, buf size: 1024 and image header size: 289␛[0m
␛[0;32mI (28289) esp_https_ota: Moved the state to begin␛[0m
I (28299) wifi:Set ps type: 0

␛[0;32mI (28379) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29609) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29619) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29619) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29679) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29679) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29679) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29689) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29749) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29749) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29749) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29759) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29809) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29809) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29809) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29819) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29869) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (29879) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (30979) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (30989) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (31019) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (31019) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (31019) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (31029) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (31089) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (31089) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (31089) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (31099) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (31149) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (31149) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (31149) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (31159) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (31189) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (31199) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (31199) esp_https_ota: data_read: 1024␛[0m
Hello world, tick time: 3005 
␛[0;32mI (32269) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32299) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32299) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32299) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32309) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32359) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32359) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32359) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32369) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32419) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32419) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32419) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32429) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32479) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32479) esp_rmaker_ota: Image bytes read: 50465␛[0m
␛[0;32mI (32479) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32479) esp_https_ota: data_read: 1024␛[0m
␛[0;32mI (32489) esp_https_ota: data_read: 1024␛[0m
␛[0;31mE (32559) Dynamic Impl: alloc(16749 bytes) failed, free size: 3598822, internal ram available: 47159, spiram available: 3562963␛[0m
␛[0;31mE (32559) esp-tls-mbedtls: read error :-0x7F00:␛[0m
␛[0;31mE (32569) TRANSPORT_BASE: esp_tls_conn_read error, errno=Success␛[0m
␛[0;32mI (32569) esp_https_ota: data_read: 289␛[0m
␛[0;31mE (32579) esp-tls-mbedtls: read error :-0x7200:␛[0m
␛[0;31mE (32579) TRANSPORT_BASE: esp_tls_conn_read error, errno=Success␛[0m
␛[0;31mE (32589) esp_https_ota: data read -1, errno 0␛[0m
␛[0;31mE (32599) esp_rmaker_ota: Complete data was not received.␛[0m
I (32599) wifi:Set ps type: 1

␛[0;32mI (32599) esp_image: segment 0: paddr=001b0020 vaddr=3f400020 size=37afch (228092) map␛[0m
␛[0;32mI (32699) esp_image: segment 1: paddr=001e7b24 vaddr=3ffb0000 size=069f8h ( 27128) ␛[0m
␛[0;32mI (32719) esp_image: segment 2: paddr=001ee524 vaddr=40080000 size=01af4h (  6900) ␛[0m
␛[0;32mI (32729) esp_image: segment 3: paddr=001f0020 vaddr=400d0020 size=d53f0h (873456) map␛[0m
␛[0;31mE (33029) esp_image: invalid segment length 0xffffffff␛[0m
␛[0;31mE (33039) esp_rmaker_ota: Image validation failed, image is corrupted␛[0m
Image validation is failing because of below error looks like:

Code: Select all

␛[0;31mE (32559) Dynamic Impl: alloc(16749 bytes) failed, free size: 3598822, internal ram available: 47159, spiram available: 3562963␛[0m
I debugged in the code and found that, it is failing here:

Code: Select all

    esp_buf = mbedtls_calloc(1, SSL_BUF_HEAD_OFFSET_SIZE + buffer_len);
    if (!esp_buf) {
        ESP_LOGE(TAG, "alloc(%d bytes) failed, free size: %d, internal ram available: %d, spiram available: %d", 
        SSL_BUF_HEAD_OFFSET_SIZE + buffer_len, heap_caps_get_free_size((1<<2)),heap_caps_get_free_size(MALLOC_CAP_INTERNAL), heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
        ret = MBEDTLS_ERR_SSL_ALLOC_FAILED;
        goto exit;
    }
To check if memory was available or not , I have added

Code: Select all

heap_caps_get_free_size
, looks like sufficient memory is present in both external and internal memory.
I have also enabled external memory in config, not sure why it is still failing. Any help would be appreciated.

Code: Select all

#
# mbedTLS
#
# CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC is not set
CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y
# CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC is not set
# CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set
CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y
CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384
CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=4096
CONFIG_MBEDTLS_DYNAMIC_BUFFER=y
CONFIG_MBEDTLS_DYNAMIC_FREE_PEER_CERT=y
CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y
CONFIG_MBEDTLS_DYNAMIC_FREE_CA_CERT=y
# CONFIG_MBEDTLS_DEBUG is not set

#
# SPI RAM config
#
CONFIG_SPIRAM_TYPE_AUTO=y
# CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set
# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set
# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set
CONFIG_SPIRAM_SIZE=-1
CONFIG_SPIRAM_SPEED_40M=y
CONFIG_SPIRAM=y
CONFIG_SPIRAM_BOOT_INIT=y
# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set
# CONFIG_SPIRAM_USE_MEMMAP is not set
# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set
CONFIG_SPIRAM_USE_MALLOC=y
CONFIG_SPIRAM_MEMTEST=y
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384
# CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP is not set
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=32768
# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set
# CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY is not set
CONFIG_SPIRAM_CACHE_WORKAROUND=y
Thanks

Who is online

Users browsing this forum: No registered users and 62 guests