mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-26 11:48:27 +08:00
frontend: make coremgmt flash zynq-compatible
This commit is contained in:
parent
2b73d5a4c6
commit
5c21649d10
@ -208,7 +208,8 @@ class CommMgmt:
|
||||
for filename in bin_paths:
|
||||
with open(filename, "rb") as fi:
|
||||
bin_ = fi.read()
|
||||
image_buf.write(struct.pack(self.endian + "I", len(bin_)))
|
||||
if (len(bin_paths) > 1):
|
||||
image_buf.write(struct.pack(self.endian + "I", len(bin_)))
|
||||
image_buf.write(bin_)
|
||||
|
||||
crc = binascii.crc32(image_buf.getvalue())
|
||||
|
@ -94,6 +94,9 @@ def get_argparser():
|
||||
t_flash = tools.add_parser("flash",
|
||||
help="flash the running system")
|
||||
|
||||
p_zynq = t_flash.add_argument("-z", "--zynq", default=False,
|
||||
help="target zynq device", action="store_true")
|
||||
|
||||
p_directory = t_flash.add_argument("directory", metavar="DIRECTORY", type=str,
|
||||
help="directory that contains the binaries")
|
||||
|
||||
@ -160,40 +163,45 @@ def main():
|
||||
mgmt.config_erase()
|
||||
|
||||
if args.tool == "flash":
|
||||
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
|
||||
*_, filename = path_filename
|
||||
return os.path.join(this_binary_dir, filename)
|
||||
if args.zynq:
|
||||
boot = os.path.join(args.directory, "boot.bin")
|
||||
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
|
||||
*_, 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:
|
||||
bit2bin(bit_file, bin_file)
|
||||
atexit.register(lambda: os.unlink(bin_filename))
|
||||
return bin_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:
|
||||
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")
|
||||
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)))
|
||||
firmware = firmwares[0]
|
||||
firmwares = []
|
||||
for firmware in "satman", "runtime":
|
||||
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)))
|
||||
firmware = firmwares[0]
|
||||
|
||||
bins = [ gateware, bootloader, firmware ]
|
||||
|
||||
bins = [ gateware, bootloader, firmware ]
|
||||
mgmt.flash(bins)
|
||||
|
||||
if args.tool == "reboot":
|
||||
|
Loading…
Reference in New Issue
Block a user