diff options
33 files changed, 495 insertions, 266 deletions
diff --git a/board/bds/board.h b/board/bds/board.h index dd4d887ad0..f22b1e8603 100644 --- a/board/bds/board.h +++ b/board/bds/board.h @@ -8,6 +8,9 @@ #ifndef __BOARD_H #define __BOARD_H +/* Optional features */ +#define CONFIG_CONSOLE_CMDHELP + enum adc_channel { ADC_CH_EC_TEMP = 0, /* EC internal die temperature in degrees K. */ diff --git a/board/link/board.h b/board/link/board.h index e7ba6abfed..e7cdda0ac1 100644 --- a/board/link/board.h +++ b/board/link/board.h @@ -12,6 +12,7 @@ #define CONFIG_BATTERY_ATL706486 #define CONFIG_CHARGER #define CONFIG_CHARGER_BQ24725 +#define CONFIG_CONSOLE_CMDHELP #define CONFIG_EOPTION #define CONFIG_ONEWIRE #define CONFIG_LPC diff --git a/chip/lm4/adc.c b/chip/lm4/adc.c index fa1d06e2b8..03516a5eb3 100644 --- a/chip/lm4/adc.c +++ b/chip/lm4/adc.c @@ -184,7 +184,10 @@ static int command_ectemp(int argc, char **argv) ccprintf("EC temperature is %d K = %d C\n", t, t-273); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(ectemp, command_ectemp); +DECLARE_CONSOLE_COMMAND(ectemp, command_ectemp, + NULL, + "Print EC temperature", + NULL); #endif @@ -198,7 +201,10 @@ static int command_adc(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(adc, command_adc); +DECLARE_CONSOLE_COMMAND(adc, command_adc, + NULL, + "Print ADC channels", + NULL); /*****************************************************************************/ /* Initialization */ diff --git a/chip/lm4/clock.c b/chip/lm4/clock.c index e709fa0b62..a342404fd5 100644 --- a/chip/lm4/clock.c +++ b/chip/lm4/clock.c @@ -197,7 +197,10 @@ static int command_sleep(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(sleep, command_sleep); +DECLARE_CONSOLE_COMMAND(sleep, command_sleep, + "[level [clock]]", + "Drop into sleep", + NULL); static int command_pll(int argc, char **argv) @@ -215,7 +218,7 @@ static int command_pll(int argc, char **argv) char *e; div = strtoi(argv[1], &e, 10); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; LM4_SYSTEM_RCC = LM4_SYSTEM_RCC_SYSDIV(div - 1) | LM4_SYSTEM_RCC_BYPASS | @@ -237,7 +240,10 @@ static int command_pll(int argc, char **argv) ccprintf("Clock: %d Hz\n", clock_get_freq()); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(pll, command_pll); +DECLARE_CONSOLE_COMMAND(pll, command_pll, + "[ on | off | <div> ]", + "Get/set PLL state", + NULL); /*****************************************************************************/ /* Initialization */ diff --git a/chip/lm4/eeprom.c b/chip/lm4/eeprom.c index 3490e6d183..dc3a17a36b 100644 --- a/chip/lm4/eeprom.c +++ b/chip/lm4/eeprom.c @@ -124,7 +124,10 @@ static int command_eeprom_info(int argc, char **argv) LM4_EEPROM_EEHIDE); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(eeinfo, command_eeprom_info); +DECLARE_CONSOLE_COMMAND(eeinfo, command_eeprom_info, + NULL, + "Print EEPROM info", + NULL); static int command_eeprom_read(int argc, char **argv) @@ -136,16 +139,16 @@ static int command_eeprom_read(int argc, char **argv) uint32_t d; if (argc < 2) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; block = strtoi(argv[1], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; if (argc > 2) { offset = strtoi(argv[2], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM2; } rv = eeprom_read(block, offset, sizeof(d), (char *)&d); @@ -153,7 +156,10 @@ static int command_eeprom_read(int argc, char **argv) ccprintf("%d:%d = 0x%08x\n", block, offset, d); return rv; } -DECLARE_CONSOLE_COMMAND(eeread, command_eeprom_read); +DECLARE_CONSOLE_COMMAND(eeread, command_eeprom_read, + "block [offset]", + "Read a word of EEPROM", + NULL); static int command_eeprom_write(int argc, char **argv) @@ -164,22 +170,25 @@ static int command_eeprom_write(int argc, char **argv) uint32_t d; if (argc < 4) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; block = strtoi(argv[1], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; offset = strtoi(argv[2], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM2; d = strtoi(argv[3], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM3; ccprintf("Writing 0x%08x to %d:%d...\n", d, block, offset); return eeprom_write(block, offset, sizeof(d), (char *)&d); } -DECLARE_CONSOLE_COMMAND(eewrite, command_eeprom_write); +DECLARE_CONSOLE_COMMAND(eewrite, command_eeprom_write, + "block offset value", + "Write a word of EEPROM", + NULL); #ifdef CONSOLE_COMMAND_EEHIDE @@ -189,16 +198,19 @@ static int command_eeprom_hide(int argc, char **argv) char *e; if (argc < 2) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; block = strtoi(argv[1], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; ccprintf("Hiding block %d\n", block); return eeprom_hide(block); } -DECLARE_CONSOLE_COMMAND(eehide, command_eeprom_hide); +DECLARE_CONSOLE_COMMAND(eehide, command_eeprom_hide, + "block", + "Hide a block of EEPROM", + NULL); #endif diff --git a/chip/lm4/i2c.c b/chip/lm4/i2c.c index be8b2067f9..5a7e8387ff 100644 --- a/chip/lm4/i2c.c +++ b/chip/lm4/i2c.c @@ -373,25 +373,25 @@ static int command_i2cread(int argc, char **argv) int d, i; if (argc < 3) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; port = strtoi(argv[1], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; for (i = 0; i < I2C_PORTS_USED && port != i2c_ports[i].port; i++) ; if (i >= I2C_PORTS_USED) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; addr = strtoi(argv[2], &e, 0); if (*e || (addr & 0x01)) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM2; if (argc > 3) { count = strtoi(argv[3], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM3; } ccprintf("Reading %d bytes from %d:0x%02x:", count, port, addr); @@ -414,7 +414,10 @@ static int command_i2cread(int argc, char **argv) ccputs("\n"); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(i2cread, command_i2cread); +DECLARE_CONSOLE_COMMAND(i2cread, command_i2cread, + "port addr [count]", + "Read from I2C", + NULL); static int command_scan(int argc, char **argv) @@ -425,7 +428,10 @@ static int command_scan(int argc, char **argv) scan_bus(i2c_ports[i].port, i2c_ports[i].name); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(i2cscan, command_scan); +DECLARE_CONSOLE_COMMAND(i2cscan, command_scan, + NULL, + "Scan I2C ports for devices", + NULL); /*****************************************************************************/ diff --git a/chip/lm4/peci.c b/chip/lm4/peci.c index 88f3f95b6e..339f300d75 100644 --- a/chip/lm4/peci.c +++ b/chip/lm4/peci.c @@ -107,7 +107,10 @@ static int command_peci_temp(int argc, char **argv) ccprintf("CPU temp = %d K = %d C\n", t, t - 273); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(pecitemp, command_peci_temp); +DECLARE_CONSOLE_COMMAND(pecitemp, command_peci_temp, + NULL, + "Print CPU temperature", + NULL); /*****************************************************************************/ /* Initialization */ diff --git a/chip/lm4/power_button.c b/chip/lm4/power_button.c index 9ec258ba51..fe7b75d8e5 100644 --- a/chip/lm4/power_button.c +++ b/chip/lm4/power_button.c @@ -569,7 +569,7 @@ static int command_powerbtn(int argc, char **argv) if (argc > 1) { ms = strtoi(argv[1], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; } ccprintf("Simulating %d ms power button press.\n", ms); @@ -586,7 +586,10 @@ static int command_powerbtn(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(powerbtn, command_powerbtn); +DECLARE_CONSOLE_COMMAND(powerbtn, command_powerbtn, + "[msec]", + "Simulate power button press", + NULL); static int command_lidopen(int argc, char **argv) @@ -594,7 +597,10 @@ static int command_lidopen(int argc, char **argv) lid_switch_open(get_time().val); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(lidopen, command_lidopen); +DECLARE_CONSOLE_COMMAND(lidopen, command_lidopen, + NULL, + "Simulate lid open", + NULL); static int command_lidclose(int argc, char **argv) @@ -602,7 +608,10 @@ static int command_lidclose(int argc, char **argv) lid_switch_close(get_time().val); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(lidclose, command_lidclose); +DECLARE_CONSOLE_COMMAND(lidclose, command_lidclose, + NULL, + "Simulate lid close", + NULL); static int command_mmapinfo(int argc, char **argv) { @@ -624,4 +633,7 @@ static int command_mmapinfo(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(mmapinfo, command_mmapinfo); +DECLARE_CONSOLE_COMMAND(mmapinfo, command_mmapinfo, + NULL, + "Print memmap switch state", + NULL); diff --git a/chip/lm4/pwm.c b/chip/lm4/pwm.c index 1c1f5fcb59..79c47e09fc 100644 --- a/chip/lm4/pwm.c +++ b/chip/lm4/pwm.c @@ -168,7 +168,10 @@ static int command_fan_info(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(faninfo, command_fan_info); +DECLARE_CONSOLE_COMMAND(faninfo, command_fan_info, + NULL, + "Print fan info", + NULL); static int command_fan_set(int argc, char **argv) @@ -177,11 +180,11 @@ static int command_fan_set(int argc, char **argv) char *e; if (argc < 2) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; rpm = strtoi(argv[1], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; /* Move the fan to automatic control */ if (LM4_FAN_FANCH(FAN_CH_CPU) & 0x0001) { @@ -198,7 +201,10 @@ static int command_fan_set(int argc, char **argv) return pwm_set_fan_target_rpm(rpm); } -DECLARE_CONSOLE_COMMAND(fanset, command_fan_set); +DECLARE_CONSOLE_COMMAND(fanset, command_fan_set, + "rpm", + "Set fan speed", + NULL); #ifdef CONSOLE_COMMAND_FANDUTY @@ -209,12 +215,11 @@ static int command_fan_duty(int argc, char **argv) char *e; if (argc < 2) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; d = strtoi(argv[1], &e, 0); - if (*e) { - return EC_ERROR_INVAL; - } + if (*e) + return EC_ERROR_PARAM1; pwm = (MAX_PWM * d) / 100; ccprintf("Setting fan duty cycle to %d%% = 0x%x...\n", d, pwm); @@ -237,7 +242,10 @@ static int command_fan_duty(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(fanduty, command_fan_duty); +DECLARE_CONSOLE_COMMAND(fanduty, command_fan_duty, + "percent", + "Set fan duty cycle", + NULL); #endif @@ -249,14 +257,17 @@ static int command_kblight(int argc, char **argv) char *e; int i = strtoi(argv[1], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; rv = pwm_set_keyboard_backlight(i); } ccprintf("Keyboard backlight: %d%%\n", pwm_get_keyboard_backlight()); return rv; } -DECLARE_CONSOLE_COMMAND(kblight, command_kblight); +DECLARE_CONSOLE_COMMAND(kblight, command_kblight, + "percent", + "Set keyboard backlight", + NULL); /*****************************************************************************/ /* Initialization */ diff --git a/chip/lm4/uart.c b/chip/lm4/uart.c index baa8129602..25e04da908 100644 --- a/chip/lm4/uart.c +++ b/chip/lm4/uart.c @@ -254,4 +254,7 @@ static int command_comxtest(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(comxtest, command_comxtest); +DECLARE_CONSOLE_COMMAND(comxtest, command_comxtest, + "[string]", + "Write test data to COMx uart", + NULL); diff --git a/common/charger_bq24725.c b/common/charger_bq24725.c index 6693a1bebe..84dc8897a2 100644 --- a/common/charger_bq24725.c +++ b/common/charger_bq24725.c @@ -234,29 +234,30 @@ static int print_info(void) static int command_charger(int argc, char **argv) { int d; - char *endptr; + char *e; if (argc != 3) return print_info(); if (strcasecmp(argv[1], "input") == 0) { - d = strtoi(argv[2], &endptr, 0); - if (*endptr) - return EC_ERROR_INVAL; + d = strtoi(argv[2], &e, 0); + if (*e) + return EC_ERROR_PARAM2; return charger_set_input_current(d); } else if (strcasecmp(argv[1], "current") == 0) { - d = strtoi(argv[2], &endptr, 0); - if (*endptr) - return EC_ERROR_INVAL; + d = strtoi(argv[2], &e, 0); + if (*e) + return EC_ERROR_PARAM2; return charger_set_current(d); } else if (strcasecmp(argv[1], "voltage") == 0) { - d = strtoi(argv[2], &endptr, 0); - if (*endptr) { - return EC_ERROR_INVAL; - } + d = strtoi(argv[2], &e, 0); + if (*e) + return EC_ERROR_PARAM2; return charger_set_voltage(d); } else - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; } -DECLARE_CONSOLE_COMMAND(charger, command_charger); - +DECLARE_CONSOLE_COMMAND(charger, command_charger, + "[input | current | voltage] [newval]", + "Get or set charger param(s)", + NULL); diff --git a/common/console.c b/common/console.c index 16a17fade7..e1c1365f11 100644 --- a/common/console.c +++ b/common/console.c @@ -124,8 +124,8 @@ static int split_words(char *input, int max_argc, int *argc, char **argv) } -/* Finds a command by name. Returns the command structure, or NULL if - * no match found. */ +/* Find a command by name. Returns the command structure, or NULL if no match + * found. */ static const struct console_command *find_command(char *name) { const struct console_command *cmd, *match = NULL; @@ -143,14 +143,14 @@ static const struct console_command *find_command(char *name) } -/* Handles a line of input containing a single command. - * - * Modifies the input string during parsing. */ +/* Handle a line of input containing a single command. Modifies the input + * string during parsing. */ static int handle_command(char *input) { const struct console_command *cmd; char *argv[MAX_ARGS_PER_COMMAND]; int argc = 0; + int rv; /* Split input into words. Ignore words past our limit. */ split_words(input, MAX_ARGS_PER_COMMAND, &argc, argv); @@ -160,11 +160,32 @@ static int handle_command(char *input) return EC_SUCCESS; cmd = find_command(argv[0]); - if (cmd) - return cmd->handler(argc, argv); + if (!cmd) { + ccprintf("Command '%s' not found or ambiguous.\n", argv[0]); + return EC_ERROR_UNKNOWN; + } - ccprintf("Command '%s' not found or ambiguous.\n", argv[0]); - return EC_ERROR_UNKNOWN; + rv = cmd->handler(argc, argv); + if (rv == EC_SUCCESS) + return rv; + + /* Print more info for errors */ + if (rv == EC_ERROR_INVAL) + ccputs("Command usage/param invalid.\n"); + else if (rv == EC_ERROR_PARAM_COUNT) + ccputs("Wrong number of params.\n"); + else if (rv >= EC_ERROR_PARAM1 && rv <= EC_ERROR_PARAM9) + ccprintf("Parameter %d invalid.\n", rv - EC_ERROR_PARAM1 + 1); + else if (rv != EC_SUCCESS) { + ccprintf("Command returned error %d\n", rv); + return rv; + } + +#ifdef CONFIG_CONSOLE_CMDHELP + if (cmd->argdesc) + ccprintf("Usage: %s %s\n", cmd->name, cmd->argdesc); +#endif + return rv; } @@ -184,20 +205,11 @@ static int console_init(void) /* handle a console command */ static void console_process(void) { - int rv; - /* Process all the pending commands. Need to do this all at once * since our interrupt may have been triggered multiple times. */ - /* TODO: Go to sleep briefly between commands to give lower - * priority tasks a chance to run? */ while (uart_peek('\n') >= 0) { uart_gets(input_buf, sizeof(input_buf)); - - rv = handle_command(input_buf); - if (rv == EC_ERROR_INVAL) - ccputs("Command usage/param invalid.\n"); - else if (rv != EC_SUCCESS) - ccprintf("Command returned error %d\n", rv); + handle_command(input_buf); ccputs(PROMPT); } } @@ -216,7 +228,7 @@ void console_task(void) while (1) { console_process(); - /* wait for the next command message */ + /* Wait for the next command message */ task_wait_event(-1); } } @@ -233,8 +245,35 @@ static int command_help(int argc, char **argv) const int rows = (ncmds + cols - 1) / cols; int i, j; - ccputs("Known commands:\n"); +#ifdef CONFIG_CONSOLE_CMDHELP + if (argc == 2) { + const struct console_command *cmd; + + if (!strcasecmp(argv[1], "list")) { + ccputs("Known commands:\n"); + for (i = 0; i < ncmds; i++) { + ccprintf(" %-15s%s\n", + __cmds[i].name, __cmds[i].shorthelp); + cflush(); + } + ccputs("HELP CMD = help on CMD.\n"); + return EC_SUCCESS; + } + cmd = find_command(argv[1]); + if (!cmd) { + ccprintf("Command '%s' not found or ambiguous.\n", + argv[1]); + return EC_ERROR_UNKNOWN; + } + ccprintf("Usage: %s %s\n", cmd->name, + (cmd->argdesc ? cmd->argdesc : "")); + if (cmd->shorthelp) + ccprintf("%s\n", cmd->shorthelp); + return EC_SUCCESS; + } +#endif + ccputs("Known commands:\n"); for (i = 0; i < rows; i++) { ccputs(" "); for (j = 0; j < cols; j++) { @@ -247,9 +286,17 @@ static int command_help(int argc, char **argv) cflush(); } +#ifdef CONFIG_CONSOLE_CMDHELP + ccputs("HELP LIST = more info; "); + ccputs("HELP CMD = help on CMD.\n"); +#endif + return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(help, command_help); +DECLARE_CONSOLE_COMMAND(help, command_help, + "[ list | <name> ]", + "Print command help", + NULL); /* Set active channels */ @@ -262,7 +309,7 @@ static int command_ch(int argc, char **argv) if (argc == 2) { int m = strtoi(argv[1], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; /* No disabling the command output channel */ channel_mask = m | CC_MASK(CC_COMMAND); @@ -283,4 +330,7 @@ static int command_ch(int argc, char **argv) } return EC_SUCCESS; }; -DECLARE_CONSOLE_COMMAND(chan, command_ch); +DECLARE_CONSOLE_COMMAND(chan, command_ch, + "[mask]", + "Get or set console channel mask", + NULL); diff --git a/common/eoption.c b/common/eoption.c index 83a94647fc..58d0ce22e0 100644 --- a/common/eoption.c +++ b/common/eoption.c @@ -141,7 +141,7 @@ static int command_eoption_get(int argc, char **argv) if (argc == 2) { i = find_option_by_name(argv[1], bool_opts); if (i == -1) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; d = bool_opts + i; ccprintf(" %d %s\n", eoption_get_bool(i), d->name); return EC_SUCCESS; @@ -157,7 +157,10 @@ static int command_eoption_get(int argc, char **argv) } return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(optget, command_eoption_get); +DECLARE_CONSOLE_COMMAND(optget, command_eoption_get, + "[name]", + "Print EC option(s)", + NULL); static int command_eoption_set(int argc, char **argv) @@ -166,16 +169,19 @@ static int command_eoption_set(int argc, char **argv) int v, i; if (argc < 3) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; v = strtoi(argv[2], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM2; i = find_option_by_name(argv[1], bool_opts); if (i == -1) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; return eoption_set_bool(i, v); } -DECLARE_CONSOLE_COMMAND(optset, command_eoption_set); +DECLARE_CONSOLE_COMMAND(optset, command_eoption_set, + "name value", + "Set EC option", + NULL); diff --git a/common/flash_commands.c b/common/flash_commands.c index ade35b15c9..cfae2124a3 100644 --- a/common/flash_commands.c +++ b/common/flash_commands.c @@ -13,30 +13,32 @@ #include "system.h" #include "util.h" -/* Parse offset and size from command line argv[0] and argv[1]. +/* Parse offset and size from command line argv[shift] and argv[shift+1] * - * Default values: If argc<1, leaves offset unchanged, returning error if - * *offset<0. If argc<2, leaves size unchanged, returning error if *size<0. */ -static int parse_offset_size(int argc, char **argv, int *offset, int *size) + * Default values: If argc<=shift, leaves offset unchanged, returning error if + * *offset<0. If argc<shift+1, leaves size unchanged, returning error if + * *size<0. */ +static int parse_offset_size(int argc, char **argv, int shift, + int *offset, int *size) { char *e; int i; - if (argc >= 1) { - i = (uint32_t)strtoi(argv[0], &e, 0); + if (argc > shift) { + i = (uint32_t)strtoi(argv[shift], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; *offset = i; } else if (*offset < 0) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; - if (argc >= 2) { - i = (uint32_t)strtoi(argv[1], &e, 0); + if (argc > shift + 1) { + i = (uint32_t)strtoi(argv[shift + 1], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM2; *size = i; } else if (*size < 0) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; return EC_SUCCESS; } @@ -82,7 +84,10 @@ static int command_flash_info(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(flashinfo, command_flash_info); +DECLARE_CONSOLE_COMMAND(flashinfo, command_flash_info, + NULL, + "Print flash info", + NULL); static int command_flash_erase(int argc, char **argv) @@ -91,14 +96,17 @@ static int command_flash_erase(int argc, char **argv) int size = flash_get_erase_block_size(); int rv; - rv = parse_offset_size(argc - 1, argv + 1, &offset, &size); + rv = parse_offset_size(argc, argv, 1, &offset, &size); if (rv) return rv; ccprintf("Erasing %d bytes at 0x%x...\n", size, offset, offset); return flash_erase(offset, size); } -DECLARE_CONSOLE_COMMAND(flasherase, command_flash_erase); +DECLARE_CONSOLE_COMMAND(flasherase, command_flash_erase, + "offset [size]", + "Erase flash", + NULL); static int command_flash_write(int argc, char **argv) @@ -110,7 +118,7 @@ static int command_flash_write(int argc, char **argv) int i; - rv = parse_offset_size(argc - 1, argv + 1, &offset, &size); + rv = parse_offset_size(argc, argv, 1, &offset, &size); if (rv) return rv; @@ -137,7 +145,10 @@ static int command_flash_write(int argc, char **argv) return rv; } -DECLARE_CONSOLE_COMMAND(flashwrite, command_flash_write); +DECLARE_CONSOLE_COMMAND(flashwrite, command_flash_write, + "offset [size]", + "Write pattern to flash", + NULL); static int command_flash_wp(int argc, char **argv) @@ -147,7 +158,7 @@ static int command_flash_wp(int argc, char **argv) int rv; if (argc < 2) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; /* Commands that don't need offset and size */ if (!strcasecmp(argv[1], "lock")) @@ -156,7 +167,7 @@ static int command_flash_wp(int argc, char **argv) return flash_lock_protect(0); /* All remaining commands need offset and size */ - rv = parse_offset_size(argc - 2, argv + 2, &offset, &size); + rv = parse_offset_size(argc, argv, 2, &offset, &size); if (rv) return rv; @@ -167,9 +178,12 @@ static int command_flash_wp(int argc, char **argv) else if (!strcasecmp(argv[1], "clear")) return flash_set_protect(offset, size, 0); else - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; } -DECLARE_CONSOLE_COMMAND(flashwp, command_flash_wp); +DECLARE_CONSOLE_COMMAND(flashwp, command_flash_wp, + "<lock | unlock | now | set | clear> offset [size]", + "Print or modify flash write protect", + NULL); /*****************************************************************************/ /* Host commands */ diff --git a/common/gaia_power.c b/common/gaia_power.c index 18e319368b..5a9f5bde3d 100644 --- a/common/gaia_power.c +++ b/common/gaia_power.c @@ -402,4 +402,7 @@ static int command_force_power(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(forcepower, command_force_power); +DECLARE_CONSOLE_COMMAND(forcepower, command_force_power, + NULL, + "Force power on", + NULL); diff --git a/common/gpio_commands.c b/common/gpio_commands.c index ca8487533d..3327e9ae9c 100644 --- a/common/gpio_commands.c +++ b/common/gpio_commands.c @@ -58,7 +58,7 @@ static int command_gpio_get(int argc, char **argv) if (argc == 2) { i = find_signal_by_name(argv[1]); if (i == GPIO_COUNT) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; g = gpio_list + i; v = gpio_get_level(i); changed = last_val_changed(i, v); @@ -82,7 +82,10 @@ static int command_gpio_get(int argc, char **argv) } return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(gpioget, command_gpio_get); +DECLARE_CONSOLE_COMMAND(gpioget, command_gpio_get, + "[name]", + "Read GPIO value(s)", + NULL); static int command_gpio_set(int argc, char **argv) @@ -92,23 +95,26 @@ static int command_gpio_set(int argc, char **argv) int v, i; if (argc < 3) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; i = find_signal_by_name(argv[1]); if (i == GPIO_COUNT) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; g = gpio_list + i; if (!g->mask) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; if (!(g->flags & GPIO_OUTPUT)) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; v = strtoi(argv[2], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM2; return gpio_set_level(i, v); } -DECLARE_CONSOLE_COMMAND(gpioset, command_gpio_set); +DECLARE_CONSOLE_COMMAND(gpioset, command_gpio_set, + "name <0 | 1>", + "Set a GPIO", + NULL); diff --git a/common/host_event_commands.c b/common/host_event_commands.c index 70ee5a102c..507d603f7b 100644 --- a/common/host_event_commands.c +++ b/common/host_event_commands.c @@ -20,7 +20,7 @@ static int command_host_event(int argc, char **argv) char *e; int i = strtoi(argv[2], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM2; if (!strcasecmp(argv[1], "set")) lpc_set_host_events(i); @@ -33,7 +33,7 @@ static int command_host_event(int argc, char **argv) else if (!strcasecmp(argv[1], "wake")) lpc_set_host_event_mask(LPC_HOST_EVENT_WAKE, i); else - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; } /* Print current SMI/SCI status */ @@ -46,7 +46,10 @@ static int command_host_event(int argc, char **argv) lpc_get_host_event_mask(LPC_HOST_EVENT_WAKE)); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(hostevent, command_host_event); +DECLARE_CONSOLE_COMMAND(hostevent, command_host_event, + "[set | clear | smi | sci | wake] [mask]", + "Print / set host event state", + NULL); /*****************************************************************************/ /* Host commands */ diff --git a/common/keyboard.c b/common/keyboard.c index 6b2dc48088..8b05485d2b 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -727,7 +727,10 @@ static int command_typematic(int argc, char **argv) ccputs("\n"); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(typematic, command_typematic); +DECLARE_CONSOLE_COMMAND(typematic, command_typematic, + "[first] [inter]", + "Get/set typematic delays", + NULL); static int command_codeset(int argc, char **argv) @@ -740,7 +743,7 @@ static int command_codeset(int argc, char **argv) scancode_set = set; break; default: - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; } } @@ -748,7 +751,10 @@ static int command_codeset(int argc, char **argv) ccprintf("I8042_XLATE: %d\n", controller_ram[0] & I8042_XLATE ? 1 : 0); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(codeset, command_codeset); +DECLARE_CONSOLE_COMMAND(codeset, command_codeset, + "[set]", + "Get/set keyboard codeset", + NULL); static int command_controller_ram(int argc, char **argv) @@ -756,11 +762,11 @@ static int command_controller_ram(int argc, char **argv) int index; if (argc < 2) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; index = strtoi(argv[1], NULL, 0); if (index >= 0x20) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; if (argc >= 3) update_ctl_ram(index, strtoi(argv[2], NULL, 0)); @@ -768,7 +774,10 @@ static int command_controller_ram(int argc, char **argv) ccprintf("%d = 0x%02x\n", index, controller_ram[index]); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(ctrlram, command_controller_ram); +DECLARE_CONSOLE_COMMAND(ctrlram, command_controller_ram, + "index [value]", + "Get/set keyboard controller RAM", + NULL); static int command_keyboard_press(int argc, char **argv) @@ -791,15 +800,15 @@ static int command_keyboard_press(int argc, char **argv) c = strtoi(argv[1], &e, 0); if (*e || c < 0 || c >= CROS_COL_NUM) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; r = strtoi(argv[2], &e, 0); if (*e || r < 0 || r >= CROS_ROW_NUM) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM2; p = strtoi(argv[3], &e, 0); if (*e || p < 0 || p > 1) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM3; if ((simulated_key[c] & (1 << r)) == (p << r)) return EC_SUCCESS; @@ -811,7 +820,10 @@ static int command_keyboard_press(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(kbpress, command_keyboard_press); +DECLARE_CONSOLE_COMMAND(kbpress, command_keyboard_press, + "[col] [row] [0 | 1]", + "Simulate keypress", + NULL); static int command_keyboard_log(int argc, char **argv) @@ -841,11 +853,14 @@ static int command_keyboard_log(int argc, char **argv) shared_mem_release(kblog); kblog = NULL; } else - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(kblog, command_keyboard_log); +DECLARE_CONSOLE_COMMAND(kblog, command_keyboard_log, + "[on | off]", + "Print or toggle keyboard event log", + NULL); /* Preserves the states of keyboard controller to keep the initialized states diff --git a/common/lightbar.c b/common/lightbar.c index 40adeff920..e440b04620 100644 --- a/common/lightbar.c +++ b/common/lightbar.c @@ -832,10 +832,10 @@ static int command_lightbar(int argc, char **argv) return 0; } num = 0xff & strtoi(argv[2], &e, 16); - if (e && *e) + if (*e) num = find_msg_by_name(argv[2]); if (num >= LIGHTBAR_NUM_SEQUENCES) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM2; lightbar_sequence(num); return EC_SUCCESS; } @@ -867,4 +867,7 @@ static int command_lightbar(int argc, char **argv) return EC_ERROR_INVAL; } -DECLARE_CONSOLE_COMMAND(lightbar, command_lightbar); +DECLARE_CONSOLE_COMMAND(lightbar, command_lightbar, + "[on | off | init | brightness | seq] | [ctrl reg val]", + "Get/set lightbar state", + NULL); diff --git a/common/memory_commands.c b/common/memory_commands.c index a313379e86..46df50e74d 100644 --- a/common/memory_commands.c +++ b/common/memory_commands.c @@ -13,11 +13,18 @@ static int command_write_word(int argc, char **argv) { volatile uint32_t *address; uint32_t value; + char *e; if (argc != 3) - return EC_ERROR_INVAL; - address = (uint32_t*)strtoi(argv[1], NULL, 0); - value = strtoi(argv[2], NULL, 0); + return EC_ERROR_PARAM_COUNT; + + address = (uint32_t *)strtoi(argv[1], &e, 0); + if (*e) + return EC_ERROR_PARAM1; + + value = strtoi(argv[2], &e, 0); + if (*e) + return EC_ERROR_PARAM2; ccprintf("write 0x%p = 0x%08x\n", address, value); cflush(); /* Flush before writing in case this crashes */ @@ -26,24 +33,32 @@ 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); +DECLARE_CONSOLE_COMMAND(ww, command_write_word, + "addr value", + "Write a word to memory", + NULL); static int command_read_word(int argc, char **argv) { volatile uint32_t *address; uint32_t value; + char *e; if (argc != 2) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; + + address = (uint32_t *)strtoi(argv[1], &e, 0); + if (*e) + return EC_ERROR_PARAM1; - address = (uint32_t*)strtoi(argv[1], NULL, 0); value = *address; ccprintf("read 0x%p = 0x%08x\n", address, value); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(rw, command_read_word); -DECLARE_CONSOLE_COMMAND(readword, command_read_word); +DECLARE_CONSOLE_COMMAND(rw, command_read_word, + "addr", + "Read a word from memory", + NULL); diff --git a/common/port80.c b/common/port80.c index 8c5e5924aa..b879ed2043 100644 --- a/common/port80.c +++ b/common/port80.c @@ -55,4 +55,7 @@ static int command_port80(int argc, char **argv) ccputs(" <--new\n"); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(port80, command_port80); +DECLARE_CONSOLE_COMMAND(port80, command_port80, + "[scroll]", + "Print port80 writes or toggle port80 scrolling", + NULL); diff --git a/common/power_led.c b/common/power_led.c index f666a76dd9..8647619f39 100644 --- a/common/power_led.c +++ b/common/power_led.c @@ -83,6 +83,9 @@ static int command_powerled(int argc, char **argv) if (!strcasecmp(argv[1], color_names[i])) return powerled_set(i); } - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; } -DECLARE_CONSOLE_COMMAND(powerled, command_powerled); +DECLARE_CONSOLE_COMMAND(powerled, command_powerled, + "<off | red | yellow | green>", + "Set power LED color", + NULL); diff --git a/common/smart_battery.c b/common/smart_battery.c index eaae395777..fb73f28ac3 100644 --- a/common/smart_battery.c +++ b/common/smart_battery.c @@ -201,7 +201,10 @@ static int command_battery(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(battery, command_battery); +DECLARE_CONSOLE_COMMAND(battery, command_battery, + NULL, + "Print battery info", + NULL); /* Usage:sb <r/w> cmd [uint16_t w_word] @@ -217,11 +220,11 @@ static int command_sb(int argc, char **argv) char *e; if (argc < 3) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; cmd = strtoi(argv[2], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM2; if (argv[1][0] == 'r') { rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, &d); @@ -233,7 +236,7 @@ static int command_sb(int argc, char **argv) } else if (argc >= 4 && argv[1][0] == 'w') { d = strtoi(argv[3], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM3; ccprintf("W SBCMD[%04x] 0x%04x (%d)\n", cmd, d, d); rv = i2c_write16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, d); @@ -246,5 +249,8 @@ static int command_sb(int argc, char **argv) } -DECLARE_CONSOLE_COMMAND(sb, command_sb); +DECLARE_CONSOLE_COMMAND(sb, command_sb, + "[r addr | w addr value]", + "Read/write smart battery data", + NULL); diff --git a/common/system_common.c b/common/system_common.c index f80db6f86c..9d93cdef25 100644 --- a/common/system_common.c +++ b/common/system_common.c @@ -455,17 +455,10 @@ static int command_sysinfo(int argc, char **argv) ccprintf("Jump: %s\n", system_jumped_to_this_image() ? "yes" : "no"); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(sysinfo, command_sysinfo); - - -static int command_chipinfo(int argc, char **argv) -{ - ccprintf("Vendor: %s\n", system_get_chip_vendor()); - ccprintf("Name: %s\n", system_get_chip_name()); - ccprintf("Revision: %s\n", system_get_chip_revision()); - return EC_SUCCESS; -} -DECLARE_CONSOLE_COMMAND(chipinfo, command_chipinfo); +DECLARE_CONSOLE_COMMAND(sysinfo, command_sysinfo, + NULL, + "Print system info", + NULL); #ifdef CONSOLE_COMMAND_SCRATCHPAD @@ -477,14 +470,17 @@ static int command_scratchpad(int argc, char **argv) char *e; int s = strtoi(argv[1], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; rv = system_set_scratchpad(s); } ccprintf("Scratchpad: 0x%08x\n", system_get_scratchpad()); return rv; } -DECLARE_CONSOLE_COMMAND(scratchpad, command_scratchpad); +DECLARE_CONSOLE_COMMAND(scratchpad, command_scratchpad, + "[val]", + "Get or set scratchpad value", + NULL); #endif @@ -494,7 +490,7 @@ static int command_hibernate(int argc, char **argv) int microseconds = 0; if (argc < 2) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; seconds = strtoi(argv[1], NULL, 0); if (argc >= 3) microseconds = strtoi(argv[2], NULL, 0); @@ -506,11 +502,16 @@ static int command_hibernate(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(hibernate, command_hibernate); +DECLARE_CONSOLE_COMMAND(hibernate, command_hibernate, + "sec [usec]", + "Hibernate the EC", + NULL); static int command_version(int argc, char **argv) { + ccprintf("Chip: %s %s %s\n", system_get_chip_vendor(), + system_get_chip_name(), system_get_chip_revision()); ccprintf("Board: %d\n", system_get_board_version()); ccprintf("RO: %s\n", system_get_version(SYSTEM_IMAGE_RO)); ccprintf("RW-A: %s\n", system_get_version(SYSTEM_IMAGE_RW_A)); @@ -518,7 +519,10 @@ static int command_version(int argc, char **argv) ccprintf("Build: %s\n", system_get_build_info()); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(version, command_version); +DECLARE_CONSOLE_COMMAND(version, command_version, + NULL, + "Print versions", + NULL); static int command_sysjump(int argc, char **argv) @@ -530,30 +534,32 @@ static int command_sysjump(int argc, char **argv) * be disabled. */ if (argc < 2) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; ccputs("Processing sysjump command\n"); /* Handle named images */ - if (!strcasecmp(argv[1], "RO")) { + if (!strcasecmp(argv[1], "RO")) return system_run_image_copy(SYSTEM_IMAGE_RO, 0); - } else if (!strcasecmp(argv[1], "A")) { + else if (!strcasecmp(argv[1], "A")) return system_run_image_copy(SYSTEM_IMAGE_RW_A, 0); - } else if (!strcasecmp(argv[1], "B")) { + else if (!strcasecmp(argv[1], "B")) return system_run_image_copy(SYSTEM_IMAGE_RW_B, 0); - } /* Check for arbitrary address */ addr = strtoi(argv[1], &e, 0); if (*e) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM1; ccprintf("Jumping to 0x%08x\n", addr); cflush(); jump_to_image(addr, 0); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(sysjump, command_sysjump); +DECLARE_CONSOLE_COMMAND(sysjump, command_sysjump, + "[RO | A | B | addr]", + "Jump to a system image or address", + NULL); static int command_reboot(int argc, char **argv) @@ -570,7 +576,10 @@ static int command_reboot(int argc, char **argv) system_reset(is_hard); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(reboot, command_reboot); +DECLARE_CONSOLE_COMMAND(reboot, command_reboot, + "[hard]", + "Reboot the EC", + NULL); /*****************************************************************************/ /* Host commands */ diff --git a/common/temp_sensor.c b/common/temp_sensor.c index 980d62d13b..c027fb560b 100644 --- a/common/temp_sensor.c +++ b/common/temp_sensor.c @@ -119,4 +119,7 @@ static int command_temps(int argc, char **argv) return rv; } -DECLARE_CONSOLE_COMMAND(temps, command_temps); +DECLARE_CONSOLE_COMMAND(temps, command_temps, + NULL, + "Print temp sensors", + NULL); diff --git a/common/thermal.c b/common/thermal.c index 72709cd8ec..4f14ca3f50 100644 --- a/common/thermal.c +++ b/common/thermal.c @@ -241,18 +241,12 @@ static int command_thermal_config(int argc, char **argv) char *e; int sensor_type, threshold_id, value; - if (argc != 2 && argc != 4) { - ccputs("Usage: thermalconf <sensor_type> " - "[<threshold_id> <value>]\n"); - return EC_ERROR_UNKNOWN; - } + if (argc != 2 && argc != 4) + return EC_ERROR_PARAM_COUNT; sensor_type = strtoi(argv[1], &e, 0); - if ((e && *e) || sensor_type < 0 || - sensor_type >= TEMP_SENSOR_TYPE_COUNT) { - ccputs("Bad sensor type ID.\n"); - return EC_ERROR_UNKNOWN; - } + if (*e || sensor_type < 0 || sensor_type >= TEMP_SENSOR_TYPE_COUNT) + return EC_ERROR_PARAM1; if (argc == 2) { print_thermal_config(sensor_type); @@ -260,16 +254,12 @@ static int command_thermal_config(int argc, char **argv) } threshold_id = strtoi(argv[2], &e, 0); - if ((e && *e) || threshold_id < 0 || threshold_id >= THRESHOLD_COUNT) { - ccputs("Bad threshold ID.\n"); - return EC_ERROR_UNKNOWN; - } + if (*e || threshold_id < 0 || threshold_id >= THRESHOLD_COUNT) + return EC_ERROR_PARAM2; value = strtoi(argv[3], &e, 0); - if ((e && *e) || value < 0) { - ccputs("Bad threshold value.\n"); - return EC_ERROR_UNKNOWN; - } + if (*e || value < 0) + return EC_ERROR_PARAM3; thermal_config[sensor_type].thresholds[threshold_id] = value; ccprintf("Setting threshold %d of sensor type %d to %d\n", @@ -277,7 +267,10 @@ static int command_thermal_config(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(thermalconf, command_thermal_config); +DECLARE_CONSOLE_COMMAND(thermalconf, command_thermal_config, + "sensortype [threshold_id temp]", + "Get/set thermal threshold temp", + NULL); static int command_fan_config(int argc, char **argv) @@ -285,18 +278,13 @@ static int command_fan_config(int argc, char **argv) char *e; int sensor_type, stepping_id, value; - if (argc != 2 && argc != 4) { - ccputs("Usage: thermalfan <sensor_type> " - "[<stepping_id> <value>]\n"); - return EC_ERROR_UNKNOWN; - } + if (argc != 2 && argc != 4) + return EC_ERROR_PARAM_COUNT; sensor_type = strtoi(argv[1], &e, 0); if ((e && *e) || sensor_type < 0 || - sensor_type >= TEMP_SENSOR_TYPE_COUNT) { - ccputs("Bad sensor type ID.\n"); - return EC_ERROR_UNKNOWN; - } + sensor_type >= TEMP_SENSOR_TYPE_COUNT) + return EC_ERROR_PARAM1; if (argc == 2) { print_fan_stepping(sensor_type); @@ -304,16 +292,12 @@ static int command_fan_config(int argc, char **argv) } stepping_id = strtoi(argv[2], &e, 0); - if ((e && *e) || stepping_id < 0 || stepping_id >= THERMAL_FAN_STEPS) { - ccputs("Bad stepping ID.\n"); - return EC_ERROR_UNKNOWN; - } + if ((e && *e) || stepping_id < 0 || stepping_id >= THERMAL_FAN_STEPS) + return EC_ERROR_PARAM2; value = strtoi(argv[3], &e, 0); - if ((e && *e) || value < 0) { - ccputs("Bad threshold value.\n"); - return EC_ERROR_UNKNOWN; - } + if (*e || value < 0) + return EC_ERROR_PARAM3; thermal_config[sensor_type].thresholds[THRESHOLD_COUNT + stepping_id] = value; @@ -322,11 +306,17 @@ static int command_fan_config(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(thermalfan, command_fan_config); +DECLARE_CONSOLE_COMMAND(thermalfan, command_fan_config, + "sensortype [threshold_id rpm]", + "Get/set thermal threshold fan rpm", + NULL); static int command_thermal_auto_fan_ctrl(int argc, char **argv) { return thermal_toggle_auto_fan_ctrl(1); } -DECLARE_CONSOLE_COMMAND(autofan, command_thermal_auto_fan_ctrl); +DECLARE_CONSOLE_COMMAND(autofan, command_thermal_auto_fan_ctrl, + NULL, + "Enable thermal fan control", + NULL); diff --git a/common/tmp006.c b/common/tmp006.c index 9ecc8084e3..18882c5fde 100644 --- a/common/tmp006.c +++ b/common/tmp006.c @@ -291,4 +291,7 @@ static int command_sensor_info(int argc, char **argv) return rv1; } -DECLARE_CONSOLE_COMMAND(tmp006, command_sensor_info); +DECLARE_CONSOLE_COMMAND(tmp006, command_sensor_info, + NULL, + "Print TMP006 sensors", + NULL); diff --git a/common/usb_charge.c b/common/usb_charge.c index 175717fadf..6495a491c0 100644 --- a/common/usb_charge.c +++ b/common/usb_charge.c @@ -120,34 +120,30 @@ static int command_set_mode(int argc, char **argv) { int port_id = -1; int mode = -1; - char* endptr; - - if (argc != 3) { - ccputs("Usage: usbchargemode <port_id> <mode>\n"); - ccputs("Modes: 0=Disabled.\n" - " 1=Dedicated charging. Auto select.\n" - " 2=Dedicated charging. BC 1.2.\n" - " 3=Downstream. Max 500mA.\n" - " 4=Downstream. Max 1.5A.\n"); - return EC_ERROR_UNKNOWN; - } + char *e; - port_id = strtoi(argv[1], &endptr, 0); - if (*endptr || port_id < 0 || port_id >= USB_CHARGE_PORT_COUNT) { - ccputs("Invalid port ID.\n"); - return EC_ERROR_UNKNOWN; - } + if (argc != 3) + return EC_ERROR_PARAM_COUNT; - mode = strtoi(argv[2], &endptr, 0); - if (*endptr || mode < 0 || mode >= USB_CHARGE_MODE_COUNT) { - ccputs("Invalid mode.\n"); - return EC_ERROR_UNKNOWN; - } + port_id = strtoi(argv[1], &e, 0); + if (*e || port_id < 0 || port_id >= USB_CHARGE_PORT_COUNT) + return EC_ERROR_PARAM1; + + mode = strtoi(argv[2], &e, 0); + if (*e || mode < 0 || mode >= USB_CHARGE_MODE_COUNT) + return EC_ERROR_PARAM2; - ccprintf("Setting USB mode...\n"); return usb_charge_set_mode(port_id, mode); } -DECLARE_CONSOLE_COMMAND(usbchargemode, command_set_mode); +DECLARE_CONSOLE_COMMAND(usbchargemode, command_set_mode, + "<port> <0 | 1 | 2 | 3 | 4>", + "Set USB charge mode", + "Modes: 0=Disabled.\n" + " 1=Dedicated charging. Auto select.\n" + " 2=Dedicated charging. BC 1.2.\n" + " 3=Downstream. Max 500mA.\n" + " 4=Downstream. Max 1.5A.\n"); + /*****************************************************************************/ /* Hooks */ diff --git a/common/x86_power.c b/common/x86_power.c index 9f1fd175d5..48d05b6d6d 100644 --- a/common/x86_power.c +++ b/common/x86_power.c @@ -588,20 +588,6 @@ void x86_power_task(void) /*****************************************************************************/ /* Console commands */ -static int command_x86power(int argc, char **argv) -{ - /* Print current state */ - ccprintf("Current X86 state: %d (%s)\n", state, state_names[state]); - - /* Forcing a power state from EC is deprecated */ - if (argc > 1) - ccputs("Use 'powerbtn' instead of 'x86power s0'.\n"); - - return EC_SUCCESS; -} -DECLARE_CONSOLE_COMMAND(x86power, command_x86power); - - static int command_x86reset(int argc, char **argv) { int is_cold = 1; @@ -616,4 +602,7 @@ static int command_x86reset(int argc, char **argv) x86_power_reset(is_cold); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(x86reset, command_x86reset); +DECLARE_CONSOLE_COMMAND(x86reset, command_x86reset, + "[warm | cold]", + "Issue x86 reset", + NULL); diff --git a/core/cortex-m/task.c b/core/cortex-m/task.c index 4bd194bd78..aaaa776385 100644 --- a/core/cortex-m/task.c +++ b/core/cortex-m/task.c @@ -534,7 +534,10 @@ int command_task_info(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(taskinfo, command_task_info); +DECLARE_CONSOLE_COMMAND(taskinfo, command_task_info, + NULL, + "Print task info", + NULL); static int command_task_ready(int argc, char **argv) @@ -549,7 +552,10 @@ static int command_task_ready(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(taskready, command_task_ready); +DECLARE_CONSOLE_COMMAND(taskready, command_task_ready, + "[setmask]", + "Print/set ready tasks", + NULL); #endif /* CONFIG_DEBUG */ diff --git a/core/cortex-m/timer.c b/core/cortex-m/timer.c index 2ea927d4be..14e59c900f 100644 --- a/core/cortex-m/timer.c +++ b/core/cortex-m/timer.c @@ -189,14 +189,24 @@ void timer_print_info(void) static int command_wait(int argc, char **argv) { + char *e; + int i; + if (argc < 2) - return EC_ERROR_INVAL; + return EC_ERROR_PARAM_COUNT; + + i = strtoi(argv[1], &e, 0); + if (*e) + return EC_ERROR_PARAM1; - udelay(atoi(argv[1]) * 1000); + udelay(i * 1000); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(waitms, command_wait); +DECLARE_CONSOLE_COMMAND(waitms, command_wait, + "msec", + "Busy-wait for msec", + NULL); static int command_get_time(int argc, char **argv) @@ -206,7 +216,10 @@ static int command_get_time(int argc, char **argv) return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(gettime, command_get_time); +DECLARE_CONSOLE_COMMAND(gettime, command_get_time, + NULL, + "Print current time", + NULL); int command_timer_info(int argc, char **argv) @@ -214,7 +227,10 @@ int command_timer_info(int argc, char **argv) timer_print_info(); return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(timerinfo, command_timer_info); +DECLARE_CONSOLE_COMMAND(timerinfo, command_timer_info, + NULL, + "Print timer info", + NULL); #define TIMER_SYSJUMP_TAG 0x4d54 /* "TM" */ diff --git a/include/common.h b/include/common.h index 291b950e48..91a1a126a1 100644 --- a/include/common.h +++ b/include/common.h @@ -35,6 +35,17 @@ enum ec_error_list { EC_ERROR_INVAL = 5, /* Already in use */ EC_ERROR_BUSY = 6, + /* Invalid console command param (PARAMn means parameter n is bad) */ + EC_ERROR_PARAM1 = 11, + EC_ERROR_PARAM2 = 12, + EC_ERROR_PARAM3 = 13, + EC_ERROR_PARAM4 = 14, + EC_ERROR_PARAM5 = 15, + EC_ERROR_PARAM6 = 16, + EC_ERROR_PARAM7 = 17, + EC_ERROR_PARAM8 = 18, + EC_ERROR_PARAM9 = 19, + EC_ERROR_PARAM_COUNT = 20, /* Wrong number of params */ /* Module-internal error codes may use this range. */ EC_ERROR_INTERNAL_FIRST = 0x10000, diff --git a/include/console.h b/include/console.h index 4a655387da..3ad4150fe4 100644 --- a/include/console.h +++ b/include/console.h @@ -8,6 +8,7 @@ #ifndef __CROS_EC_CONSOLE_H #define __CROS_EC_CONSOLE_H +#include "board.h" #include "common.h" /* Console command; used by DECLARE_CONSOLE_COMMAND macro. */ @@ -16,6 +17,12 @@ struct console_command { const char *name; /* Handler for the command. argv[0] will be the command name. */ int (*handler)(int argc, char **argv); +#ifdef CONFIG_CONSOLE_CMDHELP + /* Description of args */ + const char *argdesc; + /* Short help for command */ + const char *shorthelp; +#endif }; @@ -80,10 +87,18 @@ void console_has_input(void); * Register a console command handler. Note that `name' must never be a * beginning of another existing command name. */ -#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." #name))) \ - = {__con_cmd_label_##name, routine} +#ifdef CONFIG_CONSOLE_CMDHELP +#define DECLARE_CONSOLE_COMMAND(name, routine, argdesc, shorthelp, longhelp) \ + static const char __con_cmd_label_##name[] = #name; \ + const struct console_command __con_cmd_##name \ + __attribute__((section(".rodata.cmds." #name))) \ + = {__con_cmd_label_##name, routine, argdesc, shorthelp} +#else +#define DECLARE_CONSOLE_COMMAND(name, routine, argdesc, shorthelp, longhelp) \ + static const char __con_cmd_label_##name[] = #name; \ + const struct console_command __con_cmd_##name \ + __attribute__((section(".rodata.cmds." #name))) \ + = {__con_cmd_label_##name, routine} +#endif #endif /* __CROS_EC_CONSOLE_H */ |