From 8d1931504a6979e0f2daaf80f81aa2a73540cb05 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Mon, 15 Jan 2018 11:10:09 -0500 Subject: [PATCH] shell: rename module sections Prepare for supporting stand-alone commands. Signed-off-by: Anas Nashif --- include/linker/linker-defs.h | 8 ++++---- include/shell/shell.h | 2 +- subsys/shell/shell.c | 18 +++++++++++------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/include/linker/linker-defs.h b/include/linker/linker-defs.h index 3d9de4c12f8..03477a8e05e 100644 --- a/include/linker/linker-defs.h +++ b/include/linker/linker-defs.h @@ -99,10 +99,10 @@ * their shell commands are automatically initialized by the kernel. */ -#define SHELL_INIT_SECTIONS() \ - __shell_cmd_start = .; \ - KEEP(*(".shell_*")); \ - __shell_cmd_end = .; +#define SHELL_INIT_SECTIONS() \ + __shell_module_start = .; \ + KEEP(*(".shell_module_*")); \ + __shell_module_end = .; #ifdef CONFIG_APPLICATION_MEMORY diff --git a/include/shell/shell.h b/include/shell/shell.h index 54e99bd78c3..045d97789ed 100644 --- a/include/shell/shell.h +++ b/include/shell/shell.h @@ -86,7 +86,7 @@ struct shell_module { #define SHELL_REGISTER_WITH_PROMPT(_name, _commands, _prompt) \ \ static struct shell_module (__shell__name) __used \ - __attribute__((__section__(".shell_"))) = { \ + __attribute__((__section__(".shell_module_"))) = { \ .module_name = _name, \ .commands = _commands, \ .prompt = _prompt \ diff --git a/subsys/shell/shell.c b/subsys/shell/shell.c index 86f0ae88dad..5733e3e9957 100644 --- a/subsys/shell/shell.c +++ b/subsys/shell/shell.c @@ -36,9 +36,9 @@ #define PROMPT_MAX_LEN (MODULE_NAME_MAX_LEN + PROMPT_SUFFIX) /* command table is located in the dedicated memory segment (.shell_) */ -extern struct shell_module __shell_cmd_start[]; -extern struct shell_module __shell_cmd_end[]; -#define NUM_OF_SHELL_ENTITIES (__shell_cmd_end - __shell_cmd_start) +extern struct shell_module __shell_module_start[]; +extern struct shell_module __shell_module_end[]; +#define NUM_OF_SHELL_ENTITIES (__shell_module_end - __shell_module_start) static const char *prompt; static char default_module_prompt[PROMPT_MAX_LEN]; @@ -142,9 +142,9 @@ static struct shell_module *get_destination_module(const char *module_str) for (i = 0; i < NUM_OF_SHELL_ENTITIES; i++) { if (!strncmp(module_str, - __shell_cmd_start[i].module_name, + __shell_module_start[i].module_name, MODULE_NAME_MAX_LEN)) { - return &__shell_cmd_start[i]; + return &__shell_module_start[i]; } } @@ -239,9 +239,13 @@ module_help: } else { /* help for all entities */ int i; - printk("Available modules:\n"); + if (NUM_OF_SHELL_ENTITIES == 0) { + printk("No registered modules.\n"); + } else { + printk("Available modules:\n"); + } for (i = 0; i < NUM_OF_SHELL_ENTITIES; i++) { - printk("%s\n", __shell_cmd_start[i].module_name); + printk("%s\n", __shell_module_start[i].module_name); } printk("\nTo select a module, enter 'select '.\n");