mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-26 19:58:25 +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:
|
for filename in bin_paths:
|
||||||
with open(filename, "rb") as fi:
|
with open(filename, "rb") as fi:
|
||||||
bin_ = fi.read()
|
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_)
|
image_buf.write(bin_)
|
||||||
|
|
||||||
crc = binascii.crc32(image_buf.getvalue())
|
crc = binascii.crc32(image_buf.getvalue())
|
||||||
|
@ -94,6 +94,9 @@ def get_argparser():
|
|||||||
t_flash = tools.add_parser("flash",
|
t_flash = tools.add_parser("flash",
|
||||||
help="flash the running system")
|
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,
|
p_directory = t_flash.add_argument("directory", metavar="DIRECTORY", type=str,
|
||||||
help="directory that contains the binaries")
|
help="directory that contains the binaries")
|
||||||
|
|
||||||
@ -160,40 +163,45 @@ def main():
|
|||||||
mgmt.config_erase()
|
mgmt.config_erase()
|
||||||
|
|
||||||
if args.tool == "flash":
|
if args.tool == "flash":
|
||||||
def artifact_path(this_binary_dir, *path_filename):
|
if args.zynq:
|
||||||
if args.srcbuild:
|
boot = os.path.join(args.directory, "boot.bin")
|
||||||
# source tree - use path elements to locate file
|
bins = [ boot ]
|
||||||
return os.path.join(this_binary_dir, *path_filename)
|
else:
|
||||||
else:
|
def artifact_path(this_binary_dir, *path_filename):
|
||||||
# flat tree - all files in the same directory, discard path elements
|
if args.srcbuild:
|
||||||
*_, filename = path_filename
|
# source tree - use path elements to locate file
|
||||||
return os.path.join(this_binary_dir, filename)
|
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):
|
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_", suffix="_" + os.path.basename(bit_filename))
|
||||||
with open(bit_filename, "rb") as bit_file, open(bin_handle, "wb") as bin_file:
|
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(args.directory, "gateware", "top.bit"))
|
artifact_path(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, please clean up your build directory. "
|
||||||
"Found firmware files: {}".format(" ".join(firmwares)))
|
"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)
|
||||||
|
|
||||||
if args.tool == "reboot":
|
if args.tool == "reboot":
|
||||||
|
Loading…
Reference in New Issue
Block a user