build/generic_programmer: add automatic search/download of flash_proxy in repositories if not available locally.
This commit is contained in:
parent
a298a9e568
commit
5e149ceda2
|
@ -1,8 +1,11 @@
|
|||
# This file is Copyright (c) 2015 Sebastien Bourdeauducq <sb@m-labs.hk>
|
||||
# This file is Copyright (c) 2020 Florent Kermarrec <florent@enjoy-digital.fr>
|
||||
# License: BSD
|
||||
|
||||
|
||||
import os, sys
|
||||
import os
|
||||
import sys
|
||||
import requests
|
||||
from litex.build import tools
|
||||
|
||||
|
||||
|
@ -12,25 +15,46 @@ class GenericProgrammer:
|
|||
self.flash_proxy_dirs = [
|
||||
"~/.migen", "/usr/local/share/migen", "/usr/share/migen",
|
||||
"~/.mlabs", "/usr/local/share/mlabs", "/usr/share/mlabs",
|
||||
"~/.litex", "/usr/local/share/litex", "/usr/share/litex"]
|
||||
"~/.litex", "/usr/local/share/litex", "/usr/share/litex"
|
||||
]
|
||||
self.flash_proxy_repos = [
|
||||
"https://github.com/quartiq/bscan_spi_bitstreams/raw/master/",
|
||||
]
|
||||
self.flash_proxy_local = "flash_proxies"
|
||||
|
||||
def set_flash_proxy_dir(self, flash_proxy_dir):
|
||||
if flash_proxy_dir is not None:
|
||||
self.flash_proxy_dirs = [flash_proxy_dir]
|
||||
|
||||
def find_flash_proxy(self):
|
||||
# Search in installed flash_proxy_directories
|
||||
for d in self.flash_proxy_dirs:
|
||||
fulldir = os.path.abspath(os.path.expanduser(d))
|
||||
fullname = tools.cygpath(os.path.join(fulldir, self.flash_proxy_basename))
|
||||
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))
|
||||
if os.path.exists(fullname):
|
||||
return fullname
|
||||
# Search in repositories and download it
|
||||
os.makedirs(self.flash_proxy_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))
|
||||
try:
|
||||
r = requests.get(d + self.flash_proxy_basename)
|
||||
with open(fullname, "wb") as f:
|
||||
f.write(r.content)
|
||||
return fullname
|
||||
except:
|
||||
pass
|
||||
raise OSError("Failed to find flash proxy bitstream")
|
||||
|
||||
# must be overloaded by specific programmer
|
||||
# Must be overloaded by specific programmer
|
||||
def load_bitstream(self, bitstream_file):
|
||||
raise NotImplementedError
|
||||
|
||||
# must be overloaded by specific programmer
|
||||
# Must be overloaded by specific programmer
|
||||
def flash(self, address, data_file):
|
||||
raise NotImplementedError
|
||||
|
||||
|
|
Loading…
Reference in New Issue