编译运行rt-thread的qemu-riscv-virt64版本

背景

本文记录对国产实时操作系统rt-thread的编译运行,此版本运行于riscv的64位qemu模拟器

编译qemu的riscv环境

首先我们需要编译模拟器,以提供rt-thread运行环境,步骤如下所示:

1、下载解压qemu源码

root@rtlab-computer:/home/rtlab/szc/riscv-qemu# wget https://download.qemu.org/qemu-6.0.0.tar.xz
root@rtlab-computer:/home/rtlab/szc/riscv-qemu# chmod 777 qemu-6.0.0.tar.xz
root@rtlab-computer:/home/rtlab/szc/riscv-qemu# tar xvJf qemu-6.0.0.tar.xz

2、进入qemu目录,进行配置(prefix表示安装路径,手动指定方便我们管理)、编译和安装

root@rtlab-computer:/home/rtlab/szc/riscv-qemu# cd qemu-6.0.0/
root@rtlab-computer:/home/rtlab/szc/riscv-qemu/qemu-6.0.0# ./configure --target-list=riscv64-linux-user,riscv64-softmmu --prefix=/home/rtlab/szc/risc-qemu/qemu-6.0.0
root@rtlab-computer:/home/rtlab/szc/riscv-qemu/qemu-6.0.0# make && make install

在build目录下可以看到我们需要的可执行文件:qemu-system-riscv64

编译运行rt-thread的qemu-riscv-virt64版本

编译qemu-riscv-virt64版本的rt-thread

获取到运行环境后,就要编译操作系统了,步骤如下:

1、下载解压编译工具链:https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz,并给解压出来的目录起一个简短且区分度高的名字:

root@rtlab-computer:/home/rtlab/szc# tar -zxvf riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz
root@rtlab-computer:/home/rtlab/szc# mv riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14 riscv64-unknown-toolchain

而后安装scons,过程参见文章SCONS编译和使用

再克隆rt-thread源码,进入rt-thread/bsp/qemu-riscv-virt64目录:

root@rtlab-computer:/home/rtlab/szc/rt-thread_master# git clone https://github.com/RT-Thread/rt-thread.git
root@rtlab-computer:/home/rtlab/szc/rt-thread_master# cd rt-thread/bsp/qemu-riscv-virt64

修改rtconfig.py中的gcc路径:

root@rtlab-computer:/home/rtlab/szc/rt-thread_master/rt-thread/bsp/qemu-riscv-virt64# vim rtconfig.py
....
if  CROSS_TOOL == 'gcc':
    PLATFORM    = 'gcc'
    EXEC_PATH   = r'/home/rtlab/szc/riscv64-unknown-toolchain/bin'
.....

 运行scons编译:

root@rtlab-computer:/home/rtlab/szc/rt-thread_master/rt-thread/bsp/qemu-riscv-virt64# scons
scons: Reading SConscript files ...
b''
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: build
CC build/applications/main.o
CC build/driver/board.o
CC build/driver/drv_uart.o
CC build/driver/plic.o
CC build/driver/sbi.o
CC build/kernel/components/dfs/filesystems/devfs/devfs.o
CC build/kernel/components/dfs/filesystems/romfs/dfs_romfs.o
CC build/kernel/components/dfs/filesystems/romfs/romfs.o
CC build/kernel/components/dfs/src/dfs.o
CC build/kernel/components/dfs/src/dfs_file.o
CC build/kernel/components/dfs/src/dfs_fs.o
CC build/kernel/components/dfs/src/dfs_posix.o
CC build/kernel/components/dfs/src/poll.o
CC build/kernel/components/dfs/src/select.o
CC build/kernel/components/drivers/misc/pin.o
CC build/kernel/components/drivers/serial/serial.o
CC build/kernel/components/drivers/src/completion.o
CC build/kernel/components/drivers/src/dataqueue.o
CC build/kernel/components/drivers/src/pipe.o
CC build/kernel/components/drivers/src/ringblk_buf.o
CC build/kernel/components/drivers/src/ringbuffer.o
CC build/kernel/components/drivers/src/waitqueue.o
CC build/kernel/components/drivers/src/workqueue.o
CC build/kernel/components/finsh/cmd.o
CC build/kernel/components/finsh/msh.o
CC build/kernel/components/finsh/msh_file.o
CC build/kernel/components/finsh/shell.o
CC build/kernel/components/libc/compilers/common/delay.o
CC build/kernel/components/libc/compilers/common/stdlib.o
CC build/kernel/components/libc/compilers/common/time.o
CC build/kernel/components/libc/compilers/common/unistd.o
CC build/kernel/components/libc/compilers/newlib/libc.o
CC build/kernel/components/libc/compilers/newlib/stdio.o
CC build/kernel/components/libc/compilers/newlib/syscalls.o
CC build/kernel/src/clock.o
CC build/kernel/src/components.o
CC build/kernel/src/device.o
CC build/kernel/src/idle.o
CC build/kernel/src/ipc.o
CC build/kernel/src/irq.o
CC build/kernel/src/kservice.o
CC build/kernel/src/mem.o
CC build/kernel/src/mempool.o
CC build/kernel/src/object.o
CC build/kernel/src/scheduler.o
CC build/kernel/src/thread.o
CC build/kernel/src/timer.o
AS /home/rtlab/szc/rt-thread_master/rt-thread/libcpu/risc-v/virt64/context_gcc.o
AS /home/rtlab/szc/rt-thread_master/rt-thread/libcpu/risc-v/virt64/interrupt_gcc.o
CC /home/rtlab/szc/rt-thread_master/rt-thread/libcpu/risc-v/virt64/interrupt.o
AS /home/rtlab/szc/rt-thread_master/rt-thread/libcpu/risc-v/virt64/startup_gcc.o
CC /home/rtlab/szc/rt-thread_master/rt-thread/libcpu/risc-v/virt64/tick.o
CC /home/rtlab/szc/rt-thread_master/rt-thread/libcpu/risc-v/virt64/cpuport.o
LINK rtthread.elf
riscv64-unknown-elf-objcopy -O binary rtthread.elf rtthread.bin
riscv64-unknown-elf-size rtthread.elf
   text       data        bss        dec        hex    filename
147931       2865      70483     221279      3605f    rtthread.elf
scons: done building targets.

可以看到bin文件和elf文件:

编译运行rt-thread的qemu-riscv-virt64版本

测试运行

修改qemu-riscv-virt64/qemu-nographic.sh中的qemu-system-riscv64路径为我们第一步编译好的qemu-system-riscv64路径:

root@rtlab-computer:/home/rtlab/szc/rt-thread_master/rt-thread/bsp/qemu-riscv-virt64# vim ./qemu-nographic.sh
/home/rtlab/szc/riscv-qemu/qemu-6.0.0/build/qemu-system-riscv64 -nographic -machine virt -m 256M -bios rtthread.bin

 而后运行qemu-nographic.sh即可:

编译运行rt-thread的qemu-riscv-virt64版本

 

上一篇:Makefile 学习笔记(二) Makefile的使用


下一篇:一个数除以9余8除以8余7除以7余6