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>
Cursor up copies the last line into the buffer without checking if it
fits into the current buffer. Fix this using safe_strncpy.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
cread_add_char doesn't take the trailing '\0' into account, so adding
it at the end of readline can overflow the buffer.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
maybe it is easier to press ctrl-l to clear the screen than type
'clear' command.
Signed-off-by: Du Huanpeng <u74147@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
We cannot use list_entry() on an empty list. Without history
we have to return an empty line. This fixes a crash when the
cursor up button is pressed and no command has been entered
previously. Broken since:
commit ada160a34a
Author: Sascha Hauer <s.hauer@pengutronix.de>
Date: Tue Jul 29 11:54:26 2014 +0200
readline: reimplement history functions
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reported-by: Teresa Gamez <t.gamez@phytec.de>
This reimplements the history functions in readline.
- Use regular lists instead of homegrown list implementation
- Allocate history strings dynamically instead of copying strings
to fixed buffers without checking the size
- saves us an initcall
- slightly smaller
- no longer add duplicates to the history
- when moving past the last history entry print an empty line
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>