2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-26 11:48:27 +08:00
This commit is contained in:
occheung 2024-09-20 17:38:14 +08:00
parent 2e9622b9d6
commit cc40313501
2 changed files with 33 additions and 21 deletions

View File

@ -209,7 +209,8 @@ class CommMgmt:
with open(filename, "rb") as fi:
bin_ = fi.read()
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_)
crc = binascii.crc32(image_buf.getvalue())

View File

@ -13,7 +13,6 @@ from artiq.master.databases import DeviceDB
from artiq.coredevice.comm_kernel import CommKernel
from artiq.coredevice.comm_mgmt import CommMgmt
from artiq.frontend.bit2bin import bit2bin
from misoc.tools.mkmscimg import insert_crc
def get_argparser():
@ -95,14 +94,18 @@ def get_argparser():
help="flash the running system")
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,
help="directory that contains the binaries")
p_directory = t_flash.add_argument("directory",
metavar="DIRECTORY", type=str,
help="directory that contains the "
"binaries")
p_srcbuild = t_flash.add_argument("--srcbuild",
help="board binaries directory is laid out as a source build tree",
default=False, action="store_true")
help="board binaries directory is laid "
"out as a source build tree",
default=False, action="store_true")
# misc debug
t_debug = tools.add_parser("debug",
@ -116,8 +119,9 @@ def get_argparser():
# manage target
p_drtio_dest = parser.add_argument("-s", "--satellite", default=0,
metavar="DRTIO ID", type=int,
help="specify DRTIO destination that receives this command")
metavar="DRTIO ID", type=int,
help="specify DRTIO destination that "
"receives this command")
return parser
@ -161,46 +165,53 @@ def main():
mgmt.config_remove(key)
if args.action == "erase":
mgmt.config_erase()
if args.tool == "flash":
if args.zynq:
boot = os.path.join(args.directory, "boot.bin")
bins = [ boot ]
bins = [boot]
else:
def artifact_path(this_binary_dir, *path_filename):
if args.srcbuild:
# source tree - use path elements to locate file
return os.path.join(this_binary_dir, *path_filename)
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
return os.path.join(this_binary_dir, filename)
def convert_gateware(bit_filename):
bin_handle, bin_filename = tempfile.mkstemp(
prefix="artiq_", suffix="_" + os.path.basename(bit_filename))
with open(bit_filename, "rb") as bit_file, open(bin_handle, "wb") as bin_file:
prefix="artiq_",
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)
atexit.register(lambda: os.unlink(bin_filename))
return bin_filename
gateware = convert_gateware(
artifact_path(args.directory, "gateware", "top.bit"))
bootloader = artifact_path(args.directory, "software", "bootloader", "bootloader.bin")
gateware = convert_gateware(artifact_path(
args.directory, "gateware", "top.bit"))
bootloader = artifact_path(
args.directory, "software", "bootloader", "bootloader.bin")
firmwares = []
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):
firmwares.append(filename)
if not firmwares:
raise FileNotFoundError("no firmware found")
if len(firmwares) > 1:
raise ValueError("more than one firmware file, please clean up your build directory. "
"Found firmware files: {}".format(" ".join(firmwares)))
raise ValueError("more than one firmware file, "
"please clean up your build directory. "
"Found firmware files: {}".format(
" ".join(firmwares)))
firmware = firmwares[0]
bins = [ gateware, bootloader, firmware ]
bins = [gateware, bootloader, firmware]
mgmt.flash(bins)