前面我们移植了openc906到淘到的fpga板子上,生成了bit文件。打样的扩展板和器件还没准备好,趁着这个时间我们来跑一遍openc906的仿真,熟悉下。
这里开发环境基于win11+WSL2+Ubuntu24, wsl环境准备可以参考之前分享的文章。
git clone https://github.com/XUANTIE-RV/openc906.git
如果连接不上可以取消代理设置
git config --global --unset http.proxy
git config --global --unset https.proxy
sudo apt install make
sudo apt install gtkwave iverilog
sudo su切换到root用户
sudo apt install csh
sudo nano /etc/passwd
将最后的/bin/bash改为/bin/csh
Ctrl+x退出,提示是否保存修改,输入y回车修改后退出。
重新打开终端,sudo su切换到root用户,并echo $SHELL查看是否切换到了CSH
cd openc906/C906_RTL_FACTORY/
source setup/setup.csh
从以下地址下载
https://www.xrvm.cn/community/download?id=4352528597269942272
我这里下载的是Xuantie-900-gcc-elf-newlib-x86_64-V2.10.2-20240904.tar.gz
wget https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource//1725611943439/Xuantie-900-gcc-elf-newlib-x86_64-V2.10.2-20240904.tar.gz
解压
tar -zxvf Xuantie-900-gcc-elf-newlib-x86_64-V2.10.2-20240904.tar.gz
sudo nano openc906/smart_run/setup/example_setup.csh
设置工具链路径为setenv TOOL_EXTENSION /home/qinyunti/Xuantie-900-gcc-elf-newlib-x86_64-V2.10.2/bin
source openc906/smart_run/setup/example_setup.csh
提示语法错误
root@qinyunti:/home/qinyunti# source openc906/smart_run/setup/example_setup.csh
bash: /*Copyright: No such file or directory
bash: openc906/smart_run/setup/example_setup.csh: line 3: syntax error near unexpected token `('
bash: openc906/smart_run/setup/example_setup.csh: line 3: `Licensed under the Apache License, Version 2.0 (the "License");'
把前面的license部分注释掉
cd openc906/smart_run/
每次重新打开过终端后以下两条指令都需要执行
source ../C906_RTL_FACTORY/setup/setup.csh
source ./setup/example_setup.csh
make help可以查看命令
进行编译make compile,提示没有work目录需要手动创建
root@qinyunti:/home/qinyunti/openc906/smart_run# make compile
[THead-smart] Compiling smart now ...
[THead-smart] SIM = iverilog
/bin/sh: 1: cd: can't cd to ./work
make: *** [Makefile:65: compile] Error 2
创建work目录
mkdir work
在此编译提示以下错误
qinyunti% make compile
[ ] Compiling smart now ...
[ ] SIM = iverilog
iverilog: cannot open command file /gen_rtl/filelists/C906_asic_rtl.fl for reading.
make: *** [Makefile:65: compile] Error 1
qinyunti%
gen_rtl/filelists/C906_asic_rtl位于C906_RTL_FACTORY目录下而不是/目录下
查看Makefile文件
sudo nano Makefile
路径如下
ifeq ($(SIM), iverilog)
SIM_FILELIST := $(SIM_FILELIST) -f ${CODE_BASE_PATH}/gen_rtl/filelists/C906_asic_rtl.fl -f ${CODE_BASE_PATH}/gen_rtl/filelists/tdt>else
SIM_FILELIST := $(SIM_FILELIST) -f ../logical/filelists/sim.fl
endif
qinyunti% echo ${CODE_BASE_PATH}
/home/qinyunti/openc906/smart_run
看到目录对应不上
必须要位于openc906/C906_RTL_FACTORY下执行source ./setup/setup.csh
才会将${CODE_BASE_PATH}设置为openc906/C906_RTL_FACTORY路径才能对应上。
所以正确步骤如下,每一步的路径都要对。
假设当前位于 openc906外,
cd openc906/C906_RTL_FACTORY
source ./setup/setup.csh
然后
cd ../smart_run/
source ./setup/example_setup.csh
然后再make compile
如果还有提示
qinyunti% make compile
[THead-smart] Compiling smart now ...
[THead-smart] SIM = iverilog
xuantie_core.vvp: Permission denied
error: Code generator failure: -1
make: *** [Makefile:65: compile] Error 255
则使用注意要切换到root用户执行
在work目录下生成了vvp文件
qinyunti# ls work
xuantie_core.vvp
qinyunti#
make showcase可以看到caselist
qinyunti# make showcase
Case lists:
ISA_THEAD
ISA_INT
ISA_LS
ISA_FP
coremark
MMU
interrupt
exception
debug
csr
cache
qinyunti#
执行coremark
make runcase CASE=coremark
提示如下错误
qinyunti# make runcase CASE=coremark
[THead-smart] Compiling smart now ...
[THead-smart] SIM = iverilog
Toolchain path: /home/qinyunti/Xuantie-900-gcc-elf-newlib-x86_64-V2.10.2/bin
/bin/sh: 1: Syntax error: Bad fd number
make[2]: *** [setup/smart_cfg.mk:61: coremark_build] Error 2
make[1]: *** [Makefile:101: buildcase] Error 2
make: *** [Makefile:125: runcase] Error 2
qinyunti#
先跳到/bin
cd /bin
cp bash ./sh
再回到smart_run目录下,重新runcase
还有错误
qinyunti# make runcase CASE=coremark
[THead-smart] Compiling smart now ...
[THead-smart] SIM = iverilog
Toolchain path: /home/qinyunti/Xuantie-900-gcc-elf-newlib-x86_64-V2.10.2/bin
make[2]: *** [setup/smart_cfg.mk:61: coremark_build] Error 2
make[1]: *** [Makefile:101: buildcase] Error 2
make: *** [Makefile:125: runcase] Error 2
qinyunti#
查看log
sudo nano work/coremark_build.case.log
看到如下错误
原来是Srec2vmem无可执行权限
添加可执行权限
sudo chmod a+x ./tests/bin/Srec2vmem
重新runcase
make runcase CASE=coremark DUMP=on
DUMP=on表示生成vcd文件。
跑coremark我电脑太慢了,换个简单点的跑
make runcase CASE=csr DUMP=on
这个很快就跑完了
波形文件位于work目录下
test.vcd
输入gtkwave回车,打开gtkwave
打开文件
此时可以双击左边的信号,查看波形
以上跑了一遍仿真,初步了解了整个流程,整个过程有如下几点需要注意
1.需要手动创建work目录
2.需要切换bash为csh,先要安装csh,使用root用户,避免后面权限问题, 注意需要修改root用户的bash为csh。
3.设置环境,注意一定要在openc906/C906_RTL_FACTORY下source,否则目录不对找不到C906_asic_rtl.fl文件。
cd openc906/C906_RTL_FACTORY
source ./setup/setup.csh
4.设置编译器
cd ../smart_run/
source ./setup/example_setup.csh
example_setup.csh文件中前面使用了/**/ 注释不符合语法,改为#注释掉。
5.复制/bin/bash到/bin/sh下
cd /bin
cp bash ./sh
6.Srec2vmem文件添加可执行权限,sudo chmod a+x ./tests/bin/Srec2vmem