24 set tcl_path [
file normalize "[
file dirname [
info script]]/.."]
25 source $tcl_path/hog.tcl
26 set repo_path [
file normalize "$tcl_path/../../"]
31 proc WriteHwPlatformWorkaround {proj_dir proj_name work_path hw_platform_args} {
32 set proj_file [
file normalize "$proj_dir/$proj_name.xpr"]
33 set impl_run [
file tail $work_path]
34 set tmp_script "$work_path/hog_write_hw_platform_tmp.tcl"
36 set fp [open $tmp_script w]
37 puts $fp "open_project {$proj_file}"
38 puts $fp "open_run $impl_run"
39 puts $fp "write_hw_platform $hw_platform_args"
40 puts $fp "close_project"
43 Msg Info "Launching another Vivado instance to run write_hw_platform for $impl_run..."
44 set ret [
catch {
exec vivado -mode batch -notrace -source $tmp_script >@ stdout 2>@ stderr} result]
47 Msg Error "write_hw_platform failed in separate Vivado instance:\n$result"
49 Msg Info "write_hw_platform completed successfully in separate Vivado instance for $impl_run."
56 if {[
info exists env(HOG_TCLLIB_PATH)]} {
57 lappend auto_path $env(HOG_TCLLIB_PATH)
59 puts "ERROR: To run Hog with Microsemi Libero SoC, you need to define the HOG_TCLLIB_PATH variable."
64 if {[
info exists env(HOG_EXTERNAL_PATH)]} {
65 set ext_path $env(HOG_EXTERNAL_PATH)
66 Msg Info "Found environment variable HOG_EXTERNAL_PATH, setting path for external files to $ext_path..."
71 set bin_dir [
file normalize "$repo_path/bin"]
80 set work_path [get_property DIRECTORY [get_runs impl_1]]
83 set work_path $old_path
84 if {[
IsVersal [get_property PART [current_design]]]} {
90 set main_files [lsort [glob -nocomplain "$work_path/*.$fw_file_ext"]]
91 if {[
llength $main_files] > 1} {
94 set main_file [
file normalize [
lindex $main_files 1]]
96 set secondary_file [
file normalize [
lindex $main_files 0]]
97 set main_file_suffix "_pld"
98 set secondary_file_suffix "_boot"
99 Msg Info "Found main and secondary binary file main: [
file tail $main_file], secondary: [
file tail $secondary_file]..."
101 set top_name [regsub $main_file_suffix\$ [
file rootname [
file tail $main_file]] ""]
102 if {[
llength $main_files] > 2} {
103 Msg Warning "Multiple (more than 2) binary files found: $main_files."
106 set main_file [
file normalize [
lindex $main_files 0]]
107 set main_file_suffix ""
108 set secondary_file ""
109 set secondary_file_suffix ""
110 set top_name [
file rootname [
file tail $main_file]]
114 set proj_name [
file tail [
file normalize $work_path/../../]]
115 set proj_dir [
file normalize "$work_path/../.."]
118 set additional_ext ".bin .ltx .bif .mmi"
120 set xml_dir [
file normalize "$work_path/../xml"]
121 set run_dir [
file normalize "$work_path/.."]
125 set proj_name [
lindex $quartus(args) 1]
127 set xml_dir [
file normalize "$repo_path/xml"]
128 set run_dir [
file normalize "$proj_dir"]
129 set name [
file rootname [
file tail [
file normalize [
pwd]]]]
131 set pof_file [
file normalize "$proj_dir/output_files/$proj_name.pof"]
133 set sof_file [
file normalize "$proj_dir/output_files/$proj_name.sof"]
135 set rbf_file [
file normalize "$proj_dir/output_files/$proj_name.rbf"]
137 set rpd_file [
file normalize "$proj_dir/output_files/$proj_name.rpd"]
139 set stp_file [
file normalize "$proj_dir/output_files/$proj_name.stp"]
141 set spf_file [
file normalize "$proj_dir/output_files/$proj_name.spf"]
144 set proj_dir [
file normalize $run_folder]
145 set proj_name [
file tail $proj_dir]
146 set project $proj_name
147 set sap_file [
file normalize [
lindex [glob -nocomplain "$proj_dir/synthesis/*.sap"] 0]]
148 set srd_file [
file normalize [
lindex [glob -nocomplain "$proj_dir/synthesis/*.srd"] 0]]
149 set srm_file [
file normalize [
lindex [glob -nocomplain "$proj_dir/synthesis/*.srm"] 0]]
150 set srs_file [
file normalize [
lindex [glob -nocomplain "$proj_dir/synthesis/*.srs"] 0]]
151 set srr_file [
file normalize [
lindex [glob -nocomplain "$proj_dir/synthesis/*.srr"] 0]]
152 set top_name [
file rootname [
file tail $srr_file]]
154 set map_file [
file normalize "$proj_dir/designer/$top_name/$top_name.map"]
155 set stxt_files [glob -nocomplain "$proj_dir/synthesis/*.txt"]
156 set scsv_files [glob -nocomplain "$proj_dir/synthesis/*.csv"]
157 set slog_files [glob -nocomplain "$proj_dir/synthesis/*.log"]
158 set srpt_files [glob -nocomplain "$proj_dir/synthesis/*.rpt"]
159 set dtxt_files [glob -nocomplain "$proj_dir/designer/$top_name/*.txt"]
160 set dcsv_files [glob -nocomplain "$proj_dir/designer/$top_name/*.csv"]
161 set dlog_files [glob -nocomplain "$proj_dir/designer/$top_name/*.log"]
162 set drpt_files [glob -nocomplain "$proj_dir/designer/$top_name/*.rpt"]
163 set xml_dir [
file normalize "$repo_path/xml"]
165 set proj_dir [
file normalize "[
pwd]/.."]
166 set proj_name [
file tail $proj_dir]
167 set project $proj_name
168 set xml_dir [
file normalize "$repo_path/xml"]
169 set main_file [
file normalize "$proj_dir/Implementation0/${proj_name}_Implementation0"]
172 set work_path $old_path
173 set fw_file [
file normalize [
lindex [glob -nocomplain "$work_path/*.bit"] 0]]
174 set proj_name [
file tail [
file normalize $work_path/../../]]
175 set proj_dir [
file normalize "$work_path/../.."]
177 set top_name [
file rootname [
file tail $fw_file]]
179 set main_file [
file normalize "$work_path/$top_name.bit"]
180 set bin_file [
file normalize "$work_path/$top_name.bin"]
181 set ltx_file [
file normalize "$work_path/$top_name.ltx"]
183 set xml_dir [
file normalize "$work_path/../xml"]
184 set run_dir [
file normalize "$work_path/.."]
187 set group_name [
GetGroupName $proj_dir "$tcl_path/../.."]
191 Msg Info "Evaluating Hog describe for $proj_name..."
192 set describe [
GetHogDescribe [
file normalize ./Top/$group_name/$proj_name] $repo_path]
193 Msg Info "Hog describe set to: $describe"
195 set dst_dir [
file normalize "$bin_dir/$group_name/$proj_name\-$describe"]
196 set dst_xml [
file normalize "$dst_dir/xml"]
198 Msg Info "Creating $dst_dir..."
201 set ts [
clock format [
clock seconds] -format {%Y-%m-%d-%H-%M}]
205 if {[
IsXilinx] && [
file exists $main_file]} {
206 set dst_main [
file normalize "$dst_dir/$proj_name$main_file_suffix\-$describe.$fw_file_ext"]
207 Msg Info "Copying main binary file $main_file into $dst_main..."
208 file copy -force $main_file $dst_main
209 if {$secondary_file != ""} {
210 set dst_secondary [
file normalize "$dst_dir/$proj_name$secondary_file_suffix\-$describe.$fw_file_ext"]
211 Msg Info "Copying secondary binary file $secondary_file into $dst_secondary..."
212 file copy -force $secondary_file $dst_secondary
220 lappend ltx_files "$top_name.ltx"
222 if {$main_file_suffix != ""} {
223 foreach e $additional_ext {
225 lappend new_ext $main_file_suffix$e
226 lappend new_ext $secondary_file_suffix$e
227 lappend ltx_files "$top_name$main_file_suffix.ltx"
228 lappend ltx_files "$top_name$secondary_file_suffix.ltx"
230 set additional_ext $new_ext
235 foreach l $ltx_files {
236 set ltx_file "$work_path/$l"
237 Msg Info "Writing debug probes for $ltx_file..."
238 write_debug_probes -quiet $ltx_file
241 foreach e $additional_ext {
242 set orig [
file normalize "$work_path/$top_name$e"]
243 set dst [
file normalize "$dst_dir/$proj_name\-$describe$e"]
244 if {[
file exists $work_path/$top_name$e] == 1} {
245 Msg Info "Copying $orig file into $dst..."
246 file copy -force $orig $dst
248 Msg Debug "File: $orig not found."
252 set dst_pof [
file normalize "$dst_dir/$name\-$describe.pof"]
253 set dst_sof [
file normalize "$dst_dir/$name\-$describe.sof"]
254 set dst_rbf [
file normalize "$dst_dir/$name\-$describe.rbf"]
255 set dst_rpd [
file normalize "$dst_dir/$name\-$describe.rpd"]
256 set dst_stp [
file normalize "$dst_dir/$name\-$describe.stp"]
257 set dst_spf [
file normalize "$dst_dir/$name\-$describe.spf"]
258 set dst_xml [
file normalize "$dst_dir/xml"]
260 Msg Info "Evaluating differences with last commit..."
261 set found_uncommitted 0
264 set found_uncommitted 1
265 Msg Warning "Found non committed changes:"
267 set fp [open "$dst_dir/diff_postbistream.txt" w+]
272 if {$found_uncommitted == 0} {
273 Msg Info "No uncommitted changes found."
277 if {[
file exists $pof_file]} {
278 Msg Info "Copying pof file $pof_file into $dst_pof..."
279 file copy -force $pof_file $dst_pof
281 Msg Info "No pof file found: $pof_file, that is not a problem"
285 file mkdir $dst_dir/reports
286 set reps [glob -nocomplain "$proj_dir/output_files/*.rpt"]
288 if {[
file exists [
lindex $reps 0]]} {
289 file copy -force {*}$reps $dst_dir/reports
291 Msg Warning "No reports found in $proj_dir/output_files subfolders"
295 if {[
file exists $sof_file]} {
296 Msg Info "Copying sof file $sof_file into $dst_sof..."
297 file copy -force $sof_file $dst_sof
299 Msg Info "No sof file found: $sof_file, that is not a problem"
304 if {[
file exists $rbf_file] || [
file exists $rpd_file]} {
305 if {[
file exists $rbf_file]} {
306 file copy -force $rbf_file $dst_rbf
308 if {[
file exists $rpd_file]} {
309 file copy -force $rpd_file $dst_rpd
312 Msg Info "No rbf or rpd file found: this is not a problem"
316 if {[
file exists $stp_file] || [
file exists $spf_file]} {
317 if {[
file exists $stp_file]} {
318 file copy -force $stp_file $dst_stp
320 if {[
file exists $spf_file]} {
321 file copy -force $spf_file $dst_spf
324 Msg Info "No stp or spf file found: that is not a problem"
327 set dst_map [
file normalize "$dst_dir/$project\-$describe.map"]
328 set dst_sap [
file normalize "$dst_dir/$project\-$describe.sap"]
329 set dst_srd [
file normalize "$dst_dir/$project\-$describe.srd"]
330 set dst_srm [
file normalize "$dst_dir/$project\-$describe.srm"]
331 set dst_srs [
file normalize "$dst_dir/$project\-$describe.srs"]
332 set dst_srr [
file normalize "$dst_dir/$project\-$describe.srr"]
333 set dst_rpt [
file normalize "$dst_dir/reports"]
334 set dst_xml [
file normalize "$dst_dir/xml"]
336 file mkdir $dst_dir/reports
338 if {[
file exists $map_file]} {
339 Msg Info "Copying map file $map_file into $dst_map..."
340 file copy -force $map_file $dst_map
343 if {[
file exists $sap_file]} {
344 Msg Info "Copying sap file $sap_file into $dst_sap..."
345 file copy -force $sap_file $dst_sap
348 if {[
file exists $srd_file]} {
349 Msg Info "Copying srd file $srd_file into $dst_srd..."
350 file copy -force $srd_file $dst_srd
353 if {[
file exists $srm_file]} {
354 Msg Info "Copying srm file $srm_file into $dst_srm..."
355 file copy -force $srm_file $dst_srm
358 if {[
file exists $srs_file]} {
359 Msg Info "Copying srs file $srs_file into $dst_srs..."
360 file copy -force $srs_file $dst_srs
363 if {[
file exists $srr_file]} {
364 Msg Info "Copying srr file $srr_file into $dst_srr..."
365 file copy -force $srr_file $dst_srr
370 set reports [
concat $stxt_files $scsv_files $slog_files $srpt_files \
371 $dtxt_files $dcsv_files $dlog_files $drpt_files]
372 Msg Info "Copying [
llength $reports] synthesis and implementation reports into $dst_rpt..."
373 foreach report $reports {
374 file copy -force $report $dst_rpt
377 set dst_main [
file normalize "$dst_dir/$proj_name\-$describe.bit"]
378 Msg Info "Copying main binary file $main_file.bit into $dst_main..."
379 file copy -force $main_file.bit $dst_main
380 Msg Info "Copying binary generation log $main_file.bgn into $dst_dir/reports..."
381 file copy -force $main_file.bgn $dst_dir/reports
383 Msg CriticalWarning "Firmware binary file not found."
388 if {[
file exists $xml_dir]} {
389 Msg Info "XML directory found, copying xml files from $xml_dir to $dst_xml..."
390 if {[
file exists $dst_xml]} {
391 Msg Info "Directory $dst_xml exists, deleting it..."
392 file delete -force $dst_xml
394 file copy -force $xml_dir $dst_xml
400 set export_xsa "NONE"
401 set part [get_property part [current_project]]
405 if {[dict exists $properties "hog"]} {
406 set propDict [dict get $properties "hog"]
407 if {[dict exists $propDict "EXPORT_XSA"]} {
408 set export_xsa [dict get $propDict "EXPORT_XSA"]
412 if {$export_xsa == "NONE"} {
415 Msg Info "SoC FPGA detected (Zynq or Versal), automatically enabling XSA file creation. \
416 To disable it, add 'EXPORT_XSA = false' in the \[hog\] section of hog.conf."
423 dict for {app_name app_conf} $apps {
425 [dict exists $app_conf "proc"] &&
426 [regexp -nocase {microblaze|risc} [dict get $app_conf "proc"]]
428 Msg Info "Soft processor ([dict get $app_conf proc]) detected in app '$app_name', \
429 automatically enabling XSA file creation. \
430 To disable it, add 'EXPORT_XSA = false' in the \[hog\] section of hog.conf."
438 if {[
string compare [
string tolower $export_xsa] "true"] == 0} {
443 regexp -- {Vivado v([0-9]{4}\.[0-9,A-z,_,\.]*) } [version] -> VIVADO_VERSION
444 if {[
string compare "2020.1" $VIVADO_VERSION] == 0} {
445 Msg Warning "Vivado 2020.1, a patch must be applied to Vivado to export XSA Files, c.f. https://www.xilinx.com/support/answers/75210.html"
447 set dst_xsa [
file normalize "$dst_dir/${proj_name}\-$describe.xsa"]
448 Msg Info "Generating XSA File at $dst_xsa"
452 set user_pre_platform_file "./Top/$group_name/$proj_name/pre-platform.tcl"
453 if {[
file exists $user_pre_platform_file]} {
454 Msg Info "Sourcing user pre-platform file $user_pre_platform_file"
455 source $user_pre_platform_file
459 if {$secondary_file == ""} {
460 set pdi_post_imp [
file normalize "$work_path/$top_name.pdi"]
461 set_property platform.full_pdi_file $pdi_post_imp [current_project]
462 Msg Info "XSA file will be generated for Versal with this PDI: $pdi_post_imp"
466 Msg Warning "No XSA will be produced in post-bitream for segmented configuration mode. \
467 If you're running with the GUI, please type the following on the Tcl console: write_hw_platform -fixed -force -file $dst_xsa."
471 "-include_bit -fixed -force -file {$dst_xsa}"
476 if {$wrote_xsa == 1} {
478 set conf_file [
lindex [
GetConfFiles $repo_path/Top/$group_name/$proj_name] 0]
479 set is_vitis_classic 0
480 set is_vitis_unified 0
482 if {[
file exists $conf_file]} {
484 set ide_name [
string tolower [
lindex $ide_name_and_ver 0]]
485 if {[
string match "*vitis_classic*" $ide_name] || [
string match "*vivado_vitis_classic*" $ide_name]} {
486 set is_vitis_classic 1
487 }
elseif {[
string match "*vitis_unified*" $ide_name] || [
string match "*vivado_vitis_unified*" $ide_name]} {
488 set is_vitis_unified 1
492 if {$is_vitis_classic || $is_vitis_unified} {
493 Msg Info "XSA file written to $dst_xsa"
495 set full_proj_name [
file join $group_name $proj_name]
498 if {$is_vitis_classic} {
499 set vitis_cmd "xsct $tcl_path/launch.tcl CW -xsa $dst_xsa -vitis_only $full_proj_name"
500 set vitis_type "Vitis Classic"
501 set error_prefix "xsct (vitis classic)"
502 }
elseif {$is_vitis_unified} {
504 set vitis_log [
file normalize "$proj_dir/vitis_unified_build.log"]
505 set vitis_jou [
file normalize "$proj_dir/vitis_unified_build.jou"]
506 set vitis_cmd "vivado -mode batch -notrace \
507 -log $vitis_log -journal $vitis_jou \
508 -source $tcl_path/launch.tcl \
509 -tclargs CW -xsa $dst_xsa -vitis_only $full_proj_name"
510 set vitis_type "Vitis Unified"
511 set error_prefix "vivado (for vitis unified)"
513 Msg Error "No Vitis project type found."
517 Msg Info "Running $vitis_type to create elf file with cmd: $vitis_cmd"
518 set ret [
catch {
exec -ignorestderr {*}$vitis_cmd >@ stdout} result]
520 Msg Error "$error_prefix returned an error state: $result"
527 foreach prop_key [dict keys $properties] {
528 if {[regexp {^app:(.+)$} $prop_key -> raw_app_name]} {
529 lappend app_names [
string trim $raw_app_name]
532 foreach app_name $app_names {
533 if {$is_vitis_unified} {
534 set elf_src [
file normalize "$repo_path/Projects/$full_proj_name/vitis_unified/$app_name/build/$app_name.elf"]
536 set elf_src [
file normalize "$repo_path/Projects/$full_proj_name/vitis_classic/$app_name/Release/$app_name.elf"]
538 set elf_dst [
file normalize "$dst_dir/${proj_name}\-${app_name}\-$describe.elf"]
539 if {[
file exists $elf_src]} {
540 Msg Info "Copying ELF $elf_src into $elf_dst..."
541 file copy -force $elf_src $elf_dst
543 Msg Warning "ELF file not found: $elf_src"
548 set mmi_file [
file normalize "$dst_dir/${proj_name}\-$describe.mmi"]
549 GenerateBootArtifacts $properties $repo_path $proj_dir $dst_dir $proj_name $describe $dst_main $mmi_file
557 set user_post_bitstream_file "./Top/$group_name/$proj_name/post-bitstream.tcl"
558 if {[
file exists $user_post_bitstream_file]} {
559 Msg Info "Sourcing user post-bitstream file $user_post_bitstream_file"
560 source $user_post_bitstream_file
563 Notify Info "Completed bitstream of $proj_name."