firmware: Remove bmpblk code

All screens are now drawn by depthcharge.  ToT firmware does not
include a bmpblk / bmpfv section in the GBB.  Remove the code paths
which are no longer used.

Also drop a few cparams parameters from functions that no longer use
it, now that those functions don't need to access the GBB.

BUG=chromium:502066
BRANCH=none
TEST=make -j runtests; build bob firmware and check recovery screens

Change-Id: I4d2d0a3ba57c34151e65c6f42581df823192a4ae
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/852371
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Stefan Reinauer <reinauer@chromium.org>
This commit is contained in:
Randall Spangler
2018-01-02 15:40:04 -08:00
committed by chrome-bot
parent 3942724069
commit 7d92bd8a6b
15 changed files with 61 additions and 656 deletions

View File

@@ -305,7 +305,7 @@ struct vb2_gbb_header {
uint32_t hwid_size;
uint32_t rootkey_offset; /* Root key */
uint32_t rootkey_size;
uint32_t bmpfv_offset; /* BMP FV */
uint32_t bmpfv_offset; /* BMP FV; deprecated in current FW */
uint32_t bmpfv_size;
uint32_t recovery_key_offset; /* Recovery key */
uint32_t recovery_key_size;

View File

@@ -49,35 +49,4 @@ VbError_t VbGbbReadRootKey(VbCommonParams *cparams,
VbError_t VbGbbReadRecoveryKey(VbCommonParams *cparams,
struct VbPublicKey **keyp);
/**
* Read the bitmap block header from the GBB
*
* @param cparams Vboot common parameters
* @param hdr The header is placed in this block
* @return VBERROR_... error, VBERROR_SUCCESS on success,
*/
VbError_t VbGbbReadBmpHeader(VbCommonParams *cparams,
struct BmpBlockHeader *hdr);
/**
* Read a image from the GBB
*
* The caller must call free() on *image_datap when finished with it.
*
* @param cparams Vboot common parameters
* @param localization Localization/language number
* @param screen_index Index of screen to display (VB_SCREEN_...)
* @param image_num Image number within the screen
* @param layout Returns layout information (x, y position)
* @param image_info Returns information about the image (format)
* @param image_datap Returns a pointer to the image data
* @param iamge_data_sizep Return size of image data
* @return VBERROR_... error, VBERROR_SUCCESS on success,
*/
VbError_t VbGbbReadImage(VbCommonParams *cparams,
uint32_t localization, uint32_t screen_index,
uint32_t image_num, struct ScreenLayout *layout,
struct ImageInfo *image_info, char **image_datap,
uint32_t *image_data_sizep);
#endif

View File

@@ -95,7 +95,7 @@ typedef struct GoogleBinaryBlockHeader
uint32_t hwid_size;
uint32_t rootkey_offset; /* Root key */
uint32_t rootkey_size;
uint32_t bmpfv_offset; /* BMP FV */
uint32_t bmpfv_offset; /* BMP FV; deprecated in current FW */
uint32_t bmpfv_size;
uint32_t recovery_key_offset; /* Recovery key */
uint32_t recovery_key_size;

View File

@@ -122,7 +122,7 @@ enum VbErrorPredefined_t {
VBERROR_REGION_READ_FAILED = 0x10024,
/* Unsupported region type */
VBERROR_UNSUPPORTED_REGION = 0x10025,
/* No image present (returned from VbGbbReadImage() for missing image) */
/* No image present (was returned from VbGbbReadImage(); deprecated */
VBERROR_NO_IMAGE_PRESENT = 0x10026,
/* failed to draw screen */
VBERROR_SCREEN_DRAW = 0x10027,
@@ -196,7 +196,6 @@ typedef struct VbCommonParams {
/* For internal use of Vboot - do not examine or modify! */
struct GoogleBinaryBlockHeader *gbb;
struct BmpBlockHeader *bmp;
} VbCommonParams;
/* Flags for VbInitParams.flags */

View File

@@ -57,7 +57,7 @@ VbError_t ec_sync_all(struct vb2_context *ctx, struct VbCommonParams *cparams)
/* Display the wait screen if we need it */
if (need_wait_screen) {
VB2_DEBUG("EC is slow. Show WAIT screen.\n");
VbDisplayScreen(ctx, cparams, VB_SCREEN_WAIT, 0);
VbDisplayScreen(ctx, VB_SCREEN_WAIT, 0);
}
/* Phase 2; Applies update and/or jumps to the correct EC image */

View File

@@ -8,48 +8,20 @@
#ifndef VBOOT_REFERENCE_VBOOT_DISPLAY_H_
#define VBOOT_REFERENCE_VBOOT_DISPLAY_H_
#include "bmpblk_font.h"
struct vb2_context;
VbError_t VbDisplayScreenFromGBB(struct vb2_context *ctx,
VbCommonParams *cparams, uint32_t screen,
uint32_t locale);
VbError_t VbDisplayScreen(struct vb2_context *ctx, VbCommonParams *cparams,
uint32_t screen, int force);
VbError_t VbDisplayMenu(struct vb2_context *ctx, VbCommonParams *cparams,
VbError_t VbDisplayScreen(struct vb2_context *ctx, uint32_t screen, int force);
VbError_t VbDisplayMenu(struct vb2_context *ctx,
uint32_t screen, int force, uint32_t selected_index,
uint32_t disabled_idx_mask);
VbError_t VbDisplayDebugInfo(struct vb2_context *ctx, VbCommonParams *cparams);
VbError_t VbCheckDisplayKey(struct vb2_context *ctx, VbCommonParams *cparams,
uint32_t key);
/* Internal functions, for unit testing */
typedef FontArrayHeader VbFont_t;
VbFont_t *VbInternalizeFontData(FontArrayHeader *fonthdr);
void VbDoneWithFontForNow(VbFont_t *ptr);
ImageInfo *VbFindFontGlyph(VbFont_t *font, uint32_t ascii,
void **bufferptr, uint32_t *buffersize);
/**
* Try to display the specified text at a particular position.
*/
void VbRenderTextAtPos(const char *text, int right_to_left,
uint32_t x, uint32_t y, VbFont_t *font);
/**
* Return a description of the recovery reason code.
*/
const char *RecoveryReasonString(uint8_t code);
/**
* Get the number of localizations in the GBB bitmap data.
*/
VbError_t VbGetLocalizationCount(VbCommonParams *cparams, uint32_t *count);
#endif /* VBOOT_REFERENCE_VBOOT_DISPLAY_H_ */

View File

@@ -25,45 +25,6 @@ static VbError_t VbRegionReadGbb(VbCommonParams *cparams, uint32_t offset,
return VbRegionReadData(cparams, VB_REGION_GBB, offset, size, buf);
}
VbError_t VbGbbReadBmpHeader(VbCommonParams *cparams, BmpBlockHeader *hdr_ret)
{
BmpBlockHeader *hdr;
VbError_t ret;
if (!cparams)
return VBERROR_INVALID_GBB;
if (!cparams->bmp) {
GoogleBinaryBlockHeader *gbb = cparams->gbb;
if (0 == gbb->bmpfv_size)
return VBERROR_INVALID_GBB;
hdr = malloc(sizeof(*hdr));
ret = VbRegionReadGbb(cparams, gbb->bmpfv_offset,
sizeof(BmpBlockHeader), hdr);
if (ret) {
free(hdr);
return ret;
}
/* Sanity-check the bitmap block header */
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))) {
VB2_DEBUG("VbGbbReadBmpHeader(): "
"invalid/too new bitmap header\n");
free(hdr);
return VBERROR_INVALID_BMPFV;
}
cparams->bmp = hdr;
}
*hdr_ret = *cparams->bmp;
return VBERROR_SUCCESS;
}
VbError_t VbRegionReadHWID(VbCommonParams *cparams, char *hwid,
uint32_t max_size)
{
@@ -95,80 +56,6 @@ VbError_t VbRegionReadHWID(VbCommonParams *cparams, char *hwid,
return VBERROR_SUCCESS;
}
VbError_t VbGbbReadImage(VbCommonParams *cparams,
uint32_t localization, uint32_t screen_index,
uint32_t image_num, ScreenLayout *layout,
ImageInfo *image_info, char **image_datap,
uint32_t *image_data_sizep)
{
uint32_t layout_offset, image_offset, data_offset, data_size;
GoogleBinaryBlockHeader *gbb;
BmpBlockHeader hdr;
void *data = NULL;
VbError_t ret;
if (!cparams)
return VBERROR_INVALID_GBB;
ret = VbGbbReadBmpHeader(cparams, &hdr);
if (ret)
return ret;
gbb = cparams->gbb;
layout_offset = gbb->bmpfv_offset + sizeof(BmpBlockHeader) +
localization * hdr.number_of_screenlayouts *
sizeof(ScreenLayout) +
screen_index * sizeof(ScreenLayout);
ret = VbRegionReadGbb(cparams, layout_offset, sizeof(*layout), layout);
if (ret)
return ret;
if (!layout->images[image_num].image_info_offset)
return VBERROR_NO_IMAGE_PRESENT;
image_offset = gbb->bmpfv_offset +
layout->images[image_num].image_info_offset;
ret = VbRegionReadGbb(cparams, image_offset, sizeof(*image_info),
image_info);
if (ret)
return ret;
data_offset = image_offset + sizeof(*image_info);
data_size = image_info->compressed_size;
if (data_size) {
void *orig_data;
data = malloc(image_info->compressed_size);
ret = VbRegionReadGbb(cparams, data_offset,
image_info->compressed_size, data);
if (ret) {
free(data);
return ret;
}
if (image_info->compression != COMPRESS_NONE) {
uint32_t inoutsize = image_info->original_size;
orig_data = malloc(image_info->original_size);
ret = VbExDecompress(data,
image_info->compressed_size,
image_info->compression,
orig_data, &inoutsize);
data_size = inoutsize;
free(data);
data = orig_data;
if (ret) {
free(data);
return ret;
}
}
}
*image_datap = data;
*image_data_sizep = data_size;
return VBERROR_SUCCESS;
}
#define OUTBUF_LEN 128
void VbRegionCheckVersion(VbCommonParams *cparams)

View File

@@ -242,10 +242,6 @@ void VbApiKernelFree(VbCommonParams *cparams)
free(cparams->gbb);
cparams->gbb = NULL;
}
if (cparams->bmp) {
free(cparams->bmp);
cparams->bmp = NULL;
}
}
static VbError_t vb2_kernel_setup(VbCommonParams *cparams,
@@ -341,7 +337,6 @@ static VbError_t vb2_kernel_setup(VbCommonParams *cparams,
memset(kparams->partition_guid, 0, sizeof(kparams->partition_guid));
/* Read GBB header, since we'll needs flags from it */
cparams->bmp = NULL;
cparams->gbb = malloc(sizeof(*cparams->gbb));
uint32_t retval = VbGbbReadHeader_static(cparams, cparams->gbb);
if (retval)

View File

@@ -24,335 +24,16 @@
static uint32_t disp_current_screen = VB_SCREEN_BLANK;
static uint32_t disp_current_index = 0;
static uint32_t disp_disabled_idx_mask = 0;
static uint32_t disp_width = 0, disp_height = 0;
__attribute__((weak))
VbError_t VbExGetLocalizationCount(uint32_t *count) {
*count = 0;
return VBERROR_UNKNOWN;
}
VbError_t VbGetLocalizationCount(VbCommonParams *cparams, uint32_t *count)
{
BmpBlockHeader hdr;
VbError_t ret;
/* Default to 0 on error */
*count = 0;
/* First try to get the count from GBB */
ret = VbGbbReadBmpHeader(cparams, &hdr);
if (ret == VBERROR_SUCCESS) {
*count = hdr.number_of_localizations;
return ret;
}
/* If GBB is broken or missing, fallback to the callback */
return VbExGetLocalizationCount(count);
}
/*
* 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
* Real Soon Now. Until then, we just repeat the same linear search every time.
*/
VbFont_t *VbInternalizeFontData(FontArrayHeader *fonthdr)
{
/* Just return the raw data pointer for now. */
return (VbFont_t *)fonthdr;
}
void VbDoneWithFontForNow(VbFont_t *ptr)
{
/* Nothing. */
}
ImageInfo *VbFindFontGlyph(VbFont_t *font, uint32_t ascii,
void **bufferptr, uint32_t *buffersize)
{
uint8_t *ptr, *firstptr;
uint32_t max;
uint32_t i;
FontArrayEntryHeader *entry;
ptr = (uint8_t *)font;
max = ((FontArrayHeader *)ptr)->num_entries;
ptr += sizeof(FontArrayHeader);
firstptr = ptr;
/*
* Simple linear search.
*
* Note: We're assuming glpyhs are uncompressed. That's true because
* the bmpblk_font tool doesn't compress anything. The bmpblk_utility
* does, but it compresses the entire font blob at once, and we've
* already uncompressed that before we got here.
*/
for(i=0; i<max; i++) {
entry = (FontArrayEntryHeader *)ptr;
if (entry->ascii == ascii) {
*bufferptr = ptr + sizeof(FontArrayEntryHeader);
*buffersize = entry->info.original_size;
return &(entry->info);
}
ptr += sizeof(FontArrayEntryHeader)+entry->info.compressed_size;
}
/*
* We must return something valid. We'll just use the first glyph in
* the font structure (so it should be something distinct).
*/
entry = (FontArrayEntryHeader *)firstptr;
*bufferptr = firstptr + sizeof(FontArrayEntryHeader);
*buffersize = entry->info.original_size;
return &(entry->info);
}
void VbRenderTextAtPos(const char *text, int right_to_left,
uint32_t x, uint32_t y, VbFont_t *font)
{
int i;
ImageInfo *image_info = 0;
void *buffer;
uint32_t buffersize;
uint32_t cur_x = x, cur_y = y;
if (!text || !font) {
VB2_DEBUG(" VbRenderTextAtPos: invalid args\n");
return;
}
for (i=0; text[i]; i++) {
if (text[i] == '\n') {
if (!image_info)
image_info = VbFindFontGlyph(font, text[i],
&buffer,
&buffersize);
cur_x = x;
cur_y += image_info->height;
continue;
}
image_info = VbFindFontGlyph(font, text[i], &buffer,
&buffersize);
if (right_to_left)
cur_x -= image_info->width;
if (VBERROR_SUCCESS != VbExDisplayImage(cur_x, cur_y, buffer,
buffersize)) {
VB2_DEBUG(" VbRenderTextAtPos: "
"can't display ascii 0x%x\n", text[i]);
}
if (!right_to_left)
cur_x += image_info->width;
}
}
VbError_t VbDisplayScreenFromGBB(struct vb2_context *ctx,
VbCommonParams *cparams, uint32_t screen,
uint32_t localization)
{
char *fullimage = NULL;
BmpBlockHeader hdr;
uint32_t screen_index;
VbError_t retval = VBERROR_UNKNOWN; /* Assume error until proven ok */
uint32_t inoutsize;
uint32_t i;
VbFont_t *font;
const char *text_to_show;
int rtol = 0;
VbError_t ret;
ret = VbGbbReadBmpHeader(cparams, &hdr);
if (ret)
return ret;
/*
* Translate screen ID into index. Note that not all screens are in
* the GBB.
*
* TODO: ensure screen IDs match indices? Having this translation here
* is awful.
*/
switch (screen) {
case VB_SCREEN_DEVELOPER_WARNING:
screen_index = SCREEN_DEVELOPER_WARNING;
break;
case VB_SCREEN_RECOVERY_REMOVE:
screen_index = SCREEN_RECOVERY_REMOVE;
break;
case VB_SCREEN_RECOVERY_NO_GOOD:
screen_index = SCREEN_RECOVERY_NO_GOOD;
break;
case VB_SCREEN_RECOVERY_INSERT:
screen_index = SCREEN_RECOVERY_INSERT;
break;
case VB_SCREEN_RECOVERY_TO_DEV:
screen_index = SCREEN_RECOVERY_TO_DEV;
break;
case VB_SCREEN_DEVELOPER_TO_NORM:
screen_index = SCREEN_DEVELOPER_TO_NORM;
break;
case VB_SCREEN_WAIT:
screen_index = SCREEN_WAIT;
break;
case VB_SCREEN_TO_NORM_CONFIRMED:
screen_index = SCREEN_TO_NORM_CONFIRMED;
break;
case VB_SCREEN_OS_BROKEN:
screen_index = SCREEN_OS_BROKEN;
break;
case VB_SCREEN_BLANK:
case VB_SCREEN_DEVELOPER_EGG:
default:
/* Screens which aren't in the GBB */
VB2_DEBUG("VbDisplayScreenFromGBB(): screen %d not in GBB\n",
(int)screen);
retval = VBERROR_INVALID_SCREEN_INDEX;
goto VbDisplayScreenFromGBB_exit;
}
if (screen_index >= hdr.number_of_screenlayouts) {
VB2_DEBUG("VbDisplayScreenFromGBB(): "
"screen %d index %d not in the GBB\n",
(int)screen, (int)screen_index);
retval = VBERROR_INVALID_SCREEN_INDEX;
goto VbDisplayScreenFromGBB_exit;
}
/* Clip localization to number of localizations present in the GBB */
if (localization >= hdr.number_of_localizations) {
localization = 0;
vb2_nv_set(ctx, VB2_NV_LOCALIZATION_INDEX, localization);
vb2_nv_set(ctx, VB2_NV_BACKUP_NVRAM_REQUEST, 1);
}
/* Display all bitmaps for the image */
for (i = 0; i < MAX_IMAGE_IN_LAYOUT; i++) {
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;
} else if (ret) {
retval = ret;
goto VbDisplayScreenFromGBB_exit;
}
switch(image_info.format) {
case FORMAT_BMP:
if (i == 0) {
/**
* In current version GBB bitmaps, first image
* is always the background.
*/
ret = VbExDisplaySetDimension(
image_info.width,
image_info.height);
if (ret) {
VB2_DEBUG("VbExDisplaySetDimension"
"(%d,%d): failed (%#x).\n",
image_info.width,
image_info.height, ret);
}
}
retval = VbExDisplayImage(layout.images[i].x,
layout.images[i].y,
fullimage, inoutsize);
break;
case FORMAT_FONT:
/*
* The uncompressed blob is our font structure. Cache
* it as needed.
*/
font = VbInternalizeFontData(
(FontArrayHeader *)fullimage);
/* TODO: handle text in general here */
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);
VbDoneWithFontForNow(font);
break;
default:
VB2_DEBUG("VbDisplayScreenFromGBB(): "
"unsupported ImageFormat %d\n",
image_info.format);
retval = VBERROR_INVALID_GBB;
}
free(fullimage);
if (VBERROR_SUCCESS != retval)
goto VbDisplayScreenFromGBB_exit;
}
/* Successful if all bitmaps displayed */
retval = VBERROR_SUCCESS;
VbRegionCheckVersion(cparams);
VbDisplayScreenFromGBB_exit:
VB2_DEBUG("leaving VbDisplayScreenFromGBB() with %d\n",retval);
return retval;
}
/*
* This is the deprecated display screen function. This should be called only
* if bmpblk.bin is found in GBB. New devices store graphics data in cbfs
* and screens are rendered by Depthcharge (chromium:502066).
*/
static VbError_t VbDisplayScreenLegacy(struct vb2_context *ctx,
VbCommonParams *cparams, uint32_t screen,
int force, uint32_t locale)
{
VbError_t retval;
/* Initialize display if necessary */
if (!disp_width) {
retval = VbExDisplayInit(&disp_width, &disp_height);
if (VBERROR_SUCCESS != retval)
return retval;
}
/* If the screen is blank, turn off the backlight; else turn it on. */
VbExDisplayBacklight(VB_SCREEN_BLANK == screen ? 0 : 1);
/* Look in the GBB first */
if (VBERROR_SUCCESS == VbDisplayScreenFromGBB(ctx, cparams, screen,
locale))
return VBERROR_SUCCESS;
/* If screen wasn't in the GBB bitmaps, fall back to a default */
return VbExDisplayScreen(screen, locale);
}
VbError_t VbDisplayScreen(struct vb2_context *ctx,
VbCommonParams *cparams, uint32_t screen, int force)
VbError_t VbDisplayScreen(struct vb2_context *ctx, uint32_t screen, int force)
{
uint32_t locale;
GoogleBinaryBlockHeader *gbb = cparams->gbb;
VbError_t rv;
/* If requested screen is the same as the current one, we're done. */
@@ -362,10 +43,7 @@ VbError_t VbDisplayScreen(struct vb2_context *ctx,
/* Read the locale last saved */
locale = vb2_nv_get(ctx, VB2_NV_LOCALIZATION_INDEX);
if (gbb->bmpfv_size == 0)
rv = VbExDisplayScreen(screen, locale);
else
rv = VbDisplayScreenLegacy(ctx, cparams, screen, force, locale);
rv = VbExDisplayScreen(screen, locale);
if (rv == VBERROR_SUCCESS)
/* Keep track of the currently displayed screen */
@@ -374,8 +52,7 @@ VbError_t VbDisplayScreen(struct vb2_context *ctx,
return rv;
}
VbError_t VbDisplayMenu(struct vb2_context *ctx,
VbCommonParams *cparams, uint32_t screen, int force,
VbError_t VbDisplayMenu(struct vb2_context *ctx, uint32_t screen, int force,
uint32_t selected_index, uint32_t disabled_idx_mask)
{
uint32_t locale;
@@ -616,7 +293,7 @@ VbError_t VbDisplayDebugInfo(struct vb2_context *ctx, VbCommonParams *cparams)
* highlighted. On a non-detachable screen, this will be a
* no-op.
*/
VbDisplayMenu(ctx, cparams, disp_current_screen, 1,
VbDisplayMenu(ctx, disp_current_screen, 1,
disp_current_index, disp_disabled_idx_mask);
/* Add hardware ID */
@@ -758,7 +435,7 @@ VbError_t VbCheckDisplayKey(struct vb2_context *ctx, VbCommonParams *cparams,
uint32_t count = 0;
loc = vb2_nv_get(ctx, VB2_NV_LOCALIZATION_INDEX);
if (VBERROR_SUCCESS != VbGetLocalizationCount(cparams, &count))
if (VBERROR_SUCCESS != VbExGetLocalizationCount(&count))
loc = 0; /* No localization count (bad GBB?) */
else if (VB_KEY_RIGHT == key || VB_KEY_UP == key)
loc = (loc < count - 1 ? loc + 1 : 0);
@@ -783,13 +460,12 @@ VbError_t VbCheckDisplayKey(struct vb2_context *ctx, VbCommonParams *cparams,
#endif
/* Force redraw of current screen */
return VbDisplayScreen(ctx, cparams, disp_current_screen, 1);
return VbDisplayScreen(ctx, disp_current_screen, 1);
}
if (0 == memcmp(MagicBuffer, MAGIC_WORD, MAGIC_WORD_LEN)) {
if (VBEASTEREGG)
(void)VbDisplayScreen(ctx, cparams, disp_current_screen,
1);
(void)VbDisplayScreen(ctx, disp_current_screen, 1);
}
return VBERROR_SUCCESS;

View File

@@ -213,7 +213,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
/* If dev mode is disabled, only allow TONORM */
while (disable_dev_boot) {
VB2_DEBUG("dev_disable_boot is set\n");
VbDisplayScreen(ctx, cparams, VB_SCREEN_DEVELOPER_TO_NORM, 0);
VbDisplayScreen(ctx, VB_SCREEN_DEVELOPER_TO_NORM, 0);
VbExDisplayDebugInfo(dev_disable_msg);
/* Ignore space in VbUserConfirms()... */
@@ -221,9 +221,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
case 1:
VB2_DEBUG("leaving dev-mode\n");
vb2_nv_set(ctx, VB2_NV_DISABLE_DEV_REQUEST, 1);
VbDisplayScreen(ctx, cparams,
VB_SCREEN_TO_NORM_CONFIRMED,
0);
VbDisplayScreen(ctx, VB_SCREEN_TO_NORM_CONFIRMED, 0);
VbExSleepMs(5000);
return VBERROR_REBOOT_REQUIRED;
case -1:
@@ -236,7 +234,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
}
/* Show the dev mode warning screen */
VbDisplayScreen(ctx, cparams, VB_SCREEN_DEVELOPER_WARNING, 0);
VbDisplayScreen(ctx, VB_SCREEN_DEVELOPER_WARNING, 0);
/* Initialize audio/delay context */
vb2_audio_start(ctx);
@@ -278,9 +276,8 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
VbExBeep(120, 400);
break;
}
VbDisplayScreen(ctx, cparams,
VB_SCREEN_DEVELOPER_TO_NORM,
0);
VbDisplayScreen(ctx,
VB_SCREEN_DEVELOPER_TO_NORM, 0);
/* Ignore space in VbUserConfirms()... */
switch (VbUserConfirms(ctx, cparams, 0)) {
case 1:
@@ -288,9 +285,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
vb2_nv_set(ctx, VB2_NV_DISABLE_DEV_REQUEST,
1);
VbDisplayScreen(ctx,
cparams,
VB_SCREEN_TO_NORM_CONFIRMED,
0);
VB_SCREEN_TO_NORM_CONFIRMED, 0);
VbExSleepMs(5000);
return VBERROR_REBOOT_REQUIRED;
case -1:
@@ -300,9 +295,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
/* Stay in dev-mode */
VB2_DEBUG("stay in dev-mode\n");
VbDisplayScreen(ctx,
cparams,
VB_SCREEN_DEVELOPER_WARNING,
0);
VB_SCREEN_DEVELOPER_WARNING, 0);
/* Start new countdown */
vb2_audio_start(ctx);
}
@@ -355,17 +348,14 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
* Clear the screen to show we get the Ctrl+U
* key press.
*/
VbDisplayScreen(ctx, cparams, VB_SCREEN_BLANK,
0);
VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0);
if (VBERROR_SUCCESS ==
VbTryUsb(ctx, cparams)) {
return VBERROR_SUCCESS;
} else {
/* Show dev mode warning screen again */
VbDisplayScreen(ctx,
cparams,
VB_SCREEN_DEVELOPER_WARNING,
0);
VB_SCREEN_DEVELOPER_WARNING, 0);
}
}
break;
@@ -398,7 +388,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
VbError_t VbBootDeveloper(struct vb2_context *ctx, VbCommonParams *cparams)
{
VbError_t retval = vb2_developer_ui(ctx, cparams);
VbDisplayScreen(ctx, cparams, VB_SCREEN_BLANK, 0);
VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0);
return retval;
}
@@ -436,7 +426,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams)
*/
vb2_nv_commit(ctx);
VbDisplayScreen(ctx, cparams, VB_SCREEN_OS_BROKEN, 0);
VbDisplayScreen(ctx, VB_SCREEN_OS_BROKEN, 0);
VB2_DEBUG("VbBootRecovery() waiting for manual recovery\n");
while (1) {
key = VbExKeyboardRead();
@@ -465,7 +455,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams)
if (VBERROR_SUCCESS == retval)
break; /* Found a recovery kernel */
VbDisplayScreen(ctx, cparams, VBERROR_NO_DISK_FOUND == retval ?
VbDisplayScreen(ctx, VBERROR_NO_DISK_FOUND == retval ?
VB_SCREEN_RECOVERY_INSERT :
VB_SCREEN_RECOVERY_NO_GOOD,
0);
@@ -504,9 +494,8 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams)
}
/* Ask the user to confirm entering dev-mode */
VbDisplayScreen(ctx, cparams,
VB_SCREEN_RECOVERY_TO_DEV,
0);
VbDisplayScreen(ctx,
VB_SCREEN_RECOVERY_TO_DEV, 0);
/* SPACE means no... */
uint32_t vbc_flags =
VB_CONFIRM_SPACE_MEANS_NO |
@@ -550,6 +539,6 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams)
VbError_t VbBootRecovery(struct vb2_context *ctx, VbCommonParams *cparams)
{
VbError_t retval = recovery_ui(ctx, cparams);
VbDisplayScreen(ctx, cparams, VB_SCREEN_BLANK, 0);
VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0);
return retval;
}

