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,50 +293,48 @@ 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: try:
if action == "proxy": for action in args.action:
try: if action == "gateware":
programmer.load_proxy() gateware_bin = artifact_path("gateware", "top.bin")
except FileNotFoundError as e: if not os.access(gateware_bin, os.R_OK):
raise SystemExit(e) bin_handle, gateware_bin = tempfile.mkstemp()
elif action == "gateware": gateware_bit = artifact_path("gateware", "top.bit")
gateware_bin = artifact_path("gateware", "top.bin") with open(gateware_bit, "rb") as bit_file, open(bin_handle, "wb") as bin_file:
if not os.access(gateware_bin, os.R_OK): bit2bin(bit_file, bin_file)
bin_handle, gateware_bin = tempfile.mkstemp() atexit.register(lambda: os.unlink(gateware_bin))
gateware_bit = artifact_path("gateware", "top.bit")
with open(gateware_bit, "rb") as bit_file, open(bin_handle, "wb") as bin_file:
bit2bin(bit_file, bin_file)
atexit.register(lambda: os.unlink(gateware_bin))
programmer.flash_binary(*config["gateware"], gateware_bin) programmer.flash_binary(*config["gateware"], gateware_bin)
elif action == "bootloader": elif action == "bootloader":
bootloader_bin = artifact_path("software", "bootloader", "bootloader.bin") bootloader_bin = artifact_path("software", "bootloader", "bootloader.bin")
programmer.flash_binary(*config["bootloader"], bootloader_bin) programmer.flash_binary(*config["bootloader"], bootloader_bin)
elif action == "storage": elif action == "storage":
storage_img = args.storage storage_img = args.storage
programmer.flash_binary(*config["storage"], storage_img) programmer.flash_binary(*config["storage"], storage_img)
elif action == "firmware": elif action == "firmware":
if variant == "satellite": if variant == "satellite":
firmware = "satman" firmware = "satman"
else: else:
firmware = "runtime" firmware = "runtime"
firmware_fbi = artifact_path("software", firmware, firmware + ".fbi") firmware_fbi = artifact_path("software", firmware, firmware + ".fbi")
programmer.flash_binary(*config["firmware"], firmware_fbi) programmer.flash_binary(*config["firmware"], firmware_fbi)
elif action == "load": elif action == "load":
if args.target == "sayma_rtm": if args.target == "sayma_rtm":
gateware_bit = artifact_path("top.bit") gateware_bit = artifact_path("top.bit")
programmer.load(gateware_bit, 0) programmer.load(gateware_bit, 0)
elif args.target == "sayma_amc": elif args.target == "sayma_amc":
gateware_bit = artifact_path("gateware", "top.bit") gateware_bit = artifact_path("gateware", "top.bit")
programmer.load(gateware_bit, 1) programmer.load(gateware_bit, 1)
else:
gateware_bit = artifact_path("gateware", "top.bit")
programmer.load(gateware_bit, 0)
elif action == "start":
programmer.start()
else: else:
gateware_bit = artifact_path("gateware", "top.bit") raise ValueError("invalid action", action)
programmer.load(gateware_bit, 0) except FileNotFoundError as e:
elif action == "start": raise SystemExit(e)
programmer.start()
else:
raise ValueError("invalid action", action)
if args.dry_run: if args.dry_run:
print("\n".join(programmer.script())) print("\n".join(programmer.script()))