mibuild.xilinx_vivado: support settingsXX.sh
* in the process refactor the version search, the architecture bit width detection, the settings search and all also for xilinx_ise * use distutils.version.StrictVersion
This commit is contained in:
parent
44c6e524ba
commit
fe1c4535d0
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os, struct
|
||||||
|
from distutils.version import StrictVersion
|
||||||
|
|
||||||
def mkdir_noerror(d):
|
def mkdir_noerror(d):
|
||||||
try:
|
try:
|
||||||
|
@ -21,3 +22,16 @@ def write_to_file(filename, contents, force_unix=False):
|
||||||
f = open(filename, "w", newline=newline)
|
f = open(filename, "w", newline=newline)
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
def arch_bits():
|
||||||
|
return struct.calcsize("P")*8
|
||||||
|
|
||||||
|
def versions(path):
|
||||||
|
for n in os.listdir(path):
|
||||||
|
full = os.path.join(path, n)
|
||||||
|
if not os.path.isdir(full):
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
yield StrictVersion(n)
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import os, struct, subprocess, sys
|
import os, subprocess, sys
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from migen.fhdl.std import *
|
from migen.fhdl.std import *
|
||||||
from migen.fhdl.specials import SynthesisDirective
|
from migen.fhdl.specials import SynthesisDirective
|
||||||
|
@ -7,7 +6,7 @@ from migen.genlib.cdc import *
|
||||||
from migen.fhdl.structure import _Fragment
|
from migen.fhdl.structure import _Fragment
|
||||||
|
|
||||||
from mibuild.generic_platform import *
|
from mibuild.generic_platform import *
|
||||||
from mibuild import tools
|
from mibuild import tools, xilinx_tools
|
||||||
|
|
||||||
def _format_constraint(c):
|
def _format_constraint(c):
|
||||||
if isinstance(c, Pins):
|
if isinstance(c, Pins):
|
||||||
|
@ -89,34 +88,21 @@ synth_xilinx -arch {arch} -top top -edif {build_name}.edif""".format(arch=arch,
|
||||||
if r != 0:
|
if r != 0:
|
||||||
raise OSError("Subprocess failed")
|
raise OSError("Subprocess failed")
|
||||||
|
|
||||||
def _is_valid_version(path, v):
|
|
||||||
try:
|
|
||||||
Decimal(v)
|
|
||||||
return os.path.isdir(os.path.join(path, v))
|
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def _run_ise(build_name, ise_path, source, mode, ngdbuild_opt,
|
def _run_ise(build_name, ise_path, source, mode, ngdbuild_opt,
|
||||||
bitgen_opt, ise_commands, map_opt, par_opt):
|
bitgen_opt, ise_commands, map_opt, par_opt, ver=None):
|
||||||
if sys.platform == "win32" or sys.platform == "cygwin":
|
if sys.platform == "win32" or sys.platform == "cygwin":
|
||||||
source = False
|
source = False
|
||||||
build_script_contents = "# Autogenerated by mibuild\nset -e\n"
|
build_script_contents = "# Autogenerated by mibuild\nset -e\n"
|
||||||
if source:
|
if source:
|
||||||
vers = [ver for ver in os.listdir(ise_path) if _is_valid_version(ise_path, ver)]
|
settings = xilinx_tools.settings(ise_path, ver, "ISE_DS")
|
||||||
tools_version = max(vers)
|
build_script_contents += "source " + settings + "\n"
|
||||||
bits = struct.calcsize("P")*8
|
|
||||||
|
|
||||||
xilinx_settings_file = os.path.join(ise_path, tools_version, "ISE_DS", "settings{0}.sh".format(bits))
|
|
||||||
if not os.path.exists(xilinx_settings_file) and bits == 64:
|
|
||||||
# if we are on 64-bit system but the toolchain isn't, try the 32-bit env.
|
|
||||||
xilinx_settings_file = os.path.join(ise_path, tools_version, "ISE_DS", "settings32.sh")
|
|
||||||
build_script_contents += "source " + xilinx_settings_file + "\n"
|
|
||||||
if mode == "edif":
|
if mode == "edif":
|
||||||
ext = "edif"
|
ext = "edif"
|
||||||
else:
|
else:
|
||||||
ext = "ngc"
|
ext = "ngc"
|
||||||
build_script_contents += """
|
build_script_contents += """
|
||||||
xst -ifn {build_name}.xst"""
|
xst -ifn {build_name}.xst
|
||||||
|
"""
|
||||||
|
|
||||||
build_script_contents += """
|
build_script_contents += """
|
||||||
ngdbuild {ngdbuild_opt} -uc {build_name}.ucf {build_name}.{ext} {build_name}.ngd
|
ngdbuild {ngdbuild_opt} -uc {build_name}.ucf {build_name}.{ext} {build_name}.ngd
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
import os
|
||||||
|
from distutils.version import StrictVersion
|
||||||
|
|
||||||
|
from mibuild import tools
|
||||||
|
|
||||||
|
def settings(path, ver=None, sub=None):
|
||||||
|
vers = list(tools.versions(path))
|
||||||
|
if ver is None:
|
||||||
|
ver = max(vers)
|
||||||
|
else:
|
||||||
|
ver = StrictVersion(ver)
|
||||||
|
assert ver in vers
|
||||||
|
|
||||||
|
full = os.path.join(path, str(ver))
|
||||||
|
if sub:
|
||||||
|
full = os.path.join(full, sub)
|
||||||
|
|
||||||
|
search = [64, 32]
|
||||||
|
if tools.arch_bits() == 32:
|
||||||
|
search.reverse()
|
||||||
|
|
||||||
|
for b in search:
|
||||||
|
settings = os.path.join(full, "settings{0}.sh".format(b))
|
||||||
|
if os.path.exists(settings):
|
||||||
|
return settings
|
||||||
|
|
||||||
|
raise ValueError("no settings file found")
|
|
@ -7,7 +7,7 @@ from migen.fhdl.std import *
|
||||||
from migen.fhdl.structure import _Fragment
|
from migen.fhdl.structure import _Fragment
|
||||||
|
|
||||||
from mibuild.generic_platform import *
|
from mibuild.generic_platform import *
|
||||||
from mibuild import tools
|
from mibuild import tools, xilinx_tools
|
||||||
|
|
||||||
def _format_constraint(c):
|
def _format_constraint(c):
|
||||||
if isinstance(c, Pins):
|
if isinstance(c, Pins):
|
||||||
|
@ -56,15 +56,14 @@ def _build_files(device, sources, vincpaths, build_name):
|
||||||
tcl_contents += "quit\n"
|
tcl_contents += "quit\n"
|
||||||
tools.write_to_file(build_name + ".tcl", tcl_contents)
|
tools.write_to_file(build_name + ".tcl", tcl_contents)
|
||||||
|
|
||||||
def _run_vivado(build_name, vivado_path, source):
|
def _run_vivado(build_name, vivado_path, source, ver=None):
|
||||||
if sys.platform == "win32" or sys.platform == "cygwin":
|
if sys.platform == "win32" or sys.platform == "cygwin":
|
||||||
source = False
|
source = False
|
||||||
build_script_contents = "# Autogenerated by mibuild\nset -e\n"
|
build_script_contents = "# Autogenerated by mibuild\nset -e\n"
|
||||||
if source:
|
if source:
|
||||||
raise NotImplementedError
|
settings = xilinx_tools.settings(vivado_path, ver)
|
||||||
build_script_contents += """
|
build_script_contents += "source " + settings + "\n"
|
||||||
vivado -mode tcl -source {build_name}.tcl
|
build_script_contents += "vivado -mode tcl -source " + build_name + ".tcl\n"
|
||||||
""".format(build_name=build_name)
|
|
||||||
build_script_file = "build_" + build_name + ".sh"
|
build_script_file = "build_" + build_name + ".sh"
|
||||||
tools.write_to_file(build_script_file, build_script_contents, force_unix=True)
|
tools.write_to_file(build_script_file, build_script_contents, force_unix=True)
|
||||||
|
|
||||||
|
@ -80,7 +79,7 @@ class XilinxVivadoPlatform(GenericPlatform):
|
||||||
return GenericPlatform.get_verilog(self, *args, special_overrides=so, **kwargs)
|
return GenericPlatform.get_verilog(self, *args, special_overrides=so, **kwargs)
|
||||||
|
|
||||||
def build(self, fragment, build_dir="build", build_name="top",
|
def build(self, fragment, build_dir="build", build_name="top",
|
||||||
vivado_path="/opt/Xilinx", source=True, run=True):
|
vivado_path="/opt/Xilinx/Vivado", source=True, run=True):
|
||||||
tools.mkdir_noerror(build_dir)
|
tools.mkdir_noerror(build_dir)
|
||||||
os.chdir(build_dir)
|
os.chdir(build_dir)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue