VbError_t VbDisplayScreen(VbCommonParams *cparams, uint32_t screen,
			  int force, VbNvContext *vncptr)
{
	VbError_t retval;

	/* Initialize display if necessary */
	if (!disp_width) {
		retval = VbExDisplayInit(&disp_width, &disp_height);
		if (VBERROR_SUCCESS != retval)
			return retval;
	}

	/* If requested screen is the same as the current one, we're done. */
	if (disp_current_screen == screen && 0 == force)
		return VBERROR_SUCCESS;

	/* If the screen is blank, turn off the backlight; else turn it on. */
	VbExDisplayBacklight(VB_SCREEN_BLANK == screen ? 0 : 1);

	/* Request the screen */
	disp_current_screen = screen;

	/* Look in the GBB first */
	if (VBERROR_SUCCESS == VbDisplayScreenFromGBB(cparams, screen,
						      vncptr))
		return VBERROR_SUCCESS;

	/* If screen wasn't in the GBB bitmaps, fall back to a default */
	return VbExDisplayScreen(screen);
}
static int do_vbexport_test_display(cmd_tbl_t *cmdtp, int flag,
		int argc, char * const argv[])
{
	int ret = 0;
	uint32_t width, height;
	GoogleBinaryBlockHeader *gbbh;
	BmpBlockHeader *bmph;
	int screen = -1;
	int local = 0;

	if (argc > 1) {
		screen = simple_strtoul(argv[1], NULL, 10);
		if (argc > 2)
			local = simple_strtoul(argv[2], NULL, 10);
	}

	if (VbExDisplayInit(&width, &height)) {
		VbExDebug("Failed to init display.\n");
		return 1;
	}

	VbExDebug("The screen dimensions is %ldx%ld.\n", width, height);

	VbExDebug("Showing screens for localisation %d...\n", local);
	mdelay(500);
	if (screen == -1) {
		ret |= show_screen_and_delay(VB_SCREEN_BLANK);
		ret |= show_screen_and_delay(VB_SCREEN_DEVELOPER_WARNING);
		ret |= show_screen_and_delay(VB_SCREEN_DEVELOPER_EGG);
		ret |= show_screen_and_delay(VB_SCREEN_RECOVERY_REMOVE);
		ret |= show_screen_and_delay(VB_SCREEN_RECOVERY_INSERT);
		ret |= show_screen_and_delay(VB_SCREEN_RECOVERY_NO_GOOD);
		ret |= show_screen_and_delay(VB_SCREEN_WAIT);
	}

	gbbh = (GoogleBinaryBlockHeader *)read_gbb_from_firmware();
	if (gbbh) {
		bmph = (BmpBlockHeader *)((uint8_t *)gbbh + gbbh->bmpfv_offset);

		VbExDebug("Showing images...\n");
		if (screen != -1) {
			ret |= show_images_and_delay(bmph, local, screen);
		} else {
			for (screen = 0; screen < MAX_VALID_SCREEN_INDEX;
					screen++)
				ret |= show_images_and_delay(bmph, local,
							     screen);
		}
	} else {
		ret = 1;
	}

	VbExDebug("Showing debug info...\n");
	ret |= VbExDisplayDebugInfo("Hello!\n"
			"This is a debug message.\n"
			"Bye Bye!\n");

	return ret;
}
static int do_vbexport_test_image(cmd_tbl_t *cmdtp, int flag,
		int argc, char * const argv[])
{
	uint32_t width, height;
	GoogleBinaryBlockHeader *gbbh;
	BmpBlockHeader *bmph;
	ScreenLayout *screens;
	int snum, locale = 0;

	if (argc > 1)
		locale = simple_strtoul(argv[1], NULL, 10);

	if (VbExDisplayInit(&width, &height)) {
		VbExDebug("Failed to init display.\n");
		return 1;
	}

	gbbh = (GoogleBinaryBlockHeader *)read_gbb_from_firmware();
	if (!gbbh) {
		VbExDebug("Cannot read GBB\n");
		return 1;
	}

	bmph = (BmpBlockHeader *)((uint8_t *)gbbh + gbbh->bmpfv_offset);
	screens = (ScreenLayout *)(bmph + 1);

	VbExDebug("Total screen layouts: %d\n", bmph->number_of_screenlayouts);
	VbExDebug("Total localizations: %d\n", bmph->number_of_localizations);
	VbExDebug("Total images: %d\n", bmph->number_of_imageinfos);
	VbExDebug("bmpfv_offset=%#x, size=%#x\n", gbbh->bmpfv_offset,
		  gbbh->bmpfv_size);

	if (locale >= bmph->number_of_localizations) {
		VbExDebug("Selected localization is out of range\n");
		return 1;
	}

	/* Select the correct block */
	screens += locale * bmph->number_of_screenlayouts;

	for (snum = 0; snum < bmph->number_of_screenlayouts; snum++) {
		ScreenLayout *screen = &screens[snum];
		ImageInfo *image;
		int inum;

		VbExDebug("Screen: %d\n", snum);
		for (inum = 0; inum < MAX_IMAGE_IN_LAYOUT; inum++) {
			if (!screen->images[inum].image_info_offset)
				break;
			image = (ImageInfo *)((uint8_t *)bmph +
				screen->images[inum].image_info_offset);
			VbExDebug("   Image: %d at %d, %d: offset=%#x, "
				"size=%#x, end=%#x\n", inum,
				  screen->images[inum].x,
				  screen->images[inum].y,
				  gbbh->bmpfv_offset +
					screen->images[inum].image_info_offset,
				  image->compressed_size,
				  gbbh->bmpfv_offset +
				  screen->images[inum].image_info_offset +
					image->compressed_size);
			show_image(image, screen->images[inum].x,
				   screen->images[inum].y);
		}
		mdelay(500);
	}

	return 0;
}