diff options
author | Bill Richardson <wfrichar@chromium.org> | 2016-08-18 15:52:14 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-08-22 23:27:24 -0700 |
commit | 8f080f795b205a6bba38c9e2a5cfda8c18297944 (patch) | |
tree | cae768f4e817cfbe5bbdd5bc1f6f64f1fe00d187 /common | |
parent | bccd2f94f1a53bf604b184db266045dc657752c7 (diff) | |
download | chrome-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>
Diffstat (limited to 'common')
-rw-r--r-- | common/flash.c | 25 | ||||
-rw-r--r-- | common/util.c | 11 |
2 files changed, 23 insertions, 13 deletions
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) |