OpenCores
URL https://opencores.org/ocsvn/radiohdl/radiohdl/trunk

Subversion Repositories radiohdl

[/] [radiohdl/] [trunk/] [base/] [quartus_config] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
#! /usr/bin/env python
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/tools/oneclick/base/quartus_config.py -t unb1
27
"""
28
 
29
import common as cm
30
import hdl_libraries_wizard
31
import sys
32
from os            import listdir
33
import os.path
34
from argparse      import ArgumentParser
35
 
36
class QuartusConfig(hdl_config.HdlLibrariesWizard):
37
 
38
    def __init__(self, toolRootDir, toolFileName, libFileName='hdllib.cfg'):
39
        """Get Quartus tool info from toolRootDir and all HDL library info from libRootDir.
40
 
41
           This class uses the default keys and the keys from the libFileSections in the libFileName config file.
42
 
43
           Arguments:
44
           - toolRootDir     : Root directory from where the hdl_buildset_.cfg file is searched for.
45
           - toolFileName    : Default HDL tools configuration file name
46
           - libFileName     : Default HDL library configuration file name
47
 
48
           The libRootDir is defined in the hdl_buildset_.cfg file and is the root directory from where the hdllib.cfg
49
           files are searched for.
50
 
51
           The technologyNames parameter is defined in the hdl_buildset_.cfg file. All generic HDL libraries and these
52
           technology specific libraries are kept.
53
 
54
           Files:
55
           - hdl_buildset_.cfg : HDL tool configuration dictionary file. One central file per buildset.
56
 
57
           - hdllib.cfg : HDL library configuration dictionary file. One file for each HDL library.
58
 
59
           - .qpf : Quartus project file (QPF) for a certain HDL library based on the hdllib.cfg. The file is created by
60
                              create_quartus_project_file().
61
 
62
           - .qsf : Quartus settings file (QSF) for a certain HDL library based on the hdllib.cfg. The file is created by
63
                              create_quartus_settings_file(). There is one QSF per Quartus synthesis project.
64
        """
65
        print "QuartusConfig(toolRootDir=%s, toolFileName=%s, libFileName=%s)" % (toolRootDir, toolFileName, libFileName)
66
        libFileSections=['quartus_project_file']
67
        hdl_config.HdlLibrariesWizard.__init__(self, toolRootDir, toolFileName, libFileName, libFileSections)
68
 
69
    def create_quartus_ip_lib_file(self, lib_names=None):
70
        """Create the Quartus IP file _lib.qip for all HDL libraries. The .qip file contains the list of files that are given
71
           by the synth_files key and the quartus_*_file keys.
72
 
73
           Note:
74
           . Use post fix '_lib' in QIP file name *_lib.qip to avoid potential conflict with *.qip that may come with the IP.
75
           . 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
76
             the Quartus project will analyse all files even if there entity is not instantiated in the design. This is fine, it is unnecessary
77
             to parse the hierarchy of the synth_top_level_entity VHDL file to find and include only the source files that are actually used.
78
 
79
           Arguments:
80
           - lib_names      : one or more HDL libraries
