diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | Makefile.rules | 11 | ||||
-rw-r--r-- | common/console.c | 72 | ||||
-rw-r--r-- | include/config.h | 21 |
4 files changed, 105 insertions, 1 deletions
@@ -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) diff --git a/Makefile.rules b/Makefile.rules index 23d743fbdb..425a5e84ef 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -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) 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) { diff --git a/include/config.h b/include/config.h index afe8eab5d0..c396517a4a 100644 --- a/include/config.h +++ b/include/config.h @@ -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. |