1、安装RISCV-tools
/home/yolo/riscv
git clone https://github.com/riscv/riscv-tools.git
cd riscv-tools
git submodule update --init --recursive
如果网不好,可以一个一个安装
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
2、下载riscv gun toolchain
/home/yolo/riscv/riscv-tools
git clone https://github.com/riscv/riscv-gnu-toolchain cd riscv-gnu-toolchain git submodule update --init --recursive
3、先编译riscv gun toolchain,再编译riscv tools
安装依赖包
sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev libnewlib-dev
cd /home/yolo/riscv/riscv-tools/riscv-tools/riscv-gnu-toolchain
vim ~/.bashrc 添加环境变量
export RISCV="/home/yolo/riscv/riscv-tools/riscv-gnu-toolchain"
export PATH=$PATH:$RISCV/bin
然后 source ~/.bashrc
sudo ./configure --prefix=$RISCV sudo make
现在可以可以生成可执行文件hello
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
return 0;
}
riscv64-unknown-elf-gcc -o hello hello.c
这时候的 hello,并不能用./hello执行,因为它是riscv asi的机器码,而我们的计算机是x86平台,我们可以spike模拟器来执行该文件
4、Spike和pk安装
/home/yolo/riscv/riscv-tools/riscv-isa-sim
sudo apt-get install device-tree-compiler
sudo mkdir build
cd build
sudo ../configure --prefix=$RISCV
sudo make
sudo make install
/home/yolo/riscv/riscv-tools/riscv-pk
sudo mkdir build
cd build
sudo ../configure --prefix=$RISCV --host=riscv64-unknown-elf
sudo make
sudo make install
中间有个BUG弄的我想哭
gcc: error: unrecognized argument in option ‘-mcmodel=medany’
gcc: note: valid arguments to ‘-mcmodel=’ are: 32 kernel large medium small; did you mean ‘medium’?
Makefile:332: recipe for target 'file.o' failed
make: *** [file.o] Error 1
就是因为checking for riscv64-unknown-elf-gcc... no
此时,尽管你在 .bashrc中添加RISCV并source,还是不行,需要你单独运行一下
export RISCV="/home/yolo/riscv/riscv-tools/riscv-gnu-toolchain"
export PATH=$PATH:$RISCV/bin
如果还是不行,切换root用户喔
模拟器已完成安装,执行文件hello
spike pk hello
输出“hello,world”,安装成功!
知乎大佬有网盘:https://zhuanlan.zhihu.com/p/162907810
不错的教程:
https://www.cnblogs.com/mikewolf2002/p/10799553.html