From 88dbff46f4f1a6b487384e97ee46608d84019a68 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 30 Oct 2019 21:24:51 +0800 Subject: [PATCH] add netboot tool --- artiq/frontend/artiq_netboot.py | 38 +++++++++++++++++++++++++++++++++ setup.py | 1 + 2 files changed, 39 insertions(+) create mode 100755 artiq/frontend/artiq_netboot.py diff --git a/artiq/frontend/artiq_netboot.py b/artiq/frontend/artiq_netboot.py new file mode 100755 index 000000000..ef36ad743 --- /dev/null +++ b/artiq/frontend/artiq_netboot.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +import argparse +import socket +import struct +import os +import time + +def main(): + parser = argparse.ArgumentParser(description="ARTIQ netboot tool") + parser.add_argument("hostname", metavar="HOSTNAME", + help="hostname of the target board") + parser.add_argument("-f", "--firmware", nargs=1, + help="firmware to load") + parser.add_argument("-b", "--boot", action="store_true", + help="boot the device") + args = parser.parse_args() + + sock = socket.create_connection((args.hostname, 4269)) + try: + if args.firmware is not None: + with open(args.firmware[0], "rb") as input_file: + sock.sendall(b"F") + sock.sendall(struct.pack(">I", os.fstat(input_file.fileno()).st_size)) + while True: + data = input_file.read(4096) + if not data: + break + sock.sendall(data) + sock.sendall(b"OK") + if args.boot: + sock.sendall(b"B") + finally: + sock.close() + + +if __name__ == "__main__": + main() diff --git a/setup.py b/setup.py index 7137bce4f..da895fa89 100755 --- a/setup.py +++ b/setup.py @@ -25,6 +25,7 @@ console_scripts = [ "artiq_coremgmt = artiq.frontend.artiq_coremgmt:main", "artiq_ctlmgr = artiq.frontend.artiq_ctlmgr:main", "artiq_ddb_template = artiq.frontend.artiq_ddb_template:main", + "artiq_netboot = artiq.frontend.artiq_netboot:main", "artiq_devtool = artiq.frontend.artiq_devtool:main", "artiq_influxdb = artiq.frontend.artiq_influxdb:main", "artiq_influxdb_schedule = artiq.frontend.artiq_influxdb_schedule:main",