Skip to content

Commit 6b24661

Browse files
unicornxmysterywolf
authored andcommitted
bsp: qemu-virt64-riscv: update README for booting with rootfs
Now lwext4 is ready, and qemu-virt64-riscv smart can boot with rootfs. Updated README to introduce this. This patch also replace qemu-nographic.sh with run.sh, which has a more simple name and more robust to launch rootfs image binary. TBD: qemu-nographic.bat is not touched, hope some guys from Windows can give a hand. Signed-off-by: Chen Wang <[email protected]>
1 parent 1499dbd commit 6b24661

File tree

4 files changed

+219
-23
lines changed

4 files changed

+219
-23
lines changed

bsp/qemu-virt64-riscv/README.md

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ English | [中文](./README_cn.md)
1414
- [3. Running](#3-running)
1515
- [3.1. Installing QEMU](#31-installing-qemu)
1616
- [3.2. Running QEMU](#32-running-qemu)
17+
- [3.2.1. Running RT-Thread Standard Edition](#321-running-rt-thread-standard-edition)
18+
- [3.2.2. Running RT-Thread Smart version](#322-running-rt-thread-smart-version)
19+
- [3.2.3. Running RT-Thread Smart version + Root file-system](#323-running-rt-thread-smart-version--root-file-system)
1720
- [4. How to use rv64ilp32 toolchain](#4-how-to-use-rv64ilp32-toolchain)
1821
- [5. Contact information](#5-contact-information)
1922

@@ -83,8 +86,6 @@ $ cd $WORKSPACE
8386
$ git clone [email protected]:RT-Thread/rt-thread.git
8487
```
8588

86-
**Note: This document is based on the kernel version git commit ID: ebe2926cd6.**
87-
8889
Enter the BSP directory where qemu-virt64-riscv is located. The following operations will not be introduced separately. By default, it is in this directory.
8990

9091
```shell
@@ -153,13 +154,15 @@ Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers
153154
The repository has provided a ready-made execution script, which can be executed directly:
154155

155156
```shell
156-
$ ./qemu-nographic.sh
157+
$ ./run.sh
157158
```
158159

159-
The running results of the RT-Thread Standard version are as follows:
160+
### 3.2.1. Running RT-Thread Standard Edition
161+
162+
The following is an example:
160163

161164
```shell
162-
$ ./qemu-nographic.sh
165+
$ ./run.sh
163166

164167
OpenSBI v0.9
165168
____ _____ ____ _____
@@ -213,11 +216,12 @@ file system initialization done!
213216
Hello RISC-V
214217
msh />
215218
```
219+
### 3.2.2. Running RT-Thread Smart version
216220

217-
The running results of RT-Thread Smart version are as follows:
221+
The following is an example:
218222

219223
```shell
220-
$ ./qemu-nographic.sh
224+
$ ./run.sh
221225

222226
OpenSBI v0.9
223227
____ _____ ____ _____
@@ -273,6 +277,89 @@ Hello RISC-V
273277
msh />
274278
```
275279

280+
### 3.2.3. Running RT-Thread Smart version + Root file-system
281+
282+
For the Smart version of the kernel, you can also specify the path of the root file-system image file when executing the `run.sh` script to mount the root file-system during the startup process.
283+
284+
It should be noted that the kernel supports fat by default. If you want to mount the ext4 file-system, you need to install the lwext4 package additionally, i.e. to enable the `PKG_USING_LWEXT4` option (the specific menuconfig path is (Top) -> RT-Thread online packages -> system packages -> lwext4: an excellent choice of ext2/3/4 filesystem for microcontrollers.). If you can't find the item in the menu, you can exit menuconfig and execute `pkgs --upgrade` to update the package index and then try to enable the package.
285+
286+
After checking this option, you also need to perform the following operations to update the software and install the source code to the packages directory of bsp (this operation only needs to be performed once):
287+
288+
```shell
289+
$ source ~/.env/env.sh
290+
$ pkgs --update
291+
```
292+
293+
Save and recompile the kernel.
294+
295+
For how to make a root file-system, please refer to <https://github.com/RT-Thread/userapps/blob/main/README.md>, which will not be repeated here.
296+
297+
The example is as follows:
298+
299+
```shell
300+
$ ./run.sh /home/u/ws/duo/userapps/apps/build/ext4.img
301+
302+
OpenSBI v0.9
303+
____ _____ ____ _____
304+
/ __ \ / ____| _ \_ _|
305+
| | | |_ __ ___ _ __ | (___ | |_) || |
306+
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
307+
| |__| | |_) | __/ | | |____) | |_) || |_
308+
\____/| .__/ \___|_| |_|_____/|____/_____|
309+
| |
310+
|_|
311+
312+
Platform Name : riscv-virtio,qemu
313+
Platform Features : timer,mfdeleg
314+
Platform HART Count : 1
315+
Firmware Base : 0x80000000
316+
Firmware Size : 100 KB
317+
Runtime SBI Version : 0.2
318+
319+
Domain0 Name : root
320+
Domain0 Boot HART : 0
321+
Domain0 HARTs : 0*
322+
Domain0 Region00 : 0x0000000080000000-0x000000008001ffff ()
323+
Domain0 Region01 : 0x0000000000000000-0xffffffffffffffff (R,W,X)
324+
Domain0 Next Address : 0x0000000080200000
325+
Domain0 Next Arg1 : 0x000000008f000000
326+
Domain0 Next Mode : S-mode
327+
Domain0 SysReset : yes
328+
329+
Boot HART ID : 0
330+
Boot HART Domain : root
331+
Boot HART ISA : rv64imafdcsu
332+
Boot HART Features : scounteren,mcounteren,time
333+
Boot HART PMP Count : 16
334+
Boot HART PMP Granularity : 4
335+
Boot HART PMP Address Bits: 54
336+
Boot HART MHPM Count : 0
337+
Boot HART MHPM Count : 0
338+
Boot HART MIDELEG : 0x0000000000000222
339+
Boot HART MEDELEG : 0x000000000000b109
340+
heap: [0x00326438 - 0x04326438]
341+
342+
\ | /
343+
- RT - Thread Smart Operating System
344+
/ | \ 5.2.0 build Dec 17 2024 11:49:39
345+
2006 - 2024 Copyright by RT-Thread team
346+
lwIP-2.0.3 initialized!
347+
[I/sal.skt] Socket Abstraction Layer initialize success.
348+
[I/utest] utest is initialize success.
349+
[I/utest] total utest testcase num: (0)
350+
[I/drivers.serial] Using /dev/ttyS0 as default console
351+
[W/DFS.fs] mount / failed with file system type: elm
352+
file system initialization done!
353+
Hello RISC-V
354+
msh />[E/sal.skt] not find network interface device by protocol family(1).
355+
[E/sal.skt] SAL socket protocol family input failed, return error -3.
356+
/ # ls
357+
bin lib proc sbin tmp
358+
dev lost+found root services usr
359+
etc mnt run tc var
360+
/ #
361+
```
362+
276363
# 4. How to use rv64ilp32 toolchain
277364

278365
- Toolchain address: <https://github.com/ruyisdk/riscv-gnu-toolchain-rv64ilp32/tags>

bsp/qemu-virt64-riscv/README_cn.md

Lines changed: 95 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
- [3. 运行](#3-运行)
1515
- [3.1. 安装 QEMU](#31-安装-qemu)
1616
- [3.2. 运行 QEMU](#32-运行-qemu)
17+
- [3.2.1. 运行 RT-Thread 标准版](#321-运行-rt-thread-标准版)
18+
- [3.2.2. 运行 RT-Thread Smart 版](#322-运行-rt-thread-smart-版)
19+
- [3.2.3. 运行 RT-Thread Smart 版 + 根文件系统](#323-运行-rt-thread-smart-版--根文件系统)
1720
- [4. 如何使用 rv64ilp32 工具链](#4-如何使用-rv64ilp32-工具链)
1821
- [5. 联系人信息](#5-联系人信息)
1922

@@ -83,8 +86,6 @@ $ cd $WORKSPACE
8386
$ git clone [email protected]:RT-Thread/rt-thread.git
8487
```
8588

86-
**注:本文档基于的内核版本 git commit ID 为: ebe2926cd6。**
87-
8889
进入 qemu-virt64-riscv 所在 BSP 目录,后面的操作不做另外介绍,默认就在这个目录下。
8990

9091
```shell
@@ -153,13 +154,15 @@ Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers
153154
仓库里已经提供了现成的执行脚本,可以直接执行:
154155

155156
```shell
156-
$ ./qemu-nographic.sh
157+
$ ./run.sh
157158
```
158159

159-
RT-Thread 标准版运行结果如下:
160+
### 3.2.1. 运行 RT-Thread 标准版
161+
162+
示例如下:
160163

161164
```shell
162-
$ ./qemu-nographic.sh
165+
$ ./run.sh
163166

164167
OpenSBI v0.9
165168
____ _____ ____ _____
@@ -214,10 +217,12 @@ Hello RISC-V
214217
msh />
215218
```
216219

217-
RT-Thread Smart 版本运行结果如下:
220+
### 3.2.2. 运行 RT-Thread Smart 版
221+
222+
示例如下:
218223

219224
```shell
220-
$ ./qemu-nographic.sh
225+
$ ./run.sh
221226

222227
OpenSBI v0.9
223228
____ _____ ____ _____
@@ -273,6 +278,89 @@ Hello RISC-V
273278
msh />
274279
```
275280

281+
### 3.2.3. 运行 RT-Thread Smart 版 + 根文件系统
282+
283+
对于 Smart 版本的内核,也可以在执行 `run.sh` 脚本时指定根文件系统镜像文件的路径在启动过程中挂载根文件系统。
284+
285+
需要注意的是,内核默认支持 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` 更新软件包索引后再尝试使能软件包。
286+
287+
勾选该选项后还需要执行如下操作更新软件并安装源码到 bsp 的 packages 目录下(该操作只要执行一次即可):
288+
289+
```shell
290+
$ source ~/.env/env.sh
291+
$ pkgs --update
292+
```
293+
294+
保存后重新编译内核。
295+
296+
有关如何制作根文件系统,请参考 <https://github.com/RT-Thread/userapps/blob/main/README.md>,这里不再赘述。
297+
298+
示例如下:
299+
300+
```shell
301+
$ ./run.sh /home/u/ws/duo/userapps/apps/build/ext4.img
302+
303+
OpenSBI v0.9
304+
____ _____ ____ _____
305+
/ __ \ / ____| _ \_ _|
306+
| | | |_ __ ___ _ __ | (___ | |_) || |
307+
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
308+
| |__| | |_) | __/ | | |____) | |_) || |_
309+
\____/| .__/ \___|_| |_|_____/|____/_____|
310+
| |
311+
|_|
312+
313+
Platform Name : riscv-virtio,qemu
314+
Platform Features : timer,mfdeleg
315+
Platform HART Count : 1
316+
Firmware Base : 0x80000000
317+
Firmware Size : 100 KB
318+
Runtime SBI Version : 0.2
319+
320+
Domain0 Name : root
321+
Domain0 Boot HART : 0
322+
Domain0 HARTs : 0*
323+
Domain0 Region00 : 0x0000000080000000-0x000000008001ffff ()
324+
Domain0 Region01 : 0x0000000000000000-0xffffffffffffffff (R,W,X)
325+
Domain0 Next Address : 0x0000000080200000
326+
Domain0 Next Arg1 : 0x000000008f000000
327+
Domain0 Next Mode : S-mode
328+
Domain0 SysReset : yes
329+
330+
Boot HART ID : 0
331+
Boot HART Domain : root
332+
Boot HART ISA : rv64imafdcsu
333+
Boot HART Features : scounteren,mcounteren,time
334+
Boot HART PMP Count : 16
335+
Boot HART PMP Granularity : 4
336+
Boot HART PMP Address Bits: 54
337+
Boot HART MHPM Count : 0
338+
Boot HART MHPM Count : 0
339+
Boot HART MIDELEG : 0x0000000000000222
340+
Boot HART MEDELEG : 0x000000000000b109
341+
heap: [0x00326438 - 0x04326438]
342+
343+
\ | /
344+
- RT - Thread Smart Operating System
345+
/ | \ 5.2.0 build Dec 17 2024 11:49:39
346+
2006 - 2024 Copyright by RT-Thread team
347+
lwIP-2.0.3 initialized!
348+
[I/sal.skt] Socket Abstraction Layer initialize success.
349+
[I/utest] utest is initialize success.
350+
[I/utest] total utest testcase num: (0)
351+
[I/drivers.serial] Using /dev/ttyS0 as default console
352+
[W/DFS.fs] mount / failed with file system type: elm
353+
file system initialization done!
354+
Hello RISC-V
355+
msh />[E/sal.skt] not find network interface device by protocol family(1).
356+
[E/sal.skt] SAL socket protocol family input failed, return error -3.
357+
/ # ls
358+
bin lib proc sbin tmp
359+
dev lost+found root services usr
360+
etc mnt run tc var
361+
/ #
362+
```
363+
276364
# 4. 如何使用 rv64ilp32 工具链
277365

278366
- 工具链地址:https://github.com/ruyisdk/riscv-gnu-toolchain-rv64ilp32/tags

bsp/qemu-virt64-riscv/qemu-nographic.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

bsp/qemu-virt64-riscv/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 -nographic -machine virt -m 256M -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+
-netdev user,id=tap0 -device virtio-net-device,netdev=tap0,bus=virtio-mmio-bus.1 \
30+
-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

0 commit comments

Comments
 (0)