summaryrefslogtreecommitdiff
path: root/common/console.c
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2012-01-23 23:07:58 +0000
committerVincent Palatin <vpalatin@chromium.org>2012-01-24 00:50:08 +0000
commitc21f07e58e48144a97a844668aae68644f8e8dec (patch)
tree12a0b7f04e085a0d2035e9bfbe05013530f99501 /common/console.c
parenta2a85365d600b93ecd10d44d1a5a2115ce0252f1 (diff)
downloadchrome-ec-c21f07e58e48144a97a844668aae68644f8e8dec.tar.gz
register console commands at compile-time
Instead of using a runtime callback to register the console commands, put them in a special linker section. So we can do a macro to "register" them during the build. It saves 684 bytes and a few microseconds at startup. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BUG=None TEST=run a few commands from the BDS command line. Change-Id: Id33ea210b9035bf76ed720373c74c5dd24ccd1b1
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c50
1 files changed, 12 insertions, 38 deletions
diff --git a/common/console.c b/common/console.c
index bc558f5cf4..12db5016dc 100644
--- a/common/console.c
+++ b/common/console.c
@@ -11,13 +11,13 @@
#include "registers.h"
#include "util.h"
-#define MAX_COMMAND_GROUPS 20
#define MAX_ARGS_PER_COMMAND 10
#define PROMPT "> "
-static const struct console_group *group_list[MAX_COMMAND_GROUPS];
-static int group_count = 0;
+/* Xonsole commands are described in a special section */
+extern const struct console_command __cmds[];
+extern const struct console_command __cmds_end[];
void console_has_input(void)
@@ -27,16 +27,6 @@ void console_has_input(void)
}
-int console_register_commands(const struct console_group *group)
-{
- if (group_count >= MAX_COMMAND_GROUPS)
- return EC_ERROR_OVERFLOW;
-
- group_list[group_count++] = group;
- return EC_SUCCESS;
-}
-
-
/* Splits a line of input into words. Stores the count of words in
* <argc>. Stores pointers to the words in <argv>, which must be at
* least <max_argc> long. If more than <max_argc> words are found,
@@ -80,15 +70,10 @@ int split_words(char *input, int max_argc, int *argc, char **argv)
const struct console_command *find_command(char *name)
{
const struct console_command *cmd;
- int c, g;
-
- /* Find the command in the command groups */
- for (g = 0; g < group_count; g++) {
- cmd = group_list[g]->commands;
- for (c = group_list[g]->command_count; c > 0; c--, cmd++) {
- if (!strcasecmp(name, cmd->name))
- return cmd;
- }
+
+ for (cmd = __cmds; cmd < __cmds_end; cmd++) {
+ if (!strcasecmp(name, cmd->name))
+ return cmd;
}
return NULL;
@@ -166,15 +151,11 @@ void console_task(void)
static int command_help(int argc, char **argv)
{
const struct console_command *cmd;
- int c, g;
uart_puts("Known commands:\n");
- for (g = 0; g < group_count; g++) {
- cmd = group_list[g]->commands;
- uart_printf("Group %s:\n", group_list[g]->group_name);
- for (c = group_list[g]->command_count; c > 0; c--, cmd++)
- uart_printf(" %s\n", cmd->name);
+ for (cmd = __cmds; cmd < __cmds_end; cmd++) {
+ uart_printf(" %s\n", cmd->name);
/* Generates enough output to overflow the buffer */
uart_flush_output();
}
@@ -183,14 +164,7 @@ static int command_help(int argc, char **argv)
return EC_SUCCESS;
}
-
-static const struct console_command console_commands[] = {
- {"help", command_help},
- {"?", command_help},
-};
-static const struct console_group command_group = {
- "Console", console_commands, ARRAY_SIZE(console_commands)
-};
+DECLARE_CONSOLE_COMMAND(help, command_help);
/*****************************************************************************/
/* Initialization */
@@ -202,6 +176,6 @@ int console_init(void)
uart_set_console_mode(1);
uart_printf("Console is enabled; type HELP for help.\n");
uart_puts(PROMPT);
- /* Register our internal commands */
- return console_register_commands(&command_group);
+
+ return EC_SUCCESS;
}