Skip to content

Commit 83a250f

Browse files
authored
bsp: qemu-virt64-riscv: Improve README (#9651)
Improved README document - Unified the usage process of Standard Edition and Smart Edition. - Deleted the description of running RTT in Machine Mode. Currently, both Standard Edition and Smart Edition RTT run in S-mode by default. At the same time, some unnecessary scripts were cleaned up. Signed-off-by: Chen Wang <[email protected]>
1 parent 908dc68 commit 83a250f

File tree

5 files changed

+622
-240
lines changed

5 files changed

+622
-240
lines changed

bsp/qemu-virt64-riscv/README.md

Lines changed: 301 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,318 @@
1-
# RT-Smart QEMU SYSTEM RISC-V RV64 BSP
1+
**QEMU/RISCV64 VIRT Board Support Package User Guide**
22

3-
English | [中文](./README_ch.md)
3+
English | [中文](./README_cn.md)
44

5-
## 1. Introduction
5+
<!-- TOC -->
66

7-
QEMU can emulate both 32-bit and 64-bit RISC-V CPUs. Use the qemu-system-riscv64 executable to simulate a 64-bit RISC-V machine, qemu-system-riscv32 executable to simulate a 32-bit RISC-V machine.
7+
- [1. Introduction](#1-introduction)
8+
- [2. Building](#2-building)
9+
- [2.1. Installing the toolchain](#21-installing-the-toolchain)
10+
- [2.2. Setting RT-Thread toolchain environment variables](#22-setting-rt-thread-toolchain-environment-variables)
11+
- [2.3. Downloading the kernel](#23-downloading-the-kernel)
12+
- [2.4. Configuring the kernel](#24-configuring-the-kernel)
13+
- [2.5. Compiling the kernel](#25-compiling-the-kernel)
14+
- [3. Running](#3-running)
15+
- [3.1. Installing QEMU](#31-installing-qemu)
16+
- [3.2. Running QEMU](#32-running-qemu)
17+
- [4. How to use rv64ilp32 toolchain](#4-how-to-use-rv64ilp32-toolchain)
18+
- [5. Contact information](#5-contact-information)
819

9-
QEMU has generally good support for RISC-V guests. It has support for several different machines. The reason we support so many is that RISC-V hardware is much more widely varying than x86 hardware. RISC-V CPUs are generally built into “system-on-chip” (SoC) designs created by many different companies with different devices, and these SoCs are then built into machines which can vary still further even if they use the same SoC.
20+
<!-- /TOC -->
1021

11-
For most boards the CPU type is fixed (matching what the hardware has), so typically you don’t need to specify the CPU type by hand, except for special cases like the virt board.
22+
# 1. Introduction
1223

13-
## 2. Building
24+
RISC-V is an open and free instruction set architecture (ISA). This project is a port on the RISCV64 VIRT version of QEMU.
1425

15-
It's tedious to properly build a kernel since each RISC-V toolchain is specified to one RISC-V ISA. So you have to use different toolchain for different RISC-V ISAs.
16-
Here we focus on 2 types of ISA: `rv64imafdcv` and `rv64imac`.
26+
This project supports the world's first rv64ilp32 product-level open source toolchain jointly launched by the Xuantie team and the Institute of Software of the Chinese Academy of Sciences.
1727

18-
If you are not sure what kinds of ISA you need, then `rv64imac` should satisfied your case most time. Given a riscv toolchain, you can check the ISA it supports like this:
28+
# 2. Building
1929

20-
```bash
21-
root@a9025fd90fd4:/home/rtthread-smart# riscv64-unknown-linux-musl-gcc -v
22-
Using built-in specs.
23-
COLLECT_GCC=riscv64-unknown-linux-musl-gcc
24-
COLLECT_LTO_WRAPPER=/home/rtthread-smart/tools/gnu_gcc/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu/bin/../libexec/gcc/riscv64-unknown-linux-musl/10.1.0/lto-wrapper
25-
Target: riscv64-unknown-linux-musl
26-
Configured with: /builds/alliance/risc-v-toolchain/riscv-gcc/configure --target=riscv64-unknown-linux-musl --prefix=/builds/alliance/risc-v-toolchain/install-native/ --with-sysroot=/builds/alliance/risc-v-toolchain/install-native//riscv64-unknown-linux-musl --with-system-zlib --enable-shared --enable-tls --enable-languages=c,c++ --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libsanitizer --disable-nls --disable-bootstrap --src=/builds/alliance/risc-v-toolchain/riscv-gcc --disable-multilib --with-abi=lp64 --with-arch=rv64imac --with-tune=rocket 'CFLAGS_FOR_TARGET=-O2 -mcmodel=medany -march=rv64imac -mabi=lp64 -D __riscv_soft_float' 'CXXFLAGS_FOR_TARGET=-O2 -mcmodel=medany -march=rv64imac -mabi=lp64 -D __riscv_soft_float'
27-
Thread model: posix
28-
Supported LTO compression algorithms: zlib
29-
gcc version 10.1.0 (GCC)
30+
Working system: take Ubuntu 22.04 as an example:
31+
32+
```shell
33+
$ lsb_release -a
34+
No LSB modules are available.
35+
Distributor ID: Ubuntu
36+
Description: Ubuntu 22.04.2 LTS
37+
Release: 22.04
38+
Codename: jammy
39+
```
40+
41+
## 2.1. Installing the toolchain
42+
43+
The specific toolchain used is consistent with the official RT-Thread. For the specific toolchain version, please refer to the file <https://github.com/RT-Thread/rt-thread/blob/master/.github/workflows/action_utest.yml> in the RT-Thread repository.
44+
45+
```yaml
46+
- name: Install RISC-V ToolChains
47+
if: ${{ matrix.legs.QEMU_ARCH == 'riscv64' && matrix.legs.UTEST != 'rtsmart/riscv64' && success() }}
48+
run: |
49+
wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.4/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz
50+
sudo tar zxvf riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz -C /opt
51+
/opt/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin/riscv64-unknown-elf-gcc --version
52+
echo "RTT_EXEC_PATH=/opt/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin" >> $GITHUB_ENV
53+
54+
- name: Install RISC-V Musl ToolChains
55+
if: ${{ matrix.legs.QEMU_ARCH == 'riscv64' && matrix.legs.UTEST == 'rtsmart/riscv64' && success() }}
56+
shell: bash
57+
run: |
58+
wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.7/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu_latest.tar.bz2
59+
sudo tar xjf riscv64-linux-musleabi_for_x86_64-pc-linux-gnu_latest.tar.bz2 -C /opt
60+
/opt/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu/bin/riscv64-unknown-linux-musl-gcc --version
61+
echo "RTT_EXEC_PATH=/opt/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu/bin" >> $GITHUB_ENV
62+
echo "RTT_CC_PREFIX=riscv64-unknown-linux-musl-" >> $GITHUB_ENV
63+
```
64+
65+
Among them, `riscv64-unknown-elf-gcc` is used to build the RT-Thread Standard version, and `riscv64-unknown-linux-musl-gcc` is used to build the RT-Thread Smart version. Download them to your local computer according to the links shown above and decompress them.
66+
67+
## 2.2. Setting RT-Thread toolchain environment variables
68+
69+
There are three environment variables related to the RT-Thread toolchain
70+
71+
- `RTT_CC` is the toolchain name, which is `"gcc"` here
72+
- `RTT_CC_PREFIX`: is the toolchain prefix, which is `"riscv64-unknown-elf-"` for the Standard version and `"riscv64-unknown-linux-musl-"` for the Smart version.
73+
- `RTT_EXEC_PATH`: the path where the bin folder of the toolchain is located, such as `"$HOME/tools/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin"`. This is set according to the actual path after personal download and decompression. Note that the toolchains of the RT-Thread standard version and the Smart version are two different versions, and the path name of `RTT_EXEC_PATH` must be set to `bin`.
74+
75+
If you use them all the time, it is recommended to export these three environment variables in the `.bashrc` file.
76+
77+
## 2.3. Downloading the kernel
78+
79+
Assume that the working path is `$WORKSPACE`.
80+
81+
```shell
82+
$ cd $WORKSPACE
83+
$ git clone [email protected]:RT-Thread/rt-thread.git
84+
```
85+
86+
**Note: This document is based on the kernel version git commit ID: ebe2926cd6.**
87+
88+
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.
89+
90+
```shell
91+
$ cd $WORKSPACE/rt-thread/bsp/qemu-virt64-riscv
92+
```
93+
94+
## 2.4. Configuring the kernel
95+
96+
Refresh the configuration file before compiling for the first time.
97+
98+
```shell
99+
$ scons --menuconfig
100+
```
101+
102+
The default configuration is the RT-Thread standard version, so if you don't have any special requirements, don't change anything, just save and exit.
103+
104+
If you want to use the RT-Thread Smart version, at least turn on the `RT_USING_SMART` option after entering the configuration menu (see the figure below), and the rest depends on your needs.
105+
106+
```
107+
(Top) → RT-Thread Kernel
108+
RT-Thread Project Configuration
109+
(24) The maximal size of kernel object name
110+
[ ] Use the data types defined in ARCH_CPU
111+
[*] Enable RT-Thread Smart (microkernel on kernel/userland)
112+
[ ] Enable RT-Thread Nano
113+
...
114+
```
115+
116+
Save and exit after modification.
117+
118+
## 2.5. Compiling the kernel
119+
120+
If you have compiled before, you can clean it up:
121+
122+
```shell
123+
$ scons --clean
124+
```
125+
126+
Or compile directly:
127+
128+
```shell
129+
$ scons -j$(nproc)
30130
```
31131

32-
The `-march=***` is what you are looking for. And the `-mabi=***` is also an important message to configure compiling script.
132+
The kernel binary file `rtthread.bin` will be generated in the `$WORKSPACE/rt-thread/bsp/qemu-virt64-riscv`.
133+
134+
# 3. Running
135+
136+
## 3.1. Installing QEMU
137+
138+
```shell
139+
$ sudo apt update
140+
$ sudo apt install qemu-system-misc
141+
```
142+
143+
After the installation is complete, you can check the version.
144+
145+
```shell
146+
$ qemu-system-riscv64 --version
147+
QEMU emulator version 6.2.0 (Debian 1:6.2+dfsg-2ubuntu6.24)
148+
Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers
149+
```
150+
151+
## 3.2. Running QEMU
152+
153+
The repository has provided a ready-made execution script, which can be executed directly:
154+
155+
```shell
156+
$ ./qemu-nographic.sh
157+
```
158+
159+
The running results of the RT-Thread Standard version are as follows:
160+
161+
```shell
162+
$ ./qemu-nographic.sh
163+
164+
OpenSBI v0.9
165+
____ _____ ____ _____
166+
/ __ \ / ____| _ \_ _|
167+
| | | |_ __ ___ _ __ | (___ | |_) || |
168+
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
169+
| |__| | |_) | __/ | | |____) | |_) || |_
170+
\____/| .__/ \___|_| |_|_____/|____/_____|
171+
| |
172+
|_|
173+
174+
Platform Name : riscv-virtio,qemu
175+
Platform Features : timer,mfdeleg
176+
Platform HART Count : 1
177+
Firmware Base : 0x80000000
178+
Firmware Size : 100 KB
179+
Runtime SBI Version : 0.2
180+
181+
Domain0 Name : root
182+
Domain0 Boot HART : 0
183+
Domain0 HARTs : 0*
184+
Domain0 Region00 : 0x0000000080000000-0x000000008001ffff ()
185+
Domain0 Region01 : 0x0000000000000000-0xffffffffffffffff (R,W,X)
186+
Domain0 Next Address : 0x0000000080200000
187+
Domain0 Next Arg1 : 0x000000008f000000
188+
Domain0 Next Mode : S-mode
189+
Domain0 SysReset : yes
190+
191+
Boot HART ID : 0
192+
Boot HART Domain : root
193+
Boot HART ISA : rv64imafdcsu
194+
Boot HART Features : scounteren,mcounteren,time
195+
Boot HART PMP Count : 16
196+
Boot HART PMP Granularity : 4
197+
Boot HART PMP Address Bits: 54
198+
Boot HART MHPM Count : 0
199+
Boot HART MHPM Count : 0
200+
Boot HART MIDELEG : 0x0000000000000222
201+
Boot HART MEDELEG : 0x000000000000b109
202+
heap: [0x8028d8a8 - 0x8428d8a8]
203+
204+
\ | /
205+
- RT - Thread Operating System
206+
/ | \ 5.2.0 build Nov 14 2024 15:41:57
207+
2006 - 2024 Copyright by RT-Thread team
208+
lwIP-2.0.3 initialized!
209+
[I/sal.skt] Socket Abstraction Layer initialize success.
210+
[I/utest] utest is initialize success.
211+
[I/utest] total utest testcase num: (0)
212+
file system initialization done!
213+
Hello RISC-V
214+
msh />
215+
```
216+
217+
The running results of RT-Thread Smart version are as follows:
218+
219+
```shell
220+
$ ./qemu-nographic.sh
221+
222+
OpenSBI v0.9
223+
____ _____ ____ _____
224+
/ __ \ / ____| _ \_ _|
225+
| | | |_ __ ___ _ __ | (___ | |_) || |
226+
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
227+
| |__| | |_) | __/ | | |____) | |_) || |_
228+
\____/| .__/ \___|_| |_|_____/|____/_____|
229+
| |
230+
|_|
231+
232+
Platform Name : riscv-virtio,qemu
233+
Platform Features : timer,mfdeleg
234+
Platform HART Count : 1
235+
Firmware Base : 0x80000000
236+
Firmware Size : 100 KB
237+
Runtime SBI Version : 0.2
238+
239+
Domain0 Name : root
240+
Domain0 Boot HART : 0
241+
Domain0 HARTs : 0*
242+
Domain0 Region00 : 0x0000000080000000-0x000000008001ffff ()
243+
Domain0 Region01 : 0x0000000000000000-0xffffffffffffffff (R,W,X)
244+
Domain0 Next Address : 0x0000000080200000
245+
Domain0 Next Arg1 : 0x000000008f000000
246+
Domain0 Next Mode : S-mode
247+
Domain0 SysReset : yes
248+
249+
Boot HART ID : 0
250+
Boot HART Domain : root
251+
Boot HART ISA : rv64imafdcsu
252+
Boot HART Features : scounteren,mcounteren,time
253+
Boot HART PMP Count : 16
254+
Boot HART PMP Granularity : 4
255+
Boot HART PMP Address Bits: 54
256+
Boot HART MHPM Count : 0
257+
Boot HART MHPM Count : 0
258+
Boot HART MIDELEG : 0x0000000000000222
259+
Boot HART MEDELEG : 0x000000000000b109
260+
heap: [0x002ef030 - 0x042ef030]
261+
262+
\ | /
263+
- RT - Thread Smart Operating System
264+
/ | \ 5.2.0 build Nov 14 2024 15:48:43
265+
2006 - 2024 Copyright by RT-Thread team
266+
lwIP-2.0.3 initialized!
267+
[I/sal.skt] Socket Abstraction Layer initialize success.
268+
[I/utest] utest is initialize success.
269+
[I/utest] total utest testcase num: (0)
270+
[I/drivers.serial] Using /dev/ttyS0 as default console
271+
file system initialization done!
272+
Hello RISC-V
273+
msh />
274+
```
275+
276+
# 4. How to use rv64ilp32 toolchain
277+
278+
- Toolchain address: <https://github.com/ruyisdk/riscv-gnu-toolchain-rv64ilp32/tags>
279+
280+
- Usage:
281+
282+
- Configure toolchain path
283+
284+
- Modify ABI parameter to: `-mabi=ilp32d`
285+
286+
- Then perform regular compilation
287+
288+
- Use [script](./qemu-rv64ilp32-nographic.sh) to start QEMU (INFO: QEMU binary is also in the toolchain directory)
289+
290+
- Compare the firmware size of the same project compiled using the traditional 64-bit toolchain and the new 32-bit toolchain:
33291

34-
Steps to build kernel:
292+
Traditional 64-bit toolchain firmware size:
35293

36-
1. in `$RTT_ROOT/bsp/qemu-virt64-riscv/rtconfig.py:40`, make sure `-march=***` and `-mabi=***` is identical to your toolchain
37-
1. if your -march contains characters v/d/f, then: configure kernel by typing `scons --menuconfig` and select `Using RISC-V Vector Extension` / `Enable FPU`
38-
1. `scons`
294+
```bash
295+
Memory region Used Size Region Size %age Used
296+
SRAM: 225856 B 16 MB 1.35%
297+
riscv64-unknown-elf-objcopy -O binary rtthread.elf rtthread.bin
298+
riscv64-unknown-elf-size rtthread.elf
299+
text data bss dec hex filename
300+
150907 3664 71268 225839 3722f rtthread.elf
301+
```
302+
303+
New 32-bit toolchain firmware size:
39304

40-
## 3. Execution
305+
```bash
306+
Memory region Used Size Region Size %age Used
307+
SRAM: 209376 B 16 MB 1.25%
308+
riscv64-unknown-elf-objcopy -O binary rtthread.elf rtthread.bin
309+
riscv64-unknown-elf-size rtthread.elf
310+
text data bss dec hex filename
311+
138739 1356 69276 209371 331db rtthread.elf
312+
```
41313

42-
It's recommended to clone the latest QEMU release and build it locally.
43-
Make sure QEMU is ready by typing `qemu-system-riscv64 --version` in your shell.
314+
# 5. Contact information
44315

45-
Using `qemu-nographic.sh` or `qemu-nographic.bat` to start simulation.
316+
Maintainer: [bernard][1]
46317

47-
> if your -march contains characters v, using qemu-v-nographic.*
318+
[1]: https://github.com/BernardXiong

0 commit comments

Comments
 (0)