diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2018-02-24 16:01:19 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2018-03-01 09:39:42 +0100 |
commit | bfcdef33add4f58ebd7f6a9621c94b1fb2caabd5 (patch) | |
tree | 0d97784763bcaae6059e405673bfaae3d45f880d /scripts/remote/main.py | |
parent | 706328c33fc8e9e680f37ee4cdac9ecbf3127f23 (diff) | |
download | barebox-bfcdef33add4f58ebd7f6a9621c94b1fb2caabd5.tar.gz barebox-bfcdef33add4f58ebd7f6a9621c94b1fb2caabd5.tar.xz |
ratp: new md and mw commands
This commit introduces support for running the md and mw commands
using the binary interface provided by RATP. This allows clients to
read and write memory files without needing to do custom string
parsing on the data returned by the console 'md' and 'mw' operations.
The request and response messages used for these new operations are
structured in the same way:
* An initial fixed-sized section includes the fixed-sized
variables (e.g. integers), as well as the size and offset of the
variable-length variables.
* After the initial fixed-sized section, the buffer is given, which
contains the variable-length variables in the offsets previously
defined and with the size previously defined.
The message also defines separately the offset of the buffer
w.r.t. the start of the message. The endpoint reading the message will
use this information to decide where the buffer starts. This allows to
extend the message format in the future without needing to break the
message API, as new fields can be appended to the fixed-sized section
as long as the buffer offset is also updated to report the new
position of the buffer.
E.g.:
$ ./bbremote --port /dev/ttyUSB2 md /dev/pic_eeprom_rdu 0x107 5
0000000000
$ ./bbremote --port /dev/ttyUSB2 mw /dev/pic_eeprom_rdu 0x107 0102030405
5 bytes written
$ ./bbremote --port /dev/ttyUSB2 md /dev/pic_eeprom_rdu 0x107 5
0102030405
$ ./bbremote --port /dev/ttyUSB2 mw /dev/pic_eeprom_rdu 0x107 0000000000
5 bytes written
$ ./bbremote --port /dev/ttyUSB2 md /dev/pic_eeprom_rdu 0x107 5
0000000000
Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'scripts/remote/main.py')
-rw-r--r-- | scripts/remote/main.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/remote/main.py b/scripts/remote/main.py index 79203df05a..29f601e9f8 100644 --- a/scripts/remote/main.py +++ b/scripts/remote/main.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function import sys import os import argparse +import binascii import logging from Queue import Queue from .ratp import RatpError @@ -76,6 +77,27 @@ def handle_getenv(args): return res +def handle_md(args): + ctrl = get_controller(args) + (res,data) = ctrl.md(args.path, args.address, args.size) + if res == 0: + print(binascii.hexlify(data)) + ctrl.close() + return res + + +def handle_mw(args): + ctrl = get_controller(args) + data=args.data + if ((len(data) % 2) != 0): + data="0"+data + (res,written) = ctrl.mw(args.path, args.address, binascii.unhexlify(data)) + if res == 0: + print("%i bytes written" % written) + ctrl.close() + return res + + def handle_listen(args): port = serial.serial_for_url(args.port, args.baudrate) conn = SerialRatpConnection(port) @@ -118,6 +140,10 @@ def handle_console(args): ctrl.conn.total_retransmits, ctrl.conn.total_crc_errors)) +# Support base 10 or base 16 numbers automatically +def auto_int(x): + return int(x, 0) + VERBOSITY = { 0: logging.WARN, 1: logging.INFO, @@ -143,6 +169,18 @@ parser_getenv = subparsers.add_parser('getenv', help="get a barebox environment parser_getenv.add_argument('arg', nargs='+', help="variable name") parser_getenv.set_defaults(func=handle_getenv) +parser_md = subparsers.add_parser('md', help="run md command") +parser_md.add_argument('path', help="path") +parser_md.add_argument('address', type=auto_int, help="address") +parser_md.add_argument('size', type=auto_int, help="size") +parser_md.set_defaults(func=handle_md) + +parser_mw = subparsers.add_parser('mw', help="run mw command") +parser_mw.add_argument('path', help="path") +parser_mw.add_argument('address', type=auto_int, help="address") +parser_mw.add_argument('data', help="data") +parser_mw.set_defaults(func=handle_mw) + parser_listen = subparsers.add_parser('listen', help="listen for an incoming connection") parser_listen.set_defaults(func=handle_listen) |