ESP32
乐鑫官方移植的qemu工程:espressif/qemu: Fork of QEMU with Espressif patches. See Wiki for details.
官方使用说明:esp-toolchain-docs/qemu/README.md at main · espressif/esp-toolchain-docs
目前支持ESP32,EPS32C3,ESP32S3,功能还不错,支持多核、PSRAM、SD、GPIO等,I2C、SPI等不支持(但应该可以通过GPIO软件模拟来实现)
下面以ESP32S3为例:
# 安装依赖 sudo apt install ninja-build# 克隆工程 git clone https://github.com/espressif/qemu.git# 配置qemu ## xtensa芯片的配置(ESP32 ESP32S3) ./configure --target-list=xtensa-softmmu \ --enable-gcrypt \ --enable-slirp \ --enable-debug \ --enable-sdl \ --disable-strip --disable-user \ --disable-capstone --disable-vnc \ --disable-gtk ## riscv芯片的配置(ESP32C3) ./configure --target-list=riscv32-softmmu \ --enable-gcrypt \ --enable-slirp \ --enable-debug \ --enable-sdl \ --disable-strip --disable-user \ --disable-capstone --disable-vnc \ --disable-gtk# 编译 ninja -C build# 运行 build/qemu-system-xtensa -nographic \-machine esp32s3 \-drive file=固件.bin,if=mtd,format=raw \-global driver=ssi_psram,property=is_octal,value=true \-m 8 \-nic user,model=open_eth ## 参数说明 -drive file=xx.bin 固件路径,注,flash貌似不支持qio模式,只能dio if=mtd告诉 QEMU:“把这个文件当作 ESP32S3 的外部 Flash 芯片来用” format=raw告诉 QEMU:“这个文件是纯二进制,直接按字节读取并写入模拟的 Flash 芯片即可” -m 8 使用PSRAM,大小为8M,如果不使用PSRAM,不加这个 -global driver=ssi_psram,property=is_octal,value=true 使用OPI方式的PSRAM(默认是QSPI) -nic user,model=open_eth 开启网络# 合并固件 ## qemu貌似不支持单独加载某个分区,只能将整个Flash加载进去,所以如果编译生成的是多个文件(如引导,分区表,主程序等等),需要将它们合并成一个 esptool --chip esp32s3 merge-bin -o esp32s3_full_16M_flash.bin \0x00000000 bootloader.bin \0x00008000 partition-table.bin \0x00010000 network_adapter.bin \0x000b0000 etc.jffs2 \0x00120000 xipImage \0x00600000 rootfs.cramfs \--pad-to-size 16MB \--flash-mode dio ## qemu只能支持完整的flash文件,所以像zephyr跟micropython这种编译后会自动帮你合并成一个文件,但没有填满整个falsh空间的固件,加载后也识别不了,手动填充满flash空间 esptool --chip esp32s3 merge-bin -o micropython.bin \0x00000000 ESP32_GENERIC_S3-20250911-v1.26.1.bin \--pad-to-size 16MB esptool --chip esp32s3 merge-bin -o zephyr_8M.bin \0x00000000 build/zephyr.bin \--pad-to-size 8MB
目前只有 jeason1997/esp32s3-rv32ima-arduino 这个Arduino Linux 的程序能成功执行,其他的大多运行个开头就卡住了,原因未知
RP2040
工程路径:ME-IRL/qemu-rp2040: RP2040 support for QEMU.
这个工程多年未更新,应该是废弃了,不过无妨,RP2040有一个rp2040js的模拟器,更好用
TODO
研究怎么读取运行的qemu的gpio信息