build/openocd: add find_config method to allow using local config file or download it if not available locally.

This commit is contained in:
Florent Kermarrec 2020-05-05 09:56:13 +02:00
parent 9bef218ad6
commit b8f9f83a8f
2 changed files with 34 additions and 6 deletions

View File

@ -20,7 +20,10 @@ class GenericProgrammer:
self.flash_proxy_repos = [ self.flash_proxy_repos = [
"https://github.com/quartiq/bscan_spi_bitstreams/raw/master/", "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): def set_flash_proxy_dir(self, flash_proxy_dir):
if flash_proxy_dir is not None: if flash_proxy_dir is not None:
@ -34,14 +37,14 @@ class GenericProgrammer:
if os.path.exists(fullname): if os.path.exists(fullname):
return fullname return fullname
# Search in local flash_proxy directory # 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): if os.path.exists(fullname):
return fullname return fullname
# Search in repositories and download it # Search in repositories and download it
import requests 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: 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: try:
r = requests.get(d + self.flash_proxy_basename) r = requests.get(d + self.flash_proxy_basename)
with open(fullname, "wb") as f: with open(fullname, "wb") as f:
@ -51,6 +54,29 @@ class GenericProgrammer:
pass pass
raise OSError("Failed to find flash proxy bitstream") 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 # Must be overloaded by specific programmer
def load_bitstream(self, bitstream_file): def load_bitstream(self, bitstream_file):
raise NotImplementedError raise NotImplementedError

View File

@ -17,14 +17,16 @@ class OpenOCD(GenericProgrammer):
self.config = config self.config = config
def load_bitstream(self, bitstream): def load_bitstream(self, bitstream):
config = self.find_config()
script = "; ".join([ script = "; ".join([
"init", "init",
"pld load 0 {{{}}}".format(bitstream), "pld load 0 {{{}}}".format(bitstream),
"exit", "exit",
]) ])
subprocess.call(["openocd", "-f", self.config, "-c", script]) subprocess.call(["openocd", "-f", config, "-c", script])
def flash(self, address, data, set_qe=False): def flash(self, address, data, set_qe=False):
config = self.find_config()
flash_proxy = self.find_flash_proxy() flash_proxy = self.find_flash_proxy()
script = "; ".join([ script = "; ".join([
"init", "init",
@ -34,7 +36,7 @@ class OpenOCD(GenericProgrammer):
"fpga_program", "fpga_program",
"exit" "exit"
]) ])
subprocess.call(["openocd", "-f", self.config, "-c", script]) subprocess.call(["openocd", "-f", config, "-c", script])
def stream(self, port=20000): def stream(self, port=20000):