皋陶 发表于 2021-3-4 18:37:07

RISCV的linux模拟环境搭建整理和总结

本帖最后由 皋陶 于 2021-3-4 18:51 编辑

更详细可参考:开启你RISC-V的开发之旅--RISC-V的linux模拟环境搭建整理和总结
RISCV的linux模拟环境搭建整理和总结

一,有关RISC V的开源代码,可以从改网站的连接进入,该网站归纳整理了有关RISC V的多方面资料: https://cnrv.io/resource

二,自己的虚拟机或linux系统事先安装好

三,装好git工具,因为riscv很多开源的东西需要从git上checkout,这样会方便不少

四,

1. 首先安装开源程序版本管理工具:

(linux)Fedora系统上用 yum 安装,
Debian系统上用apt-get 安装(先安装curl、zlib、openssl、expat、libiconv等库,再从git官网上下载最新版本源代码编译安装);

windows系统上安装msysGit。

具体安装说明:http://blog.jobbole.com/25775/

2. RISC-V工具链.lriscv-tools(https://github.com/riscv/riscv-tools) - 基本上所有RISC-V相关工具链、仿真器、测试的宏项目,包含以下的项目
nriscv-gnu-toolchain(https://github.com/riscv/riscv-gnu-toolchain) - GNU工具链
uriscv-gcc(https://github.com/riscv/riscv-gcc) - GCC 编译器
uriscv-binutils-gdb(https://github.com/riscv/riscv-binutils-gdb) - 二进制工具(链接器,汇编器等·)、GDB 调试工具
uriscv-glibc(https://github.com/riscv/riscv-glibc) - GNU C标准库实现
nriscv-isa-sim(https://github.com/riscv/riscv-isa-sim) - Spike周期精确指令集模拟器
nriscv-llvm(https://github.com/riscv/riscv-llvm) -LLVM编译器框架
uriscv-clang(https://github.com/riscv/riscv-clang) - 基于LLVM框架的C编译器
nriscv-opcodes(https://github.com/riscv/riscv-opcodes) - RISC-V操作码信息和转换脚本
nriscv-tests(https://github.com/riscv/riscv-tests) - RISC-V指令集测试用例
nriscv-fesvr(https://github.com/riscv/riscv-fesvr) - 用于实现在上位机和CPU之间通信机制的库
nriscv-pk(https://github.com/riscv/riscv-pk) - 提供一个运行RISC-V可执行文件运行的最简的程序运行环境,同时提供一个最简单的bootloader
nriscv-qemu(https://github.com/riscv/riscv-qemu) - 一个支持RISC-V的CPU和系统模拟器

gcc configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+
ubuntu自身带有gcc,直接apt-get install gcc(或gc++)安装或更新。
没有安装的linux系统可从svn checkout svn://gcc.gnu.org/svn/gcc/trunk拿最新的gcc代码。
即便如此,在执行riscv-tools下的build.sh脚本时,依然会报如下error:

configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/.See also
http://gcc.gnu.org/install/prerequisites.html for additional info.If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files.They may be located in separate packages.
make: *** 错误 1

所以在网上搜到了如下解决方法:

http://www.multiprecision.org/mpc/   下载最新mpc压缩包
ftp://ftp.gnu.org/gnu/gmp/               下载最新gmp压缩包
http://ftp.gnu.org/gnu/mpfr/             下载最新mpfr压缩包

1.先安装GMP

解压GMP的压缩包后,得到源代码目录gmp-6.1.2。在该目录的同级目录下建立一个临时的编译目录如temp。
进入temp目录,配置安装选项,输入以下命令进行配置:
  ../gmp-6.1.2/configure --prefix=/usr/local/gmp-6.1.2
   make
   sudo make install

2.先安装mpfr.解压mpfr的压缩包,得到源代码目录mpfr-3.1.6。
进入temp目录,配置安装选项,输入以下命令进行配置:
../mpfr-3.1.6/configure --prefix=/usr/local/mpfr-3.1.6
../mpfr-3.1.6/configure --prefix=/usr/local/mpfr-3.1.6 --with-gmp=/usr/local/gmp-6.1.2
make
sudo make install

3.先安装mpc

解压mpc的压缩包,得到源代码目录mpc-1.0.3。
进入temp目录,配置安装选项,输入以下命令进行配置:
../mpc-1.0.3/configure --prefix=/usr/local/mpc-1.0.3
../mpc-1.0.3/configure --prefix=/usr/local/mpc-1.0.3 --with-gmp=/usr/local/gmp-6.1.2 --with-mpfr=/usr/local/mpfr-3.1.6
make
sudo make install

安装/更新gcc:链接的时需要上述3个lib。

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-1.0.3/lib:/usr/local/gmp-6.1.2/lib:/usr/local/mpfr-3.1.6/lib 
../trunk/configure --prefix=/usr/local/gcc-4.8 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-6.1.2 --with-mpfr=/usr/local/mpfr-3.1.6 --with-mpc=/usr/local/mpc-1.0.3
make
make check(可选)
sudo make install

。。。。。。等待。。。。。。
查看当前gcc版本:
/usr/local/gcc-4.8/bin/g++ -v

使用内建 specs
COLLECT_GCC=/usr/local/gcc-4.8/bin/g++
COLLECT_LTO_WRAPPER=/usr/local/gcc-4.8/libexec/gcc/x86_64-unknown-linux-gnu/4.8.4/lto-wrapper

目标:x86_64-unknown-linux-gnu

配置为:
../trunk/configure --prefix=/usr/local/gcc-4.8 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-6.1.2 --with-mpfr=/usr/local/mpfr-3.1.6 --with-mpc=/usr/local/mpc-1.0.3
页: [1]
查看完整版本: RISCV的linux模拟环境搭建整理和总结