Skip to content
This repository was archived by the owner on Jan 18, 2026. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion artiq/coredevice/comm_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ def close(self):
# Protocol elements

def _write(self, data):
self.socket.sendall(data)
total_sent = 0
while total_sent < len(data):
sent = self.socket.send(data[total_sent:])
total_sent += sent
logger.debug("sent %d bytes", sent)

def _write_header(self, ty):
self.open()
Expand Down Expand Up @@ -206,6 +210,7 @@ def flash(self, bin_paths):

with io.BytesIO() as image_buf:
for filename in bin_paths:
logger.debug("writing %s to byte buffer", filename)
with open(filename, "rb") as fi:
bin_ = fi.read()
if (len(bin_paths) > 1):
Expand All @@ -216,6 +221,7 @@ def flash(self, bin_paths):
crc = binascii.crc32(image_buf.getvalue())
image_buf.write(struct.pack(self.endian + "I", crc))

logger.debug("sending byte buffer to core device")
self._write_bytes(image_buf.getvalue())

self._read_expect(Reply.RebootImminent)
11 changes: 10 additions & 1 deletion artiq/frontend/artiq_coremgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import struct
import tempfile
import atexit
import logging

from sipyco import common_args

Expand All @@ -14,6 +15,8 @@
from artiq.coredevice.comm_mgmt import CommMgmt
from artiq.frontend.flash_tools import bit2bin, fetch_bin

logger = logging.getLogger(__name__)


def get_argparser():
parser = argparse.ArgumentParser(description="ARTIQ core device "
Expand Down Expand Up @@ -147,7 +150,7 @@ def main():
if args.action == "read":
value = mgmt.config_read(args.key)
if not value:
print("Key {} does not exist".format(args.key))
logger.error("Key {} does not exist".format(args.key))
else:
print(value)
if args.action == "write":
Expand Down Expand Up @@ -175,6 +178,8 @@ def main():
],
}

logger.info("Retrieving binaries...")

for bin_list in bin_dict.values():
try:
bins = []
Expand All @@ -192,9 +197,13 @@ def main():
raise ValueError("both risc-v and zynq binaries were found, "
"please clean up your build directory. ")

logger.info("Flashing core device...")

bins = retrieved_bins[0]
mgmt.flash(bins)

logger.info("Rebooting core device.")

if args.tool == "reboot":
mgmt.reboot()

Expand Down
9 changes: 6 additions & 3 deletions artiq/frontend/flash_tools.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import atexit
import logging
import os
import tempfile
import struct

logger = logging.getLogger(__name__)


def artifact_path(this_binary_dir, *path_filename, srcbuild=False):
if srcbuild:
Expand Down Expand Up @@ -99,14 +102,14 @@ def bit2bin(bit, bin, flip=False):
"c": "Date",
"d": "Time"
}[key]
print("{}: {}".format(name, d))
logger.debug("{}: {}".format(name, d))
elif key == "e":
l, = struct.unpack(">I", bit.read(4))
print("Bitstream payload length: {:#x}".format(l))
logger.debug("Bitstream payload length: {:#x}".format(l))
d = bit.read(l)
if flip:
d = flip32(d)
bin.write(d)
else:
d = bit.read(*struct.unpack(">H", bit.read(2)))
print("Unexpected key: {}: {}".format(key, d))
logger.error("Unexpected key: {}: {}".format(key, d))