Illegal instruction with esptool.py elf2image

dlakatos847
Posts: 2
Joined: Tue Jan 30, 2024 11:38 am

Illegal instruction with esptool.py elf2image

Postby dlakatos847 » Sun Feb 04, 2024 11:11 am

Hello all,

I'm using a ESP32-C6-DevKitC-1 v1.1 board https://docs.espressif.com/projects/esp ... _v1.1.html for self-educational purposes. I'm experimenting with the integrated addressable RGB LED via the example code https://github.com/esp-rs/esp-hal/blob/ ... llo_rgb.rs.

[Codebox]
$ cargo build --example hello_rgb
$ cd target/riscv32imac-unknown-none-elf/debug/examples/
$ file hello_rgb
hello_rgb: ELF 32-bit LSB executable, UCB RISC-V, RVC, soft-float ABI, version 1 (SYSV), statically linked, with debug_info, not stripped
[/Codebox]

I flash my board via

Code: Select all

espflash
first to have a secondary bootloader and the standard partition table set up.

[Codebox]
$ espflash flash hello_rgb
[2024-02-04T11:00:17Z INFO ] Serial port: '/dev/ttyACM0'
[2024-02-04T11:00:17Z INFO ] Connecting...
[2024-02-04T11:00:18Z INFO ] Using flash stub
Chip type: esp32c6 (revision v0.0)
Crystal frequency: 40MHz
Flash size: 8MB
Features: WiFi 6, BT 5
MAC address: 40:4c:ca:42:5b:80
App/part. size: 299,504/8,323,072 bytes, 3.60%
[00:00:00] [========================================] 13/13 0x0 [00:00:00] [========================================] 1/1 0x8000 [00:00:01] [========================================] 105/105 0x10000 [2024-02-04T11:00:20Z INFO ] Flashing has completed!
[/Codebox]

The LED changes colors as expected. I can even overwrite the application image if I want.

[Codebox]
$ espflash save-image --chip esp32c6 --flash-size 8mb hello_rgb hello_rgb.bin
Chip type: esp32c6
Merge: false
Skip padding: false
App/part. size: 299,504/8,323,072 bytes, 3.60%
$ espflash write-bin 0x10000 ./hello_rgb.bin
[2024-02-04T11:02:35Z INFO ] Serial port: '/dev/ttyACM0'
[2024-02-04T11:02:35Z INFO ] Connecting...
[2024-02-04T11:02:35Z INFO ] Using flash stub
Chip type: esp32c6 (revision v0.0)
Crystal frequency: 40MHz
Flash size: 8MB
Features: WiFi 6, BT 5
MAC address: 40:4c:ca:42:5b:80
[00:00:01] [========================================] 105/105 0x10000
[/Codebox]

The LED works as expected.

Here comes the tricky part that I do not understand:
I generate an app image with the

Code: Select all

esptool.py
tool.

[Codebox]
$ esptool.py --chip esp32c6 elf2image --flash_mode dio --flash_size 8MB --output hello_rgb.bin --max-rev-full 99 hello_rgb
esptool.py v4.6.2
Creating esp32c6 image...
Merged 1 ELF section
Successfully created esp32c6 image.
$ espflash write-bin 0x10000 ./hello_rgb.bin
[2024-02-04T11:04:45Z INFO ] Serial port: '/dev/ttyACM0'
[2024-02-04T11:04:45Z INFO ] Connecting...
[2024-02-04T11:04:45Z INFO ] Using flash stub
Chip type: esp32c6 (revision v0.0)
Crystal frequency: 40MHz
Flash size: 8MB
Features: WiFi 6, BT 5
MAC address: 40:4c:ca:42:5b:80
[00:00:02] [========================================] 105/105 0x10000
[/Codebox]

The LED freezes. Monitor shows that the processor hit an illegal instruction:
[Codebox]
$ espflash monitor
[2024-02-04T11:05:30Z INFO ] Serial port: '/dev/ttyACM0'
[2024-02-04T11:05:30Z INFO ] Connecting...
[2024-02-04T11:05:30Z INFO ] Using flash stub
Commands:
CTRL+R Reset chip
CTRL+C Exit

ESP-ROM:esp32c6-20220919
Build:Sep 19 2022
rst:0x15 (USB_UART_HPSYS),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x408007fe
SPIWP:0xee
mode:DIO, clock div:2
load:0x4086c410,len:0xd48
load:0x4086e610,len:0x2d68
load:0x40875720,len:0x1800
SHA-256 comparison failed:
Calculated: 377c26481ad6ab0cce508450f353a55f4bd7eb9159aaf85fde3111071f164514
Expected: 0af544a033ab3492852b8232c904c578d5f07c9d4a423a64473f060db374ab32
Attempting to boot anyway...
entry 0x4086c410
I (41) boot: ESP-IDF v5.1-beta1-378-gea5e0ff298-dirt 2nd stage bootloader
I (42) boot: compile time Jun 7 2023 08:02:08
I (43) boot: chip revision: v0.0
I (46) boot.esp32c6: SPI Speed : 40MHz
I (51) boot.esp32c6: SPI Mode : DIO
I (56) boot.esp32c6: SPI Flash Size : 8MB
I (61) boot: Enabling RNG early entropy source...
I (66) boot: Partition Table:
I (70) boot: ## Label Usage Type ST Offset Length
I (77) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (84) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (92) boot: 2 factory factory app 00 00 00010000 007f0000
I (99) boot: End of partition table
I (103) esp_image: segment 0: paddr=00010020 vaddr=42000020 size=3fee8h (261864) map
I (165) esp_image: segment 1: paddr=0004ff10 vaddr=40800000 size=012d8h ( 4824) load
I (167) esp_image: segment 2: paddr=000511f0 vaddr=00000000 size=1ed38h (126264)
I (196) esp_image: segment 3: paddr=0006ff30 vaddr=4203ff30 size=07fd4h ( 32724) map
I (204) boot: Loaded app from partition at offset 0x10000
I (205) boot: Disabling RNG early entropy source...
Guru Meditation Error: Core 0 panic'ed (Illegal instruction)
Core 0 register dump:
PC : 0x4203a37c RA : 0x4200c5be SP : 0x4086e390 GP : 0x40801ad8
...
[/Codebox]

If I compare the app images generated by

Code: Select all

espflash
and

Code: Select all

esptool.py
and debug the image via

Code: Select all

esptoo.py image_info
command, the difference shows in the segments:

[Codebox]
$ diff /tmp/bad.txt /tmp/good.txt
2c2
< File size: 425776 (bytes)
---
> File size: 299504 (bytes)
27,29c27,29
< 2 0x012d8 0x40800000 0x0003ff08 DRAM, BYTE_ACCESSIBLE, IRAM
< 3 0x1ed38 0x00000000 0x000411e8 PADDING
< 4 0x07fd4 0x4203ff30 0x0005ff28 IROM
---
> 2 0x00018 0x40800000 0x0003ff08 DRAM, BYTE_ACCESSIBLE, IRAM
> 3 0x07fd4 0x4203ff30 0x0003ff28 IROM
> 4 0x012c0 0x40800018 0x00047f04 DRAM, BYTE_ACCESSIBLE, IRAM
34c34
< Validation hash: 15824527f693380a1d0dc1858a40217311c5f5b2b8b18005249c210957eb5069 (valid)
---
> Validation hash: 32fba993864ed70f9e448d01ba846eca2eaa248bfd0ae1f8ad3245cc5697807b (valid)
[/Codebox]

The ELF segments looks like this which is converted into app images:
[Codebox]
$ readelf --segments hello_rgb

Elf file type is EXEC (Executable file)
Entry point 0x42000020
There are 7 program headers, starting at offset 52

Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x001020 0x42000020 0x42000020 0x3fee6 0x3fee6 R E 0x1000
LOAD 0x041000 0x40800000 0x40800000 0x012d8 0x012d8 R E 0x1000
LOAD 0x042f06 0x4203ff06 0x4203ff06 0x00000 0x00026 R E 0x1000
LOAD 0x042f30 0x4203ff30 0x4203ff30 0x07fd4 0x07fd4 R 0x1000
LOAD 0x04b2d8 0x408012d8 0x408012d8 0x00000 0x00004 RW 0x1000
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0
RISCV_ATTRIBUT 0x379ba8 0x00000000 0x00000000 0x0002b 0x0002b R 0x1

Section to Segment mapping:
Segment Sections...
00 .text
01 .trap .rwtext
02 .text_gap
03 .rodata
04 .bss
05
06 .riscv.attributes
[/Codebox]

Why does

Code: Select all

esptool.py
generate an image that does not work on my board? What do I miss?

Thanks in advance.
David

Who is online

Users browsing this forum: No registered users and 34 guests