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

Subversion Repositories radiohdl

[/] [radiohdl/] [trunk/] [base/] [generate_ip_libs] - 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-2018
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
# $Id: generate_ip_libs 18918 2018-09-26 14:30:49Z overeem $
22
#
23
###############################################################################
24
 
25
import sys
26
from os.path        import expandvars, dirname, basename
27
from subprocess     import call, STDOUT
28
from common         import listify, mkdir
29
from argparse       import ArgumentParser
30
from hdl_configfile import HdlBuildset, HdlTool
31
from hdl_configtree import HdlLibTree
32
 
33
def run_qmegawiz(buildset, outputdir, hdllib, vhdl_files, options):
34
    """
35
    Run qmegawiz for the configuration in the given hdllib.
36
    The script takes care that the exit code of qmegawiz is returned to the caller.
37
    """
38
    extra_options = hdllib.get_value("qmegawiz_extra_options", False)
39
    if not extra_options:
40
        extra_options = ""
41
 
42
    error_code = 0
43
    for vhdl_file in vhdl_files:
44
        script =  '. ${RADIOHDL}/tools/quartus/set_quartus %s\n' % buildset
45
        script += 'cd %s\n' % outputdir
46
        script += 'cp %s/%s .\n' % (hdllib.location, vhdl_file)
47
        script += 'set -o pipefail\n'
48
        # echo line without 'Info:' to make sure grep it's exit code is 0
49
        script += '(echo " " ; qmegawiz %s %s %s 2>&1) | grep -iv Info:\n' \
50
                   % (options, extra_options, vhdl_file)
51
        script += 'exit_code=$?\n'
52
        script += 'rm %s\n' % vhdl_file
53
        script += 'exit $exit_code\n'
54
        #execute script
55
        print "compiling {} ... ".format(vhdl_file)
56
        return_code = call(script, stdout=None, stderr=STDOUT, shell=True)
57
        # qmegawiz is very sloppy with it's exitcodes. We assume 0 is OK although this not always the case. :-(
58
        if return_code == 0:
59
            print "*** Generation (probably) OK\n"
60
        else:
61
            print "*** Error during generation, exitcode={}\n".format(return_code)
62
            error_code |= return_code
63
    return error_code
64
 
65
 
66
def run_qsys(buildset, outputdir, hdllib, vhdl_files, options):
67
    """
68
    Run qsys for the configuration in the given hdllib.
69
    The script takes care that the exit code of qsys is returned to the caller.
70
    """
71
    extra_options = hdllib.get_value("qsys-generate_extra_options", False)
72
    if not extra_options:
73
        extra_options = ""
74
 
75
    error_code = 0
76
    for vhdl_file in vhdl_files:
77
        script =  '. ${RADIOHDL}/tools/quartus/set_quartus %s\n' % buildset
78
        script += 'cd %s\n' % hdllib.location
79
        script += 'set -o pipefail\n'
80
        # echo line without 'Info:' to make sure grep it's exit code is 0
81
        script += '(echo " " ; qsys-generate %s %s --output-directory=%s %s 2>&1) | grep -iv Info:\n' \
82
                   % (options, extra_options, outputdir, vhdl_file)
83
        script += 'exit_code=$?\n'
84
        script += 'exit $exit_code\n'
85
        # execute script
86
        print "compiling {} ... ".format(vhdl_file)
87
        return_code = call(script, stdout=None, stderr=STDOUT, shell=True)
88
        if return_code == 0:
89
            print "*** Generation OK\n"
90
        else:
91
            print "*** Error during generation, exitcode={}\n".format(return_code)
92
            error_code |= return_code
93
    return error_code
94
 
95
 
96
def run_quartus_sh(buildset, outputdir, hdllib, tcl_files, options):
97
    """
98
    Run quartus_sh for the configuration in the given hdllib.
99
    The script takes care that the exit code of quartus_sh is returned to the caller.
100
    """
101
    extra_options = hdllib.get_value("quartus_sh_extra_options", False)
102
    if not extra_options:
103
        extra_options = ""
104
 
105
    error_code = 0
106
    for tcl_file in tcl_files:
107
        script =  '. ${RADIOHDL}/tools/quartus/set_quartus %s\n' % buildset
108
        script += 'cd %s/%s\n' % (outputdir, hdllib.quartus_sh_ip_srcdir)
109
        script += 'set -o pipefail\n'
110
        # echo line without 'Info:' to make sure grep it's exit code is 0
