diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2016-09-22 09:48:20 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-10-04 21:19:12 -0700 |
commit | c3daa95c50ad6976507c2f164f8be87bc7b75c1f (patch) | |
tree | 0c0ae829ccab7abb27e8401cc732fbc1908d801e /futility/bdb_helper.c | |
parent | a1026841a3db4c76288576c8660248fd925763f9 (diff) | |
download | vboot-c3daa95c50ad6976507c2f164f8be87bc7b75c1f.tar.gz |
bdb: Make 'futility show' support BDB
This patch makes futility show command support boot block descriptor (BDB)
of the common boot flow.
BUG=chromium:649554
BRANCH=none
TEST=make runtests. Ran futility show bdb.bin.
Change-Id: I5f199a32ab1c268351e822e37ed39e41ae19bc7a
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/388631
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'futility/bdb_helper.c')
-rw-r--r-- | futility/bdb_helper.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/futility/bdb_helper.c b/futility/bdb_helper.c new file mode 100644 index 00000000..d2f428c8 --- /dev/null +++ b/futility/bdb_helper.c @@ -0,0 +1,68 @@ +/* Copyright 2016 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Boot descriptor block helper functions + */ + +#include <stdio.h> + +#include "2sha.h" +#include "bdb.h" +#include "bdb_struct.h" +#include "file_type.h" + +enum futil_file_type ft_recognize_bdb(uint8_t *buf, uint32_t len) +{ + const struct bdb_header *header = bdb_get_header(buf); + + if (bdb_check_header(header, len)) + return FILE_TYPE_UNKNOWN; + + return FILE_TYPE_BDB; +} + +static void print_digest(const char *label, const uint8_t *digest, size_t size) +{ + int i; + + if (label) + printf("%s", label); + for (i = 0; i < size; i++) + printf("%02x", digest[i]); + printf("\n"); +} + +static void show_bdb_header(const uint8_t *bdb) +{ + const struct bdb_header *header = bdb_get_header(bdb); + const struct bdb_key *key = bdb_get_bdbkey(bdb); + uint8_t digest[BDB_SHA256_DIGEST_SIZE]; + + printf("BDB Header:\n"); + printf(" Struct Version: 0x%x:0x%x\n", + header->struct_major_version, header->struct_minor_version); + + bdb_sha256(digest, key, key->struct_size); + print_digest(" BDB key digest: ", digest, sizeof(digest)); + printf(" size: %d\n", key->struct_size); +} + + +int ft_show_bdb(const char *name, uint8_t *buf, uint32_t len, void *data) +{ + const struct bdb_header *header = bdb_get_header(buf); + int rv; + + /* We can get here because of '--type' option */ + rv = bdb_check_header(header, len); + if (rv) { + fprintf(stderr, "ERROR: Invalid BDB blob: %d\n", rv); + return 1; + } + + printf("Boot Descriptor Block: %s\n", name); + show_bdb_header(buf); + + return 0; +} |