From 1ea94ca264b88de39fd8df62a14399f35811c04d Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Sat, 4 Mar 2023 11:25:46 +0100 Subject: [PATCH 1/2] build/anlogic/platform: fix extension format fs -> bit --- litex/build/anlogic/platform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litex/build/anlogic/platform.py b/litex/build/anlogic/platform.py index e857ce0a6..734b49109 100644 --- a/litex/build/anlogic/platform.py +++ b/litex/build/anlogic/platform.py @@ -13,7 +13,7 @@ from litex.build.anlogic import common, anlogic # AnlogicPlatform ---------------------------------------------------------------------------------- class AnlogicPlatform(GenericPlatform): - bitstream_ext = ".fs" + bitstream_ext = ".bit" _supported_toolchains = ["td"] From c40963531cea3f0378b0f6896f9ce015b624498b Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Sat, 4 Mar 2023 11:36:29 +0100 Subject: [PATCH 2/2] build/generic_platform build/xxx/platform soc/integration/builder: generic_platform add a method to return extension for sram/flash vendor platform: bitstream_ext -> _bitstream_ext and replace by a dict when extension depends on mode builder: use `get_bitstream_extension` instead of directly using bitstream_ext --- litex/build/altera/platform.py | 5 ++++- litex/build/anlogic/platform.py | 2 +- litex/build/efinix/platform.py | 5 ++++- litex/build/generic_platform.py | 28 ++++++++++++++++++++++++++++ litex/build/gowin/platform.py | 2 +- litex/build/lattice/platform.py | 4 ++-- litex/build/microsemi/platform.py | 2 +- litex/build/osfpga/platform.py | 2 +- litex/build/quicklogic/platform.py | 2 +- litex/build/xilinx/platform.py | 5 ++++- litex/soc/integration/builder.py | 5 +---- 11 files changed, 48 insertions(+), 14 deletions(-) diff --git a/litex/build/altera/platform.py b/litex/build/altera/platform.py index 4e880f145..ca690dd77 100644 --- a/litex/build/altera/platform.py +++ b/litex/build/altera/platform.py @@ -13,7 +13,10 @@ from litex.build.altera import common, quartus # AlteraPlatform ----------------------------------------------------------------------------------- class AlteraPlatform(GenericPlatform): - bitstream_ext = ".sof" + _bitstream_ext = { + "sram" : ".sof", + "flash" : ".rbf" + } create_rbf = True _supported_toolchains = ["quartus"] diff --git a/litex/build/anlogic/platform.py b/litex/build/anlogic/platform.py index 734b49109..627882467 100644 --- a/litex/build/anlogic/platform.py +++ b/litex/build/anlogic/platform.py @@ -13,7 +13,7 @@ from litex.build.anlogic import common, anlogic # AnlogicPlatform ---------------------------------------------------------------------------------- class AnlogicPlatform(GenericPlatform): - bitstream_ext = ".bit" + _bitstream_ext = ".bit" _supported_toolchains = ["td"] diff --git a/litex/build/efinix/platform.py b/litex/build/efinix/platform.py index a186cae3d..f08b8f44f 100644 --- a/litex/build/efinix/platform.py +++ b/litex/build/efinix/platform.py @@ -16,7 +16,10 @@ from litex.build.efinix import EfinixDbParser # EfinixPlatform ----------------------------------------------------------------------------------- class EfinixPlatform(GenericPlatform): - bitstream_ext = ".bit" + _bitstream_ext = { + "sram" : ".bit", + "flash" : ".hex" + } _supported_toolchains = ["efinity"] diff --git a/litex/build/generic_platform.py b/litex/build/generic_platform.py index c86287bee..1e160589f 100644 --- a/litex/build/generic_platform.py +++ b/litex/build/generic_platform.py @@ -323,6 +323,9 @@ class ConstraintManager: class GenericPlatform: device_family = None + _bitstream_ext = None # None by default, overridden by vendor platform, may + # be a string when same extension is used for sram and + # flash. A dict must be provided otherwise def __init__(self, device, io, connectors=[], name=None): self.toolchain = None @@ -463,6 +466,31 @@ class GenericPlatform: def build(self, fragment): raise NotImplementedError("GenericPlatform.build must be overloaded") + def get_bitstream_extension(self, mode="sram"): + """ + Return the bitstream's extension according to mode (sram / flash). + The default (generic) implementation check if `self._bitstream_ext` + is a dict or a string. For former case it return extension using `mode` + parameter, in latter case simply return `self._bitstream_ext`'s value. + When this behaviour is not adapted this method must be overriden by + a specific one at vendor level. + + Parameters + ---------- + mode: str + bitstream destination (must be sram or flash) + + Returns + ------- + bitstream extension: str + """ + if self._bitstream_ext is None: + return None + elif type(self._bitstream_ext) == dict: + return self._bitstream_ext[mode] + else: + return self._bitstream_ext + def create_programmer(self): raise NotImplementedError diff --git a/litex/build/gowin/platform.py b/litex/build/gowin/platform.py index 62525fe65..b37e8d155 100644 --- a/litex/build/gowin/platform.py +++ b/litex/build/gowin/platform.py @@ -13,7 +13,7 @@ from litex.build.gowin import common, gowin # GowinPlatform ------------------------------------------------------------------------------------ class GowinPlatform(GenericPlatform): - bitstream_ext = ".fs" + _bitstream_ext = ".fs" _supported_toolchains = ["gowin", "apicula"] diff --git a/litex/build/lattice/platform.py b/litex/build/lattice/platform.py index d6ce941f7..029ca578c 100644 --- a/litex/build/lattice/platform.py +++ b/litex/build/lattice/platform.py @@ -11,7 +11,7 @@ from litex.build.lattice import common, diamond, icestorm, trellis, radiant, oxi # LatticePlatform ---------------------------------------------------------------------------------- class LatticePlatform(GenericPlatform): - bitstream_ext = ".bit" + _bitstream_ext = ".bit" _supported_toolchains = { "ice40" : ["icestorm"], @@ -26,7 +26,7 @@ class LatticePlatform(GenericPlatform): elif toolchain == "trellis": self.toolchain = trellis.LatticeTrellisToolchain() elif toolchain == "icestorm": - self.bitstream_ext = ".bin" + self._bitstream_ext = ".bin" self.toolchain = icestorm.LatticeIceStormToolchain() elif toolchain == "radiant": self.toolchain = radiant.LatticeRadiantToolchain() diff --git a/litex/build/microsemi/platform.py b/litex/build/microsemi/platform.py index a36ee7656..ace9bfe4a 100644 --- a/litex/build/microsemi/platform.py +++ b/litex/build/microsemi/platform.py @@ -10,7 +10,7 @@ from litex.build.microsemi import common, libero_soc # MicrosemiPlatform -------------------------------------------------------------------------------- class MicrosemiPlatform(GenericPlatform): - bitstream_ext = ".bit" + _bitstream_ext = ".bit" _supported_toolchains = ["libero_soc_polarfire"] diff --git a/litex/build/osfpga/platform.py b/litex/build/osfpga/platform.py index 265d48080..b01516629 100644 --- a/litex/build/osfpga/platform.py +++ b/litex/build/osfpga/platform.py @@ -12,7 +12,7 @@ from litex.build.osfpga import common, osfpga # OSFPGAPlatform ----------------------------------------------------------------------------------- class OSFPGAPlatform(GenericPlatform): - bitstream_ext = ".bin" + _bitstream_ext = ".bin" _supported_toolchains = ["osfpga"] diff --git a/litex/build/quicklogic/platform.py b/litex/build/quicklogic/platform.py index 506ac0bed..ce099aac1 100644 --- a/litex/build/quicklogic/platform.py +++ b/litex/build/quicklogic/platform.py @@ -12,7 +12,7 @@ from litex.build.quicklogic import common, f4pga # QuickLogicPlatform ------------------------------------------------------------------------------- class QuickLogicPlatform(GenericPlatform): - bitstream_ext = ".bit" + _bitstream_ext = ".bit" _supported_toolchains = ["f4pga"] diff --git a/litex/build/xilinx/platform.py b/litex/build/xilinx/platform.py index 5e9eedbde..8a167b761 100644 --- a/litex/build/xilinx/platform.py +++ b/litex/build/xilinx/platform.py @@ -14,7 +14,10 @@ from litex.build.xilinx import common, vivado, ise, yosys_nextpnr # XilinxPlatform ----------------------------------------------------------------------------------- class XilinxPlatform(GenericPlatform): - bitstream_ext = ".bit" + _bitstream_ext = { + "sram" : ".bit", + "flash" : ".bin" + } _supported_toolchains = { "spartan6" : ["ise"], diff --git a/litex/soc/integration/builder.py b/litex/soc/integration/builder.py index ceac465e9..ea75e0a66 100644 --- a/litex/soc/integration/builder.py +++ b/litex/soc/integration/builder.py @@ -382,10 +382,7 @@ class Builder: def get_bitstream_filename(self, mode="sram", ext=None): assert mode in ["sram", "flash"] if ext is None: - ext = { - "sram" : self.soc.platform.bitstream_ext, - "flash" : ".bin" # FIXME. - }[mode] + ext = self.soc.platform.get_bitstream_extension(mode) return os.path.join(self.gateware_dir, self.soc.get_build_name() + ext) # Builder Arguments --------------------------------------------------------------------------------