summaryrefslogtreecommitdiff
path: root/futility/cmd_show.c
diff options
context:
space:
mode:
Diffstat (limited to 'futility/cmd_show.c')
-rw-r--r--futility/cmd_show.c224
1 files changed, 4 insertions, 220 deletions
diff --git a/futility/cmd_show.c b/futility/cmd_show.c
index 714b0e58..44a3ab36 100644
--- a/futility/cmd_show.c
+++ b/futility/cmd_show.c
@@ -20,14 +20,12 @@
#include <sys/types.h>
#include <unistd.h>
-#include "bmpblk_header.h"
#include "file_type.h"
+#include "file_type_bios.h"
#include "fmap.h"
#include "futility.h"
#include "futility_options.h"
-#include "gbb_header.h"
#include "host_common.h"
-#include "traversal.h"
#include "util_misc.h"
#include "vb1_helper.h"
#include "vboot_common.h"
@@ -38,42 +36,7 @@ struct show_option_s show_option = {
.type = FILE_TYPE_UNKNOWN,
};
-/* Stuff for BIOS images. */
-
-/* Forward declarations */
-static int fmap_fw_main(const char *name, uint8_t *buf, uint32_t len,
- void *data);
-
-/* These are the functions we'll call for each FMAP area. */
-static int (*fmap_func[])(const char *name, uint8_t *buf, uint32_t len,
- void *data) = {
- ft_show_gbb,
- fmap_fw_main,
- fmap_fw_main,
- ft_show_fw_preamble,
- ft_show_fw_preamble,
-};
-BUILD_ASSERT(ARRAY_SIZE(fmap_func) == NUM_BIOS_COMPONENTS);
-
-/* Where is the component we're looking at? */
-struct bios_area_s {
- uint32_t offset; /* to avoid pointer math */
- uint8_t *buf;
- uint32_t len;
- uint32_t is_valid;
-};
-
-/* When looking at the FMAP areas, we need to gather some state for later. */
-struct show_state_s {
- /* Current component */
- enum bios_component c;
- /* Other activites, possibly before or after the current one */
- struct bios_area_s area[NUM_BIOS_COMPONENTS];
- struct bios_area_s recovery_key;
- struct bios_area_s rootkey;
-};
-
-static void show_key(VbPublicKey *pubkey, const char *sp)
+void show_pubkey(VbPublicKey *pubkey, const char *sp)
{
printf("%sVboot API: 1.0\n", sp);
printf("%sAlgorithm: %" PRIu64 " %s\n", sp, pubkey->algorithm,
@@ -129,7 +92,7 @@ int ft_show_pubkey(const char *name, uint8_t *buf, uint32_t len, void *data)
}
printf("Public Key file: %s\n", name);
- show_key(pubkey, " ");
+ show_pubkey(pubkey, " ");
return 0;
}
@@ -166,108 +129,6 @@ int ft_show_privkey(const char *name, uint8_t *buf, uint32_t len, void *data)
return 0;
}
-int ft_show_gbb(const char *name, uint8_t *buf, uint32_t len, void *data)
-{
- GoogleBinaryBlockHeader *gbb = (GoogleBinaryBlockHeader *)buf;
- struct show_state_s *state = (struct show_state_s *)data;
- VbPublicKey *pubkey;
- BmpBlockHeader *bmp;
- int retval = 0;
- uint32_t maxlen = 0;
-
- if (!len) {
- printf("GBB header: %s <invalid>\n", name);
- return 1;
- }
-
- /* It looks like a GBB or we wouldn't be called. */
- if (!futil_valid_gbb_header(gbb, len, &maxlen))
- retval = 1;
-
- printf("GBB header: %s\n", name);
- printf(" Version: %d.%d\n",
- gbb->major_version, gbb->minor_version);
- printf(" Flags: 0x%08x\n", gbb->flags);
- printf(" Regions: offset size\n");
- printf(" hwid 0x%08x 0x%08x\n",
- gbb->hwid_offset, gbb->hwid_size);
- printf(" bmpvf 0x%08x 0x%08x\n",
- gbb->bmpfv_offset, gbb->bmpfv_size);
- printf(" rootkey 0x%08x 0x%08x\n",
- gbb->rootkey_offset, gbb->rootkey_size);
- printf(" recovery_key 0x%08x 0x%08x\n",
- gbb->recovery_key_offset, gbb->recovery_key_size);
-
- printf(" Size: 0x%08x / 0x%08x%s\n",
- maxlen, len, maxlen > len ? " (not enough)" : "");
-
- if (retval) {
- printf("GBB header is invalid, ignoring content\n");
- return 1;
- }
-
- printf("GBB content:\n");
- printf(" HWID: %s\n", buf + gbb->hwid_offset);
- print_hwid_digest(gbb, " digest: ", "\n");
-
- pubkey = (VbPublicKey *)(buf + gbb->rootkey_offset);
- if (PublicKeyLooksOkay(pubkey, gbb->rootkey_size)) {
- if (state) {
- state->rootkey.offset =
- state->area[BIOS_FMAP_GBB].offset +
- gbb->rootkey_offset;
- state->rootkey.buf = buf + gbb->rootkey_offset;
- state->rootkey.len = gbb->rootkey_size;
- state->rootkey.is_valid = 1;
- }
- printf(" Root Key:\n");
- show_key(pubkey, " ");
- } else {
- retval = 1;
- printf(" Root Key: <invalid>\n");
- }
-
- pubkey = (VbPublicKey *)(buf + gbb->recovery_key_offset);
- if (PublicKeyLooksOkay(pubkey, gbb->recovery_key_size)) {
- if (state) {
- state->recovery_key.offset =
- state->area[BIOS_FMAP_GBB].offset +
- gbb->recovery_key_offset;
- state->recovery_key.buf = buf +
- gbb->recovery_key_offset;
- state->recovery_key.len = gbb->recovery_key_size;
- state->recovery_key.is_valid = 1;
- }
- printf(" Recovery Key:\n");
- show_key(pubkey, " ");
- } else {
- retval = 1;
- printf(" Recovery Key: <invalid>\n");
- }
-
- bmp = (BmpBlockHeader *)(buf + gbb->bmpfv_offset);
- if (0 != memcmp(bmp, BMPBLOCK_SIGNATURE, BMPBLOCK_SIGNATURE_SIZE)) {
- printf(" BmpBlock: <invalid>\n");
- /* We don't support older BmpBlock formats, so we can't
- * be strict about this. */
- } else {
- printf(" BmpBlock:\n");
- printf(" Version: %d.%d\n",
- bmp->major_version, bmp->minor_version);
- printf(" Localizations: %d\n",
- bmp->number_of_localizations);
- printf(" Screen layouts: %d\n",
- bmp->number_of_screenlayouts);
- printf(" Image infos: %d\n",
- bmp->number_of_imageinfos);
- }
-
- if (!retval && state)
- state->area[BIOS_FMAP_GBB].is_valid = 1;
-
- return retval;
-}
-
int ft_show_keyblock(const char *name, uint8_t *buf, uint32_t len, void *data)
{
VbKeyBlockHeader *block = (VbKeyBlockHeader *)buf;
@@ -294,38 +155,11 @@ int ft_show_keyblock(const char *name, uint8_t *buf, uint32_t len, void *data)
return retval;
}
-/*
- * This handles FW_MAIN_A and FW_MAIN_B while processing a BIOS image.
- *
- * The data is just the RW firmware blob, so there's nothing useful to show
- * about it. We'll just mark it as present so when we encounter corresponding
- * VBLOCK area, we'll have this to verify.
- */
-static int fmap_fw_main(const char *name, uint8_t *buf, uint32_t len,
- void *data)
-{
- struct show_state_s *state = (struct show_state_s *)data;
-
- if (!len) {
- printf("Firmware body: %s <invalid>\n", name);
- return 1;
- }
-
- printf("Firmware body: %s\n", name);
- printf(" Offset: 0x%08x\n",
- state->area[state->c].offset);
- printf(" Size: 0x%08x\n", len);
-
- state->area[state->c].is_valid = 1;
-
- return 0;
-}
-
int ft_show_fw_preamble(const char *name, uint8_t *buf, uint32_t len,
void *data)
{
VbKeyBlockHeader *key_block = (VbKeyBlockHeader *)buf;
- struct show_state_s *state = (struct show_state_s *)data;
+ struct bios_state_s *state = (struct bios_state_s *)data;
VbPublicKey *sign_key = show_option.k;
uint8_t *fv_data = show_option.fv;
uint64_t fv_size = show_option.fv_size;
@@ -346,7 +180,6 @@ int ft_show_fw_preamble(const char *name, uint8_t *buf, uint32_t len,
* so we'll have to get any keys or data from options.
*/
if (state) {
-
if (!sign_key && state->rootkey.is_valid)
/* BIOS should have a rootkey in the GBB */
sign_key = (VbPublicKey *)state->rootkey.buf;
@@ -449,55 +282,6 @@ done:
return retval;
}
-int ft_show_bios(const char *name, uint8_t *buf, uint32_t len, void *data)
-{
- FmapHeader *fmap;
- FmapAreaHeader *ah = 0;
- char ah_name[FMAP_NAMELEN + 1];
- int i;
- int retval = 0;
- struct show_state_s state;
-
- memset(&state, 0, sizeof(state));
-
- printf("BIOS: %s\n", name);
-
- /* We've already checked, so we know this will work. */
- fmap = fmap_find(buf, len);
- for (i = 0; i < NUM_BIOS_COMPONENTS; i++) {
- /* We know one of these will work, too */
- if (fmap_find_by_name(buf, len, fmap,
- bios_area[i].name, &ah) ||
- fmap_find_by_name(buf, len, fmap,
- bios_area[i].oldname, &ah)) {
- /* But the file might be truncated */
- fmap_limit_area(ah, len);
- /* The name is not necessarily null-terminated */
- snprintf(ah_name, sizeof(ah_name), "%s", ah->area_name);
-
- /* Update the state we're passing around */
- state.c = i;
- state.area[i].offset = ah->area_offset;
- state.area[i].buf = buf + ah->area_offset;
- state.area[i].len = ah->area_size;
-
- Debug("%s() showing FMAP area %d (%s),"
- " offset=0x%08x len=0x%08x\n",
- __func__, i, ah_name,
- ah->area_offset, ah->area_size);
-
- /* Go look at it. */
- if (fmap_func[i])
- retval += fmap_func[i](ah_name,
- state.area[i].buf,
- state.area[i].len,
- &state);
- }
- }
-
- return retval;
-}
-
int ft_show_kernel_preamble(const char *name, uint8_t *buf, uint32_t len,
void *data)
{