diff --git a/litex/build/lattice/programmer.py b/litex/build/lattice/programmer.py index c8cae7944..addc51dcf 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):