Added openocd jtagspi programmer, to be used with ECP5-EVN board
authorIlya Epifanov <elijah.epifanov@gmail.com>
Sat, 28 Mar 2020 10:20:30 +0000 (11:20 +0100)
committerIlya Epifanov <elijah.epifanov@gmail.com>
Sat, 28 Mar 2020 10:20:30 +0000 (11:20 +0100)
litex/build/lattice/programmer.py

index c8cae7944e048643944f52b73e55c96d97a9d49d..addc51dcffe06d54f006012a6f1bd88700919e56 100644 (file)
@@ -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):