summaryrefslogtreecommitdiffstats
path: root/common/console.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-11-26 09:47:23 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2016-01-18 09:25:09 +0100
commit266057337402f45adf707ef59beebd2a6821a749 (patch)
tree522ebf43324c9af913035e3044c2397d747c8d2b /common/console.c
parentbbdbda0a7442545ab9022f2ec78e45f1d6750f38 (diff)
downloadbarebox-266057337402f45adf707ef59beebd2a6821a749.tar.gz
barebox remote control
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>
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/common/console.c b/common/console.c
index 4a1d257..a541892 100644
--- a/common/console.c
+++ b/common/console.c
@@ -31,6 +31,7 @@
#include <kfifo.h>
#include <module.h>
#include <poller.h>
+#include <ratp_bb.h>
#include <magicvar.h>
#include <globalvar.h>
#include <linux/list.h>
@@ -313,8 +314,16 @@ static int getc_raw(void)
if (!(cdev->f_active & CONSOLE_STDIN))
continue;
active = 1;
- if (cdev->tstc(cdev))
- return cdev->getc(cdev);
+ if (cdev->tstc(cdev)) {
+ int ch = cdev->getc(cdev);
+
+ if (IS_ENABLED(CONFIG_RATP) && ch == 0x01) {
+ barebox_ratp(cdev);
+ return -1;
+ }
+
+ return ch;
+ }
}
if (!active)
/* no active console found. bail out */
@@ -349,16 +358,26 @@ int getc(void)
start = get_time_ns();
while (1) {
if (tstc_raw()) {
- kfifo_putc(console_input_fifo, getc_raw());
+ int c = getc_raw();
+
+ if (c < 0)
+ break;
+
+ kfifo_putc(console_input_fifo, c);
start = get_time_ns();
}
+
if (is_timeout(start, 100 * USECOND) &&
kfifo_len(console_input_fifo))
break;
}
+ if (!kfifo_len(console_input_fifo))
+ return -1;
+
kfifo_getc(console_input_fifo, &ch);
+
return ch;
}
EXPORT_SYMBOL(getc);