mirror of https://github.com/m-labs/artiq.git
flake8
This commit is contained in:
parent
2e9622b9d6
commit
cc40313501
|
@ -209,7 +209,8 @@ class CommMgmt:
|
||||||
with open(filename, "rb") as fi:
|
with open(filename, "rb") as fi:
|
||||||
bin_ = fi.read()
|
bin_ = fi.read()
|
||||||
if (len(bin_paths) > 1):
|
if (len(bin_paths) > 1):
|
||||||
image_buf.write(struct.pack(self.endian + "I", len(bin_)))
|
image_buf.write(
|
||||||
|
struct.pack(self.endian + "I", len(bin_)))
|
||||||
image_buf.write(bin_)
|
image_buf.write(bin_)
|
||||||
|
|
||||||
crc = binascii.crc32(image_buf.getvalue())
|
crc = binascii.crc32(image_buf.getvalue())
|
||||||
|
|
|
@ -13,7 +13,6 @@ from artiq.master.databases import DeviceDB
|
||||||
from artiq.coredevice.comm_kernel import CommKernel
|
from artiq.coredevice.comm_kernel import CommKernel
|
||||||
from artiq.coredevice.comm_mgmt import CommMgmt
|
from artiq.coredevice.comm_mgmt import CommMgmt
|
||||||
from artiq.frontend.bit2bin import bit2bin
|
from artiq.frontend.bit2bin import bit2bin
|
||||||
from misoc.tools.mkmscimg import insert_crc
|
|
||||||
|
|
||||||
|
|
||||||
def get_argparser():
|
def get_argparser():
|
||||||
|
@ -95,14 +94,18 @@ def get_argparser():
|
||||||
help="flash the running system")
|
help="flash the running system")
|
||||||
|
|
||||||
p_zynq = t_flash.add_argument("-z", "--zynq", default=False,
|
p_zynq = t_flash.add_argument("-z", "--zynq", default=False,
|
||||||
help="target zynq device", action="store_true")
|
help="target zynq device",
|
||||||
|
action="store_true")
|
||||||
|
|
||||||
p_directory = t_flash.add_argument("directory", metavar="DIRECTORY", type=str,
|
p_directory = t_flash.add_argument("directory",
|
||||||
help="directory that contains the binaries")
|
metavar="DIRECTORY", type=str,
|
||||||
|
help="directory that contains the "
|
||||||
|
"binaries")
|
||||||
|
|
||||||
p_srcbuild = t_flash.add_argument("--srcbuild",
|
p_srcbuild = t_flash.add_argument("--srcbuild",
|
||||||
help="board binaries directory is laid out as a source build tree",
|
help="board binaries directory is laid "
|
||||||
default=False, action="store_true")
|
"out as a source build tree",
|
||||||
|
default=False, action="store_true")
|
||||||
|
|
||||||
# misc debug
|
# misc debug
|
||||||
t_debug = tools.add_parser("debug",
|
t_debug = tools.add_parser("debug",
|
||||||
|
@ -116,8 +119,9 @@ def get_argparser():
|
||||||
|
|
||||||
# manage target
|
# manage target
|
||||||
p_drtio_dest = parser.add_argument("-s", "--satellite", default=0,
|
p_drtio_dest = parser.add_argument("-s", "--satellite", default=0,
|
||||||
metavar="DRTIO ID", type=int,
|
metavar="DRTIO ID", type=int,
|
||||||
help="specify DRTIO destination that receives this command")
|
help="specify DRTIO destination that "
|
||||||
|
"receives this command")
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
@ -161,46 +165,53 @@ def main():
|
||||||
mgmt.config_remove(key)
|
mgmt.config_remove(key)
|
||||||
if args.action == "erase":
|
if args.action == "erase":
|
||||||
mgmt.config_erase()
|
mgmt.config_erase()
|
||||||
|
|
||||||
if args.tool == "flash":
|
if args.tool == "flash":
|
||||||
if args.zynq:
|
if args.zynq:
|
||||||
boot = os.path.join(args.directory, "boot.bin")
|
boot = os.path.join(args.directory, "boot.bin")
|
||||||
bins = [ boot ]
|
bins = [boot]
|
||||||
else:
|
else:
|
||||||
def artifact_path(this_binary_dir, *path_filename):
|
def artifact_path(this_binary_dir, *path_filename):
|
||||||
if args.srcbuild:
|
if args.srcbuild:
|
||||||
# source tree - use path elements to locate file
|
# source tree - use path elements to locate file
|
||||||
return os.path.join(this_binary_dir, *path_filename)
|
return os.path.join(this_binary_dir, *path_filename)
|
||||||
else:
|
else:
|
||||||
# flat tree - all files in the same directory, discard path elements
|
# flat tree
|
||||||
|
# all files in the same directory, discard path elements
|
||||||
*_, filename = path_filename
|
*_, filename = path_filename
|
||||||
return os.path.join(this_binary_dir, filename)
|
return os.path.join(this_binary_dir, filename)
|
||||||
|
|
||||||
def convert_gateware(bit_filename):
|
def convert_gateware(bit_filename):
|
||||||
bin_handle, bin_filename = tempfile.mkstemp(
|
bin_handle, bin_filename = tempfile.mkstemp(
|
||||||
prefix="artiq_", suffix="_" + os.path.basename(bit_filename))
|
prefix="artiq_",
|
||||||
with open(bit_filename, "rb") as bit_file, open(bin_handle, "wb") as bin_file:
|
suffix="_" + os.path.basename(bit_filename))
|
||||||
|
with open(bit_filename, "rb") as bit_file, \
|
||||||
|
open(bin_handle, "wb") as bin_file:
|
||||||
bit2bin(bit_file, bin_file)
|
bit2bin(bit_file, bin_file)
|
||||||
atexit.register(lambda: os.unlink(bin_filename))
|
atexit.register(lambda: os.unlink(bin_filename))
|
||||||
return bin_filename
|
return bin_filename
|
||||||
|
|
||||||
gateware = convert_gateware(
|
gateware = convert_gateware(artifact_path(
|
||||||
artifact_path(args.directory, "gateware", "top.bit"))
|
args.directory, "gateware", "top.bit"))
|
||||||
bootloader = artifact_path(args.directory, "software", "bootloader", "bootloader.bin")
|
bootloader = artifact_path(
|
||||||
|
args.directory, "software", "bootloader", "bootloader.bin")
|
||||||
|
|
||||||
firmwares = []
|
firmwares = []
|
||||||
for firmware in "satman", "runtime":
|
for firmware in "satman", "runtime":
|
||||||
filename = artifact_path(args.directory, "software", firmware, firmware + ".fbi")
|
filename = artifact_path(
|
||||||
|
args.directory, "software", firmware, firmware + ".fbi")
|
||||||
if os.path.exists(filename):
|
if os.path.exists(filename):
|
||||||
firmwares.append(filename)
|
firmwares.append(filename)
|
||||||
if not firmwares:
|
if not firmwares:
|
||||||
raise FileNotFoundError("no firmware found")
|
raise FileNotFoundError("no firmware found")
|
||||||
if len(firmwares) > 1:
|
if len(firmwares) > 1:
|
||||||
raise ValueError("more than one firmware file, please clean up your build directory. "
|
raise ValueError("more than one firmware file, "
|
||||||
"Found firmware files: {}".format(" ".join(firmwares)))
|
"please clean up your build directory. "
|
||||||
|
"Found firmware files: {}".format(
|
||||||
|
" ".join(firmwares)))
|
||||||
firmware = firmwares[0]
|
firmware = firmwares[0]
|
||||||
|
|
||||||
bins = [ gateware, bootloader, firmware ]
|
bins = [gateware, bootloader, firmware]
|
||||||
|
|
||||||
mgmt.flash(bins)
|
mgmt.flash(bins)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue