1 |
4 |
danv |
#! /usr/bin/env python3
|
2 |
|
|
###############################################################################
|
3 |
|
|
#
|
4 |
|
|
# Copyright (C) 2014
|
5 |
|
|
# ASTRON (Netherlands Institute for Radio Astronomy)
|
6 |
|
|
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
7 |
|
|
#
|
8 |
|
|
# This program is free software: you can redistribute it and/or modify
|
9 |
|
|
# it under the terms of the GNU General Public License as published by
|
10 |
|
|
# the Free Software Foundation, either version 3 of the License, or
|
11 |
|
|
# (at your option) any later version.
|
12 |
|
|
#
|
13 |
|
|
# This program is distributed in the hope that it will be useful,
|
14 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
# GNU General Public License for more details.
|
17 |
|
|
#
|
18 |
|
|
# You should have received a copy of the GNU General Public License
|
19 |
|
|
# along with this program. If not, see .
|
20 |
|
|
#
|
21 |
|
|
###############################################################################
|
22 |
|
|
|
23 |
|
|
"""HDL configuration for building Quartus synthesis targets.
|
24 |
|
|
|
25 |
|
|
Usage:
|
26 |
|
|
> python ${RADIOHDL_GEAR}/core/quartus_config -t unb1
|
27 |
|
|
"""
|
28 |
|
|
|
29 |
|
|
import sys
|
30 |
|
|
from os import listdir
|
31 |
|
|
import os.path
|
32 |
|
|
from argparse import ArgumentParser
|
33 |
|
|
import common_radiohdl as cm
|
34 |
|
|
import hdl_libraries_wizard
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
class QuartusConfig(hdl_libraries_wizard.HdlLibrariesWizard):
|
38 |
|
|
|
39 |
|
|
def __init__(self, toolRootDir, toolFileName, libFileName='hdllib.cfg'):
|
40 |
|
|
"""Get Quartus tool info from toolRootDir and all HDL library info from libRootDir.
|
41 |
|
|
|
42 |
|
|
This class uses the default keys and the keys from the libFileSections in the libFileName config file.
|
43 |
|
|
|
44 |
|
|
Arguments:
|
45 |
|
|
- toolRootDir : Root directory from where the hdl_buildset_.cfg file is searched for.
|
46 |
|
|
- toolFileName : Default HDL tools configuration file name
|
47 |
|
|
- libFileName : Default HDL library configuration file name
|
48 |
|
|
|
49 |
|
|
The libRootDir is defined in the hdl_buildset_.cfg file and is the root directory from where the hdllib.cfg
|
50 |
|
|
files are searched for.
|
51 |
|
|
|
52 |
|
|
The technologyNames parameter is defined in the hdl_buildset_.cfg file. All generic HDL libraries and these
|
53 |
|
|
technology specific libraries are kept.
|
54 |
|
|
|
55 |
|
|
Files:
|
56 |
|
|
- hdl_buildset_.cfg : HDL tool configuration dictionary file. One central file per buildset.
|
57 |
|
|
|
58 |
|
|
- hdllib.cfg : HDL library configuration dictionary file. One file for each HDL library.
|
59 |
|
|
|
60 |
|
|
- .qpf : Quartus project file (QPF) for a certain HDL library based on the hdllib.cfg. The file is created by
|
61 |
|
|
create_quartus_project_file().
|
62 |
|
|
|
63 |
|
|
- .qsf : Quartus settings file (QSF) for a certain HDL library based on the hdllib.cfg. The file is created by
|
64 |
|
|
create_quartus_settings_file(). There is one QSF per Quartus synthesis project.
|
65 |
|
|
"""
|
66 |
|
|
print("QuartusConfig(toolRootDir=%s, toolFileName=%s, libFileName=%s)" % (toolRootDir, toolFileName, libFileName))
|
67 |
|
|
libFileSections = ['quartus_project_file']
|
68 |
|
|
hdl_libraries_wizard.HdlLibrariesWizard.__init__(self, toolRootDir, toolFileName, libFileName, libFileSections)
|
69 |
|
|
|
70 |
|
|
def create_quartus_ip_lib_file(self, lib_names=None):
|
71 |
|
|
"""Create the Quartus IP file _lib.qip for all HDL libraries. The .qip file contains the list of files that are given
|
72 |
|
|
by the synth_files key and the quartus_*_file keys.
|
73 |
|
|
|
74 |
|
|
Note:
|
75 |
|
|
. Use post fix '_lib' in QIP file name *_lib.qip to avoid potential conflict with *.qip that may come with the IP.
|
76 |
|
|
. The HDL library *_lib.qip files contain all files that are listed by the synth_files key. Hence when these qip files are included then
|
77 |
|
|
the Quartus project will analyse all files even if there entity is not instantiated in the design. This is fine, it is unnecessary
|
78 |
|
|
to parse the hierarchy of the synth_top_level_entity VHDL file to find and include only the source files that are actually used.
|
79 |
|
|
|
80 |
|
|
Arguments:
|
81 |
|
|
- lib_names : one or more HDL libraries
|
82 |
|
|
"""
|
83 |
|
|
if lib_names is None:
|
84 |
|
|
lib_names = self.lib_names
|
85 |
|
|
|
86 |
|
|
lib_dicts = self.libs.get_configfiles('hdl_lib_name', values=lib_names)
|
87 |
|
|
for lib_dict in lib_dicts:
|
88 |
|
|
# Open qip
|
89 |
|
|
lib_name = lib_dict['hdl_lib_name']
|
90 |
|
|
qip_name = lib_name + '_lib.qip'
|
91 |
|
|
qip_path = self.get_lib_build_dirs('synth', lib_dicts=lib_dict)
|
92 |
|
|
cm.mkdir(qip_path)
|
93 |
|
|
qipPathName = cm.expand_file_path_name(qip_name, qip_path)
|
94 |
|
|
with open(qipPathName, 'w') as fp:
|
95 |
|
|
if lib_dict.get_value('synth_files'):
|
96 |
|
|
fp.write('# synth_files\n')
|
97 |
|
|
synth_files = lib_dict['synth_files'].split()
|
98 |
|
|
for fn in synth_files:
|
99 |
|
|
filePathName = cm.expand_file_path_name(fn, lib_dict.location)
|
100 |
|
|
|
101 |
|
|
file_ext = fn.split('.')[-1]
|
102 |
|
|
if file_ext == 'vhd' or file_ext == 'vhdl':
|
103 |
|
|
file_type = 'VHDL_FILE'
|
104 |
|
|
elif file_ext == 'v':
|
105 |
|
|
file_type = 'VERILOG_FILE'
|
106 |
|
|
else:
|
107 |
|
|
print('\nERROR - Undefined file extension in synth_files:', fn)
|
108 |
|
|
sys.exit()
|
109 |
|
|
|
110 |
|
|
fp.write('set_global_assignment -name %s %s -library %s\n' % (file_type, filePathName, lib_name + '_lib'))
|
111 |
|
|
|
112 |
|
|
if lib_dict.get_value('quartus_vhdl_files'):
|
113 |
|
|
fp.write('\n')
|
114 |
|
|
fp.write('# quartus_vhdl_files\n')
|
115 |
|
|
quartus_vhdl_files = lib_dict['quartus_vhdl_files'].split()
|
116 |
|
|
for fn in quartus_vhdl_files:
|
117 |
|
|
filePathName = cm.expand_file_path_name(fn, lib_dict.location)
|
118 |
|
|
|
119 |
|
|
file_ext = fn.split('.')[-1]
|
120 |
|
|
if file_ext == 'vhd' or file_ext == 'vhdl':
|
121 |
|
|
file_type = 'VHDL_FILE'
|
122 |
|
|
elif file_ext == 'v':
|
123 |
|
|
file_type = 'VERILOG_FILE'
|
124 |
|
|
else:
|
125 |
|
|
print('\nERROR - Undefined file extension in quartus_vhdl_files:', fn)
|
126 |
|
|
sys.exit()
|
127 |
|
|
|
128 |
|
|
fp.write('set_global_assignment -name VHDL_FILE %s -library %s\n' % (filePathName, lib_name + '_lib'))
|
129 |
|
|
|
130 |
|
|
if lib_dict.get_value('quartus_qip_files'):
|
131 |
|
|
fp.write('\n')
|
132 |
|
|
fp.write('# quartus_qip_files\n')
|
133 |
|
|
quartus_qip_files = lib_dict['quartus_qip_files'].split()
|
134 |
|
|
for fn in quartus_qip_files:
|
135 |
|
|
filePathName = cm.expand_file_path_name(fn, lib_dict.location)
|
136 |
|
|
fp.write('set_global_assignment -name QIP_FILE %s\n' % filePathName)
|
137 |
|
|
|
138 |
|
|
if lib_dict.get_value('quartus_tcl_files'):
|
139 |
|
|
fp.write('\n')
|
140 |
|
|
fp.write('# quartus_tcl_files\n')
|
141 |
|
|
quartus_tcl_files = lib_dict['quartus_tcl_files'].split()
|
142 |
|
|
for fn in quartus_tcl_files:
|
143 |
|
|
filePathName = cm.expand_file_path_name(fn, lib_dict.location)
|
144 |
|
|
fp.write('set_global_assignment -name SOURCE_TCL_SCRIPT_FILE %s\n' % filePathName)
|
145 |
|
|
|
146 |
|
|
if lib_dict.get_value('quartus_sdc_files'):
|
147 |
|
|
fp.write('\n')
|
148 |
|
|
fp.write('# quartus_sdc_files\n')
|
149 |
|
|
quartus_sdc_files = lib_dict['quartus_sdc_files'].split()
|
150 |
|
|
for fn in quartus_sdc_files:
|
151 |
|
|
filePathName = cm.expand_file_path_name(fn, lib_dict.location)
|
152 |
|
|
fp.write('set_global_assignment -name SDC_FILE %s\n' % filePathName)
|
153 |
|
|
print("Created {} .qip files".format(len(lib_dicts)))
|
154 |
|
|
|
155 |
|
|
def create_quartus_project_file(self, lib_names=None):
|
156 |
|
|
"""Create the Quartus project file (QPF) for all HDL libraries that have a toplevel entity key synth_top_level_entity.
|
157 |
|
|
|
158 |
|
|
Note:
|
159 |
|
|
. Default if the synth_top_level_entity key is defined but left empty then the top level entity has the same name as the lib_name in hdl_lib_name.
|
160 |
|
|
Otherwise synth_top_level_entity can specify another top level entity name in the library. Each HDL library can only have one Quartus project
|
161 |
|
|
file
|
162 |
|
|
. The project revision has the same name as the lib_name and will result in a .sof FPGA image file.
|
163 |
|
|
. For each additional revision a subdirectory can be used.
|
164 |
|
|
This subdirectory can be named 'revisions/' and lists a number of revisions as subdirectories. Each revision will have a separate hdllib.cfg file and a
|
165 |
|
|
.vhd file with the toplevel entity. The toplevel .vhd file specifies the for the revision in the generics.
|
166 |
|
|
|
167 |
|
|
Arguments:
|
168 |
|
|
- lib_names : one or more HDL libraries
|
169 |
|
|
"""
|
170 |
|
|
if lib_names is None:
|
171 |
|
|
lib_names = self.lib_names
|
172 |
|
|
lib_dicts = self.libs.get_configfiles(key='hdl_lib_name', values=lib_names)
|
173 |
|
|
syn_dicts = self.libs.get_configfiles(key='synth_top_level_entity', values=None, user_configfiles=lib_dicts)
|
174 |
|
|
for syn_dict in syn_dicts:
|
175 |
|
|
# Open qpf for each HDL library that has a synth_top_level_entity
|
176 |
|
|
lib_name = syn_dict['hdl_lib_name']
|
177 |
|
|
qpf_name = lib_name + '.qpf'
|
178 |
|
|
qpf_path = self.get_lib_build_dirs('synth', lib_dicts=syn_dict)
|
179 |
|
|
cm.mkdir(qpf_path)
|
180 |
|
|
qpfPathName = cm.expand_file_path_name(qpf_name, qpf_path)
|
181 |
|
|
with open(qpfPathName, 'w') as fp:
|
182 |
|
|
fp.write('PROJECT_REVISION = "%s"\n' % lib_name)
|
183 |
|
|
print("Created {} .qpf files".format(len(syn_dicts)))
|
184 |
|
|
|
185 |
|
|
def create_quartus_settings_file(self, lib_names=None):
|
186 |
|
|
"""Create the Quartus settings file (QSF) for all HDL libraries that have a toplevel entity key synth_top_level_entity.
|
187 |
|
|
|
188 |
|
|
Note:
|
189 |
|
|
. No support for revisions, so only one qsf per qpf
|
190 |
|
|
|
191 |
|
|
Arguments:
|
192 |
|
|
- lib_names : one or more HDL libraries
|
193 |
|
|
"""
|
194 |
|
|
if lib_names is None:
|
195 |
|
|
lib_names = self.lib_names
|
196 |
|
|
lib_dicts = self.libs.get_configfiles(key='hdl_lib_name', values=lib_names)
|
197 |
|
|
syn_dicts = self.libs.get_configfiles(key='synth_top_level_entity', values=None, user_configfiles=lib_dicts)
|
198 |
|
|
for syn_dict in syn_dicts:
|
199 |
|
|
# Open qsf for each HDL library that has a synth_top_level_entity
|
200 |
|
|
lib_name = syn_dict['hdl_lib_name']
|
201 |
|
|
top_level_entity = syn_dict['synth_top_level_entity']
|
202 |
|
|
if top_level_entity == '':
|
203 |
|
|
top_level_entity = lib_name
|
204 |
|
|
qsf_path = self.get_lib_build_dirs('synth', lib_dicts=syn_dict)
|
205 |
|
|
cm.mkdir(qsf_path)
|
206 |
|
|
|
207 |
|
|
# One qsf per lib_name
|
208 |
|
|
qsf_name = lib_name + '.qsf'
|
209 |
|
|
qsfPathName = cm.expand_file_path_name(qsf_name, qsf_path)
|
210 |
|
|
with open(qsfPathName, 'w') as fp:
|
211 |
|
|
fp.write('# synth_top_level_entity\n')
|
212 |
|
|
fp.write('set_global_assignment -name TOP_LEVEL_ENTITY %s\n' % top_level_entity)
|
213 |
|
|
|
214 |
|
|
fp.write('\n')
|
215 |
|
|
fp.write('# quartus_qsf_files\n')
|
216 |
|
|
quartus_qsf_files = syn_dict['quartus_qsf_files'].split()
|
217 |
|
|
for fn in quartus_qsf_files:
|
218 |
|
|
filePathName = cm.expand_file_path_name(fn, syn_dict.location)
|
219 |
|
|
fp.write('set_global_assignment -name SOURCE_TCL_SCRIPT_FILE %s\n' % filePathName)
|
220 |
|
|
|
221 |
|
|
fp.write('\n')
|
222 |
|
|
fp.write('# All used HDL library *_lib.qip files in order with top level last\n')
|
223 |
|
|
use_lib_order = self.derive_lib_order('synth', lib_name)
|
224 |
|
|
# use_lib_dicts = self.libs.get_configfiles('hdl_lib_name', values=use_lib_order) # uses original libs.dicts order, but
|
225 |
|
|
use_lib_dicts = self.get_lib_dicts_from_lib_names(lib_names=use_lib_order) # must preserve use_lib_order order to ensure that top level design qip with sdc file is include last in qsf
|
226 |
|
|
for lib_dict in cm.listify(use_lib_dicts):
|
227 |
|
|
qip_path = self.get_lib_build_dirs('synth', lib_dicts=lib_dict)
|
228 |
|
|
qip_name = lib_dict['hdl_lib_name'] + '_lib.qip'
|
229 |
|
|
qipPathName = cm.expand_file_path_name(qip_name, qip_path)
|
230 |
|
|
fp.write('set_global_assignment -name QIP_FILE %s\n' % qipPathName)
|
231 |
|
|
|
232 |
|
|
if syn_dict.get_value('quartus_ip_files'):
|
233 |
|
|
# print(syn_dict['quartus_ip_files'])
|
234 |
|
|
fp.write('\n')
|
235 |
|
|
fp.write('# All used HDL library *.ip files in order with top level last\n')
|
236 |
|
|
quartus_ip_files = syn_dict['quartus_ip_files'].split()
|
237 |
|
|
for fn in quartus_ip_files:
|
238 |
|
|
filePathName = cm.expand_file_path_name(fn)
|
239 |
|
|
fp.write('set_global_assignment -name IP_FILE %s\n' % filePathName)
|
240 |
|
|
|
241 |
|
|
fp.write('\n')
|
242 |
|
|
print("Created {} .qsf files".format(len(syn_dicts)))
|
243 |
|
|
|
244 |
|
|
|
245 |
|
|
if __name__ == '__main__':
|
246 |
|
|
# Parse command line arguments
|
247 |
|
|
buildsetSelect = sorted([cfgfile[13:-4] for cfgfile in listdir(os.getenv('RADIOHDL_CONFIG'))
|
248 |
|
|
if cfgfile.startswith("hdl_buildset_") and cfgfile.endswith(".cfg")])
|
249 |
|
|
argparser = ArgumentParser(description='Quartus_config creates/updates all your quartus projectfiles.')
|
250 |
|
|
argparser.add_argument('buildset', help='choose buildset %s' % (buildsetSelect))
|
251 |
|
|
argparser.add_argument('-v', '--verbosity', required=False, type=int, default=0, help='verbosity >= 0 for more info')
|
252 |
|
|
args = argparser.parse_args()
|
253 |
|
|
|
254 |
|
|
# check arguments
|
255 |
|
|
if args.buildset not in buildsetSelect:
|
256 |
|
|
print('buildset %s is not supported' % args.buildset)
|
257 |
|
|
print("Supported buildset are:", buildsetSelect)
|
258 |
|
|
sys.exit(1)
|
259 |
|
|
args.buildsetFile = 'hdl_buildset_' + args.buildset + '.cfg'
|
260 |
|
|
|
261 |
|
|
# Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories
|
262 |
|
|
qsyn = QuartusConfig(toolRootDir=os.getenv('RADIOHDL_CONFIG'),
|
263 |
|
|
toolFileName=args.buildsetFile,
|
264 |
|
|
libFileName='hdllib.cfg')
|
265 |
|
|
|
266 |
|
|
if args.verbosity >= 2:
|
267 |
|
|
print('#')
|
268 |
|
|
print('# QuartusConfig:')
|
269 |
|
|
print('#')
|
270 |
|
|
print('')
|
271 |
|
|
print('HDL library paths that are found in $%s:' % qsyn.libRootDirs)
|
272 |
|
|
for p in sorted(qsyn.libs.configfiles.values()):
|
273 |
|
|
print(' ', p.location)
|
274 |
|
|
|
275 |
|
|
if args.verbosity >= 1:
|
276 |
|
|
print('')
|
277 |
|
|
print('HDL libraries with a top level entity for synthesis that are found in $%s:' % qsyn.libRootDirs)
|
278 |
|
|
print(' %-40s' % 'HDL library', ': Top level entity')
|
279 |
|
|
syn_dicts = qsyn.libs.get_configfiles(key='synth_top_level_entity')
|
280 |
|
|
for d in syn_dicts:
|
281 |
|
|
if d['synth_top_level_entity'] == '':
|
282 |
|
|
print(' %-40s' % d['hdl_lib_name'], ':', d['hdl_lib_name'])
|
283 |
|
|
else:
|
284 |
|
|
print(' %-40s' % d['hdl_lib_name'], ':', d['synth_top_level_entity'])
|
285 |
|
|
|
286 |
|
|
print('')
|
287 |
|
|
print('Create Quartus IP library qip files for all HDL libraries in $%s.'
|
288 |
|
|
% qsyn.libRootDirs)
|
289 |
|
|
qsyn.create_quartus_ip_lib_file()
|
290 |
|
|
|
291 |
|
|
print('')
|
292 |
|
|
print('Copy Quartus directories and files from HDL library source tree to build_dir for all HDL libraries that are found in $%s.'
|
293 |
|
|
% qsyn.libRootDirs)
|
294 |
|
|
qsyn.copy_files('synth')
|
295 |
|
|
|
296 |
|
|
print('')
|
297 |
|
|
print('Create Quartus project files (QPF) for technology %s and all HDL libraries with a top level entity for synthesis that are found in $%s.'
|
298 |
|
|
% (qsyn.technologyNames, qsyn.libRootDirs))
|
299 |
|
|
qsyn.create_quartus_project_file()
|
300 |
|
|
|
301 |
|
|
print('')
|
302 |
|
|
print('Create Quartus settings files (QSF) for technology %s and all HDL libraries with a top level entity for synthesis that are found in $%s.'
|
303 |
|
|
% (qsyn.technologyNames, qsyn.libRootDirs))
|
304 |
|
|
qsyn.create_quartus_settings_file()
|