目录
在centos7系统上安装riscv-tools仿真工具(在装过riscv-gnu-toolchain交叉编译器情况下安装此仿真工具)。
两者的关系:riscv-gnu-toolchain是编译环境,利用这个工具链对C/C++文件进行编译,生成一个输出文件(file.o或者file.ELF类型),riscv-tools是仿真工具(模拟目标机器),对前面输出的可执行文件(.o类型)进行仿真。
1、安装软件包
对于Ubuntu :
$ sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev libusb-1.0-0-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev device-tree-compiler pkg-config libexpat-dev
对于Fedora :
$ sudo dnf install autoconf automake @development-tools curl dtc libmpc-devel mpfr-devel gmp-devel libusb-devel gawk gcc-c++ bison flex texinfo gperf libtool patchutils bc zlib-devel expat-devel
具体细节见:https://github.com/riscv-software-src/riscv-tools
但是我的Linux系统是centos7,对于centos在装过riscv-gnu-toolchain交叉编译器情况下,主要查看device-tree-compiler(即dtc工具)是否拥有。
2、设置环境变量
vim ~/.bashrc
export RISCV="/opt/riscv64" ///opt/riscv是工具的安装链接路径(与之前riscv-gnu-toolchain路径一致)
export PATH=$PATH:$RISCV/bin //$RISCV/bin链接工具的位置
:wq #保存退出
source ~/.bashrc //使此设置永久有效,不然每次打开终端都需要重新设置
3、下载并编译riscv-fesvr
git clone https://github.com/riscv/riscv-fesvr.git
cd riscv-fesvr #克隆完成进入克隆下来的目录
mkdir build && cd build #创建并进入build文件夹
../configure --prefix=$RISCV --target=riscv64-unknown-elf #检查环境并生成当前环境使用的Makefile,如果需要指定编译链的输出目录,就可以把R I S C V 改 为 相 应 目 录 或 者 配 置 RISCV改为相应目录或者配置RISCV改为相应目录或者配置RISCV环境变量为相应的目录。如果没有配置就默认为/bin --target=为你的编译链的路径
[sudo] make install #编译安装,[sudo]代表sudo可选,安装输出目录的读写全写的实际情况选择
具体细节见:https://github.com/riscv/riscv-fesvr.git
4、下载riscv-tools
git clone --recursive https://github.com/riscv/riscv-tools.git
会下载下面的几个模块
- Spike, the ISA simulator
- riscv-tests, a battery of ISA-level tests
- riscv-opcodes, the enumeration of all RISC-V opcodes executable by the simulator
- riscv-pk, which contains
bbl
, a boot loader for Linux and similar OS kernels, andpk
, a proxy kernel that services system calls for a target-machine application by forwarding them to the host machine
具体源码查看:https://github.com/riscv-software-src/riscv-tools
如果网络环境不好,可以使用下面命令一个模块一个模块单独下载:
git clone --recursive https://github.com/riscv/riscv-openocd.git
git clone --recursive https://github.com/riscv/riscv-isa-sim.git
git clone --recursive https://github.com/riscv/riscv-opcodes.git
git clone --recursive https://github.com/riscv/riscv-pk.git
git clone --recursive https://github.com/riscv/riscv-tests.git
下载完成后编译riscv-tools(注意:先编译riscv gun toolchain和riscv-fesvr,最后编译riscv tools,否则pk模块会编译出错)
编译指令:
./build.sh
或者是其他可执行文件的命令:./build-spike-pk.sh
5、测试环境
5.1、创建hello.c文件
#include <stdio.h>
int main(void)
{
printf("Hello Word!\n");
return 0;
}
5.2、编译执行
/opt/riscv64/bin/riscv64-unknown-elf-gcc hello.c -o hello.o
/opt/riscv64/bin/spike pk hello.o
5.3、执行结果
bbl loader
hello, word
如图: