summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2016-09-22 09:48:20 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-10-04 21:19:12 -0700
commitc3daa95c50ad6976507c2f164f8be87bc7b75c1f (patch)
tree0c0ae829ccab7abb27e8401cc732fbc1908d801e
parenta1026841a3db4c76288576c8660248fd925763f9 (diff)
downloadvboot-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>
-rw-r--r--Makefile3
-rw-r--r--futility/bdb_helper.c68
-rw-r--r--futility/cmd_show.c1
-rw-r--r--futility/file_type.inc4
-rw-r--r--tests/futility/data/bdb.binbin0 -> 3716 bytes
-rw-r--r--tests/futility/test_file_types.c1
-rwxr-xr-xtests/futility/test_file_types.sh1
7 files changed, 77 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index d56b97e2..490b9f79 100644
--- a/Makefile
+++ b/Makefile
@@ -691,7 +691,8 @@ FUTIL_SRCS = \
futility/file_type_rwsig.c \
futility/file_type_usbpd1.c \
futility/vb1_helper.c \
- futility/vb2_helper.c
+ futility/vb2_helper.c \
+ futility/bdb_helper.c
# List of commands built in futility and futility_s.
FUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c
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;
+}
diff --git a/futility/cmd_show.c b/futility/cmd_show.c
index 261197de..9ad55ad8 100644
--- a/futility/cmd_show.c
+++ b/futility/cmd_show.c
@@ -399,6 +399,7 @@ static const char usage[] = "\n"
"\n"
"Where FILE could be\n"
"\n"
+ " a BDB\n"
" a keyblock (.keyblock)\n"
" a firmware preamble signature (VBLOCK_A/B)\n"
" a firmware image (bios.bin)\n"
diff --git a/futility/file_type.inc b/futility/file_type.inc
index 9259f648..b48c6c42 100644
--- a/futility/file_type.inc
+++ b/futility/file_type.inc
@@ -80,3 +80,7 @@ FILE_TYPE(USBPD1, "usbpd1", "USB-PD charger image (v1.0)",
R_(ft_recognize_usbpd1),
S_(ft_show_usbpd1),
S_(ft_sign_usbpd1))
+FILE_TYPE(BDB, "bdb", "Common Boot Flow Boot Descriptor Block",
+ R_(ft_recognize_bdb),
+ S_(ft_show_bdb),
+ NONE)
diff --git a/tests/futility/data/bdb.bin b/tests/futility/data/bdb.bin
new file mode 100644
index 00000000..1fe84463
--- /dev/null
+++ b/tests/futility/data/bdb.bin
Binary files differ
diff --git a/tests/futility/test_file_types.c b/tests/futility/test_file_types.c
index 6b286293..2bf27887 100644
--- a/tests/futility/test_file_types.c
+++ b/tests/futility/test_file_types.c
@@ -37,6 +37,7 @@ static struct {
{FILE_TYPE_VB2_PRIVKEY, "tests/futility/data/sample.vbprik2"},
{FILE_TYPE_PEM, "tests/testkeys/key_rsa2048.pem"},
{FILE_TYPE_USBPD1, "tests/futility/data/zinger_mp_image.bin"},
+ {FILE_TYPE_BDB, "tests/futility/data/bdb.bin"},
{FILE_TYPE_RWSIG, }, /* need a test for this */
};
BUILD_ASSERT(ARRAY_SIZE(test_case) == NUM_FILE_TYPES);
diff --git a/tests/futility/test_file_types.sh b/tests/futility/test_file_types.sh
index 4b7a9fb6..b0248a94 100755
--- a/tests/futility/test_file_types.sh
+++ b/tests/futility/test_file_types.sh
@@ -44,6 +44,7 @@ test_case "pubkey21" "tests/futility/data/sample.vbpubk2"
test_case "prikey21" "tests/futility/data/sample.vbprik2"
test_case "pem" "tests/testkeys/key_rsa2048.pem"
test_case "pem" "tests/testkeys/key_rsa8192.pub.pem"
+test_case "bdb" "tests/futility/data/bdb.bin"
# Expect failure here.
fail_case "/Sir/Not/Appearing/In/This/Film"