summaryrefslogtreecommitdiff
path: root/firmware/lib/vboot_display.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2013-07-25 08:48:47 -0600
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-08-30 16:47:03 +0000
commit527ba810eff4006cf69579f6b96cb4350cb1e189 (patch)
treeb6dbfc7e51af7478d8a333dbe32d3f7cc4574d8b /firmware/lib/vboot_display.c
parent8fa13ad6f727d44fdc0ae1d2bde5f54b32dab9b9 (diff)
downloadvboot-stabilize-4636.B.tar.gz
Implementation of Region APIstabilize-4636.B
At present reading data from storage in Vboot is a little fragmented. For the firmware image, we expect the boot loader to handle this. For the disk we have a block-level API. For the GBB (which also sits in the firmware image) we expect the entire thing to be read before Vboot is called. Add the concept of a region, and an API to read from a region. At present, and most pressing, is reading from a GBB region. In the future this could be extended to other parts of the firmware or even the disk. Move all access to the GBB into this API so that the boot loader can provide either a GBB region in one large contiguous chunk, or a function to deal with read requests from vboot. The call to VbExRegionRead() is behind a flag since not all boot loaders support it yet. The main change for boot loaders which don't support this new API is that vboot will do more behind the scenes. For example, it will allocate memory for chunks of data that it reads from the GBB, rather than just accessing it directly. This approach is considerably simpler than trying to pass char ** everywhere and have vboot decide whether something needs to be allocated or not. The tests are updated, mainly to include setting up a GBB structure accessible from VbCommonParams, which is now required by the firmware and kernel functions. In normal operation this is set up at the start of VbLoadFIrmware() and VbSelectAndLoadKernel() but for tests which call children of these functions directly, the GBB structure must be set up manually by the test. BUG=chrome-os-partner:21115 BRANCH=none TEST=manual FEATURES=test sudo -E emerge vboot_reference Change-Id: If2b8bbe467fdbd643239d8d9b5d7aa98df4d286f Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Hendricks <dhendrix@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/63336 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/167361
Diffstat (limited to 'firmware/lib/vboot_display.c')
-rw-r--r--firmware/lib/vboot_display.c233
1 files changed, 71 insertions, 162 deletions
diff --git a/firmware/lib/vboot_display.c b/firmware/lib/vboot_display.c
index f79dfe13..910c60a0 100644
--- a/firmware/lib/vboot_display.c
+++ b/firmware/lib/vboot_display.c
@@ -8,7 +8,9 @@
#include "sysincludes.h"
#include "bmpblk_font.h"
+#include "gbb_access.h"
#include "gbb_header.h"
+#include "region.h"
#include "utility.h"
#include "vboot_api.h"
#include "vboot_common.h"
@@ -20,49 +22,20 @@ static uint32_t disp_width = 0, disp_height = 0;
VbError_t VbGetLocalizationCount(VbCommonParams *cparams, uint32_t *count)
{
- GoogleBinaryBlockHeader *gbb =
- (GoogleBinaryBlockHeader *)cparams->gbb_data;
- BmpBlockHeader *hdr;
+ BmpBlockHeader hdr;
+ VbError_t ret;
/* Default to 0 on error */
*count = 0;
- /* Make sure bitmap data is inside the GBB and is non-zero in size */
- if (0 == gbb->bmpfv_size ||
- gbb->bmpfv_offset > cparams->gbb_size ||
- gbb->bmpfv_offset + gbb->bmpfv_size > cparams->gbb_size) {
- return VBERROR_INVALID_GBB;
- }
-
- /* Sanity-check the bitmap block header */
- hdr = (BmpBlockHeader *)(((uint8_t *)gbb) + gbb->bmpfv_offset);
- if ((0 != Memcmp(hdr->signature, BMPBLOCK_SIGNATURE,
- BMPBLOCK_SIGNATURE_SIZE)) ||
- (hdr->major_version > BMPBLOCK_MAJOR_VERSION) ||
- ((hdr->major_version == BMPBLOCK_MAJOR_VERSION) &&
- (hdr->minor_version > BMPBLOCK_MINOR_VERSION))) {
- return VBERROR_INVALID_BMPFV;
- }
+ ret = VbGbbReadBmpHeader(cparams, &hdr);
+ if (ret)
+ return ret;
- *count = hdr->number_of_localizations;
+ *count = hdr.number_of_localizations;
return VBERROR_SUCCESS;
}
-const char *VbHWID(VbCommonParams *cparams)
-{
- GoogleBinaryBlockHeader *gbb =
- (GoogleBinaryBlockHeader *)cparams->gbb_data;
-
- if (0 == gbb->hwid_size ||
- gbb->hwid_offset > cparams->gbb_size ||
- gbb->hwid_offset + gbb->hwid_size > cparams->gbb_size) {
- VBDEBUG(("VbHWID(): invalid hwid offset/size\n"));
- return "{INVALID}";
- }
-
- return (char *)((uint8_t *)gbb + gbb->hwid_offset);
-}
-
/*
* TODO: We could cache the font info to speed things up, by making the
* in-memory font structure distinct from the in-flash version. We'll do that
@@ -164,62 +137,24 @@ void VbRenderTextAtPos(const char *text, int right_to_left,
}
}
-#define OUTBUF_LEN 128
-
VbError_t VbDisplayScreenFromGBB(VbCommonParams *cparams, uint32_t screen,
VbNvContext *vncptr)
{
- GoogleBinaryBlockHeader *gbb =
- (GoogleBinaryBlockHeader *)cparams->gbb_data;
- static uint8_t *bmpfv;
- void *fullimage = NULL;
- BmpBlockHeader *hdr;
- ScreenLayout *layout;
- ImageInfo *image_info;
+ char *fullimage = NULL;
+ BmpBlockHeader hdr;
uint32_t screen_index;
uint32_t localization = 0;
VbError_t retval = VBERROR_UNKNOWN; /* Assume error until proven ok */
uint32_t inoutsize;
- uint32_t offset;
uint32_t i;
VbFont_t *font;
const char *text_to_show;
int rtol = 0;
- char outbuf[OUTBUF_LEN] = "";
- uint32_t used = 0;
+ VbError_t ret;
- /* Make sure bitmap data is inside the GBB and is non-zero in size */
- if (0 == gbb->bmpfv_size ||
- gbb->bmpfv_offset > cparams->gbb_size ||
- gbb->bmpfv_offset + gbb->bmpfv_size > cparams->gbb_size) {
- VBDEBUG(("VbDisplayScreenFromGBB(): "
- "invalid bmpfv offset/size\n"));
- return VBERROR_INVALID_GBB;
- }
-
- /* Copy bitmap data from GBB into RAM for speed */
- if (!bmpfv) {
-#ifdef COPY_BMP_DATA
- bmpfv = (uint8_t *)VbExMalloc(gbb->bmpfv_size);
- Memcpy(bmpfv, ((uint8_t *)gbb) + gbb->bmpfv_offset,
- gbb->bmpfv_size);
-#else
- bmpfv = ((uint8_t *)gbb) + gbb->bmpfv_offset;
-#endif
- }
-
- /* Sanity-check the bitmap block header */
- hdr = (BmpBlockHeader *)bmpfv;
- if ((0 != Memcmp(hdr->signature, BMPBLOCK_SIGNATURE,
- BMPBLOCK_SIGNATURE_SIZE)) ||
- (hdr->major_version > BMPBLOCK_MAJOR_VERSION) ||
- ((hdr->major_version == BMPBLOCK_MAJOR_VERSION) &&
- (hdr->minor_version > BMPBLOCK_MINOR_VERSION))) {
- VBDEBUG(("VbDisplayScreenFromGBB(): "
- "invalid/too new bitmap header\n"));
- retval = VBERROR_INVALID_BMPFV;
- goto VbDisplayScreenFromGBB_exit;
- }
+ ret = VbGbbReadBmpHeader(cparams, &hdr);
+ if (ret)
+ return ret;
/*
* Translate screen ID into index. Note that not all screens are in
@@ -263,7 +198,7 @@ VbError_t VbDisplayScreenFromGBB(VbCommonParams *cparams, uint32_t screen,
goto VbDisplayScreenFromGBB_exit;
}
- if (screen_index >= hdr->number_of_screenlayouts) {
+ if (screen_index >= hdr.number_of_screenlayouts) {
VBDEBUG(("VbDisplayScreenFromGBB(): "
"screen %d index %d not in the GBB\n",
(int)screen, (int)screen_index));
@@ -273,48 +208,31 @@ VbError_t VbDisplayScreenFromGBB(VbCommonParams *cparams, uint32_t screen,
/* Clip localization to number of localizations present in the GBB */
VbNvGet(vncptr, VBNV_LOCALIZATION_INDEX, &localization);
- if (localization >= hdr->number_of_localizations) {
+ if (localization >= hdr.number_of_localizations) {
localization = 0;
VbNvSet(vncptr, VBNV_LOCALIZATION_INDEX, localization);
}
- /*
- * Calculate offset of screen layout = start of screen stuff + correct
- * locale + correct screen.
- */
- offset = sizeof(BmpBlockHeader) +
- localization * hdr->number_of_screenlayouts *
- sizeof(ScreenLayout) +
- screen_index * sizeof(ScreenLayout);
- layout = (ScreenLayout *)(bmpfv + offset);
-
/* Display all bitmaps for the image */
for (i = 0; i < MAX_IMAGE_IN_LAYOUT; i++) {
- if (!layout->images[i].image_info_offset)
+ ScreenLayout layout;
+ ImageInfo image_info;
+ char hwid[256];
+
+ ret = VbGbbReadImage(cparams, localization, screen_index,
+ i, &layout, &image_info,
+ &fullimage, &inoutsize);
+ if (ret == VBERROR_NO_IMAGE_PRESENT) {
continue;
-
- offset = layout->images[i].image_info_offset;
- image_info = (ImageInfo *)(bmpfv + offset);
- fullimage = bmpfv + offset + sizeof(ImageInfo);
- inoutsize = image_info->original_size;
- if (inoutsize &&
- image_info->compression != COMPRESS_NONE) {
- fullimage = VbExMalloc(inoutsize);
- retval = VbExDecompress(
- bmpfv + offset + sizeof(ImageInfo),
- image_info->compressed_size,
- image_info->compression,
- fullimage, &inoutsize);
- if (VBERROR_SUCCESS != retval) {
- VbExFree(fullimage);
- goto VbDisplayScreenFromGBB_exit;
- }
+ } else if (ret) {
+ retval = ret;
+ goto VbDisplayScreenFromGBB_exit;
}
- switch(image_info->format) {
+ switch(image_info.format) {
case FORMAT_BMP:
- retval = VbExDisplayImage(layout->images[i].x,
- layout->images[i].y,
+ retval = VbExDisplayImage(layout.images[i].x,
+ layout.images[i].y,
fullimage, inoutsize);
break;
@@ -323,21 +241,23 @@ VbError_t VbDisplayScreenFromGBB(VbCommonParams *cparams, uint32_t screen,
* The uncompressed blob is our font structure. Cache
* it as needed.
*/
- font = VbInternalizeFontData(fullimage);
+ font = VbInternalizeFontData(
+ (FontArrayHeader *)fullimage);
/* TODO: handle text in general here */
- if (TAG_HWID == image_info->tag ||
- TAG_HWID_RTOL == image_info->tag) {
- text_to_show = VbHWID(cparams);
- rtol = (TAG_HWID_RTOL == image_info->tag);
+ if (TAG_HWID == image_info.tag ||
+ TAG_HWID_RTOL == image_info.tag) {
+ VbRegionReadHWID(cparams, hwid, sizeof(hwid));
+ text_to_show = hwid;
+ rtol = (TAG_HWID_RTOL == image_info.tag);
} else {
text_to_show = "";
rtol = 0;
}
VbRenderTextAtPos(text_to_show, rtol,
- layout->images[i].x,
- layout->images[i].y, font);
+ layout.images[i].x,
+ layout.images[i].y, font);
VbDoneWithFontForNow(font);
break;
@@ -345,12 +265,11 @@ VbError_t VbDisplayScreenFromGBB(VbCommonParams *cparams, uint32_t screen,
default:
VBDEBUG(("VbDisplayScreenFromGBB(): "
"unsupported ImageFormat %d\n",
- image_info->format));
+ image_info.format));
retval = VBERROR_INVALID_GBB;
}
- if (COMPRESS_NONE != image_info->compression)
- VbExFree(fullimage);
+ VbExFree(fullimage);
if (VBERROR_SUCCESS != retval)
goto VbDisplayScreenFromGBB_exit;
@@ -359,29 +278,15 @@ VbError_t VbDisplayScreenFromGBB(VbCommonParams *cparams, uint32_t screen,
/* Successful if all bitmaps displayed */
retval = VBERROR_SUCCESS;
- /*
- * If GBB flags is nonzero, complain because that's something that the
- * factory MUST fix before shipping. We only have to do this here,
- * because it's obvious that something is wrong if we're not displaying
- * screens from the GBB.
- */
- if (gbb->major_version == GBB_MAJOR_VER && gbb->minor_version >= 1 &&
- (gbb->flags != 0)) {
- used += StrnAppend(outbuf + used, "gbb.flags is nonzero: 0x",
- OUTBUF_LEN - used);
- used += Uint64ToString(outbuf + used, OUTBUF_LEN - used,
- gbb->flags, 16, 8);
- used += StrnAppend(outbuf + used, "\n", OUTBUF_LEN - used);
- (void)VbExDisplayDebugInfo(outbuf);
- }
+ VbRegionCheckVersion(cparams);
VbDisplayScreenFromGBB_exit:
VBDEBUG(("leaving VbDisplayScreenFromGBB() with %d\n",retval));
return retval;
}
-VbError_t VbDisplayScreen(VbCommonParams *cparams, uint32_t screen, int force,
- VbNvContext *vncptr)
+VbError_t VbDisplayScreen(VbCommonParams *cparams, uint32_t screen,
+ int force, VbNvContext *vncptr)
{
VbError_t retval;
@@ -403,7 +308,8 @@ VbError_t VbDisplayScreen(VbCommonParams *cparams, uint32_t screen, int force,
disp_current_screen = screen;
/* Look in the GBB first */
- if (VBERROR_SUCCESS == VbDisplayScreenFromGBB(cparams, screen, vncptr))
+ if (VBERROR_SUCCESS == VbDisplayScreenFromGBB(cparams, screen,
+ vncptr))
return VBERROR_SUCCESS;
/* If screen wasn't in the GBB bitmaps, fall back to a default */
@@ -571,29 +477,22 @@ VbError_t VbDisplayDebugInfo(VbCommonParams *cparams, VbNvContext *vncptr)
{
VbSharedDataHeader *shared =
(VbSharedDataHeader *)cparams->shared_data_blob;
- GoogleBinaryBlockHeader *gbb =
- (GoogleBinaryBlockHeader *)cparams->gbb_data;
+ GoogleBinaryBlockHeader *gbb = cparams->gbb;
char buf[DEBUG_INFO_SIZE] = "";
char sha1sum[SHA1_DIGEST_SIZE * 2 + 1];
+ char hwid[256];
uint32_t used = 0;
+ VbPublicKey *key;
+ VbError_t ret;
uint32_t i;
/* Redisplay current screen to overwrite any previous debug output */
VbDisplayScreen(cparams, disp_current_screen, 1, vncptr);
/* Add hardware ID */
+ VbRegionReadHWID(cparams, hwid, sizeof(hwid));
used += StrnAppend(buf + used, "HWID: ", DEBUG_INFO_SIZE - used);
- if (0 == gbb->hwid_size ||
- gbb->hwid_offset > cparams->gbb_size ||
- gbb->hwid_offset + gbb->hwid_size > cparams->gbb_size) {
- VBDEBUG(("VbDisplayDebugInfo(): invalid hwid offset/size\n"));
- used += StrnAppend(buf + used,
- "(INVALID)", DEBUG_INFO_SIZE - used);
- } else {
- used += StrnAppend(buf + used,
- (char *)((uint8_t *)gbb + gbb->hwid_offset),
- DEBUG_INFO_SIZE - used);
- }
+ used += StrnAppend(buf + used, hwid, DEBUG_INFO_SIZE - used);
/* Add recovery reason */
used += StrnAppend(buf + used,
@@ -654,15 +553,25 @@ VbError_t VbDisplayDebugInfo(VbCommonParams *cparams, VbNvContext *vncptr)
}
/* Add sha1sum for Root & Recovery keys */
- FillInSha1Sum(sha1sum,
- (VbPublicKey *)((uint8_t *)gbb + gbb->rootkey_offset));
- used += StrnAppend(buf + used, "\ngbb.rootkey: ", DEBUG_INFO_SIZE - used);
- used += StrnAppend(buf + used, sha1sum, DEBUG_INFO_SIZE - used);
- FillInSha1Sum(sha1sum,
- (VbPublicKey *)((uint8_t *)gbb + gbb->recovery_key_offset));
- used += StrnAppend(buf + used,
- "\ngbb.recovery_key: ", DEBUG_INFO_SIZE - used);
- used += StrnAppend(buf + used, sha1sum, DEBUG_INFO_SIZE - used);
+ ret = VbGbbReadRootKey(cparams, &key);
+ if (!ret) {
+ FillInSha1Sum(sha1sum, key);
+ VbExFree(key);
+ used += StrnAppend(buf + used, "\ngbb.rootkey: ",
+ DEBUG_INFO_SIZE - used);
+ used += StrnAppend(buf + used, sha1sum,
+ DEBUG_INFO_SIZE - used);
+ }
+
+ ret = VbGbbReadRecoveryKey(cparams, &key);
+ if (!ret) {
+ FillInSha1Sum(sha1sum, key);
+ VbExFree(key);
+ used += StrnAppend(buf + used, "\ngbb.recovery_key: ",
+ DEBUG_INFO_SIZE - used);
+ used += StrnAppend(buf + used, sha1sum,
+ DEBUG_INFO_SIZE - used);
+ }
/* If we're in dev-mode, show the kernel subkey that we expect, too. */
if (0 == shared->recovery_reason) {