summaryrefslogtreecommitdiff
path: root/lib/vbexport/display.c
blob: 107136294fc0c0ea23d412f3d90092bb5921c27d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
 * Copyright (c) 2011 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.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 */

#include <common.h>
#include <fdt_decode.h>
#include <lcd.h>
#include <chromeos/common.h>
#include <lzma/LzmaTypes.h>
#include <lzma/LzmaDec.h>
#include <lzma/LzmaTools.h>

/* Import the header files from vboot_reference */
#include <vboot_api.h>

#define PRINT_MAX_ROW	20
#define PRINT_MAX_COL	80

DECLARE_GLOBAL_DATA_PTR;

/* Defined in common/lcd.c */
extern int lcd_display_bitmap (ulong, int, int);

VbError_t VbExDisplayInit(uint32_t *width, uint32_t *height)
{
	struct fdt_lcd config;

	/* Get LCD details from FDT */
	if (fdt_decode_lcd(gd->blob, &config)) {
		VBDEBUG("No LCD information in device tree.\n");
		return 1;
	}

	*width = config.width;
	*height = config.height;

	return VBERROR_SUCCESS;
}

VbError_t VbExDisplayBacklight(uint8_t enable)
{
	/* TODO(waihong@chromium.org) Implement it later */
	return VBERROR_SUCCESS;
}

/* Print the message on the center of LCD. */
static void print_on_center(const char *message)
{
	char result[PRINT_MAX_ROW * (PRINT_MAX_COL + 1) + 1] = "\0";
	int i, j, left_space, right_space;

	for (i = 0; i < PRINT_MAX_ROW / 2 - 1; i++) {
		for (j = 0; j < PRINT_MAX_COL; j++)
			strcat(result, ".");
		strcat(result, "\n");
	}

	left_space = (PRINT_MAX_COL - strlen(message)) / 2;
	for (i = 0; i < left_space; i++)
		strcat(result, ".");
	strcat(result, message);

	right_space = PRINT_MAX_COL - strlen(message) - left_space;
	for (i = 0; i < right_space; i++)
		strcat(result, ".");
	strcat(result, "\n");

	for (i = 0; i < PRINT_MAX_ROW - PRINT_MAX_ROW / 2; i++) {
		for (j = 0; j < PRINT_MAX_COL; j++)
			strcat(result, ".");
		strcat(result, "\n");
	}

	VbExDisplayDebugInfo(result);
}

VbError_t VbExDisplayScreen(uint32_t screen_type)
{
	/*
	 * Show the debug messages for development. It is a backup method
	 * when GBB does not contain a full set of bitmaps.
	 */
	switch (screen_type) {
		case VB_SCREEN_BLANK:
			print_on_center("");
			break;
		case VB_SCREEN_DEVELOPER_WARNING:
			print_on_center("developer mode warning");
			break;
		case VB_SCREEN_DEVELOPER_EGG:
			print_on_center("easter egg");
			break;
		case VB_SCREEN_RECOVERY_REMOVE:
			print_on_center("remove inserted devices");
			break;
		case VB_SCREEN_RECOVERY_INSERT:
			print_on_center("insert recovery image");
			break;
		case VB_SCREEN_RECOVERY_NO_GOOD:
			print_on_center("insert image invalid");
			break;
		default:
			VBDEBUG("Not a valid screen type: %08x.\n",
					screen_type);
			return 1;
	}
	return VBERROR_SUCCESS;
}

static uint8_t *uncompress_lzma(uint8_t *in_addr, SizeT in_size,
                                SizeT out_size)
{
	uint8_t *out_addr = VbExMalloc(out_size);
	SizeT lzma_len = out_size;
	int ret;

	ret = lzmaBuffToBuffDecompress(out_addr, &lzma_len, in_addr, in_size);
	if (ret != SZ_OK) {
		VbExFree(out_addr);
		out_addr = NULL;
	}
	return out_addr;
}

VbError_t VbExDisplayImage(uint32_t x, uint32_t y, const ImageInfo *info,
                           const void *buffer)
{
	int ret;
	uint8_t *raw_data;

	switch (info->compression) {
	case COMPRESS_NONE:
		raw_data = (uint8_t *)buffer;
		break;

	case COMPRESS_LZMA1:
		raw_data = uncompress_lzma((uint8_t *)buffer,
				(SizeT)info->compressed_size,
				(SizeT)info->original_size);
		if (!raw_data) {
			VBDEBUG("LZMA decompress failed.\n");
			return 1;
		}
		break;

	default:
		VBDEBUG("Unsupported compression format: %08x\n",
				info->compression);
		return 1;
	}

	ret = lcd_display_bitmap((ulong)raw_data, x, y);

	if (info->compression == COMPRESS_LZMA1)
		VbExFree(raw_data);

	if (ret) {
		VBDEBUG("LCD display error.\n");
		return 1;
	}

	return VBERROR_SUCCESS;
}

VbError_t VbExDisplayDebugInfo(const char *info_str)
{
	/* Show the debug message on the upper left corner */
	console_col = 0;
	console_row = 0;
	lcd_puts(info_str);

	return VBERROR_SUCCESS;
}