summaryrefslogtreecommitdiff
path: root/util/ectool.c
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-07-18 13:15:40 -0700
committerRandall Spangler <rspangler@chromium.org>2012-07-18 18:15:29 -0700
commit8137b29125dec793c84273b522d8adfa7c1748dc (patch)
tree763ea30bc74eb93b205aac543be708fe6d99d583 /util/ectool.c
parent3dfc336b440979c1eb58102df0f15a7cc0f305e8 (diff)
downloadchrome-ec-8137b29125dec793c84273b522d8adfa7c1748dc.tar.gz
Add EC flash protect command to ectool
BUG=chrome-os-partner:11150 TEST=manual Enable WP GPIO. Then from a root shell localhost ~ # ectool flashprotect Flash protect flags: 0x00000008 wp_gpio_asserted Writable flags: 0x00000005 ro_at_boot rw_now localhost ~ # ectool flashprotect enable Flash protect flags: 0x0000000b wp_gpio_asserted ro_at_boot ro_now Writable flags: 0x00000004 rw_now localhost ~ # ectool flashprotect enable Flash protect flags: 0x0000000b wp_gpio_asserted ro_at_boot ro_now Writable flags: 0x00000004 rw_now localhost ~ # ectool flashprotect now Flash protect flags: 0x0000000f wp_gpio_asserted ro_at_boot ro_now rw_now Writable flags: 0x00000000 localhost ~ # ectool flashprotect now Flash protect flags: 0x0000000f wp_gpio_asserted ro_at_boot ro_now rw_now Writable flags: 0x00000000 localhost ~ # ectool flashprotect disable Flash protect flags: 0x0000000f wp_gpio_asserted ro_at_boot ro_now rw_now Writable flags: 0x00000000 Unable to set requested flags (wanted mask 0x00000001 flags 0x00000000) Which is expected, because writable mask is 0x00000000. Then disable WP GPIO and reboot localhost ~ # ectool flashprotect Flash protect flags: 0x00000001 ro_at_boot Writable flags: 0x00000001 ro_at_boot localhost ~ # ectool flashprotect disable Flash protect flags: 0x00000000 Writable flags: 0x00000001 ro_at_boot Change-Id: Idc5de3b3033521467aca8fb0ba9b7c378d0ad2a1 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/27799
Diffstat (limited to 'util/ectool.c')
-rw-r--r--util/ectool.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/util/ectool.c b/util/ectool.c
index 3fddb992f1..0cb9825c06 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -65,6 +65,8 @@ const char help_str[] =
" Erases EC flash\n"
" flashinfo\n"
" Prints information on the EC flash\n"
+ " flashprotect [now] [enable | disable]\n"
+ " Prints or sets EC flash protection state\n"
" flashread <offset> <size> <outfile>\n"
" Reads from EC flash to a file\n"
" flashwrite <offset> <infile>\n"
@@ -574,6 +576,78 @@ int cmd_flash_erase(int argc, char *argv[])
}
+static void print_flash_protect_flags(const char *desc, uint32_t flags)
+{
+ printf("%s 0x%08x", desc, flags);
+ if (flags & EC_FLASH_PROTECT_GPIO_ASSERTED)
+ printf(" wp_gpio_asserted");
+ if (flags & EC_FLASH_PROTECT_RO_AT_BOOT)
+ printf(" ro_at_boot");
+ if (flags & EC_FLASH_PROTECT_RW_AT_BOOT)
+ printf(" rw_at_boot");
+ if (flags & EC_FLASH_PROTECT_RO_NOW)
+ printf(" ro_now");
+ if (flags & EC_FLASH_PROTECT_RW_NOW)
+ printf(" rw_now");
+ if (flags & EC_FLASH_PROTECT_ERROR_STUCK)
+ printf(" STUCK");
+ if (flags & EC_FLASH_PROTECT_ERROR_INCONSISTENT)
+ printf(" INCONSISTENT");
+ printf("\n");
+}
+
+
+int cmd_flash_protect(int argc, char *argv[])
+{
+ struct ec_params_flash_protect p;
+ struct ec_response_flash_protect r;
+ int rv, i;
+
+ /*
+ * Set up requested flags. If no flags were specified, p.mask will
+ * be 0 and nothing will change.
+ */
+ p.mask = p.flags = 0;
+ for (i = 1; i < argc; i++) {
+ if (!strcasecmp(argv[i], "now")) {
+ p.mask |= EC_FLASH_PROTECT_RW_NOW;
+ p.flags |= EC_FLASH_PROTECT_RW_NOW;
+ } else if (!strcasecmp(argv[i], "enable")) {
+ p.mask |= EC_FLASH_PROTECT_RO_AT_BOOT;
+ p.flags |= EC_FLASH_PROTECT_RO_AT_BOOT;
+ } else if (!strcasecmp(argv[i], "disable"))
+ p.mask |= EC_FLASH_PROTECT_RO_AT_BOOT;
+ }
+
+ rv = ec_command(EC_CMD_FLASH_PROTECT, EC_VER_FLASH_PROTECT,
+ &p, sizeof(p), &r, sizeof(r));
+ if (rv < 0)
+ return rv;
+ if (rv < sizeof(r)) {
+ fprintf(stderr, "Too little data returned.\n");
+ return -1;
+ }
+
+ /* Print returned flags */
+ print_flash_protect_flags("Flash protect flags:", r.flags);
+ print_flash_protect_flags("Writable flags: ", r.writable_flags);
+
+ /* Check if we got all the flags we asked for */
+ if ((r.flags & p.mask) != (p.flags & p.mask)) {
+ fprintf(stderr, "Unable to set requested flags "
+ "(wanted mask 0x%08x flags 0x%08x)\n",
+ p.mask, p.flags);
+ if (p.mask & ~r.writable_flags)
+ fprintf(stderr, "Which is expected, because writable "
+ "mask is 0x%08x.\n", r.writable_flags);
+
+ return -1;
+ }
+
+ return 0;
+}
+
+
int cmd_serial_test(int argc, char *argv[])
{
const char *c = "COM2 sample serial output from host!\r\n";
@@ -1964,6 +2038,7 @@ const struct command commands[] = {
{"eventsetwakemask", cmd_host_event_set_wake_mask},
{"fanduty", cmd_fanduty},
{"flasherase", cmd_flash_erase},
+ {"flashprotect", cmd_flash_protect},
{"flashread", cmd_flash_read},
{"flashwrite", cmd_flash_write},
{"flashinfo", cmd_flash_info},