xiuos3/Ubiquitous/XiUOS/board/k210-emulator/README.md

165 lines
5.9 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 从零开始构建矽璓工业物联操作系统使用risc-v架构的k210 emulator
# k210 emulator
[XiUOS](http://xuos.io/) (X Industrial Ubiquitous Operating System) 矽璓XiUOS是一款面向智慧车间的工业物联网操作系统主要由一个极简的微型实时操作系统内核和其上的工业物联框架构成通过高效管理工业物联网设备、支撑工业物联应用在生产车间内实现智能化的“感知环境、联网传输、知悉识别、控制调整”促进以工业设备和工业控制系统为核心的人、机、物深度互联帮助提升生产线的数字化和智能化水平。
>注最新版README请访问[从零开始构建矽璓工业物联操作系统使用risc-v架构的k210 emulator](https://blog.csdn.net/AIIT_Ubiquitous/article/details/116610203),如博客内容与本地文档有差异,以网站内容为准。
## 1. 简介
QEMU 是一个通用的开源模拟器和虚拟化工具。从5.0版本开始QEMU已经可以较完整的支持RISC-V架构。目前XiUOS同样支持运行在QEMU上
| 硬件 | 描述 |
| -- | -- |
|芯片型号| K210 |
|架构| 双核RV64GC |
|主频| 400MHz |
|片内SRAM| 8MB |
| 外设支持 | UART |
XiUOS板级当前支持使用UART。
## 2. 编译说明
**操作系统:** ubuntu18.04 [https://ubuntu.com/download/desktop](https://ubuntu.com/download/desktop)
**开发工具推荐使用 VSCode VScode下载地址为** 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)
### 依赖包安装:
```
$ 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)
新建一个空文件夹并进入文件夹中,并下载源码,具体命令如下:
```c
mkdir test && cd test
git clone https://git.trustie.net/xuos/xiuos.git
```
打开源码文件包可以看到以下目录:
| 名称 | 说明 |
| -- | -- |
| application | 应用代码 |
| board | 板级支持包 |
| framework | 应用框架 |
| fs | 文件系统 |
| kernel | 内核源码 |
| resources | 驱动文件 |
| tool | 系统工具 |
使用VScode打开代码具体操作步骤为在源码文件夹下打开系统终端输入`code .`即可打开VScode开发环境如下图所示
![vscode](img/vscode.jpg)
### 裁减配置工具的下载
**裁减配置工具:** kconfig-frontends [https://forgeplus.trustie.net/projects/xuos/kconfig-frontends](https://forgeplus.trustie.net/projects/xuos/kconfig-frontends)
执行以下命令下载配置工具:
```c
mkdir kfrontends && cd kfrontends
git clone https://git.trustie.net/xuos/kconfig-frontends.git
```
下载源码后按以下步骤执行软件安装:
```c
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),下载完成后,执行以下命令:
```c
sudo tar -xvjf gnu-mcu-eclipse.tar.bz2 -C /opt/
```
在VScode中将上述解压的编译工具链的路径添加到board/k210-emulator/config.mk文件当中操作如下
```c
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`的“命令终端”中执行以下命令,生成配置文件
```
make BOARD=k210-emulator menuconfig
```
2.在menuconfig界面配置需要关闭和开启的功能按回车键进入下级菜单按Y键选中需要开启的功能按N键选中需要关闭的功能配置结束后选择Exit保存并退出本例旨在演示简单的输出例程所以没有需要配置的选项双击快捷键ESC退出配置
![menuconfig1](img/menuconfig1.png)
退出时选择`yes`保存上面所配置的内容,如下图所示:
![menuconfig2](img/menuconfig2.png)
若执行 `make BOARD=k210-emulator menuconfig`后出现以下界面:
![menuconfig3](img/menuconfig3.png)
解决的方法是将终端向上拉伸超过当前界面的三分之二以上,效果如下:
![menuconfig4](img/menuconfig4.png)
3.继续在VScode命令终端中执行以下命令进行编译
```c
make BOARD=k210-emulator
```
4.如果编译正确无误会在build目录下产生XiUOS_k210-emulator.elf、XiUOS_k210-emulator.bin文件。
## 3. 运行
### 3.1 编译并安装QEMU
**QEMU v6.0.0源码下载:** Qemu-K210 Emulator for XiUOS [https://forgeplus.trustie.net/projects/xuos/QemuK210](https://forgeplus.trustie.net/projects/xuos/QemuK210)
```
git clone https://git.trustie.net/xuos/QemuK210.git
sudo apt install ninja-build libpixman-1-dev
cd QemuK210
./configure --target-list=riscv64-softmmu
make
sudo make install
```
### 3.2 运行结果
通过以下命令启动QEMU并加载XiUOS ELF文件
```
qemu-system-riscv64 -nographic -machine sifive_u -bios build/XiUOS_k210-emulator.elf
```
QEMU运行起来后将会在终端上看到信息打印输出
![terminal](img/terminal.png)
### 3.3 调试
利用QEMU可以方便的对XiUOS进行调试首先通过以下命令启动QEMU
```
qemu-system-riscv64 -nographic -machine sifive_u -bios build/XiUOS_k210-emulator.elf -s -S
```
然后要重新开启另一个linux系统终端一个终端执行`riscv-none-embed-gdb`命令
```
riscv-none-embed-gdb build/XiUOS_k210-emulator.elf -ex "target remote localhost:1234"
```