Ebiroll / qemu-xtensa-esp32s2

ESP32 and ESP32S2 qemu emulation
Other
8 stars 1 forks source link

Offset in partition when reading flash #1

Closed fariouche closed 2 years ago

fariouche commented 2 years ago

Hello!

Thank you so much, works great! I do have a new toflash.c file that automatically parse and add all partition images (no need to hardcode the values!). It is parsing the build/flash_project_args file to figure out all the file to "flash" and is able to merge any arbitrary image in a partition (that must be declared in the partition.csv file). I still need to improve the code before submiting it here :)

Anyway, my question is more related to maybe a bug in the qemu xtense esp32s2. While doing my tests, I "flash" a partition (that is just a string "Hello" for testing).... then execute it using qemu.

The application in the esp32 is using esp_partition_read(partition, 0, ((uint8_t*)ptr), SPI_FLASH_SEC_SIZE) to read the partition data to a buffer and then I compare the 4 first bytes of this partition.

To my surprise, I see that the byte are offset by 1 byte. Instead of reading "Hell", the buffer contain only "ello" I double checked my flash image and I can see Hello starting at address 0x10000.

I haven't tried my app in a real esp32 yet, but the code is so simple (esp_partition_find_first() followed by a esp_partition_read())

If you have any idea! Thanks!

Ebiroll commented 2 years ago

Thanks for the feedback. Unfortunately I never got esp32 s2 emulation to work beyond the boot loader, as timer ticks did not work so well. Maybe you can post your program so I can test it.

fariouche commented 2 years ago

Here is a example. example.tgz.zip You may need to remove the zip extention. Inside is a esp32 project that you can build using esp-idf 4.4. You will also find an image already working for the emulator: esp32flash.bin If you need to regen the flash image, you can do so by adding the storage.bin partition at offset 0x10000.

This is my command line I'm using: /xtensa-softmmu/qemu-system-xtensa -nographic -M esp32 -drive file=./ex/esp32flash.bin,if=mtd,format=raw -s

The example will print the 4 bytes of the storage partition, in hexadecimal. This is what I get:

Hello world!
This is esp32 chip with 2 CPU core(s), WiFi/BT/BLE, silicon revision 0, 4MB external flash
Minimum free heap size: 313428 bytes
65 6c 6c 6f

65 6c 6c 6f is "ello". Should be 48 65 6c 6c....

fariouche commented 2 years ago

Hello! Did you get time to look at the issue? If not, Maybe I can investigate if you tell me were to look at.

Thank you!

Ebiroll commented 2 years ago

Hello. Sorry I forgot about this. If you are running esp32s2 emulation, why do you mot use -M esp32s2 on the command line?

If you want to use esp32 emulation, consider using espressifs version: https://github.com/espressif/qemu

fariouche commented 2 years ago

good point! I wanted to use your other emulator for esp32 (because of the wifi emulation if I do remember), but was not able to compile it. So I found this one in one of the issues comments and switch to it assuming it will work the same... But now I see no wifi support, hum... I'm confused... Anyway my problem may be coming from this then.. I will switch to the official qemu until I really need the wifi Thanks!