81
        """
82
        if lib_names==None:
83
            lib_names=self.lib_names
84
 
85
        lib_dicts = self.libs.get_configfiles('hdl_lib_name', values=lib_names)
86
        for lib_dict in lib_dicts:
87
            # Open qip
88
            lib_name = lib_dict['hdl_lib_name']
89
            qip_name = lib_name + '_lib.qip'
90
            qip_path = self.get_lib_build_dirs('synth', lib_dicts=lib_dict)
91
            cm.mkdir(qip_path)
92
            qipPathName = cm.expand_file_path_name(qip_name, qip_path)
93
            with open(qipPathName, 'w') as fp:
94
                if lib_dict.get_value('synth_files'):
95
                    fp.write('# synth_files\n')
96
                    synth_files = lib_dict['synth_files'].split()
97
                    for fn in synth_files:
98
                        filePathName = cm.expand_file_path_name(fn, lib_dict.location)
99
 
100
                        file_ext = fn.split('.')[-1]
101
                        if file_ext=='vhd' or file_ext=='vhdl':
102
                            file_type = 'VHDL_FILE'
103
                        elif file_ext=='v':
104
                            file_type = 'VERILOG_FILE'
105
                        else:
106
                             print '\nERROR - Undefined file extension in synth_files:', fn
107
                             sys.exit()
108
 
109
                        fp.write('set_global_assignment -name %s %s -library %s\n' % (file_type, filePathName, lib_name + '_lib'))
110
 
111
                if lib_dict.get_value('quartus_vhdl_files'):
112
                    fp.write('\n')
113
                    fp.write('# quartus_vhdl_files\n')
114
                    quartus_vhdl_files = lib_dict['quartus_vhdl_files'].split()
115
                    for fn in quartus_vhdl_files:
116
                        filePathName = cm.expand_file_path_name(fn, lib_dict.location)
117
 
118
                        file_ext = fn.split('.')[-1]
119
                        if file_ext=='vhd' or file_ext=='vhdl':
120
                            file_type = 'VHDL_FILE'
121
                        elif file_ext=='v':
122
                            file_type = 'VERILOG_FILE'
123
                        else:
124
                             print '\nERROR - Undefined file extension in quartus_vhdl_files:', fn
125
                             sys.exit()
126
 
127
                        fp.write('set_global_assignment -name VHDL_FILE %s -library %s\n' % (filePathName, lib_name + '_lib'))
128
 
129
                if lib_dict.get_value('quartus_qip_files'):
130
                    fp.write('\n')
131
                    fp.write('# quartus_qip_files\n')
132
                    quartus_qip_files = lib_dict['quartus_qip_files'].split()
133
                    for fn in quartus_qip_files:
134
                        filePathName = cm.expand_file_path_name(fn, lib_dict.location)
135
                        fp.write('set_global_assignment -name QIP_FILE %s\n' % filePathName)
136
 
137
                if lib_dict.get_value('quartus_tcl_files'):
138
                    fp.write('\n')
139
                    fp.write('# quartus_tcl_files\n')
140
                    quartus_tcl_files = lib_dict['quartus_tcl_files'].split()
141
                    for fn in quartus_tcl_files:
142
                        filePathName = cm.expand_file_path_name(fn, lib_dict.location)
143
                        fp.write('set_global_assignment -name SOURCE_TCL_SCRIPT_FILE %s\n' % filePathName)
144
 
145
                if lib_dict.get_value('quartus_sdc_files'):
146
                    fp.write('\n')
147
                    fp.write('# quartus_sdc_files\n')
148
                    quartus_sdc_files = lib_dict['quartus_sdc_files'].split()
149
                    for fn in quartus_sdc_files:
150
                        filePathName = cm.expand_file_path_name(fn, lib_dict.location)
151
                        fp.write('set_global_assignment -name SDC_FILE %s\n' % filePathName)
152
        print "Created {} .qip files".format(len(lib_dicts))
153
 
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==None: lib_names=self.lib_names
171
        lib_dicts = self.libs.get_configfiles(key='hdl_lib_name', values=lib_names)
172
        syn_dicts = self.libs.get_configfiles(key='synth_top_level_entity', values=None, user_configfiles=lib_dicts)
173
        for syn_dict in syn_dicts:
174
            # Open qpf for each HDL library that has a synth_top_level_entity
175
            lib_name = syn_dict['hdl_lib_name']
176
            qpf_name = lib_name + '.qpf'
177
            qpf_path = self.get_lib_build_dirs('synth', lib_dicts=syn_dict)
178
            cm.mkdir(qpf_path)
179
            qpfPathName = cm.expand_file_path_name(qpf_name, qpf_path)
180
            with open(qpfPathName, 'w') as fp:
181
                fp.write('PROJECT_REVISION = "%s"\n' % lib_name)
182
        print "Created {} .qpf files".format(len(syn_dicts))
183
 
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==None: lib_names=self.lib_names
195
        lib_dicts = self.libs.get_configfiles(key='hdl_lib_name', values=lib_names)
196
        syn_dicts = self.libs.get_configfiles(key='synth_top_level_entity', values=None, user_configfiles=lib_dicts)
197
        for syn_dict in syn_dicts:
198
            # Open qsf for each HDL library that has a synth_top_level_entity
199
            lib_name = syn_dict['hdl_lib_name']
200
            top_level_entity = syn_dict['synth_top_level_entity']
201
            if top_level_entity=='':
202
                top_level_entity = lib_name
203
            qsf_path = self.get_lib_build_dirs('synth', lib_dicts=syn_dict)
204
            cm.mkdir(qsf_path)
205
 
206
            # One qsf per lib_name
207
            qsf_name = lib_name + '.qsf'
208
            qsfPathName = cm.expand_file_path_name(qsf_name, qsf_path)
209
            with open(qsfPathName, 'w') as fp:
210
                fp.write('# synth_top_level_entity\n')
211
                fp.write('set_global_assignment -name TOP_LEVEL_ENTITY %s\n' % top_level_entity)
212
 
213
                fp.write('\n')
214
                fp.write('# quartus_qsf_files\n')
215
                quartus_qsf_files = syn_dict['quartus_qsf_files'].split()
216
                for fn in quartus_qsf_files:
217
                    filePathName = cm.expand_file_path_name(fn, syn_dict.location)
218
                    fp.write('set_global_assignment -name SOURCE_TCL_SCRIPT_FILE %s\n' % filePathName)
219
 
220
                fp.write('\n')
221
                fp.write('# All used HDL library *_lib.qip files in order with top level last\n')
222
                use_lib_order = self.derive_lib_order('synth', lib_name)
223
                #use_lib_dicts = self.libs.get_configfiles('hdl_lib_name', values=use_lib_order)    # uses original libs.dicts order, but
224
                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
225
                for lib_dict in cm.listify(use_lib_dicts):
226
                    qip_path = self.get_lib_build_dirs('synth', lib_dicts=lib_dict)
227
                    qip_name = lib_dict['hdl_lib_name'] + '_lib.qip'
228
                    qipPathName = cm.expand_file_path_name(qip_name, qip_path)
229
                    fp.write('set_global_assignment -name QIP_FILE %s\n' % qipPathName)
230
        print "Created {} .qsf files".format(len(syn_dicts))
231
 
232
 
233
if __name__ == '__main__':
234
    # Parse command line arguments
235
    buildsetSelect = sorted([cfgfile[13:-4] for cfgfile in listdir(os.path.expandvars('$HDL_CONFIG_DIR'))
236
                                                if cfgfile.startswith("hdl_buildset_") and cfgfile.endswith(".cfg")])
237
    argparser = ArgumentParser(description='Quartus_config creates/updates all your quartus projectfiles.')
238
    argparser.add_argument('buildset',         help='choose buildset %s' % (buildsetSelect))
239
    argparser.add_argument('-v','--verbosity', required=False, type=int, default=0, help='verbosity >= 0 for more info')
240
    args = argparser.parse_args()
241
 
242
    # check arguments
243
    if args.buildset not in buildsetSelect:
244
        print 'buildset %s is not supported' % args.buildset
245
        print "Supported buildset are:", buildsetSelect
246
        sys.exit(1)
247
    args.buildsetFile = 'hdl_buildset_' + args.buildset + '.cfg'
248
 
249
    # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories
250
    qsyn = QuartusConfig(toolRootDir = os.path.expandvars('${HDL_CONFIG_DIR}'),
251
                         toolFileName= args.buildsetFile,
252
                         libFileName = 'hdllib.cfg')
253
 
254
    if args.verbosity>=2:
255
        print '#'
256
        print '# QuartusConfig:'
257
        print '#'
258
        print ''
259
        print 'HDL library paths that are found in $%s:' % qsyn.libRootDirs
260
        for p in sorted(qsyn.libs.configfiles.values()):
261
            print '    ', p.location
262
 
263
    if args.verbosity>=1:
264
        print ''
265
        print 'HDL libraries with a top level entity for synthesis that are found in $%s:' % qsyn.libRootDirs
266
        print '    %-40s' % 'HDL library', ': Top level entity'
267
        syn_dicts = qsyn.libs.get_configfiles(key='synth_top_level_entity')
268
        for d in syn_dicts:
269
            if d['synth_top_level_entity']=='':
270
                print '    %-40s' % d['hdl_lib_name'], ':', d['hdl_lib_name']
271
            else:
272
                print '    %-40s' % d['hdl_lib_name'], ':', d['synth_top_level_entity']
273
 
274
    print ''
275
    print 'Create Quartus IP library qip files for all HDL libraries in $%s.' % qsyn.libRootDirs
276
    qsyn.create_quartus_ip_lib_file()
277
 
278
    print ''
279
    print 'Copy Quartus directories and files from HDL library source tree to build_dir for all HDL libraries that are found in $%s.' % qsyn.libRootDirs
280
    qsyn.copy_files('synth')
281
 
282
    print ''
283
    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.' % (qsyn.technologyNames, qsyn.libRootDirs)
284
    qsyn.create_quartus_project_file()
285
 
286
    print ''
287
    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.' % (qsyn.technologyNames, qsyn.libRootDirs)
288
    qsyn.create_quartus_settings_file()

powered by: WebSVN 2.1.0

© copyright 1999-2019 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.