summaryrefslogtreecommitdiff
path: root/common/flash.c
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 /common/flash.c
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>
Diffstat (limited to 'common/flash.c')
-rw-r--r--common/flash.c25
1 files changed, 15 insertions, 10 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);