blob: 1d1be46eb8f58ce2c2fd2db04169aba9673ddff8 [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
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070058#define YELLOW_WARNING_MSG "Your device has loaded a different operating system\n\n "\
59 "Visit this link on another device:\n g.co/ABH"
lijuang7d235f42015-07-16 20:19:45 +080060
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070061#define ORANGE_WARNING_MSG "Your device software can't be\n checked for corruption. Please lock the bootloader\n\n"\
62 "Visit this link on another device:\n g.co/ABH"
lijuang7d235f42015-07-16 20:19:45 +080063
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070064#define RED_WARNING_MSG "Your device is corrupt. It can't be\ntrusted and will not boot\n\n" \
65 "Visit this link on another device:\n g.co/ABH"
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
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070070#define EIO_WARNING_MSG "Your device is corrupt. It can't be\n trusted and may not work properly.\n\n"\
71 "Visit this link on another device:\n g.co/ABH"
72
lijuang7d235f42015-07-16 20:19:45 +080073static bool is_thread_start = false;
lijuang9a7d3b92015-11-30 14:41:24 +080074static struct select_msg_info msg_info;
lijuang7d235f42015-07-16 20:19:45 +080075
lijuang4ece1e72015-08-14 21:02:36 +080076#if VERIFIED_BOOT
77struct boot_verify_info {
78 int msg_type;
79 const char *warning_msg;
80};
81
82struct boot_verify_info boot_verify_info[] = {
83 [DISPLAY_MENU_RED] = {FBCON_RED_MSG, RED_WARNING_MSG},
84 [DISPLAY_MENU_YELLOW] = {FBCON_YELLOW_MSG, YELLOW_WARNING_MSG},
lijuangbdd9bb42016-03-01 18:22:17 +080085 [DISPLAY_MENU_ORANGE] = {FBCON_ORANGE_MSG, ORANGE_WARNING_MSG},
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070086 [DISPLAY_MENU_LOGGING] = {FBCON_RED_MSG, LOGGING_WARNING_MSG},
87 [DISPLAY_MENU_EIO] = {FBCON_RED_MSG, EIO_WARNING_MSG}};
lijuang4ece1e72015-08-14 21:02:36 +080088#endif
89
90static char *verify_option_menu[] = {
lijuang7d235f42015-07-16 20:19:45 +080091 [POWEROFF] = "Power off\n",
92 [RESTART] = "Restart\n",
93 [RECOVER] = "Recovery\n",
94 [FASTBOOT] = "Fastboot\n",
95 [BACK] = "Back to previous page\n"};
96
lijuang4ece1e72015-08-14 21:02:36 +080097static char *fastboot_option_menu[] = {
98 [0] = "START\n",
99 [1] = "Restart bootloader\n",
100 [2] = "Recovery mode\n",
lijuang42aefaa2016-04-14 15:55:17 +0800101 [3] = "Power off\n",
102 [4] = "Boot to FFBM\n"};
lijuang4ece1e72015-08-14 21:02:36 +0800103
lijuang7d235f42015-07-16 20:19:45 +0800104static int big_factor = 2;
105static int common_factor = 1;
106
lijuangde34d502016-02-26 16:04:50 +0800107static void wait_for_exit()
lijuang7d235f42015-07-16 20:19:45 +0800108{
109 struct select_msg_info *select_msg;
110 select_msg = &msg_info;
111
lijuang9a7d3b92015-11-30 14:41:24 +0800112 mutex_acquire(&select_msg->msg_lock);
lijuangde34d502016-02-26 16:04:50 +0800113 while(!select_msg->info.rel_exit == true) {
lijuang9a7d3b92015-11-30 14:41:24 +0800114 mutex_release(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800115 thread_sleep(10);
lijuang9a7d3b92015-11-30 14:41:24 +0800116 mutex_acquire(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800117 }
lijuang9a7d3b92015-11-30 14:41:24 +0800118 mutex_release(&select_msg->msg_lock);
119
lijuangde34d502016-02-26 16:04:50 +0800120 is_thread_start = false;
lijuang7d235f42015-07-16 20:19:45 +0800121 fbcon_clear();
122 display_image_on_screen();
123}
124
lijuangde34d502016-02-26 16:04:50 +0800125void wait_for_users_action()
126{
127 /* Waiting for exit menu keys detection if there is no any usr action
128 * otherwise it will do the action base on the keys detection thread
129 */
130 wait_for_exit();
131}
132
133void exit_menu_keys_detection()
134{
135 struct select_msg_info *select_msg;
136 select_msg = &msg_info;
137
138 mutex_acquire(&select_msg->msg_lock);
139 select_msg->info.is_exit = true;
140 mutex_release(&select_msg->msg_lock);
141
142 wait_for_exit();
143}
144
lijuang7d235f42015-07-16 20:19:45 +0800145static void set_message_factor()
146{
147 uint32_t tmp_factor = 0;
148 uint32_t max_x_count = 40;
149 uint32_t max_x = fbcon_get_max_x();
150
151 max_x = fbcon_get_max_x();
152 tmp_factor = max_x/max_x_count;
153
154 if(tmp_factor <= 1) {
155 big_factor = 2;
156 common_factor = 1;
157 } else {
158 big_factor = tmp_factor*2;
159 common_factor = tmp_factor;
160 }
161}
162
163static void display_fbcon_menu_message(char *str, unsigned type,
164 unsigned scale_factor)
165{
166 while(*str != 0) {
167 fbcon_putc_factor(*str++, type, scale_factor);
168 }
169}
170
171static char *str_align_right(char *str, int factor)
172{
173 uint32_t max_x = 0;
174 int diff = 0;
175 int i = 0;
176 char *str_target = NULL;
177
178 max_x = fbcon_get_max_x();
179 if (!str_target && max_x) {
180 str_target = malloc(max_x);
181 }
182
183 if (str_target) {
184 memset(str_target, 0, max_x);
185 if ( max_x/factor > strlen(str)) {
186 if (factor == 1)
187 diff = max_x/factor - strlen(str) - 1;
188 else
189 diff = max_x/factor - strlen(str);
190 for (i = 0; i < diff; i++) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530191 strlcat(str_target, " ", max_x);
lijuang7d235f42015-07-16 20:19:45 +0800192 }
Parth Dixit73d3bd02016-01-07 14:29:41 +0530193 strlcat(str_target, str, max_x);
lijuang7d235f42015-07-16 20:19:45 +0800194 return str_target;
195 } else {
196 free(str_target);
197 return str;
198 }
199 }
200 return str;
201}
202
lijuang9a7d3b92015-11-30 14:41:24 +0800203/* msg_lock need to be holded when call this function. */
204void display_unlock_menu_renew(struct select_msg_info *unlock_msg_info, int type)
lijuang7d235f42015-07-16 20:19:45 +0800205{
206 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800207 memset(&unlock_msg_info->info, 0, sizeof(struct menu_info));
208
lijuang7d235f42015-07-16 20:19:45 +0800209 display_fbcon_menu_message("Unlock bootloader?\n",
210 FBCON_UNLOCK_TITLE_MSG, big_factor);
lijuang4ece1e72015-08-14 21:02:36 +0800211 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang7d235f42015-07-16 20:19:45 +0800212
lijuang4ece1e72015-08-14 21:02:36 +0800213 display_fbcon_menu_message((char*)unlock_menu_common_msg,
lijuang7d235f42015-07-16 20:19:45 +0800214 FBCON_COMMON_MSG, common_factor);
lijuang4ece1e72015-08-14 21:02:36 +0800215 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800216 unlock_msg_info->info.option_start[0] = fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800217 display_fbcon_menu_message("Yes\n",
218 FBCON_COMMON_MSG, big_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800219 unlock_msg_info->info.option_bg[0] = fbcon_get_current_bg();
lijuang7d235f42015-07-16 20:19:45 +0800220 display_fbcon_menu_message("Unlock bootloader(may void warranty)\n",
221 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800222 unlock_msg_info->info.option_end[0] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800223 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800224 unlock_msg_info->info.option_start[1] = fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800225 display_fbcon_menu_message("No\n",
226 FBCON_COMMON_MSG, big_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800227 unlock_msg_info->info.option_bg[1] = fbcon_get_current_bg();
lijuang7d235f42015-07-16 20:19:45 +0800228 display_fbcon_menu_message("Do not unlock bootloader and restart phone\n",
229 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800230 unlock_msg_info->info.option_end[1] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800231 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang7d235f42015-07-16 20:19:45 +0800232
lijuang4ece1e72015-08-14 21:02:36 +0800233 if (type == UNLOCK)
lijuang9a7d3b92015-11-30 14:41:24 +0800234 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK;
lijuang4ece1e72015-08-14 21:02:36 +0800235 else if (type == UNLOCK_CRITICAL)
lijuang9a7d3b92015-11-30 14:41:24 +0800236 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK_CRITICAL;
lijuang4ece1e72015-08-14 21:02:36 +0800237
lijuang9a7d3b92015-11-30 14:41:24 +0800238 unlock_msg_info->info.option_num = 2;
239
240 /* Initialize the option index */
241 unlock_msg_info->info.option_index= 2;
lijuang7d235f42015-07-16 20:19:45 +0800242}
243
lijuang4ece1e72015-08-14 21:02:36 +0800244#if VERIFIED_BOOT
lijuang9a7d3b92015-11-30 14:41:24 +0800245/* msg_lock need to be holded when call this function. */
246void display_bootverify_menu_renew(struct select_msg_info *msg_info, int type)
lijuang7d235f42015-07-16 20:19:45 +0800247{
lijuang7d235f42015-07-16 20:19:45 +0800248 unsigned char* fp_buf = NULL;
249 char fp_str_temp[EVP_MAX_MD_SIZE] = {'\0'};
250 char fp_str[EVP_MAX_MD_SIZE*2] = {'\0'};
251 char str_temp[8];
252
253 char str1[]= "Start >";
254 char str2[] = "Continue boot";
255 char *str_target = NULL;
256 uint32 fp_size = 0;
257 unsigned int i = 0;
258
259 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800260 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800261
lijuang7d235f42015-07-16 20:19:45 +0800262 /* Align Right */
263 str_target = str_align_right(str1, big_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800264 if(str_target != NULL) {
Sridhar Parasuram995a3552015-08-22 08:46:10 -0700265 display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, big_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800266 free(str_target);
267 }
lijuang7d235f42015-07-16 20:19:45 +0800268
269 str_target = str_align_right(str2, common_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800270 if(str_target != NULL) {
Sridhar Parasuram995a3552015-08-22 08:46:10 -0700271 display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, common_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800272 free(str_target);
273 }
lijuang7d235f42015-07-16 20:19:45 +0800274
275 display_fbcon_menu_message("\n< More options\n",
276 FBCON_COMMON_MSG, common_factor);
277 display_fbcon_menu_message("press VOLUME keys\n\n",
278 FBCON_SUBTITLE_MSG, common_factor);
lijuang4ece1e72015-08-14 21:02:36 +0800279 if(boot_verify_info[type].warning_msg != NULL)
280 display_fbcon_menu_message((char*)boot_verify_info[type].warning_msg,
281 FBCON_COMMON_MSG, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800282
283 display_fbcon_menu_message("g.co/placeholder\n",
lijuang4ece1e72015-08-14 21:02:36 +0800284 boot_verify_info[type].msg_type, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800285
lijuang7d235f42015-07-16 20:19:45 +0800286 if (type == DISPLAY_MENU_YELLOW) {
287 fp_buf = get_boot_fingerprint(&fp_size);
288 if (fp_buf != NULL) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530289 strlcpy(fp_str_temp, (char const *)fp_buf, fp_size);
lijuang7d235f42015-07-16 20:19:45 +0800290 for (i = 0; i < fp_size; i++) {
291 if(i == fp_size - 1)
Parth Dixit73d3bd02016-01-07 14:29:41 +0530292 snprintf(str_temp, sizeof(str_temp), "%02x", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800293 else
Parth Dixit73d3bd02016-01-07 14:29:41 +0530294 snprintf(str_temp, sizeof(str_temp), "%02x-", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800295
Parth Dixit73d3bd02016-01-07 14:29:41 +0530296 strlcat(fp_str, str_temp, sizeof(fp_str));
lijuang7d235f42015-07-16 20:19:45 +0800297 }
298 }
299 display_fbcon_menu_message("ID:", FBCON_COMMON_MSG, common_factor);
300 display_fbcon_menu_message(fp_str, FBCON_COMMON_MSG, common_factor);
301 }
lijuang7d235f42015-07-16 20:19:45 +0800302
303 display_fbcon_menu_message("\n\nIf no key pressed:\n"\
304 "Your device will boot in 5 seconds\n\n", FBCON_COMMON_MSG, common_factor);
305
lijuang9a7d3b92015-11-30 14:41:24 +0800306 msg_info->info.msg_type = type;
lijuang9a7d3b92015-11-30 14:41:24 +0800307
308 /* Initialize the time out time */
309 msg_info->info.timeout_time = 5000; //5s
lijuang7d235f42015-07-16 20:19:45 +0800310}
lijuang4ece1e72015-08-14 21:02:36 +0800311#endif
lijuang7d235f42015-07-16 20:19:45 +0800312
lijuang9a7d3b92015-11-30 14:41:24 +0800313/* msg_lock need to be holded when call this function. */
314void display_bootverify_option_menu_renew(struct select_msg_info *msg_info)
lijuang7d235f42015-07-16 20:19:45 +0800315{
316 int i = 0;
lijuang4ece1e72015-08-14 21:02:36 +0800317 int len = 0;
lijuang9a7d3b92015-11-30 14:41:24 +0800318
lijuang7d235f42015-07-16 20:19:45 +0800319 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800320 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800321
lijuang4ece1e72015-08-14 21:02:36 +0800322 len = ARRAY_SIZE(verify_option_menu);
lijuang7d235f42015-07-16 20:19:45 +0800323 display_fbcon_menu_message("Options menu:\n\n",
324 FBCON_COMMON_MSG, big_factor);
325 display_fbcon_menu_message("Press volume key to select, and "\
326 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor);
327
lijuang4ece1e72015-08-14 21:02:36 +0800328 for (i = 0; i < len; i++) {
329 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800330 msg_info->info.option_start[i] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800331 display_fbcon_menu_message(verify_option_menu[i],
lijuang7d235f42015-07-16 20:19:45 +0800332 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800333 msg_info->info.option_bg[i]= fbcon_get_current_bg();
334 msg_info->info.option_end[i]= fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800335 }
336
lijuang4ece1e72015-08-14 21:02:36 +0800337 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800338 msg_info->info.msg_type = DISPLAY_MENU_MORE_OPTION;
339 msg_info->info.option_num = len;
340
341 /* Initialize the option index */
342 msg_info->info.option_index= len;
lijuang4ece1e72015-08-14 21:02:36 +0800343}
344
lijuang9a7d3b92015-11-30 14:41:24 +0800345/* msg_lock need to be holded when call this function. */
346void display_fastboot_menu_renew(struct select_msg_info *fastboot_msg_info)
lijuang4ece1e72015-08-14 21:02:36 +0800347{
348 int len;
349 int msg_type = FBCON_COMMON_MSG;
350 char msg_buf[64];
351 char msg[128];
352
lijuang9a7d3b92015-11-30 14:41:24 +0800353 /* The fastboot menu is switched base on the option index
354 * So it's need to store the index for the menu switching
355 */
356 uint32_t option_index = fastboot_msg_info->info.option_index;
357
lijuang4ece1e72015-08-14 21:02:36 +0800358 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800359 memset(&fastboot_msg_info->info, 0, sizeof(struct menu_info));
lijuang4ece1e72015-08-14 21:02:36 +0800360
361 len = ARRAY_SIZE(fastboot_option_menu);
362 switch(option_index) {
363 case 0:
364 msg_type = FBCON_GREEN_MSG;
365 break;
366 case 1:
367 case 2:
368 msg_type = FBCON_RED_MSG;
369 break;
370 case 3:
lijuang42aefaa2016-04-14 15:55:17 +0800371 case 4:
lijuang4ece1e72015-08-14 21:02:36 +0800372 msg_type = FBCON_COMMON_MSG;
373 break;
374 }
375 fbcon_draw_line(msg_type);
376 display_fbcon_menu_message(fastboot_option_menu[option_index],
377 msg_type, big_factor);
378 fbcon_draw_line(msg_type);
379 display_fbcon_menu_message("\n\nPress volume key to select, and "\
380 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor);
381
382 display_fbcon_menu_message("FASTBOOT MODE\n", FBCON_RED_MSG, common_factor);
383
384 get_product_name((unsigned char *) msg_buf);
385 snprintf(msg, sizeof(msg), "PRODUCT_NAME - %s\n", msg_buf);
386 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
387
388 memset(msg_buf, 0, sizeof(msg_buf));
389 smem_get_hw_platform_name((unsigned char *) msg_buf, sizeof(msg_buf));
390 snprintf(msg, sizeof(msg), "VARIANT - %s %s\n",
391 msg_buf, target_is_emmc_boot()? "eMMC":"UFS");
392 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
393
394 memset(msg_buf, 0, sizeof(msg_buf));
395 get_bootloader_version((unsigned char *) msg_buf);
396 snprintf(msg, sizeof(msg), "BOOTLOADER VERSION - %s\n",
397 msg_buf);
398 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
399
400 memset(msg_buf, 0, sizeof(msg_buf));
401 get_baseband_version((unsigned char *) msg_buf);
402 snprintf(msg, sizeof(msg), "BASEBAND VERSION - %s\n",
403 msg_buf);
404 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
405
406 memset(msg_buf, 0, sizeof(msg_buf));
407 target_serialno((unsigned char *) msg_buf);
408 snprintf(msg, sizeof(msg), "SERIAL NUMBER - %s\n", msg_buf);
409 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
410
411 snprintf(msg, sizeof(msg), "SECURE BOOT - %s\n",
412 is_secure_boot_enable()? "enabled":"disabled");
413 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
414
415 snprintf(msg, sizeof(msg), "DEVICE STATE - %s\n",
416 is_device_locked()? "locked":"unlocked");
417 display_fbcon_menu_message(msg, FBCON_RED_MSG, common_factor);
418
lijuang9a7d3b92015-11-30 14:41:24 +0800419 fastboot_msg_info->info.msg_type = DISPLAY_MENU_FASTBOOT;
420 fastboot_msg_info->info.option_num = len;
421 fastboot_msg_info->info.option_index = option_index;
422}
423
424void msg_lock_init()
425{
426 static bool is_msg_lock_init = false;
427 struct select_msg_info *msg_lock_info;
428 msg_lock_info = &msg_info;
429
430 if (!is_msg_lock_init) {
431 mutex_init(&msg_lock_info->msg_lock);
432 is_msg_lock_init = true;
433 }
lijuang7d235f42015-07-16 20:19:45 +0800434}
435
436static void display_menu_thread_start(struct select_msg_info *msg_info)
437{
438 thread_t *thr;
439
440 if (!is_thread_start) {
441 thr = thread_create("selectkeydetect", &select_msg_keys_detect,
442 (void*)msg_info, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
443 if (!thr) {
444 dprintf(CRITICAL, "ERROR: creat device status detect thread failed!!\n");
445 return;
446 }
447 thread_resume(thr);
lijuang9a7d3b92015-11-30 14:41:24 +0800448 is_thread_start = true;
lijuang7d235f42015-07-16 20:19:45 +0800449 }
lijuang7d235f42015-07-16 20:19:45 +0800450}
451
lijuang9a7d3b92015-11-30 14:41:24 +0800452/* The fuction be called after device in fastboot mode,
453 * so it's no need to initialize the msg_lock again
454 */
455void display_unlock_menu(int type)
lijuang7d235f42015-07-16 20:19:45 +0800456{
lijuang4ece1e72015-08-14 21:02:36 +0800457 struct select_msg_info *unlock_menu_msg_info;
458 unlock_menu_msg_info = &msg_info;
lijuang7d235f42015-07-16 20:19:45 +0800459
460 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800461
462 msg_lock_init();
463 mutex_acquire(&unlock_menu_msg_info->msg_lock);
464
465 /* Initialize the last_msg_type */
466 unlock_menu_msg_info->last_msg_type =
467 unlock_menu_msg_info->info.msg_type;
468
469 display_unlock_menu_renew(unlock_menu_msg_info, type);
470 mutex_release(&unlock_menu_msg_info->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800471
lijuang4ece1e72015-08-14 21:02:36 +0800472 dprintf(INFO, "creating unlock keys detect thread\n");
473 display_menu_thread_start(unlock_menu_msg_info);
lijuang7d235f42015-07-16 20:19:45 +0800474}
475
lijuang9a7d3b92015-11-30 14:41:24 +0800476void display_fastboot_menu()
lijuang4ece1e72015-08-14 21:02:36 +0800477{
478 struct select_msg_info *fastboot_menu_msg_info;
479 fastboot_menu_msg_info = &msg_info;
480
481 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800482
483 msg_lock_init();
484 mutex_acquire(&fastboot_menu_msg_info->msg_lock);
485
486 /* There are 4 pages for fastboot menu:
487 * Page: Start/Fastboot/Recovery/Poweroff
488 * The menu is switched base on the option index
489 * Initialize the option index and last_msg_type
490 */
491 fastboot_menu_msg_info->info.option_index = 0;
492 fastboot_menu_msg_info->last_msg_type =
493 fastboot_menu_msg_info->info.msg_type;
494
495 display_fastboot_menu_renew(fastboot_menu_msg_info);
496 mutex_release(&fastboot_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800497
498 dprintf(INFO, "creating fastboot menu keys detect thread\n");
499 display_menu_thread_start(fastboot_menu_msg_info);
500}
501
502#if VERIFIED_BOOT
lijuang9a7d3b92015-11-30 14:41:24 +0800503void display_bootverify_menu(int type)
lijuang4ece1e72015-08-14 21:02:36 +0800504{
505 struct select_msg_info *bootverify_menu_msg_info;
506 bootverify_menu_msg_info = &msg_info;
507
508 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800509
510 msg_lock_init();
511 mutex_acquire(&bootverify_menu_msg_info->msg_lock);
512
513 /* Initialize the last_msg_type */
514 bootverify_menu_msg_info->last_msg_type =
515 bootverify_menu_msg_info->info.msg_type;
516
517 display_bootverify_menu_renew(bootverify_menu_msg_info, type);
518 mutex_release(&bootverify_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800519
520 dprintf(INFO, "creating boot verify keys detect thread\n");
521 display_menu_thread_start(bootverify_menu_msg_info);
522}
523#endif