blob: cea49375ffa293a6d6475663d6b73803ae5e2c4c [file] [log] [blame]
lijuang9a7d3b92015-11-30 14:41:24 +08001/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
lijuang7d235f42015-07-16 20:19:45 +08002*
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 <reg.h>
31#include <stdlib.h>
32#include <openssl/evp.h>
33#include <dev/fbcon.h>
34#include <kernel/thread.h>
35#include <display_menu.h>
36#include <menu_keys_detect.h>
37#include <boot_verifier.h>
38#include <string.h>
39#include <platform.h>
lijuang4ece1e72015-08-14 21:02:36 +080040#include <smem.h>
41#include <target.h>
42#include <sys/types.h>
43#include <../../../app/aboot/devinfo.h>
lijuang7d235f42015-07-16 20:19:45 +080044
lijuang4ece1e72015-08-14 21:02:36 +080045static const char *unlock_menu_common_msg = "If you unlock the bootloader, "\
lijuang7d235f42015-07-16 20:19:45 +080046 "you will be able to install "\
47 "custom operating system on this phone.\n\n"\
48 "A custom OS is not subject to the same testing "\
49 "as the original OS, "\
50 "and can cause your phone and installed "\
51 "applications to stop working properly.\n\n"\
52 "To prevent unauthorized access to your personal data, "\
53 "unlocking the bootloader will also delete all personal "\
lijuang57d48b82016-01-20 17:23:50 +080054 "data from your phone(a \"factory data reset\").\n\n"\
lijuang7d235f42015-07-16 20:19:45 +080055 "Press the Volume Up/Down buttons to select Yes "\
56 "or No. Then press the Power button to continue.\n";
57
lijuang57d48b82016-01-20 17:23:50 +080058#define YELLOW_WARNING_MSG "Your device has loaded a different operating "\
lijuang4ece1e72015-08-14 21:02:36 +080059 "system\n\nTo learn more, visit:\n"
lijuang7d235f42015-07-16 20:19:45 +080060
lijuang57d48b82016-01-20 17:23:50 +080061#define ORANGE_WARNING_MSG "Your device has been unlocked and can't "\
lijuang4ece1e72015-08-14 21:02:36 +080062 "be trusted\n\nTo learn more, visit:\n"
lijuang7d235f42015-07-16 20:19:45 +080063
lijuang4ece1e72015-08-14 21:02:36 +080064#define RED_WARNING_MSG "Your device has failed verification and may "\
65 "not work properly\n\nTo learn more, visit:\n"
lijuang7d235f42015-07-16 20:19:45 +080066
lijuangbdd9bb42016-03-01 18:22:17 +080067#define LOGGING_WARNING_MSG "The dm-verity is not started in enforcing mode and may "\
68 "not work properly\n\nTo learn more, visit:\n"
69
lijuang7d235f42015-07-16 20:19:45 +080070static bool is_thread_start = false;
lijuang9a7d3b92015-11-30 14:41:24 +080071static struct select_msg_info msg_info;
lijuang7d235f42015-07-16 20:19:45 +080072
lijuang4ece1e72015-08-14 21:02:36 +080073#if VERIFIED_BOOT
74struct boot_verify_info {
75 int msg_type;
76 const char *warning_msg;
77};
78
79struct boot_verify_info boot_verify_info[] = {
80 [DISPLAY_MENU_RED] = {FBCON_RED_MSG, RED_WARNING_MSG},
81 [DISPLAY_MENU_YELLOW] = {FBCON_YELLOW_MSG, YELLOW_WARNING_MSG},
lijuangbdd9bb42016-03-01 18:22:17 +080082 [DISPLAY_MENU_ORANGE] = {FBCON_ORANGE_MSG, ORANGE_WARNING_MSG},
83 [DISPLAY_MENU_LOGGING] = {FBCON_RED_MSG, LOGGING_WARNING_MSG}};
lijuang4ece1e72015-08-14 21:02:36 +080084#endif
85
86static char *verify_option_menu[] = {
lijuang7d235f42015-07-16 20:19:45 +080087 [POWEROFF] = "Power off\n",
88 [RESTART] = "Restart\n",
89 [RECOVER] = "Recovery\n",
90 [FASTBOOT] = "Fastboot\n",
91 [BACK] = "Back to previous page\n"};
92
lijuang4ece1e72015-08-14 21:02:36 +080093static char *fastboot_option_menu[] = {
94 [0] = "START\n",
95 [1] = "Restart bootloader\n",
96 [2] = "Recovery mode\n",
lijuang42aefaa2016-04-14 15:55:17 +080097 [3] = "Power off\n",
98 [4] = "Boot to FFBM\n"};
lijuang4ece1e72015-08-14 21:02:36 +080099
lijuang7d235f42015-07-16 20:19:45 +0800100static int big_factor = 2;
101static int common_factor = 1;
102
lijuangde34d502016-02-26 16:04:50 +0800103static void wait_for_exit()
lijuang7d235f42015-07-16 20:19:45 +0800104{
105 struct select_msg_info *select_msg;
106 select_msg = &msg_info;
107
lijuang9a7d3b92015-11-30 14:41:24 +0800108 mutex_acquire(&select_msg->msg_lock);
lijuangde34d502016-02-26 16:04:50 +0800109 while(!select_msg->info.rel_exit == true) {
lijuang9a7d3b92015-11-30 14:41:24 +0800110 mutex_release(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800111 thread_sleep(10);
lijuang9a7d3b92015-11-30 14:41:24 +0800112 mutex_acquire(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800113 }
lijuang9a7d3b92015-11-30 14:41:24 +0800114 mutex_release(&select_msg->msg_lock);
115
lijuangde34d502016-02-26 16:04:50 +0800116 is_thread_start = false;
lijuang7d235f42015-07-16 20:19:45 +0800117 fbcon_clear();
118 display_image_on_screen();
119}
120
lijuangde34d502016-02-26 16:04:50 +0800121void wait_for_users_action()
122{
123 /* Waiting for exit menu keys detection if there is no any usr action
124 * otherwise it will do the action base on the keys detection thread
125 */
126 wait_for_exit();
127}
128
129void exit_menu_keys_detection()
130{
131 struct select_msg_info *select_msg;
132 select_msg = &msg_info;
133
134 mutex_acquire(&select_msg->msg_lock);
135 select_msg->info.is_exit = true;
136 mutex_release(&select_msg->msg_lock);
137
138 wait_for_exit();
139}
140
lijuang7d235f42015-07-16 20:19:45 +0800141static void set_message_factor()
142{
143 uint32_t tmp_factor = 0;
144 uint32_t max_x_count = 40;
145 uint32_t max_x = fbcon_get_max_x();
146
147 max_x = fbcon_get_max_x();
148 tmp_factor = max_x/max_x_count;
149
150 if(tmp_factor <= 1) {
151 big_factor = 2;
152 common_factor = 1;
153 } else {
154 big_factor = tmp_factor*2;
155 common_factor = tmp_factor;
156 }
157}
158
159static void display_fbcon_menu_message(char *str, unsigned type,
160 unsigned scale_factor)
161{
162 while(*str != 0) {
163 fbcon_putc_factor(*str++, type, scale_factor);
164 }
165}
166
167static char *str_align_right(char *str, int factor)
168{
169 uint32_t max_x = 0;
170 int diff = 0;
171 int i = 0;
172 char *str_target = NULL;
173
174 max_x = fbcon_get_max_x();
175 if (!str_target && max_x) {
176 str_target = malloc(max_x);
177 }
178
179 if (str_target) {
180 memset(str_target, 0, max_x);
181 if ( max_x/factor > strlen(str)) {
182 if (factor == 1)
183 diff = max_x/factor - strlen(str) - 1;
184 else
185 diff = max_x/factor - strlen(str);
186 for (i = 0; i < diff; i++) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530187 strlcat(str_target, " ", max_x);
lijuang7d235f42015-07-16 20:19:45 +0800188 }
Parth Dixit73d3bd02016-01-07 14:29:41 +0530189 strlcat(str_target, str, max_x);
lijuang7d235f42015-07-16 20:19:45 +0800190 return str_target;
191 } else {
192 free(str_target);
193 return str;
194 }
195 }
196 return str;
197}
198
lijuang9a7d3b92015-11-30 14:41:24 +0800199/* msg_lock need to be holded when call this function. */
200void display_unlock_menu_renew(struct select_msg_info *unlock_msg_info, int type)
lijuang7d235f42015-07-16 20:19:45 +0800201{
202 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800203 memset(&unlock_msg_info->info, 0, sizeof(struct menu_info));
204
lijuang7d235f42015-07-16 20:19:45 +0800205 display_fbcon_menu_message("Unlock bootloader?\n",
206 FBCON_UNLOCK_TITLE_MSG, big_factor);
lijuang4ece1e72015-08-14 21:02:36 +0800207 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang7d235f42015-07-16 20:19:45 +0800208
lijuang4ece1e72015-08-14 21:02:36 +0800209 display_fbcon_menu_message((char*)unlock_menu_common_msg,
lijuang7d235f42015-07-16 20:19:45 +0800210 FBCON_COMMON_MSG, common_factor);
lijuang4ece1e72015-08-14 21:02:36 +0800211 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800212 unlock_msg_info->info.option_start[0] = fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800213 display_fbcon_menu_message("Yes\n",
214 FBCON_COMMON_MSG, big_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800215 unlock_msg_info->info.option_bg[0] = fbcon_get_current_bg();
lijuang7d235f42015-07-16 20:19:45 +0800216 display_fbcon_menu_message("Unlock bootloader(may void warranty)\n",
217 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800218 unlock_msg_info->info.option_end[0] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800219 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800220 unlock_msg_info->info.option_start[1] = fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800221 display_fbcon_menu_message("No\n",
222 FBCON_COMMON_MSG, big_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800223 unlock_msg_info->info.option_bg[1] = fbcon_get_current_bg();
lijuang7d235f42015-07-16 20:19:45 +0800224 display_fbcon_menu_message("Do not unlock bootloader and restart phone\n",
225 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800226 unlock_msg_info->info.option_end[1] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800227 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang7d235f42015-07-16 20:19:45 +0800228
lijuang4ece1e72015-08-14 21:02:36 +0800229 if (type == UNLOCK)
lijuang9a7d3b92015-11-30 14:41:24 +0800230 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK;
lijuang4ece1e72015-08-14 21:02:36 +0800231 else if (type == UNLOCK_CRITICAL)
lijuang9a7d3b92015-11-30 14:41:24 +0800232 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK_CRITICAL;
lijuang4ece1e72015-08-14 21:02:36 +0800233
lijuang9a7d3b92015-11-30 14:41:24 +0800234 unlock_msg_info->info.option_num = 2;
235
236 /* Initialize the option index */
237 unlock_msg_info->info.option_index= 2;
lijuang7d235f42015-07-16 20:19:45 +0800238}
239
lijuang4ece1e72015-08-14 21:02:36 +0800240#if VERIFIED_BOOT
lijuang9a7d3b92015-11-30 14:41:24 +0800241/* msg_lock need to be holded when call this function. */
242void display_bootverify_menu_renew(struct select_msg_info *msg_info, int type)
lijuang7d235f42015-07-16 20:19:45 +0800243{
lijuang7d235f42015-07-16 20:19:45 +0800244 unsigned char* fp_buf = NULL;
245 char fp_str_temp[EVP_MAX_MD_SIZE] = {'\0'};
246 char fp_str[EVP_MAX_MD_SIZE*2] = {'\0'};
247 char str_temp[8];
248
249 char str1[]= "Start >";
250 char str2[] = "Continue boot";
251 char *str_target = NULL;
252 uint32 fp_size = 0;
253 unsigned int i = 0;
254
255 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800256 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800257
lijuang7d235f42015-07-16 20:19:45 +0800258 /* Align Right */
259 str_target = str_align_right(str1, big_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800260 if(str_target != NULL) {
Sridhar Parasuram995a3552015-08-22 08:46:10 -0700261 display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, big_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800262 free(str_target);
263 }
lijuang7d235f42015-07-16 20:19:45 +0800264
265 str_target = str_align_right(str2, common_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800266 if(str_target != NULL) {
Sridhar Parasuram995a3552015-08-22 08:46:10 -0700267 display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, common_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800268 free(str_target);
269 }
lijuang7d235f42015-07-16 20:19:45 +0800270
271 display_fbcon_menu_message("\n< More options\n",
272 FBCON_COMMON_MSG, common_factor);
273 display_fbcon_menu_message("press VOLUME keys\n\n",
274 FBCON_SUBTITLE_MSG, common_factor);
lijuang4ece1e72015-08-14 21:02:36 +0800275 if(boot_verify_info[type].warning_msg != NULL)
276 display_fbcon_menu_message((char*)boot_verify_info[type].warning_msg,
277 FBCON_COMMON_MSG, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800278
279 display_fbcon_menu_message("g.co/placeholder\n",
lijuang4ece1e72015-08-14 21:02:36 +0800280 boot_verify_info[type].msg_type, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800281
lijuang7d235f42015-07-16 20:19:45 +0800282 if (type == DISPLAY_MENU_YELLOW) {
283 fp_buf = get_boot_fingerprint(&fp_size);
284 if (fp_buf != NULL) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530285 strlcpy(fp_str_temp, (char const *)fp_buf, fp_size);
lijuang7d235f42015-07-16 20:19:45 +0800286 for (i = 0; i < fp_size; i++) {
287 if(i == fp_size - 1)
Parth Dixit73d3bd02016-01-07 14:29:41 +0530288 snprintf(str_temp, sizeof(str_temp), "%02x", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800289 else
Parth Dixit73d3bd02016-01-07 14:29:41 +0530290 snprintf(str_temp, sizeof(str_temp), "%02x-", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800291
Parth Dixit73d3bd02016-01-07 14:29:41 +0530292 strlcat(fp_str, str_temp, sizeof(fp_str));
lijuang7d235f42015-07-16 20:19:45 +0800293 }
294 }
295 display_fbcon_menu_message("ID:", FBCON_COMMON_MSG, common_factor);
296 display_fbcon_menu_message(fp_str, FBCON_COMMON_MSG, common_factor);
297 }
lijuang7d235f42015-07-16 20:19:45 +0800298
299 display_fbcon_menu_message("\n\nIf no key pressed:\n"\
300 "Your device will boot in 5 seconds\n\n", FBCON_COMMON_MSG, common_factor);
301
lijuang9a7d3b92015-11-30 14:41:24 +0800302 msg_info->info.msg_type = type;
lijuang9a7d3b92015-11-30 14:41:24 +0800303
304 /* Initialize the time out time */
305 msg_info->info.timeout_time = 5000; //5s
lijuang7d235f42015-07-16 20:19:45 +0800306}
lijuang4ece1e72015-08-14 21:02:36 +0800307#endif
lijuang7d235f42015-07-16 20:19:45 +0800308
lijuang9a7d3b92015-11-30 14:41:24 +0800309/* msg_lock need to be holded when call this function. */
310void display_bootverify_option_menu_renew(struct select_msg_info *msg_info)
lijuang7d235f42015-07-16 20:19:45 +0800311{
312 int i = 0;
lijuang4ece1e72015-08-14 21:02:36 +0800313 int len = 0;
lijuang9a7d3b92015-11-30 14:41:24 +0800314
lijuang7d235f42015-07-16 20:19:45 +0800315 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800316 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800317
lijuang4ece1e72015-08-14 21:02:36 +0800318 len = ARRAY_SIZE(verify_option_menu);
lijuang7d235f42015-07-16 20:19:45 +0800319 display_fbcon_menu_message("Options menu:\n\n",
320 FBCON_COMMON_MSG, big_factor);
321 display_fbcon_menu_message("Press volume key to select, and "\
322 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor);
323
lijuang4ece1e72015-08-14 21:02:36 +0800324 for (i = 0; i < len; i++) {
325 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800326 msg_info->info.option_start[i] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800327 display_fbcon_menu_message(verify_option_menu[i],
lijuang7d235f42015-07-16 20:19:45 +0800328 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800329 msg_info->info.option_bg[i]= fbcon_get_current_bg();
330 msg_info->info.option_end[i]= fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800331 }
332
lijuang4ece1e72015-08-14 21:02:36 +0800333 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800334 msg_info->info.msg_type = DISPLAY_MENU_MORE_OPTION;
335 msg_info->info.option_num = len;
336
337 /* Initialize the option index */
338 msg_info->info.option_index= len;
lijuang4ece1e72015-08-14 21:02:36 +0800339}
340
lijuang9a7d3b92015-11-30 14:41:24 +0800341/* msg_lock need to be holded when call this function. */
342void display_fastboot_menu_renew(struct select_msg_info *fastboot_msg_info)
lijuang4ece1e72015-08-14 21:02:36 +0800343{
344 int len;
345 int msg_type = FBCON_COMMON_MSG;
346 char msg_buf[64];
347 char msg[128];
348
lijuang9a7d3b92015-11-30 14:41:24 +0800349 /* The fastboot menu is switched base on the option index
350 * So it's need to store the index for the menu switching
351 */
352 uint32_t option_index = fastboot_msg_info->info.option_index;
353
lijuang4ece1e72015-08-14 21:02:36 +0800354 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800355 memset(&fastboot_msg_info->info, 0, sizeof(struct menu_info));
lijuang4ece1e72015-08-14 21:02:36 +0800356
357 len = ARRAY_SIZE(fastboot_option_menu);
358 switch(option_index) {
359 case 0:
360 msg_type = FBCON_GREEN_MSG;
361 break;
362 case 1:
363 case 2:
364 msg_type = FBCON_RED_MSG;
365 break;
366 case 3:
lijuang42aefaa2016-04-14 15:55:17 +0800367 case 4:
lijuang4ece1e72015-08-14 21:02:36 +0800368 msg_type = FBCON_COMMON_MSG;
369 break;
370 }
371 fbcon_draw_line(msg_type);
372 display_fbcon_menu_message(fastboot_option_menu[option_index],
373 msg_type, big_factor);
374 fbcon_draw_line(msg_type);
375 display_fbcon_menu_message("\n\nPress volume key to select, and "\
376 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor);
377
378 display_fbcon_menu_message("FASTBOOT MODE\n", FBCON_RED_MSG, common_factor);
379
380 get_product_name((unsigned char *) msg_buf);
381 snprintf(msg, sizeof(msg), "PRODUCT_NAME - %s\n", msg_buf);
382 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
383
384 memset(msg_buf, 0, sizeof(msg_buf));
385 smem_get_hw_platform_name((unsigned char *) msg_buf, sizeof(msg_buf));
386 snprintf(msg, sizeof(msg), "VARIANT - %s %s\n",
387 msg_buf, target_is_emmc_boot()? "eMMC":"UFS");
388 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
389
390 memset(msg_buf, 0, sizeof(msg_buf));
391 get_bootloader_version((unsigned char *) msg_buf);
392 snprintf(msg, sizeof(msg), "BOOTLOADER VERSION - %s\n",
393 msg_buf);
394 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
395
396 memset(msg_buf, 0, sizeof(msg_buf));
397 get_baseband_version((unsigned char *) msg_buf);
398 snprintf(msg, sizeof(msg), "BASEBAND VERSION - %s\n",
399 msg_buf);
400 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
401
402 memset(msg_buf, 0, sizeof(msg_buf));
403 target_serialno((unsigned char *) msg_buf);
404 snprintf(msg, sizeof(msg), "SERIAL NUMBER - %s\n", msg_buf);
405 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
406
407 snprintf(msg, sizeof(msg), "SECURE BOOT - %s\n",
408 is_secure_boot_enable()? "enabled":"disabled");
409 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
410
411 snprintf(msg, sizeof(msg), "DEVICE STATE - %s\n",
412 is_device_locked()? "locked":"unlocked");
413 display_fbcon_menu_message(msg, FBCON_RED_MSG, common_factor);
414
lijuang9a7d3b92015-11-30 14:41:24 +0800415 fastboot_msg_info->info.msg_type = DISPLAY_MENU_FASTBOOT;
416 fastboot_msg_info->info.option_num = len;
417 fastboot_msg_info->info.option_index = option_index;
418}
419
420void msg_lock_init()
421{
422 static bool is_msg_lock_init = false;
423 struct select_msg_info *msg_lock_info;
424 msg_lock_info = &msg_info;
425
426 if (!is_msg_lock_init) {
427 mutex_init(&msg_lock_info->msg_lock);
428 is_msg_lock_init = true;
429 }
lijuang7d235f42015-07-16 20:19:45 +0800430}
431
432static void display_menu_thread_start(struct select_msg_info *msg_info)
433{
434 thread_t *thr;
435
436 if (!is_thread_start) {
437 thr = thread_create("selectkeydetect", &select_msg_keys_detect,
438 (void*)msg_info, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
439 if (!thr) {
440 dprintf(CRITICAL, "ERROR: creat device status detect thread failed!!\n");
441 return;
442 }
443 thread_resume(thr);
lijuang9a7d3b92015-11-30 14:41:24 +0800444 is_thread_start = true;
lijuang7d235f42015-07-16 20:19:45 +0800445 }
lijuang7d235f42015-07-16 20:19:45 +0800446}
447
lijuang9a7d3b92015-11-30 14:41:24 +0800448/* The fuction be called after device in fastboot mode,
449 * so it's no need to initialize the msg_lock again
450 */
451void display_unlock_menu(int type)
lijuang7d235f42015-07-16 20:19:45 +0800452{
lijuang4ece1e72015-08-14 21:02:36 +0800453 struct select_msg_info *unlock_menu_msg_info;
454 unlock_menu_msg_info = &msg_info;
lijuang7d235f42015-07-16 20:19:45 +0800455
456 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800457
458 msg_lock_init();
459 mutex_acquire(&unlock_menu_msg_info->msg_lock);
460
461 /* Initialize the last_msg_type */
462 unlock_menu_msg_info->last_msg_type =
463 unlock_menu_msg_info->info.msg_type;
464
465 display_unlock_menu_renew(unlock_menu_msg_info, type);
466 mutex_release(&unlock_menu_msg_info->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800467
lijuang4ece1e72015-08-14 21:02:36 +0800468 dprintf(INFO, "creating unlock keys detect thread\n");
469 display_menu_thread_start(unlock_menu_msg_info);
lijuang7d235f42015-07-16 20:19:45 +0800470}
471
lijuang9a7d3b92015-11-30 14:41:24 +0800472void display_fastboot_menu()
lijuang4ece1e72015-08-14 21:02:36 +0800473{
474 struct select_msg_info *fastboot_menu_msg_info;
475 fastboot_menu_msg_info = &msg_info;
476
477 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800478
479 msg_lock_init();
480 mutex_acquire(&fastboot_menu_msg_info->msg_lock);
481
482 /* There are 4 pages for fastboot menu:
483 * Page: Start/Fastboot/Recovery/Poweroff
484 * The menu is switched base on the option index
485 * Initialize the option index and last_msg_type
486 */
487 fastboot_menu_msg_info->info.option_index = 0;
488 fastboot_menu_msg_info->last_msg_type =
489 fastboot_menu_msg_info->info.msg_type;
490
491 display_fastboot_menu_renew(fastboot_menu_msg_info);
492 mutex_release(&fastboot_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800493
494 dprintf(INFO, "creating fastboot menu keys detect thread\n");
495 display_menu_thread_start(fastboot_menu_msg_info);
496}
497
498#if VERIFIED_BOOT
lijuang9a7d3b92015-11-30 14:41:24 +0800499void display_bootverify_menu(int type)
lijuang4ece1e72015-08-14 21:02:36 +0800500{
501 struct select_msg_info *bootverify_menu_msg_info;
502 bootverify_menu_msg_info = &msg_info;
503
504 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800505
506 msg_lock_init();
507 mutex_acquire(&bootverify_menu_msg_info->msg_lock);
508
509 /* Initialize the last_msg_type */
510 bootverify_menu_msg_info->last_msg_type =
511 bootverify_menu_msg_info->info.msg_type;
512
513 display_bootverify_menu_renew(bootverify_menu_msg_info, type);
514 mutex_release(&bootverify_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800515
516 dprintf(INFO, "creating boot verify keys detect thread\n");
517 display_menu_thread_start(bootverify_menu_msg_info);
518}
519#endif