#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
###############################################################################
|
###############################################################################
|
#
|
#
|
# Copyright (C) 2014-2018
|
# Copyright (C) 2014-2018
|
# ASTRON (Netherlands Institute for Radio Astronomy)
|
# ASTRON (Netherlands Institute for Radio Astronomy)
|
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
#
|
#
|
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
# the Free Software Foundation, either version 3 of the License, or
|
# the Free Software Foundation, either version 3 of the License, or
|
# (at your option) any later version.
|
# (at your option) any later version.
|
#
|
#
|
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
#
|
#
|
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
# along with this program. If not, see .
|
# along with this program. If not, see .
|
#
|
#
|
# $Id$
|
# $Id$
|
#
|
#
|
###############################################################################
|
###############################################################################
|
|
|
import sys
|
import sys
|
import os
|
import os
|
from os.path import expandvars, dirname, basename
|
from os.path import expandvars, dirname, basename
|
from subprocess import call, STDOUT
|
from subprocess import call, STDOUT
|
from common_radiohdl import listify, mkdir
|
from common_radiohdl import listify, mkdir
|
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
from hdl_configfile import HdlBuildset, HdlTool
|
from hdl_configfile import HdlBuildset, HdlTool
|
from hdl_configtree import HdlLibTree
|
from hdl_configtree import HdlLibTree
|
|
|
|
|
def run_qmegawiz(buildset, outputdir, hdllib, vhdl_files, options):
|
def run_qmegawiz(buildset, outputdir, hdllib, vhdl_files, options):
|
"""
|
"""
|
Run qmegawiz for the configuration in the given hdllib.
|
Run qmegawiz for the configuration in the given hdllib.
|
The script takes care that the exit code of qmegawiz is returned to the caller.
|
The script takes care that the exit code of qmegawiz is returned to the caller.
|
"""
|
"""
|
extra_options = hdllib.get_value("qmegawiz_extra_options", False)
|
extra_options = hdllib.get_value("qmegawiz_extra_options", False)
|
if not extra_options:
|
if not extra_options:
|
extra_options = ""
|
extra_options = ""
|
|
|
error_code = 0
|
error_code = 0
|
for vhdl_file in vhdl_files:
|
for vhdl_file in vhdl_files:
|
script = '. ${RADIOHDL_GEAR}/quartus/set_quartus %s\n' % buildset
|
script = '. ${RADIOHDL_GEAR}/quartus/set_quartus %s\n' % buildset
|
script += 'cd %s\n' % outputdir
|
script += 'cd %s\n' % outputdir
|
script += 'cp %s/%s .\n' % (hdllib.location, vhdl_file)
|
script += 'cp %s/%s .\n' % (hdllib.location, vhdl_file)
|
script += 'set -o pipefail\n'
|
script += 'set -o pipefail\n'
|
# echo line without 'Info:' to make sure grep it's exit code is 0
|
# echo line without 'Info:' to make sure grep it's exit code is 0
|
script += '(echo " " ; qmegawiz %s %s %s 2>&1) | grep -iv Info:\n' \
|
script += '(echo " " ; qmegawiz %s %s %s 2>&1) | grep -iv Info:\n' \
|
% (options, extra_options, vhdl_file)
|
% (options, extra_options, vhdl_file)
|
script += 'exit_code=$?\n'
|
script += 'exit_code=$?\n'
|
script += 'rm %s\n' % vhdl_file
|
script += 'rm %s\n' % vhdl_file
|
script += 'exit $exit_code\n'
|
script += 'exit $exit_code\n'
|
# execute script
|
# execute script
|
print("compiling {} ... ".format(vhdl_file))
|
print("compiling {} ... ".format(vhdl_file))
|
return_code = call(script, stdout=None, stderr=STDOUT, shell=True)
|
return_code = call(script, stdout=None, stderr=STDOUT, shell=True, exectuable="/bin/bash")
|
# qmegawiz is very sloppy with it's exitcodes. We assume 0 is OK although this not always the case. :-(
|
# qmegawiz is very sloppy with it's exitcodes. We assume 0 is OK although this not always the case. :-(
|
if return_code == 0:
|
if return_code == 0:
|
print("*** Generation (probably) OK\n")
|
print("*** Generation (probably) OK\n")
|
else:
|
else:
|
print("*** Error during generation, exitcode={}\n".format(return_code))
|
print("*** Error during generation, exitcode={}\n".format(return_code))
|
error_code |= return_code
|
error_code |= return_code
|
return error_code
|
return error_code
|
|
|
|
|
def run_qsys(buildset, outputdir, hdllib, vhdl_files, options):
|
def run_qsys(buildset, outputdir, hdllib, vhdl_files, options):
|
"""
|
"""
|
Run qsys for the configuration in the given hdllib.
|
Run qsys for the configuration in the given hdllib.
|
The script takes care that the exit code of qsys is returned to the caller.
|
The script takes care that the exit code of qsys is returned to the caller.
|
"""
|
"""
|
extra_options = hdllib.get_value("qsys-generate_extra_options", False)
|
extra_options = hdllib.get_value("qsys-generate_extra_options", False)
|
if not extra_options:
|
if not extra_options:
|
extra_options = ""
|
extra_options = ""
|
|
|
error_code = 0
|
error_code = 0
|
for vhdl_file in vhdl_files:
|
for vhdl_file in vhdl_files:
|
script = '. ${RADIOHDL_GEAR}/quartus/set_quartus %s\n' % buildset
|
script = '. ${RADIOHDL_GEAR}/quartus/set_quartus %s\n' % buildset
|
script += 'cd %s\n' % outputdir
|
script += 'cd %s\n' % outputdir
|
script += 'cp %s/%s .\n' % (hdllib.location, vhdl_file)
|
script += 'cp %s/%s .\n' % (hdllib.location, vhdl_file)
|
#script += 'cd %s\n' % hdllib.location
|
#script += 'cd %s\n' % hdllib.location
|
script += 'set -o pipefail\n'
|
script += 'set -o pipefail\n'
|
# echo line without 'Info:' to make sure grep it's exit code is 0
|
# echo line without 'Info:' to make sure grep it's exit code is 0
|
script += '(echo " " ; qsys-generate %s %s %s --search-path=%s --output-directory=%s 2>&1) | grep -iv Info:\n' \
|
script += '(echo " " ; qsys-generate %s %s %s --search-path=%s --output-directory=%s 2>&1) | grep -iv Info:\n' \
|
% (vhdl_file, options, extra_options, "outputdir,$", outputdir)
|
% (vhdl_file, options, extra_options, "outputdir,$", outputdir)
|
script += 'exit_code=$?\n'
|
script += 'exit_code=$?\n'
|
script += 'rm %s\n' % vhdl_file
|
script += 'rm %s\n' % vhdl_file
|
script += 'exit $exit_code\n'
|
script += 'exit $exit_code\n'
|
# execute script
|
# execute script
|
print("compiling {} ... , output-dir = {}".format(vhdl_file, outputdir))
|
print("compiling {} ... , output-dir = {}".format(vhdl_file, outputdir))
|
return_code = call(script, stdout=None, stderr=STDOUT, shell=True)
|
return_code = call(script, stdout=None, stderr=STDOUT, shell=True, executable="/bin/bash")
|
if return_code == 0:
|
if return_code == 0:
|
print("*** Generation OK\n")
|
print("*** Generation OK\n")
|
else:
|
else:
|
print("*** Error during generation, exitcode={}\n".format(return_code))
|
print("*** Error during generation, exitcode={}\n".format(return_code))
|
error_code |= return_code
|
error_code |= return_code
|
return error_code
|
return error_code
|
|
|
|
|
def run_quartus_sh(buildset, outputdir, hdllib, tcl_files, options):
|
def run_quartus_sh(buildset, outputdir, hdllib, tcl_files, options):
|
"""
|
"""
|
Run quartus_sh for the configuration in the given hdllib.
|
Run quartus_sh for the configuration in the given hdllib.
|
The script takes care that the exit code of quartus_sh is returned to the caller.
|
The script takes care that the exit code of quartus_sh is returned to the caller.
|
"""
|
"""
|
extra_options = hdllib.get_value("quartus_sh_extra_options", False)
|
extra_options = hdllib.get_value("quartus_sh_extra_options", False)
|
if not extra_options:
|
if not extra_options:
|
extra_options = ""
|
extra_options = ""
|
|
|
error_code = 0
|
error_code = 0
|
for tcl_file in tcl_files:
|
for tcl_file in tcl_files:
|
script = '. ${RADIOHDL_GEAR}/quartus/set_quartus %s\n' % buildset
|
script = '. ${RADIOHDL_GEAR}/quartus/set_quartus %s\n' % buildset
|
script += 'cd %s/%s\n' % (outputdir, hdllib.quartus_sh_ip_srcdir)
|
script += 'cd %s/%s\n' % (outputdir, hdllib.quartus_sh_ip_srcdir)
|
script += 'set -o pipefail\n'
|
script += 'set -o pipefail\n'
|
# echo line without 'Info:' to make sure grep it's exit code is 0
|
# echo line without 'Info:' to make sure grep it's exit code is 0
|
script += '(echo " " ; quartus_sh %s %s -t %s 2>&1) | grep -iv Info:\n' \
|
script += '(echo " " ; quartus_sh %s %s -t %s 2>&1) | grep -iv Info:\n' \
|
% (options, extra_options, tcl_file)
|
% (options, extra_options, tcl_file)
|
script += 'exit_code=$?\n'
|
script += 'exit_code=$?\n'
|
script += 'exit $exit_code\n'
|
script += 'exit $exit_code\n'
|
# execute script
|
# execute script
|
print("compiling {} ... ".format(tcl_file))
|
print("compiling {} ... ".format(tcl_file))
|
return_code = call(script, stdout=None, stderr=STDOUT, shell=True)
|
return_code = call(script, stdout=None, stderr=STDOUT, shell=True, executable="/bin/bash")
|
if return_code == 0:
|
if return_code == 0:
|
print("*** Generation OK\n")
|
print("*** Generation OK\n")
|
else:
|
else:
|
print("*** Error during generation, exitcode={}\n".format(return_code))
|
print("*** Error during generation, exitcode={}\n".format(return_code))
|
error_code |= return_code
|
error_code |= return_code
|
return error_code
|
return error_code
|
|
|
|
|
def expand_all_vars(dir_name):
|
def expand_all_vars(dir_name):
|
_dirname = dir_name
|
_dirname = dir_name
|
while '$' in _dirname:
|
while '$' in _dirname:
|
# print(_dirname)
|
# print(_dirname)
|
_dirname = expandvars(_dirname)
|
_dirname = expandvars(_dirname)
|
return _dirname
|
return _dirname
|
|
|
|
|
if __name__ == '__main__':
|
if __name__ == '__main__':
|
# setup parser and parse the arguments.
|
# setup parser and parse the arguments.
|
argparser = ArgumentParser(description='Generate the IP libraries for all technologies of the given buildset')
|
argparser = ArgumentParser(description='Generate the IP libraries for all technologies of the given buildset')
|
argparser.add_argument('buildset', help="Filename like 'hdl_buildset_.cfg'")
|
argparser.add_argument('buildset', help="Filename like 'hdl_buildset_.cfg'")
|
args = argparser.parse_args()
|
args = argparser.parse_args()
|
|
|
# resolve full name of buildsetfile and force it to be explicit absolute or relative.
|
# resolve full name of buildsetfile and force it to be explicit absolute or relative.
|
full_buildsetfile_name = os.path.join(os.getenv('RADIOHDL_CONFIG'), 'hdl_buildset_{}.cfg'.format(args.buildset))
|
full_buildsetfile_name = os.path.join(os.getenv('RADIOHDL_CONFIG'), 'hdl_buildset_{}.cfg'.format(args.buildset))
|
print('full_buildsetfile_name={}'.format(full_buildsetfile_name))
|
print('full_buildsetfile_name={}'.format(full_buildsetfile_name))
|
if full_buildsetfile_name[0] != '/':
|
if full_buildsetfile_name[0] != '/':
|
full_buildsetfile_name = "./" + full_buildsetfile_name
|
full_buildsetfile_name = "./" + full_buildsetfile_name
|
# read the file
|
# read the file
|
buildset_info = HdlBuildset(full_buildsetfile_name)
|
buildset_info = HdlBuildset(full_buildsetfile_name)
|
buildset_info.resolve_key_references()
|
buildset_info.resolve_key_references()
|
|
|
# read in all hdllib configfiles
|
# read in all hdllib configfiles
|
root_dirs = [expand_all_vars(rootdir) for rootdir in buildset_info.lib_root_dirs.replace("\t", " ").split(" ")
|
root_dirs = [expand_all_vars(rootdir) for rootdir in buildset_info.lib_root_dirs.replace("\t", " ").split(" ")
|
if rootdir != '']
|
if rootdir != '']
|
lib_tree = HdlLibTree(rootdirs=root_dirs, filename="hdllib.cfg", sections="generate_ip_libs")
|
lib_tree = HdlLibTree(rootdirs=root_dirs, filename="hdllib.cfg", sections="generate_ip_libs")
|
|
|
# read in the tool environment settings
|
# read in the tool environment settings
|
tool_config_file = os.path.join(os.getenv('RADIOHDL_CONFIG'), 'hdl_tool_{}.cfg'.format(buildset_info.synth_tool_name))
|
tool_config_file = os.path.join(os.getenv('RADIOHDL_CONFIG'), 'hdl_tool_{}.cfg'.format(buildset_info.synth_tool_name))
|
print('tool_config_file={}'.format(tool_config_file))
|
print('tool_config_file={}'.format(tool_config_file))
|
tool_info = HdlTool(tool_config_file)
|
tool_info = HdlTool(tool_config_file)
|
tool_info.resolve_key_references()
|
tool_info.resolve_key_references()
|
ip_tools = [tool for tool in tool_info.ip_tools.replace("\t", " ").split(" ")
|
ip_tools = [tool for tool in tool_info.ip_tools.replace("\t", " ").split(" ")
|
if tool != '']
|
if tool != '']
|
|
|
files_with_errors = []
|
files_with_errors = []
|
for technology in listify(buildset_info.technology_names):
|
for technology in listify(buildset_info.technology_names):
|
print()
|
print()
|
print("Generating IP libraries for technology:", technology)
|
print("Generating IP libraries for technology:", technology)
|
# for all tools supported by quartus
|
# for all tools supported by quartus
|
for ip_tool in ip_tools:
|
for ip_tool in ip_tools:
|
tool_options = tool_info['{}_default_options'.format(ip_tool)]
|
tool_options = tool_info['{}_default_options'.format(ip_tool)]
|
ip_tool_key = "{}_ip_files".format(ip_tool)
|
ip_tool_key = "{}_ip_files".format(ip_tool)
|
# for all hdllib.cfg files found
|
# for all hdllib.cfg files found
|
for ip_lib_name in sorted(lib_tree.configfiles.keys())[::-1]: # TODO reverse order issue!
|
for ip_lib_name in sorted(lib_tree.configfiles.keys())[::-1]: # TODO reverse order issue!
|
ip_lib_info = lib_tree.configfiles[ip_lib_name]
|
ip_lib_info = lib_tree.configfiles[ip_lib_name]
|
# if technology matches and there are files defined for the current tool
|
# if technology matches and there are files defined for the current tool
|
if ip_lib_info.hdl_lib_technology == technology and ip_tool_key in ip_lib_info.content:
|
if ip_lib_info.hdl_lib_technology == technology and ip_tool_key in ip_lib_info.content:
|
# we have a match do the compilation
|
# we have a match do the compilation
|
print("==> Processing {} with {}".format(ip_lib_info.ID, ip_tool))
|
print("==> Processing {} with {}".format(ip_lib_info.ID, ip_tool))
|
outputdir = os.path.join(os.getenv('RADIOHDL_BUILD_DIR'), '{}/{}/'.format(args.buildset, ip_tool))
|
outputdir = os.path.join(os.getenv('RADIOHDL_BUILD_DIR'), '{}/{}/'.format(args.buildset, ip_tool))
|
mkdir(outputdir)
|
mkdir(outputdir)
|
vhdl_files = [name for name in ip_lib_info[ip_tool_key].replace("\t", " ").split(" ")
|
vhdl_files = [name for name in ip_lib_info[ip_tool_key].replace("\t", " ").split(" ")
|
if name != '']
|
if name != '']
|
if ip_tool == 'qmegawiz':
|
if ip_tool == 'qmegawiz':
|
err_code = run_qmegawiz(args.buildset, outputdir, ip_lib_info, vhdl_files, tool_options)
|
err_code = run_qmegawiz(args.buildset, outputdir, ip_lib_info, vhdl_files, tool_options)
|
elif ip_tool == 'qsys-generate':
|
elif ip_tool == 'qsys-generate':
|
err_code = run_qsys(args.buildset, outputdir, ip_lib_info, vhdl_files, tool_options)
|
err_code = run_qsys(args.buildset, outputdir, ip_lib_info, vhdl_files, tool_options)
|
|
|
elif ip_tool == 'quartus_sh':
|
elif ip_tool == 'quartus_sh':
|
err_code = run_quartus_sh(args.buildset, outputdir, ip_lib_info, vhdl_files, tool_options)
|
err_code = run_quartus_sh(args.buildset, outputdir, ip_lib_info, vhdl_files, tool_options)
|
else:
|
else:
|
raise NameError("Hdllib file in %s contains a unknown tool (%s) for generating IP." %
|
raise NameError("Hdllib file in %s contains a unknown tool (%s) for generating IP." %
|
(ip_lib_info.ID, ip_tool))
|
(ip_lib_info.ID, ip_tool))
|
if err_code:
|
if err_code:
|
files_with_errors.append(ip_lib_info.ID)
|
files_with_errors.append(ip_lib_info.ID)
|
|
|
if files_with_errors:
|
if files_with_errors:
|
print("##### The following files had compile errors:")
|
print("##### The following files had compile errors:")
|
print(" ", files_with_errors)
|
print(" ", files_with_errors)
|
else:
|
else:
|
print("+++++ No errors during compilation! +++++\n")
|
print("+++++ No errors during compilation! +++++\n")
|
|
|