diff --git a/litex/build/generic_programmer.py b/litex/build/generic_programmer.py index 394440300..2927d8298 100644 --- a/litex/build/generic_programmer.py +++ b/litex/build/generic_programmer.py @@ -20,7 +20,10 @@ class GenericProgrammer: self.flash_proxy_repos = [ "https://github.com/quartiq/bscan_spi_bitstreams/raw/master/", ] - self.flash_proxy_local = "flash_proxies" + self.config_repos = [ + "https://raw.githubusercontent.com/litex-hub/litex-boards/master/litex_boards/prog/", + ] + self.prog_local = "prog" def set_flash_proxy_dir(self, flash_proxy_dir): if flash_proxy_dir is not None: @@ -34,14 +37,14 @@ class GenericProgrammer: if os.path.exists(fullname): return fullname # Search in local flash_proxy directory - fullname = tools.cygpath(os.path.join(self.flash_proxy_local, self.flash_proxy_basename)) + fullname = tools.cygpath(os.path.join(self.prog_local, self.flash_proxy_basename)) if os.path.exists(fullname): return fullname # Search in repositories and download it import requests - os.makedirs(self.flash_proxy_local, exist_ok=True) + os.makedirs(self.prog_local, exist_ok=True) for d in self.flash_proxy_repos: - fullname = tools.cygpath(os.path.join(self.flash_proxy_local, self.flash_proxy_basename)) + fullname = tools.cygpath(os.path.join(self.prog_local, self.flash_proxy_basename)) try: r = requests.get(d + self.flash_proxy_basename) with open(fullname, "wb") as f: @@ -51,6 +54,29 @@ class GenericProgrammer: pass raise OSError("Failed to find flash proxy bitstream") + def find_config(self): + # Search in local directory + fullname = tools.cygpath(self.config) + if os.path.exists(fullname): + return self.config + # Search in local config directory + fullname = tools.cygpath(os.path.join(self.prog_local, self.config)) + if os.path.exists(fullname): + return fullname + # Search in repositories and download it + import requests + os.makedirs(self.prog_local, exist_ok=True) + for d in self.config_repos: + fullname = tools.cygpath(os.path.join(self.prog_local, self.config)) + try: + r = requests.get(d + self.config) + with open(fullname, "wb") as f: + f.write(r.content) + return fullname + except: + pass + raise OSError("Failed to find config file") + # Must be overloaded by specific programmer def load_bitstream(self, bitstream_file): raise NotImplementedError diff --git a/litex/build/openocd.py b/litex/build/openocd.py index c149ca2cc..d3680d609 100644 --- a/litex/build/openocd.py +++ b/litex/build/openocd.py @@ -17,14 +17,16 @@ class OpenOCD(GenericProgrammer): self.config = config def load_bitstream(self, bitstream): + config = self.find_config() script = "; ".join([ "init", "pld load 0 {{{}}}".format(bitstream), "exit", ]) - subprocess.call(["openocd", "-f", self.config, "-c", script]) + subprocess.call(["openocd", "-f", config, "-c", script]) def flash(self, address, data, set_qe=False): + config = self.find_config() flash_proxy = self.find_flash_proxy() script = "; ".join([ "init", @@ -34,7 +36,7 @@ class OpenOCD(GenericProgrammer): "fpga_program", "exit" ]) - subprocess.call(["openocd", "-f", self.config, "-c", script]) + subprocess.call(["openocd", "-f", config, "-c", script]) def stream(self, port=20000):