diff options
-rw-r--r-- | board/cr50/rdd.c | 18 | ||||
-rw-r--r-- | chip/g/usb.c | 17 | ||||
-rw-r--r-- | common/flash.c | 25 | ||||
-rw-r--r-- | common/util.c | 11 |
4 files changed, 47 insertions, 24 deletions
diff --git a/board/cr50/rdd.c b/board/cr50/rdd.c index 40a3cb08b7..608a025006 100644 --- a/board/cr50/rdd.c +++ b/board/cr50/rdd.c @@ -125,21 +125,29 @@ void rdd_detached(void) static int command_ccd(int argc, char **argv) { + int val; + if (argc > 1) { if (!strcasecmp("uart", argv[1]) && argc > 2) { - if (!strcasecmp("enable", argv[2])) { + if (!parse_bool(argv[2], &val)) + return EC_ERROR_PARAM2; + + if (val) { uart_enabled = 1; uartn_tx_connect(UART_EC); uartn_tx_connect(UART_AP); - } else if (!strcasecmp("disable", argv[2])) { + } else { uart_enabled = 0; uartn_tx_disconnect(UART_EC); uartn_tx_disconnect(UART_AP); } } else if (argc == 2) { - if (!strcasecmp("enable", argv[1])) + if (!parse_bool(argv[1], &val)) + return EC_ERROR_PARAM1; + + if (val) rdd_attached(); - else if (!strcasecmp("disable", argv[1])) + else rdd_detached(); } else return EC_ERROR_PARAM1; @@ -152,6 +160,6 @@ static int command_ccd(int argc, char **argv) return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(ccd, command_ccd, - "[uart] [enable|disable]", + "[uart] [<BOOLEAN>]", "Get/set the case closed debug state", NULL); diff --git a/chip/g/usb.c b/chip/g/usb.c index 809c1aefb0..751b4b131d 100644 --- a/chip/g/usb.c +++ b/chip/g/usb.c @@ -1381,15 +1381,20 @@ void usb_release(void) static int command_usb(int argc, char **argv) { + int val; + if (argc > 1) { - if (!strcasecmp("on", argv[1])) - usb_init(); - else if (!strcasecmp("off", argv[1])) - usb_release(); - else if (!strcasecmp("a", argv[1])) + if (!strcasecmp("a", argv[1])) usb_select_phy(USB_SEL_PHY0); else if (!strcasecmp("b", argv[1])) usb_select_phy(USB_SEL_PHY1); + else if (parse_bool(argv[1], &val)) { + if (val) + usb_init(); + else + usb_release(); + } else + return EC_ERROR_PARAM1; } showregs(); @@ -1398,6 +1403,6 @@ static int command_usb(int argc, char **argv) return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(usb, command_usb, - "[on|off|a|b]", + "[<BOOLEAN> | a | b]", "Get/set the USB connection state and PHY selection", NULL); diff --git a/common/flash.c b/common/flash.c index cffae7843e..b67e8da678 100644 --- a/common/flash.c +++ b/common/flash.c @@ -820,24 +820,29 @@ DECLARE_CONSOLE_COMMAND(flashread, command_flash_read, static int command_flash_wp(int argc, char **argv) { + int val; + if (argc < 2) return EC_ERROR_PARAM_COUNT; - if (!strcasecmp(argv[1], "enable")) - return flash_set_protect(EC_FLASH_PROTECT_RO_AT_BOOT, -1); - else if (!strcasecmp(argv[1], "disable")) - return flash_set_protect(EC_FLASH_PROTECT_RO_AT_BOOT, 0); - else if (!strcasecmp(argv[1], "now")) + if (!strcasecmp(argv[1], "now")) return flash_set_protect(EC_FLASH_PROTECT_ALL_NOW, -1); - else if (!strcasecmp(argv[1], "rw")) + + if (!strcasecmp(argv[1], "rw")) return flash_set_protect(EC_FLASH_PROTECT_ALL_AT_BOOT, -1); - else if (!strcasecmp(argv[1], "norw")) + + if (!strcasecmp(argv[1], "norw")) return flash_set_protect(EC_FLASH_PROTECT_ALL_AT_BOOT, 0); - else - return EC_ERROR_PARAM1; + + /* Do this last, since anything starting with 'n' means "no" */ + if (parse_bool(argv[1], &val)) + return flash_set_protect(EC_FLASH_PROTECT_RO_AT_BOOT, + val ? -1 : 0); + + return EC_ERROR_PARAM1; } DECLARE_CONSOLE_COMMAND(flashwp, command_flash_wp, - "<enable | disable | now | rw | norw>", + "<BOOLEAN> | now | rw | norw", "Modify flash write protect", NULL); diff --git a/common/util.c b/common/util.c index 9df5b5596f..e1b523de97 100644 --- a/common/util.c +++ b/common/util.c @@ -142,17 +142,22 @@ int strtoi(const char *nptr, char **endptr, int base) int parse_bool(const char *s, int *dest) { + /* off, disable, false, no */ if (!strcasecmp(s, "off") || !strncasecmp(s, "dis", 3) || tolower(*s) == 'f' || tolower(*s) == 'n') { *dest = 0; return 1; - } else if (!strcasecmp(s, "on") || !strncasecmp(s, "ena", 3) || + } + + /* on, enable, true, yes */ + if (!strcasecmp(s, "on") || !strncasecmp(s, "ena", 3) || tolower(*s) == 't' || tolower(*s) == 'y') { *dest = 1; return 1; - } else { - return 0; } + + /* dunno */ + return 0; } int memcmp(const void *s1, const void *s2, size_t len) |