From 8755dcc9a750d1f6fb7e9bb9c2d900a8dea932ac Mon Sep 17 00:00:00 2001 From: Marius Schilder Date: Thu, 19 Mar 2020 14:26:51 -0700 Subject: g: add CONFIG_USB_CONSOLE_DEFAULT_DISABLED To avoid some sort of race in private-cr52 endpoint initialization, which results in a reboot loop. Calling usb_console_enable() in HOOK_LAST instead appears stable, at cost of missing some early console output. While at it, reduce some SRAM usage and improve legibility by moving to bool from int. Strictly opt-in; behavior unchanged for existing code. BUG=chromium:1063240 BRANCH=cr50 TEST=make buildall; cr52 build w/ usb_console now enumerates w/o resets. Signed-off-by: mschilder@google.com Change-Id: I352edb4c045df401cb99573da5765b88deb45d0d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2111450 Reviewed-by: Vadim Bendebury Reviewed-by: Marius Schilder Reviewed-by: Namyoon Woo Commit-Queue: Marius Schilder Tested-by: Marius Schilder Auto-Submit: Marius Schilder --- chip/g/usb_console.c | 17 +++++++++++------ include/config.h | 3 +++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/chip/g/usb_console.c b/chip/g/usb_console.c index 68cdea8a6e..65c15e144f 100644 --- a/chip/g/usb_console.c +++ b/chip/g/usb_console.c @@ -11,6 +11,7 @@ #include "printf.h" #include "queue.h" #include "registers.h" +#include "stdbool.h" #include "task.h" #include "timer.h" #include "util.h" @@ -21,21 +22,25 @@ #define CPRINTF(format, args...) cprintf(CC_USB, format, ## args) #define USB_CONSOLE_TIMEOUT_US (30 * MSEC) -static int last_tx_ok = 1; +static bool last_tx_ok = true; -static int is_reset; +static bool is_reset; +#if defined(CONFIG_USB_CONSOLE_DEFAULT_DISABLED) +static bool is_enabled; +#else /* * Start enabled, so we can queue early debug output before the board gets * around to calling usb_console_enable(). */ -static int is_enabled = 1; +static bool is_enabled = true; +#endif /* * But start read-only, so we don't accept console input until we explicitly * decide that we're ready for it. */ -static int is_readonly = 1; +static bool is_readonly = true; /* USB-Serial descriptors */ const struct usb_interface_descriptor USB_IFACE_DESC(USB_IFACE_CONSOLE) = @@ -387,6 +392,6 @@ int usb_vprintf(const char *format, va_list args) void usb_console_enable(int enabled, int readonly) { - is_enabled = enabled; - is_readonly = readonly; + is_enabled = !!enabled; + is_readonly = !!readonly; } diff --git a/include/config.h b/include/config.h index 00ea17e4fd..f810be8e90 100644 --- a/include/config.h +++ b/include/config.h @@ -4044,6 +4044,9 @@ /* Enable USB serial console module. */ #undef CONFIG_USB_CONSOLE +/* Require explicit enable call vs. active at time zero. */ +#undef CONFIG_USB_CONSOLE_DEFAULT_DISABLED + /* * Enable USB serial console module using usb stream config. * NOTE: CONFIG_USB_CONSOLE and CONFIG_USB_CONSOLE_STREAM should be defined -- cgit v1.2.1