- riscv工具可以生成Verilog的仿真器
- 所有的export请自行添加至~/.bashrc
- 本步骤尚不完善,后续及时更新,
- 如有任何建议,请联系lpn709695399@163.com.
RISCV综述
boom主页
riscv-toolchain主页
rocket chip generator主页
jdk下载页
vcs下载页(密码: 22f2)
vcs安装教程
vivado安装教程
fpga-zynq主页
export TOP=~/riscv
# pwd即为当前tools的安装路径,为方便后续工程的完整性,建议先创建riscv,
# 以下步骤都安装在riscv目录下
cd $TOP
git clone https://github.com/ucb-bar/rocket-chip.git
cd rocket-chip
git submodule update --init
rocke chip generator 的编译过程如下
步骤 | 转换 | 工具 |
---|---|---|
1. | Chisel3 -> Firrtl | sbt |
2. | Firrtl -> Verilog | Firrtl |
3. | Verilog -> C++ | Verilator |
安装Chisel,该工具包含sbt与Firrtl
cd $TOP
echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 642AC823
sudo apt-get update
sudo apt-get install sbt
cd ~/Software/riscv/rocket-chip/chisel3
sbt compile
# compile the chisel library
sbt test
# run the included unit tests
export RISCV=$TOP/rocket-chip/riscv-tools/riscv-tc
# 改路径为工具链的安装路径
export PATH=$PATH:$RISCV/bin
当前仿真器的编译需要工具链版本为6.1
- riscv-gnu-toolchain riscv-V 的交叉编译工具
- riscv-fesvr “front-end” server,通过Host-Target Interface(HTIF)* ,负责host和target处理器间的services calls,提供虚拟的控制台和disk设备
- riscv-isa-sim ISA的simulator和 执行的”golden standard”
- riscv-opcodes 模拟器所有可执行的riscv-V操作码
- riscv-pk 代理核服务通过RISC-V Newlib port编译链接的代码所生成的services system * calls
- riscv-tests 一些assembly示例和benchmarks
cd $TOP/rocket-chip/riscv-tools
git submodule update --init --recursive
# 安装各种依赖项
sudo apt-get install autoconf automake autotools-dev curl device-tree-compiler libmpc-dev libmpfr-dev libgmp-dev libusb-1.0-0-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev
# 生成各种工具
./build.sh
cd $TOP
echo -e '#include <stdio.h>\n int main(void) { printf("Hello world!\\n"); return 0; }' > hello.c
riscv64-unknown-elf-gcc -o hello hello.c
spike pk hello
# 这里之所以需要pk,是因为程序中有printf,该命令需要系统调用
# spike可以找到相对应的$RISCV/riscv-elf/bin/pk
cd $TOP/rocket-chip
git checkout boom
git submodule update --init
cd emulator
make CONFIG=BOOMConfig
# 若想测试benchmark和isa,make run CONFIG=BOOMConfig
sudo apt-get install gem5
gvim boom/src/main/scala/consts.scala
# 启用pipeline trace
# val O3PIPEVIEW_PRINTF = true // dump trace for O3PipeView from gem5
cd emulator
make output/towers.riscv.out
# 运行benchmark中的towers
cd ../
boom/util/pipeview-helper.py -f emulator/output/rv64mi-p-scall.out > cleaned_trace.out
# 这里Python用的是2.x版本
~/Software/gem5/util/o3-pipeview.py --color --store_completions -o pipeview.out cleaned_trace.out
less -r pipeview.out
# 观察pipeline,q可退出
cd vsim
make
Boom的FPGA实验采用Xilinx的ZC706,以下路径中均以该型号示例,其他型号请参看源链接
ucv-bar/fpga-zynq还未跟进,目前以donggyukim/fpga-zynq示例
cd $TOP
git clone https://github.com/donggyukim/fpga-zynq.git
gvim common/Makefrag
# ROCKET_DIR ?= $TOP/rocket-chip
# 如此一来,就将该环境下的rocket设置为之前运行的Rocket环境
cd zc706
make init-submodules
make rocket
# 此处生成新代码
make project
# 此步骤只需要运行一次,此后修改不再执行
cd zc706_rocketchip_BOOMZynqConfig
vivado zc706_rocketchip_BOOMZynqConfig.xpr
# 此处应保证vivado安装成功,相应的环境变量配置完善
# 或者直接运行vivado,打开zc706_rocketchip_BOOMZynqConfig.xpr
# Program and Debug -> Generate Bitstream
* IP Integrator -> Open Block Design(主页说此步骤对于正确生成FSBL很重要)
* Program and Debug -> Generate Bitstream
* 生成的bit文件在为
`$REPO/zc706/zc706_rocketchip_BOOMZynqConfig/zc706_rocketchip_BOOMZynqConfig.runs/impl_1/rocketchip_wrapper.bit`
* 启动SDK之前必须File -> Export Hardware,该步骤会生成
`$REPO/zc706/zc706_rocketchip_BOOMZynqConfig/zc706_rocketchip_BOOMZynqConfig.sdk`
* File -> Launch SDK
sudo apt-get install lib32z1 lib32ncurses5 libbz2-1.0:i386 lib32stdc++6
# 在下一步编译FSBL(First Stage Bootloader)时需要安装的依赖项
生成FSBL.elf
自动编译,编译过程中遇到部分undefined reference,从FSBL_bsp下的libsrc中拷贝到FSBL的src中即可
如有更好的解决办法,请告知我
添加环境变量
export PATH=$SDK_HOME/gnu/arm/lin/bin:$PATH
sudo apt-get install libssl-dev
# $(srctree)/scripts/check-config.sh u-boot.cfg \
# $(srctree)/scripts/config_whitelist.txt ${srctree} 1>&2
# # 参考 http://www.100ask.org/bbs/forum.php?mod=viewthread&tid=15932
gvim $VIVADO_HOME/.settings64-Vivado.sh
# 注释掉所有LD_LIBRA_PATH的设置
LD_LIBRA_PATH为全局设置,影响shell运行时的所有命令
该参数主要针对需要使用Vivado库的AXI BFM而设置
在使用时,部分库文件会发生冲突,如sybol lookup error: awk: undefined symbol: mpfr_z_sub
参考 https://www.xilinx.com/support/answers/66998.html
cd ../zc706
make arm-uboot
# 此处会clone u-boot-xlnx
# 若您通过浏览器下载,请注释掉common/Makefrag中的
# git submodule update --init $(uboot_dir)
生成boot.bin
Create Image,BOOT.bin生成到$REPO/zc706/deliver_output
若后续对工程进行修改,之前的操作不用再手动执行,可以依据output.bif直接运行
make deliver_output/boot.bin
# 执行此步骤是因为后续在make arm-linux中
# git submodule update --init $(arm_linux_dir)
# 可能不能正确执行,若您的环境可以,便可以不执行此操作
# 若您通过浏览器下载,请注释掉Makefile中的这行
cd ../common
git clone https://github.com/Xilinx/linux-xlnx.git
cd linux-xlnx
git submodule update --init --recursive
make arm-linux
make arm-dtb
此时deliver_output文件夹应有以下三部分
获取ARM上linux的文件系统
make fetch-ramdisk
# 如果不能运行,从Makefile中找到对应链接,通过浏览器下载,拷贝到deliver_output
将deliver_output文件拷贝到SD卡的根目录下
到目前为止,已经生成了在Rocket上运行binaries的环境,此处可以测试FPGA环境是否搭建成功了
当前仿真器的编译需要工具链版本为6.1,vmlinux的生成需要工具链版本为7.1,查看工具链版本最方法为riscv64-unknown-linux-gnu-gcc -v
安装6.1版本与之前的6.1安装方法一致,但要注意安装路径不同,环境变量RISCV的设置(可以通过备份两份bashrc,一份编译emulator,一份编译vmlinux)
编译riscv64-unknown-linux-gnu-gcc,这是从Newlib到GNU C的交叉编译,可以通过riscv64-unknown-elf-gcc来编译系统,但是应用就需要通过riscv64-unknown-linux-gnu-gcc来编译了
cd $TOP/riscv-tools/riscv-gnu-toolchain
./configure --prefix=$RISCV
# 生成相应的Makefile
make linux
* **编译linux**
cd $TOP
git clone https://github.com/riscv/riscv-linux.git riscv-linux
# 此环境尚不稳定,可以下载其他分支
# git clone https://github.com/riscv/riscv-linux.git -b riscv-for-submission-v7 riscv-linux
gvim ~/.bashrc
# 将riscv64-unknown-linux-gnu-gcc的路径添加至环境变量
# export PATH=$PATH:~/riscv/rocket-chip/riscv-tools/riscv/bin
source ~/.bashrc
* **配置linux**
cd riscv-linux
make ARCH=riscv defconfig
sudo apt-get install libncurses5-dev libncursesw5-dev
# 安装依赖项
make ARCH=riscv menuconfig
# 图形界面可以配置相应的参数,后续将详述,改配置可以改变.config文件
gvim .config
# 置 CONFIG_CROSS_COMPILE="riscv64-unknown-linux-gnu-"
make -j8 ARCH=riscv
# 若没有设置交叉编译选项,请运行
# # make -j8 ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu-
2. BusyBox,用来配置init和ash applets
cd ../
curl -L http://busybox.net/downloads/busybox-1.26.2.tar.bz2 > busybox-1.26.2.tar.bz2
tar xvjf busybox-1.26.2.tar.bz2
cd busybox-1.26.2
make allnoconfig
# 关闭默认配置
make ARCH=riscv menuconfig
# 找到相应的选项,并配置
# CONFIG_STATIC=y, listed as "Build BusyBox as a static binary (no shared libs)" in BusyBox Settings → Build Options
# CONFIG_CROSS_COMPILER_PREFIX=riscv64-unknown-linux-gnu-, listed "Cross Compiler prefix" in BusyBox Settings → Build Options
# CONFIG_FEATURE_INSTALLER=y, listed as "Support --install [-s] install applet links at runtime" in BusyBox Settings → Include busybox applet
# CONFIG_INIT=y, listed as "init" in Init utilities
# CONFIG_ASH=y, listed as "ash" in Shells
# CONFIG_ASH_JOB_CONTROL=n, listed as "Job control" in Shells
# CONFIG_MOUNT=y, listed as "mount" in Linux System Utilities
# CONFIG_FEATURE_USE_INITTAB=y, listed as "Support reading an inittab file" in Init Utilities
# Applets栏中Coreutils可以选择echo,ls等命令是否可以运
make -j8
# 此后,RISC-V上就可以运行BusyBox了
3. 采用root disk image,将Kernel链接到BusyBox
cd $TOP/riscv-linux
mkdir root
cd root
mkdir -p bin etc dev lib proc sbin sys tmp usr usr/bin usr/lib usr/sbin
cp $TOP/busybox-1.26.2/busybox bin
gvim etc/inittab
# 添加以下四行(去掉‘#’)
# ::sysinit:/bin/busybox mount -t proc proc /proc
# ::sysinit:/bin/busybox mount -t tmpfs tmpfs /tmp
# ::sysinit:/bin/busybox mount -o remount,rw /dev/htifblk0 /
# ::sysinit:/bin/busybox --install -s
# /dev/console::sysinit:-/bin/ash
ln -s ../bin/busybox sbin/init
ln -s sbin/init init
# lrwxrwxrwx 1 init -> sbin/init
# cd sbin ...
# lrwxrwxrwx 1 init -> ../bin/busybox
sudo mknod dev/console c 5 1
# 控制台
find . | cpio --quiet -o -H newc > $TOP/riscv-linux/rootfs.cpio
# intramfs
cd ..
make ARCH=riscv menuconfig
# General Setup -> Initial RAM filesystem and RAM disk -> Initramfs source file -> Input "rootfs.cpio" -> Exit
4. 重新编译riscv-linux和riscv-pk
cd $TOP/riscv-tools/riscv-pk
# pk 中包含Berkeley Boot Loader,即bbl,
mkdir build
cd build
rm -rf *
../configure --prefix=$RISCV --host=riscv64-unknown-linux-gnu --with-payload=$TOP/riscv-linux/vmlinux
make
make install
5. 采用spike模拟器启动linux
spike bbl vmlinux
二. 下载已经编译好的Binary和Root FS
make fetch-riscv-linux-deliver
# 若无法下载,同样通过浏览器下载即可
在6中已将必要文件生成
相关资料请参考ug961-zc706-GSG、ug1033-cp210x-usb-uart-install、xtp242-zc706-bist-c-2015-4
./fesvr-zynq pk hello
# 测试RISCV核是否可以正常运行
./fesvr-zynq bbl
# 启动RISCV的操作系统
cat /etc/cpuinfo
cat /etc/meminfo
# ...
find
和grep
语句