libratp, libratp-barebox and ratp-barebox-cli
Aleksander Morgado
aleksander at aleksander.es
Thu Jun 15 04:18:41 PDT 2017
Hey,
For anyone interested, I ended up preparing a pair of C libraries and
a CLI tool that allow controlling barebox remotely using RATP, in the
same way as bbremote does it. The libraries would allow easy
integration on C applications that may want to remotely control
barebox.
Repositories:
https://github.com/aleksander0m/libratp
https://github.com/aleksander0m/libratp-barebox
Some initial 0.0.2 tagged versions here:
https://aleksander.es/software/libratp-0.0.2.tar.xz
https://aleksander.es/software/libratp-barebox-0.0.2.tar.xz
APIs:
https://aleksander0m.github.io/libratp
https://aleksander0m.github.io/libratp-barebox
The libratp library provides a generic RATP implementation, much like
barebox' lib/ratp.c:
* The library currently supports creating ratp_t objects for TTYs or
FIFO pairs (e.g. for barebox sandbox testing).
* The library launches a background thread running a libevent main
loop, which takes care of all the async reading from the TTY (or
FIFO). all the timers in the RATP logic and all the link management
state machine.
* Callbacks may be registered by the user to get reported when new
data arrives or when RATP link state changes. Worth noting that these
callbacks are called from within the support thread.
* The ratp_close() and ratp_establish() operations in barebox'
lib/ratp.c are blocking, they will not return until the desired final
state has been reached or a timeout happened. In the libratp library
the equivalent operations would be ratp_link_active_open_sync() and
ratp_link_close_sync(); but the library also includes support for just
sending the active open or close requests, without waiting for the
final state to be reached, via ratp_link_active_open() and
ratp_link_close(). This allows to e.g. request an active open and
queue data to be sent, so that the data is directly sent on the ACK
finishing the establishment.
* The library doesn't make any assumption on the maximum data length
chosen by each peer, so a peer may choose a MDL<255 to receive data in
shorter chunks or even choose MDL=0 to indicate no data may be
received.
The libratp-barebox library "extends" the libratp library with barebox
specific operations. Right now, these are implemented:
* ratp_barebox_link_ping()
* ratp_barebox_link_command()
* ratp_barebox_link_getenv()
The ratp-barebox-cli implements the barebox specific operations in a
CLI, just a simple way to exercise the library APIs:
$ ratp-barebox-cli -t /dev/ttyUSB3 --ping
Sending PING...
PONG received...
$ ratp-barebox-cli -t /dev/ttyUSB3 --getenv global.boot.default
Sending getenv request: global.boot.default
global.boot.default: net
$ ratp-barebox-cli -t /dev/ttyUSB3 --command "ls /dev"
Sending command: ls /dev
Received response (errno Success):
cs0 eeprom0 eeprom1 full
imx-ocotp mem netconsole-1 null
prng ram0 ratpconsole-1 serial0-1
serial1-1 serial2-1 zero
Cheers!
--
Aleksander
https://aleksander.es
More information about the barebox
mailing list