在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 32708|回复: 44

[原创] RISCV的linux模拟环境搭建整理和总结

[复制链接]
发表于 2017-11-17 17:00:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
一,有关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工具链
l  riscv-tools(https://github.com/riscv/riscv-tools) - 基本上所有RISC-V相关工具链、仿真器、测试的宏项目,包含以下的项目
n  riscv-gnu-toolchain(https://github.com/riscv/riscv-gnu-toolchain) - GNU工具链
u  riscv-gcc(https://github.com/riscv/riscv-gcc) - GCC 编译器
u  riscv-binutils-gdb(https://github.com/riscv/riscv-binutils-gdb) - 二进制工具(链接器,汇编器等·)、GDB 调试工具
u  riscv-glibc(https://github.com/riscv/riscv-glibc) - GNU C标准库实现
n  riscv-isa-sim(https://github.com/riscv/riscv-isa-sim) - Spike周期精确指令集模拟器
n  riscv-llvm(https://github.com/riscv/riscv-llvm) -LLVM编译器框架
u  riscv-clang(https://github.com/riscv/riscv-clang) - 基于LLVM框架的C编译器
n  riscv-opcodes(https://github.com/riscv/riscv-opcodes) - RISC-V操作码信息和转换脚本
n  riscv-tests(https://github.com/riscv/riscv-tests) - RISC-V指令集测试用例
n  riscv-fesvr(https://github.com/riscv/riscv-fesvr) - 用于实现在上位机和cpu之间通信机制的库
n  riscv-pk(https://github.com/riscv/riscv-pk) - 提供一个运行RISC-V可执行文件运行的最简的程序运行环境,同时提供一个最简单的bootloader
n  riscv-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: *** [stamps/build-gcc-newlib] 错误 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
 楼主| 发表于 2017-11-30 16:44:28 | 显示全部楼层
Boom环境搭建

1,从github上克隆boom仿真器:

   $ git clone https://github.com/ucb-bar/rocket-chip.git
   $ cd rocket-chip
   $ git checkout boom
   $ git submodule update --init
   $ cd emulator; make run CONFIG=BOOMConfig

2,RISC-V Toolchain安装

   $ export RISCV=/path/to/install/riscv/toolchain   
   $ export PATH="${PATH}RISCV/bin"
   $ git clone https://github.com/ucb-bar/rocket-chip.git
   $ cd rocket-chip
   $ git checkout boom
   $ git submodule update --init
   $ cd riscv-tools
   $ git submodule update --init --recursive
   $ ./build.sh                                     //安装
   $ cd ../emulator; make run CONFIG=BOOMConfig     //配置为boom模式
 楼主| 发表于 2017-12-8 11:12:23 | 显示全部楼层
https://github.com/riscv/riscv-tools上有一个文件README.md,安装步骤和提示按照上面指示的一步一步来,肯定可以成功安装riscv toolchain.... 本人在ubuntu上安装,在./build.sh时总是会报error,后来把该README.md里包含的所有库都装了一遍,配置好.bashrc文件后,再次./build.sh, 经过漫长的等待,最终显示:
RISC-V Toolchain installation completed!
-------------------------------------------------------------------------------
riscv-toolchain安装好这个只是第一步,后面仿真所依赖的仿真工具vcs/modelsim和波形查看工具verdi等的安装是另一个大问题。首先你要下载到支持你当前虚拟机版本的仿真工具。不同的虚拟机系统如redhat和ubuntu的vcs工具需要下载不同的安装包,破解也不同。
--------------------------------------------------------------------------------
欢迎  各位大神有更好建议的,留言讨论。
发表于 2017-12-8 11:29:39 | 显示全部楼层
好文,已发到EETOP微信
 楼主| 发表于 2017-12-12 14:15:40 | 显示全部楼层
本帖最后由 birdman007 于 2017-12-12 14:27 编辑

ubuntu虚拟机空间不够用,重新安装过后,再次安装了java, gmp, mpfr, mpc,gcc后,一定要记得需要修改/etc/profile文件。在profile文件末尾添加如下环境变量配置语句:
export JAVA_HOME=/usr/java/jdk1.8.0_151
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:%{JAVA_HOME}/jre/lib/:%{JRE_HOME}/lib
export PATH=${JAVA_HOME}/binPATH   ## bin和PATH间是:冒号美元符号

添加完成后记得source一下:
source /etc/profile

注:
若profile文件不能写入,可用chmod来修改其读写权限,改完profile文件后,一定要记着在把profile的访问权限该回去。例如:
sudo chmod -c 777 profile  ## 打开所有读写编译权限
sudo chmod -c 644 profile  ## 改回profile文件原权限属性
 楼主| 发表于 2017-12-12 14:21:03 | 显示全部楼层
在riscv-tool安装,相关库安装过程中需要export多个环境变量,建议将所有的export写入~/.bashrc文件中。如在.bashrc文件尾追加如下代码:
# set env-var
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr    /games:/usr/local/games
#------------------------------------------------------------------------
export JAVA_HOME=/usr/java/jdk1.8.0_151
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.{JAVA_HOME}/lib{JRE_HOME}/lib
export PATH=${JAVA_HOME}/binPATH

export C_INCLUDE_PAth=$C_INCLUDE_PATH:/usr/mpc-1.0.3/include:/usr/gmp-6.1.2/i    nclude:/usr/mpfr-3.1.6/include
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/mpc-1.0.3/lib:/usr/gmp-6.1.2/lib    :/usr/mpfr-3.1.6/lib

export RISCV=/usr/riscv/toolchain
export PATH=$PATH:$RISCV/bin
echo "bashrc script source finished..."
 楼主| 发表于 2017-12-15 17:07:24 | 显示全部楼层
版本够用就行,不用下载更新的,除非报错
mpfr下载官网:http://www.mpfr.org/mpfr-current/
gmp下载官网:https://gmplib.org
mpc下载官网:http://www.multiprecision.org/in ... c&page=download
 楼主| 发表于 2017-12-15 17:31:17 | 显示全部楼层
发表于 2018-1-14 16:21:44 | 显示全部楼层
好文章,对于新手还是很有帮助的
发表于 2018-3-10 00:36:45 | 显示全部楼层
回复 1# birdman007


   Creating observer.htmpCreating observer.itmp
In file included from /home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:26:0:
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui-data.h:42:3: error: ‘WINDOW’ does not name a type
   WINDOW *handle;     /* Window handle.  */
   ^
In file included from /home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:31:0:
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui-win.h:40:8: error: ‘chtype’ does not name a type
extern chtype tui_border_ulcorner;
        ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui-win.h:41:8: error: ‘chtype’ does not name a type
extern chtype tui_border_urcorner;
        ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui-win.h:42:8: error: ‘chtype’ does not name a type
extern chtype tui_border_lrcorner;
        ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui-win.h:43:8: error: ‘chtype’ does not name a type
extern chtype tui_border_llcorner;
        ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui-win.h:44:8: error: ‘chtype’ does not name a type
extern chtype tui_border_vline;
        ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui-win.h:45:8: error: ‘chtype’ does not name a type
extern chtype tui_border_hline;
        ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c: In function ‘int tui_rl_other_window(int, int)’:
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:240:36: error: ‘struct tui_gen_win_info’ has no member named ‘handle’
       keypad (TUI_CMD_WIN->generic.handle, (win_info != TUI_CMD_WIN));
                                    ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:240:69: error: ‘keypad’ was not declared in this scope
       keypad (TUI_CMD_WIN->generic.handle, (win_info != TUI_CMD_WIN));
                                                                     ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c: In function ‘void tui_enable()’:
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:409:7: error: ‘WINDOW’ was not declared in this scope
       WINDOW *w;
       ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:409:15: error: ‘w’ was not declared in this scope
       WINDOW *w;
               ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:410:7: error: ‘SCREEN’ was not declared in this scope
       SCREEN *s;
       ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:410:15: error: ‘s’ was not declared in this scope
       SCREEN *s;
               ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:425:39: error: ‘newterm’ was not declared in this scope
       s = newterm (NULL, stdout, stdin);
                                       ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:437:11: error: ‘stdscr’ was not declared in this scope
       w = stdscr;
           ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:442:37: error: ‘tigetstr’ was not declared in this scope
       cap = tigetstr ((char *) "cup");
                                     ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:445:12: error: ‘endwin’ was not declared in this scope
    endwin ();
            ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:446:16: error: ‘delscreen’ was not declared in this scope
    delscreen (s);
                ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:453:15: error: ‘cbreak’ was not declared in this scope
       cbreak ();
               ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:454:15: error: ‘noecho’ was not declared in this scope
       noecho ();
               ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:456:23: error: ‘nodelay’ was not declared in this scope
       nodelay(w, FALSE);
                       ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:457:10: error: ‘nl’ was not declared in this scope
       nl();
          ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:458:22: error: ‘keypad’ was not declared in this scope
       keypad (w, TRUE);
                      ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:460:31: error: ‘LINES’ was not declared in this scope
       tui_set_term_height_to (LINES);
                               ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:461:30: error: ‘COLS’ was not declared in this scope
       tui_set_term_width_to (COLS);
                              ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:462:22: error: ‘def_prog_mode’ was not declared in this scope
       def_prog_mode ();
                      ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:467:36: error: ‘struct tui_gen_win_info’ has no member named ‘handle’
       keypad (TUI_CMD_WIN->generic.handle, TRUE);
                                    ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:468:38: error: ‘struct tui_gen_win_info’ has no member named ‘handle’
       wrefresh (TUI_CMD_WIN->generic.handle);
                                      ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:468:44: error: ‘wrefresh’ was not declared in this scope
       wrefresh (TUI_CMD_WIN->generic.handle);
                                            ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:475:22: error: ‘def_shell_mode’ was not declared in this scope
      def_shell_mode ();
                      ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:476:15: error: ‘stdscr’ was not declared in this scope
      clearok (stdscr, TRUE);
               ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:476:27: error: ‘clearok’ was not declared in this scope
      clearok (stdscr, TRUE);
                           ^
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c: In function ‘void tui_disable()’:
/home/sun/Desktop/RISC-V/riscv-tools/riscv-gnu-toolchain/build/../riscv-binutils-gdb/gdb/tui/tui.c:530:11: error: ‘endwin’ was not declared in this scope
   endwin ();
           ^
make[3]: *** [tui.o] Error 1
make[2]: *** [all-gdb] Error 2
make[1]: *** [all] Error 2
make: *** [stamps/build-binutils-newlib] Error 2


求赐教,谢谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-3-29 02:04 , Processed in 0.045015 second(s), 6 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表