1. Tcl:用脚本创建工程,避免路径乱#
要点:
- 用 Tcl 创建工程更可控(路径、文件集、生成目录都可标准化)
init.tcl 可用于初始化工程通用配置(例如:默认语言、仿真设置、生成目录、IP repo 路径等)
常见骨架(示意):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| # 1) 约定工程根目录
set origin_dir [file normalize [file dirname [info script]]]
# 2) 创建工程并设定 part
# create_project <prj_name> <prj_dir> -part <part>
# 3) 添加 rtl/xdc/ip
# add_files ...
# add_files -fileset constrs_1 ...
# 4) 统一生成目录(可选)
# set_property target_simulator ...
|
2. 自动生成版本号(写入 version.vh)#
用途建议:
- 用于“bit/固件版本可追溯”(上板/回归/现场问题定位更快)
示例(时间戳):
1
2
3
4
| set time_now [clock seconds]
set time0 [clock format $time_now -format "%Y%m%d%H"]
|
写入 version.vh(示例,注意路径要与你的工程结构一致):
1
2
3
4
5
6
7
8
9
10
| set file "../../../rtl/top/version.vh"
set fileid [open $file w+]
seek $fileid 0 start
puts $fileid "`define FPGA_VERSION 32'h$time0"
close $fileid
|
加入综合 pre-hook(示例):
1
2
3
4
| add_files -fileset utils_1 -norecurse ../tcl/gen_version.tcl
set_property STEPS.SYNTH_DESIGN.TCL.PRE [ get_files ../tcl/gen_version.tcl -of [get_fileset utils_1] ] [get_runs synth_1]
|
补充建议(工程化角度):
- 如果你追求“可复现构建”,时间戳版本要配合记录 git commit/分支/tag(可写到同一个
version.vh 或产物清单里)。 - 写文件路径建议用“相对工程根目录”的约定,避免同一脚本在不同机器路径漂移。
3. 自动复制 bit 文件 + probes(ltx)#
目标:把产物集中到固定目录(便于脚本烧录、备份、发布)。
示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| set copy_path ../../../bit/
if {![file exists $copy_path]} {
file mkdir $copy_path
}
set bitfile ./top.bit
set bitname [file tail $bitfile]
file copy -force $bitfile $copy_path/$bitname
write_debug_probes -quiet -force $copy_path/top
|
补充建议:
- 建议同时复制
.ltx(或用 write_debug_probes 统一生成到目标目录),避免“bit 有了但 ILA 探针不匹配”。 - 产物目录建议按:工程名/日期/版本号分层(至少保证不会被新产物覆盖)。
4. 工程脚本:清理 prj 目录(BAT)#
用途:清理 Vivado 项目生成物,保留 .xpr。
风险提示:
- 这是“不可逆删除”,建议只对 prj 目录执行;并确保
.xpr 在白名单里。
1
2
3
4
5
6
7
8
9
10
| @REM @echo off
pushd "../prj/."
for /d %%i in (*) do rd /q /s "%%i"
for %%i in (*) do if not "%%i" == "prj.xpr" del "%%i"
popd
|
"" 持续更新 ""