View File

@@ -252,7 +252,7 @@ VbError_t vb2_draw_current_screen(struct vb2_context *ctx,
screen = VB_MENU_TO_SCREEN_MAP[current_menu];
else
return VBERROR_UNKNOWN;
return VbDisplayMenu(ctx, cparams, screen, 0,
return VbDisplayMenu(ctx, screen, 0,
current_menu_idx, disabled_idx_mask);
}
@@ -538,17 +538,16 @@ VbError_t vb2_set_disabled_idx_mask(uint32_t flags) {
* will not wrap, meaning that we block on the 0 or max index when
* we hit the ends of the menu.
*
* @param cparams common params
* @param key VOL_KEY_UP = increase index selection
* VOL_KEY_DOWN = decrease index selection.
* Every other key has no effect now.
*/
void vb2_update_selection(VbCommonParams *cparams, uint32_t key) {
void vb2_update_selection(uint32_t key) {
int idx;
uint32_t menu_size;
if (current_menu == VB_MENU_LANGUAGES) {
VbGetLocalizationCount(cparams, &menu_size);
VbExGetLocalizationCount(&menu_size);
} else {
vb2_get_current_menu_size(current_menu,
NULL, &menu_size);
@@ -706,8 +705,7 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams)
* Clear the screen to show we get the Ctrl+U
* key press.
*/
VbDisplayScreen(ctx, cparams, VB_SCREEN_BLANK,
0);
VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0);
if (VBERROR_SUCCESS ==
VbTryUsbMenu(ctx, cparams)) {
return VBERROR_SUCCESS;
@@ -719,14 +717,14 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams)
break;
case VB_BUTTON_VOL_UP_SHORT_PRESS:
case VB_KEY_UP:
vb2_update_selection(cparams, key);
vb2_update_selection(key);
vb2_draw_current_screen(ctx, cparams);
/* reset 30 second timer */
vb2_audio_start(ctx);
break;
case VB_BUTTON_VOL_DOWN_SHORT_PRESS:
case VB_KEY_DOWN:
vb2_update_selection(cparams, key);
vb2_update_selection(key);
vb2_draw_current_screen(ctx, cparams);
/* reset 30 second timer */
vb2_audio_start(ctx);
@@ -791,7 +789,7 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams)
* Ctrl+U key press.
*/
VbDisplayScreen(ctx,
cparams, VB_SCREEN_BLANK, 0);
VB_SCREEN_BLANK, 0);
if (VBERROR_SUCCESS ==
VbTryUsbMenu(ctx, cparams)) {
return VBERROR_SUCCESS;
@@ -842,9 +840,7 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams)
VB2_NV_DISABLE_DEV_REQUEST,
1);
VbDisplayScreen(ctx,
cparams,
VB_SCREEN_TO_NORM_CONFIRMED,
0);
VB_SCREEN_TO_NORM_CONFIRMED, 0);
current_menu = VB_MENU_TO_NORM_CONFIRMED;
VbExSleepMs(5000);
return VBERROR_REBOOT_REQUIRED;
@@ -883,7 +879,7 @@ fallout:
VbError_t VbBootDeveloperMenu(struct vb2_context *ctx, VbCommonParams *cparams)
{
VbError_t retval = vb2_developer_menu(ctx, cparams);
VbDisplayScreen(ctx, cparams, VB_SCREEN_BLANK, 0);
VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0);
return retval;
}
@@ -930,7 +926,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams)
*/
vb2_nv_commit(ctx);
VbDisplayScreen(ctx, cparams, VB_SCREEN_OS_BROKEN, 0);
VbDisplayScreen(ctx, VB_SCREEN_OS_BROKEN, 0);
current_menu = VB_MENU_RECOVERY_BROKEN;
VB2_DEBUG("waiting for manual recovery\n");
while (1) {
@@ -977,9 +973,8 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams)
if (retval == VBERROR_NO_DISK_FOUND)
vb2_draw_current_screen(ctx, cparams);
else {
VbDisplayScreen(ctx, cparams,
VB_SCREEN_RECOVERY_NO_GOOD,
0);
VbDisplayScreen(ctx,
VB_SCREEN_RECOVERY_NO_GOOD, 0);
current_menu = VB_MENU_RECOVERY_NO_GOOD;
}
}
@@ -1010,7 +1005,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams)
break;
}
vb2_update_selection(cparams, key);
vb2_update_selection(key);
vb2_draw_current_screen(ctx, cparams);
break;
case VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS:
@@ -1065,9 +1060,8 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams)
vb2_draw_current_screen(ctx,
cparams);
else {
VbDisplayScreen(ctx, cparams,
VB_SCREEN_RECOVERY_NO_GOOD,
0);
VbDisplayScreen(ctx,
VB_SCREEN_RECOVERY_NO_GOOD, 0);
current_menu = VB_MENU_RECOVERY_NO_GOOD;
}
}
@@ -1140,6 +1134,6 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams)
VbError_t VbBootRecoveryMenu(struct vb2_context *ctx, VbCommonParams *cparams)
{
VbError_t retval = recovery_ui(ctx, cparams);
VbDisplayScreen(ctx, cparams, VB_SCREEN_BLANK, 0);
VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0);
return retval;
}

