使用cva6+spike搭建RISC-V环境
# 0.准备
虚拟机:Ubuntu 20.04
sudo apt install -y git curl gcc g++ make autoconf gtkwave
1
1
# 1. Clone cva6
git clone https://github.com/openhwgroup/cva6.git
1
1
cd cva6
1
1
下载子模块
git submodule update --init --recursive
1
1
可能会failed,多执行几次,直到全部下载完成
# 2. Set up environment
mkdir install
1
1
export RISCV="/home/jiaolong/cva6/install"
1
1
export PATH="$PATH:/home/jiaolong/cva6/install/bin"
1
1
路径更换为自己的cva6路径
export为临时更改环境变量
source ~/.bashrc
1
1
./ci/setup.sh
1
1
./ci/install-riscvpk.sh
1
1
# 3.安装Spike和pk
在riscv-isa-sim
路径下打开终端:
apt-get install device-tree-compiler
mkdir build
cd build
../configure --prefix=$RISCV
make
[sudo] make install
1
2
3
4
5
6
2
3
4
5
6
1
2
3
4
5
6
2
3
4
5
6
在riscv-pk
路径下打开终端:
mkdir build
cd build
../configure --prefix=$RISCV --host=riscv64-unknown-elf
make
make install
1
2
3
4
5
2
3
4
5
1
2
3
4
5
2
3
4
5
# 4.1. 编译测试
编写简单测试函数add.c
echo ' #include <stdio.h> int f(int x){ return x+3; } int main(){ printf("hello cva6\n"); printf("%d\n",f(3)); }' > hello.c
1
2
3
4
5
6
7
8
91
2
3
4
5
6
7
8
9使用
riscv64-unknown-elf-gcc
编译RISC-V可执行文件riscv64-unknown-elf-gcc add.c -o add
11使用
spike pk
模拟运行RISC-V指令spike pk add
11使用
riscv64-unknown-elf-gcc
生成RISC-V指令的汇编代码riscv64-unknown-elf-gcc -S add.c -o add.s
11
参考链接:
Last updated: 2022/12/04, 13:58:10