espressif/qemu

ESP32C3 fails to boot with otadata partition and no factory app. (QEMU-160)

Samureimer opened this issue · 15 comments

When I try to run the emulator with the following partitions table the program fails to enter the main function it seems.
When targeting the ESP32 it works just fine.

Link to repo that reproduces and documents this:
https://github.com/Samureimer/ESP32C3QemuProblem

QEMU version:
esp-qemu-riscv32-softmmu-develop_8.0.0_20230522
https://github.com/espressif/qemu/releases/tag/esp-develop-8.0.0-20230522

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x4000,
otadata,  data, ota,     0xd000,  0x2000,
phy_init, data, phy,     0xf000,  0x1000,
app0,     app,  ota_0,   0x10000, 0x1F0000,
app1,     app,  ota_1,   ,        0x1F0000,
nvs_key,  data, nvs_keys,,0x1000 ,          encrypted

Console output:

Adding SPI flash device
ESP-ROM:esp32c3-api1-20210111-dirty
Build:Sep 30 2022
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5820,len:0x1738
load:0x403cc710,len:0xae8
load:0x403ce710,len:0x2e70
entry 0x403cc71a
I (0) boot: ESP-IDF HEAD-HASH-NOTFOUND 2nd stage bootloader
I (0) boot: compile time Jul 25 2023 11:11:04
I (0) boot: chip revision: v0.3
I (0) boot.esp32c3: SPI Speed      : 80MHz
I (0) boot.esp32c3: SPI Mode       : SLOW READ
I (0) boot.esp32c3: SPI Flash Size : 4MB
I (1) boot: Enabling RNG early entropy source...
I (1) boot: Partition Table:
I (1) boot: ## Label            Usage          Type ST Offset   Length
I (1) boot:  0 nvs              WiFi data        01 02 00009000 00004000
I (1) boot:  1 otadata          OTA data         01 00 0000d000 00002000
I (1) boot:  2 phy_init         RF data          01 01 0000f000 00001000
I (2) boot:  3 app0             OTA app          00 10 00010000 001f0000
I (2) boot:  4 app1             OTA app          00 11 00200000 001f0000
I (2) boot:  5 nvs_key          NVS keys         01 04 003f0000 00001000
I (2) boot: End of partition table
I (2) boot: No factory image, trying OTA 0
I (2) esp_image: segment 0: paddr=00010020 vaddr=3c020020 size=08cc0h ( 36032) map
I (6) esp_image: segment 1: paddr=00018ce8 vaddr=3fc8a800 size=01120h (  4384) load
I (7) esp_image: segment 2: paddr=00019e10 vaddr=40380000 size=06208h ( 25096) load
I (10) esp_image: segment 3: paddr=00020020 vaddr=42000020 size=157f4h ( 88052) map
I (19) esp_image: segment 4: paddr=0003581c vaddr=40386208 size=04540h ( 17728) load
I (24) boot: Loaded app from partition at offset 0x10000

And then nothing.....

If I remove the otadata from the partitions table, or change the partition table to: Factory app, two OTA definitions, it runs just fine:

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x4000,
phy_init, data, phy,     0xf000,  0x1000,
app0,     app,  ota_0,   0x10000, 0x1F0000,
app1,     app,  ota_1,   ,        0x1F0000,
nvs_key,  data, nvs_keys,,0x1000 ,          encrypted

Console output:

Adding SPI flash device
ESP-ROM:esp32c3-api1-20210111-dirty
Build:Sep 30 2022
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5820,len:0x1738
load:0x403cc710,len:0xae8
load:0x403ce710,len:0x2e70
entry 0x403cc71a
I (0) boot: ESP-IDF HEAD-HASH-NOTFOUND 2nd stage bootloader
I (0) boot: compile time Jul 25 2023 11:14:29
I (0) boot: chip revision: v0.3
I (0) boot.esp32c3: SPI Speed      : 80MHz
I (0) boot.esp32c3: SPI Mode       : SLOW READ
I (0) boot.esp32c3: SPI Flash Size : 4MB
I (1) boot: Enabling RNG early entropy source...
I (1) boot: Partition Table:
I (1) boot: ## Label            Usage          Type ST Offset   Length
I (1) boot:  0 nvs              WiFi data        01 02 00009000 00004000
I (1) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (1) boot:  2 app0             OTA app          00 10 00010000 001f0000
I (2) boot:  3 app1             OTA app          00 11 00200000 001f0000
I (2) boot:  4 nvs_key          NVS keys         01 04 003f0000 00001000
I (2) boot: End of partition table
I (2) esp_image: segment 0: paddr=00010020 vaddr=3c020020 size=08cc0h ( 36032) map
I (6) esp_image: segment 1: paddr=00018ce8 vaddr=3fc8a800 size=01120h (  4384) load
I (7) esp_image: segment 2: paddr=00019e10 vaddr=40380000 size=06208h ( 25096) load
I (10) esp_image: segment 3: paddr=00020020 vaddr=42000020 size=157f4h ( 88052) map
I (18) esp_image: segment 4: paddr=0003581c vaddr=40386208 size=04540h ( 17728) load
I (23) boot: Loaded app from partition at offset 0x10000
I (24) boot: Disabling RNG early entropy source...
I (24) cpu_start: Unicore app
I (24) cpu_start: Pro cpu up.
I (33) cpu_start: Pro cpu start user code
I (33) cpu_start: cpu freq: 160000000 Hz
I (33) cpu_start: Application information:
I (33) cpu_start: Project name:     test
I (33) cpu_start: App version:      e2e517a-dirty
I (33) cpu_start: Compile time:     Jul 25 2023 11:14:22
I (33) cpu_start: ELF file SHA256:  24f6c40c6...
I (33) cpu_start: ESP-IDF:          HEAD-HASH-NOTFOUND
I (33) cpu_start: Min chip rev:     v0.3
I (33) cpu_start: Max chip rev:     v0.99 
I (33) cpu_start: Chip rev:         v0.3
I (33) heap_init: Initializing. RAM available for dynamic allocation:
I (33) heap_init: At 3FC8C790 len 0004FF80 (319 KiB): DRAM
I (33) heap_init: At 3FCDC710 len 00002950 (10 KiB): STACK/DRAM
I (34) heap_init: At 50000010 len 00001FD8 (7 KiB): RTCRAM
I (34) spi_flash: detected chip: gd
I (34) spi_flash: flash io: dio
I (34) sleep: Configure to isolate all GPIO pins in sleep state
I (34) sleep: Enable automatic switching of GPIO sleep configuration
I (34) app_start: Starting scheduler on CPU0
I (35) main_task: Started on CPU0
I (65) main_task: Calling app_main()
W (65) TEST: HELLO WORLD

Hello @Samureimer ,

Thank you for reporting the issue and sorry for the delay of reply. I was able to reproduce the issue you are seeing with esp-develop_8.0.0_20230522 version.

The good thing is this issue is now fixed on the esp-develop branch, which has the newest commits. Since, these commits are not part of any release at the moment, I would advise you to use build esp-develop from source and to use it in your development.