console: Add support for using EC-3PO console.

This commit introduces a new CONFIG_* option.  To utilise the
experimental console, simply define the following config option in the
board's board.h file.

     #define CONFIG_EXPERIMENTAL_CONSOLE

This is a temporary option which allows the EC console to be work with
the EC-3PO interactive console interface.  When this option is enabled,
the EC expects commands to packed in a particular format.  This is for
command integrity and allows the interpreter to perform automatic
command retrying in the event that a character is dropped from the sent
command.

It also removes a lot of the console editing methods since they are now
being served by EC-3PO.

Once the EC-3PO interpreter is pulled into servod, we can enable this
feature by default and the config option can go away.

BUG=chrome-os-partner:46054
BRANCH=None
TEST=make -j buildall tests
TEST=Enable CONFIG_EXPERIMENTAL_CONSOLE on GLaDOS; Flash EC and verify
that console works via the EC-3PO interactive console interface.
TEST=Build and flash on GLaDOS and verify normal console operation on
standard EC UART.

CQ-DEPEND=CL:308615

Change-Id: I5e66eb94e31299b27ce029b7f7ce6ba0a7fb6816
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/309991
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Aseda Aboagye
2015-10-29 15:56:49 -07:00
committed by chrome-bot
parent ac7a8864dc
commit 397dbec3d6
4 changed files with 105 additions and 1 deletions

View File

@@ -175,7 +175,7 @@ deps := $(ro-deps) $(rw-deps)
$(config): $(out)/$(PROJECT).bin
@printf '%s=y\n' $(_tsk_cfg) $(_flag_cfg) > $@
def_all_deps:=utils ro rw $(config) $(PROJECT_EXTRA)
def_all_deps:=utils ro rw notice $(config) $(PROJECT_EXTRA)
all_deps?=$(def_all_deps)
all: $(all_deps)

View File

@@ -95,6 +95,17 @@ buildall:
@touch .tests-passed
@echo "$@ completed successfully!"
# Print any important notices at the end of the build.
.PHONY: notice
notice: $(config)
ifeq ($(CONFIG_EXPERIMENTAL_CONSOLE),y)
ifeq ($(TEST_BUILD),)
@echo "*** NOTE: The experimental console is ENABLED. ***"
@echo "You will need to run the EC-3PO interactive console in the util"
@echo "directory! Otherwise, you won't be able to enter any commands."
endif # not a TEST_BUILD
endif # CONFIG_EXPERIMENTAL_CONSOLE=y
proj-%:
@echo "======= building $*"; \
$(MAKE) --no-print-directory BOARD=$* V=$(V)

View File

