Rename artiq_coreconfig → artiq_coretool; add log subcommand.

This commit is contained in:
whitequark 2015-08-02 16:35:49 +03:00
parent b2f720da67
commit ad7cbc4394
5 changed files with 57 additions and 39 deletions

View File

@ -11,15 +11,26 @@ def to_bytes(string):
def get_argparser():
parser = argparse.ArgumentParser(description="ARTIQ core device config "
"remote access")
parser = argparse.ArgumentParser(description="ARTIQ core device "
"remote access tool")
parser.add_argument("--ddb", default="ddb.pyon",
help="device database file")
subparsers = parser.add_subparsers(dest="action")
subparsers.required = True
p_read = subparsers.add_parser("read",
# Log Read command
subparsers.add_parser("log",
help="read from the core device log ring buffer")
# Configuration Read command
p_read = subparsers.add_parser("cfg-read",
help="read key from core device config")
p_read.add_argument("key", type=to_bytes,
help="key to be read from core device config")
p_write = subparsers.add_parser("write",
# Configuration Write command
p_write = subparsers.add_parser("cfg-write",
help="write key-value records to core "
"device config")
p_write.add_argument("-s", "--string", nargs=2, action="append",
@ -31,14 +42,17 @@ def get_argparser():
metavar=("KEY", "FILENAME"),
help="key and file whose content to be written to "
"core device config")
subparsers.add_parser("erase", help="erase core device config")
p_delete = subparsers.add_parser("delete",
# Configuration Delete command
p_delete = subparsers.add_parser("cfg-delete",
help="delete key from core device config")
p_delete.add_argument("key", nargs=argparse.REMAINDER,
default=[], type=to_bytes,
help="key to be deleted from core device config")
parser.add_argument("--ddb", default="ddb.pyon",
help="device database file")
# Configuration Erase command
subparsers.add_parser("cfg-erase", help="erase core device config")
return parser
@ -48,23 +62,25 @@ def main():
try:
comm = dmgr.get("comm")
if args.action == "read":
if args.action == "log":
print(comm.get_log())
elif args.action == "cfg-read":
value = comm.flash_storage_read(args.key)
if not value:
print("Key {} does not exist".format(args.key))
else:
print(value)
elif args.action == "erase":
comm.flash_storage_erase()
elif args.action == "delete":
for key in args.key:
comm.flash_storage_remove(key)
elif args.action == "write":
elif args.action == "cfg-write":
for key, value in args.string:
comm.flash_storage_write(key, value)
for key, filename in args.file:
with open(filename, "rb") as fi:
comm.flash_storage_write(key, fi.read())
elif args.action == "cfg-delete":
for key in args.key:
comm.flash_storage_remove(key)
elif args.action == "cfg-erase":
comm.flash_storage_erase()
finally:
dmgr.close_devices()

View File

@ -11,4 +11,4 @@ This storage area is used to store the core device MAC address, IP address and e
The flash storage area is one sector (64 kB) large and is organized as a list
of key-value records.
This flash storage space can be accessed by using the artiq_coreconfig.py :ref:`core-device-configuration-tool`.
This flash storage space can be accessed by using the artiq_coretool.py :ref:`core-device-access-tool`.

View File

@ -289,9 +289,9 @@ To flash the ``idle`` kernel:
* Write it into the core device configuration flash storage: ::
$ artiq_coreconfig write -f idle_kernel idle.elf
$ artiq_coretool cfg-write -f idle_kernel idle.elf
.. note:: You can find more information about how to use the ``artiq_coreconfig`` tool on the :ref:`Utilities <core-device-configuration-tool>` page.
.. note:: You can find more information about how to use the ``artiq_coretool`` utility on the :ref:`Utilities <core-device-access-tool>` page.
Installing the host-side software
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -93,60 +93,62 @@ This tool compiles key/value pairs into a binary image suitable for flashing int
:ref: artiq.frontend.artiq_mkfs.get_argparser
:prog: artiq_mkfs
.. _core-device-configuration-tool:
.. _core-device-access-tool:
Core device configuration tool
------------------------------
Core device access tool
-----------------------
The artiq_coreconfig tool allows to read, write and remove key-value records from the :ref:`core-device-flash-storage`.
The artiq_coretool utility allows to perform maintenance on the core device:
It also allows to erase the entire flash storage area.
* read core device logs;
* as well as read, write and remove key-value records from the :ref:`core-device-flash-storage`;
* erase the entire flash storage area.
To use this tool, you need to specify a ``ddb.pyon`` DDB file which contains a ``comm`` device (an example is provided in ``artiq/examples/master/ddb.pyon``).
This tells the tool how to connect to the core device (via serial or via TCP) and with which parameters (baudrate, serial device, IP address, TCP port).
When not specified, the artiq_coreconfig tool will assume that there is a file named ``ddb.pyon`` in the current directory.
When not specified, the artiq_coretool utility will assume that there is a file named ``ddb.pyon`` in the current directory.
To read the record whose key is ``mac``::
$ artiq_coreconfig read mac
$ artiq_coretool cfg-read mac
To write the value ``test_value`` in the key ``my_key``::
$ artiq_coreconfig write -s my_key test_value
$ artiq_coreconfig read my_key
$ artiq_coretool cfg-write -s my_key test_value
$ artiq_coretool cfg-read my_key
b'test_value'
You can also write entire files in a record using the ``-f`` parameter. This is useful for instance to write the ``idle`` kernel in the flash storage::
$ artiq_coreconfig write -f idle_kernel idle.elf
$ artiq_coreconfig read idle_kernel | head -c9
$ artiq_coretool cfg-write -f idle_kernel idle.elf
$ artiq_coretool cfg-read idle_kernel | head -c9
b'\x7fELF
You can write several records at once::
$ artiq_coreconfig write -s key1 value1 -f key2 filename -s key3 value3
$ artiq_coretool cfg-write -s key1 value1 -f key2 filename -s key3 value3
To remove the previously written key ``my_key``::
$ artiq_coreconfig delete my_key
$ artiq_coretool cfg-delete my_key
You can remove several keys at once::
$ artiq_coreconfig delete key1 key2
$ artiq_coretool cfg-delete key1 key2
To erase the entire flash storage area::
$ artiq_coreconfig erase
$ artiq_coretool cfg-erase
You don't need to remove a record in order to change its value, just overwrite
it::
$ artiq_coreconfig write -s my_key some_value
$ artiq_coreconfig write -s my_key some_other_value
$ artiq_coreconfig read my_key
$ artiq_coretool cfg-write -s my_key some_value
$ artiq_coretool cfg-write -s my_key some_other_value
$ artiq_coretool cfg-read my_key
b'some_other_value'
.. argparse::
:ref: artiq.frontend.artiq_coreconfig.get_argparser
:prog: artiq_coreconfig
:ref: artiq.frontend.artiq_coretool.get_argparser
:prog: artiq_coretool

View File

@ -26,7 +26,7 @@ requirements = [
scripts = [
"artiq_client=artiq.frontend.artiq_client:main",
"artiq_compile=artiq.frontend.artiq_compile:main",
"artiq_coreconfig=artiq.frontend.artiq_coreconfig:main",
"artiq_coretool=artiq.frontend.artiq_coretool:main",
"artiq_ctlmgr=artiq.frontend.artiq_ctlmgr:main",
"artiq_gui=artiq.frontend.artiq_gui:main",
"artiq_master=artiq.frontend.artiq_master:main",