Skip to content

Commit

Permalink
Merge pull request #1809 from trabucayre/jtagbone_uartbone_parser
Browse files Browse the repository at this point in the history
soc/integration/soc_core: add new parameters --with-uartbone and --with-jtagbone, deprecate crossover+uartbone
  • Loading branch information
enjoy-digital authored Oct 23, 2023
2 parents 7e64189 + 745e584 commit ad98c7c
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 2 deletions.
3 changes: 2 additions & 1 deletion litex/build/anlogic/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
# AnlogicPlatform ----------------------------------------------------------------------------------

class AnlogicPlatform(GenericPlatform):
_bitstream_ext = ".bit"
_bitstream_ext = ".bit"
_jtag_support = False

_supported_toolchains = ["td"]

Expand Down
1 change: 1 addition & 0 deletions litex/build/colognechip/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class CologneChipPlatform(GenericPlatform):
bitstream_ext = "_00.cfg.bit"
_jtag_support = False

_supported_toolchains = ["colognechip"]

Expand Down
11 changes: 11 additions & 0 deletions litex/build/generic_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ def get_platform_commands(self):

class GenericPlatform:
device_family = None
_jtag_support = True # JTAGBone can't be used with all FPGAs.
_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
Expand Down Expand Up @@ -504,6 +505,16 @@ def get_bitstream_extension(self, mode="sram"):
def create_programmer(self):
raise NotImplementedError

@property
def jtag_support(self):
if isinstance(self._jtag_support, str):
return self._jtag_support
else:
for dev in self._jtag_support:
if self.device.startswith(dev):
return True
return False

@property
def support_mixed_language(self):
return self.toolchain.support_mixed_language
Expand Down
1 change: 1 addition & 0 deletions litex/build/gowin/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

class GowinPlatform(GenericPlatform):
_bitstream_ext = ".fs"
_jtag_support = False

_supported_toolchains = ["gowin", "apicula"]

Expand Down
1 change: 1 addition & 0 deletions litex/build/microsemi/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class MicrosemiPlatform(GenericPlatform):
_bitstream_ext = ".bit"
_jtag_support = False

_supported_toolchains = ["libero_soc_polarfire"]

Expand Down
28 changes: 27 additions & 1 deletion litex/build/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
import logging
import argparse
import importlib
import time

from litex.soc.cores import cpu
from litex.soc.integration import soc_core
from litex.soc.integration import builder

from litex.gen.common import *

# Litex Argument Parser ----------------------------------------------------------------------------

class LiteXArgumentParser(argparse.ArgumentParser):
Expand Down Expand Up @@ -63,6 +66,9 @@ def __init__(self, platform=None, **kwargs):
self.set_platform(platform)
self.add_target_group()
self.add_logging_group()
# workaround for backward compatibility
self._rm_jtagbone = False
self._rm_uartbone = False

def set_platform(self, platform):
""" set platform. Check first if not already set
Expand Down Expand Up @@ -104,8 +110,21 @@ def add_target_argument(self, *args, **kwargs):
""" wrapper to add argument to "Target options group" from outer of this
class
"""
arg = args[0]
if arg in ["--with-jtagbone", "--with-uartbone"]:
if arg == "--with-jtagbone":
self._rm_jtagbone = True
else:
self._rm_uartbone = True
print("Warning {} {} {}".format(
colorer(arg, color="red"),
colorer(" is added by SoCCore. ", color="red"),
colorer("Please remove this option from target", color="yellow")))
time.sleep(2)
return # bypass insert
if self._target_group is None:
self._target_group = self.add_argument_group(title="Target options")

self._target_group.add_argument(*args, **kwargs)

def add_logging_group(self):
Expand Down Expand Up @@ -147,7 +166,14 @@ def soc_argdict(self):
======
soc_core arguments dict
"""
return soc_core.soc_core_argdict(self._args) # FIXME: Rename to soc_argdict in the future.
soc_arg = soc_core.soc_core_argdict(self._args) # FIXME: Rename to soc_argdict in the future.

# Work around for backward compatibility
if self._rm_jtagbone:
soc_arg.pop("with_jtagbone")
if self._rm_uartbone:
soc_arg.pop("with_uartbone")
return soc_arg

@property
def toolchain_argdict(self):
Expand Down
1 change: 1 addition & 0 deletions litex/build/quicklogic/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class QuickLogicPlatform(GenericPlatform):
_bitstream_ext = ".bit"
_jtag_support = False

_supported_toolchains = ["f4pga"]

Expand Down
7 changes: 7 additions & 0 deletions litex/build/xilinx/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class XilinxPlatform(GenericPlatform):
"ultrascale+" : ["vivado"],
}

_jtag_support = [
"xc6",
"xc7a", "xc7k", "xc7v", "xc7z",
"xcau", "xcku", "xcvu", "xczu"
]

def __init__(self, *args, toolchain="ise", **kwargs):
GenericPlatform.__init__(self, *args, **kwargs)
self.edifs = set()
Expand Down Expand Up @@ -126,6 +132,7 @@ def get_argdict(cls, toolchain, args):
else:
return dict()


# XilinxSpartan6Platform ---------------------------------------------------------------------------

class XilinxSpartan6Platform(XilinxPlatform):
Expand Down
47 changes: 47 additions & 0 deletions litex/soc/integration/soc_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ def __init__(self, platform, clk_freq,
# Controller parameters
with_ctrl = True,

# JTAGBone
with_jtagbone = False,
jtagbone_chain = 1,

# UARTBone
with_uartbone = False,

# Others
**kwargs):

Expand Down Expand Up @@ -174,6 +181,31 @@ def __init__(self, platform, clk_freq,
# Wishbone Slaves.
self.wb_slaves = {}

# Parameters check validity ----------------------------------------------------------------

# Check if jtagbone is supported (SPI only device or no user access).
if with_jtagbone:
if not platform.jtag_support:
self.logger.error("{} {} with {} FPGA".format(
colorer("JTAGBone isn't supported for platform", color="red"),
platform.name, platform.device))
raise SoCError()
if with_uart:
# crossover+uartbone is kept as backward compatibility
if uart_name == "crossover+uartbone":
self.logger.warning("{} UART: is deprecated {}".format(
colorer(uart_name, color="yellow"),
colorer("please use --uart-name=\"crossover\" --with-uartbone", color="red")))
time.sleep(2)
# Already configured.
self._uartbone = True
uart_name = "crossover"

# JTAGBone and jtag_uart can't be used at the same time.
assert not (with_jtagbone and uart_name == "jtag_uart")
# UARTBone and serial can't be used at the same time.
assert not (with_uartbone and uart_name == "serial")

# Modules instances ------------------------------------------------------------------------

# Add SoCController
Expand Down Expand Up @@ -220,10 +252,18 @@ def __init__(self, platform, clk_freq,
if ident != "":
self.add_identifier("identifier", identifier=ident, with_build_time=ident_version)

# Add UARTBone
if with_uartbone:
self.add_uartbone(baudrate=uart_baudrate)

# Add UART
if with_uart:
self.add_uart(name="uart", uart_name=uart_name, baudrate=uart_baudrate, fifo_depth=uart_fifo_depth)

# Add JTAGBone
if with_jtagbone:
self.add_jtagbone(chain=jtagbone_chain)

# Add Timer
if with_timer:
self.add_timer(name="timer0")
Expand Down Expand Up @@ -294,6 +334,13 @@ def soc_core_args(parser):
soc_group.add_argument("--uart-baudrate", default=115200, type=auto_int, help="UART baudrate.")
soc_group.add_argument("--uart-fifo-depth", default=16, type=auto_int, help="UART FIFO depth.")

# UARTBone parameters
soc_group.add_argument("--with-uartbone", action="store_true", help="Enable UARTbone.")

# JTAGBone parameters
soc_group.add_argument("--with-jtagbone", action="store_true", help="Enable Jtagbone support.")
soc_group.add_argument("--jtagbone-chain", default=1, type=int, help="Jtagbone chain index.")

# Timer parameters
soc_group.add_argument("--no-timer", action="store_true", help="Disable Timer.")
soc_group.add_argument("--timer-uptime", action="store_true", help="Add an uptime capability to Timer.")
Expand Down

0 comments on commit ad98c7c

Please sign in to comment.