From 5e149ceda2e60ffce2740f8ef60f66428bbba449 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Wed, 15 Apr 2020 08:59:03 +0200 Subject: [PATCH] build/generic_programmer: add automatic search/download of flash_proxy in repositories if not available locally. --- litex/build/generic_programmer.py | 34 ++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/litex/build/generic_programmer.py b/litex/build/generic_programmer.py index ac22c74f..2fb34444 100644 --- a/litex/build/generic_programmer.py +++ b/litex/build/generic_programmer.py @@ -1,8 +1,11 @@ # This file is Copyright (c) 2015 Sebastien Bourdeauducq +# This file is Copyright (c) 2020 Florent Kermarrec # 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)) + 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 -- 2.30.2