vivado生成dcp脚本

# ============================================================
# Auto export DCP (synth only, clean)
# Disable constr XDC before synth, restore after export
# Output: <proj_dir>/<top>.dcp
# ============================================================

proc print_banner {msg {width 60}} {
    set left  [expr {($width - [string length $msg] - 2) / 2}]
    set right [expr {$width - $left - [string length $msg] - 2}]
    puts "[string repeat "=" $left] $msg [string repeat "=" $right]"
}

print_banner "DCP Export (Synth Only)"

# 1. 基本信息
set proj [current_project -quiet]
if {$proj eq ""} { error "ERROR: No project open." }

set fs [current_fileset]
set top_name [get_property top $fs]
if {$top_name eq ""} { error "ERROR: Top not set." }

set proj_dir [get_property DIRECTORY $proj]
set dcp_file [file join $proj_dir "${top_name}_synth.dcp"]

puts "INFO: TOP  = $top_name"
puts "INFO: PATH = $proj_dir"

# 2. 找 synthesis run
set synth_runs [get_runs -quiet -filter {IS_SYNTHESIS == 1}]
if {[llength $synth_runs] == 0} {
    error "ERROR: No synthesis run found."
}

set run_name ""
foreach r $synth_runs {
    if {[get_property SOURCE_SET $r] eq $fs} {
        set run_name $r
        break
    }
}
if {$run_name eq ""} {
    set run_name [lindex $synth_runs 0]
    puts "WARNING: Using fallback run: $run_name"
} else {
    puts "INFO: Using run: $run_name"
}

# 3. 收集 constr fileset 里的 XDC(不动 IP 自带)
set constr_sets [get_filesets -quiet -filter {FILESET_TYPE == "Constrs"}]
set xdc_files {}

foreach cfs $constr_sets {
    set fs_xdc [get_files -quiet -of_objects $cfs -filter {FILE_TYPE == "XDC"}]
    if {[llength $fs_xdc] > 0} {
        set xdc_files [concat $xdc_files $fs_xdc]
    }
}

set xdc_files [lsort -unique $xdc_files]
puts "INFO: Found [llength $xdc_files] XDC file(s)."

# 4. 备份并禁用
array set xdc_enable_bak {}

foreach f $xdc_files {
    set xdc_enable_bak($f) [get_property IS_ENABLED $f]
    catch {set_property IS_ENABLED false $f}
    puts "INFO: disabled [file tail $f]"
}

# 5. 跑综合 + 导出 DCP
set failed 0

if {[catch {

    catch {reset_run $run_name}

    puts "INFO: Running synthesis..."
    launch_runs $run_name -jobs 32
    wait_on_run $run_name

    set status [get_property STATUS [get_runs $run_name]]
    if {![string match "*Complete*" $status]} {
        error "ERROR: Synthesis failed. Status: $status"
    }

    open_run $run_name

    puts "INFO: Writing DCP -> $dcp_file"
    write_checkpoint -force $dcp_file

} err_msg]} {
    set failed 1
    puts $err_msg
}

# 6. 恢复 XDC
foreach f $xdc_files {
    catch {set_property IS_ENABLED $xdc_enable_bak($f) $f}
    puts "INFO: restored [file tail $f]"
}

if {$failed} {
    error "ERROR: DCP export failed."
}

print_banner "DONE"
puts "DCP: $dcp_file"
posted @ 2026-04-29 11:17  Oppenic  阅读(22)  评论(0)    收藏  举报