Loading files
22023cc43This file is pinned to the selected release. Download the original to open it in your design tool.
#
# This file is part of LiteX.
#
# Copyright (c) 2015 Sebastien Bourdeauducq <sb@m-labs.hk>
# Copyright (c) 2015-2018 Florent Kermarrec <florent@enjoy-digital.fr>
# Copyright (c) 2022 Victor Suarez Rovere <suarezvictor@gmai.com>
# SPDX-License-Identifier: BSD-2-Clause
import os
from litex.build.generic_platform import GenericPlatform
from litex.build.xilinx import common, vivado, ise, yosys_nextpnr
# XilinxPlatform -----------------------------------------------------------------------------------
class XilinxPlatform(GenericPlatform):
_bitstream_ext = {
"sram" : ".bit",
"flash" : ".bin"
}
_supported_toolchains = {
"spartan6" : ["ise"],
"7series" : ["vivado", "f4pga", "yosys+nextpnr", "openxc7"],
"ultrascale" : ["vivado"],
"ultrascale+" : ["vivado"],
}
_jtag_support = [
"xc6",
"xc7a", "xc7k", "xc7s", "xc7v", "xc7z",
"xcau", "xcku", "xcvu", "xczu"
]
def __init__(self, *args, toolchain="ise", device_image_arch=None, **kwargs):
GenericPlatform.__init__(self, *args, **kwargs)
self.edifs = set()
self.ips = {}
if toolchain == "ise":
self.toolchain = ise.XilinxISEToolchain()
elif toolchain == "vivado":
self.toolchain = vivado.XilinxVivadoToolchain(device_image_arch=device_image_arch)
elif toolchain == "symbiflow" or toolchain == "f4pga":
from litex.build.xilinx import f4pga
self.toolchain = f4pga.F4PGAToolchain()
elif toolchain in ["yosys+nextpnr", "openxc7"]:
self.toolchain = yosys_nextpnr.XilinxYosysNextpnrToolchain(toolchain)
else:
raise ValueError(f"Unknown toolchain {toolchain}")
if device_image_arch is not None:
self._bitstream_ext = dict(self._bitstream_ext)
self._bitstream_ext["sram"] = ".pdi"
def add_edif(self, filename):
self.edifs.add((os.path.abspath(filename)))
def add_ip(self, filename, disable_constraints=False):
self.ips.update({os.path.abspath(filename): disable_constraints})
def add_platform_command(self, command, **signals):
skip = False
if isinstance(self.toolchain, yosys_nextpnr.XilinxYosysNextpnrToolchain):
# FIXME: Add support for INTERNAL_VREF to yosys+nextpnr flow.
if "set_property INTERNAL_VREF" in command:
print("WARNING: INTERNAL_VREF constraint removed since not yet supported by yosys-nextpnr flow.")
skip = True
if "set_property CFGBVS" in command:
print("WARNING: CFGBVS constraint removed since not yet supported by yosys-nextpnr flow.")
skip = True
if "set_property CONFIG_VOLTAGE" in command:
print("WARNING: CONFIG_VOLTAGE constraint removed since not yet supported by yosys-nextpnr flow.")
skip = True
if not skip:
GenericPlatform.add_platform_command(self, command, **signals)
def get_verilog(self, *args, special_overrides=dict(), **kwargs):
so = dict(common.xilinx_special_overrides)
device = self.device.lower()
family = self.device_family
if family is None:
if device.startswith(("xc6", "xa6", "xq6")):
family = "spartan6"
elif device.startswith(("xc7", "xa7", "xq7")):
family = "7series"
elif device.startswith(("xcau", "xcku", "xqku", "xcvu", "xqvu", "xczu", "xqzu")):
family = "ultrascale"
if family == "spartan6":
so.update(common.xilinx_s6_special_overrides)
elif family == "7series":
so.update(common.xilinx_s7_special_overrides)
elif family in ["ultrascale", "ultrascale+"]:
so.update(common.xilinx_us_special_overrides)
so.update(special_overrides)
return GenericPlatform.get_verilog(self, *args,
special_overrides = so,
attr_translate = self.toolchain.attr_translate,
**kwargs
)
def get_edif(self, fragment, **kwargs):
return GenericPlatform.get_edif(self, fragment, "UNISIMS", "Xilinx", self.device, **kwargs)
def build(self, *args, **kwargs):
return self.toolchain.build(self, *args, **kwargs)
def add_false_path_constraint(self, from_, to):
if hasattr(from_, "p"):
from_ = from_.p
if hasattr(to, "p"):
to = to.p
self.toolchain.add_false_path_constraint(self, from_, to)
def add_generated_clock_from_divider_reg(self, name, reg_basename, divide_by):
self.add_platform_command(
f"create_generated_clock -name {name} -divide_by {divide_by} "
+ "-source [get_pins -hierarchical -filter {{NAME =~ *" + reg_basename + "/C}}] "
+ "[get_pins -hierarchical -filter {{NAME =~ *" + reg_basename + "/Q}}]"
)
def add_false_path_constraints_by_name(self, *clock_names):
# On Vivado, some generated/internal clocks are only resolvable after synthesis.
# Emit explicit set_clock_groups in pre-placement commands for robust resolution.
if hasattr(self.toolchain, "pre_placement_commands"):
for i, a in enumerate(clock_names):
for b in clock_names[i+1:]:
self.toolchain.pre_placement_commands.append(
f"set_clock_groups -asynchronous -group [get_clocks {a}] -group [get_clocks {b}]"
)
else:
for a in clock_names:
for b in clock_names:
if a != b:
self.add_false_path_constraint(a, b)
@classmethod
def fill_args(cls, toolchain, parser):
"""
pass parser to the specific toolchain to
fill this with toolchain args
Parameters
==========
toolchain: str
toolchain name
parser: argparse.ArgumentParser
parser to be filled
"""
if toolchain == "vivado":
vivado.vivado_build_args(parser)
elif toolchain in ["yosys+nextpnr", "openxc7"]:
yosys_nextpnr.xilinx_yosys_nextpnr_args(parser)
@classmethod
def get_argdict(cls, toolchain, args):
"""
return a dict of args
Parameters
==========
toolchain: str
toolchain name
Return
======
a dict of key/value for each args or an empty dict
"""
if toolchain == "vivado":
return vivado.vivado_build_argdict(args)
elif toolchain in ["yosys+nextpnr", "openxc7"]:
return yosys_nextpnr.xilinx_yosys_nextpnr_argdict(args)
else:
return dict()
# XilinxSpartan6Platform ---------------------------------------------------------------------------
class XilinxSpartan6Platform(XilinxPlatform):
device_family = "spartan6"
# Xilinx7SeriesPlatform ----------------------------------------------------------------------------
class Xilinx7SeriesPlatform(XilinxPlatform):
device_family = "7series"
# XilinxUSPlatform ---------------------------------------------------------------------------------
class XilinxUSPlatform(XilinxPlatform):
device_family = "ultrascale"
# XilinxUSPPlatform --------------------------------------------------------------------------------
class XilinxUSPPlatform(XilinxPlatform):
device_family = "ultrascale+"