From 351551a041f737b7b0ac08132a5b356fa8be468b Mon Sep 17 00:00:00 2001 From: Ilya Epifanov Date: Sat, 28 Mar 2020 11:20:30 +0100 Subject: [PATCH] Added openocd jtagspi programmer, to be used with ECP5-EVN board --- litex/build/lattice/programmer.py | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/litex/build/lattice/programmer.py b/litex/build/lattice/programmer.py index c8cae794..addc51dc 100644 --- a/litex/build/lattice/programmer.py +++ b/litex/build/lattice/programmer.py @@ -22,6 +22,43 @@ class LatticeProgrammer(GenericProgrammer): tools.write_to_file(xcf_file, xcf_content) subprocess.call(["pgrcmd", "-infile", xcf_file]) +# OpenOCDJTAGProgrammer -------------------------------------------------------------------------------- + +class OpenOCDJTAGProgrammer(GenericProgrammer): + def __init__(self, openocd_config, flash_proxy_basename=None): + GenericProgrammer.__init__(self, flash_proxy_basename=flash_proxy_basename) + self.openocd_config = openocd_config + + def load_bitstream(self, bitstream_file): + svf_file = bitstream_file.replace(".bit", ".svf") + + subprocess.call(["openocd", "-f", self.openocd_config , "-c", f"transport select jtag; init; svf \"{svf_file}\"; exit"]) + + def flash(self, address, data, erase=False, verify=True): + if self.flash_proxy_basename is None: + flash_proxy = None + else: + flash_proxy = self.find_flash_proxy() + + if erase: + erase = "erase" + else: + erase = "" + + script = "; ".join([ + "transport select jtag", + "target create ecp5.spi0.proxy testee -chain-position ecp5.tap", + "flash bank spi0 jtagspi 0 0 0 0 ecp5.spi0.proxy 0x32", + "init", + f"svf \"{flash_proxy}\"" if flash_proxy is not None else "", + "reset halt", + "flash probe spi0", + f"flash write_image {erase} \"{data}\" 0x{address:x}", + f"flash verify_bank spi0 \"{data}\" 0x{address:x}" if verify else "", + "exit" + ]) + subprocess.call(["openocd", "-f", self.openocd_config, "-c", script]) + # IceStormProgrammer ------------------------------------------------------------------------------- class IceStormProgrammer(GenericProgrammer): -- 2.30.2