View File

@@ -211,8 +211,7 @@ VbError_t VbExEcUpdateImage(int devidx, enum VbSelectFirmware_t select,
return update_retval;
}
VbError_t VbDisplayScreen(struct vb2_context *ctx, VbCommonParams *cparams,
uint32_t screen, int force)
VbError_t VbDisplayScreen(struct vb2_context *ctx, uint32_t screen, int force)
{
if (screens_count < ARRAY_SIZE(screens_displayed))
screens_displayed[screens_count++] = screen;

View File

@@ -190,8 +190,7 @@ uint32_t VbTryLoadKernel(struct vb2_context *ctx, VbCommonParams *cparams,
return vbtlk_retval + get_info_flags;
}
VbError_t VbDisplayScreen(struct vb2_context *ctx, VbCommonParams *cparams,
uint32_t screen, int force)
VbError_t VbDisplayScreen(struct vb2_context *ctx, uint32_t screen, int force)
{
if (screens_count < ARRAY_SIZE(screens_displayed))
screens_displayed[screens_count++] = screen;

View File

@@ -196,8 +196,7 @@ uint32_t VbTryLoadKernel(struct vb2_context *ctx, VbCommonParams *cparams,
return vbtlk_retval + get_info_flags;
}
VbError_t VbDisplayScreen(struct vb2_context *ctx, VbCommonParams *cparams,
uint32_t screen, int force)
VbError_t VbDisplayScreen(struct vb2_context *ctx, uint32_t screen, int force)
{
if (screens_count < ARRAY_SIZE(screens_displayed))
screens_displayed[screens_count++] = screen;
@@ -206,8 +205,7 @@ VbError_t VbDisplayScreen(struct vb2_context *ctx, VbCommonParams *cparams,
return VBERROR_SUCCESS;
}
VbError_t VbDisplayMenu(struct vb2_context *ctx,
VbCommonParams *cparams, uint32_t screen, int force,
VbError_t VbDisplayMenu(struct vb2_context *ctx, uint32_t screen, int force,
uint32_t selected_index, uint32_t disabled_idx_mask)
{
if (screens_count < ARRAY_SIZE(screens_displayed))

View File

@@ -29,10 +29,10 @@ static uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE];
static VbSharedDataHeader *shared = (VbSharedDataHeader *)shared_data;
static char gbb_data[4096 + sizeof(GoogleBinaryBlockHeader)];
static GoogleBinaryBlockHeader *gbb = (GoogleBinaryBlockHeader *)gbb_data;
static BmpBlockHeader *bhdr;
static char debug_info[4096];
static struct vb2_context ctx;
static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE];
static uint32_t mock_localization_count;
/* Reset mock data (for use before each test) */
static void ResetMocks(void)
@@ -50,14 +50,7 @@ static void ResetMocks(void)
gbb->hwid_size = strlen(gbb_data + gbb->hwid_offset) + 1;
gbb_used = (gbb_used + gbb->hwid_size + 7) & ~7;
gbb->bmpfv_offset = gbb_used;
bhdr = (BmpBlockHeader *)(gbb_data + gbb->bmpfv_offset);
gbb->bmpfv_size = sizeof(BmpBlockHeader);
gbb_used = (gbb_used + gbb->bmpfv_size + 7) & ~7;
memcpy(bhdr->signature, BMPBLOCK_SIGNATURE, BMPBLOCK_SIGNATURE_SIZE);
bhdr->major_version = BMPBLOCK_MAJOR_VERSION;
bhdr->minor_version = BMPBLOCK_MINOR_VERSION;
bhdr->number_of_localizations = 3;
mock_localization_count = 3;
memset(&cparams, 0, sizeof(cparams));
cparams.shared_data_size = sizeof(shared_data);
@@ -93,6 +86,15 @@ static void ResetMocks(void)
/* Mocks */
VbError_t VbExGetLocalizationCount(uint32_t *count) {
if (mock_localization_count == 0xffffffff)
return VBERROR_UNKNOWN;
*count = mock_localization_count;
return VBERROR_SUCCESS;
}
VbError_t VbExDisplayDebugInfo(const char *info_str)
{
strncpy(debug_info, info_str, sizeof(debug_info));
@@ -147,31 +149,6 @@ static void DebugInfoTest(void)
VbApiKernelFree(&cparams);
}
/* Test localization */
static void LocalizationTest(void)
{
uint32_t count = 6;
ResetMocks();
cparams.gbb->bmpfv_size = 0;
TEST_EQ(VbGetLocalizationCount(&cparams, &count),
VBERROR_UNKNOWN, "VbGetLocalizationCount bad gbb");
TEST_EQ(count, 0, " count");
VbApiKernelFree(&cparams);
ResetMocks();
bhdr->signature[0] ^= 0x5a;
TEST_EQ(VbGetLocalizationCount(&cparams, &count),
VBERROR_UNKNOWN, "VbGetLocalizationCount bad bmpfv");
VbApiKernelFree(&cparams);
ResetMocks();
TEST_EQ(VbGetLocalizationCount(&cparams, &count), 0,
"VbGetLocalizationCount()");
TEST_EQ(count, 3, " count");
VbApiKernelFree(&cparams);
}
/* Test display key checking */
static void DisplayKeyTest(void)
{
@@ -208,66 +185,17 @@ static void DisplayKeyTest(void)
/* Reset localization if localization count is invalid */
ResetMocks();
vb2_nv_set(&ctx, VB2_NV_LOCALIZATION_INDEX, 1);
bhdr->signature[0] ^= 0x5a;
mock_localization_count = 0xffffffff;
VbCheckDisplayKey(&ctx, &cparams, VB_KEY_UP);
TEST_EQ(vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX), 0,
"DisplayKey invalid");
VbApiKernelFree(&cparams);
}
static void FontTest(void)
{
FontArrayHeader h;
FontArrayEntryHeader eh[3] = {
{
.ascii = 'A',
.info.original_size = 10,
},
{
.ascii = 'B',
.info.original_size = 20,
},
{
.ascii = 'C',
.info.original_size = 30,
},
};
FontArrayEntryHeader *eptr;
uint8_t buf[sizeof(h) + sizeof(eh)];
VbFont_t *fptr;
void *bufferptr;
uint32_t buffersize;
/* Create font data */
h.num_entries = ARRAY_SIZE(eh);
memcpy(buf, &h, sizeof(h));
eptr = (FontArrayEntryHeader *)(buf + sizeof(h));
memcpy(eptr, eh, sizeof(eh));
fptr = VbInternalizeFontData((FontArrayHeader *)buf);
TEST_PTR_EQ(fptr, buf, "Internalize");
TEST_PTR_EQ(VbFindFontGlyph(fptr, 'B', &bufferptr, &buffersize),
&eptr[1].info, "Glyph found");
TEST_EQ(buffersize, eptr[1].info.original_size, " size");
TEST_PTR_EQ(VbFindFontGlyph(fptr, 'X', &bufferptr, &buffersize),
&eptr[0].info, "Glyph not found");
TEST_EQ(buffersize, eptr[0].info.original_size, " size");
/* Test invalid rendering params */
VbRenderTextAtPos(NULL, 0, 0, 0, fptr);
VbRenderTextAtPos("ABC", 0, 0, 0, NULL);
VbDoneWithFontForNow(fptr);
}
int main(void)
{
DebugInfoTest();
LocalizationTest();
DisplayKeyTest();
FontTest();
return gTestSuccess ? 0 : 255;
}