summaryrefslogtreecommitdiff
path: root/common
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
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')
-rw-r--r--common/console.c50
-rw-r--r--common/flash_commands.c27
-rw-r--r--common/host_command.c11
-rw-r--r--common/keyboard.c15
-rw-r--r--common/main.c5
-rw-r--r--common/memory_commands.c22
-rw-r--r--common/port80.c10
-rw-r--r--common/usb_charge.c10
-rw-r--r--common/vboot.c17
9 files changed, 26 insertions, 141 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;
}
diff --git a/common/flash_commands.c b/common/flash_commands.c
index e8e2c9591c..000be73e20 100644
--- a/common/flash_commands.c
+++ b/common/flash_commands.c
@@ -23,6 +23,7 @@ static int command_flash_info(int argc, char **argv)
uart_printf("Usable flash size: %d B\n", flash_get_size());
return EC_SUCCESS;
}
+DECLARE_CONSOLE_COMMAND(flashinfo, command_flash_info);
static int command_flash_erase(int argc, char **argv)
@@ -61,6 +62,7 @@ static int command_flash_erase(int argc, char **argv)
return rv;
}
+DECLARE_CONSOLE_COMMAND(flasherase, command_flash_erase);
static int command_flash_write(int argc, char **argv)
@@ -119,6 +121,7 @@ static int command_flash_write(int argc, char **argv)
return rv;
}
+DECLARE_CONSOLE_COMMAND(flashwrite, command_flash_write);
static int command_flash_wp(int argc, char **argv)
@@ -144,6 +147,7 @@ static int command_flash_wp(int argc, char **argv)
uart_printf("FMPPE1 after: 0x%08x\n", LM4_FLASH_FMPPE1);
return EC_SUCCESS;
}
+DECLARE_CONSOLE_COMMAND(flashwp, command_flash_wp);
static int command_flash_wp_range(int argc, char **argv)
{
@@ -182,18 +186,7 @@ static int command_flash_wp_range(int argc, char **argv)
}
return EC_SUCCESS;
}
-
-static const struct console_command console_commands[] = {
- {"flasherase", command_flash_erase},
- {"flashinfo", command_flash_info},
- {"flashwrite", command_flash_write},
- {"flashwp", command_flash_wp},
- {"flashwprange", command_flash_wp_range},
-};
-static const struct console_group command_group = {
- "Flash", console_commands, ARRAY_SIZE(console_commands)
-};
-
+DECLARE_CONSOLE_COMMAND(flashwprange, command_flash_wp_range);
/*****************************************************************************/
@@ -338,13 +331,3 @@ enum lpc_status flash_command_wp_get_range(uint8_t *data)
return EC_LPC_STATUS_SUCCESS;
}
-
-/*****************************************************************************/
-/* Initialization */
-
-int flash_commands_init(void)
-{
- /* Register our internal commands */
- console_register_commands(&command_group);
- return EC_SUCCESS;
-}
diff --git a/common/host_command.c b/common/host_command.c
index aa72535987..5cebed2131 100644
--- a/common/host_command.c
+++ b/common/host_command.c
@@ -202,15 +202,7 @@ static int command_version(int argc, char **argv)
system_get_version(SYSTEM_IMAGE_RW_B));
return EC_SUCCESS;
}
-
-
-static const struct console_command console_commands[] = {
- {"version", command_version},
-};
-
-static const struct console_group command_group = {
- "Host commands", console_commands, ARRAY_SIZE(console_commands)
-};
+DECLARE_CONSOLE_COMMAND(version, command_version);
/*****************************************************************************/
/* Initialization / task */
@@ -219,7 +211,6 @@ static int host_command_init(void)
{
host_command[0] = host_command[1] = -1;
- console_register_commands(&command_group);
return EC_SUCCESS;
}
diff --git a/common/keyboard.c b/common/keyboard.c
index bf155f22c2..fad9d2eda5 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -473,17 +473,4 @@ static int command_codeset(int argc, char **argv)
return EC_SUCCESS;
}
-
-
-static const struct console_command console_commands[] = {
- {"codeset", command_codeset},
-};
-static const struct console_group command_group = {
- "Keyboard", console_commands, ARRAY_SIZE(console_commands)
-};
-
-
-enum ec_error_list keyboard_init(void) {
-
- return console_register_commands(&command_group);
-}
+DECLARE_CONSOLE_COMMAND(codeset, command_codeset);
diff --git a/common/main.c b/common/main.c
index 30faa87066..15a2547665 100644
--- a/common/main.c
+++ b/common/main.c
@@ -79,19 +79,14 @@ int main(void)
timer_init();
uart_init();
system_init();
- gpio_init();
flash_init();
eeprom_init();
port_80_init();
lpc_init();
- flash_commands_init();
- vboot_init();
pwm_init();
i2c_init();
temp_sensor_init();
- memory_commands_init();
power_button_init();
- keyboard_init();
adc_init();
usb_charge_init();
diff --git a/common/memory_commands.c b/common/memory_commands.c
index e54d567080..3a0a8ec83e 100644
--- a/common/memory_commands.c
+++ b/common/memory_commands.c
@@ -31,6 +31,8 @@ static int command_write_word(int argc, char **argv)
return EC_SUCCESS;
}
+DECLARE_CONSOLE_COMMAND(ww, command_write_word);
+DECLARE_CONSOLE_COMMAND(writeword, command_write_word);
static int command_read_word(int argc, char **argv)
@@ -50,21 +52,5 @@ static int command_read_word(int argc, char **argv)
return EC_SUCCESS;
}
-
-
-static const struct console_command console_commands[] = {
- {"rw", command_read_word},
- {"ww", command_write_word},
- {"readword", command_read_word},
- {"writeword", command_write_word},
-};
-static const struct console_group command_group = {
- "Memory", console_commands, ARRAY_SIZE(console_commands)
-};
-
-
-int memory_commands_init(void)
-{
- /* Register our internal commands */
- return console_register_commands(&command_group);
-}
+DECLARE_CONSOLE_COMMAND(rw, command_read_word);
+DECLARE_CONSOLE_COMMAND(readword, command_read_word);
diff --git a/common/port80.c b/common/port80.c
index 68d3219aa0..6349975b75 100644
--- a/common/port80.c
+++ b/common/port80.c
@@ -54,21 +54,13 @@ static int command_port80(int argc, char **argv)
uart_puts(" <--newest\n");
return EC_SUCCESS;
}
-
-
-static const struct console_command console_commands[] = {
- {"port80", command_port80},
-};
-static const struct console_group command_group = {
- "Port 80", console_commands, ARRAY_SIZE(console_commands)
-};
+DECLARE_CONSOLE_COMMAND(port80, command_port80);
/*****************************************************************************/
/* Initialization */
int port_80_init(void)
{
- console_register_commands(&command_group);
memset(history, 0, sizeof(history));
return EC_SUCCESS;
}
diff --git a/common/usb_charge.c b/common/usb_charge.c
index 5fcf653915..28c98e4130 100644
--- a/common/usb_charge.c
+++ b/common/usb_charge.c
@@ -119,13 +119,7 @@ static int command_set_mode(int argc, char **argv)
uart_printf("Setting USB mode...\n");
return usb_charge_set_mode(port_id, mode);
}
-
-static const struct console_command console_commands[] = {
- {"usbchargemode", command_set_mode},
-};
-static const struct console_group command_group = {
- "USB Charging Control", console_commands, ARRAY_SIZE(console_commands)
-};
+DECLARE_CONSOLE_COMMAND(usbchargemode, command_set_mode);
/*****************************************************************************/
@@ -138,7 +132,5 @@ int usb_charge_init(void)
for (i = 0; i < USB_CHARGE_PORT_COUNT; ++i)
usb_charge_set_mode(i, USB_CHARGE_MODE_DOWNSTREAM_500MA);
- console_register_commands(&command_group);
return EC_SUCCESS;
}
-
diff --git a/common/vboot.c b/common/vboot.c
index ebf514d79d..4f8934bcec 100644
--- a/common/vboot.c
+++ b/common/vboot.c
@@ -85,14 +85,7 @@ static int command_reboot(int argc, char **argv)
system_reset(1);
return EC_SUCCESS;
}
-
-static const struct console_command console_commands[] = {
- {"reboot", command_reboot},
-};
-
-static const struct console_group command_group = {
- "Verified boot", console_commands, ARRAY_SIZE(console_commands)
-};
+DECLARE_CONSOLE_COMMAND(reboot, command_reboot);
/*****************************************************************************/
/* Initialization */
@@ -103,11 +96,3 @@ int vboot_pre_init(void)
jump_to_other_image();
return EC_SUCCESS;
}
-
-
-int vboot_init(void)
-{
- /* Register our internal commands */
- console_register_commands(&command_group);
- return EC_SUCCESS;
-}