使用qemu在windows系统下搭建树莓派3b环境运行RT-Thread

需要下载的资源

表1 下载资源

序号

资源名称

下载地址

说明

1

raspi3b_run_rt_thread_in_Qemu.rar

https://download.csdn.net/download/camelbrand/87371458

包含内容:

1.qemu在windows环境下的安装包以及win7 64位系统的dll补丁文件

2.rt-thread env配置脚本

3.rt-thread源码包

4.编译好的树莓派3b运行rt-thread的环境

5.aarch64在win64环境的交叉编译环境

2

rt-thread官方env工具

https://www.rt-thread.org/download.html#download-rt-thread-env-tool

用于编译rt-thread系统

qemu windows环境搭建

安装上述表格中的资源1:qemu-w64-setup-20221230.exe(win7 64位系统验证OK),安装完毕之后,可以通过CMD运行以下命令测试是否可以正常运行qemu,如果能够正常显示版本号,说明可以正常运行。

注意:对于win7 64位系统,如果提示缺失api-ms-win-core-path-l1-1-0.dll文件,请将压缩包内的api-ms-win-core-path-l1-1-0.dll文件复制一份拷贝到qemu安装目录

如果是win10 64位系统,请使用qemu-w64-setup-20211215.exe安装

C:\Users\xxxxx>"C:\Program Files\qemu\qemu-system-aarch64.exe" -version
QEMU emulator version 7.2.0 (v7.2.0-11948-ge6523b71fc-dirty)
Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers

可以通过 -M help命令选项,查看qemu aarch64支持的开发板类型,这里我们使用树莓派3b开发板,也就是raspi3b,Raspberry Pi 3B (revision 1.2)

