下載編譯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,一個軟件解決你所有需求。用來初學非常合適
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://blog.csdn.net/shensen0304/article/details/95504258
方法二:
2.1 工具鏈去這里下,ubuntu里直接解壓就能用:
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 是自定義安裝目錄,可以去掉
2.2.3 然后qemu的具體的用法和gdb方法,就還是參考這篇文章吧
方法三:
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