summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2016-08-18 15:52:14 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-08-22 23:27:24 -0700
commit8f080f795b205a6bba38c9e2a5cfda8c18297944 (patch)
treecae768f4e817cfbe5bbdd5bc1f6f64f1fe00d187
parentbccd2f94f1a53bf604b184db266045dc657752c7 (diff)
downloadchrome-ec-8f080f795b205a6bba38c9e2a5cfda8c18297944.tar.gz
Cr50: Use parse_bool() for boolean args
The parse_bool() function exists so we don't have to litter our console commands with stuff like this: if (!strncasecmp(argv[1], "on") || !strncasecmp(argv[1], "enable" || !strncasecmp(argv[1], "true" || [...] This CL uses parse_bool instead of that kind of thing so I don't have to remember which commands use "enable" and which use "on" and so forth. I only changed the commands that Cr50 uses. BUG=none BRANCH=none TEST=make buildall; test on Cr50 hardware I tested all the affected commands to ensure that they still work correctly: usb, ccd, flashwp (which doesn't do anything anyway). Change-Id: I7d875ab22934fb4b500e3d0f62ebe3e04101272d Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/373658 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--board/cr50/rdd.c18
-rw-r--r--chip/g/usb.c17
-rw-r--r--common/flash.c25
-rw-r--r--common/util.c11
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)