C:\Users\xxx>"C:\Program Files\qemu\qemu-system-aarch64.exe" -M help
Supported machines are:
akita                Sharp SL-C1000 (Akita) PDA (PXA270)
ast1030-evb          Aspeed AST1030 MiniBMC (Cortex-M4)
ast2500-evb          Aspeed AST2500 EVB (ARM1176)
ast2600-evb          Aspeed AST2600 EVB (Cortex-A7)
bletchley-bmc        Facebook Bletchley BMC (Cortex-A7)
borzoi               Sharp SL-C3100 (Borzoi) PDA (PXA270)
canon-a1100          Canon PowerShot A1100 IS (ARM946)
cheetah              Palm Tungsten|E aka. Cheetah PDA (OMAP310)
collie               Sharp SL-5500 (Collie) PDA (SA-1110)
connex               Gumstix Connex (PXA255)
cubieboard           cubietech cubieboard (Cortex-A8)
emcraft-sf2          SmartFusion2 SOM kit from Emcraft (M2S010)
fby35-bmc            Facebook fby35 BMC (Cortex-A7)
fby35                Meta Platforms fby35
fp5280g2-bmc         Inspur FP5280G2 BMC (ARM1176)
fuji-bmc             Facebook Fuji BMC (Cortex-A7)
g220a-bmc            Bytedance G220A BMC (ARM1176)
highbank             Calxeda Highbank (ECX-1000)
imx25-pdk            ARM i.MX25 PDK board (ARM926)
integratorcp         ARM Integrator/CP (ARM926EJ-S)
kudo-bmc             Kudo BMC (Cortex-A9)
kzm                  ARM KZM Emulation Baseboard (ARM1136)
lm3s6965evb          Stellaris LM3S6965EVB (Cortex-M3)
lm3s811evb           Stellaris LM3S811EVB (Cortex-M3)
mainstone            Mainstone II (PXA27x)
mcimx6ul-evk         Freescale i.MX6UL Evaluation Kit (Cortex-A7)
mcimx7d-sabre        Freescale i.MX7 DUAL SABRE (Cortex-A7)
microbit             BBC micro:bit (Cortex-M0)
midway               Calxeda Midway (ECX-2000)
mori-bmc             Mori BMC (Cortex-A9)
mps2-an385           ARM MPS2 with AN385 FPGA image for Cortex-M3
mps2-an386           ARM MPS2 with AN386 FPGA image for Cortex-M4
mps2-an500           ARM MPS2 with AN500 FPGA image for Cortex-M7
mps2-an505           ARM MPS2 with AN505 FPGA image for Cortex-M33
mps2-an511           ARM MPS2 with AN511 DesignStart FPGA image for Cortex-M3
mps2-an521           ARM MPS2 with AN521 FPGA image for dual Cortex-M33
mps3-an524           ARM MPS3 with AN524 FPGA image for dual Cortex-M33
mps3-an547           ARM MPS3 with AN547 FPGA image for Cortex-M55
musca-a              ARM Musca-A board (dual Cortex-M33)
musca-b1             ARM Musca-B1 board (dual Cortex-M33)
musicpal             Marvell 88w8618 / MusicPal (ARM926EJ-S)
n800                 Nokia N800 tablet aka. RX-34 (OMAP2420)
n810                 Nokia N810 tablet aka. RX-44 (OMAP2420)
netduino2            Netduino 2 Machine (Cortex-M3)
netduinoplus2        Netduino Plus 2 Machine (Cortex-M4)
none                 empty machine
npcm750-evb          Nuvoton NPCM750 Evaluation Board (Cortex-A9)
nuri                 Samsung NURI board (Exynos4210)
orangepi-pc          Orange Pi PC (Cortex-A7)
palmetto-bmc         OpenPOWER Palmetto BMC (ARM926EJ-S)
qcom-dc-scm-v1-bmc   Qualcomm DC-SCM V1 BMC (Cortex A7)
qcom-firework-bmc    Qualcomm DC-SCM V1/Firework BMC (Cortex A7)
quanta-gbs-bmc       Quanta GBS (Cortex-A9)
quanta-gsj           Quanta GSJ (Cortex-A9)
quanta-q71l-bmc      Quanta-Q71l BMC (ARM926EJ-S)
rainier-bmc          IBM Rainier BMC (Cortex-A7)
raspi0               Raspberry Pi Zero (revision 1.2)
raspi1ap             Raspberry Pi A+ (revision 1.1)
raspi2b              Raspberry Pi 2B (revision 1.1)
raspi3ap             Raspberry Pi 3A+ (revision 1.0)
raspi3b              Raspberry Pi 3B (revision 1.2)
realview-eb          ARM RealView Emulation Baseboard (ARM926EJ-S)
realview-eb-mpcore   ARM RealView Emulation Baseboard (ARM11MPCore)
realview-pb-a8       ARM RealView Platform Baseboard for Cortex-A8
realview-pbx-a9      ARM RealView Platform Baseboard Explore for Cortex-A9
romulus-bmc          OpenPOWER Romulus BMC (ARM1176)
sabrelite            Freescale i.MX6 Quad SABRE Lite Board (Cortex-A9)
sbsa-ref             QEMU 'SBSA Reference' ARM Virtual Machine
smdkc210             Samsung SMDKC210 board (Exynos4210)
sonorapass-bmc       OCP SonoraPass BMC (ARM1176)
spitz                Sharp SL-C3000 (Spitz) PDA (PXA270)
stm32vldiscovery     ST STM32VLDISCOVERY (Cortex-M3)
supermicrox11-bmc    Supermicro X11 BMC (ARM926EJ-S)
sx1                  Siemens SX1 (OMAP310) V2
sx1-v1               Siemens SX1 (OMAP310) V1
tacoma-bmc           OpenPOWER Tacoma BMC (Cortex-A7)
terrier              Sharp SL-C3200 (Terrier) PDA (PXA270)
tosa                 Sharp SL-6000 (Tosa) PDA (PXA255)
verdex               Gumstix Verdex (PXA270)
versatileab          ARM Versatile/AB (ARM926EJ-S)
versatilepb          ARM Versatile/PB (ARM926EJ-S)
vexpress-a15         ARM Versatile Express for Cortex-A15
vexpress-a9          ARM Versatile Express for Cortex-A9
virt-2.10            QEMU 2.10 ARM Virtual Machine
virt-2.11            QEMU 2.11 ARM Virtual Machine
virt-2.12            QEMU 2.12 ARM Virtual Machine
virt-2.6             QEMU 2.6 ARM Virtual Machine
virt-2.7             QEMU 2.7 ARM Virtual Machine
virt-2.8             QEMU 2.8 ARM Virtual Machine
virt-2.9             QEMU 2.9 ARM Virtual Machine
virt-3.0             QEMU 3.0 ARM Virtual Machine
virt-3.1             QEMU 3.1 ARM Virtual Machine
virt-4.0             QEMU 4.0 ARM Virtual Machine
virt-4.1             QEMU 4.1 ARM Virtual Machine
virt-4.2             QEMU 4.2 ARM Virtual Machine
virt-5.0             QEMU 5.0 ARM Virtual Machine
virt-5.1             QEMU 5.1 ARM Virtual Machine
virt-5.2             QEMU 5.2 ARM Virtual Machine
virt-6.0             QEMU 6.0 ARM Virtual Machine
virt-6.1             QEMU 6.1 ARM Virtual Machine
virt-6.2             QEMU 6.2 ARM Virtual Machine
virt-7.0             QEMU 7.0 ARM Virtual Machine
virt-7.1             QEMU 7.1 ARM Virtual Machine
virt                 QEMU 7.2 ARM Virtual Machine (alias of virt-7.2)
virt-7.2             QEMU 7.2 ARM Virtual Machine
witherspoon-bmc      OpenPOWER Witherspoon BMC (ARM1176)
xilinx-zynq-a9       Xilinx Zynq Platform Baseboard for Cortex-A9
xlnx-versal-virt     Xilinx Versal Virtual development board
xlnx-zcu102          Xilinx ZynqMP ZCU102 board with 4xA53s and 2xR5Fs based on the value of smp
z2                   Zipit Z2 (PXA27x)

