This repository has been archived by the owner on Aug 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vivado-checkout.tcl
215 lines (186 loc) · 8 KB
/
vivado-checkout.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# Note: argument order does not matter when setting argv; all arguments are optional
# Usage (No Defaults):
# set argv "-r <repo_path> -x <xpr_path> -v <vivado_version>
# source vivado-checkout.tcl
# Usage (All Defaults):
# set argv ""
# source vivado-checkout.tcl
# Handle repo_path argument
set idx [lsearch ${argv} "-r"]
if {${idx} != -1} {
set repo_path [glob -nocomplain [file normalize [lindex ${argv} [expr {${idx}+1}]]]]
} else {
# Default
set repo_path [file normalize [file dirname [info script]]/..]
}
# Handle xpr_path argument
set idx [lsearch ${argv} "-x"]
if {${idx} != -1} {
set xpr_path [file normalize [lindex ${argv} [expr {${idx}+1}]]]
} else {
# Default
set xpr_path [file join ${repo_path} proj [file tail $repo_path]].xpr]
}
# Handle vivado_version argument
set idx [lsearch ${argv} "-v"]
if {${idx} != -1} {
set vivado_version [lindex ${argv} [expr {${idx}+1}]]
} else {
# Default
set vivado_version [version -short]
}
# Other variables
set vivado_year [lindex [split $vivado_version "."] 0]
set proj_name [file rootname [file tail $xpr_path]]
puts "INFO: Creating new project \"$proj_name\" in [file dirname $xpr_path]"
# Create project
create_project $proj_name [file dirname $xpr_path]
source $repo_path/project_info.tcl
# Capture board information for the project
puts "INFO: Capturing board information from $repo_path/project_info.tcl"
set_project_properties_post_create_project $proj_name
set obj [get_projects $proj_name]
set part_name [get_property "part" $obj]
# Uncomment the following 3 lines to greatly increase build speed while working with IP cores (and/or block diagrams)
puts "INFO: Configuring project IP handling properties"
set_property "corecontainer.enable" "0" $obj
set_property "ip_cache_permissions" "read write" $obj
set_property "ip_output_repo" "[file normalize "$repo_path/proj/cache"]" $obj
# Create 'sources_1' fileset (if not found)
if {[string equal [get_filesets -quiet sources_1] ""]} {
puts "INFO: Creating sources_1 fileset"
create_fileset -srcset sources_1
}
# Create 'sim_1' fileset (if not found)
if {[string equal [get_filesets -quiet sim_1] ""]} {
puts "INFO: Creating im_1 fileset"
create_fileset -simset sim_1
}
# Create 'constrs_1' fileset (if not found)
if {[string equal [get_filesets -quiet constrs_1] ""]} {
puts "INFO: Creating constrs_1 fileset"
create_fileset -constrset constrs_1
}
# Capture project-specific IP settings
puts "INFO: capturing IP-related settings from $repo_path/project_info.tcl"
set_project_properties_pre_add_repo $proj_name
# Set IP repository paths
puts "INFO: Setting IP repository paths"
set obj [get_filesets sources_1]
if { [file isdirectory "[file normalize $repo_path/repo]"] == 1 } {
set_property "ip_repo_paths" "[file normalize $repo_path/repo]" $obj
}
# Refresh IP Repositories
puts "INFO: Refreshing IP repositories"
update_ip_catalog -rebuild
# Add hardware description language sources
puts "INFO: Adding HDL sources"
add_files -quiet -norecurse $repo_path/src/hdl
# Add simulation sources
puts "INFO: Adding simulation sources"
add_files -quiet -norecurse -fileset sim_1 $repo_path/src/sim
# Add IPs
# TODO: handle IP core-container files
puts "INFO: Adding XCI IP sources"
add_files -quiet [glob -nocomplain $repo_path/src/ip/*/*.xci]
# Add constraints
puts "INFO: Adding constraints"
add_files -quiet -norecurse -fileset constrs_1 $repo_path/src/constraints
# Recreate block design
# TODO: handle multiple block designs
set ipi_tcl_files [glob -nocomplain "$repo_path/src/bd/*.tcl"]
set ipi_bd_files [glob -nocomplain "$repo_path/src/bd/*/*.bd"]
if {[llength $ipi_tcl_files] > 1} {
# TODO: quit and log the error
puts "ERROR: This script cannot handle projects containing more than one block design!"
} elseif {[llength $ipi_tcl_files] == 1} {
# Use TCL script to rebuild block design
puts "INFO: Rebuilding block design from script"
# Create local source directory for bd
if {[file exist "[file rootname $xpr_path].srcs"] == 0} {
file mkdir "[file rootname $xpr_path].srcs"
}
if {[file exist "[file rootname $xpr_path].srcs/sources_1"] == 0} {
file mkdir "[file rootname $xpr_path].srcs/sources_1"
}
if {[file exist "[file rootname $xpr_path].srcs/sources_1/bd"] == 0} {
file mkdir "[file rootname $xpr_path].srcs/sources_1/bd"
}
# Force Non-Remote BD Flow
set origin_dir [pwd]
cd "[file rootname $xpr_path].srcs/sources_1"
set run_remote_bd_flow 0
source [lindex $ipi_tcl_files 0]
cd $origin_dir
} elseif {[llength $ipi_bd_files] > 1} {
# TODO: quit and log the error
puts "ERROR: This script cannot handle projects containing more than one block design!"
} elseif {[llength $ipi_bd_files] == 1} {
# Add block design from .bd file and sources
puts "INFO: Rebuilding block design from BD fileset"
add_files -norecurse -quiet -fileset sources_1 [glob -nocomplain $repo_path/src/bd/*/*.bd]
open_bd_design [glob -nocomplain $repo_path/src/bd/*/*.bd]
set design_name [get_bd_designs]
set file "$repo_path/src/bd/$design_name/$design_name.bd"
set file [file normalize $file]
set file_obj [get_files -of_objects [get_filesets sources_1] [list "*$file"]]
if { ![get_property "is_locked" $file_obj] } {
set_property "synth_checkpoint_mode" "Hierarchical" $file_obj
}
}
# Make sure IPs are upgraded to the most recent version
foreach ip [get_ips -filter "IS_LOCKED==1"] {
upgrade_ip -vlnv [get_property UPGRADE_VERSIONS $ip] $ip
export_ip_user_files -of_objects $ip -no_script -sync -force -quiet
}
# Generate the wrapper
set bd_files [get_files -of_objects [get_filesets sources_1] -filter "NAME=~*.bd"]
if {[llength $bd_files] > 1} {
puts "ERROR: This script cannot handle projects containing more than one block design!"
} elseif {[llength $bd_files] == 1} {
set bd_name [get_bd_designs]
set bd_file [get_files $bd_name.bd]
set wrapper_file [make_wrapper -files $bd_file -top -force]
import_files -quiet -force -norecurse $wrapper_file
set obj [get_filesets sources_1]
set_property "top" "${bd_name}_wrapper" $obj
}
# Create 'synth_1' run (if not found)
if {[string equal [get_runs -quiet synth_1] ""]} {
puts "INFO: Creating synth_1 run"
create_run -name synth_1 -part $part_name -flow {Vivado Synthesis $vivado_year} -strategy "Vivado Synthesis Defaults" -constrset constrs_1
} else {
set_property strategy "Vivado Synthesis Defaults" [get_runs synth_1]
set_property flow "Vivado Synthesis $vivado_year" [get_runs synth_1]
}
puts "INFO: Configuring synth_1 run"
set obj [get_runs synth_1]
set_property "part" $part_name $obj
set_property "steps.synth_design.args.flatten_hierarchy" "none" $obj
set_property "steps.synth_design.args.directive" "RuntimeOptimized" $obj
set_property "steps.synth_design.args.fsm_extraction" "off" $obj
# Set the current synth run
puts "INFO: Setting current synthesis run"
current_run -synthesis [get_runs synth_1]
# Create 'impl_1' run (if not found)
if {[string equal [get_runs -quiet impl_1] ""]} {
puts "INFO: Creating impl_1 run"
create_run -name impl_1 -part $part_name -flow {Vivado Implementation $vivado_year} -strategy "Vivado Implementation Defaults" -constrset constrs_1 -parent_run synth_1
} else {
set_property strategy "Vivado Implementation Defaults" [get_runs impl_1]
set_property flow "Vivado Implementation $vivado_year" [get_runs impl_1]
}
puts "INFO: Configuring impl_1 run"
set obj [get_runs impl_1]
set_property "part" $part_name $obj
set_property "steps.opt_design.args.directive" "RuntimeOptimized" $obj
set_property "steps.place_design.args.directive" "RuntimeOptimized" $obj
set_property "steps.route_design.args.directive" "RuntimeOptimized" $obj
# Set the current impl run
puts "INFO: Setting current implementation run"
current_run -implementation [get_runs impl_1]
# Capture project-specific IP settings
puts "INFO: capturing run settings from $repo_path/project_info.tcl"
set_project_properties_post_create_runs $proj_name
puts "INFO: Project created: [file tail $proj_name]"
puts "INFO: Exiting Vivado"