mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-15 20:37:33 +00:00
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>
This commit is contained in:
committed by
chrome-bot
parent
a1026841a3
commit
c3daa95c50
3
Makefile
3
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
|
||||
|
||||
68
futility/bdb_helper.c
Normal file
68
futility/bdb_helper.c
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
BIN
tests/futility/data/bdb.bin
Normal file
BIN
tests/futility/data/bdb.bin
Normal file
Binary file not shown.
@@ -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);
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user