From 109dfab76c9b276e6eddb6170dd108a5c2cba7c8 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 30 Apr 2015 20:03:11 +0800 Subject: [PATCH] frontend: add artiq_mkfs --- artiq/frontend/artiq_mkfs.py | 50 ++++++++++++++++++++++++++++++++++++ doc/manual/utilities.rst | 9 +++++++ setup.py | 1 + 3 files changed, 60 insertions(+) create mode 100755 artiq/frontend/artiq_mkfs.py diff --git a/artiq/frontend/artiq_mkfs.py b/artiq/frontend/artiq_mkfs.py new file mode 100755 index 000000000..ac00f632d --- /dev/null +++ b/artiq/frontend/artiq_mkfs.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +import argparse +import struct + + +def get_argparser(): + parser = argparse.ArgumentParser(description="ARTIQ flash storage image generator") + + parser.add_argument("output", help="output file") + + parser.add_argument("-s", nargs=2, action="append", default=[], + metavar=("KEY", "STRING"), + help="add string") + parser.add_argument("-f", nargs=2, action="append", default=[], + metavar=("KEY", "FILENAME"), + help="add file contents") + + return parser + + +def write_record(f, key, value): + f.write(key.encode()) + f.write(b"\x00") + key_size = len(key) + 1 + if key_size % 4: + f.write(bytes(4 - (key_size % 4))) + f.write(struct.pack(">l", len(value))) + f.write(value) + value_size = len(value) + if value_size % 4: + f.write(bytes(4 - (value_size % 4))) + + +def write_end_marker(f): + f.write(b"\xff\xff\xff\xff") + + +def main(): + args = get_argparser().parse_args() + with open(args.output, "wb") as fo: + for key, string in args.s: + write_record(fo, key, string.encode()) + for key, filename in args.f: + with open(filename, "rb") as fi: + write_record(fo, key, fi.read()) + write_end_marker(fo) + +if __name__ == "__main__": + main() diff --git a/doc/manual/utilities.rst b/doc/manual/utilities.rst index 212180a23..ebf6c2bb9 100644 --- a/doc/manual/utilities.rst +++ b/doc/manual/utilities.rst @@ -83,3 +83,12 @@ Experiments compiled with this tool are not allowed to use RPCs, and their ``run .. argparse:: :ref: artiq.frontend.artiq_compile.get_argparser :prog: artiq_compile + +Flash storage image generator +----------------------------- + +This tool compiles key/value pairs into a binary image suitable for flashing into the flash storage space of the core device. + +.. argparse:: + :ref: artiq.frontend.artiq_mkfs.get_argparser + :prog: artiq_mkfs diff --git a/setup.py b/setup.py index f4737297d..0b86af88c 100755 --- a/setup.py +++ b/setup.py @@ -14,6 +14,7 @@ scripts = [ "artiq_compile=artiq.frontend.artiq_compile:main", "artiq_ctlmgr=artiq.frontend.artiq_ctlmgr:main", "artiq_master=artiq.frontend.artiq_master:main", + "artiq_mkfs=artiq.frontend.artiq_mkfs:main", "artiq_rpctool=artiq.frontend.artiq_rpctool:main", "artiq_run=artiq.frontend.artiq_run:main", "lda_controller=artiq.frontend.lda_controller:main",