esp_image: invalid segment length 0xffffffff

Simon Leung
Posts: 10
Joined: Tue Jun 25, 2019 1:28 am

esp_image: invalid segment length 0xffffffff

Postby Simon Leung » Mon Sep 23, 2019 7:48 am

When I run the simple_ota_example, I encountered the invalid segment length problem. The error message is "esp_image: invalid segment length 0xffffffff". Below is a capture from the development platform:

Toolchain path: /opt/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc
Toolchain version: crosstool-ng-1.22.0-80-g6c4433a5
Compiler version: 5.2.0
Python requirements from C:/msys32/home/Simon/esp/esp-idf/requirements.txt are s atisfied.
MONITOR
--- idf_monitor on com10 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:6184
load:0x40078000,len:10180
load:0x40080400,len:6660
entry 0x40080764
I (29) boot: ESP-IDF v3.2.2 2nd stage bootloader
I (29) boot: compile time 14:07:02
I (29) boot: Enabling RNG early entropy source...
I (33) boot: SPI Speed : 40MHz
I (38) boot: SPI Mode : DIO
I (42) boot: SPI Flash Size : 4MB
I (46) boot: Partition Table:
I (49) boot: ## Label Usage Type ST Offset Length
I (56) boot: 0 nvs WiFi data 01 02 00009000 00004000
I (64) boot: 1 otadata OTA data 01 00 0000d000 00002000
I (71) boot: 2 phy_init RF data 01 01 0000f000 00001000
I (79) boot: 3 factory factory app 00 00 00010000 00100000
I (86) boot: 4 ota_0 OTA app 00 10 00110000 00100000
I (94) boot: 5 ota_1 OTA app 00 11 00210000 00100000
I (101) boot: End of partition table
I (106) boot: Defaulting to factory image
I (110) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x1c878 (11
6856) map
I (160) esp_image: segment 1: paddr=0x0002c8a0 vaddr=0x3ffb0000 size=0x02ef4 ( 1
2020) load
I (165) esp_image: segment 2: paddr=0x0002f79c vaddr=0x40080000 size=0x00400 (
1024) load
0x40080000: _WindowOverflow4 at C:/msys32/home/Simon/esp/esp-idf/components/free
rtos/xtensa_vectors.S:1779

I (167) esp_image: segment 3: paddr=0x0002fba4 vaddr=0x40080400 size=0x0046c (
1132) load
I (176) esp_image: segment 4: paddr=0x00030018 vaddr=0x400d0018 size=0x857c0 (54
6752) map
0x400d0018: _stext at ??:?

I (2739) wifi: state: assoc -> run (10)
I (2759) wifi: connected with HELLO_INNOPLAY, channel 11
I (2759) wifi: pm start, type: 1

I (3759) event: sta ip: 10.0.1.67, mask: 255.255.255.0, gw: 10.0.1.1
I (3759) simple_ota_example: Connect to Wifi ! Start to Connect to Server....
I (5849) esp_https_ota: Starting OTA...
I (5849) esp_https_ota: Writing to partition subtype 16 at offset 0x110000
I (6049) esp_https_ota: esp_ota_begin succeeded
I (6049) esp_https_ota: Please Wait. This may take time
I (6059) esp_https_ota: Connection closed,all data received
I (6069) esp_image: segment 0: paddr=0x00110020 vaddr=0x3f400020 size=0x07518 ( 29976) map
E (6089) esp_image: invalid segment length 0xffffffff
E (6089) esp_https_ota: Error: esp_ota_end failed! err=0x5379. Image is invalid
E (6099) simple_ota_example: Firmware Upgrades Failed

Any idea what cause this problem?

Simon Leung
Posts: 10
Joined: Tue Jun 25, 2019 1:28 am

Re: esp_image: invalid segment length 0xffffffff

Postby Simon Leung » Wed Sep 25, 2019 9:55 am

I also tried the native_ota_example. The result is just the same as the simple_ota_example. Then I tried to print out the error code from esp_ota_end, the error code, update_handle is 1503HEX.

Is there anyone got any idea of the meaning of this error code? Is there any solution to this issue?

DrSegatron
Posts: 22
Joined: Tue Oct 10, 2017 2:46 pm

Re: esp_image: invalid segment length 0xffffffff

Postby DrSegatron » Wed Oct 02, 2019 2:43 pm

+1 on toolchain 8.2.0 and IDF v4.0 beta1

Code: Select all

I (46791) esp_https_ota: Starting OTA...
I (46791) esp_https_ota: Writing to partition subtype 17 at offset 0x200000
I (61701) esp_https_ota: Connection closed, all data received
I (61701) esp_image: segment 0: paddr=0x00200020 vaddr=0x3f400020 size=0x2f6b0 (194224) map
E (61831) esp_image: invalid segment length 0xffffffff
E (61841) config.c: ota(): Error: config.c:146 ota() ret=esp_https_ota(&client) returned 5379
E (61841) config.c: ota(): OTA failed!
Edit: Also tried IDF v4.1-dev-369-g4dac7c7df-dirty
Failed exactly the same first go, succeeded second go.

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

