Hog v10.58.0
vivado.tcl
Go to the documentation of this file.
1 namespace eval Tools::Vivado {
2 
3  Tools::RegisterTool [namespace current] {
4  name "Vivado"
5  vendor "AMD/Xilinx"
6  description "AMD/Xilinx Vivado (and Vivado-Vitis classic + legacy PlanAhead) FPGA design suite."
7  ref_name {vivado vivado_vitis_classic planahead}
8  }
9 
10  RegisterFlow CREATE {
11  aliases {C}
12  description "Create the project, replace it if already existing."
13  options {
14  {ext_path.arg "" "Sets the absolute path for the external libraries."}
15  {lib.arg "" "Simulation library path, compiled or to be compiled"}
16  {vivado_only "If set, and project is vivado-vitis, vitis project will not be created."}
17  {vitis_only "If set, and project is vivado-vitis create only vitis project. If an xsa is not given, a pre-synth xsa will be created."}
18  {verbose "If set, launch the script in verbose mode"}
19  }
20  stages {
21  CreateProject
22  }
23  }
24 
25  RegisterFlow SYNTHESIS {
26  aliases {synth synthesize}
27  stages {@CREATE Synthesize}
28  description "Run synthesis only, create the project if not existing."
29  options {
30  {recreate "If set, the project will be re-created if it already exists."}
31  {check_syntax "If set, the HDL syntax will be checked at the beginning of the workflow."}
32  {njobs.arg 4 "Number of jobs."}
33  {no_reset "If set, runs (synthesis and implementation) won't be reset before launching them."}
34  }
35  }
36 
37  RegisterFlow IMPLEMENTATION {
38  aliases {i impl implement}
39  description "Runs only the implementation, the project must already exist and be synthesised."
40  stages {@SYNTHESIS Implement}
41  options {
42  {no_bitstream "If set, the bitstream file will not be produced."}
43  }
44  }
45 
46  RegisterFlow WORKFLOW {
47  aliases {w work cw}
48  description "Runs the full workflow, creates the project if not existing."
49  options {
50  {bitstream_only "If set, only the bitstream will be produced. This assumes implementation was already done. For a Vivado-Vitis\
51  project this command can be used to generate the boot artifacts including the ELF file(s) without running the\
52  full Vivado workflow."}
53  {synth_only "If set, only the synthesis will be performed."}
54  {impl_only "If set, only the implementation will be performed. This assumes synthesis was already done."}
55  }
56  stages {@IMPLEMENTATION GenerateBitstream}
57  }
58 
59 
60  RegisterStage Synthesize { description "Run the synthesis run." }
61  RegisterStage CreateProject { description "Create the Vivado project from the Top/ description." }
62  RegisterStage Implement { description "Run the implementation run." }
63  RegisterStage GenerateBitstream { description "Write the bitstream." }
64 
65 
66  #Add vivado-only commands
67  source [file join [file dirname [info script]] commands.tcl]
68 
69  proc Launch {} {
70  set script [Launcher::Get script]
71  puts "Launching vivado: \n vivado -nojournal -nolog -mode batch -notrace -source $script -tclargs {*}$::argv"
72  exec -ignorestderr vivado -nojournal -nolog -mode batch -notrace -source $script -tclargs {*}$::argv >@ stdout
73  }
74 
75  proc Initialize {} {
76  # Tool-specific setup — DataStores are already populated by _ConfigureEnvironment
77  set repo_path [Repo::Get repo_path]
78  set top_path [Repo::Get top_path]
79 
80 
81  set_msg_config -suppress -regexp -string {".*The IP file '.*' has been moved from its original location, as a result the outputs for this IP will now be \
82  generated in '.*'. Alternatively a copy of the IP can be imported into the project using one of the 'import_ip' or 'import_files' commands..*"}
83  set_msg_config -suppress -regexp -string {".*File '.*.xci' referenced by design '.*' could not be found..*"}
84 
85  # File inside .bd
86  set_msg_config -suppress -id {IP_Flow 19-3664}
87  # This is due to simulations in project with NoC
88  # tclint-disable-next-line line-length
89  set_msg_config -suppress -id {Vivado 12-23660} -string {{ERROR: [Vivado 12-23660] Simulation is not supported for the target language VHDL when design \
90  contains NoC (Network-on-Chip) blocks} }
91 
92 
93  if {[info exists env(HOG_EXTERNAL_PATH)]} {
94  CurrentProject::Set HOG_EXTERNAL_PATH $env(HOG_EXTERNAL_PATH)
95  } else {
96  CurrentProject::Set HOG_EXTERNAL_PATH ""
97  }
98 
99  if {[CurrentProject::Exists project_name] == 0} {
100  FlowControl::Produce VIVADO_INITIALIZED
101  return
102  }
103 
104  set project_name [CurrentProject::Get project_name]
105  CurrentProject::Set project_file [file normalize [file join [CurrentProject::Get build_dir] [CurrentProject::Get project].xpr]]
106  CurrentProject::Set LIBERO_MANDATORY_VARIABLES {"FAMILY" "PACKAGE" "DIE" }
107  set proj_dir [file normalize "${repo_path}/Top/${project_name}"]
108 
109 
110  if {[Launcher::GetOr options lib ""] != ""} {
111  if {[IsRelativePath [Launcher::Get options lib]] == 0} {
112  CurrentProject::Set simlib_path "[Launcher::Get options lib]"
113  } else {
114  CurrentProject::Set simlib_path "${repo_path}/[Launcher::Get options lib]"
115  }
116  Msg Info "Simulation library path set to [CurrentProject::Get simlib_path]"
117  } else {
118  CurrentProject::Set simlib_path "${repo_path}/simlib"
119  Msg Info "Simulation library path set to default [CurrentProject::Get simlib_path]"
120  }
121 
122 
123 
124  FlowControl::Produce VIVADO_INITIALIZED
125  }
126 
127  proc CreateProject {} {
128 
129  FlowControl::Require VIVADO_INITIALIZED
130  CurrentProject::SaveJsonToFile [Repo::Get repo_path]/last_run.json 1
131 
132  if {[file exists [CurrentProject::Get project_file]] && [Launcher::GetOr options recreate 1] == 0} {
133  Msg Info "Project file found at [CurrentProject::Get project_file], opening project..."
134  #file mkdir "[CurrentProject::Get project_file]/[CurrentProject::Get project_name].gen/sources_1"
135  OpenProject [CurrentProject::Get project_file] [Repo::Get repo_path]
136  FlowControl::Produce PROJECT_OPEN
137  return
138  }
139 
140 
141  Msg Info "Creating project with part: [CurrentProject::Get config main PART] at [CurrentProject::Get project_file]"
142  if {[catch {
143  create_project -force [file tail [CurrentProject::Get design]] [CurrentProject::Get build_dir] -part [CurrentProject::Get config main PART]
144  } _err _opts ]} {
145  Msg Error "Failed to create project: $_err with options: $_opts"
146  Msg Warning "Failed to Create Project"
147  } else {
148  FlowControl::Produce PROJECT_OPEN
149  FlowControl::Produce PROJECT_CREATED "[CurrentProject::Get project_file]"
150  }
151 
152  set obj [get_projects [file tail [CurrentProject::Get design]]]
153  set_property "target_language" "VHDL" $obj
154 
155  set_property "simulator_language" "Mixed" $obj
156  foreach simulator [GetSimulators] {
157  set_property "compxlib.${simulator}_compiled_library_dir" [CurrentProject::Get simlib_path] $obj
158  }
159  set_property "default_lib" "xil_defaultlib" $obj
160  ## Enable VHDL 2008
161  set_param project.enableVHDL2008 1
162  set_property "enable_vhdl_2008" 1 $obj
163  ## Enable Automatic compile order mode, otherwise we cannot find the right top module...
164  set_property source_mgmt_mode All [current_project]
165  # Set PART Immediately
166  Msg Info "Setting PART = [CurrentProject::Get config main PART]"
167  set_property PART [CurrentProject::Get config main PART] [current_project]
168 
169 
171  Msg Info "Project created at [CurrentProject::Get project_file]"
173  Msg Info "Project files added to [CurrentProject::Get project_file]"
177  }
178 
179 
180  proc ConfigureProperties {} {
181  FlowControl::Require PROJECT_OPEN
182  set user_repo "0"
183  Msg Info "Setting project-wide properties..."
184  set proj_props [CurrentProject::Get config main]
185  dict for {prop_name prop_val} $proj_props {
186  if {[string tolower $prop_name] != "ip_repo_paths"} {
187  if {[string tolower $prop_name] != "part"} {
188  # Part is already set
189  Msg Debug "Setting $prop_name = $prop_val"
190  set_property -name $prop_name -value $prop_val -objects [current_project]
191  }
192  } else {
193  set ip_repo_list [regsub -all {\s+} $prop_val " [Repo::Get repo_path]/"]
194  set ip_repo_list [Repo::Get repo_path]/$ip_repo_list
195  set user_repo "1"
196  Msg Info "Setting $ip_repo_list as user IP repository..."
197  if {[IsISE]} {
198  set_property ip_repo_paths "$ip_repo_list" [current_fileset]
199  } else {
200  set_property ip_repo_paths "$ip_repo_list" [current_project]
201  }
202  update_ip_catalog
203  }
204  }
205 
206  # Setting Run Properties
207  foreach run [get_runs -quiet] {
208  if {[CurrentProject::Exists config $run]} {
209  Msg Info "Setting properties for run: $run..."
210  set run_props [CurrentProject::Get config $run]
211  set stragety_str "STRATEGY strategy Strategy"
212  Msg Debug "Setting Strategy and Flow for run $run (if specified in hog.conf)"
213  foreach s $stragety_str {
214  if {[tdict exists $run_props $s]} {
215  set prop [tdict getval $run_props $s]
216  set_property -name $s -value $prop -objects $run
217  set run_props [tdict remove $run_props $s]
218  Msg Warning "A strategy for run $run has been defined inside hog.conf. This prevents Hog to compare the project properties. \
219  Please regenerate your hog.conf file using the dedicated Hog button."
220  Msg Info "Setting $s = $prop"
221  }
222  }
223 
224  dict for {prop_name prop_val} $run_props {
225  Msg Debug "Setting $prop_name = $prop_val"
226  if {[string trim $prop_val] == ""} {
227  Msg Warning "Property $prop_name has empty value. Skipping..."
228  continue
229  }
230  if {[IsInList [string toupper $prop_name] [VIVADO_PATH_PROPERTIES] 1]} {
231  # Check that the file exists before setting these properties
232  set utility_file [Repo::Get repo_path]/$prop_val
233  if {[file exists $utility_file]} {
234  lassign [GetHogFiles -ext_path [CurrentProject::Get HOG_EXTERNAL_PATH] [CurrentProject::Get list_path] [Repo::Get repo_path]] lib prop dummy
235  foreach {l f} $lib {
236  foreach ff $f {
237  lappend hog_files $ff:
238  }
239  }
240  if {[lsearch $hog_files $utility_file] < 0} {
241  Msg CriticalWarning "The file: $utility_file is set as a property in hog.conf, \
242  but is not added to the project in any list file. Hog cannot track it."
243  } else {
244  #Add file tu utils_1 to avoid warning
245  AddFile [Repo::Get repo_path]/$prop_val [get_filesets -quiet utils_1]
246  }
247  set_property -name $prop_name -value $utility_file -objects $run
248  } else {
249  Msg Warning "Impossible to set property $prop_name to $prop_val. File is missing"
250  }
251  } else {
252  set_property -name $prop_name -value $prop_val -objects $run
253  }
254  }
255  }
256  }
257  }
258 
259 
260  proc AddProjectFiles {} {
261  FlowControl::RequireOr PROJECT_OPEN {
262  Msg Info "Project not open; run CreateProject first..."
263  }
264 
265  if {[get_filesets -quiet sources_1] eq ""} { create_fileset -srcset sources_1 }
266  if {[get_filesets -quiet constrs_1] eq ""} { create_fileset -constrset constrs_1 }
267 
268  # Create any non-standard filesets (simulation sets).
269  tlist foreachval fs [CurrentProject::Get filesets] {
270  if {$fs in {sources_1 constrs_1}} { continue }
271  if {[get_filesets -quiet $fs] eq ""} {
272  create_fileset -simset $fs
273  current_fileset -simset [get_filesets $fs]
274  set sim [get_filesets $fs]
275  foreach simulator [GetSimulators] {
276  set_property -name "$simulator.compile.vhdl_syntax" -value 2008 -objects $sim
277  }
278  set_property SOURCE_SET sources_1 $sim
279  }
280  }
281 
282  # Add files fileset by fileset (batch add, then apply per-file properties).
283  # IPs are added last within each fileset to respect tool dependency order.
284  set proj_ds [CurrentProject::GetProjectObj]
285 
286  Msg Info "Modifying Added Files"
287  tlist foreachval fs [CurrentProject::Get filesets] {
288  # Get all files for this fileset, excluding Vitis app libraries.
289  set all_fs [Projects::GetProjectFiles $proj_ds -fileset "^${fs}$" -as tdict]
290  set all_fs [ListFile::HogFileObj::Filter $all_fs -library {^(?!app_)}]
291 
292  if {[llength [tdict keys $all_fs]] == 0} { continue }
293 
294  # Batch-add paths: regular sources first, IPs last (tool dependency order).
295  set regular [ListFile::HogFileObj::Filter $all_fs -library {^(?!ips\.src$)}]
296  set ip_files [ListFile::HogFileObj::Filter $all_fs -library {^ips\.src$}]
297  puts "Adding [llength [tdict keys $all_fs]] files and [llength [tdict keys $ip_files]] IPs to fileset $fs"
298  add_files -norecurse -fileset $fs [concat [tdict keys $regular] [tdict keys $ip_files]]
299 
300 
301  # Apply per-file properties.
302  tdict for {path fobj} $all_fs {
303  set ext [tdict getval $fobj ext]
304  set lib [tlist getval [tdict get $fobj libraries] 0]
305  set rootlib [file rootname [file tail $lib]]
306  set file_obj [get_files -of_objects [get_filesets $fs] [list "*$path"]]
307 
308  if {$ext in {.vhd .vhdl}} {
309  set_property -name library -value $rootlib -objects $file_obj
310  }
311 
312  if {$ext eq ".bd"} {
313  Msg Info "Generating Target for [file tail $path]"
314  generate_target all [get_files $path]
315  }
316 
317  tdict for {key val} [tdict get $fobj props] {
318  set v [tnative $val]
319  switch -- $key {
320  std {
321  if {$ext in {.vhd .vhdl}} {
322  switch -- $v {
323  93 { Msg Debug "VHDL 93 for $path" }
324  2019 {
325  if {[GetIDEVersion] >= 2023.2} {
326  set_property -name file_type -value "VHDL 2019" -objects $file_obj
327  } else {
328  Msg CriticalWarning "VHDL 2019 requires Vivado >= 2023.2; using 2008 for $path"
329  set_property -name file_type -value "VHDL 2008" -objects $file_obj
330  }
331  }
332  default { set_property -name file_type -value "VHDL 2008" -objects $file_obj }
333  }
334  }
335  }
336  SystemVerilog { set_property -name file_type -value SystemVerilog -objects $file_obj }
337  verilog_header { set_property file_type {Verilog Header} [get_files $path] }
338  verilog_template { set_property file_type {Verilog Template} [get_files $path] }
339  verilog { set_property file_type Verilog [get_files $path] }
340  nosynth { set_property -name used_in_synthesis -value false -objects $file_obj }
341  noimpl { set_property -name used_in_implementation -value false -objects $file_obj }
342  nosim { set_property -name used_in_simulation -value false -objects $file_obj }
343  top {
344  Msg Info "Setting $v as top module for fileset $fs"
345  CurrentProject::Set synth_top_module $v
346  }
347  locked {
348  if {$ext eq ".ip"} {
349  Msg Info "Locking IP $path"
350  set_property IS_MANAGED 0 [get_files $path]
351  }
352  }
353  source {
354  if {$ext eq ".tcl"} {
355  Msg Info "Sourcing $path (excluded from synth/impl/sim)"
356  source $path
357  set_property -name used_in_synthesis -value false -objects $file_obj
358  set_property -name used_in_implementation -value false -objects $file_obj
359  set_property -name used_in_simulation -value false -objects $file_obj
360  }
361  }
362  scoped_to_ref { set_property SCOPED_TO_REF $v $file_obj }
363  scoped_to_cells { set_property SCOPED_TO_CELLS $v $file_obj }
364  topsim { Msg Warning "topsim is deprecated; use sim.conf top=$v" }
365  runtime { Msg Warning "runtime is deprecated; use sim.conf <sim>.simulate.runtime=$v" }
366  wavefile { Msg Warning "wavefile is deprecated; use sim.conf <sim>.simulate.custom_wave_do=$v" }
367  dofile { Msg Warning "dofile is deprecated; use sim.conf <sim>.simulate.custom_do=$v" }
368  }
369  }
370  }
371  }
372 
373  if {[get_filesets -quiet sim_1] ne "" \
374  && [llength [get_files -quiet -of_objects [get_filesets sim_1]]] == 0} {
375  delete_fileset -quiet [get_filesets sim_1]
376  }
377 
378  SetTopProperty [CurrentProject::Get synth_top_module] sources_1
379  }
380 
381  ## @brief configure synthesis.
382  #
383  # The method uses the content of globalSettings::SYNTH_FLOW and globalSettings::SYNTH_STRATEGY to set the implementation strategy and flow.
384  # The function also sets Hog specific pre and post synthesis scripts
385  #
386  proc ConfigureSynthesis {} {
387  ## Create 'synthesis ' run (if not found)
388  if {[string equal [get_runs -quiet synth_1] ""]} {
389  puts "create_run -name synth_1 -part [CurrentProject::Get config main PART] -constrset constrs_1"
390  create_run -name synth_1 -part [CurrentProject::Get config main PART] -constrset constrs_1
391  }
392 
393  set obj [get_runs synth_1]
394  set_property "part" [CurrentProject::Get config main PART] $obj
395 
396  ## set pre synthesis script
397  if {[Repo::Get pre_synth] ne ""} {
398  if {[IsVivado]} {
399  if {[get_filesets -quiet utils_1] != ""} {
400  AddFile [ Repo::Get pre_synth] [get_filesets -quiet utils_1]
401  }
402  set_property STEPS.SYNTH_DESIGN.TCL.PRE [ Repo::Get pre_synth] $obj
403  }
404  Msg Debug "Setting [ Repo::Get pre_synth] to be run before synthesis"
405  }
406 
407  ## set post synthesis script
408  if {[Repo::Get post_synth] ne ""} {
409  if {[IsVivado]} {
410  if {[get_filesets -quiet utils_1] != ""} {
411  AddFile [ Repo::Get post_synth] [get_filesets -quiet utils_1]
412  }
413  set_property STEPS.SYNTH_DESIGN.TCL.POST [ Repo::Get post_synth] $obj
414  }
415  Msg Debug "Setting [ Repo::Get post_synth] to be run after synthesis"
416  }
417 
418 
419  #VIVADO ONLY
420  ## set the current synth run
421  current_run -synthesis $obj
422 
423  ## Report Strategy
424  if {[string equal [get_property -quiet report_strategy $obj] ""]} {
425  # No report strategy needed
426  Msg Debug "No report strategy needed for synthesis"
427  } else {
428  # Report strategy needed since version 2017.3
429  set_property set_report_strategy_name 1 $obj
430  set_property report_strategy {Vivado Synthesis Default Reports} $obj
431  set_property set_report_strategy_name 0 $obj
432  # Create 'synth_1_synth_report_utilization_0' report (if not found)
433  if {[string equal [get_report_configs -of_objects [get_runs synth_1] synth_1_synth_report_utilization_0] ""]} {
434  create_report_config -report_name synth_1_synth_report_utilization_0 -report_type report_utilization:1.0 -steps synth_design -runs synth_1
435  }
436  set reports [get_report_configs -of_objects [get_runs synth_1] synth_1_synth_report_utilization_0]
437  }
438  }
439 
440  ## @brief configure implementation.
441  #
442  # The configuration is based on the content of globalSettings::IMPL_FLOW and globalSettings::IMPL_STRATEGY
443  # The function also sets Hog specific pre- and- post implementation and, pre- and post- implementation scripts
444  #
445  proc ConfigureImplementation {} {
446  set obj ""
447  if {[string equal [get_runs -quiet impl_1] ""]} {
448  puts "create_run -name impl_1 -part [ CurrentProject::Get config main PART] -constrset constrs_1 -parent_run synth_1"
449  create_run -name impl_1 -part [ CurrentProject::Get config main PART] -constrset constrs_1 -parent_run synth_1
450  }
451 
452  set obj [get_runs impl_1]
453  set_property "part" [ CurrentProject::Get config main PART] $obj
454 
455  set_property "steps.[BinaryStepName [ CurrentProject::Get config main PART]].args.readback_file" "0" $obj
456  set_property "steps.[BinaryStepName [ CurrentProject::Get config main PART]].args.verbose" "0" $obj
457 
458  ## set pre implementation script
459  if {[ Repo::Get pre_impl] ne ""} {
460  if {[IsVivado]} {
461  if {[get_filesets -quiet utils_1] != ""} {
462  AddFile [ Repo::Get pre_impl] [get_filesets -quiet utils_1]
463  }
464  set_property STEPS.INIT_DESIGN.TCL.POST [ Repo::Get pre_impl] $obj
465  }
466  Msg Debug "Setting [ Repo::Get pre_impl] to be run after implementation"
467  }
468 
469 
470  ## set post routing script
471  if {[ Repo::Get post_impl] ne ""} {
472  #Vivado Only
473  if {[IsVivado]} {
474  if {[get_filesets -quiet utils_1] != ""} {
475  AddFile [ Repo::Get post_impl] [get_filesets -quiet utils_1]
476  }
477  set_property STEPS.ROUTE_DESIGN.TCL.POST [ Repo::Get post_impl] $obj
478  }
479  Msg Debug "Setting [ Repo::Get post_impl] to be run after implementation"
480  }
481 
482  ## set pre write bitstream script
483  if {[ Repo::Get pre_bit] ne ""} {
484  #Vivado Only
485  if {[IsVivado]} {
486  if {[get_filesets -quiet utils_1] != ""} {
487  AddFile [ Repo::Get pre_bit] [get_filesets -quiet utils_1]
488  }
489  set_property STEPS.[BinaryStepName [ CurrentProject::Get config main PART]].TCL.PRE [ Repo::Get pre_bit] $obj
490  }
491  Msg Debug "Setting [ Repo::Get pre_bit] to be run before bitfile generation"
492  }
493 
494  ## set post write bitstream script
495  if {[ Repo::Get post_bit] ne ""} {
496  if {[IsVivado]} {
497  if {[get_filesets -quiet utils_1] != ""} {
498  AddFile [ Repo::Get post_bit] [get_filesets -quiet utils_1]
499  }
500  set_property STEPS.[BinaryStepName [ CurrentProject::Get config main PART]].TCL.POST [ Repo::Get post_bit] $obj
501  }
502  Msg Debug "Setting [ Repo::Get post_bit] to be run after bitfile generation"
503  }
505  }
506 
507 
508  ## @brief configure simulation
509  #
510  proc ConfigureSimulation {} {
511  set simsets_dict [GetSimSets "[CurrentProject::Get group_name]/[CurrentProject::Get design]" [Repo::Get repo_path]]
512 
513  ##############
514  # SIMULATION #
515  ##############
516  Msg Debug "Setting load_glbl parameter to true for every fileset..."
517  foreach simset [get_filesets -quiet] {
518  if {[get_property FILESET_TYPE $simset] != "SimulationSrcs"} {
519  continue
520  }
521  if {[IsVivado]} {
522  set_property -name {xsim.elaborate.load_glbl} -value {true} -objects [get_filesets $simset]
523  }
524  # Setting Simulation Properties
525  set sim_dict [DictGet $simsets_dict $simset]
526  set sim_props [DictGet $sim_dict "properties"]
527 
528  if {$sim_props != ""} {
529  Msg Info "Setting properties for simulation set: $simset..."
530  dict for {prop_name prop_val} $sim_props {
531  set prop_name [string toupper $prop_name]
532  if {$prop_name == "ACTIVE" && $prop_val == 1} {
533  Msg Info "Setting $simset as active simulation set..."
534  current_fileset -simset [get_filesets $simset]
535  } else {
536  Msg Debug "Setting $prop_name = $prop_val"
537  if {[IsInList [string toupper $prop_name] [VIVADO_PATH_PROPERTIES] 1]} {
538  # Check that the file exists before setting these properties
539  if {[file exists [Repo::Get repo_path]/$prop_val]} {
540  set_property -name $prop_name -value [Repo::Get repo_path]/$prop_val -objects [get_filesets $simset]
541  } else {
542  Msg Warning "Impossible to set property $prop_name to $prop_val. File is missing"
543  }
544  } else {
545  set_property -name $prop_name -value $prop_val -objects [get_filesets $simset]
546  }
547  }
548  }
549  }
550  }
551  }
552 
553  ## @brief uses the content of globalSettings::PROPERTIES to set additional project properties
554  #
555  proc ConfigureProperties {} {
556  set cur_dir [pwd]
557  cd [Repo::Get repo_path]
558  set user_repo "0"
559  # Setting Main Properties
560  if {[CurrentProject::Exists PROPERTIES]} {
561  if {[dict exists [ CurrentProject::Get PROPERTIES] main]} {
562  Msg Info "Setting project-wide properties..."
563  set proj_props [dict get [ CurrentProject::Get PROPERTIES] main]
564  dict for {prop_name prop_val} $proj_props {
565  if {[string tolower $prop_name] != "ip_repo_paths"} {
566  if {[string tolower $prop_name] != "part"} {
567  # Part is already set
568  Msg Debug "Setting $prop_name = $prop_val"
569  set_property -name $prop_name -value $prop_val -objects [current_project]
570  }
571  } else {
572  set ip_repo_list [regsub -all {\s+} $prop_val " [Repo::Get repo_path]/"]
573  set ip_repo_list [Repo::Get repo_path]/$ip_repo_list
574  set user_repo "1"
575  Msg Info "Setting $ip_repo_list as user IP repository..."
576  if {[IsISE]} {
577  set_property ip_repo_paths "$ip_repo_list" [current_fileset]
578  } else {
579  set_property ip_repo_paths "$ip_repo_list" [current_project]
580  }
581  update_ip_catalog
582  }
583  }
584  }
585  # Setting Run Properties
586  foreach run [get_runs -quiet] {
587  if {[CurrentProject::Exists config $run]} {
588  Msg Info "Setting properties for run: $run..."
589  set run_props [dict get [ CurrentProject::Get config] $run]
590  #set_property -dict $run_props $run
591  set stragety_str "STRATEGY strategy Strategy"
592  Msg Debug "Setting Strategy and Flow for run $run (if specified in hog.conf)"
593  foreach s $stragety_str {
594  if {[dict exists $run_props $s]} {
595  set prop [dict get $run_props $s]
596  set_property -name $s -value $prop -objects $run
597  set run_props [dict remove $run_props $s]
598  Msg Warning "A strategy for run $run has been defined inside hog.conf. This prevents Hog to compare the project properties. \
599  Please regenerate your hog.conf file using the dedicated Hog button."
600  Msg Info "Setting $s = $prop"
601  }
602  }
603 
604  dict for {prop_name prop_val} $run_props {
605  Msg Debug "Setting $prop_name = $prop_val"
606  if {[string trim $prop_val] == ""} {
607  Msg Warning "Property $prop_name has empty value. Skipping..."
608  continue
609  }
610  if {[IsInList [string toupper $prop_name] [VIVADO_PATH_PROPERTIES] 1]} {
611  # Check that the file exists before setting these properties
612  set utility_file [Repo::Get repo_path]/$prop_val
613  if {[file exists $utility_file]} {
614  lassign [GetHogFiles -ext_path [CurrentProject::Get config HOG_EXTERNAL_PATH] [Repo::Get list_path] [Repo::Get repo_path]] lib prop dummy
615  foreach {l f} $lib {
616  foreach ff $f {
617  lappend hog_files $ff
618  }
619  }
620  if {[lsearch $hog_files $utility_file] < 0} {
621  Msg CriticalWarning "The file: $utility_file is set as a property in hog.conf, \
622  but is not added to the project in any list file. Hog cannot track it."
623  } else {
624  #Add file tu utils_1 to avoid warning
625  AddFile [Repo::Get repo_path]/$prop_val [get_filesets -quiet utils_1]
626  }
627  set_property -name $prop_name -value $utility_file -objects $run
628  } else {
629  Msg Warning "Impossible to set property $prop_name to $prop_val. File is missing"
630  }
631  } else {
632  set_property -name $prop_name -value $prop_val -objects $run
633  }
634  }
635  }
636  }
637  }
638  cd $cur_dir
639  }
640 
641 
642 
643  proc Synthesize {} {
644  set no_reset [Launcher::Get options no_reset ]
645  set do_create [Launcher::Get options recreate ]
646  set njobs [Launcher::Get options njobs ]
647  set project [CurrentProject::Get project ]
648  set project_name [CurrentProject::Get project_name ]
649  set repo_path [Repo::Get repo_path ]
650  set build_dir [CurrentProject::Get build_dir ]
651  set run_folder "$build_dir/$project.runs/"
652 
653  if {$no_reset == 0} {
654  Msg Info "Resetting run before launching synthesis..."
655  reset_run synth_1
656  }
657 
658  set prog [get_property PROGRESS [get_runs synth_1]]
659  set status [get_property STATUS [get_runs synth_1]]
660  if {$prog eq "100%"} {
661  Msg Info "Run: synth_1 progress: $prog, status : $status"
662  Msg Info "Synthesis already completed, skipping synthesis step..."
663  FlowControl::Produce SYNTHESIS_DONE
664  return
665  }
666 
667  if {[IsISE]} {
668  source [CurrentProject::Get config pre_synth]
669  }
670 
671  launch_runs synth_1 -jobs $njobs -dir $run_folder
672  wait_on_run synth_1
673  set prog [get_property PROGRESS [get_runs synth_1]]
674  set status [get_property STATUS [get_runs synth_1]]
675  Msg Info "Run: synth_1 progress: $prog, status : $status"
676  # Copy IP reports in bin/
677  set ips [get_ips *]
678 
679  #go to repository path
680  cd $repo_path
681 
682  set describe [GetHogDescribe [file normalize ./Top/$project_name] $repo_path]
683  Msg Info "Git describe set to $describe"
684 
685  foreach ip $ips {
686  set xci_file [get_property IP_FILE $ip]
687 
688  set xci_path [file dirname $xci_file]
689  set xci_ip_name [file rootname [file tail $xci_file]]
690  foreach rptfile [glob -nocomplain -directory $xci_path *.rpt] {
691  file copy $rptfile $repo_path/bin/$project_name-$describe/reports
692  }
693  }
694 
695  if {$prog ne "100%"} {
696  Msg Error "Synthesis error, status is: $status"
697  }
698  FlowControl::Produce SYNTHESIS_DONE
699 
700  }
701 
702  proc Implement {} {
703  FlowControl::Require SYNTHESIS_DONE PROJECT_OPEN
704  Msg Info "Starting implementation flow..."
705 
706  set no_reset [Launcher::Get options no_reset ]
707  set do_create [Launcher::Get options recreate ]
708  set njobs [Launcher::Get options njobs ]
709  set no_bitstream [Launcher::Get options no_bitstream ]
710  set project [CurrentProject::Get project ]
711  set project_name [CurrentProject::Get project_name ]
712  set repo_path [Repo::Get repo_path ]
713  set build_dir [CurrentProject::Get build_dir ]
714  set run_folder "$build_dir/$project.runs/"
715 
716 
717 
718  if {$no_reset == 0} {
719  Msg Info "Resetting run before launching implementation..."
720  reset_run impl_1
721  }
722 
723  set prog [get_property PROGRESS [get_runs impl_1]]
724  set status [get_property STATUS [get_runs impl_1]]
725  if {$prog eq "100%" } {
726  Msg Info "Run: impl_1 progress: $prog, status : $status"
727  Msg Info "Implementation already completed, skipping implementation step..."
728  FlowControl::Produce IMPLEMENTATION_DONE
729  return
730  }
731 
732 
733  if {[IsISE]} {
734  source $repo_path/Hog/Tcl/integrated/pre-implementation.tcl
735  }
736 
737  if {$no_bitstream == 0} {
738  launch_runs impl_1 -to_step [BinaryStepName [get_property PART [current_project]]] -jobs $njobs -dir $run_folder
739  } else {
740  launch_runs impl_1 -jobs $njobs -dir $run_folder
741  }
742  wait_on_run impl_1
743 
744  if {[IsISE]} {
745  Msg Info "running post-implementation"
746  source $repo_path/Hog/Tcl/integrated/post-implementation.tcl
747  if {$no_bitstream == 0} {
748  Msg Info "running pre-bitstream"
749  source $repo_path/Hog/Tcl/integrated/pre-bitstream.tcl
750  Msg Info "running post-bitstream"
751  source $repo_path/Hog/Tcl/integrated/post-bitstream.tcl
752  }
753  }
754 
755  set prog [get_property PROGRESS [get_runs impl_1]]
756  set status [get_property STATUS [get_runs impl_1]]
757  Msg Info "Run: impl_1 progress: $prog, status : $status"
758 
759  # Check timing
760  if {[IsISE]} {
761  set status_file [open "$run_folder/timing.txt" "w"]
762  puts $status_file "## $project_name Timing summary"
763 
764  set f [open [lindex [glob "$run_folder/impl_1/*.twr" 0]]]
765  set errs -1
766  while {[gets $f line] >= 0} {
767  if {[string match "Timing summary:" $line]} {
768  while {[gets $f line] >= 0} {
769  if {[string match "Timing errors:*" $line]} {
770  set errs [regexp -inline -- {[0-9]+} $line]
771  }
772  if {[string match "*Footnotes*" $line]} {
773  break
774  }
775  puts $status_file "$line"
776  }
777  }
778  }
779 
780  close $f
781  close $status_file
782 
783  if {$errs == 0} {
784  Msg Info "Time requirements are met"
785  file rename -force "$run_folder/timing.txt" "$run_folder/timing_ok.txt"
786  set timing_ok 1
787  } else {
788  Msg CriticalWarning "Time requirements are NOT met"
789  file rename -force "$run_folder/timing.txt" "$run_folder/timing_error.txt"
790  set timing_ok 0
791  }
792  }
793 
794  if {[IsVivado]} {
795  set wns [get_property STATS.WNS [get_runs [current_run]]]
796  set tns [get_property STATS.TNS [get_runs [current_run]]]
797  set whs [get_property STATS.WHS [get_runs [current_run]]]
798  set ths [get_property STATS.THS [get_runs [current_run]]]
799  set tpws [get_property STATS.TPWS [get_runs [current_run]]]
800 
801  if {$wns >= 0 && $whs >= 0 && $tpws >= 0} {
802  Msg Info "Time requirements are met"
803  set status_file [open "$run_folder/timing_ok.txt" "w"]
804  set timing_ok 1
805  } else {
806  Msg CriticalWarning "Time requirements are NOT met"
807  set status_file [open "$run_folder/timing_error.txt" "w"]
808  set timing_ok 0
809  }
810 
811  Msg Status "*** Timing summary ***"
812  Msg Status "WNS: $wns"
813  Msg Status "TNS: $tns"
814  Msg Status "WHS: $whs"
815  Msg Status "THS: $ths"
816  Msg Status "TPWS: $tpws"
817 
818  struct::matrix m
819  m add columns 5
820  m add row
821 
822  puts $status_file "## $project_name Timing summary"
823 
824  m add row "| **Parameter** | \"**value (ns)**\" |"
825  m add row "| --- | --- |"
826  m add row "| WNS: | $wns |"
827  m add row "| TNS: | $tns |"
828  m add row "| WHS: | $whs |"
829  m add row "| THS: | $ths |"
830  m add row "| TPWS: | $tpws |"
831 
832  puts $status_file [m format 2string]
833  puts $status_file "\n"
834  if {$timing_ok == 1} {
835  puts $status_file " Time requirements are met."
836  } else {
837  puts $status_file "Time requirements are **NOT** met."
838  }
839  puts $status_file "\n\n"
840  close $status_file
841  }
842 
843  if {$prog ne "100%"} {
844  Msg Error "Implementation error"
845  }
846 
847  #Go to repository path
848  cd $repo_path
849  set describe [GetHogDescribe [file normalize ./Top/$project_name] $repo_path]
850  Msg Info "Git describe set to $describe"
851 
852  set dst_dir [file normalize "$repo_path/bin/$project_name\-$describe"]
853 
854  file mkdir $dst_dir
855 
856  #Version table
857  if {[file exists $run_folder/versions.txt]} {
858  file copy -force $run_folder/versions.txt $dst_dir
859  } else {
860  Msg Warning "No versions file found in $run_folder/versions.txt"
861  }
862  #Timing file
863  set timing_files [glob -nocomplain "$run_folder/timing_*.txt"]
864  set timing_file [file normalize [lindex $timing_files 0]]
865 
866  if {[file exists $timing_file]} {
867  file copy -force $timing_file $dst_dir/
868  } else {
869  Msg Warning "No timing file found, not a problem if running locally"
870  }
871 
872  #### XSA here only for Versal Segmented Configuration
873  if {[IsVersal [get_property part [current_project]]]} {
874  if {[get_property segmented_configuration [current_project]] == 1} {
875  Msg Info "Versal Segmented configuration detected: exporting XSA file..."
876  set xsa_name "$dst_dir/[file tail $project_name]\-$describe.xsa"
877  write_hw_platform -fixed -force -file $xsa_name
878  }
879  }
880  FlowControl::Produce IMPLEMENTATION_DONE
881  }
882 
883  proc GenerateBitstream {} {
884  Msg Info "Generating bitstream..."
885 
886  puts "Current Flow state:"
887  puts "[tobj tojson $FlowControl::_state -pretty]"
888  puts "Datastores:"
889  puts "[tobj tojson [DataStore::Serialize] -pretty]"
890  }
891 
892  proc Simulate {} {
893 
894  if {[FlowControl::Has SYNTH] && ![FlowControl::Has IMPL]} {
895  Msg Info "Running post-synthesis simulation..."
896  } elseif {[FlowControl::Has IMPL]} {
897  Msg Info "Running post-implementation simulation..."
898  } else {
899  Msg Info "Running RTL simulation..."
900  FlowControl::Produce PRE_SYNTH_SIM
901  }
902 
903  }
904 
905  proc CheckSyntax {} {
906  Msg Info "Checking syntax..."
907  }
908 
909  proc RtlAnalysis {} {
910  Msg Info "Running RTL analysis..."
911  }
912 
913 }