Skip to content

Commit 13ef664

Browse files
committed
add run.sh and readme_cn
1 parent 67a451b commit 13ef664

File tree

2 files changed

+323
-0
lines changed

2 files changed

+323
-0
lines changed
Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
2+
# QEMU/RISCV64/C906 VIRT 板级支持包使用说明
3+
4+
中文页 | [English](./README.md)
5+
6+
<!-- TOC -->
7+
8+
- [QEMU/RISCV64/C906 VIRT 板级支持包使用说明](#qemuriscv64c906-virt-板级支持包使用说明)
9+
- [1. 简介](#1-简介)
10+
- [2. 构建](#2-构建)
11+
- [2.1. 安装工具链](#21-安装工具链)
12+
- [2.2. 设置 RT-Thread 工具链环境变量](#22-设置-rt-thread-工具链环境变量)
13+
- [2.3. 下载内核](#23-下载内核)
14+
- [2.4. 配置内核](#24-配置内核)
15+
- [2.5. 编译内核](#25-编译内核)
16+
- [3. 运行](#3-运行)
17+
- [3.1. 安装 QEMU](#31-安装-qemu)
18+
- [3.2. 运行 QEMU](#32-运行-qemu)
19+
- [3.2.1. 运行 RT-Thread Smart 版](#321-运行-rt-thread-smart-版)
20+
- [3.2.2. 运行 RT-Thread Smart 版 + 根文件系统](#322-运行-rt-thread-smart-版--根文件系统)
21+
22+
<!-- /TOC -->
23+
24+
## 1. 简介
25+
26+
RISC-V 是一种开放和免费的指令集体系结构 (ISA)。本工程基于 QEMU 的 RISC-V64 VIRT 平台,移植至 C906 处理器平台。
27+
28+
## 2. 构建
29+
30+
工作系统:以 Ubuntu 24.04 为例:
31+
32+
```shell
33+
$ lsb_release -a
34+
No LSB modules are available.
35+
Distributor ID: Ubuntu
36+
Description: Ubuntu 24.04.2 LTS
37+
Release: 24.04
38+
Codename: noble
39+
```
40+
41+
### 2.1. 安装工具链
42+
43+
- 编译器: [Xuantie-900-gcc-linux-6.6.0-musl64-x86_64-V3.0.2-20250410.tar.gz](https://www.xrvm.cn/community/download?id=4433353576298909696)
44+
- 模拟器: [Xuantie-qemu-x86_64-Ubuntu-20.04-V5.0.5-B20250108-0335.tar.gz](https://www.xrvm.cn/community/download?id=4397435198627713024)
45+
46+
注:若上述链接中的模拟器不能使用,可以使用下述仓库编译模拟器
47+
> [XUANTIE-RV/qemu](https://github.com/XUANTIE-RV/qemu)
48+
49+
### 2.2. 设置 RT-Thread 工具链环境变量
50+
51+
和 RT-Thread 工具链相关的环境变量有三个
52+
53+
- `RTT_CC` 为工具链名称, 这里统一为 `"gcc"`
54+
- `RTT_CC_PREFIX`: 为工具链前缀, 这里对于标准版是 `"riscv64-unknown-elf-"`,对于 Smart 版是 `"riscv64-unknown-linux-musl-"`
55+
- `RTT_EXEC_PATH`: 工具链的 bin 文件夹所在路径, 如 `"$HOME/tools/Xuantie-900-gcc-linux-6.6.0-musl64-x86_64-V3.0.2/bin"`, 这个根据个人下载解压后的实际路径进行设置,注意 RT-Thread 标准版和 Smart 版本的工具链是两套不同的版本,而且设置 `RTT_EXEC_PATH` 的路径名时要一直到 `bin`
56+
57+
>注:对于不同的工具链`RTT_CC_PREFIX`可能有所不同,可在工具链 bin 文件夹所在路径下查看
58+
如果一直使用的话,建议将这三个环境变量在 `.bashrc` 文件中 export。
59+
60+
### 2.3. 下载内核
61+
62+
假设工作路径是 `$WORKSPACE`
63+
64+
```shell
65+
$ cd $WORKSPACE
66+
git clone [email protected]:RT-Thread/rt-thread.git
67+
```
68+
69+
进入 xuantie/virt64/c906 所在 BSP 目录,后面的操作不做另外介绍,默认就在这个目录下。
70+
71+
```shell
72+
cd $WORKSPACE/rt-thread/bsp/xuantie/virt64/c906
73+
```
74+
75+
### 2.4. 配置内核
76+
77+
第一次编译前先刷新一下配置文件。
78+
79+
```shell
80+
scons --menuconfig
81+
```
82+
83+
要使用 RT-Thread Smart 版,进入配置菜单后至少要打开 `RT_USING_SMART` 这个选项(见下图),其他的看自己的需求,如果此处已开启,直接保存退出即可。
84+
85+
```kconfiglib
86+
(Top) → RT-Thread Kernel
87+
RT-Thread Project Configuration
88+
(24) The maximal size of kernel object name
89+
[ ] Use the data types defined in ARCH_CPU
90+
[*] Enable RT-Thread Smart (microkernel on kernel/userland)
91+
[ ] Enable RT-Thread Nano
92+
...
93+
```
94+
95+
修改后保存退出。
96+
97+
### 2.5. 编译内核
98+
99+
如果以前编译后,可以清理一下:
100+
101+
```shell
102+
scons --clean
103+
```
104+
105+
或者直接编译:
106+
107+
```shell
108+
scons -j$(nproc)
109+
```
110+
111+
`$WORKSPACE/rt-thread/bsp/xuantie/virt64/c906` 路径下会生成内核的二进制文件 `rtthread.bin`
112+
113+
## 3. 运行
114+
115+
### 3.1. 安装 QEMU
116+
117+
这里通过编译`XUANTIE-RV/qemu`仓库安装qemu模拟器
118+
119+
```shell
120+
121+
git clone [email protected]:XUANTIE-RV/qemu.git
122+
123+
mkdir build
124+
125+
cd build
126+
127+
../configure --target-list="riscv64-softmmu riscv64-linux-user
128+
129+
make -j8
130+
131+
make install
132+
133+
```
134+
135+
安装完毕后可以看一下版本。
136+
137+
```shell
138+
$ qemu-system-riscv64 --version
139+
QEMU emulator version 8.2.94 (v6.1.0-22774-ge0ace167ef)
140+
Copyright (c) 2003-2024 Fabrice Bellard and the QEMU Project developers
141+
```
142+
143+
### 3.2. 运行 QEMU
144+
145+
仓库里已经提供了现成的执行脚本,可以直接执行:
146+
147+
```shell
148+
./run.sh
149+
```
150+
151+
#### 3.2.1. 运行 RT-Thread Smart 版
152+
153+
示例如下:
154+
155+
```shell
156+
$ ./run.sh
157+
158+
OpenSBI v0.9
159+
____ _____ ____ _____
160+
/ __ \ / ____| _ \_ _|
161+
| | | |_ __ ___ _ __ | (___ | |_) || |
162+
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
163+
| |__| | |_) | __/ | | |____) | |_) || |_
164+
\____/| .__/ \___|_| |_|_____/|____/_____|
165+
| |
166+
|_|
167+
168+
Platform Name : riscv-virtio,qemu
169+
Platform Features : timer,mfdeleg
170+
Platform HART Count : 1
171+
Firmware Base : 0x80000000
172+
Firmware Size : 100 KB
173+
Runtime SBI Version : 0.2
174+
175+
Domain0 Name : root
176+
Domain0 Boot HART : 0
177+
Domain0 HARTs : 0*
178+
Domain0 Region00 : 0x0000000080000000-0x000000008001ffff ()
179+
Domain0 Region01 : 0x0000000000000000-0xffffffffffffffff (R,W,X)
180+
Domain0 Next Address : 0x0000000080200000
181+
Domain0 Next Arg1 : 0x000000008f000000
182+
Domain0 Next Mode : S-mode
183+
Domain0 SysReset : yes
184+
185+
Boot HART ID : 0
186+
Boot HART Domain : root
187+
Boot HART ISA : rv64imafdcsu
188+
Boot HART Features : scounteren,mcounteren,time
189+
Boot HART PMP Count : 16
190+
Boot HART PMP Granularity : 4
191+
Boot HART PMP Address Bits: 54
192+
Boot HART MHPM Count : 0
193+
Boot HART MHPM Count : 0
194+
Boot HART MIDELEG : 0x0000000000000222
195+
Boot HART MEDELEG : 0x000000000000b109
196+
heap: [0x002ef030 - 0x042ef030]
197+
198+
\ | /
199+
- RT - Thread Smart Operating System
200+
/ | \ 5.2.0 build Nov 14 2024 15:48:43
201+
2006 - 2024 Copyright by RT-Thread team
202+
lwIP-2.0.3 initialized!
203+
[I/sal.skt] Socket Abstraction Layer initialize success.
204+
[I/utest] utest is initialize success.
205+
[I/utest] total utest testcase num: (0)
206+
[I/drivers.serial] Using /dev/ttyS0 as default console
207+
file system initialization done!
208+
Hello RISC-V
209+
msh />
210+
```
211+
212+
#### 3.2.2. 运行 RT-Thread Smart 版 + 根文件系统
213+
214+
对于 Smart 版本的内核,也可以在执行 `run.sh` 脚本时指定根文件系统镜像文件的路径在启动过程中挂载根文件系统。
215+
216+
需要注意的是,内核默认支持 fat, 如果要挂载 ext4 的文件系统,则还需要额外安装 lwext4 软件包,即使能 `PKG_USING_LWEXT4`(具体 menuconfig 路径是 (Top) -> RT-Thread online packages -> system packages -> lwext4: an excellent choice of ext2/3/4 filesystem for microcontrollers.)。如果在菜单中找不到该软件包,可以退出 menuconfig 并执行 `pkgs --upgrade` 更新软件包索引后再尝试使能软件包。
217+
218+
勾选该选项后还需要执行如下操作更新软件并安装源码到 bsp 的 packages 目录下(该操作只要执行一次即可):
219+
220+
```shell
221+
source ~/.env/env.sh
222+
pkgs --update
223+
```
224+
225+
保存后重新编译内核。
226+
227+
有关如何制作根文件系统,请参考 <https://github.com/RT-Thread/userapps/blob/main/README.md>,这里不再赘述。
228+
229+
示例如下:
230+
231+
```shell
232+
$ ./run.sh /home/u/ws/duo/userapps/apps/build/ext4.img
233+
234+
OpenSBI v0.9
235+
____ _____ ____ _____
236+
/ __ \ / ____| _ \_ _|
237+
| | | |_ __ ___ _ __ | (___ | |_) || |
238+
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
239+
| |__| | |_) | __/ | | |____) | |_) || |_
240+
\____/| .__/ \___|_| |_|_____/|____/_____|
241+
| |
242+
|_|
243+
244+
Platform Name : riscv-virtio,qemu
245+
Platform Features : timer,mfdeleg
246+
Platform HART Count : 1
247+
Firmware Base : 0x80000000
248+
Firmware Size : 100 KB
249+
Runtime SBI Version : 0.2
250+
251+
Domain0 Name : root
252+
Domain0 Boot HART : 0
253+
Domain0 HARTs : 0*
254+
Domain0 Region00 : 0x0000000080000000-0x000000008001ffff ()
255+
Domain0 Region01 : 0x0000000000000000-0xffffffffffffffff (R,W,X)
256+
Domain0 Next Address : 0x0000000080200000
257+
Domain0 Next Arg1 : 0x000000008f000000
258+
Domain0 Next Mode : S-mode
259+
Domain0 SysReset : yes
260+
261+
Boot HART ID : 0
262+
Boot HART Domain : root
263+
Boot HART ISA : rv64imafdcsu
264+
Boot HART Features : scounteren,mcounteren,time
265+
Boot HART PMP Count : 16
266+
Boot HART PMP Granularity : 4
267+
Boot HART PMP Address Bits: 54
268+
Boot HART MHPM Count : 0
269+
Boot HART MHPM Count : 0
270+
Boot HART MIDELEG : 0x0000000000000222
271+
Boot HART MEDELEG : 0x000000000000b109
272+
heap: [0x00326438 - 0x04326438]
273+
274+
\ | /
275+
- RT - Thread Smart Operating System
276+
/ | \ 5.2.0 build Dec 17 2024 11:49:39
277+
2006 - 2024 Copyright by RT-Thread team
278+
lwIP-2.0.3 initialized!
279+
[I/sal.skt] Socket Abstraction Layer initialize success.
280+
[I/utest] utest is initialize success.
281+
[I/utest] total utest testcase num: (0)
282+
[I/drivers.serial] Using /dev/ttyS0 as default console
283+
[W/DFS.fs] mount / failed with file system type: elm
284+
file system initialization done!
285+
Hello RISC-V
286+
msh />[E/sal.skt] not find network interface device by protocol family(1).
287+
[E/sal.skt] SAL socket protocol family input failed, return error -3.
288+
/ # ls
289+
bin lib proc sbin tmp
290+
dev lost+found root services usr
291+
etc mnt run tc var
292+
/ #
293+
```

bsp/xuantie/virt64/c906/run.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
usage ()
4+
{
5+
echo "Usage:"
6+
echo "./run.sh [<path_to_image>]"
7+
echo "Note: if <path_to_image> is not provided, will create a 'sd.bin'"
8+
echo "in the current directory and load it by default."
9+
}
10+
11+
path_image=${1}
12+
13+
if [ -z $path_image ]; then
14+
path_image="./sd.bin"
15+
if [ ! -f $path_image ]; then
16+
dd if=/dev/zero of=$path_image bs=1024 count=65536
17+
mkfs.fat $path_image
18+
fi
19+
fi
20+
21+
if [ ! -f $path_image ]; then
22+
echo "ERROR: $path_image does not exist!"
23+
usage
24+
exit
25+
fi
26+
27+
qemu-system-riscv64 -cpu c906fd -machine virt -m 256M -nographic -kernel rtthread.bin \
28+
-drive if=none,file=$path_image,format=raw,id=blk0 -device virtio-blk-device,drive=blk0,bus=virtio-mmio-bus.0 \
29+
-device virtio-serial-device -chardev socket,host=127.0.0.1,port=4321,server=on,wait=off,telnet=on,id=console0 -device virtserialport,chardev=console0
30+

0 commit comments

Comments
 (0)