Ubuntu 24.04 从零跑通 OpenTitan:IC 验证工程师实录(Verilator + VCS + Verdi)

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
标签OpenTitan RISC-V UVM VCS Verilator dvsim IC验证 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.txtlibncursesw5,在 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. 第 1 周 :跑通 Verilator smoke + 阅读 HW 文档
  2. 第 2 周 :精读 hw/ip/uart/dv/,对照 uart_testplan.hjson
  3. 第 3 周dvsimuart_tx_rxuart_csr_hw_reset--waves fsdb + Verdi
  4. 第 4 周 :了解 DV methodology,尝试 uvmdvgen

十五、参考链接


附录:一键脚本思路(可选)

可将 apt 修复、venv、Verilator 路径、hw/check_tool_requirements.py、bazelisk 测试写入 ~/projects/setup_opentitan.sh,在终端直接执行。注意 VCS/License 需按本机 Synopsys 安装路径单独配置


如果本文对你有帮助,欢迎点赞收藏。
声明:请使用合法授权的 EDA 与 License;本文仅作技术学习与开源项目实践记录。

相关推荐
一叶龙洲1 小时前
向日葵远程Ubuntu,支持隐私屏
linux·运维·ubuntu
寒水馨2 小时前
Linux下载、安装llama.cpp-b10068(附安装包llama-b10068-bin-ubuntu-vulkan-x64.tar.gz)
linux·ubuntu·llm·llama·本地部署·llama.cpp·推理引擎
ziguo11225 小时前
C/C++ 错误处理全解:从 errno 到 C++ 异常
linux·c语言·c++·windows·visual studio
三8446 小时前
使用Samba/NFS实现文件共享/自动挂载共享目录/autofs自动挂载服务
linux·服务器·网络
高铭杰7 小时前
万物皆可KV(2)SurrealDB 存储布局分析
linux·服务器
无小道8 小时前
深入解析操作系统文件缓冲区:页缓存、基数树与f_pos的协同设计
linux·缓存·文件缓冲区
AOwhisky9 小时前
Linux(CentOS)系统管理入门笔记(第十二期)——系统管理工具与软件包管理(上篇):Cockpit 与 RPM 包管理
linux·运维·笔记·centos·云计算
寒水馨9 小时前
Linux下载、安装godot-4.7.1-stable(附安装包Godot_v4.7.1-stable_linux.x86_64.zip)
linux·游戏引擎·godot·游戏开发·2d游戏·3d游戏·godot engine
念恒123069 小时前
Socket编程UDP(中)
linux·网络协议·udp
深耕运维十八载云架构实务9 小时前
系统故障玄学之内存明明显示空闲,服务器却频繁卡顿卡死?拆解被忽略的 Linux 隐性内存陷阱
linux