opene906

简介

|--E906_RTL_FACRORY/
  |--gen_rtl/     ## the source verilog code of E906 (CPU核心的RTL代码)
  |--setup/       ## set the environment variables
|--smart_run/     ## the RTL simulation environment (仿真验证用的RTL代码)
  |--impl/        ## sdc file
  |--logical/     ## the SoC demo and test bench to run the simulation 
  |--setup/       ## GNU tool chain setting
  |--tests/       ## include the test suit, linker file, boot code and so on (C代码测试用例)
  |--work/        ## the working directory (若不存在,则需要手动创建。 )
  |--Makefile     ## the simulation script
|--doc/           ## the user and integration manual of E906

详细流程可以参考doc目录下的玄铁E906集成手册(opene906)

编译

安装依赖

sudo apt install iverilog gtkwave
sudo apt install csh

下载工具链

# 玄铁官网下载:裸机程序、linux-64bit工具链(我用WSL2-ubuntu22.2)
Xuantie-900-gcc-elf-newlib-x86_64-V3.1.0-20250522.tar.gz

# README推荐用的是2.03,但是实测3.1.0也可以用。就是有些配置比较麻烦点而已

环境配置

setenv CODE_BASE_PATH /mnt/f/OpenSource/ali/opene906/E906_RTL_FACTORY
setenv TOOL_EXTENSION /home/orig/Xuantie-900-gcc-elf-newlib-x86_64-V3.1.0/bin

csh  # 切换到csh环境
# 分别测试环境变量是否配置成功
echo $CODE_BASE_PATH
echo $TOOL_EXTENSION

# 后续若无特殊提示,则命令均使用csh环境执行

Tips 后续若存在环境问题,则把源码自带的csh脚本对应运行一下

source E906_RTL_FACTORY\setup\setup.csh
source smart_run\setup\example_setup.csh

编译

查看

cd smart_run
make help      # 查看支持命令
make showcase  # 查看支持的测试用例
# 这里以 hello_world 为例

平台RTL编译

由于后续的C代码通过Makefile编译有问题,导致后续的编译流程无法进行,因此这里先单独编译RTL代码。

make compile

测试用例编译

make buildcase CASE=hello_world

波形生成

其中smart_run/Makefile文件中,DUMP变量决定是否生成波形文件。

SIM = iverilog
# DUMP = off
DUMP = on

当然了,如果编译一切顺利,也可以按照官方文档,在make阶段进行传参。

make DUMP=on

仿真和波形查看

# 仿真
vvp xueantie_core.vvp

# 若开启DUMP,则会生成test.vcd波形文件
gtkwave test.vcd

编译问题

  1. 编译错误 Bad fd number 问题
make buildcase CASE=hello_world
  Toolchain path: /home/orig/Xuantie-900-gcc-elf-newlib-x86_64-V3.1.0/bin
/bin/sh: 1: Syntax error: Bad fd number
make[1]: *** [setup/smart_cfg.mk:103: hello_world_build] Error 2
make: *** [Makefile:101: buildcase] Error 2

解决方案: 将smart_cfg.mk文件中最后的重定向删除。

@cd ./work && make -s clean && make -s all CPU_ARCH_FLAG_0=e906f CPU_ARCH_FLAG_1=nodsp  ENDIAN_MODE=little-endian CASENAME=hello_world FILE=hello_world_main >& hello_world_build.case.log
  1. 编译错误 zifencei 问题
编译opene906报错:GNU assembler version 2.42.50 (riscv64-unknown-elf) using BFD version (GNU Binutils) 2.42.50
crt0.s: Assembler messages:
crt0.s:120: Error: unrecognized opcode `fence.i', extension `zifencei' required
crt0.s:130: Error: unrecognized opcode `fence.i', extension `zifencei' required
make[2]: *** [Makefile:100: crt0.o] Error 1
make[1]: *** [setup/smart_cfg.mk:103: hello_world_build] Error 2
make: *** [Makefile:101: buildcase] Error 2

可能原因及解决方案:

  1. 工具链版本不匹配,换!(由于我已经安装了3.1了就懒的重新下载更换了,因此按照2修改)
  2. 添加对应的汇编指令扩展支持
# 在CFLGS中添加扩展支持,但是还会出错。因此按照2的方案进行修改
-march=rv32imac_zifencei
  1. 编译错误 zicsr 问题
/home/orig/Xuantie-900-gcc-elf-newlib-x86_64-V3.1.0/bin/../lib/gcc/riscv64-unknown-elf/14.1.1/../../../../riscv64-unknown-elf/bin/as -v --traditional-format -march=rv32imac_zifencei -march=rv32imac_zifencei -mabi=ilp32f -misa-spec=20191213 -o crt0.o crt0.s

GNU assembler version 2.42.50 (riscv64-unknown-elf) using BFD version (GNU Binutils) 2.42.50
crt0.s: Assembler messages:
crt0.s:29: Error: ilp32f/lp64f ABI can't be used when f extension isn't supported
crt0.s:70: Error: unrecognized opcode `csrw mtvec,x3', extension `zicsr' required
crt0.s:74: Error: unrecognized opcode `csrw mtvt,x3', extension `zicsr' required
crt0.s:103: Error: unrecognized opcode `csrw mstatus,x3', extension `zicsr' required
crt0.s:107: Error: unrecognized opcode `csrs mstatus,x3', extension `zicsr' required
crt0.s:110: Error: unrecognized opcode `csrw mhcr,x3', extension `zicsr' required
crt0.s:112: Error: unrecognized opcode `csrw mhint,x3', extension `zicsr' required
crt0.s:149: Error: unrecognized opcode `csrr x14,mcause', extension `zicsr' required
make: *** [Makefile:100: crt0.o] Error 1

将参数都添加上

-march=rv32imacf_zicsr_zifencei
  1. C语言编译问题 上述两个问题都解决了之后,由于示例代码,存在指针直接复制常数导致编译出错。 因此需要对C语言代码略作修改,加上强制转换即可。这里不详细展开了,毕竟C语言问题很简单。

另外,如果想一劳永逸,可以直接修改源码库,而不是修改work目录下的生成的中间文件。