Ubuntu 24.04 从零跑通 OpenTitan:IC 验证工程师实录(Verilator + VCS + Verdi)
摘要 :本文记录在 ThinkBook / Ubuntu 24.04 上搭建 lowRISC OpenTitan 的完整过程,涵盖 Verilator 软件仿真、VCS+UVM 块级 DV、Verdi 波形调试,并汇总 Ubuntu 24.04 下的依赖替换、Bazel、License 与覆盖率工具链等踩坑与解法。
环境 :Ubuntu 24.04 LTS | 16GB RAM | OpenTitan @21f062eb| VCS/Verdi V-2023.12-SP2 | Verilator 4.210
标签 :OpenTitanRISC-VUVMVCSVerilatordvsimIC验证Ubuntu24.04
一、为什么要跑 OpenTitan?
OpenTitan 是 lowRISC 主导的开源安全芯片(Root of Trust)项目,包含完整 RTL、UVM 验证环境、软件栈与文档,非常适合 IC 验证工程师:
- 学习 UVM block/toplevel DV 的标准写法(UART DV 是官方模板)
- 熟悉 dvsim 回归流程、testplan、coverage
- 在无商用 EDA 时可用 Verilator 免费跑通软件联调
官方文档:OpenTitan Getting Started
二、硬件与系统要求
| 项目 | 官方建议 | 本机实测 |
|---|---|---|
| 系统 | Linux(CI 为 Ubuntu 22.04) | Ubuntu 24.04 ✅(需自行处理依赖差异) |
| 内存 | 模块级 ≥7GB;全芯片 Verilator 建议 32GB | 16GB + Swap,块级 UART 足够 |
| 磁盘 | 建议 ≥512GB(含工具链) | /home 200GB+ 可用即可 |
| 商用仿真 | VCS / Xcelium(UVM DV) | VCS V-2023.12-SP2 |
| 免费仿真 | Verilator 4.210 | 源码编译安装 |
三、整体路线(两条线)
text
克隆 OpenTitan + apt/Python 依赖
│
├─► 路线 A:Verilator + Bazel(入门,无需 License)
│ └─► uart_smoketest_sim_verilator → PASS
│
└─► 路线 B:VCS + dvsim(验证工程师主战场)
├─► uart_smoke UVM → PASS
├─► --cov 采集 → default.vdb ✅
├─► URG/Verdi -cov 报告 → ❌(本机 License/工具限制)
└─► Verdi -ssf 波形 → ✅(推荐 debug 方式)
四、阶段 0:规划目录
bash
mkdir -p ~/projects ~/tools
export REPO_TOP=~/projects/opentitan
建议将仓库与大型工具链放在 /home,避免根分区空间不足。
五、阶段 1:克隆仓库与系统依赖
5.1 克隆 OpenTitan
bash
cd ~/projects
git clone https://github.com/lowRISC/opentitan.git
cd opentitan
若 GitHub 不稳定,可尝试镜像:
git clone https://ghproxy.com/https://github.com/lowRISC/opentitan.git
5.2 安装 apt 依赖(Ubuntu 24.04 特别注意)
官方 apt-requirements.txt 含 libncursesw5,在 24.04 中已不存在,需替换:
bash
cd ~/projects/opentitan
PKGS=$(sed '/^#/d' apt-requirements.txt | grep -v '^libncursesw5$')
sudo apt install -y $PKGS libncursesw6
5.3 Ubuntu 24.04:Bazel 自带 LLVM 需要 libtinfo5
OpenTitan 预编译 clang 工具链依赖 libtinfo.so.5 ,仅软链到 v6 不够,需安装真实包:
bash
cd /tmp
wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb
wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libncurses5_6.3-2ubuntu0.1_amd64.deb
sudo apt install -y ./libtinfo5_6.3-2ubuntu0.1_amd64.deb ./libncurses5_6.3-2ubuntu0.1_amd64.deb
sudo ln -sf libncursesw.so.6 /usr/lib/x86_64-linux-gnu/libncursesw.so.5
5.4 安装 gcc-11(编译 Verilator 必需)
bash
sudo apt install -y gcc-11 g++-11 python3-venv autoconf flex bison \
libfl2 libfl-dev zlib1g-dev git curl wget
六、阶段 2:Python 虚拟环境
bash
cd ~/projects/opentitan
python3 -m venv .venv
source .venv/bin/activate
pip3 install -U pip "setuptools<66.0.0"
pip3 install -r python-requirements.txt --require-hashes
# 注意:新版仓库脚本路径已变更
python3 ./hw/check_tool_requirements.py
七、阶段 3:编译安装 Verilator 4.210
必须用 GCC 11 编译(GCC 12+ 会导致 Verilator 4.210 编译失败):
bash
export VERILATOR_VERSION=4.210
export VERILATOR_PREFIX="${HOME}/tools/verilator/${VERILATOR_VERSION}"
git clone https://github.com/verilator/verilator.git ~/tools/verilator-src
cd ~/tools/verilator-src
git checkout v${VERILATOR_VERSION}
autoconf
CC=gcc-11 CXX=g++-11 ./configure --prefix="${VERILATOR_PREFIX}"
CC=gcc-11 CXX=g++-11 make -j$(nproc)
make install
# 验证
export PATH="${VERILATOR_PREFIX}/bin:$PATH"
verilator --version # 应显示 Verilator 4.210
写入 ~/.bashrc(可选):
bash
echo 'export PATH="${HOME}/tools/verilator/4.210/bin:$PATH"' >> ~/.bashrc
八、阶段 4:路线 A --- Verilator 软件测试(首个里程碑)
不要使用 apt 安装的 bazel ,使用仓库自带 bazelisk:
bash
cd ~/projects/opentitan
source .venv/bin/activate
export PATH="${HOME}/tools/verilator/4.210/bin:$PATH"
./bazelisk.sh test --test_output=streamed \
//sw/device/tests:uart_smoketest_sim_verilator
成功标志 :日志中出现 PASS!,例如:
text
I00000 status.c:28] PASS!
//sw/device/tests:uart_smoketest_sim_verilator PASSED
首次运行 Bazel 会下载工具链并编译 Verilator 模型,约 10~30 分钟,属正常现象。
九、阶段 5:路线 B --- VCS + UVM(dvsim)
9.1 Synopsys 环境变量(示例)
bash
# ~/.bashrc 或每次手动 source
source ~/synopsys/setup_env.sh
# 典型内容:
# export VCS_HOME=~/synopsys/vcs/V-2023.12-SP2
# export VERDI_HOME=~/synopsys/verdi/V-2023.12-SP2
# export SNPSLMD_LICENSE_FILE=27000@$(hostname -s)
启动 License(若使用本地 License Server):
bash
~/synopsys/start_license.sh
~/synopsys/check_license.sh
9.2 Ubuntu 24.04:VCS 构建需 bash
默认 /bin/sh 指向 dash ,VCS 脚本中 >& 会触发:
text
sh: 1: Syntax error: Bad fd number
解决:
bash
export SHELL=/bin/bash
# 或一次性:sudo ln -sf /bin/bash /bin/sh
9.3 跑 UART smoke(UVM 入门用例)
bash
cd ~/projects/opentitan
source .venv/bin/activate
source ~/synopsys/setup_env.sh
export SHELL=/bin/bash
dvsim hw/ip/uart/dv/uart_sim_cfg.hjson -i uart_smoke
成功标志 :50/50 或设定 reseed 数量全部 PASS,例如:
text
//sw/device/tests uart_smoke PASSED
Executed N out of N tests: N tests passed.
Canonical 学习目录:hw/ip/uart/dv/(env、seq_lib、testplan)。
十、阶段 6:覆盖率与波形
10.1 带覆盖率仿真
bash
dvsim hw/ip/uart/dv/uart_sim_cfg.hjson -i uart_smoke --cov --reseed 3 --purge
export SHELL=/bin/bash
- 仿真 PASS 后,数据在:
scratch/master/uart-sim-vcs/coverage/default.vdb - 不带
--cov不会生成cov_report/dashboard.html(正常)
10.2 URG / Verdi -cov(本机未打通)
在本机环境中:
| 工具 | 现象 |
|---|---|
urg |
License 签出时崩溃 / ptrace 限制 |
verdi -cov |
vdCov SIGSEGV(LicenseCheckUtility) |
dve -cov |
未安装 DVE($VCS_HOME/gui/dve 不存在) |
lmstat 虽能列出 VT_CoverageURG,但进程 checkout 仍可能失败------与 License 实现方式、Ubuntu 24.04 兼容性有关。可尝试:
bash
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
或使用公司正版 License Server、Ubuntu 22.04 VM 再试 URG。
10.3 Verdi 波形调试(推荐,已验证可用)
bash
dvsim hw/ip/uart/dv/uart_sim_cfg.hjson -i uart_smoke --reseed 1 --waves fsdb
verdi -ssf ~/projects/opentitan/scratch/master/uart-sim-vcs/0.uart_smoke/latest/waves.fsdb &
在 nWave 中添加 tb.dut 下信号,配合 run.log 做 UVM debug------这是当前最稳定的商用 EDA 调试闭环。
十一、踩坑速查表
| 现象 | 原因 | 解决 |
|---|---|---|
Unable to locate package libncursesw5 |
Ubuntu 24.04 已移除 | 装 libncursesw6,从 apt-requirements 去掉 w5 |
./util/check_tool_requirements.py 不存在 |
脚本移至 hw/ |
python3 ./hw/check_tool_requirements.py |
Command 'bazel' not found |
未装 Bazel | 使用 ./bazelisk.sh |
configure: error: expected absolute directory for --prefix |
~ 不能用于 configure |
--prefix="${HOME}/tools/verilator/4.210" |
bindgen libclang / NCURSES_TINFO_5 |
缺 libtinfo5 | 安装 jammy 的 libtinfo5、libncurses5 |
Syntax error: Bad fd number |
dash 不支持 >& |
export SHELL=/bin/bash |
cov_report/dashboard.html 不存在 |
未加 --cov 或 URG 失败 |
加 --cov;报告依赖 URG merge |
| URG/Verdi -cov 崩溃 | License/GUI 工具链 | 先用 verdi -ssf 波形;换 License 或 22.04 |
十二、日常环境速查(复制即用)
bash
# 1. License
~/synopsys/start_license.sh
# 2. OpenTitan
cd ~/projects/opentitan
source .venv/bin/activate
source ~/synopsys/setup_env.sh
export PATH="${HOME}/tools/verilator/4.210/bin:$PATH"
export SHELL=/bin/bash
export SNPSLMD_LICENSE_FILE=27000@nick-pc
export LM_LICENSE_FILE=$SNPSLMD_LICENSE_FILE
# 3. 常用命令
./bazelisk.sh test --test_output=streamed //sw/device/tests:uart_smoketest_sim_verilator
dvsim hw/ip/uart/dv/uart_sim_cfg.hjson -i uart_smoke --waves fsdb
十三、最终成果一览
| 能力 | 状态 |
|---|---|
Verilator + Bazel uart_smoketest |
✅ PASS |
VCS + dvsim uart_smoke UVM |
✅ PASS |
--cov 写入 default.vdb |
✅ |
| URG HTML 覆盖率报告 | ❌(环境限制) |
| Verdi FSDB 波形 | ✅ |
结论 :在 Ubuntu 24.04 上,OpenTitan 模块级验证与波形 debug 已可日常开发 ;覆盖率 GUI 可作为后续优化项,不影响阅读 hw/ip/uart/dv、扩展 test、跑回归。
十四、推荐学习路径(验证工程师)
- 第 1 周 :跑通 Verilator smoke + 阅读 HW 文档
- 第 2 周 :精读
hw/ip/uart/dv/,对照uart_testplan.hjson - 第 3 周 :
dvsim跑uart_tx_rx、uart_csr_hw_reset,--waves fsdb+ Verdi - 第 4 周 :了解 DV methodology,尝试
uvmdvgen
十五、参考链接
- OpenTitan 官方 Getting Started:https://opentitan.org/book/doc/getting_started/index.html
- Verilator 安装:https://opentitan.org/book/doc/getting_started/setup_verilator.html
- DV 入门:https://opentitan.org/book/doc/getting_started/setup_dv.html
- UART DV 目录:https://github.com/lowRISC/opentitan/tree/master/hw/ip/uart/dv
- GitHub Issue(Ubuntu 24.04 libncurses):https://github.com/lowRISC/opentitan/issues/24589
附录:一键脚本思路(可选)
可将 apt 修复、venv、Verilator 路径、hw/check_tool_requirements.py、bazelisk 测试写入 ~/projects/setup_opentitan.sh,在终端直接执行。注意 VCS/License 需按本机 Synopsys 安装路径单独配置。
如果本文对你有帮助,欢迎点赞收藏。
声明:请使用合法授权的 EDA 与 License;本文仅作技术学习与开源项目实践记录。