Verilator 的设置和安装
备注
如果您在 SpinalHDL 安装和设置 期间安装了推荐的 oss-cad-suite,您可以跳过下面的说明 - 但您需要激活 oss-cad-suite 环境。
Linux 和 Windows 平台均支持 SpinalSim + Verilator。
建议使用的 Verilator 版本最老不低于 v4.218。虽然可以使用较旧的 verilator 版本,但 SpinalHDL 可以使用的一些可选的和 Scala 源文件相关功能(例如 Verilog $urandom
支持)可能不受旧版本 Verilator 支持,并且会在尝试仿真时会导致错误。
理想情况下,最新的 v4.xxx 和 v5.xxx 得到良好支持,并且应针对您遇到的任何问题打开错误报告工单。
Scala
不要忘记在 build.sbt
文件中添加以下内容:
fork := true
你总是需要在Scala测试平台中加入以下导入代码:
import spinal.core._
import spinal.core.sim._
Linux
您还需要安装最新版本的 Verilator:
sudo apt-get install git make autoconf g++ flex bison # First time prerequisites
git clone http://git.veripool.org/git/verilator # Only first time
unsetenv VERILATOR_ROOT # For csh; ignore error if on bash
unset VERILATOR_ROOT # For bash
cd verilator
git pull # Make sure we're up-to-date
git checkout v4.218 # Can use newer v4.228 and v5.xxx
autoconf # Create ./configure script
./configure
make -j$(nproc)
sudo make install
echo "DONE"
Windows
为了让 SpinalSim + Verilator 在 Windows 上工作,您必须执行以下操作:
安装 MSYS2
通过 MSYS2 获取 gcc/g++/verilator (对于 Verilator,您可以从源代码编译它)
将 MSYS2 的
bin
和usr\bin
添加到 WindowsPATH
中(即:C:\msys64\usr\bin;C:\msys64\mingw64 \bin
)检查 JAVA_HOME 环境变量是否指向 JDK 安装文件夹(即:
C:\Program Files\Java\jdk-13.0.2
)
然后您应该能够从 Scala 项目运行 SpinalSim + Verilator,而无需再使用 MSYS2。
从全新安装 MSYS2 MinGW 64 位开始,您必须在 MSYS2 MinGW 64 位 shell 中运行以下命令:
从 MinGW 包管理器安装
pacman -Syuu
# Close the MSYS2 shell once you're asked to
pacman -Syuu
pacman -S --needed base-devel mingw-w64-x86_64-toolchain \
git flex\
mingw-w64-x86_64-cmake
pacman -U http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-verilator-4.032-1-any.pkg.tar.xz
# Add C:\msys64\usr\bin;C:\msys64\mingw64\bin to your Windows PATH
从源码安装
pacman -Syuu
# Close the MSYS2 shell once you're asked to
pacman -Syuu
pacman -S --needed base-devel mingw-w64-x86_64-toolchain \
git flex\
mingw-w64-x86_64-cmake
git clone http://git.veripool.org/git/verilator
unset VERILATOR_ROOT
cd verilator
git pull
git checkout v4.218 # Can use newer v4.228 and v5.xxx
autoconf
./configure
export CPLUS_INCLUDE_PATH=/usr/include:$CPLUS_INCLUDE_PATH
export PATH=/usr/bin/core_perl:$PATH
cp /usr/include/FlexLexer.h ./src
make -j$(nproc)
make install
echo "DONE"
# Add C:\msys64\usr\bin;C:\msys64\mingw64\bin to your Windows PATH
重要
确保您的 PATH
环境变量指向 JDK 1.8 并且不包含 JRE 安装。
重要
将 MSYS2 bin
文件夹添加到 Windows PATH
可能会产生一些副作用。这就是为什么将它们添加为 PATH
的最后一个元素以降低其优先级,这样会更安全。