Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 87ae250baa6b
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 56c85dd2cb26
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Apr 30, 2015

  1. Copy the full SHA
    109dfab View commit details
  2. style

    sbourdeauducq committed Apr 30, 2015
    Copy the full SHA
    56c85dd View commit details
Showing with 62 additions and 2 deletions.
  1. +50 −0 artiq/frontend/artiq_mkfs.py
  2. +9 −0 doc/manual/utilities.rst
  3. +1 −0 setup.py
  4. +2 −2 soc/runtime/flash_storage.c
50 changes: 50 additions & 0 deletions artiq/frontend/artiq_mkfs.py
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 9 additions & 0 deletions doc/manual/utilities.rst
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
"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",
4 changes: 2 additions & 2 deletions soc/runtime/flash_storage.c
Original file line number Diff line number Diff line change
@@ -21,11 +21,11 @@

#define goto_next_record(buff, addr) do { \
unsigned int key_size = strlen(&buff[addr])+1; \
if (key_size % 4) \
if(key_size % 4) \
key_size += 4 - (key_size % 4); \
unsigned int *buflen_p = (unsigned int *)&buff[addr + key_size]; \
unsigned int buflen = *buflen_p; \
if (buflen % 4) \
if(buflen % 4) \
buflen += 4 - (buflen % 4); \
addr += key_size + sizeof(int) + buflen; \
} while (0)