diff options
author | Rob Barnes <robbarnes@google.com> | 2022-09-12 15:06:42 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-09-15 16:22:45 +0000 |
commit | 6bff94908b4cda15d31baa2e152d76fe45b08ca1 (patch) | |
tree | c79d058ebcc0a36260817443f4ecd95e7416a2db /zephyr | |
parent | db3db9e9cb9c2ccbc18b7ecef88700c3c735ad0f (diff) | |
download | chrome-ec-6bff94908b4cda15d31baa2e152d76fe45b08ca1.tar.gz |
zephyr/console: Add console buffer logging backendstabilize-15120.B-main
Add a zephyr logging backend for the console buffer. This allows the AP
to access the logs sent to the zephyr logging subsystem.
This backend will not run in LOG_MODE_MINIMAL, so it may not be usable
for some EC OS projects.
BUG=b:243709788
BRANCH=None
TEST='ectool console' on Skyrim in immediate and deferred logging mode.
Signed-off-by: Rob Barnes <robbarnes@google.com>
Change-Id: I24d9ffeb5c90c99982c70ac2bcbdc0f814b45b01
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3853303
Reviewed-by: Keith Short <keithshort@chromium.org>
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Diffstat (limited to 'zephyr')
-rw-r--r-- | zephyr/Kconfig.console | 22 | ||||
-rw-r--r-- | zephyr/shim/src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | zephyr/shim/src/log_backend_console_buffer.c | 56 |
3 files changed, 80 insertions, 0 deletions
diff --git a/zephyr/Kconfig.console b/zephyr/Kconfig.console index 75a4ca7879..74de199067 100644 --- a/zephyr/Kconfig.console +++ b/zephyr/Kconfig.console @@ -66,3 +66,25 @@ menuconfig PLATFORM_EC_CONSOLE_DEBUG Write all zephyr_print() messages to printk() also. Not recommended outside of tests. + +config PLATFORM_EC_LOG_BACKEND_CONSOLE_BUFFER + bool "Logging backend for the console buffer" + depends on PLATFORM_EC_HOSTCMD_CONSOLE + select LOG_OUTPUT + help + Enable the logging backend for the console buffer. + + This will copy messages sent to the zephyr logging subsystem + to the EC console buffer. This allows the AP to access the + log messages with the console host command. + +config PLATFORM_EC_LOG_BACKEND_CONSOLE_BUFFER_TMP_BUF_SIZE + int "Size of temporary buffer used by console buffer logging backend" + default 128 if LOG_MODE_DEFERRED + default 1 + depends on PLATFORM_EC_LOG_BACKEND_CONSOLE_BUFFER + help + The size of the temporary buffer used by the console buffer backend. + The logging subsystem will buffer up to this many bytes before calling + the backend in deferred logging mode. Ideally this will be large + enough to fit an entire log line. diff --git a/zephyr/shim/src/CMakeLists.txt b/zephyr/shim/src/CMakeLists.txt index 636f8ba5c9..97968e8a52 100644 --- a/zephyr/shim/src/CMakeLists.txt +++ b/zephyr/shim/src/CMakeLists.txt @@ -43,6 +43,8 @@ if (NOT DEFINED CONFIG_PLATFORM_EC_KEYBOARD_DISCRETE) keyboard_raw.c) endif() zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_KEYBOARD keyscan.c) +zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_LOG_BACKEND_CONSOLE_BUFFER + log_backend_console_buffer.c) zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_MKBP_EVENT mkbp_event.c) zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_MOTIONSENSE motionsense_sensors.c) diff --git a/zephyr/shim/src/log_backend_console_buffer.c b/zephyr/shim/src/log_backend_console_buffer.c new file mode 100644 index 0000000000..cafb690b87 --- /dev/null +++ b/zephyr/shim/src/log_backend_console_buffer.c @@ -0,0 +1,56 @@ +/* Copyright 2022 The ChromiumOS Authors. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <zephyr/logging/log_backend.h> +#include <zephyr/logging/log_output.h> +#include <zephyr/logging/log_backend_std.h> + +#include "console.h" + +static uint8_t + char_out_buf[CONFIG_PLATFORM_EC_LOG_BACKEND_CONSOLE_BUFFER_TMP_BUF_SIZE]; + +static int char_out(uint8_t *data, size_t length, void *ctx) +{ + /* + * console_buf_notify_chars uses a mutex, which may not be + * locked in ISRs. + */ + if (k_is_in_isr()) + return 0; + return console_buf_notify_chars(data, length); +} +LOG_OUTPUT_DEFINE(log_output_console_buffer, char_out, char_out_buf, + sizeof(char_out_buf)); + +static void process(const struct log_backend *const backend, + union log_msg_generic *msg) +{ + uint32_t flags = log_backend_std_get_flags(); + log_format_func_t log_output_func = + log_format_func_t_get(LOG_OUTPUT_TEXT); + log_output_func(&log_output_console_buffer, &msg->log, flags); +} + +static void panic(struct log_backend const *const backend) +{ + log_backend_std_panic(&log_output_console_buffer); +} + +static void dropped(const struct log_backend *const backend, uint32_t cnt) +{ + log_backend_std_dropped(&log_output_console_buffer, cnt); +} + +const struct log_backend_api log_backend_console_buffer_api = { + .process = process, + .panic = panic, + .dropped = IS_ENABLED(CONFIG_LOG_MODE_DEFERRED) ? dropped : NULL, + /* TODO(b/244170593): Support switching output formats */ + .format_set = NULL, +}; + +LOG_BACKEND_DEFINE(log_backend_console_buffer, log_backend_console_buffer_api, + true); |