diff options
author | Randall Spangler <rspangler@chromium.org> | 2012-07-19 16:41:57 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-07-30 13:41:33 -0700 |
commit | 7d06db201fb2eded0bd45a10a460756007eb0679 (patch) | |
tree | 422055d72f14320cff275f52d37cca3f72be431b /common/vboot_hash.c | |
parent | 25e1ebf671c60f59bb9110b7825c90a67f67692c (diff) | |
download | chrome-ec-7d06db201fb2eded0bd45a10a460756007eb0679.tar.gz |
Enhance printf()
1. Add precision to limit string length.
ccprintf("%.4s", "foobar") prints "foob"
2. Handle '*' for length, precision fields.
ccprintf("%.*s", 3, "foobar") prints "foo"
3. Add hex-dump code "%h"
ccprintf("%.*s", 4, "foobar") prints 666f6f62
BUG=none
TEST=at ec console, 'hash' prints the current hash
Change-Id: I568310f2727495b021081bf58df2a0bbb3c74e73
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28704
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'common/vboot_hash.c')
-rw-r--r-- | common/vboot_hash.c | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/common/vboot_hash.c b/common/vboot_hash.c index 6f944622da..3362917e0d 100644 --- a/common/vboot_hash.c +++ b/common/vboot_hash.c @@ -143,14 +143,9 @@ void vboot_hash_task(void) size); curr_pos += size; if (curr_pos >= data_size) { - int i; - hash = SHA256_final(&ctx); - - CPRINTF("[%T hash done "); - for (i = 0; i < SHA256_DIGEST_SIZE; i++) - CPRINTF("%02x", hash[i]); - CPUTS("]\n"); + CPRINTF("[%T hash done %.*h]\n", + SHA256_DIGEST_SIZE, hash); } /* @@ -196,14 +191,11 @@ static int command_hash(int argc, char **argv) ccprintf("Offset: 0x%08x\n", data_offset); ccprintf("Size: 0x%08x (%d)\n", data_size, data_size); ccprintf("Digest: "); - if (vboot_hash_in_progress()) { + if (vboot_hash_in_progress()) ccprintf("(in progress)\n"); - } else { - int i; - for (i = 0; i < SHA256_DIGEST_SIZE; i++) - ccprintf("%02x", hash[i]); - ccprintf("\n"); - } + else + ccprintf("%.*h\n", SHA256_DIGEST_SIZE, hash); + return EC_SUCCESS; } |