blob: 30d70d6c1d5b595c18c609a34ae35cbc4ee69313 [file] [log] [blame]
Amit Blay6281ebc2015-01-11 14:44:08 +02001/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <debug.h>
30#include <dev/fbcon.h>
31#include <target.h>
32#include <mmc.h>
33#include <partition_parser.h>
34#include <stdlib.h>
35#include "mdtp.h"
36
37#define MDTP_IMAGE_WIDTH 500
38#define MDTP_IMAGE_HEIGHT 800
39#define MDTP_UX_DELAY 1000
40#define MDTP_OK_OFFSET 0x0
41#define MDTP_CHECKING_OFFSET 0x200000
42#define MDTP_INVALID_OFFSET 0x400000
43#define MDTP_RECOVERED_OFFSET 0x600000
44
45extern uint32_t target_volume_down(void);
46extern void fbcon_putImage(struct fbimage *fbimg, bool flag);
47extern void mdelay(unsigned msecs);
48
Amit Blay6281ebc2015-01-11 14:44:08 +020049static struct fbimage mdtp_header;/* = {0};*/
50
51/********************************************************************************/
52
53/* Load the "Firmware Valid" image from EMMC */
54static struct fbimage* mdtp_images_mmc_OK()
55{
56 int index = INVALID_PTN;
57 unsigned long long ptn = 0;
58 struct fbcon_config *fb_display = NULL;
59 struct fbimage *logo = &mdtp_header;
Amit Blaydf42d2f2015-02-03 16:37:09 +020060 uint32_t block_size = mmc_get_device_blocksize();
Amit Blay6281ebc2015-01-11 14:44:08 +020061
62 index = partition_get_index("mdtp");
63 if (index == 0) {
64 dprintf(CRITICAL, "ERROR: mdtp Partition table not found\n");
65 return NULL;
66 }
67
68 ptn = partition_get_offset(index);
69 if (ptn == 0) {
70 dprintf(CRITICAL, "ERROR: mdtp Partition invalid\n");
71 return NULL;
72 }
73
74 fb_display = fbcon_display();
75 if (fb_display)
76 {
77 uint8_t *base = (uint8_t *) fb_display->base;
78 base += LOGO_IMG_OFFSET;
79
80 if (mmc_read(ptn, (void*)base, ROUNDUP(MDTP_IMAGE_WIDTH*MDTP_IMAGE_HEIGHT*3, block_size))) {
81 fbcon_clear();
82 dprintf(CRITICAL, "ERROR: mdtp image read failed\n");
83 return NULL;
84 }
85 logo->image = base;
86 }
87
88 return logo;
89}
90
91/* Load the "Firmware Invalid" image from EMMC */
92static struct fbimage* mdtp_images_mmc_INVALID()
93{
94 int index = INVALID_PTN;
95 unsigned long long ptn = 0;
96 struct fbcon_config *fb_display = NULL;
97 struct fbimage *logo = &mdtp_header;
Amit Blaydf42d2f2015-02-03 16:37:09 +020098 uint32_t block_size = mmc_get_device_blocksize();
Amit Blay6281ebc2015-01-11 14:44:08 +020099
100 index = partition_get_index("mdtp");
101 if (index == 0) {
102 dprintf(CRITICAL, "ERROR: mdtp Partition table not found\n");
103 return NULL;
104 }
105
106 ptn = partition_get_offset(index);
107 if (ptn == 0) {
108 dprintf(CRITICAL, "ERROR: mdtp Partition invalid\n");
109 return NULL;
110 }
111
112 fb_display = fbcon_display();
113 if (fb_display)
114 {
115 uint8_t *base = (uint8_t *) fb_display->base;
116 base += LOGO_IMG_OFFSET;
117
118 if (mmc_read(ptn+MDTP_INVALID_OFFSET, (void*)base, ROUNDUP(MDTP_IMAGE_WIDTH*MDTP_IMAGE_HEIGHT*3, block_size))) {
119 fbcon_clear();
120 dprintf(CRITICAL, "ERROR: mdtp image read failed\n");
121 return NULL;
122 }
123 logo->image = base;
124 }
125
126 return logo;
127}
128
129/* Load the "Verifying Firmware" image from EMMC */
130static struct fbimage* mdtp_images_mmc_CHECKING()
131{
132 int index = INVALID_PTN;
133 unsigned long long ptn = 0;
134 struct fbcon_config *fb_display = NULL;
135 struct fbimage *logo = &mdtp_header;
Amit Blaydf42d2f2015-02-03 16:37:09 +0200136 uint32_t block_size = mmc_get_device_blocksize();
Amit Blay6281ebc2015-01-11 14:44:08 +0200137
138 index = partition_get_index("mdtp");
139 if (index == 0) {
140 dprintf(CRITICAL, "ERROR: mdtp Partition table not found\n");
141 return NULL;
142 }
143
144 ptn = partition_get_offset(index);
145 if (ptn == 0) {
146 dprintf(CRITICAL, "ERROR: mdtp Partition invalid\n");
147 return NULL;
148 }
149
150 fb_display = fbcon_display();
151 if (fb_display)
152 {
153 uint8_t *base = (uint8_t *) fb_display->base;
154 base += LOGO_IMG_OFFSET;
155
156 if (mmc_read(ptn+MDTP_CHECKING_OFFSET, (void*)base, ROUNDUP(MDTP_IMAGE_WIDTH*MDTP_IMAGE_HEIGHT*3, block_size))) {
157 fbcon_clear();
158 dprintf(CRITICAL, "ERROR: mdtp image read failed\n");
159 return NULL;
160 }
161 logo->image = base;
162 }
163
164 return logo;
165}
166
167/* Load the "Verifying Firmware" image from EMMC */
168static struct fbimage* mdtp_images_mmc_RECOVERED()
169{
170 int index = INVALID_PTN;
171 unsigned long long ptn = 0;
172 struct fbcon_config *fb_display = NULL;
173 struct fbimage *logo = &mdtp_header;
Amit Blaydf42d2f2015-02-03 16:37:09 +0200174 uint32_t block_size = mmc_get_device_blocksize();
Amit Blay6281ebc2015-01-11 14:44:08 +0200175
176 index = partition_get_index("mdtp");
177 if (index == 0) {
178 dprintf(CRITICAL, "ERROR: mdtp Partition table not found\n");
179 return NULL;
180 }
181
182 ptn = partition_get_offset(index);
183 if (ptn == 0) {
184 dprintf(CRITICAL, "ERROR: mdtp Partition invalid\n");
185 return NULL;
186 }
187
188 fb_display = fbcon_display();
189 if (fb_display)
190 {
191 uint8_t *base = (uint8_t *) fb_display->base;
192 base += LOGO_IMG_OFFSET;
193
194 if (mmc_read(ptn+MDTP_RECOVERED_OFFSET, (void*)base, ROUNDUP(MDTP_IMAGE_WIDTH*MDTP_IMAGE_HEIGHT*3, block_size))) {
195 fbcon_clear();
196 dprintf(CRITICAL, "ERROR: mdtp image read failed\n");
197 return NULL;
198 }
199 logo->image = base;
200 }
201
202 return logo;
203}
204
205/* Show the "Firmware Valid" image */
206static void display_image_on_screen_OK()
207{
208 struct fbimage *fbimg;
209
210 fbcon_clear();
211 fbimg = mdtp_images_mmc_OK();
212 fbimg->header.width = MDTP_IMAGE_WIDTH;
213 fbimg->header.height = MDTP_IMAGE_HEIGHT;
214
215 dprintf(CRITICAL, "display_image_on_screen_OK\n");
216 fbcon_putImage(fbimg, true);
217}
218
219/* Show the "Firmware Invalid" image */
220static void display_image_on_screen_INVALID()
221{
222 struct fbimage *fbimg;
223
224 fbcon_clear();
225 fbimg = mdtp_images_mmc_INVALID();
226 fbimg->header.width = MDTP_IMAGE_WIDTH;
227 fbimg->header.height = MDTP_IMAGE_HEIGHT;
228
229 dprintf(CRITICAL, "display_image_on_screen_INVALID\n");
230 fbcon_putImage(fbimg, true);
231}
232
233/* Show the "Verifying Firmware" image */
234static void display_image_on_screen_CHECKING()
235{
236 struct fbimage *fbimg;
237
238 fbcon_clear();
239 fbimg = mdtp_images_mmc_CHECKING();
240 fbimg->header.width = MDTP_IMAGE_WIDTH;
241 fbimg->header.height = MDTP_IMAGE_HEIGHT;
242
243 dprintf(CRITICAL, "display_image_on_screen_CHECKING\n");
244 fbcon_putImage(fbimg, true);
245}
246
247/* Show the "Verifying Firmware" image */
248static void display_image_on_screen_RECOVERED()
249{
250 struct fbimage *fbimg;
251
252 fbcon_clear();
253 fbimg = mdtp_images_mmc_RECOVERED();
254 fbimg->header.width = MDTP_IMAGE_WIDTH;
255 fbimg->header.height = MDTP_IMAGE_HEIGHT;
256
257 dprintf(CRITICAL, "display_image_on_screen_RECOVERED\n");
258 fbcon_putImage(fbimg, true);
259}
260
261/* Display the "Firmware Valid" screen */
262void show_OK_msg()
263{
264 display_image_on_screen_OK();
265 mdelay(MDTP_UX_DELAY);
266
267 return;
268}
269
270/* Display the "Firmware Invalid" screen */
271void show_invalid_msg()
272{
273 display_image_on_screen_INVALID();
274
275 while (1)
276 {
277 if(target_volume_down())
278 {
279 display_image_on_screen_RECOVERED();
280 mdelay(MDTP_UX_DELAY);
281 break;
282 }
283 }
284
285 return;
286}
287
288/* Display the "Verifying Firmware" screen */
289void show_checking_msg()
290{
291 display_image_on_screen_CHECKING();
292 return;
293}
294
295/* Display the "Verifying Firmware" screen */
296void show_recovered_msg()
297{
298 display_image_on_screen_RECOVERED();
299 return;
300}
301