QEMU virt平台是否支持Cortex-M4处理器及解决方案
QEMU兼容Cortex-M4裸机程序的平台选择问题
问题现象
- QEMU 4.2.1(Debian 1:4.2-3ubuntu6.30)环境下,执行
qemu-system-arm -machine virt -cpu help时,virt平台CPU列表显示包含Cortex-M4,但实际运行qemu-system-arm -M virt -cpu cortex-m4 -kernel build/kernel.elf时,报错:mach-virt: CPU type cortex-m4-arm-cpu not supported - 直接执行
qemu-system-arm -cpu help会报错,必须指定机器类型,且不同机器的可用CPU列表显示一致 - 测试
netduino2机器搭配Cortex-M4可正常启动,但不确定兼容性
原因分析
QEMU的virt机器核心面向Cortex-A系列ARM处理器,虽然-cpu help列表显示包含Cortex-M4,但该平台并未适配M系列内核必需的运行环境(如NVIC中断控制器等外设),属于列表显示的误导性问题。
解决方案
旧版本QEMU(4.2.1)适配方案
- 使用
netduino2虚拟平台:该平台原生适配Cortex-M4,可稳定运行裸机程序,兼容性有保障,启动命令示例:qemu-system-arm -machine netduino2 -cpu cortex-m4 -kernel build/kernel.elf
新版本QEMU(8.2.10+)适配方案
升级后新增多个专为Cortex-M4设计的虚拟开发板平台,这些平台完整适配M系列内核的外设环境,更适合裸机程序开发调试,包括:
ast1030-evbmps2-an386netduinoplus2olimex-stm32-h405
内容的提问来源于stack exchange,提问作者smwikipedia




