feature(doc/appdev): add hifive1 simulator

This commit is contained in:
Liu Yongkai 2021-04-30 17:55:47 +08:00
parent 6da7bdfc74
commit 51ec4d6fdd
2 changed files with 155 additions and 0 deletions

View File

@ -9,3 +9,5 @@
## 使用risc-v架构的开发板
* [KD233](/doc/appdev/start_from_scratch/kd233.md)
* [hifive1 emulator](/doc/appdev/start_from_scratch/hifive1-emulator.md)

View File

@ -0,0 +1,153 @@
# 从零开始构建矽璓工业物联操作系统使用risc-v架构的hifive1 emulator
[XiUOS](http://xuos.io/) (X Industrial Ubiquitous Operating System) 矽璓XiUOS是一款面向智慧车间的工业物联网操作系统主要由一个极简的微型实时操作系统内核和其上的工业物联框架构成通过高效管理工业物联网设备、支撑工业物联应用在生产车间内实现智能化的“感知环境、联网传输、知悉识别、控制调整”促进以工业设备和工业控制系统为核心的人、机、物深度互联帮助提升生产线的数字化和智能化水平。
## 1. 简介
QEMU 是一个通用的开源模拟器和虚拟化工具。从5.0版本开始QEMU已经可以较完整的支持RISC-V架构同时支持SiFive的E系列核心。目前XiUOS同样支持运行在QEMU上
| 硬件 | 描述 |
| -- | -- |
|芯片型号| Hifive1-FE310 |
|架构| RV32IMAC |
|主频| NA |
|片内SRAM| 16KB |
| 外设支持 | UART |
XiUOS板级当前支持使用UART。
## 2. 编译说明
**操作系统:** ubuntu18.04[https://ubuntu.com/download/desktop](https://ubuntu.com/download/desktop)
**开发工具推荐使用 VSCodeVScode下载地址为** VSCode[https://code.visualstudio.com/](https://code.visualstudio.com/),推荐下载地址为 [http://vscode.cdn.azure.cn/stable/3c4e3df9e89829dce27b7b5c24508306b151f30d/code_1.55.2-1618307277_amd64.deb](http://vscode.cdn.azure.cn/stable/3c4e3df9e89829dce27b7b5c24508306b151f30d/code_1.55.2-1618307277_amd64.deb)
### 依赖包安装
```bash
sudo apt install build-essential pkg-config
sudo apt install gcc make libncurses5-dev openssl libssl-dev bison flex libelf-dev autoconf libtool gperf libc6-dev git
```
**XiUOS操作系统源码下载** XiUOS[https://forgeplus.trustie.net/projects/xuos/xiuos](https://forgeplus.trustie.net/projects/xuos/xiuos)
新建一个空文件夹并进入文件夹中,并下载源码,具体命令如下:
```bash
mkdir test && cd test
git clone https://git.trustie.net/xuos/xiuos.git
```
打开源码文件包可以看到以下目录:
| 名称 | 说明 |
| -- | -- |
| application | 应用代码 |
| board | 板级支持包 |
| framework | 应用框架 |
| fs | 文件系统 |
| kernel | 内核源码 |
| resources | 驱动文件 |
| tool | 系统工具 |
使用VScode打开代码具体操作步骤为在源码文件夹下打开系统终端输入`code .`即可打开VScode开发环境如下图所示
<div align="center"><img src = https://img-blog.csdnimg.cn/20210429154839715.jpg width =1000></div>
### 裁减配置工具的下载
**裁减配置工具:** kconfig-frontends [https://forgeplus.trustie.net/projects/xuos/kconfig-frontends](https://forgeplus.trustie.net/projects/xuos/kconfig-frontends)
执行以下命令下载配置工具:
```bash
mkdir kfrontends && cd kfrontends
git clone https://git.trustie.net/xuos/kconfig-frontends.git
```
下载源码后按以下步骤执行软件安装:
```bash
cd kconfig-frontends
./xs_build.sh
```
### 编译工具链
RISC-V: riscv-none-embed-默认安装到Ubuntu的/opt/,下载源码并解压。[下载网址 http://101.36.126.201:8011/gnu-mcu-eclipse.tar.bz2](http://101.36.126.201:8011/gnu-mcu-eclipse.tar.bz2),下载完成后,执行以下命令:
```bash
sudo tar -xvjf gnu-mcu-eclipse.tar.bz2 -C /opt/
```
在VScode中将上述解压的编译工具链的路径添加到board/hifive1-emulator/config.mk文件当中操作如下
```bash
export CROSS_COMPILE ?=/opt/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.1-20190425-1021/bin/riscv-none-embed-
```
若`CROSS_COMPILE` 变量定义语句已经存在,将它替换成上面的语句
# 编译步骤
1.在`VScode`的“命令终端”中执行以下命令,生成配置文件
```bash
make BOARD=hifive1-emulator menuconfig
```
2.在menuconfig界面配置需要关闭和开启的功能按回车键进入下级菜单按Y键选中需要开启的功能按N键选中需要关闭的功能配置结束后选择Exit保存并退出本例旨在演示简单的输出例程所以没有需要配置的选项双击快捷键ESC退出配置
<div align=center><img src="https://img-blog.csdnimg.cn/20210430102341188.png?x-oss-process=none,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0FJSVRfVWJpcXVpdG91cw==,size_16,color_FFFFFF,t_70" /></div>
</br>
退出时选择`yes`保存上面所配置的内容,如下图所示:
</br>
<div align=center><img src="https://img-blog.csdnimg.cn/20210430105320235.jpg?x-oss-process=none,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0FJSVRfVWJpcXVpdG91cw==,size_16,color_FFFFFF,t_70" /></div>
</br>
若执行 `make BOARD=hifive1-emulator menuconfig`后出现以下界面:
<div align=center><img src="https://img-blog.csdnimg.cn/20210429204440614.png" /></div>
解决的方法是将终端向上拉伸超过当前界面的三分之二以上,效果如下:
<div align=center><img src="https://img-blog.csdnimg.cn/20210429204819645.png?x-oss-process=none,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0FJSVRfVWJpcXVpdG91cw==,size_16,color_FFFFFF,t_70" /></div>
</br>
3.继续在VScode命令终端中执行以下命令进行编译
```bash
make BOARD=hifive1-emulator
```
4.如果编译正确无误会在build目录下产生XiUOS_hifive1-emulator.elf、XiUOS_hifive1-emulator.bin文件。
## 3. 运行
### 3.1 编译并安装QEMU
官网下载QEMU源码编译安装推荐使用[QEMU v5.2.0](https://download.qemu.org/qemu-5.2.0.tar.xz)版本如果官网下载速度慢也可从下面链接下载QEMU v5.2.0源码压缩包[下载地址](https://download.qemu.org/qemu-5.2.0.tar.xz),用户可执行下面的命令进行下载并安装`QUME`。
```bash
wget https://download.qemu.org/qemu-5.2.0.tar.xz
tar -xvf qemu-5.2.0.tar.xz
sudo apt install ninja-build libpixman-1-dev
cd qemu-5.2.0
./configure --target-list=riscv32-softmmu
make
sudo make install
```
### 3.2 运行结果
通过以下命令启动QEMU并加载XiUOS ELF文件
```bash
qemu-system-riscv32 -nographic -machine sifive_e -kernel build/XiUOS_hifive1-emulator.elf
```
QEMU运行起来后将会在终端上看到信息打印输出
<div align="center"><img src="https://img-blog.csdnimg.cn/20210430102443529.png?x-oss-process=none,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0FJSVRfVWJpcXVpdG91cw==,size_16,color_FFFFFF,t_70" /></div>
### 3.3 调试
利用QEMU可以方便的对XiUOS进行调试首先通过以下命令启动QEMU
```bash
qemu-system-riscv32 -nographic -machine sifive_e -kernel build/XiUOS_hifive1-emulator.elf -s -S
```
然后要重新开启另一个linux系统终端一个终端执行`riscv-none-embed-gdb`命令
```bash
riscv-none-embed-gdb build/XiUOS_hifive1-emulator.elf -ex "target remote localhost:1234"
```