- 关于RISCV的综述介绍,请参看本链接
- 此安装步骤基于 Ubuntu 16.04
- 从github上clone的Boom不可以直接运行,需要Rocket Chip Generator以及riscv-tool工具链
- riscv工具可以生成Verilog的仿真器
- 所有的export请自行添加至~/.bashrc
- 本步骤尚不完善,后续及时更新,
- 如有任何建议,请联系lpn709695399@163.com. FPGA启动操作系统
- 相关链接
- 安装步骤
- 请先安装jdk,vcs
- Rocket Chip Generator的安装
- Toolchain的安装
- 切换到Boom分支
- 安装Vivado,请参看vivado安装教程
- FPGA必要文件的生成
- Linux Kernel的生成
- FPGA启动操作系统
- 后记
RISCV综述
boom主页
riscv-toolchain主页
rocket chip generator主页
jdk下载页
vcs下载页(密码: 22f2)
vcs安装教程
vivado安装教程
fpga-zynq主页
- vcs的安装教程访问本链接
- clone rocket-chip
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
- 测试Chisel是否安装成功
cd ~/Software/riscv/rocket-chip/chisel3
sbt compile
# compile the chisel library
sbt test
# run the included unit tests
3. Toolchain的安装
- 添加环境变量至~/.bashrc
export RISCV=$TOP/rocket-chip/riscv-tools/riscv-tc
# 改路径为工具链的安装路径
export PATH=$PATH:$RISCV/bin
- 安装依赖项,生成工具链
- 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
> <font color="red">当前仿真器的编译需要工具链版本为6.1</font>
- 测试工具链是否安装成功,采用riscv的模拟器spike
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
- checkout boom
cd $TOP/rocket-chip
git checkout boom
git submodule update --init
- 生成C模拟器(若想观察Boom的流水线,跳过此块)
cd emulator
make CONFIG=BOOMConfig
# 若想测试benchmark和isa,make run CONFIG=BOOMConfig
- Boom可乱序执行,可以安装gem5,以便观察pipeline
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可退出
- 生成Verilog模拟器
cd vsim
make
5. 安装Vivado,请参看vivado安装教程
Boom的FPGA实验采用Xilinx的ZC706,以下路径中均以该型号示例,其他型号请参看源链接 ucv-bar/fpga-zynq还未跟进,目前以donggyukim/fpga-zynq示例
- clone fpgq-zynq,仍在$(TOP)目录下,将编译好的代码拷贝到该环境中
cd $TOP
git clone https://github.com/donggyukim/fpga-zynq.git
gvim common/Makefrag
# ROCKET_DIR ?= $TOP/rocket-chip
# 如此一来,就将该环境下的rocket设置为之前运行的Rocket环境
- 为方便调试,该工程将对rocket例化adapter,与ARM连接,以便调试
cd zc706
make init-submodules
make rocket
# 此处生成新代码
- 建立Vivado项目
make project
# 此步骤只需要运行一次,此后修改不再执行
- 生成rocketchip_wrapper.bit
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
- 进入SDK界面
- File -> New -> Application Project
- 项目起名 FSBL -> Next
- 选择 Zynq FSBL -> Finish
自动编译,编译过程中遇到部分undefined reference,从FSBL_bsp下的libsrc中拷贝到FSBL的src中即可 如有更好的解决办法,请告知我
- 添加环境变量
export PATH=$SDK_HOME/gnu/arm/lin/bin:$PATH
- 编译工具需要依赖项openssl,部分系统中没有
sudo apt-get install libssl-dev
- 注释Makefile中冗余错误提示代码
# $(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
- 注释Vivado关于LD_LIBRA_PATH的设置
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
- 生成 u-boot.elf
cd ../zc706
make arm-uboot
# 此处会clone u-boot-xlnx
# 若您通过浏览器下载,请注释掉common/Makefrag中的
# git submodule update --init $(uboot_dir)
- 生成boot.bin
-
回到SDK,Xilinx Tools -> Create Zynq Boot Image
-
输出路径为:$REPO/zc706/deliver_output,此路径存放后续往SD卡烧写的文件(若没有,请创建)
-
按序进行以下操作,否则会出错:
- Add -> $REPO/zc706/zc706_rocketchip_BOOMZynqConfig/zc706_rocketchip_BOOMZynqConfig.sdk/FSBL/Debug/FSBL.elf
- 选择Partition type为bootloader,否则工具会自动改为datafile,导致生成失效
- Add -> $REPO/zc706/zc706_rocketchip_BOOMZynqConfig/zc706_rocketchip_BOOMZynqConfig.runs/impl_1/rocketchip_wrapper.bit
- 选择Partition type为datafile
- Add -> $REPO/zc706/soft_build/u-boot.elf
- 选择Partition type为datafile
-
Create Image,BOOT.bin生成到$REPO/zc706/deliver_output
-
若后续对工程进行修改,之前的操作不用再手动执行,可以依据output.bif直接运行
-
make deliver_output/boot.bin
- clone linux-xlnx
# 执行此步骤是因为后续在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
- 生成uImage
- 将在Zynq的ARM核中启动Linux,生成linux的备份
make arm-linux
- 生成devicetree.dtb
- linux将用该文件初始化ARM核的各种外设
make arm-dtb
-
此时deliver_output文件夹应有以下三部分
- BOOT.bin - (the filename is case insensitive, you may see boot.bin). This contains the FSBL, the bitstream with Rocket, and u-boot.
- uImage - Linux for the ARM PS
- devicetree.dtb - Contains information about the ARM core's peripherals for linux.
-
获取ARM上linux的文件系统
make fetch-ramdisk
# 如果不能运行,从Makefile中找到对应链接,通过浏览器下载,拷贝到deliver_output
-
将deliver_output文件拷贝到SD卡的根目录下
- SD_ROOT/
- |-> boot.bin
- |-> devicetree.dtb
- |-> uImage
- |-> uramdisk.image.gz
-
到目前为止,已经生成了在Rocket上运行binaries的环境,此处可以测试FPGA环境是否搭建成功了
- Linux Kernel的获取方式有两种
当前仿真器的编译需要工具链版本为6.1,vmlinux的生成需要工具链版本为7.1,查看工具链版本最方法为riscv64-unknown-linux-gnu-gcc -v 安装6.1版本与之前的6.1安装方法一致,但要注意安装路径不同,环境变量RISCV的设置(可以通过备份两份bashrc,一份编译emulator,一份编译vmlinux) 1. 获取源代码进行编译,参考riscv-tools的教程 > 编译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
2. 下载已经编译好的Binary和Root FS
make fetch-riscv-linux-deliver
# 若无法下载,同样通过浏览器下载即可
在6中已将必要文件生成
- 将相关文件拷入SD卡
- 在win环境下安装CP210x_windows_drivers、Tera Term串口调试工具
相关资料请参考ug961-zc706-GSG、ug1033-cp210x-usb-uart-install、xtp242-zc706-bist-c-2015-4
- 将SD卡插入ZC706,将SW3/SW4拨起(SD卡启动)
boot.bin中有相应的硬件bit文件、操作系统等
- 在ARM将操作系统启动后,输入
./fesvr-zynq pk hello
# 测试RISCV核是否可以正常运行
./fesvr-zynq bbl
# 启动RISCV的操作系统
- 启动RISCV的操作系统后可以查看核的部分信息
cat /proc/cpuinfo
cat /proc/meminfo
# ...
- 在安装过程中可能会遇到各种编译不通过,大多数情况下会是因为github上工程在更新,尝试切换到别的分支
- 定位问题的过程中记得巧用
find
和grep
语句