diff options
author | Aseda Aboagye <aaboagye@google.com> | 2015-10-29 15:56:49 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2015-11-11 12:58:34 -0800 |
commit | 397dbec3d6e8ca3d3f9961d1f9379dd810692da7 (patch) | |
tree | 012101e25c2c4fb309b8ebdfb1d341f7b207cf51 /common/console.c | |
parent | ac7a8864dcda3fa914535118796144c3e29a73d0 (diff) | |
download | chrome-ec-397dbec3d6e8ca3d3f9961d1f9379dd810692da7.tar.gz |
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>
Diffstat (limited to 'common/console.c')
-rw-r--r-- | common/console.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/common/console.c b/common/console.c index 3743eae93a..d7365be189 100644 --- a/common/console.c +++ b/common/console.c @@ -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) { |