This adds the ability to control barebox over serial lines. The regular console is designed for human input and is unsuitable for controlling barebox from scripts since characters can be lost on both ends, the data stream contains escape sequences and the prompt cannot be easily matched upon. This approach is based on the RATP protocol. RATP packages start with a binary 0x01 which does not occur in normal console data. Whenever a 0x01 character is detected in the console barebox goes into RATP mode. The RATP packets contain a simple structure with a command/respone type and data for that type. Currently defined types are: BB_RATP_TYPE_COMMAND (host->barebox): Execute a command in the shell BB_RATP_TYPE_COMMAND_RETURN (barebox->host) Sends return value of the command back to the host, also means barebox is ready for the next command BB_RATP_TYPE_CONSOLEMSG (barebox->host) Console message from barebox Planned but not yet implemented are: BB_RATP_TYPE_PING (host->barebox) BB_RATP_TYPE_PONG (barebox->host) For testing purposes BB_RATP_TYPE_GETENV (host->barebox) BB_RATP_TYPE_GETENV_RETURN (barebox->host) Get values of environment variables Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Tested-by: Andrey Smirnov <andrew.smirnov@gmail.com>
22 lines
704 B
C
22 lines
704 B
C
#ifndef __RATP_H
|
|
#define __RATP_H
|
|
|
|
struct ratp {
|
|
struct ratp_internal *internal;
|
|
int (*send)(struct ratp *, void *pkt, int len);
|
|
int (*recv)(struct ratp *, uint8_t *data);
|
|
};
|
|
|
|
int ratp_establish(struct ratp *ratp, bool active, int timeout_ms);
|
|
void ratp_close(struct ratp *ratp);
|
|
int ratp_recv(struct ratp *ratp, void **data, size_t *len);
|
|
int ratp_send(struct ratp *ratp, const void *data, size_t len);
|
|
int ratp_send_complete(struct ratp *ratp, const void *data, size_t len,
|
|
void (*complete)(void *ctx, int status), void *complete_ctx);
|
|
int ratp_poll(struct ratp *ratp);
|
|
bool ratp_closed(struct ratp *ratp);
|
|
bool ratp_busy(struct ratp *ratp);
|
|
|
|
void ratp_run_command(void);
|
|
|
|
#endif /* __RATP_H */ |