summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Short <keithshort@chromium.org>2021-02-16 13:13:07 -0700
committerCommit Bot <commit-bot@chromium.org>2021-02-17 21:53:29 +0000
commite8a96e49e310cd6a8a5f915e3c53b92f18fb8ace (patch)
tree32fcbf152edee2649df37f9bee8cf6c9c2cc5e22
parent844783bbd9e11ce936c78b03299197cc85adafd2 (diff)
downloadchrome-ec-e8a96e49e310cd6a8a5f915e3c53b92f18fb8ace.tar.gz
zephyr: add support for disabling console channels
Add support in the device tree for disabling console output channels by default. BUG=b:180421120 BRANCH=none TEST=make buildall TEST=zmake testall TEST=On Volteer, verify "hostcmd" channel is disabled by default Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: I9fa1fe78ee3927346ede8e75378260f6061075cd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2698268 Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r--common/console_output.c28
-rw-r--r--include/console.h14
-rw-r--r--zephyr/dts/bindings/console/ec-console.yaml14
-rw-r--r--zephyr/shim/src/console.c16
4 files changed, 72 insertions, 0 deletions
diff --git a/common/console_output.c b/common/console_output.c
index 23c208c61b..237c45cba6 100644
--- a/common/console_output.c
+++ b/common/console_output.c
@@ -35,6 +35,34 @@ static const char * const channel_names[] = {
BUILD_ASSERT(ARRAY_SIZE(channel_names) == CC_CHANNEL_COUNT);
/* ensure that we are not silently masking additional channels */
BUILD_ASSERT(CC_CHANNEL_COUNT <= 8*sizeof(uint32_t));
+
+static int console_channel_name_to_index(const char *name)
+{
+ int i;
+
+ for (i = 0; i < CC_CHANNEL_COUNT; i++) {
+ if (!strncasecmp(name, channel_names[i], strlen(name)))
+ return i;
+ }
+
+ /* Not found */
+ return -1;
+}
+
+void console_channel_enable(const char *name)
+{
+ int index = console_channel_name_to_index(name);
+
+ if (index >= 0 && index != CC_COMMAND)
+ channel_mask |= CC_MASK(index);
+}
+void console_channel_disable(const char *name)
+{
+ int index = console_channel_name_to_index(name);
+
+ if (index >= 0 && index != CC_COMMAND)
+ channel_mask &= ~CC_MASK(index);
+}
#endif /* CONFIG_CONSOLE_CHANNEL */
/*****************************************************************************/
diff --git a/include/console.h b/include/console.h
index 2c8503f0ee..47c2113ec3 100644
--- a/include/console.h
+++ b/include/console.h
@@ -103,6 +103,20 @@ enum console_channel {
#define CC_ALL 0xffffffffU
/**
+ * Enable a console channel by name
+ *
+ * @param name Console channel name
+ */
+void console_channel_enable(const char *name);
+
+/**
+ * Disable a console channel by name
+ *
+ * @param name Console channel name
+ */
+void console_channel_disable(const char *name);
+
+/**
* Put a string to the console channel.
*
* @param channel Output chanel
diff --git a/zephyr/dts/bindings/console/ec-console.yaml b/zephyr/dts/bindings/console/ec-console.yaml
new file mode 100644
index 0000000000..f79ddd67b0
--- /dev/null
+++ b/zephyr/dts/bindings/console/ec-console.yaml
@@ -0,0 +1,14 @@
+# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+description: EC Console node
+
+compatible: "ec-console"
+
+properties:
+ disabled:
+ required: false
+ type: string-array
+ description:
+ List of EC channel names that are disabled in the output by default.
diff --git a/zephyr/shim/src/console.c b/zephyr/shim/src/console.c
index 3b580318c2..adf8bd3f2a 100644
--- a/zephyr/shim/src/console.c
+++ b/zephyr/shim/src/console.c
@@ -3,6 +3,8 @@
* found in the LICENSE file.
*/
+#include <device.h>
+#include <init.h>
#include <kernel.h>
#include <shell/shell.h>
#include <stdbool.h>
@@ -36,6 +38,20 @@ int zshim_run_ec_console_command(int (*handler)(int argc, char **argv),
return handler(argc, argv);
}
+#if DT_NODE_EXISTS(DT_PATH(ec_console))
+#define EC_CONSOLE DT_PATH(ec_console)
+
+static const char * const disabled_channels[] = DT_PROP(EC_CONSOLE, disabled);
+static const size_t disabled_channel_count = DT_PROP_LEN(EC_CONSOLE, disabled);
+static int init_ec_console(const struct device *unused)
+{
+ for (size_t i = 0; i < disabled_channel_count; i++)
+ console_channel_disable(disabled_channels[i]);
+
+ return 0;
+} SYS_INIT(init_ec_console, PRE_KERNEL_1, 50);
+#endif
+
/*
* Minimal implementation of a few uart_* functions we need.
* TODO(b/178033156): probably need to swap this for something more