-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.tcl
1316 lines (1178 loc) · 49.6 KB
/
build.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SPDX-License-Identifier: Apache-2.0
#
################################################################################
##
## Copyright 2017-2023 Missing Link Electronics, Inc.
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
################################################################################
##
## File Name : build.tcl
## Initial Author : Andreas Braun <[email protected]>
##
################################################################################
##
## File Summary : Vivado build TCL script executed from build.sh
##
################################################################################
################################################################################
## Declare build steps
set build_steps(prj) 0
set build_steps(exec_tcl) 1
set build_steps(sim_prep) 2
set build_steps(sim) 3
set build_steps(package) 4
set build_steps(synth_ooc) 5
set build_steps(synth) 6
set build_steps(impl) 7
set build_steps(bit) 8
################################################################################
## Script command processing
# Command line option defaults
set flavor "."
set start_step $build_steps(prj)
set end_step $build_steps(bit)
set generic_tupels [list]
set vdefine_tupels [list]
set ign_vivado_vers 0
set tcl_files [list]
# Process command line options
set num_arg $argc
if {$num_arg > 0} {
for {set i 0} {$i < $num_arg} {incr i} {
set arg [lindex $argv $i]
if {[regexp {^script_dir=(.*)$} $arg match val] == 1} {
set scripts_dir "[file normalize "${val}"]"
}
if {[regexp {^base_dir=(.*)$} $arg match val] == 1} {
set base_dir "[file normalize "${val}"]"
}
if {[regexp {^flavor=(.*)$} $arg match val] == 1} {
set flavor "$val"
}
if {[regexp {^xpr_name=(.*)$} $arg match val] == 1} {
set xpr_name "$val"
}
if {[regexp {^config_dict_name=(.*)$} $arg match val] == 1} {
set config_dict_name $val
}
if {[regexp {^start_step=(.*)$} $arg match val] == 1} {
set start_step $build_steps($val)
}
if {[regexp {^end_step=(.*)$} $arg match val] == 1} {
set end_step $build_steps($val)
}
if {[regexp {^generic=(.*)$} $arg match val] == 1} {
lappend generic_tupels $val
}
if {[regexp {^vdefine=(.*)$} $arg match val] == 1} {
lappend vdefine_tupels $val
}
if {[regexp {^ign_vivado_vers.*} $arg] == 1} {
set ign_vivado_vers 1
}
if {[regexp {^tcl_file=(.*)$} $arg match val] == 1} {
lappend tcl_files $val
}
}
}
set tcl_files [lreverse $tcl_files]
if {![info exists scripts_dir]} {
puts "Please set the scripts directory or use build.sh"
exit 2
}
if {![info exists base_dir]} {
puts "Please set the base directory or use build.sh"
exit 2
}
if {![info exists xpr_name]} {
puts "Please set XPR name or use build.sh"
exit 2
}
################################################################################
## Paths
set project_dir "[pwd]"
set flavor_dir "[file normalize "${base_dir}/${flavor}"]"
################################################################################
## Build helpers
set helper_tcl_file "[file normalize "${scripts_dir}/helper.tcl"]"
source "${helper_tcl_file}"
set config_dict_file "[file normalize "${base_dir}/${flavor}/${config_dict_name}"]"
if {[file exists "${config_dict_file}"]} {
set config_dict [parse_dict [restore_dict "${config_dict_file}"]]
} else {
puts "ERROR: Configuration dictionary file not found: ${config_dict_file}"
exit 2
}
set bvars_file "[file normalize "${project_dir}/bvars.dict"]"
if {[file exists "${bvars_file}"]} {
set bvars_dict [restore_dict "${bvars_file}"]
} else {
set bvars_dict [dict create]
}
## Set/reset error counters
# Vivado log file parsing defaults
dict set bvars_dict VMERR 0
dict set bvars_dict VMCWARN 0
dict set bvars_dict VMWARN 0
# GIT command execution error
dict set bvars_dict GITERR 0
# Store script arguments
dict set bvars_dict BDIR $base_dir
dict set bvars_dict FLAV $flavor
dict set bvars_dict XPR $xpr_name
dict set bvars_dict CDICT $config_dict_name
dict set bvars_dict SSTEP $start_step
dict set bvars_dict ESTEP $end_step
dict set bvars_dict IGNVV $ign_vivado_vers
dict set bvars_dict EXTCL $tcl_files
dict set bvars_dict CDF $config_dict_file
################################################################################
## Set project parameters from configuration-dictionary
set mdt_params [dict get $config_dict "MDT_PARAMS"]
dict for {key val} $mdt_params {
set "${key}" "${val}"
}
if {[dict exists $config_dict "OPT_PARAMS"]} {
set opt_params [dict get $config_dict "OPT_PARAMS"]
dict for {key val} $opt_params {
set "${key}" "${val}"
}
}
if {[dict exists $config_dict "SIM_PARAMS"]} {
set sim_params [dict get $config_dict "SIM_PARAMS"]
dict for {key val} $sim_params {
set "${key}" "${val}"
}
}
# Set global TCL variables
if {[dict exists $config_dict "TCL_GLOBALS"]} {
set tcl_globals [dict get $config_dict "TCL_GLOBALS"]
dict for {key val} $tcl_globals {
global "${key}"
set "${key}" "${val}"
}
}
################################################################################
## Setup hook scripts
# Helper tcl path to be used in hooks
dict set bvars_dict HELPER $helper_tcl_file
# Build system hooks
dict set bvars_dict HOOKS "sys_synth_post" \
"[file normalize "${scripts_dir}/hooks/sys_synth_post.tcl"]" \
"[file normalize "${scripts_dir}/hooks/sys_write_netlist.tcl"]"
dict set bvars_dict HOOKS "sys_impl_pre" \
"[file normalize "${scripts_dir}/hooks/sys_impl_pre.tcl"]"
dict set bvars_dict HOOKS "sys_impl_post" \
"[file normalize "${scripts_dir}/hooks/sys_impl_post.tcl"]"
dict set bvars_dict HOOKS "sys_bit_pre" \
"[file normalize "${scripts_dir}/hooks/sys_bit_pre.tcl"]"
dict set bvars_dict HOOKS "sys_bit_post" \
"[file normalize "${scripts_dir}/hooks/sys_bit_post.tcl"]"
# User hooks
if {[dict exists $config_dict "USER_HOOKS"]} {
set user_hooks [dict get $config_dict "USER_HOOKS"]
dict for {build_step filenames} $user_hooks {
set build_step_hooks [list]
foreach file $filenames {
lappend build_step_hooks "[file normalize "${flavor_dir}/${file}"]"
}
dict set bvars_dict HOOKS $build_step $build_step_hooks
}
}
################################################################################
# Vivado version verification
set vivado_version [version -short]
if {[lsearch -exact $req_vivado_vers $vivado_version] < 0} {
puts ""
if {$ign_vivado_vers == 1} {
puts -nonewline "WARNING: You are using Vivado '$vivado_version' and "
puts "not the recommended '[lindex $req_vivado_vers 0]'!"
puts -nonewline "The build will continue since you chose to ignore the "
puts "incorrect Vivado version"
} else {
puts -nonewline "ERROR: Please use Vivado '[lindex $req_vivado_vers 0]'"
puts " and not '$vivado_version' to build the system!"
puts -nonewline "You can prevent this error message by providing the "
puts "'-i' argument to build.sh"
exit 2
}
} elseif {![string equal "[lindex $req_vivado_vers 0]" "$vivado_version"]} {
puts -nonewline "WARNING: You are using Vivado '$vivado_version' and not "
puts "the recommended '[lindex $req_vivado_vers 0]'!"
}
set vivado_year [lindex [split "${vivado_version}" "."] 0]
################################################################################
## Check simulation environment
if {[catch {set pre_comp_simlib_dir $::env(PRECOMP_SIM_LIBS)}]} {
puts "INFO: Simulation environment variable PRECOMP_SIM_LIBS not set"
set lib_compile [dict_val4key "SIM_PARAMS:LIB_COMPILE" $config_dict]
if {$lib_compile != ""} {
# Set pre_comp_simlib_dir to the LIB_COMPILE directory or default path
if {[dict exists $lib_compile "directory"]} {
set pre_comp_simlib_dir [file normalize \
"$flavor_dir/[dict get $lib_compile "directory"]"]
} else {
set pre_comp_simlib_dir "$flavor_dir/sim/sim_libs"
}
file mkdir $pre_comp_simlib_dir
puts "INFO: Using ${pre_comp_simlib_dir} as PRECOMP_SIM_LIBS"
}
} else {
set pre_comp_simlib_dir "[file normalize "${pre_comp_simlib_dir}"]"
puts "INFO: Simulation environment variable set to '${pre_comp_simlib_dir}'"
}
if {[info exists target_simulator]} {
if {[string equal $target_simulator "XSim"]} {
set sim_lib_valid 1
set pre_comp_simlib_dir ""
} elseif {[info exists pre_comp_simlib_dir] && \
![string equal $pre_comp_simlib_dir ""]} {
set rpt_file "[file normalize "${project_dir}/report_simlib_info.log"]"
set code [catch {report_simlib_info -file $rpt_file $pre_comp_simlib_dir}]
set i 0
set fid [open $rpt_file r]
while {[gets $fid line] > -1} {incr i}
close $fid
if {[expr {$i > 100}]} {
set sim_lib_valid 1
} else {
puts -nonewline "WARNING: Invalid pre-compiled simulation libraries"
puts -nonewline " for target simulator '${target_simulator}' located "
puts -nonewline "in '${pre_comp_simlib_dir}'. Check Simlib-info "
puts "report file '${rpt_file}' for details"
}
} else {
puts -nonewline "WARNING: No path to pre-compiled simulation libraries "
puts "set for target simulator '${target_simulator}'"
}
} else {
set target_simulator "XSim"
}
set target_simulator_lc [string tolower $target_simulator]
################################################################################
## Set up project
if {$start_step == $build_steps(prj)} {
save_dict "${bvars_file}" $bvars_dict
exec_usr_hooks "bld_prj_pre" $bvars_dict
set fileset_constrs_name "constrs_1"
set fileset_sources_name "sources_1"
set fileset_sim_name "sim_1"
puts "Creating project \"$xpr_name\" in $project_dir"
if {![info exists board]} {
set board ""
puts "Using a $part FPGA on an unspecified board"
} else {
puts "Using a $part FPGA on the $board board"
}
puts "Create filesets constraints, source, simulation"
create_project $xpr_name $project_dir -part $part -force
set cur_prj [get_projects $xpr_name]
set_property board_part $board $cur_prj
set_property target_language $target_language $cur_prj
set_property default_lib $default_lib $cur_prj
set_property target_simulator $target_simulator $cur_prj
if {[info exists sim_lib_valid]} {
set_property "compxlib.${target_simulator_lc}_compiled_library_dir" \
$pre_comp_simlib_dir $cur_prj
}
if {[info exists simulator_language]} {
set_property simulator_language $simulator_language $cur_prj
}
# IP-XACT repositories relative to flavor
if {[info exists ipxact_dir]} {
puts "Parsing IP-XACT repositories from configuration file ..."
set ipxact_dirs [list]
# Procedure to resolve a shell variable and return the full path
proc resolve_path {path flavor_dir} {
# Resolve shell variables using shell execution
set shell_command "echo $path"
# Use exec to get the resolved path
set resolved_path [exec /bin/sh -c $shell_command]
# Check if the resolved path is absolute (for UNIX and Windows)
if {[string index $resolved_path 0] eq "/" || \
[string match "?:*\\*" $resolved_path]} {
# It's an absolute path
return $resolved_path
} else {
# Normalize it relative to the flavor directory
return [file normalize [file join $flavor_dir $resolved_path]]
}
}
# Use the resolve_path function for each IP-XACT directory
foreach value $ipxact_dir {
set resolved_path [resolve_path "$value" $flavor_dir]
lappend ipxact_dirs $resolved_path
puts $resolved_path
}
if {[package vcompare [version -short] 2014.3] >= 0} {
set_property ip_repo_paths $ipxact_dirs $cur_prj
} else {
set_property ip_repo_paths $ipxact_dirs [current_fileset]
}
}
# Set IP Cache
if {[info exists use_ip_cache_dir]} {
if {"${use_ip_cache_dir}" == ""} {
set use_ip_cache_dir "[file normalize "${project_dir}/../ip_cache"]"
} else {
set use_ip_cache_dir "[file normalize \
"${flavor_dir}/${use_ip_cache_dir}"]"
}
file mkdir $use_ip_cache_dir
config_ip_cache -import_from_project -use_cache_location \
"${use_ip_cache_dir}"
}
if {[string equal [get_filesets -quiet $fileset_constrs_name] ""]} {
create_fileset -constrset $fileset_constrs_name
}
set fileset_constrs [get_filesets $fileset_constrs_name]
if {[string equal [get_filesets -quiet $fileset_sources_name] ""]} {
create_fileset -srcset $fileset_sources_name
}
set fileset_sources [get_filesets $fileset_sources_name]
if {[string equal [get_filesets -quiet $fileset_sim_name] ""]} {
create_fileset -simset $fileset_sim_name
}
set fileset_sim [get_filesets $fileset_sim_name]
if {[package vcompare [version -short] 2018.3] >= 0} {
set fileset_utils [current_fileset "utils_1"]
set vbs_bd_util_file [file normalize \
"${scripts_dir}/util/vbs_bd_util.tcl"]
add_files -fileset $fileset_utils -norecurse $helper_tcl_file
add_files -fileset $fileset_utils -norecurse $bvars_file
add_files -fileset $fileset_utils -norecurse $vbs_bd_util_file
}
# Process .f and return filelist
proc process_filelist {filelist_path files_dir} {
set filelist [list]
set fd_filelist [open "${filelist_path}" r]
while {[gets $fd_filelist line] >= 0} {
if {![regexp {^(\s*#.*|^$)} $line]} {
set filepath "[file normalize "${files_dir}/${line}"]"
if {![file exists $filepath]} {
puts "ERROR: File not found '$filepath'"
exit 2
} else {
lappend filelist $filepath
puts $filepath
}
}
}
close $fd_filelist
return $filelist
}
## Process filelists
# Iterate over all filelists and add named files from given directory to
# fileset. Paths are relative to flavor directory
# Process constraints set
set filelist_constr [list]
if {[dict exists $config_dict "CONSTR_SET"]} {
puts "Adding files to constraints set ..."
set constr_set [dict get $config_dict "CONSTR_SET"]
dict for {constr_f files_dir} $constr_set {
set filelist_constr [concat $filelist_constr [process_filelist \
"${flavor_dir}/${constr_f}" "${flavor_dir}/${files_dir}"]]
}
if {[llength $filelist_constr] == 0} {
puts "WARNING: No files have been added to constraints set"
} else {
add_files -norecurse -fileset $fileset_constrs $filelist_constr
}
}
# Process source set
set filelist_src [list]
if {[dict exists $config_dict "SRC_SET"]} {
puts "Adding files to source set ..."
set src_set [dict get $config_dict "SRC_SET"]
dict for {src_f files_dir} $src_set {
set filelist_src [concat $filelist_src [process_filelist \
"${flavor_dir}/${src_f}" "${flavor_dir}/${files_dir}"]]
}
if {[llength $filelist_src] == 0} {
puts "WARNING: No files have been added to source set"
} else {
add_files -norecurse -fileset $fileset_sources $filelist_src
}
}
# Process simulation set
set filelist_sim [list]
if {[dict exists $config_dict "SIM_SET"]} {
puts "Adding files to simulation set ..."
set sim_set [dict get $config_dict "SIM_SET"]
dict for {sim_f files_dir} $sim_set {
set filelist_sim [concat $filelist_sim [process_filelist \
"${flavor_dir}/${sim_f}" "${flavor_dir}/${files_dir}"]]
}
if {[llength $filelist_sim] == 0} {
puts "WARNING: No files have been added to simulation set"
} else {
add_files -norecurse -fileset $fileset_sim $filelist_sim
}
}
# Process include set
if {[dict exists $config_dict "INCL_SET"]} {
puts "Parsing INCL_SET files ..."
set filelist_incl [list]
set incl_set [dict get $config_dict "INCL_SET"]
dict for {incl_f files_dir} $incl_set {
set filelist_incl [concat $filelist_incl [process_filelist \
"${flavor_dir}/${incl_f}" "${flavor_dir}/${files_dir}"]]
}
if {[llength $filelist_incl] == 0} {
puts "WARNING: No directories have been included to source and simulation set"
} else {
set incl_file_dirs [list]
foreach incl_file $filelist_incl {
lappend incl_file_dirs [file dirname $incl_file]
}
set incl_file_dirs [lsort -unique $incl_file_dirs]
puts "Adding include directories to source and simulation set"
foreach incl_file_dir $incl_file_dirs {
puts "${incl_file_dir}"
}
set_property include_dirs $incl_file_dirs $fileset_sources
set_property include_dirs $incl_file_dirs $fileset_sim
}
}
# Process simulation include set
if {[dict exists $config_dict "SIM_INCL_SET"]} {
puts "Parsing SIM_INCL_SET files ..."
set filelist_incl [list]
set incl_set [dict get $config_dict "SIM_INCL_SET"]
dict for {incl_f files_dir} $incl_set {
set filelist_incl [concat $filelist_incl [process_filelist \
"${flavor_dir}/${incl_f}" "${flavor_dir}/${files_dir}"]]
}
if {[llength $filelist_incl] == 0} {
puts "WARNING: No directories have been included to simulation set"
} else {
set incl_file_dirs [list]
foreach incl_file $filelist_incl {
lappend incl_file_dirs [file dirname $incl_file]
}
set incl_file_dirs [lsort -unique $incl_file_dirs]
puts "Adding include directories to simulation set"
foreach incl_file_dir $incl_file_dirs {
puts "${incl_file_dir}"
}
set_property include_dirs $incl_file_dirs $fileset_sim
}
}
# Process tcl set
set filelist_tcl [list]
if {[dict exists $config_dict "TCL_SET"]} {
puts "Sourcing TCL files ..."
set tcl_set [dict get $config_dict "TCL_SET"]
dict for {tcl_f files_dir} $tcl_set {
set filelist_tcl [concat $filelist_tcl [process_filelist \
"${flavor_dir}/${tcl_f}" "${flavor_dir}/${files_dir}"]]
}
if {[llength $filelist_tcl] == 0} {
puts "WARNING: No TCL files have been sourced"
} else {
foreach tcl_file $filelist_tcl {
if {[file exists "${tcl_file}"]} {
source "${tcl_file}"
} else {
puts "WARNING: TCL file does not exist: ${tcl_file}"
}
}
}
}
if {[info exists debug_target]} {
# If set but empty, use default name
if {"${debug_target}" == ""} {
set debug_target "debug.xdc"
}
set debug_constrs_file [get_files -quiet "${debug_target}"]
# Check if file exists, if not, create it local to the project
if {[llength $debug_constrs_file] == 0} {
puts "Create empty constraints file '${debug_target}' \
for debug statements and mark the file as target ..."
set debug_constrs_dir "[file normalize \
"${project_dir}/${xpr_name}.srcs/${fileset_constrs_name}"]"
file mkdir $debug_constrs_dir
set debug_constrs_file "[file normalize \
"${debug_constrs_dir}/${debug_target}"]"
close [ open $debug_constrs_file w ]
add_files -fileset $fileset_constrs_name $debug_constrs_file
}
set_property target_constrs_file $debug_constrs_file $fileset_constrs
} else {
set debug_target ""
}
dict set bvars_dict DBGT [file rootname "${debug_target}"]
############################################################################
# Pass generics to top level HDL
if {[dict exists $config_dict "GENERICS"]} {
puts "Parsing generics from configuration file ..."
set generics [dict get $config_dict "GENERICS"]
dict for {gen_name gen_value} $generics {
# Insert at the beginning of the list, to let the values be
# overridden by generics passed from command line.
set generic_tupels [linsert $generic_tupels 0 \
"${gen_name}=${gen_value}"]
}
}
if {[llength $generic_tupels] > 0} {
set_property generic $generic_tupels $fileset_sources
}
if {[dict exists $config_dict "VERILOG_OPTIONS"]} {
set vopts_dict [dict get $config_dict "VERILOG_OPTIONS"]
# Include files search path relative to flavor
if {[dict exists $vopts_dict "INCL_DIRS"]} {
puts "Parsing Verilog include directories from configuration file ..."
set vincl_dirs [list]
set incl_dirs_key [dict get $vopts_dict "INCL_DIRS"]
foreach value $incl_dirs_key {
lappend vincl_dirs "[file normalize "${flavor_dir}/${value}"]"
}
set_property include_dirs $vincl_dirs $fileset_sources
}
# Pass Verilog defines to top level HDL
if {[dict exists $vopts_dict "DEFINES"]} {
puts "Parsing Verilog defines from configuration file ..."
set vdefines [dict get $vopts_dict "DEFINES"]
dict for {vdef_name vdef_value} $vdefines {
# Insert at the beginning of the list, to let the values be
# overridden by verilog defines passed from command line.
set vdefine_tupels [linsert $vdefine_tupels 0 \
"${vdef_name}=${vdef_value}"]
}
}
# Pass Verilog defines to Simulation
if {[dict exists $vopts_dict "SIM_DEFINES"]} {
puts "Parsing Verilog Simulation defines from configuration file ..."
set vsimdefine_tupels [list]
set vsimdefines [dict get $vopts_dict "SIM_DEFINES"]
dict for {vdef_name vdef_value} $vsimdefines {
lappend vsimdefine_tupels "${vdef_name}=${vdef_value}"
}
set_property verilog_define $vsimdefine_tupels $fileset_sim
}
}
if {[llength $vdefine_tupels] > 0} {
set_property verilog_define $vdefine_tupels $fileset_sources
}
dict set bvars_dict GNRCS [regsub -all -line {=} "${generic_tupels}" " "]
dict set bvars_dict VDEFS [regsub -all -line {=} "${vdefine_tupels}" " "]
############################################################################
if {[info exists sim_time] && ![string equal $sim_time ""]} {
set_property -name "${target_simulator_lc}.simulate.runtime" \
-value "${sim_time}" -objects $fileset_sim
}
if {[info exists sim_log_all] && ![string equal $sim_log_all ""]} {
set_property -name "${target_simulator_lc}.simulate.log_all_signals" \
-value "${sim_log_all}" -objects $fileset_sim
}
if {[info exists sim_wave_do] && ![string equal $sim_wave_do ""]} {
set_property -name "${target_simulator_lc}.simulate.custom_wave_do" \
-value "${sim_wave_do}" -objects $fileset_sim
}
############################################################################
## Out of context runs
puts "Creating out of context runs ..."
if {[dict exists $config_dict "OOC_MODULES"]} {
set ooc_modules [dict get $config_dict "OOC_MODULES"]
dict for {ooc_module ooc_fileset} $ooc_modules {
set filelist_ooc_constr [list]
set ooc_module_dict [dict get $ooc_modules "${ooc_module}"]
dict for {ooc_constr_f ooc_files_dir} $ooc_module_dict {
set filelist_ooc_constr [concat $filelist_ooc_constr \
[process_filelist \
"${flavor_dir}/${ooc_constr_f}" \
"${flavor_dir}/${ooc_files_dir}"]]
}
# Create OOC fileset
set fileset_ooc_module "${ooc_module}_ooc"
create_fileset -blockset -define_from "${ooc_module}" \
"${fileset_ooc_module}"
if {[llength $filelist_ooc_constr] == 0} {
puts "WARNING: No files have been added to OOC constraints set\
for module '${ooc_module}'"
} else {
add_files -norecurse -fileset $fileset_ooc_module \
$filelist_ooc_constr
}
}
}
############################################################################
## In context run
puts "Creating synthesis run ..."
set run_synth_name "synth_1"
if {[string equal [get_runs -quiet $run_synth_name] ""]} {
create_run $run_synth_name -part $part \
-flow "Vivado Implementation ${vivado_year}" \
-srcset $fileset_sources -constrset $fileset_constrs
}
set run_synth [get_runs $run_synth_name]
puts "Setting active run to synthesis run ..."
current_run $run_synth
if {[dict exists $config_dict "SYNTH_STRAT"]} {
set synth_strat [dict get $config_dict "SYNTH_STRAT"]
dict for {key value} $synth_strat {
set_property "${key}" "${value}" $run_synth
}
}
############################################################################
if {[info exists hdl_top_module_name]} {
puts "Setting ${hdl_top_module_name} as top-level module ..."
set_property top $hdl_top_module_name $fileset_sources
}
puts "Updating compile order on fileset_sources ..."
update_compile_order -fileset $fileset_sources
if {[info exists sim_top_module_name]} {
puts "Setting ${sim_top_module_name} as test bench top-level module ..."
set_property top $sim_top_module_name $fileset_sim
set_property top_lib $default_lib $fileset_sim
puts "Updating compile order on fileset_sim ..."
update_compile_order -fileset $fileset_sim
}
############################################################################
puts "Creating implementation run ..."
set run_impl_name "impl_1"
if {[string equal [get_runs -quiet $run_impl_name] ""]} {
create_run $run_impl_name -part $part -parent_run $run_synth \
-flow "Vivado Implementation ${vivado_year}" \
-constrset $fileset_constrs
}
set run_impl [get_runs $run_impl_name]
if {[dict exists $config_dict "IMPL_STRAT"]} {
set impl_strat [dict get $config_dict "IMPL_STRAT"]
dict for {key value} $impl_strat {
set_property "${key}" "${value}" $run_impl
}
}
############################################################################
# Special file properties
# Use file only in defined steps
if {[dict exists $config_dict "USE_FILE_ONLY_IN_STEPS"]} {
set file_step_dict [dict get $config_dict "USE_FILE_ONLY_IN_STEPS"]
dict for {file_name step} $file_step_dict {
set_property USED_IN "$step" [get_files $file_name]
}
}
# Set constraints file processing order EARLY, NORMAL, LATE
if {[dict exists $config_dict "CONSTR_PROC_ORDER"]} {
set file_proc_order_dict [dict get $config_dict "CONSTR_PROC_ORDER"]
dict for {file_name order} $file_proc_order_dict {
set_property PROCESSING_ORDER "$order" [get_files $file_name]
}
}
############################################################################
# Hook setup
# Copy template hook file to build folder and replace build step string. Set
# hook as Vivado's pre/post step property. Use hook as entry point to
# execute user hooks
if {[dict exists $bvars_dict "HOOKS"]} {
# Template hook file
set hook_src "${scripts_dir}/templates/viv_sys_hook.tcl"
set hooks [dict get $bvars_dict "HOOKS"]
dict for {build_step filenames} $hooks {
if {[info exists fileset_utils]} {
foreach file $filenames {
add_files -fileset $fileset_utils -norecurse $file
}
}
if {[string match "viv_sim_pre" $build_step]} {
# Simulation pre
set hook_dest "${project_dir}/hooks/viv_sys_sim_pre.tcl"
copy_sub $hook_src $hook_dest "<HOOK_STEP>" $build_step
if {[info exists fileset_utils]} {
add_files -fileset $fileset_utils -norecurse $hook_dest
}
set_property -name "${target_simulator_lc}.compile.tcl.pre" \
-value $hook_dest -objects $fileset_sim
} elseif {[string match "viv_sim_post" $build_step]} {
# Simulation post
set hook_dest "${project_dir}/hooks/viv_sys_sim_post.tcl"
copy_sub $hook_src $hook_dest "<HOOK_STEP>" $build_step
if {[info exists fileset_utils]} {
add_files -fileset $fileset_utils -norecurse $hook_dest
}
set_property -name "${target_simulator_lc}.simulate.tcl.post" \
-value $hook_dest -objects $fileset_sim
} elseif {[string match "viv_impl_*" $build_step]} {
# Implementation pre/post
set split_step [split $build_step "_"]
set step_impl [join [lrange $split_step 2 end-1] "_"]
set step_prefix [lindex $split_step end]
set hook_dest "${project_dir}/hooks/viv_sys_impl_${step_impl}.${step_prefix}.tcl"
copy_sub $hook_src $hook_dest "<HOOK_STEP>" $build_step
if {[info exists fileset_utils]} {
add_files -fileset $fileset_utils -norecurse $hook_dest
}
set_property steps.${step_impl}.tcl.${step_prefix} $hook_dest \
$run_impl
} elseif {[string match "viv_bit_post" $build_step]} {
# Bitstream post
set hook_dest "${project_dir}/hooks/viv_sys_bit_post.tcl"
copy_sub $hook_src $hook_dest "<HOOK_STEP>" $build_step
if {[info exists fileset_utils]} {
add_files -fileset $fileset_utils -norecurse $hook_dest
}
# Bitstream is a Device Image for Versal devices
if {[llength [list_property $run_impl STEPS.WRITE_DEVICE_IMAGE.TCL.PRE]]} {
set_property steps.write_device_image.tcl.post $hook_dest $run_impl
} else {
set_property steps.write_bitstream.tcl.post $hook_dest $run_impl
}
}
}
}
# Vivado Hooks
set syn_pre [file normalize "${scripts_dir}/hooks/viv_sys_synth_pre.tcl"]
set syn_post [file normalize "${scripts_dir}/hooks/viv_sys_synth_post.tcl"]
set bit_pre [file normalize "${scripts_dir}/hooks/viv_sys_bit_pre.tcl"]
if {[info exists fileset_utils]} {
add_files -fileset $fileset_utils -norecurse $syn_pre
add_files -fileset $fileset_utils -norecurse $syn_post
add_files -fileset $fileset_utils -norecurse $bit_pre
}
set_property steps.synth_design.tcl.pre $syn_pre $run_synth
set_property steps.synth_design.tcl.post $syn_post $run_synth
# Bitstream is a Device Image for Versal devices
if {[llength [list_property $run_impl STEPS.WRITE_DEVICE_IMAGE.TCL.PRE]]} {
set_property steps.write_device_image.tcl.pre $bit_pre $run_impl
} else {
set_property steps.write_bitstream.tcl.pre $bit_pre $run_impl
}
############################################################################
puts "INFO: Creating project done"
save_dict "${bvars_file}" $bvars_dict
exec_usr_hooks "bld_prj_post" $bvars_dict
} else {
puts "INFO: Opening project ${xpr_name}.xpr"
open_project "${xpr_name}.xpr"
}
################################################################################
## Update build helper
set run_synth [current_run -synthesis]
set run_impl [current_run -implementation]
# Vivado context will be lost in Hooks
dict set bvars_dict RSYNTH "${run_synth}"
dict set bvars_dict RIMPL "${run_impl}"
dict set bvars_dict RSIM [current_fileset -simset]
dict set bvars_dict PNAME [get_projects]
dict set bvars_dict TLNAME [get_property top [current_fileset]]
save_dict "${bvars_file}" $bvars_dict
################################################################################
## Execute TCL script files
foreach tcl_file $tcl_files {
if {[file exists "${tcl_file}"]} {
puts "INFO: Execute TCL script ${tcl_file}"
source "${tcl_file}"
} else {
puts "ERROR: TCL file does not exist: '${tcl_file}'"
exit 2
}
}
################################################################################
## Generate simulation scripts and compile simulation libraries
if {$start_step == $build_steps(sim_prep) || $end_step == $build_steps(sim_prep)} {
set end_step $build_steps(sim_prep)
puts "INFO: Generate simulation scripts and compile simulation libraries"
if {$target_simulator_lc != "xsim"} {
set lib_compile [dict_val4key "SIM_PARAMS:LIB_COMPILE" $config_dict]
if {$lib_compile == ""} {
puts "WARNING: Missing LIB_COMPILE key in dictionary.\
Will not compile simulation libraries"
} else {
set cmd_args [list \
"-simulator" ${target_simulator_lc} \
]
if {[dict exists $lib_compile "directory"]} {
set directory "$flavor_dir/[dict get $lib_compile "directory"]"
} else {
set directory "$flavor_dir/sim/sim_libs"
}
lappend cmd_args "-directory" [file normalize "${directory}"]
# If the key does not exist, then no argument will be appended and
# Vivado uses the default
catch {
lappend cmd_args "-family" \
[string tolower [dict get $lib_compile "family"]]
}
catch {
lappend cmd_args "-language" \
[string tolower [dict get $lib_compile "language"]]
}
if {[dict exists $lib_compile "libraries"]} {
foreach lib [dict get $lib_compile "libraries"] {
lappend cmd_args "-library" [string tolower $lib]
}
}
if {[dict exists $lib_compile "no_ip_compile"]} {
if {[string tolower [dict get $lib_compile "no_ip_compile"]] == "true"} {
lappend cmd_args "-no_ip_compile"
}
}
puts "INFO: Running command 'compile_simlib ${cmd_args}'"
catch {eval "compile_simlib ${cmd_args}"}
}
}
set sim_set [current_fileset -simset]
update_compile_order -fileset $sim_set
launch_simulation -scripts_only
set simscripts_dir "[file normalize \
"${project_dir}/${xpr_name}.sim/${sim_set}/behav/${target_simulator_lc}/"]"
puts "INFO: Simulation scripts generated in '${simscripts_dir}'"
}
################################################################################
## Run simulation
if {$start_step == $build_steps(sim) || $end_step == $build_steps(sim)} {
set end_step $build_steps(sim)
puts "INFO: Start simulation"
update_compile_order -fileset [current_fileset -simset]
launch_simulation
puts "Running simulation ..."
}
################################################################################
## IP-XACT package project
if {$start_step == $build_steps(package) || \
$end_step == $build_steps(package)} {
set end_step $build_steps(package)
puts "Package project in IP-XACT format"
puts "Running Syntax Check ..."
set cs [check_syntax -return_string -quiet]
if {[regexp {CRITICAL WARNING:} $cs] == 1} {
puts $cs
puts "ERROR: Syntax Check failed"
exit 2
} else {
puts "Syntax Check passed"
}
if {[dict exists $config_dict "PACKAGE_IP"]} {
# Parse dictionary section PACKAGE_IP
set package_ip_dict [dict get $config_dict "PACKAGE_IP"]
if {[dict exists $package_ip_dict "zip_name"]} {
set zip_name [dict get $package_ip_dict "zip_name"]
} else {
set zip_name "packaged-ip.zip"
}
if {![dict exists $package_ip_dict "ident"]} {
puts "ERROR: Key 'ident' of section 'PACKAGE_IP' not found in dictionary"
exit 2
}
set ident_dict [dict get $package_ip_dict "ident"]
dict for {key value} $ident_dict {
set "${key}" "${value}"
}
if {[dict exists $package_ip_dict "container_dir"]} {
set container_dir [dict get $package_ip_dict "container_dir"]
set container_dir "[file normalize \
"${flavor_dir}/${container_dir}"]"
} else {
set container_dir "${project_dir}"
}
# Set supported_device_families values
if {![llength $supported_device_families]} {
# Enable all
set supported_device_families [list \
zynquplus artix7 artix7l artixuplus qartix7 qkintex7 qkintex7l kintexu \
kintexuplus versal qvirtex7 virtexuplus virtexuplusHBM qzynq kintex7 \
kintex7l spartan7 virtex7 virtexu virtexuplus58g aartix7 akintex7 \
aspartan7 azynq zynq \
]
}
set supp_families ""
foreach supp_device $supported_device_families {