111
        script += '(echo " " ; quartus_sh %s %s -t %s 2>&1) | grep -iv Info:\n' \
112
                   % (options, extra_options, tcl_file)
113
        script += 'exit_code=$?\n'
114
        script += 'exit $exit_code\n'
115
        # execute script
116
        print "compiling {} ... ".format(tcl_file)
117
        return_code = call(script, stdout=None, stderr=STDOUT, shell=True)
118
        if return_code == 0:
119
            print "*** Generation OK\n"
120
        else:
121
            print "*** Error during generation, exitcode={}\n".format(return_code)
122
            error_code |= return_code
123
    return error_code
124
 
125
 
126
if __name__ == '__main__':
127
    # setup parser and parse the arguments.
128
    argparser = ArgumentParser(description='Generate the IP libraries for all technologies of the given buildset')
129
    argparser.add_argument('buildset', help="Filename like 'hdl_buildset_.cfg'")
130
    args = argparser.parse_args()
131
 
132
    # resolve full name of buildsetfile and force it to be explicit absolute or relative.
133
    full_buildsetfile_name = expandvars("${HDL_CONFIG_DIR}/hdl_buildset_%s.cfg" % (args.buildset))
134
    if full_buildsetfile_name[0] != '/':
135
        full_buildsetfile_name = "./" + full_buildsetfile_name
136
    # read the file
137
    buildset_info = HdlBuildset(full_buildsetfile_name)
138
    buildset_info.resolve_key_references()
139
 
140
    # read in all hdllib configfiles
141
    root_dirs = [ expandvars(rootdir) for rootdir in buildset_info.lib_root_dirs.replace("\t"," ").split(" ")
142
                                                     if rootdir != '' ]
143
    lib_tree = HdlLibTree(rootdirs=root_dirs, filename="hdllib.cfg", sections="generate_ip_libs")
144
 
145
    # read in the tool environment settings
146
    tool_config_file = expandvars("${HDL_CONFIG_DIR}/hdl_tool_{}.cfg".format(buildset_info.synth_tool_name))
147
    tool_info = HdlTool(tool_config_file)
148
    tool_info.resolve_key_references()
149
    ip_tools = [ tool for tool in tool_info.ip_tools.replace("\t"," ").split(" ") if tool != '' ]
150
 
151
    files_with_errors = []
152
    for technology in listify(buildset_info.technology_names):
153
        print
154
        print "Generating IP libraries for technology:", technology
155
        # for all tools supported by quartus
156
        for ip_tool in ip_tools:
157
            tool_options = tool_info['{}_default_options'.format(ip_tool)]
158
            ip_tool_key = "{}_ip_files".format(ip_tool)
159
            # for all hdllib.cfg files found
160
            for ip_lib_name in sorted(lib_tree.configfiles.keys())[::-1]:   #TODO reverse order issue!
161
                ip_lib_info = lib_tree.configfiles[ip_lib_name]
162
                # if technology matches and there are files defined for the current tool
163
                if ip_lib_info.hdl_lib_technology == technology and ip_tool_key in ip_lib_info.content:
164
                    # we have a match do the compilation
165
                    print "==> Processing {} with {}".format(ip_lib_info.ID, ip_tool)
166
                    outputdir = "${HDL_BUILD_DIR}/%s/%s" % (args.buildset, ip_tool)
167
                    mkdir(outputdir)
168
                    vhdl_files = [ name for name in ip_lib_info[ip_tool_key].replace("\t"," ").split(" ") \
169
                                   if name != '' ]
170
                    if ip_tool == 'qmegawiz':
171
                        err_code = run_qmegawiz  (args.buildset, outputdir, ip_lib_info, vhdl_files, tool_options)
172
                    elif ip_tool == 'qsys-generate':
173
                        err_code = run_qsys      (args.buildset, outputdir, ip_lib_info, vhdl_files, tool_options)
174
                    elif ip_tool == 'quartus_sh':
175
                        err_code = run_quartus_sh(args.buildset, outputdir, ip_lib_info, vhdl_files, tool_options)
176
                    else:
177
                        raise NameError("Hdllib file in %s contains a unknown tool (%s) for generating IP." %
178
                                        (ip_lib_info.ID, ip_tool))
179
                    if err_code:
180
                        files_with_errors.append(ip_lib_info.ID)
181
 
182
    if files_with_errors:
183
        print "##### The following files had compile errors:"
184
        print "     ", files_with_errors
185
    else:
186
        print "+++++ No errors during compilation! +++++\n"
187
 

powered by: WebSVN 2.1.0

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