编译和运行RT-Thread

rt-thread的开发需要下载源码和rt-thread官方的env工具,env工具对应表格1中的资源2,env工具需要解压,该工具默认是aarch32的配置,也就是默认支持的编译arm处理器32位,比如qemu-vexpress-a9的板级编译,如果需要编译aarch64,需要配置aarch64架构的编译器(gcc-arm-10.3-2021.07-mingw-w64-i686-aarch64-none-elf)

解压env_released_1.2.0.7z,进入env文件夹目录,将raspi3b_run_rt_thread_in_Qemu.rar压缩包内部的gcc-arm-10.3-2021.07-mingw-w64-i686-aarch64-none-elf.tar.xz继续解压,复制gcc-arm-10.3-2021.07-mingw-w64-i686-aarch64-none-elf文件夹的所有内容到env路径:env\tools\gnu_gcc\arm_gcc

如下图所示:

使用qemu在windows系统下搭建树莓派3b环境运行RT-Thread_第1张图片

将rt-thread env BuilConfig.rar内部的文件夹BuilConfig解压到env根路径,如下图所示,进入BuildConfig,双击执行批处理脚本aarch64config.bat(如需恢复默认的配置,双击执行aarch32config.bat即可恢复默认配置),执行完毕后,此时env工具具备构建aarch64架构处理器的能力了。

使用qemu在windows系统下搭建树莓派3b环境运行RT-Thread_第2张图片

然后运行env.bat,启动rt-thread的cmd工具,执行cd命令,进入rt-thread源码目录:rt-thread\bsp\raspberry-pi\raspi3-64,修改该目录下的rtconfig.py文件,将内容

EXEC_PATH   = r'/opt/gcc-arm-8.3-2019.03-x86_64-aarch64-elf/bin/' 

修改为:

EXEC_PATH   = os.getenv('RTT_EXEC_PATH') or r'/usr/bin'

然后执行命令scons开始构建

使用qemu在windows系统下搭建树莓派3b环境运行RT-Thread_第3张图片

构建完毕之后,在该目录下会生成两个文件:kernel8.img和rtthread.elf,在该目录下使用qemu_raspi3-64.bat脚本运行启动rt-thread应用,内容如下

@echo off
if exist sd.bin goto run
qemu-img create -f raw sd.bin 64M

:run
"C:\Program Files\qemu\qemu-system-aarch64.exe" -M raspi3b -kernel kernel8.img -serial null -serial stdio -sd sd.bin

我的操作系统是win10 64位,提示如下错误问题,实际在win7 64位系统上没有暴露过该问题,这里的qemu安装包版本是:qemu-w64-setup-20221230.exe(win10 64位验证报错,win7 64位验证没有问题)

> qemu_raspi3-64.bat
WARNING: Image format was not specified for 'sd.bin' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.

(qemu:12604): Gtk-WARNING **: 18:28:39.291: Could not load a pixbuf from icon theme.
This may indicate that pixbuf loaders or the mime database could not be found.

经过排查分析,确认上述问题是安装的qemu版本不兼容win10 64位系统导致,更换为qemu-w64-setup-20211215.exe,卸载并重新安装,问题解决

最终的运行结果(qemu+rt-thread+aarhch64+树莓派3b)

使用qemu在windows系统下搭建树莓派3b环境运行RT-Thread_第4张图片

你可能感兴趣的:(嵌入式技术,开源软件,arm开发)