forked from M-Labs/artiq
1
0
Fork 0

artiq_flash: make the proxy action unnecessary.

This commit is contained in:
whitequark 2018-01-27 15:43:27 +00:00
parent d58393a1e5
commit eed2db3a98
1 changed files with 50 additions and 46 deletions

View File

@ -8,6 +8,7 @@ import shutil
import re import re
import atexit import atexit
from functools import partial from functools import partial
from collections import defaultdict
from artiq import __artiq_dir__ as artiq_dir from artiq import __artiq_dir__ as artiq_dir
from artiq.tools import verbosity_args, init_logger from artiq.tools import verbosity_args, init_logger
@ -62,7 +63,7 @@ Prerequisites:
parser.add_argument("--srcbuild", help="look for bitstream, bootloader and firmware in this " parser.add_argument("--srcbuild", help="look for bitstream, bootloader and firmware in this "
"ARTIQ source build tree") "ARTIQ source build tree")
parser.add_argument("action", metavar="ACTION", nargs="*", parser.add_argument("action", metavar="ACTION", nargs="*",
default="proxy gateware bootloader firmware start".split(), default="gateware bootloader firmware start".split(),
help="actions to perform, default: %(default)s") help="actions to perform, default: %(default)s")
return parser return parser
@ -104,6 +105,7 @@ class Programmer:
self._client = client self._client = client
self._board_script = [] self._board_script = []
self._preinit_script = preinit_script self._preinit_script = preinit_script
self._loaded = defaultdict(lambda: None)
self._script = [] self._script = []
def _transfer_script(self, script): def _transfer_script(self, script):
@ -125,6 +127,12 @@ class Programmer:
tap=tap, name=name, ir=0x02 + index) tap=tap, name=name, ir=0x02 + index)
def load(self, bitfile, pld): def load(self, bitfile, pld):
os.stat(bitfile) # check for existence
if self._loaded[pld] == bitfile:
return
self._loaded[pld] = bitfile
bitfile = self._client.transfer_file(bitfile) bitfile = self._client.transfer_file(bitfile)
add_commands(self._script, add_commands(self._script,
"pld load {pld} {filename}", "pld load {pld} {filename}",
@ -134,6 +142,8 @@ class Programmer:
raise NotImplementedError raise NotImplementedError
def flash_binary(self, bankname, address, filename): def flash_binary(self, bankname, address, filename):
self.load_proxy()
size = os.path.getsize(filename) size = os.path.getsize(filename)
filename = self._client.transfer_file(filename) filename = self._client.transfer_file(filename)
add_commands(self._script, add_commands(self._script,
@ -269,10 +279,6 @@ def main():
bin_name += "-" + variant bin_name += "-" + variant
bin_dir = os.path.join(artiq_dir, "binaries", bin_name) bin_dir = os.path.join(artiq_dir, "binaries", bin_name)
if args.srcbuild is None and not os.path.exists(bin_dir) and args.action != ["start"]:
raise SystemExit("Binaries directory '{}' does not exist"
.format(bin_dir))
if args.host is None: if args.host is None:
client = LocalClient() client = LocalClient()
else: else:
@ -287,13 +293,9 @@ def main():
else: else:
return os.path.join(args.srcbuild, *path_filename) return os.path.join(args.srcbuild, *path_filename)
for action in args.action:
if action == "proxy":
try: try:
programmer.load_proxy() for action in args.action:
except FileNotFoundError as e: if action == "gateware":
raise SystemExit(e)
elif action == "gateware":
gateware_bin = artifact_path("gateware", "top.bin") gateware_bin = artifact_path("gateware", "top.bin")
if not os.access(gateware_bin, os.R_OK): if not os.access(gateware_bin, os.R_OK):
bin_handle, gateware_bin = tempfile.mkstemp() bin_handle, gateware_bin = tempfile.mkstemp()
@ -331,6 +333,8 @@ def main():
programmer.start() programmer.start()
else: else:
raise ValueError("invalid action", action) raise ValueError("invalid action", action)
except FileNotFoundError as e:
raise SystemExit(e)
if args.dry_run: if args.dry_run:
print("\n".join(programmer.script())) print("\n".join(programmer.script()))