From 1c616f739262f1271617ff0979b8e7606d45a441 Mon Sep 17 00:00:00 2001 From: Keith Short Date: Fri, 13 Aug 2021 15:45:33 -0600 Subject: zephyr: Disable console help strings Add support for disabling the console command help strings. With CONFIG_SHELL_HELP=n, 2000 bytes saved on Volteer BUG=none BRANCH=none TEST=zmake testall TEST=Verify console on Volteer with and without CONFIG_SHELL_HELP enabled. Signed-off-by: Keith Short Change-Id: I2186828f28691182f673851ac27d207b4a4a6f44 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3093492 Reviewed-by: Jack Rosenthal Commit-Queue: Jack Rosenthal --- zephyr/Kconfig.console | 5 +++++ zephyr/shim/include/zephyr_console_shim.h | 13 +++++++++++-- zephyr/shim/src/console.c | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/zephyr/Kconfig.console b/zephyr/Kconfig.console index c1edee71d5..04e1d137bd 100644 --- a/zephyr/Kconfig.console +++ b/zephyr/Kconfig.console @@ -26,7 +26,12 @@ config SHELL_PRINTF_BUFF_SIZE default 130 # Some boards may need to increase the size, depending on the amount of output +# +# TODO(b/196627937): zephyr: hang when running help with CONFIG_SHELL_HELP +# enabled. Increase the TX buffer size to workaround the hang when the help +# is enabled. config SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE + default 4096 if SHELL_HELP default 1024 menuconfig PLATFORM_EC_HOSTCMD_CONSOLE diff --git a/zephyr/shim/include/zephyr_console_shim.h b/zephyr/shim/include/zephyr_console_shim.h index a45d65659b..b3c1f23922 100644 --- a/zephyr/shim/include/zephyr_console_shim.h +++ b/zephyr/shim/include/zephyr_console_shim.h @@ -11,12 +11,22 @@ struct zephyr_console_command { /* Handler for the command. argv[0] will be the command name. */ int (*handler)(int argc, char **argv); +#ifdef CONFIG_SHELL_HELP /* Description of args */ const char *argdesc; /* Short help for command */ const char *help; +#endif }; +#ifdef CONFIG_SHELL_HELP +#define _HELP_ARGS(A, H) \ + .argdesc = A, \ + .help = H, +#else +#define _HELP_ARGS(A, H) +#endif + /** * zshim_run_ec_console_command() - Dispatch a CrOS EC console command * using Zephyr's shell @@ -35,8 +45,7 @@ int zshim_run_ec_console_command(const struct zephyr_console_command *command, WRAPPER_ID, ENTRY_ID) \ static const struct zephyr_console_command ENTRY_ID = { \ .handler = ROUTINE_ID, \ - .argdesc = ARGDESC, \ - .help = HELP, \ + _HELP_ARGS(ARGDESC, HELP) \ }; \ static int WRAPPER_ID(const struct shell *shell, size_t argc, \ char **argv) \ diff --git a/zephyr/shim/src/console.c b/zephyr/shim/src/console.c index 929f7a9d1c..23f169f70c 100644 --- a/zephyr/shim/src/console.c +++ b/zephyr/shim/src/console.c @@ -164,10 +164,16 @@ void uart_shell_start(void) int zshim_run_ec_console_command(const struct zephyr_console_command *command, size_t argc, char **argv) { + /* + * The Zephyr shell only displays the help string and not + * the argument descriptor when passing "-h" or "--help". Mimic the + * cros-ec behavior by displaying both the user types " help", + */ +#ifdef CONFIG_SHELL_HELP for (int i = 1; i < argc; i++) { if (!command->help && !command->argdesc) break; - if (!strcmp(argv[i], "-h")) { + if (!strcmp(argv[i], "help")) { if (command->help) printk("%s\n", command->help); if (command->argdesc) @@ -175,6 +181,7 @@ int zshim_run_ec_console_command(const struct zephyr_console_command *command, return 0; } } +#endif return command->handler(argc, argv); } -- cgit v1.2.1