diff options
author | Vincent Palatin <vpalatin@chromium.org> | 2012-01-23 23:07:58 +0000 |
---|---|---|
committer | Vincent Palatin <vpalatin@chromium.org> | 2012-01-24 00:50:08 +0000 |
commit | c21f07e58e48144a97a844668aae68644f8e8dec (patch) | |
tree | 12a0b7f04e085a0d2035e9bfbe05013530f99501 | |
parent | a2a85365d600b93ecd10d44d1a5a2115ce0252f1 (diff) | |
download | chrome-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
-rw-r--r-- | chip/lm4/adc.c | 13 | ||||
-rw-r--r-- | chip/lm4/clock.c | 13 | ||||
-rw-r--r-- | chip/lm4/ec.lds.S | 3 | ||||
-rw-r--r-- | chip/lm4/eeprom.c | 16 | ||||
-rw-r--r-- | chip/lm4/gpio.c | 20 | ||||
-rw-r--r-- | chip/lm4/i2c.c | 10 | ||||
-rw-r--r-- | chip/lm4/pwm.c | 9 | ||||
-rw-r--r-- | chip/lm4/system.c | 20 | ||||
-rw-r--r-- | chip/lm4/task.c | 16 | ||||
-rw-r--r-- | chip/lm4/temp_sensor.c | 14 | ||||
-rw-r--r-- | chip/lm4/timer.c | 16 | ||||
-rw-r--r-- | common/console.c | 50 | ||||
-rw-r--r-- | common/flash_commands.c | 27 | ||||
-rw-r--r-- | common/host_command.c | 11 | ||||
-rw-r--r-- | common/keyboard.c | 15 | ||||
-rw-r--r-- | common/main.c | 5 | ||||
-rw-r--r-- | common/memory_commands.c | 22 | ||||
-rw-r--r-- | common/port80.c | 10 | ||||
-rw-r--r-- | common/usb_charge.c | 10 | ||||
-rw-r--r-- | common/vboot.c | 17 | ||||
-rw-r--r-- | include/console.h | 17 |
21 files changed, 61 insertions, 273 deletions
diff --git a/chip/lm4/adc.c b/chip/lm4/adc.c index f4524c3adb..531411fd21 100644 --- a/chip/lm4/adc.c +++ b/chip/lm4/adc.c @@ -101,6 +101,7 @@ static int command_adc(int argc, char **argv) adc_read(ADC_CH_POT)); return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(adc, command_adc); static int command_ectemp(int argc, char **argv) @@ -109,18 +110,9 @@ static int command_ectemp(int argc, char **argv) uart_printf("EC temperature is %d K = %d C\n", t, t-273); return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(ectemp, command_ectemp); -static const struct console_command console_commands[] = { - {"adc", command_adc}, - {"ectemp", command_ectemp}, -}; -static const struct console_group command_group = { - "ADC", console_commands, ARRAY_SIZE(console_commands) -}; - - -/*****************************************************************************/ /* Initialization */ int adc_init(void) @@ -162,6 +154,5 @@ int adc_init(void) /* Enable sample sequencer 3 */ LM4_ADC_ADCACTSS |= 0x08; - console_register_commands(&command_group); return EC_SUCCESS; } diff --git a/chip/lm4/clock.c b/chip/lm4/clock.c index fcf0da99e1..c80f36ecc1 100644 --- a/chip/lm4/clock.c +++ b/chip/lm4/clock.c @@ -143,15 +143,9 @@ static int command_sleep(int argc, char **argv) return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(sleep, command_sleep); -static const struct console_command clock_commands[] = { - {"sleep", command_sleep} -}; -static const struct console_group clock_group = { - "Clock", clock_commands, ARRAY_SIZE(clock_commands) -}; - static void clock_init_pll(uint32_t value) { /** @@ -200,10 +194,5 @@ int clock_init(void) /* Osc source = internal 16MHz oscillator */ clock_init_pll(0x01400550); -#ifdef CONFIG_DEBUG - /* Register our internal commands */ - console_register_commands(&clock_group); -#endif - return EC_SUCCESS; } diff --git a/chip/lm4/ec.lds.S b/chip/lm4/ec.lds.S index c5ff6c6cb6..5750967e3d 100644 --- a/chip/lm4/ec.lds.S +++ b/chip/lm4/ec.lds.S @@ -30,6 +30,9 @@ SECTIONS __irqprio = .; *(.rodata.irqprio) __irqprio_end = .; + __cmds = .; + *(.rodata.cmds) + __cmds_end = .; *(.rodata*) . = ALIGN(4); #ifdef COMPILE_FOR_RAM diff --git a/chip/lm4/eeprom.c b/chip/lm4/eeprom.c index 266dbe3d44..c605d0e560 100644 --- a/chip/lm4/eeprom.c +++ b/chip/lm4/eeprom.c @@ -125,6 +125,7 @@ static int command_eeprom_info(int argc, char **argv) uart_printf(" Block-hide flags: 0x%08x\n", LM4_EEPROM_EEHIDE); return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(eeinfo, command_eeprom_info); static int command_eeprom_read(int argc, char **argv) @@ -160,6 +161,7 @@ static int command_eeprom_read(int argc, char **argv) block, offset, d); return rv; } +DECLARE_CONSOLE_COMMAND(eeread, command_eeprom_read); static int command_eeprom_write(int argc, char **argv) @@ -198,6 +200,7 @@ static int command_eeprom_write(int argc, char **argv) uart_puts("done.\n"); return rv; } +DECLARE_CONSOLE_COMMAND(eewrite, command_eeprom_write); static int command_eeprom_hide(int argc, char **argv) @@ -223,17 +226,7 @@ static int command_eeprom_hide(int argc, char **argv) uart_printf("Done.\n"); return rv; } - - -static const struct console_command console_commands[] = { - {"eeinfo", command_eeprom_info}, - {"eeread", command_eeprom_read}, - {"eewrite", command_eeprom_write}, - {"eehide", command_eeprom_hide}, -}; -static const struct console_group command_group = { - "EEPROM", console_commands, ARRAY_SIZE(console_commands) -}; +DECLARE_CONSOLE_COMMAND(eehide, command_eeprom_hide); /*****************************************************************************/ @@ -251,6 +244,5 @@ int eeprom_init(void) wait_for_done(); block_count = LM4_EEPROM_EESIZE >> 16; - console_register_commands(&command_group); return EC_SUCCESS; } diff --git a/chip/lm4/gpio.c b/chip/lm4/gpio.c index 7836cb776e..0c84f1d1cb 100644 --- a/chip/lm4/gpio.c +++ b/chip/lm4/gpio.c @@ -308,6 +308,7 @@ static int command_gpio_get(int argc, char **argv) } return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(gpioget, command_gpio_get); static int command_gpio_set(int argc, char **argv) @@ -345,21 +346,4 @@ static int command_gpio_set(int argc, char **argv) return gpio_set_level(i, v); } - - -static const struct console_command console_commands[] = { - {"gpioget", command_gpio_get}, - {"gpioset", command_gpio_set}, -}; -static const struct console_group command_group = { - "GPIO", console_commands, ARRAY_SIZE(console_commands) -}; - -/*****************************************************************************/ -/* Initialization */ - -int gpio_init(void) -{ - console_register_commands(&command_group); - return EC_SUCCESS; -} +DECLARE_CONSOLE_COMMAND(gpioset, command_gpio_set); diff --git a/chip/lm4/i2c.c b/chip/lm4/i2c.c index 8a9e74ec52..8ac7da8c01 100644 --- a/chip/lm4/i2c.c +++ b/chip/lm4/i2c.c @@ -192,14 +192,7 @@ static int command_scan(int argc, char **argv) uart_puts("done.\n"); return EC_SUCCESS; } - - -static const struct console_command console_commands[] = { - {"i2cscan", command_scan}, -}; -static const struct console_group command_group = { - "I2C", console_commands, ARRAY_SIZE(console_commands) -}; +DECLARE_CONSOLE_COMMAND(i2cscan, command_scan); /*****************************************************************************/ @@ -266,6 +259,5 @@ int i2c_init(void) task_enable_irq(LM4_IRQ_I2C4); task_enable_irq(LM4_IRQ_I2C5); - console_register_commands(&command_group); return EC_SUCCESS; } diff --git a/chip/lm4/pwm.c b/chip/lm4/pwm.c index 655fda18e1..a1810ab128 100644 --- a/chip/lm4/pwm.c +++ b/chip/lm4/pwm.c @@ -74,6 +74,7 @@ static int command_fan_info(int argc, char **argv) (LM4_FAN_FANSTS >> (2 * FAN_CH_CPU)) & 0x03); return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(faninfo, command_fan_info); static int command_fan_set(int argc, char **argv) @@ -107,6 +108,7 @@ static int command_fan_set(int argc, char **argv) uart_printf("Done.\n"); return rv; } +DECLARE_CONSOLE_COMMAND(fanset, command_fan_set); /* TODO: this is a temporary command for debugging tach issues */ @@ -141,6 +143,7 @@ static int command_fan_duty(int argc, char **argv) return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(fanduty, command_fan_duty); static int command_kblight(int argc, char **argv) @@ -166,7 +169,7 @@ static int command_kblight(int argc, char **argv) uart_printf("Done.\n"); return rv; } - +DECLARE_CONSOLE_COMMAND(kblight, command_kblight); static const struct console_command console_commands[] = { {"fanduty", command_fan_duty}, @@ -174,9 +177,6 @@ static const struct console_command console_commands[] = { {"fanset", command_fan_set}, {"kblight", command_kblight}, }; -static const struct console_group command_group = { - "PWM", console_commands, ARRAY_SIZE(console_commands) -}; /*****************************************************************************/ @@ -225,6 +225,5 @@ int pwm_init(void) /* Enable CPU fan and keyboard backlight */ LM4_FAN_FANCTL |= (1 << FAN_CH_CPU) | (1 << FAN_CH_KBLIGHT); - console_register_commands(&command_group); return EC_SUCCESS; } diff --git a/chip/lm4/system.c b/chip/lm4/system.c index c1ff285187..8cf0dc6bb3 100644 --- a/chip/lm4/system.c +++ b/chip/lm4/system.c @@ -12,20 +12,6 @@ #include "util.h" #include "version.h" -/* Forward declarations for console commands */ -static int command_sysinfo(int argc, char **argv); -static int command_set_scratchpad(int argc, char **argv); -static int command_hibernate(int argc, char **argv); - -static const struct console_command console_commands[] = { - {"setscratch", command_set_scratchpad}, - {"sysinfo", command_sysinfo}, - {"hibernate", command_hibernate} -}; -static const struct console_group command_group = { - "System", console_commands, ARRAY_SIZE(console_commands) -}; - struct version_struct { uint32_t cookie1; char version[32]; @@ -161,8 +147,7 @@ int system_init(void) * this image. */ LM4_SYSTEM_RESC = 0; - /* Register our internal commands */ - return console_register_commands(&command_group); + return EC_SUCCESS; } @@ -339,6 +324,7 @@ static int command_sysinfo(int argc, char **argv) uart_printf("Firmware copy: %s\n", system_get_image_copy_string()); return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(sysinfo, command_sysinfo); static int command_set_scratchpad(int argc, char **argv) @@ -359,6 +345,7 @@ static int command_set_scratchpad(int argc, char **argv) uart_printf("Setting scratchpad to 0x%08x\n", s); return system_set_scratchpad(s); } +DECLARE_CONSOLE_COMMAND(setscratchpad, command_set_scratchpad); static int command_hibernate(int argc, char **argv) { @@ -380,3 +367,4 @@ static int command_hibernate(int argc, char **argv) return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(hibernate, command_hibernate); diff --git a/chip/lm4/task.c b/chip/lm4/task.c index e01be96bdd..e400457e30 100644 --- a/chip/lm4/task.c +++ b/chip/lm4/task.c @@ -316,6 +316,7 @@ int command_task_info(int argc, char **argv) } return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(taskinfo, command_task_info); static int command_task_ready(int argc, char **argv) @@ -330,15 +331,7 @@ static int command_task_ready(int argc, char **argv) return EC_SUCCESS; } - - -static const struct console_command task_commands[] = { - {"taskinfo", command_task_info}, - {"taskready", command_task_ready} -}; -static const struct console_group task_group = { - "Task", task_commands, ARRAY_SIZE(task_commands) -}; +DECLARE_CONSOLE_COMMAND(taskready, command_task_ready); #endif @@ -351,10 +344,5 @@ int task_init(void) /* Initialize IRQs */ __nvic_init_irqs(); -#ifdef CONFIG_DEBUG - /* Register our internal commands */ - console_register_commands(&task_group); -#endif - return EC_SUCCESS; } diff --git a/chip/lm4/temp_sensor.c b/chip/lm4/temp_sensor.c index bdb8b42ea6..1aafa00f4c 100644 --- a/chip/lm4/temp_sensor.c +++ b/chip/lm4/temp_sensor.c @@ -92,6 +92,7 @@ static int command_temps(int argc, char **argv) return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(temps, command_temps); /* TODO: the battery charger would normally be on a separate I2C bus. @@ -126,6 +127,7 @@ static int command_charger(int argc, char **argv) return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(charger, command_charger); /* TODO: the battery would normally be on a separate I2C bus. For @@ -160,16 +162,7 @@ static int command_battery(int argc, char **argv) return EC_SUCCESS; } - - -static const struct console_command console_commands[] = { - {"temps", command_temps}, - {"charger", command_charger}, - {"battery", command_battery}, -}; -static const struct console_group command_group = { - "Temp sensor", console_commands, ARRAY_SIZE(console_commands) -}; +DECLARE_CONSOLE_COMMAND(battery, command_battery); /*****************************************************************************/ @@ -192,6 +185,5 @@ int temp_sensor_init(void) i2c_write16(I2C_PORT_THERMAL, TEMP0_ADDR, 0x02, 0x7500); #endif - console_register_commands(&command_group); return EC_SUCCESS; } diff --git a/chip/lm4/timer.c b/chip/lm4/timer.c index 7c105a9ca7..cb4b24fb77 100644 --- a/chip/lm4/timer.c +++ b/chip/lm4/timer.c @@ -229,6 +229,7 @@ static int command_wait(int argc, char **argv) return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(waitms, command_wait); static int command_get_time(int argc, char **argv) @@ -238,6 +239,7 @@ static int command_get_time(int argc, char **argv) return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(gettime, command_get_time); int command_timer_info(int argc, char **argv) @@ -258,16 +260,7 @@ int command_timer_info(int argc, char **argv) } return EC_SUCCESS; } - - -static const struct console_command timer_commands[] = { - {"waitms", command_wait}, - {"timerinfo", command_timer_info}, - {"gettime", command_get_time} -}; -static const struct console_group timer_group = { - "Timer", timer_commands, ARRAY_SIZE(timer_commands) -}; +DECLARE_CONSOLE_COMMAND(timerinfo, command_timer_info); int timer_init(void) @@ -276,8 +269,5 @@ int timer_init(void) __hw_clock_source_init(); - /* Register our internal commands */ - console_register_commands(&timer_group); - return EC_SUCCESS; } 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; -} diff --git a/include/console.h b/include/console.h index f8f76860da..4aeca1c5f4 100644 --- a/include/console.h +++ b/include/console.h @@ -19,14 +19,6 @@ struct console_command { }; -/* Console command group */ -struct console_group { - const char *group_name; /* Name of the command group */ - const struct console_command *commands; /* List of commands */ - int command_count; /* Number of commands in list */ -}; - - /* Initializes the console module. */ int console_init(void); @@ -34,8 +26,11 @@ int console_init(void); /* Called by UART when a line of input is pending. */ void console_has_input(void); - -/* Registers a group of console commands. */ -int console_register_commands(const struct console_group *group); +/* Register a console command handler */ +#define DECLARE_CONSOLE_COMMAND(name, routine) \ + static const char __con_cmd_label_##name[] = #name; \ + const struct console_command __con_cmd_##name \ + __attribute__((section(".rodata.cmds"))) \ + = {__con_cmd_label_##name, routine} #endif /* __CROS_EC_CONSOLE_H */ |