esp_https_ota is complaining about "invalid size"

matthew798
Posts: 16
Joined: Mon Jun 01, 2020 2:31 am

esp_https_ota is complaining about "invalid size"

Postby matthew798 » Sun Nov 08, 2020 4:56 am

Hi all,

I am trying to use esp_https_ota to update my app from an HTTPS server. I verified that my server implementation returns exactly the same response as the python "simpleHTTPServer" that is used in the official examples.

I also verified that my TLS information is correct, and the connection succeeds. My issue is that the esp_https_ota function complains about the binary being too large. This is my partitions.csv:

Code: Select all

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xE000,  0x2000,
ota_0,    0,    ota_0,   0x10000, 0x1E0480,
ota_1,    0,    ota_1,         ,  0x1E0480,
The logs say:
I (39944) esp_https_ota: Writing to partition subtype 17 at offset 0x200000
E (39954) esp_https_ota: esp_ota_begin failed (ESP_ERR_INVALID_SIZE)
As an aside, can someone confirm that the second OTA's offset is 0x20000 because it has to be aligned on a multiple of 0x1000?

as you can see, both partitions are just under 2MB, and the binary in question is 1.3MB in size:
Flash: [======= ] 70.7% (used 1390786 bytes from 1967232 bytes)
I tried erasing flash to make sure that the ota_data partition didn't have garbage data causing a problem.

This is the exact code i'm using to fetch the binary:

Code: Select all

esp_err_t WiFiManager::DoUpdate(const char* uri){
    esp_http_client_config_t cfg = {
        .url = uri,
        .cert_pem = caCert
    };

    esp_err_t ret = esp_https_ota(&cfg);
    if (ret == ESP_OK) {
        esp_restart();
    } else {
        return ESP_FAIL;
    }
    return ESP_OK;
}
I'm not even sure how to go about debugging this. Any help is greatly appreciated. Thanks!

boarchuz
Posts: 606
Joined: Tue Aug 21, 2018 5:28 am

Re: esp_https_ota is complaining about "invalid size"

Postby boarchuz » Sun Nov 08, 2020 10:15 am

matthew798 wrote:
Sun Nov 08, 2020 4:56 am
As an aside, can someone confirm that the second OTA's offset is 0x20000 because it has to be aligned on a multiple of 0x1000?
0x200000, aligned to 0x10000 after the end of the previous partition.

I think you're seeing this error because flash is erased in 4K (SPI_FLASH_SEC_SIZE) sectors and your app partitions don't align neatly. Can you try changing the size of your OTA partitions to a 4K-aligned value (eg. 0x1E1000)?

matthew798
Posts: 16
Joined: Mon Jun 01, 2020 2:31 am

Re: esp_https_ota is complaining about "invalid size"

Postby matthew798 » Sun Nov 08, 2020 12:56 pm

Thanks! That seems to have helped. Now it hangs on writing for a few seconds then spits out:

Code: Select all

I (33763) esp_https_ota: Starting OTA...
I (33763) esp_https_ota: Writing to partition subtype 17 at offset 0x200000
Guru Meditation Error: Core  0 panic'ed (Cache disabled but cached memory region accessed)
Core 0 register dump:
PC      : 0x401aaae4  PS      : 0x00060034  A0      : 0x80046686  A1      : 0x3ffbe730  
A2      : 0x00000000  A3      : 0x401aaae4  A4      : 0x00000000  A5      : 0x0000000c  
A6      : 0x3ffb93cc  A7      : 0x3ffb8360  A8      : 0x80019fb8  A9      : 0x00002070  
A10     : 0xf2f2f2f2  A11     : 0x00000000  A12     : 0x0000e54f  A13     : 0x00000022  
A14     : 0x000015fc  A15     : 0x3ffbee90  SAR     : 0x00000017  EXCCAUSE: 0x00000007  
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  
Core 0 was running in ISR context:
EPC1    : 0x40097557  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x401aaae4

ELF file SHA256: ef81d36eed44a080

Backtrace: 0x401aaae1:0x3ffbe730 0x40046683:0x3ffbe760 0x40047515:0x3ffbe780 0x4008b771:0x3ffbe7a0 0x4008b43d:0x3ffbe7c0 0x4008ce66:0x3ffbe7e0 0x4008dd2b:0x3ffbe800 0x40083bd1:0x3ffbe820 0x4008473e:0x3ffb7da0 0x40083717:0x3ffb7dc0 0x4009745d:0x3ffb7de0
  #0  0x401aaae1:0x3ffbe730 in r_get_stack_usage at ??:?
  #1  0x40046683:0x3ffbe760 in ?? ??:0
  #2  0x40047515:0x3ffbe780 in ?? ??:0
  #3  0x4008b771:0x3ffbe7a0 in r_lld_evt_end at ??:?
  #4  0x4008b43d:0x3ffbe7c0 in r_lld_evt_end_isr at ??:?
  #5  0x4008ce66:0x3ffbe7e0 in r_rwble_isr at ??:?
  #6  0x4008dd2b:0x3ffbe800 in r_rwbtdm_isr_wrapper at intc.c:?
  #7  0x40083bd1:0x3ffbe820 in _xt_lowint1 at /home/matthew/.platformio/packages/framework-espidf@3.40001.200521/components/freertos/xtensa_vectors.S:1153
  #8  0x4008473e:0x3ffb7da0 in spi_flash_op_block_func at /home/matthew/.platformio/packages/framework-espidf@3.40001.200521/components/spi_flash/cache_utils.c:81
  #9  0x40083717:0x3ffb7dc0 in ipc_task at /home/matthew/.platformio/packages/framework-espidf@3.40001.200521/components/esp_common/src/ipc.c:62
  #10 0x4009745d:0x3ffb7de0 in vPortTaskWrapper at /home/matthew/.platformio/packages/framework-espidf@3.40001.200521/components/freertos/port.c:143


matthew798
Posts: 16
Joined: Mon Jun 01, 2020 2:31 am

Re: esp_https_ota is complaining about "invalid size"

Postby matthew798 » Sun Nov 08, 2020 9:07 pm

Thank chegewara, I saw your issue. I had looked over the issues before but never clicked on yours for whatever reason. The solution was to call

Code: Select all

esp_log_level_set("*", ESP_LOG_ERROR);
Additionally, I had to

Code: Select all

disableCore0WDT();
because of how my code is set up. I think I'll move things around in order to avoid disabling the WDT.

Now my only issue is that esp_restart(); isn't being called. I have to manually restart the device... Time to investigate a new problem!

Who is online

Users browsing this forum: kaxx1975, Majestic-12 [Bot] and 114 guests