@@ -7,6 +7,9 @@
#include "clock.h"
#include "console.h"
#ifdef CONFIG_EXPERIMENTAL_CONSOLE
#include "crc8.h"
#endif /* defined(CONFIG_EXPERIMENTAL_CONSOLE) */
#include "link_defs.h"
#include "system.h"
#include "task.h"
@@ -39,6 +42,7 @@ static int input_pos;
/* Was last received character a carriage return? */
static int last_rx_was_cr;
#ifndef CONFIG_EXPERIMENTAL_CONSOLE
/* State of input escape code */
static enum {
ESC_OUTSIDE, /* Not in escape code */
@@ -49,6 +53,7 @@ static enum {
ESC_BRACKET_3, /* Got ESC [ 3 */
ESC_O, /* Got ESC O */
} esc_state;
#endif /* !defined(CONFIG_EXPERIMENTAL_CONSOLE) */
/* Extended key code values, from multi-byte escape sequences */
enum extended_key_code {
@@ -165,9 +170,60 @@ static int handle_command(char *input)
char *argv[MAX_ARGS_PER_COMMAND];
int argc = 0;
int rv;
#ifdef CONFIG_EXPERIMENTAL_CONSOLE
char *e = NULL;
int i = 0;
int j = 0;
int command_len = 0;
uint8_t packed_crc8 = 0;
/* Need to perform some checking to see if our command is intact. */
/* There's nothing to do if the buffer is empty. */
if (!input_len)
return EC_SUCCESS;
/*
* Scan the first two characters in the command string looking for
* ampersands. We need at least one to continue.
*/
if ((input_len < 2) || (input[0] != '&' && input[1] != '&'))
goto command_has_error;
/*
* Okay, we've found at least one. We need to see if we actually got
* 2 ampersands in order to adjust our position properly.
*/
i = input[1] == '&' ? 2 : 1;
/* Next, there should be 4 hex digits: XXYY + '&' */
if (i+5 > input_len)
goto command_has_error;
/* Replace the '&' with null so we can call strtoi(). */
input[i+4] = 0;
j = strtoi(input + i, &e, 16);
if (*e)
goto command_has_error;
/* command length = XX, CRC8 = YY */
command_len = j >> 8;
packed_crc8 = (uint8_t)j;
i += 5;
/* Lastly, verify the CRC8 of the command. */
if (i+command_len > input_len)
goto command_has_error;
if (packed_crc8 != crc8(&input[i], command_len)) {
command_has_error:
/* Send back the error string. */
ccprintf("&&EE\n");
return EC_ERROR_UNKNOWN;
}
/* Split input into words. Ignore words past our limit. */
split_words(&input[i], &argc, argv);
#else
split_words(input, &argc, argv);
#endif /* defined(CONFIG_EXPERIMENTAL_CONSOLE) */
/* If no command, nothing to do */
if (!argc)
@@ -215,6 +271,7 @@ static int console_putc(int c)
return rv1 == EC_SUCCESS ? rv2 : rv1;
}
#ifndef CONFIG_EXPERIMENTAL_CONSOLE
static void move_cursor_right(void)
{
if (input_pos == input_len)
@@ -250,6 +307,7 @@ static void move_cursor_begin(void)
ccprintf("\x1b[%dD", input_pos);
input_pos = 0;
}
#endif /* !defined(CONFIG_EXPERIMENTAL_CONSOLE) */
static void repeat_char(char c, int cnt)
{
@@ -293,6 +351,7 @@ static void save_history(void)
#endif /* CONFIG_CONSOLE_HISTORY */
#ifndef CONFIG_EXPERIMENTAL_CONSOLE
static void handle_backspace(void)
{
if (!input_pos)
@@ -384,6 +443,7 @@ static int handle_esc(int c)
return -1;
}
#endif /* !defined(CONFIG_EXPERIMENTAL_CONSOLE) */
static void console_handle_char(int c)
{
@@ -398,6 +458,7 @@ static void console_handle_char(int c)
last_rx_was_cr = 0;
}
#ifndef CONFIG_EXPERIMENTAL_CONSOLE
/* Handle terminal escape sequences (ESC [ ...) */
if (c == 0x1B) {
esc_state = ESC_START;
@@ -407,8 +468,10 @@ static void console_handle_char(int c)
if (c != -1)
esc_state = ESC_OUTSIDE;
}
#endif /* !defined(CONFIG_EXPERIMENTAL_CONSOLE) */
switch (c) {
#ifndef CONFIG_EXPERIMENTAL_CONSOLE
case KEY_DEL:
if (input_pos == input_len)
break; /* Already at end */
@@ -420,10 +483,13 @@ static void console_handle_char(int c)
case 0x7f:
handle_backspace();
break;
#endif /* !defined(CONFIG_EXPERIMENTAL_CONSOLE) */
case '\n':
#ifndef CONFIG_EXPERIMENTAL_CONSOLE
/* Terminate this line */
console_putc('\n');
#endif /* !defined(CONFIG_EXPERIMENTAL_CONSOLE) */
#ifdef CONFIG_CONSOLE_HISTORY
/* Save command in history buffer */
@@ -442,10 +508,13 @@ static void console_handle_char(int c)
input_pos = input_len = 0;
input_buf[0] = '\0';
#ifndef CONFIG_EXPERIMENTAL_CONSOLE
/* Reprint prompt */
ccputs(PROMPT);
#endif /* !defined(CONFIG_EXPERIMENTAL_CONSOLE) */
break;
#ifndef CONFIG_EXPERIMENTAL_CONSOLE
case CTRL('A'):
case KEY_HOME:
move_cursor_begin();
@@ -511,18 +580,21 @@ static void console_handle_char(int c)
break;
#endif /* CONFIG_CONSOLE_HISTORY */
#endif /* !defined(CONFIG_EXPERIMENTAL_CONSOLE) */
default:
/* Ignore non-printing characters */
if (!isprint(c))
break;
#ifndef CONFIG_EXPERIMENTAL_CONSOLE
/* Ignore if line is full (leaving room for terminating null) */
if (input_len >= sizeof(input_buf) - 1)
break;
/* Print character */
console_putc(c);
#endif /* !defined(CONFIG_EXPERIMENTAL_CONSOLE) */
/* If not at end of line, print rest of line and move it down */
if (input_pos != input_len) {

View File

@@ -602,6 +602,15 @@
*/
#undef CONFIG_CONSOLE_RESTRICTED_INPUT
/*
* Enable the experimental console.
*
* NOTE: If you enable this experimental console, you will need to run the
* EC-3PO interactive console in the util directory! Otherwise, you won't be
* able to enter any commands.
*/
#undef CONFIG_EXPERIMENTAL_CONSOLE
/* Include CRC-8 utility function */
#undef CONFIG_CRC8
@@ -2008,6 +2017,18 @@
#include "config_chip.h"
#include "board.h"
/******************************************************************************/
/*
* Disable the built-in console history if using the experimental console.
*
* The experimental console keeps its own session-persistent history which
* survives EC reboot. It also requires CRC8 for command integrity.
*/
#ifdef CONFIG_EXPERIMENTAL_CONSOLE
#undef CONFIG_CONSOLE_HISTORY
#define CONFIG_CRC8
#endif /* defined(CONFIG_EXPERIMENTAL_CONSOLE) */
/*****************************************************************************/
/*
* Handle task-dependent configs.