summaryrefslogtreecommitdiffstats
path: root/src/console
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2022-01-21 15:24:12 -0800
committerJulius Werner <jwerner@chromium.org>2022-02-07 23:27:34 +0000
commita120e0defd14f20ed1b2cb7796d47afbb2f0b54f (patch)
treec035503c974a5cee8f25a19baf7a6dcff449d416 /src/console
parent6bb9e57a8fb4418af24ddfbc45fb597dafa3a95f (diff)
downloadcoreboot-a120e0defd14f20ed1b2cb7796d47afbb2f0b54f.tar.gz
coreboot-a120e0defd14f20ed1b2cb7796d47afbb2f0b54f.tar.bz2
coreboot-a120e0defd14f20ed1b2cb7796d47afbb2f0b54f.zip
console: Add ANSI escape sequences for highlighting
This patch adds ANSI escape sequences to highlight a log line based on its loglevel to the output of "interactive" consoles that are meant to be displayed on a terminal (e.g. UART). This should help make errors and warnings stand out better among the usual spew of debug messages. For users whose terminal or use case doesn't support these sequences for some reason (or who simply don't like them), they can be disabled with a Kconfig. While ANSI escape sequences can be used to add color, minicom (the presumably most common terminal emulator for UART endpoints?) doesn't support color output unless explicitly enabled (via -c command line flag), and other terminal emulators may have similar restrictions, so in an effort to make this as widely useful by default as possible I have chosen not to use color codes and implement this highlighting via bolding, underlining and inverting alone (which seem to go through in all cases). If desired, support for separate color highlighting could be added via Kconfig later. Signed-off-by: Julius Werner <jwerner@chromium.org> Change-Id: I868f4026918bc0e967c32e14bcf3ac05816415e8 Reviewed-on: https://review.coreboot.org/c/coreboot/+/61307 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Raul Rangel <rrangel@chromium.org>
Diffstat (limited to 'src/console')
-rw-r--r--src/console/Kconfig9
-rw-r--r--src/console/printk.c12
2 files changed, 20 insertions, 1 deletions
diff --git a/src/console/Kconfig b/src/console/Kconfig
index f80d2e49722e..37d8fefe96bc 100644
--- a/src/console/Kconfig
+++ b/src/console/Kconfig
@@ -395,6 +395,15 @@ config DEFAULT_CONSOLE_LOGLEVEL
endif
+config CONSOLE_USE_ANSI_ESCAPES
+ bool "Use ANSI escape sequences for console highlighting"
+ default y
+ help
+ If enabled, certain consoles (e.g. UART) that are meant to be read on
+ a terminal will use ANSI escape sequences (like `ESC [1m`) to
+ highlight lines based on their log level. Disable this if your
+ terminal does not support ANSI escape sequences.
+
config NO_POST
bool "Don't show any POST codes"
default n
diff --git a/src/console/printk.c b/src/console/printk.c
index ddd14c05891a..93aed523779e 100644
--- a/src/console/printk.c
+++ b/src/console/printk.c
@@ -81,16 +81,26 @@ static void line_start(union log_state state)
if (state.speed == CONSOLE_LOG_FAST)
return;
- /* Interactive consoles get a `[DEBUG] ` style readable prefix. */
+ /* Interactive consoles get a `[DEBUG] ` style readable prefix,
+ and potentially an escape sequence for highlighting. */
+ if (CONFIG(CONSOLE_USE_ANSI_ESCAPES))
+ wrap_interactive_printf(BIOS_LOG_ESCAPE_PATTERN, bios_log_escape[state.level]);
wrap_interactive_printf(BIOS_LOG_PREFIX_PATTERN, bios_log_prefix[state.level]);
}
+static void line_end(union log_state state)
+{
+ if (CONFIG(CONSOLE_USE_ANSI_ESCAPES) && state.speed != CONSOLE_LOG_FAST)
+ wrap_interactive_printf(BIOS_LOG_ESCAPE_RESET);
+}
+
static void wrap_putchar(unsigned char byte, void *data)
{
union log_state state = { .as_ptr = data };
static bool line_started = false;
if (byte == '\n') {
+ line_end(state);
line_started = false;
} else if (!line_started) {
line_start(state);