-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvivado_post.mak
185 lines (164 loc) · 6.53 KB
/
vivado_post.mak
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
################################################################################
# vivado_post.mak
# Support for creating post synthesis/implementation netlists with Vivado.
# See https://github.com/amb5l/make-fpga
################################################################################
# User makefile variables:
# VIVADO_POST_UNIT list of design units
# VIVADO_POST_SRC.<unit> list of sources for <unit>
# VIVADO_POST_GEN.<unit> list of generics for <unit>
# Created variables:
# VIVADO_POST_SYN_FUNC.<unit>.vhd path to post synthesis functional VHDL netlist
################################################################################
include $(dir $(lastword $(MAKEFILE_LIST)))/common.mak
VIVADO_POST_DIR?=vivado_post
VIVADO_POST_PROJ?=post
VIVADO_POST_LANGUAGE?=VHDL
VIVADO_POST_VHDL_LRM?=2008
VIVADO_POST_WORK?=work
# checks
$(call check_defined,XILINX_VIVADO)
$(foreach u,$(VIVADO_POST_UNIT),$(if $(VIVADO_POST_SRC.$u),,$(error $(VIVADO_POST_SRC.$u) not defined)))
$(if $(filter 2000 2008,$(VIVADO_POST_VHDL_LRM)),,$(error VIVADO_VHDL_LRM value is unsupported: $(VIVADO_POST_VHDL_LRM)))
$(foreach u,$(VIVADO_POST_UNIT),$(foreach s,$(VIVADO_POST_SRC.$u),$(if $(filter 2000 2008,$(call get_src_lrm,$s,$(VIVADO_POST_VHDL_LRM))),,$(error source file LRM is unsupported: $s))))
################################################################################
# TCL sequences
vivado_post_scripts+=vivado_post_xpr_tcl
define vivado_post_xpr_tcl
set top [lindex $$argv 0]
set src_spec [lrange $$argv 1 end]
create_project -force "$(VIVADO_POST_PROJ)"
puts "setting target language..."
set_property target_language "$(VIVADO_POST_LANGUAGE)" [current_project]
puts "adding design sources, assigning libraries, and setting language defaults/overrides..."
foreach src_spec [lrange $$argv 1 end] {
set src_file_lib [split $$src_spec ";"]
set src_file [lindex [split $$src_file_lib "="] 0]
set src_lib [lindex [split $$src_file_lib "="] 1]
if {$$src_lib == ""} {
set src_lib "$(VIVADO_POST_WORK)"
}
set src_lang [lindex [split $$src_spec ";"] 1]
if {$$src_lang == ""} {
if {[string range [file extension $$src_file] 0 2] == ".vh"} {
if {"$(VIVADO_POST_VHDL_LRM)" == "2008"} {
set src_lang "VHDL-2008"
} else {
set src_lang "VHDL-2000"
}
} else {
set src_lang "Verilog"
}
}
set src_lang [string map {"-" " "} $$src_lang]
if {$$src_lang == "VHDL 2000"} {
set src_lang "VHDL"
}
add_files -norecurse -fileset [get_filesets sources_1] $$src_file
set_property library $$src_lib [get_files -of_objects [get_filesets sources_1] $$src_file]
set_property file_type $$src_lang [get_files -of_objects [get_filesets sources_1] $$src_file]
}
puts "setting top design unit..."
set_property top $$top [get_filesets sources_1]
puts "enabling synthesis assertions..."
set_property STEPS.SYNTH_DESIGN.ARGS.ASSERT true [get_runs synth_1]
exit 0
endef
vivado_post_scripts+=vivado_post_gen_tcl
define vivado_post_gen_tcl
if {$$argv != ""} {
open_project $(VIVADO_POST_PROJ)
puts "setting top design unit generics..."
set_property generic $$argv [get_filesets sources_1]
} else {
puts "no top design unit generics specified"
}
endef
vivado_post_scripts+=vivado_post_syn_func_vhd_tcl
define vivado_post_syn_func_vhd_tcl
open_project $(VIVADO_POST_PROJ)
set outfile [lindex $$argv 0]
set top [lindex $$argv 1]
foreach src_spec [lrange $$argv 2 end] {
set src_file_lib [split $$src_spec ";"]
set src_file [lindex [split $$src_file_lib "="] 0]
set src_lib [lindex [split $$src_file_lib "="] 1]
if {$$src_lib == ""} {
set src_lib "$(VIVADO_POST_WORK)"
}
set src_lang [lindex [split $$src_spec ";"] 1]
if {$$src_lang == ""} {
if {[string range [file extension $$src_file] 0 2] == ".vh"]} {
if {"$(VIVADO_POST_VHDL_LRM)" == "2008"} {
set src_lang "VHDL-2008"
} else {
set src_lang "VHDL-2000"
}
} else {
set src_lang "Verilog"
}
}
set src_lang [string map {"-" " "} $$src_lang]
if {$$src_lang == "VHDL 2000"} {
set src_lang "VHDL"
}
set vhdl2008 ""
if {$$src_lang == "VHDL 2008"} {
set vhdl2008 "-vhdl2008"
}
read_vhdl -library $$src_lib $$vhdl2008 $$src_file
}
synth_design -top $$top
puts "writing netlist..."
write_vhdl -force $$outfile
endef
################################################################################
# create directory and write script files
$(shell $(MKDIR) -p $(VIVADO_POST_DIR))
$(foreach s,$(vivado_post_scripts),\
$(file >$(VIVADO_POST_DIR)/$(subst _tcl,.tcl,$s),set code [catch { $($s) } result]; puts $$result; exit $$code) \
)
################################################################################
# rules and recipes
define RR_VIVADO_POST
$$(VIVADO_POST_DIR)/$1:
$(MKDIR) -p $$@
$$(VIVADO_POST_DIR)/$1/$$(VIVADO_POST_PROJ).xpr: $$(if $$(filter dev,$$(MAKECMDGOALS)),,$$(MAKEFILE_LIST)) | $$(call get_src_file,$$(VIVADO_POST_SRC.$1)) $$(VIVADO_POST_DIR)/$1
$(call banner,Vivado Post Synthesis/Implementation Netlist Support: create project)
@rm -f $$@
@cd $$(dir $$@) && vivado \
-nolog -nojou -notrace -mode batch \
-source $$(abspath $$(VIVADO_POST_DIR)/vivado_post_xpr.tcl) \
-tclargs \
$1 \
$$(call get_src_file,$$(VIVADO_POST_SRC.$1))
@cd $$(dir $$@) && vivado \
-nolog -nojou -notrace -mode batch \
-source $$(abspath $$(VIVADO_POST_DIR)/vivado_post_gen.tcl) \
-tclargs \
$(VIVADO_POST_GEN.$1)
VIVADO_POST_SYN_FUNC.$1.vhd=$$(abspath $$(VIVADO_POST_DIR)/$1/$1_post_syn_func.vhd)
$$(VIVADO_POST_SYN_FUNC.$1.vhd): $$(call get_src_file,$$(VIVADO_POST_SRC.$1)) $$(VIVADO_POST_DIR)/$1/$$(VIVADO_POST_PROJ).xpr
$(call banner,Vivado Post Synthesis/Implementation Netlist Support: create netlist)
@cd $$(dir $$@) && vivado \
-nolog -nojou -notrace -mode batch \
-source $$(abspath $$(VIVADO_POST_DIR)/vivado_post_syn_func_vhd.tcl) \
-tclargs \
$$(notdir $$@) \
$1 \
$^ \
|| echo error synthesising unit: $1 > $$@
psf:: $$(VIVADO_POST_SYN_FUNC.$1.vhd)
endef
$(foreach u,$(VIVADO_POST_UNIT),$(eval $(call RR_VIVADO_POST,$u)))
################################################################################
help::
$(call print_col,col_fi_cyn, vivado_post.mak)
$(call print_col,col_fi_wht, Support for creating post-synthesis function simulation netlists with Vivado.)
$(call print_col,col_fg_wht, )
$(call print_col,col_fg_wht, Goals:)
$(call print_col,col_fi_grn, psf$(col_fg_wht) - build netlists for all specified units)
$(call print_col,col_fg_wht, )
################################################################################
clean::
@rm -rf $(VIVADO_POST_DIR)