rust-esp32-std-demo: ESP32C3: "esp_image: invalid segment length" when running a build based on ESP-IDF V4.3.X
UPDATE: WORKAROUNDS
If you are using the ESP32C3 chip, and once the binary is flashed you see this error:
E (174) esp_image: invalid segment length 0xffee
… potentially followed by these:
E (174) boot: Factory app partition is not bootable
E (174) boot: No bootable app partitions in the partition table
… then you are hitting this problem.
We are not sure yet what is causing the invalid segment size. It might be the esp-idf-sys
build of ESP V4.3.X, or the ESP-IDF V4.3.X itself. However we know that:
- It does not always happen (depends on the concrete size your program happens to have when compiled to binary)
- Happens ONLY for ESP32C3 + ESP-IDF V4.3.X (later versions work OK).
Workaround (NOTE: only for platforms <> Windows; for Windows, currently there is no (easy) workaround):
To workaround the issue, you have to use a version > ESP-IDF 4.3.X. Using version > 4.3.X is not possible with the PIO build, hence why you also need to switch to the native build. This leaves you with two options:
- Use ESP-IDF master. Unfortunately this one cannot be built at the moment. We have not yet looked into this issue, might be an issue in ESP-IDF itself
- Use ESP-IDF release/v4.4 branch <-- This is what I would recommend
So to build, please use export ESP_IDF_VERSION=release/v4.4; cargo build --features native
.
Unfortunately, the above will not work on Windows (i.e. on Windows currently there is simply no workaround for that problem), because the native build generates too long command lines on Windows. We are aware of that, and the fix should actually be implemented inside ESP-IDF itself (to be more precise, on how they build the ESP-IDF GCC toolchains for Windows). We are waiting for the next GCC Windows toolchains release from them.
===============================================
Original bug report: When I comment out all of the code and just print something, the ESP32C3 board I’m using prints:
E (174) esp_image: invalid segment length 0xffee
E (174) boot: Factory app partition is not bootable
E (174) boot: No bootable app partitions in the partition table
My partition table looks like:
I (62) boot: ## Label Usage Type ST Offset Length
I (69) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (77) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (84) boot: 2 factory factory app 00 00 00010000 00100000
I’ve been looking into it for a bit but it seems that the padding is not aligned to 4-byte, which is causing this error to pop up. I’m using esptool.py
to generate an app image from the compiled ELF.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 35 (17 by maintainers)
Commits related to this issue
- A fix for https://github.com/ivmarkov/rust-esp32-std-demo/issues/14 — committed to esp-rs/esp-idf-sys by ivmarkov 2 years ago
- A fix for https://github.com/ivmarkov/rust-esp32-std-demo/issues/14 — committed to esp-rs/esp-idf-hal by ivmarkov 2 years ago
- A fix for https://github.com/ivmarkov/rust-esp32-std-demo/issues/14 — committed to BaybyPig0329/esp-idf-hal by deleted user 2 years ago
With the above ^^^ commits I would consider this issue finally fixed!
Forget about using the native build on Windows currently. See below.
This is not (yet) supported, but is work in progress (i.e. supplying your own local copy of ESP-IDF). You can still supply your own Git clone of ESP-IDF, but then see below - that’s not necessary.
Yes, the issue does not always happen.
To workaround the issue, you have to use a version > ESP-IDF 4.3.X. Using version > 4.3.X is not possible with the PIO build, hence why you also need to switch to the native build. This leaves you with two options:
So to build, please use
export ESP_IDF_VERSION=release/v4.4; cargo build --features native
.Unfortunately, the above will not work on Windows (i.e. on Windows currently there is simply no workaround for that problem), because the native build generates too long command lines on Windows. We are aware of that, and the fix should actually be implemented inside ESP-IDF itself (to be more precise, on how they build the ESP-IDF GCC toolchains for Windows). We are waiting for the next GCC Windows toolchains release from them.
Done! Check the esptool issue.
@ivmarkov @FrozenDroid May I ask you to attach an ELF file which triggers this issue over at https://github.com/espressif/esptool/issues/661? This would help the folks working on esptool pick up the issue report quicker, since they won’t have to set up rust-esp32-std-hello to reproduce. Thanks in advance!
Ha! You are completely right!
I just reproduced it. Full log just in case:
Segment info, just in case: