Yosys:开源综合流程
更新时间:2026-09-21。硬件工具。综合前后的功能验证可用 Icarus Verilog、Verilator。
一句话回答
Yosys 是开源逻辑综合工具:把 RTL「综合」成门级/LUT 网表。核心三步——read_verilog 读入设计、synth(或针对 FPGA 的 synth_ice40/synth_ecp5)做优化与工艺映射(内部调 ABC)、write_verilog/write_json 输出网表供后续布局布线(如 nextpnr)。
一、安装
bash
sudo apt install yosys # 或源码编译
yosys -V二、一条命令综合
bash
yosys -p "read_verilog top.v; synth; write_verilog netlist.v"更常用的是写成脚本文件(flow.ys):
bash
read_verilog top.v
synth -top top
abc # 映射到通用单元 / LUT
stat # 打印资源统计
write_verilog netlist.v
show # 可选:生成结构图(需 graphviz)bash
yosys flow.ys三、面向具体 FPGA(与 nextpnr 配合)
bash
read_verilog top.v
synth_ice40 -top top -json top.json # Lattice iCE40 流程bash
yosys flow.ys
nextpnr-ice40 --hx8k --json top.json --asc top.asc # 布局布线
icepack top.asc top.bin # 生成比特流Yosys 负责「RTL → 网表」,nextpnr 负责「网表 → 布线/比特流」,分工清晰。
常见坑
- 设计不可综合:含
#延时、$display、初始化不定行为等仿真结构,综合会忽略或报错;综合只接受可综合 RTL。 - 没指定 top 模块:多个模块时顶层不明导致结果不对,用
-top。 - 把综合当仿真验证:Yosys 不验证功能对不对,功能要靠仿真/形式验证先保证。
- 缺目标工艺库:ASIC 流程要
read_liberty提供标准单元库,否则无法映射真实单元。 - 混淆 synth 通用脚本和专用脚本:上 FPGA 要用对应
synth_ice40/synth_ecp5,输出 json 而非通用网表。 - VHDL 支持依赖插件:Yosys 原生偏 Verilog,VHDL 需 GHDL 插件(ghdl-yosys-plugin)。
总结
Yosys 用 read_verilog 读入、synth/abc 做优化与工艺映射、write_verilog/json 输出网表,是开源 RTL 综合的核心;FPGA 流程再把 json 交给 nextpnr 布局布线。注意它只处理可综合设计、不验证功能,ASIC 还需提供标准单元库。