Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bsp/qemu-riscv-virt64/.config
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ CONFIG_RT_LIBC_FIXED_TIMEZONE=8
# CONFIG_RT_USING_RYM is not set
# CONFIG_RT_USING_ULOG is not set
# CONFIG_RT_USING_UTEST is not set
# CONFIG_RT_USING_RT_LINK is not set

#
# RT-Thread Utestcases
Expand Down Expand Up @@ -335,6 +336,7 @@ CONFIG_RT_LIBC_FIXED_TIMEZONE=8
# CONFIG_PKG_USING_HELIX is not set
# CONFIG_PKG_USING_AZUREGUIX is not set
# CONFIG_PKG_USING_TOUCHGFX2RTT is not set
# CONFIG_PKG_USING_NUEMWIN is not set

#
# tools packages
Expand Down Expand Up @@ -492,6 +494,7 @@ CONFIG_RT_LIBC_FIXED_TIMEZONE=8
# CONFIG_PKG_USING_LIBNFC is not set
# CONFIG_PKG_USING_MFOC is not set
# CONFIG_PKG_USING_TMC51XX is not set
# CONFIG_PKG_USING_TCA9534 is not set

#
# AI packages
Expand Down Expand Up @@ -519,6 +522,7 @@ CONFIG_RT_LIBC_FIXED_TIMEZONE=8
# CONFIG_PKG_USING_FLEXIBLE_BUTTON is not set
# CONFIG_PKG_USING_CANFESTIVAL is not set
# CONFIG_PKG_USING_ZLIB is not set
# CONFIG_PKG_USING_MINIZIP is not set
# CONFIG_PKG_USING_DSTR is not set
# CONFIG_PKG_USING_TINYFRAME is not set
# CONFIG_PKG_USING_KENDRYTE_DEMO is not set
Expand Down Expand Up @@ -558,7 +562,8 @@ CONFIG_BOARD_virt=y
CONFIG_RT_USING_USERSPACE=y

#
# General Purpose UARTs
# RISCV qemu virt64 configs
#
# CONFIG_BSP_USING_UART1 is not set
# CONFIG_RISCV_S_MODE is not set
CONFIG___STACKSIZE__=16384
136 changes: 136 additions & 0 deletions bsp/qemu-riscv-virt64/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# QEMU/RISCV64 VIRT板级支持包说明

## 1. 简介

RISC-V是一种开放和免费的指令集体系结构(ISA)。本工程是在QEMU的RISCV64 VIRT版本上进行的一份移植。

## 2. 编译说明

首先可以下载交叉编译工具链,建议采用sifive的工具链进行编译。
```
https://www.sifive.com/software
```
选择对应的平台即可。

这里推荐在Ubuntu上进行开发工作。

解压工具链到指定的目录。

```
export RTT_EXEC_PATH=~/gcc/bin
```

进入到`rt-thread/bsp/qemu-riscv-virt64`目录进行输入
```
scons
```
可以看到正常生成`rtthread.elf`与`rtthread.bin`文件。

## 3. 执行

本工程提供了riscv64的两种可配置运行模式,默认运行在M-Mode下。

*M-Mode*

首先安装`qemu-system-riscv64`。

```
sudo apt install qemu-system-misc
```
直接输入
```
./qemu-nographic.sh
```
可以看到程序运行

```
heap: [0x80035804 - 0x86435804]

\ | /
- RT - Thread Operating System
/ | \ 4.0.4 build May 21 2021
2006 - 2021 Copyright by rt-thread team
Hello RISC-V!
msh />
```

*S-Mode*

如果运行在S-Mode下,那么需要通过menuconfig选择配置

```
scons --menuconfig
```
选择如下:
```
RISCV qemu virt64 configs --->
[*] RT-Thread run in riscv smode
```
保存后,重新`scons`编译即可。

要让rt-thread运行在S-Mode,首先需要启动opensbi,然后通过opensbi启动rt-thread。

自行编译的qemu或者下载的高版本的qemu内置opensbi,执行`./qemu-nographic-smode.sh`即可正常运行。

通过`sudo apt install qemu-system-misc`安装的qemu版本较低,可自行编译opensbi。

```
git clone git@github.com:riscv/opensbi.git
cd opensbi
make PLATFORM=generic CROSS_COMPILE=~/gcc/bin/riscv64-unknown-elf-
```
最后生成的`/build/platform/generic/firmware/fw_jump.elf`则是需要的文件。

输入以下的命令即可运行:

```
qemu-system-riscv64 -nographic -machine virt -m 256M -kernel rtthread.bin -bios ~/opensbi/build/platform/generic/firmware/fw_jump.elf
```
可以看到如下的结果
```
OpenSBI v0.9
____ _____ ____ _____
/ __ \ / ____| _ \_ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
\____/| .__/ \___|_| |_|_____/|____/_____|
| |
|_|

Platform Name : riscv-virtio,qemu
Platform Features : timer,mfdeleg
.
.
.
Boot HART ISA : rv64imafdcsu
Boot HART Features : scounteren,mcounteren
Boot HART PMP Count : 16
Boot HART PMP Granularity : 4
Boot HART PMP Address Bits: 54
Boot HART MHPM Count : 0
Boot HART MHPM Count : 0
Boot HART MIDELEG : 0x0000000000000222
Boot HART MEDELEG : 0x000000000000b109
heap: [0x80235a58 - 0x86635a58]

\ | /
- RT - Thread Operating System
/ | \ 4.0.4 build May 21 2021
2006 - 2021 Copyright by rt-thread team
Hello RISC-V!
msh />
```
## 4. 支持情况

| 驱动 | 支持情况 | 备注 |
| ------ | ---- | :------: |
| UART | 支持 | UART0 |
| PLIC | 支持 | - |
| CLIC | 支持 | - |

## 5. 联系人信息

维护人:[bernard][1]

[1]: https://github.com/BernardXiong
6 changes: 5 additions & 1 deletion bsp/qemu-riscv-virt64/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ stack_size = 4096

stack_lds = open('link_stacksize.lds', 'w')
if GetDepend('__STACKSIZE__'): stack_size = GetDepend('__STACKSIZE__')
stack_lds.write('__STACKSIZE__ = %d;' % stack_size)
stack_lds.write('__STACKSIZE__ = %d;\r\n' % stack_size)
if GetDepend('RISCV_S_MODE'): start_addr = int(0x80200000)
else: start_addr = int(0x80000000)
stack_lds.write('__START_ADDR__ = 0x%x;' % start_addr)

stack_lds.close()

# make a building
Expand Down
7 changes: 3 additions & 4 deletions bsp/qemu-riscv-virt64/applications/main.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-05-20 bigmagic first version
*/

#include <rtthread.h>
Expand All @@ -14,9 +15,7 @@

int main(void)
{
void rt_hw_uart_start_rx_thread();
rt_hw_uart_start_rx_thread();
printf("Hello RISC-V\n");
printf("Hello RISC-V!\n");

return 0;
}
7 changes: 5 additions & 2 deletions bsp/qemu-riscv-virt64/driver/Kconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


menu "General Purpose UARTs"
menu "RISCV qemu virt64 configs"

menuconfig BSP_USING_UART1
bool "Enable UART1"
Expand All @@ -14,5 +14,8 @@ menuconfig BSP_USING_UART1
default 21
endif

endmenu
config RISCV_S_MODE
bool "RT-Thread run in riscv smode"
default y

endmenu
Loading