快速搭建具备一个RISCV开发环境及其qemu仿真(全)

下载编译riscv-gnu-toolchain非常耗时又麻烦。但是如果仅仅是学习测试,可以试试第0种方法,节省大家时间。

   声明:每个人电脑上已经安装过的东西不同,编译时会提示各种缺组件,缺什么安装什么,善用搜索引擎。方法都肯定都走得通。

  一般就是这些

  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

方法零:

 用sifive的Freedom Studio,集成toolchain、qemu、ide,一个软件解决你所有需求。用来初学非常合适

https://www.sifive.com/boards

Freedom Studio is the fastest way to get started

  或者:andes的andesight,和它差不多,3个月免费试用。

 

也可以用buildroot,一键下载、编译 工具链、linux、qemu。

  make qemu_riscv64_virt_defconfig

  make menuconfig

  make

buildroot的国内镜像:https://www.cnblogs.com/qmjc/p/14600173.html

 BR2_BACKUP_SITE="http://sources.buildroot.net"
BR2_KERNEL_MIRROR="https://mirror.bjtu.edu.cn/kernel/"
BR2_GNU_MIRROR="http://mirrors.nju.edu.cn/gnu/"
BR2_LUAROCKS_MIRROR="https://luarocks.cn"
BR2_CPAN_MIRROR="http://mirrors.nju.edu.cn/CPAN/"
是直接编辑的.config文件。也可以在menuconfig时挨个设置

 

 

方法一:

直接去github把这个拉下来编译,如果网速可以的话。

 

 

Technically, binutils with "V" extension support is sufficient to assemble our example. However, building the Proxy-Kernel requires the full GNU toolchain.

 

git clone https://github.com/riscv/riscv-gnu-toolchain.git --branch rvv-0.8.x \
          --single-branch --depth 1 riscv-gnu-toolchain_rvv-0.8.x 

注意这里没有把整个仓库全部下载,而是只下载想用的版本分支
rvv-0.8.x,这样是为了节省时间。国内源代码下载很慢,可以根据方法三,到国内镜像站 gitee 去下载

cd riscv-gnu-toolchain_rvv-0.8.x
git submodule update --init --recursive --depth 1 riscv-binutils riscv-gcc \
                        riscv-glibc riscv-dejagnu riscv-newlib riscv-gdb
mkdir build
cd build
../configure
make
make install

 

The explicit submodule update is done like this to skip the optional Qemu module. Besides Qemu doesn't supporting the "V" extension, it would also require a deeper clone and take up some disk space and waste some compile time.

 

Note that the make install step is superfluous because the previous make call already installs everything.

 

参考:

https://gms.tf/riscv-vector.html#getting-started

https://whycan.cn/t_1685.html

 

同时辅食:

 

https://blog.csdn.net/shensen0304/article/details/95504258

 

 

 

 

方法二:

  2.1 工具链去这里下,ubuntu里直接解压就能用:

 https://www.sifive.com/boards

 

sifive公司编译好的,成品,可以用。参考:https://blog.csdn.net/weiqi7777/article/details/88045720

 

 

 

  2.2 qemu环境

2.2.1 sifive提供的编译好的成品qemu,只有qemu-system-riscv64。

  qemu-system-riscv64 也是可以跑完整的裸机elf程序,甚至bin(这几个脚本很有代表性):

 

qemu-system-riscv64 \
-nographic \
-machine virt \
-bios none
-kernel ./test/rv64-virt-rvv10.elf

 

qemu-system-riscv64 \
-nographic \
-machine virt \
-m 128
-nographic \
-bios none \
-cpu rv64,x-v=true,vlen=512,elen=64,vext_spec=v1.0 \
-device loader,file=./rv64-virt-rvv07.elf 

 

 

qemu-system-riscv64 \
-nographic \
-machine virt \
-bios ./test/rv64-virt-rvv10.bin

 

 

 

 

 

我需要qemu-riscv64(相当于自带linux kernel,只模拟运行app程序),所以自己编译一个。

去官网下完整源代码包

 https://www.qemu.org/download/#source

 

 

2.2.2 解压后,参考这篇文章编译,提示需要的其他组件,自行搜索安装。注意qemu配置项不要按照他的来,

我是用的 4.2.0 版本源码,配置项用这个: 

       ./configure --target-list="riscv64-linux-user" --enable-user --prefix=~/qemu-riscv

"riscv64-linux-user" --enable-user     是为了编译出 qemu-riscv64 这个可执行文件而不是 qemu-system-riscv64

--prefix=~/qemu-riscv                        是自定义安装目录,可以去掉

https://my.oschina.net/kelvinxupt/blog/265108

 

 

2.2.3 然后qemu的具体的用法和gdb方法,就还是参考这篇文章吧

https://whycan.cn/t_1685.html

 

 

方法三:

3.1 qemu的部分和方法二一样。

 

3.2 riscv-gnu-toolchain部分:

3.2.1 源代码下载很慢,建议到国内镜像站 gitee 去下载

https://gitee.com/mirrors/riscv-gnu-toolchain.git

下载速度10MB/s,对比github 10KB/s

 

3.2.2 改git

3.2.2.1 改riscv-gnu-toolchain目录下的 .gitmodule文件:更改那几个子模组的url,改成gitee的网址。

       大概改成这样,不改或许也会自动定位到gitee,没试过。

[submodule "riscv-binutils"]
path = riscv-binutils
url = https://gitee.com/mirrors/riscv-binutils-gdb.git
[submodule "riscv-gcc"]
path = riscv-gcc
url = https://gitee.com/mirrors/riscv-gcc.git
[submodule "riscv-glibc"]
path = riscv-glibc
url = https://gitee.com/mirrors/riscv-glibc.git
[submodule "riscv-dejagnu"]
path = riscv-dejagnu
url = https://gitee.com/mirrors/riscv-dejagnu.git
[submodule "riscv-newlib"]
path = riscv-newlib
url = https://gitee.com/mirrors/riscv-newlib.git
[submodule "riscv-gdb"]
path = riscv-gdb
url = https://gitee.com/mirrors/riscv-binutils-gdb.git

3.2.2.2 删除qemu模块:这个模块不需要了,还子孙众多,改git麻烦,直接删了。去网上搜索:git删除子模块

 

    或者

git submodule update --init --recursive --depth 1 riscv-binutils riscv-gcc \
                        riscv-glibc riscv-dejagnu riscv-newlib riscv-gdb
mkdir build
cd build
../configure
make
make install

The explicit submodule update is done like this to skip the optional Qemu module. Besides Qemu doesn't supporting the "V" extension, it would also require a deeper clone and take up some disk space and waste some compile time.

 

3.2.2.3 然后就可以 10MB/s下载子模块。riscv-gnu-toolchain目录下:

git submodule update --init --recursive

编译:

  https://gms.tf/riscv-vector.html#getting-started

https://whycan.cn/t_1685.html

 

posted @ 2020-04-13 17:16  园友1683564  阅读(5878)  评论(0编辑  收藏  举报