summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-09-12 13:48:07 -0700
committerGerrit <chrome-bot@google.com>2012-09-12 15:42:25 -0700
commit88ff608ae261ceca193e7d5689dc67b1536ce3eb (patch)
tree11245c8dcbaf87f526e071a44ba50e2122412293 /util
parent0ac4bc36537ce3ee98a3ce3068a79919cd9804d3 (diff)
downloadchrome-ec-88ff608ae261ceca193e7d5689dc67b1536ce3eb.tar.gz
Add capability to auto-hash correct size for EC-RO or EC-RW
Otherwise the host needs to tell the EC how big this image is (which it knows, but it's inconvenient for it to provide). BUG=chrome-os-partner:13511 BRANCH=all TEST=manual 1. ectool echash recalc ro -> prints hash of RO code (offset 0) 2. ectool echash recalc rw -> prints hash of RW code (offset non-zero) In each case, size should be an exact number and not the size of the whole RO or RW section. So for link, output should be something similar to: localhost ~ # ectool echash recalc ro Hashing EC-RO... status: done type: SHA-256 offset: 0x00000000 size: 0x00012a64 hash: 03a66c076d6dd4b4aa9ed6386713f45291f5143f9af2093003e632485899daf1 localhost ~ # ectool echash recalc rw Hashing EC-RW... status: done type: SHA-256 offset: 0x00014000 size: 0x000123d1 hash: 0d6225e70f0b1e0419e987370371e00783f945827ef25915a8fb8549159dd2a4 Signed-off-by: Randall Spangler <rspangler@chromium.org> 3. At ec console, 'hash ro' or 'hash rw' should regenerate the same hash values printed above. Change-Id: I3f6085d29927b8cdf9dabc6930f0fdc7222bd8b5 Reviewed-on: https://gerrit.chromium.org/gerrit/33123 Tested-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org> Commit-Ready: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'util')
-rw-r--r--util/ectool.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/util/ectool.c b/util/ectool.c
index 90b0d558ee..4fbc6ce781 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -1990,6 +1990,10 @@ static int ec_hash_help(const char *cmd)
printf(" %s abort - abort hashing\n", cmd);
printf(" %s start [<offset> <size> [<nonce>]] - start hashing\n", cmd);
printf(" %s recalc [<offset> <size> [<nonce>]] - sync rehash\n", cmd);
+ printf("\n"
+ "If <offset> is RO or RW, offset and size are computed\n"
+ "automatically for the EC-RO or EC-RW firmware image.\n");
+
return 0;
}
@@ -2060,21 +2064,36 @@ int cmd_ec_hash(int argc, char *argv[])
else
return ec_hash_help(argv[0]);
- if (argc < 4) {
- fprintf(stderr, "Must specify offset and size\n");
- return -1;
- }
-
p.hash_type = EC_VBOOT_HASH_TYPE_SHA256;
- p.offset = strtol(argv[2], &e, 0);
- if (e && *e) {
- fprintf(stderr, "Bad offset.\n");
+
+ if (argc < 3) {
+ fprintf(stderr, "Must specify offset\n");
return -1;
}
- p.size = strtol(argv[3], &e, 0);
- if (e && *e) {
- fprintf(stderr, "Bad size.\n");
+
+ if (!strcasecmp(argv[2], "ro")) {
+ p.offset = EC_VBOOT_HASH_OFFSET_RO;
+ p.size = 0;
+ printf("Hashing EC-RO...\n");
+ } else if (!strcasecmp(argv[2], "rw")) {
+ p.offset = EC_VBOOT_HASH_OFFSET_RW;
+ p.size = 0;
+ printf("Hashing EC-RW...\n");
+ } else if (argc < 4) {
+ fprintf(stderr, "Must specify size\n");
return -1;
+ } else {
+ p.offset = strtol(argv[2], &e, 0);
+ if (e && *e) {
+ fprintf(stderr, "Bad offset.\n");
+ return -1;
+ }
+ p.size = strtol(argv[3], &e, 0);
+ if (e && *e) {
+ fprintf(stderr, "Bad size.\n");
+ return -1;
+ }
+ printf("Hashing %d bytes at offset %d...\n", p.size, p.offset);
}
if (argc == 5) {
@@ -2092,7 +2111,6 @@ int cmd_ec_hash(int argc, char *argv[])
} else
p.nonce_size = 0;
- printf("Hashing %d bytes at offset %d...\n", p.size, p.offset);
rv = ec_command(EC_CMD_VBOOT_HASH, 0, &p, sizeof(p), &r, sizeof(r));
if (rv < 0)
return rv;