2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-26 03:38:25 +08:00

artiq_devtool: refactor.

This commit is contained in:
whitequark 2018-01-19 20:34:31 +00:00
parent ebd02c4f43
commit 934bc53cb5

View File

@ -33,6 +33,9 @@ def get_argparser():
help="target to build, one of: " help="target to build, one of: "
"kc705_dds kasli sayma_rtm sayma_amc_standalone " "kc705_dds kasli sayma_rtm sayma_amc_standalone "
"sayma_amc_drtio_master sayma_amc_drtio_satellite") "sayma_amc_drtio_master sayma_amc_drtio_satellite")
parser.add_argument("-g", "--build-gateware",
default=False, action="store_true",
help="build gateware, not just software")
parser.add_argument("-H", "--host", parser.add_argument("-H", "--host",
type=str, default="lab.m-labs.hk", type=str, default="lab.m-labs.hk",
help="SSH host where the development board is located") help="SSH host where the development board is located")
@ -69,12 +72,12 @@ def main():
def build_dir(*path, target=args.target): def build_dir(*path, target=args.target):
return os.path.join("/tmp", target, *path) return os.path.join("/tmp", target, *path)
build_args = [] extra_build_args = []
if args.target == "kc705_dds": if args.target == "kc705_dds":
board_type, firmware = "kc705", "runtime" board_type, firmware = "kc705", "runtime"
elif args.target == "sayma_amc_standalone": elif args.target == "sayma_amc_standalone":
board_type, firmware = "sayma_amc", "runtime" board_type, firmware = "sayma_amc", "runtime"
build_args += ["--rtm-csr-csv", build_dir("sayma_rtm_csr.csv", target="sayma_rtm")] extra_build_args += ["--rtm-csr-csv", build_dir("sayma_rtm_csr.csv", target="sayma_rtm")]
elif args.target == "sayma_amc_drtio_master": elif args.target == "sayma_amc_drtio_master":
board_type, firmware = "sayma_amc", "runtime" board_type, firmware = "sayma_amc", "runtime"
elif args.target == "sayma_amc_drtio_satellite": elif args.target == "sayma_amc_drtio_satellite":
@ -127,7 +130,16 @@ def main():
logger.error("Failed to get lock") logger.error("Failed to get lock")
sys.exit(1) sys.exit(1)
def command(*args, on_failure="Command failed"):
try:
subprocess.check_call(args)
except subprocess.CalledProcessError:
logger.error(on_failure)
sys.exit(1)
def flash(*steps): def flash(*steps):
lock()
flash_args = ["artiq_flash"] flash_args = ["artiq_flash"]
for _ in range(args.verbose): for _ in range(args.verbose):
flash_args.append("-v") flash_args.append("-v")
@ -135,40 +147,32 @@ def main():
flash_args += ["--srcbuild", build_dir()] flash_args += ["--srcbuild", build_dir()]
flash_args += ["--preinit-command", "source {}".format(board_file)] flash_args += ["--preinit-command", "source {}".format(board_file)]
flash_args += steps flash_args += steps
subprocess.check_call(flash_args) command(*flash_args, on_failure="Flashing failed")
for action in args.actions: for action in args.actions:
if action == "build": if action == "build":
logger.info("Building target") logger.info("Building target")
try:
subprocess.check_call([ build_args = ["python3", "-m", "artiq.gateware.targets." + args.target]
"python3", "-m", "artiq.gateware.targets." + args.target, if not args.build_gateware:
"--no-compile-gateware", build_args.append("--no-compile-gateware")
*build_args, build_args += ["--output-dir", build_dir()]
"--output-dir", build_dir()]) build_args += extra_build_args
except subprocess.CalledProcessError: command(*build_args, on_failure="Build failed")
logger.error("Build failed")
sys.exit(1)
elif action == "clean": elif action == "clean":
logger.info("Cleaning build directory") logger.info("Cleaning build directory")
shutil.rmtree(build_dir, ignore_errors=True) shutil.rmtree(build_dir, ignore_errors=True)
elif action == "reset": elif action == "reset":
lock()
logger.info("Resetting device") logger.info("Resetting device")
flash("start") flash("start")
elif action == "flash": elif action == "flash":
lock()
logger.info("Flashing and booting firmware") logger.info("Flashing and booting firmware")
flash("proxy", "bootloader", "firmware", "start") flash("proxy", "bootloader", "firmware", "start")
elif action == "flash+log": elif action == "flash+log":
lock()
logger.info("Flashing firmware") logger.info("Flashing firmware")
flash("proxy", "bootloader", "firmware") flash("proxy", "bootloader", "firmware")
@ -234,12 +238,9 @@ def main():
elif action == "hotswap": elif action == "hotswap":
logger.info("Hotswapping firmware") logger.info("Hotswapping firmware")
try: firmware = build_dir("software", firmware, firmware + ".bin")
subprocess.check_call(["artiq_coreboot", "hotswap", command("artiq_coreboot", "hotswap", firmware,
build_dir("software", firmware, firmware + ".bin")]) on_failure="Hotswapping failed")
except subprocess.CalledProcessError:
logger.error("Build failed")
sys.exit(1)
else: else:
logger.error("Unknown action {}".format(action)) logger.error("Unknown action {}".format(action))