Re: esp_image: invalid segment length 0xffffffff

Postby ESP_Mahavir » Tue Oct 08, 2019 3:49 am

Can you please try out suggestion from https://github.com/espressif/esp-idf/is ... -538271762? This will essentially try to download simple `hello-world` application hosted on github server instance, thus we can isolate if its server setup issue (if any) or device side issue. (Interim, we do have an internal CI test https://github.com/espressif/esp-idf/bl ... le_test.py, which ensures functionality of `simple_ota` example before every github repository sync).

Let us know update.

Thanks.

DrSegatron
Posts: 22
Joined: Tue Oct 10, 2017 2:46 pm

Re: esp_image: invalid segment length 0xffffffff

Postby DrSegatron » Thu Oct 10, 2019 9:02 pm

I have some trouble following the example due to our setup; only HTTP, but I can try putting the image on a known good server.
Last edited by DrSegatron on Mon Oct 28, 2019 1:33 pm, edited 1 time in total.

DrSegatron
Posts: 22
Joined: Tue Oct 10, 2017 2:46 pm

Re: esp_image: invalid segment length 0xffffffff

Postby DrSegatron » Mon Oct 28, 2019 1:20 pm

Tested again twice witout making any changes, updating locally. First time succeeded although a bit slow due to being in debug mode.

Second time:
D (53223) esp_https_ota: Written image length 5202
D (53223) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1
D (53223) HTTP_CLIENT: need_read=289, byte_to_read=289, rlen=289, ridx=0
D (53233) HTTP_CLIENT: http_on_body 289
D (53243) esp_https_ota: Written image length 5491
D (53243) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1
D (53253) HTTP_CLIENT: need_read=289, byte_to_read=289, rlen=177, ridx=0
D (53253) HTTP_CLIENT: http_on_body 177
D (53263) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1
D (58263) HTTP_CLIENT: need_read=112, byte_to_read=112, rlen=0, ridx=177
D (58263) esp_https_ota: Written image length 5668
D (58263) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1
D (63263) HTTP_CLIENT: need_read=289, byte_to_read=289, rlen=0, ridx=0
I (63263) esp_https_ota: Connection closed, all data received
D (63263) esp_image: reading image header @ 0x200000
D (63263) esp_image: image header: 0xe9 0x06 0x02 0x02 400813a4
I (63273) boot_comm: mismatch chip revision, expect 1, found 0
I (63283) esp_image: segment 0: paddr=0x00200020 vaddr=0x3f400020 size=0x4057c (263548) map
D (63283) esp_image: free data page_count 0x0000003b
I (63333) wifi.c: disconnect_socket(): Disconnected socket 56 (1). 0 client(s) left
E (63473) esp_image: invalid segment length 0xffffffff
E (63473) config.c: ota(): Error: config.c:135 ota() ret=esp_https_ota(&client) returned 5379
E (63483) config.c: ota(): OTA failed!
Connection is closed unexpectedly? I will try to connect it to the internet and OTA from there next.

DrSegatron
Posts: 22
Joined: Tue Oct 10, 2017 2:46 pm

Re: esp_image: invalid segment length 0xffffffff

Postby DrSegatron » Thu Oct 31, 2019 10:30 am

Cannot reproduce in station mode on v4.0-beta1.

Problem is perhaps that the web server does not give a content-length so when the transfer is interrupted prematurely the OTA process does not know it does not have all data?

DrSegatron
Posts: 22
Joined: Tue Oct 10, 2017 2:46 pm

Re: esp_image: invalid segment length 0xffffffff

Postby DrSegatron » Mon Nov 04, 2019 3:42 pm

My problems seem to have been fixed by assuring a content-length is supplied in the HTTP header.

User avatar
TheRealRevK
Posts: 9
Joined: Mon Aug 26, 2019 7:32 pm

Re: esp_image: invalid segment length 0xffffffff

Postby TheRealRevK » Fri Jan 10, 2020 5:49 pm

FYI, I had this, and it was caused by TCP closing the OTA early on and hence an invalid image, which in turn was caused by low dynamic memory. I only had 15k of free memory and that was not enough - but no clue or warning from debug logs to tell me why TCP had closed the connection!

Zarkzeugan
Posts: 1
Joined: Fri Feb 11, 2022 1:48 pm

Re: esp_image: invalid segment length 0xffffffff

Postby Zarkzeugan » Fri Feb 11, 2022 1:50 pm

How did you make sure that the content length is same as the one provided?

Who is online

Users browsing this forum: No registered users and 8 guests