2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-24 19:04:02 +08:00

frontend: add artiq_mkfs

This commit is contained in:
Sebastien Bourdeauducq 2015-04-30 20:03:11 +08:00
parent 87ae250baa
commit 109dfab76c
3 changed files with 60 additions and 0 deletions

50
artiq/frontend/artiq_mkfs.py Executable file
View File

@ -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()

View File

@ -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

View File

@ -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",