blob: b55486004f5dc784e9b1b7e645a258a6bba9a9cf [file] [log] [blame]
lijuangbdb18ea2018-02-06 17:21:18 +08001/* Copyright (c) 2015-2018, 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>
lijuangf55ad052018-04-23 18:30:50 +080044#include <../../../app/aboot/recovery.h>
lijuang7d235f42015-07-16 20:19:45 +080045
lijuangf55ad052018-04-23 18:30:50 +080046static const char *unlock_menu_common_msg = "By unlocking the bootloader, you will be able to install "\
47 "custom operating system on this phone. "\
48 "A custom OS is not subject to the same level of testing "\
49 "as the original OS, and can cause your phone "\
50 "and installed applications to stop working properly.\n\n"\
51 "Software integrity cannot be guaranteed with a custom OS, "\
52 "so any data stored on the phone while the bootloader "\
53 "is unlocked may be at risk.\n\n"\
lijuang7d235f42015-07-16 20:19:45 +080054 "To prevent unauthorized access to your personal data, "\
55 "unlocking the bootloader will also delete all personal "\
lijuangf55ad052018-04-23 18:30:50 +080056 "data on your phone.\n\n"\
57 "Press the Volume keys to select whether to unlock the bootloader, "\
58 "then the Power Button to continue.\n\n";
59
60static const char *lock_menu_common_msg = "If you lock the bootloader, "\
61 "you will not be able to install "\
62 "custom operating system on this phone.\n\n"\
63 "To prevent unauthorized access to your personal data, "\
64 "locking the bootloader will also delete all personal "\
65 "data on your phone.\n\n"\
66 "Press the Volume keys to select whether to "\
67 "lock the bootloader, then the power button to continue.\n\n";
lijuang7d235f42015-07-16 20:19:45 +080068
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070069#define YELLOW_WARNING_MSG "Your device has loaded a different operating system\n\n "\
Brahmaji K0c2d5982017-09-07 18:44:21 +053070 "Visit this link on another device:\n"
lijuang7d235f42015-07-16 20:19:45 +080071
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070072#define ORANGE_WARNING_MSG "Your device software can't be\n checked for corruption. Please lock the bootloader\n\n"\
Brahmaji K0c2d5982017-09-07 18:44:21 +053073 "Visit this link on another device:\n"
lijuang7d235f42015-07-16 20:19:45 +080074
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070075#define RED_WARNING_MSG "Your device is corrupt. It can't be\ntrusted and will not boot\n\n" \
Brahmaji K0c2d5982017-09-07 18:44:21 +053076 "Visit this link on another device:\n"
lijuang7d235f42015-07-16 20:19:45 +080077
lijuangbdd9bb42016-03-01 18:22:17 +080078#define LOGGING_WARNING_MSG "The dm-verity is not started in enforcing mode and may "\
79 "not work properly\n\nTo learn more, visit:\n"
80
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070081#define EIO_WARNING_MSG "Your device is corrupt. It can't be\n trusted and may not work properly.\n\n"\
Brahmaji K0c2d5982017-09-07 18:44:21 +053082 "Visit this link on another device:\n"
83
84#define URL_MSG "g.co/ABH\n"
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070085
Parth Dixit54ac3bb2017-03-07 15:52:48 +053086#define DELAY_5SEC 5000
87#define DELAY_30SEC 30000
88
lijuang7d235f42015-07-16 20:19:45 +080089static bool is_thread_start = false;
lijuang9a7d3b92015-11-30 14:41:24 +080090static struct select_msg_info msg_info;
lijuang7d235f42015-07-16 20:19:45 +080091
Monika Singh5e170362018-03-14 00:48:36 +053092#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang4ece1e72015-08-14 21:02:36 +080093struct boot_verify_info {
94 int msg_type;
95 const char *warning_msg;
Brahmaji K0c2d5982017-09-07 18:44:21 +053096 const char *url_msg;
lijuang4ece1e72015-08-14 21:02:36 +080097};
98
99struct boot_verify_info boot_verify_info[] = {
Brahmaji K0c2d5982017-09-07 18:44:21 +0530100 [DISPLAY_MENU_RED] = {FBCON_RED_MSG, RED_WARNING_MSG, URL_MSG},
101 [DISPLAY_MENU_YELLOW] = {FBCON_YELLOW_MSG, YELLOW_WARNING_MSG, URL_MSG},
102 [DISPLAY_MENU_ORANGE] = {FBCON_ORANGE_MSG, ORANGE_WARNING_MSG, URL_MSG},
103 [DISPLAY_MENU_LOGGING] = {FBCON_RED_MSG, LOGGING_WARNING_MSG, NULL},
104 [DISPLAY_MENU_EIO] = {FBCON_RED_MSG, EIO_WARNING_MSG, URL_MSG}};
lijuang4ece1e72015-08-14 21:02:36 +0800105#endif
106
107static char *verify_option_menu[] = {
lijuang7d235f42015-07-16 20:19:45 +0800108 [POWEROFF] = "Power off\n",
109 [RESTART] = "Restart\n",
110 [RECOVER] = "Recovery\n",
111 [FASTBOOT] = "Fastboot\n",
112 [BACK] = "Back to previous page\n"};
113
lijuang4ece1e72015-08-14 21:02:36 +0800114static char *fastboot_option_menu[] = {
115 [0] = "START\n",
116 [1] = "Restart bootloader\n",
117 [2] = "Recovery mode\n",
lijuang42aefaa2016-04-14 15:55:17 +0800118 [3] = "Power off\n",
119 [4] = "Boot to FFBM\n"};
lijuang4ece1e72015-08-14 21:02:36 +0800120
lijuangf55ad052018-04-23 18:30:50 +0800121static struct unlock_info munlock_info[] = {
122 [DISPLAY_MENU_LOCK] = {UNLOCK, FALSE},
123 [DISPLAY_MENU_UNLOCK] = {UNLOCK, TRUE},
124 [DISPLAY_MENU_LOCK_CRITICAL] = {UNLOCK_CRITICAL, FALSE},
125 [DISPLAY_MENU_UNLOCK_CRITICAL] = {UNLOCK_CRITICAL, TRUE},
126};
127
128struct unlock_option_msg munlock_option_msg[] = {
129 [TRUE] = {"DO NOT UNLOCK THE BOOTLOADER \n", "UNLOCK THE BOOTLOADER \n"},
130 [FALSE] = {"DO NOT LOCK THE BOOTLOADER \n", "LOCK THE BOOTLOADER \n"},
131};
132
lijuang7d235f42015-07-16 20:19:45 +0800133static int big_factor = 2;
134static int common_factor = 1;
135
lijuangde34d502016-02-26 16:04:50 +0800136static void wait_for_exit()
lijuang7d235f42015-07-16 20:19:45 +0800137{
138 struct select_msg_info *select_msg;
139 select_msg = &msg_info;
140
lijuang9a7d3b92015-11-30 14:41:24 +0800141 mutex_acquire(&select_msg->msg_lock);
lijuangde34d502016-02-26 16:04:50 +0800142 while(!select_msg->info.rel_exit == true) {
lijuang9a7d3b92015-11-30 14:41:24 +0800143 mutex_release(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800144 thread_sleep(10);
lijuang9a7d3b92015-11-30 14:41:24 +0800145 mutex_acquire(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800146 }
lijuang9a7d3b92015-11-30 14:41:24 +0800147 mutex_release(&select_msg->msg_lock);
148
lijuangde34d502016-02-26 16:04:50 +0800149 is_thread_start = false;
lijuang7d235f42015-07-16 20:19:45 +0800150 fbcon_clear();
151 display_image_on_screen();
152}
153
lijuangde34d502016-02-26 16:04:50 +0800154void wait_for_users_action()
155{
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530156 if (is_display_disabled())
157 return;
lijuangde34d502016-02-26 16:04:50 +0800158 /* Waiting for exit menu keys detection if there is no any usr action
159 * otherwise it will do the action base on the keys detection thread
160 */
161 wait_for_exit();
162}
163
164void exit_menu_keys_detection()
165{
166 struct select_msg_info *select_msg;
167 select_msg = &msg_info;
168
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530169 if (is_display_disabled())
170 return;
171
lijuangde34d502016-02-26 16:04:50 +0800172 mutex_acquire(&select_msg->msg_lock);
173 select_msg->info.is_exit = true;
174 mutex_release(&select_msg->msg_lock);
175
176 wait_for_exit();
177}
178
lijuang7d235f42015-07-16 20:19:45 +0800179static void set_message_factor()
180{
181 uint32_t tmp_factor = 0;
182 uint32_t max_x_count = 40;
183 uint32_t max_x = fbcon_get_max_x();
184
185 max_x = fbcon_get_max_x();
186 tmp_factor = max_x/max_x_count;
187
188 if(tmp_factor <= 1) {
189 big_factor = 2;
190 common_factor = 1;
191 } else {
192 big_factor = tmp_factor*2;
193 common_factor = tmp_factor;
194 }
195}
196
197static void display_fbcon_menu_message(char *str, unsigned type,
198 unsigned scale_factor)
199{
200 while(*str != 0) {
201 fbcon_putc_factor(*str++, type, scale_factor);
202 }
203}
204
205static char *str_align_right(char *str, int factor)
206{
207 uint32_t max_x = 0;
208 int diff = 0;
209 int i = 0;
210 char *str_target = NULL;
211
212 max_x = fbcon_get_max_x();
213 if (!str_target && max_x) {
214 str_target = malloc(max_x);
215 }
216
217 if (str_target) {
218 memset(str_target, 0, max_x);
219 if ( max_x/factor > strlen(str)) {
220 if (factor == 1)
221 diff = max_x/factor - strlen(str) - 1;
222 else
223 diff = max_x/factor - strlen(str);
224 for (i = 0; i < diff; i++) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530225 strlcat(str_target, " ", max_x);
lijuang7d235f42015-07-16 20:19:45 +0800226 }
lijuang7d235f42015-07-16 20:19:45 +0800227 }
lijuangbdb18ea2018-02-06 17:21:18 +0800228 strlcat(str_target, str, max_x);
lijuang7d235f42015-07-16 20:19:45 +0800229 }
lijuangbdb18ea2018-02-06 17:21:18 +0800230 return str_target;
lijuang7d235f42015-07-16 20:19:45 +0800231}
232
lijuangf55ad052018-04-23 18:30:50 +0800233/**
234 Reset device unlock status
235 @param[in] Type The type of the unlock.
236 [DISPLAY_MENU_UNLOCK]: unlock the device
237 [DISPLAY_MENU_UNLOCK_CRITICAL]: critical unlock the device
238 [DISPLAY_MENU_LOCK]: lock the device
239 [DISPLAY_MENU_LOCK_CRITICAL]: critical lock the device
240 **/
241void reset_device_unlock_status (int type)
242{
243 struct recovery_message msg;
244
245 if (type == DISPLAY_MENU_LOCK ||
246 type == DISPLAY_MENU_UNLOCK ||
247 type == DISPLAY_MENU_LOCK_CRITICAL ||
248 type == DISPLAY_MENU_UNLOCK_CRITICAL) {
249 set_device_unlock_value (munlock_info[type].unlock_type,
250 munlock_info[type].unlock_value);
251 memset(&msg, 0, sizeof(msg));
252 snprintf(msg.recovery, sizeof(msg.recovery), "recovery\n--wipe_data");
253 write_misc(0, &msg, sizeof(msg));
254 }
255}
256
lijuang9a7d3b92015-11-30 14:41:24 +0800257/* msg_lock need to be holded when call this function. */
lijuangf55ad052018-04-23 18:30:50 +0800258static void display_unlock_menu_renew(struct select_msg_info *unlock_msg_info,
259 int type, bool status)
lijuang7d235f42015-07-16 20:19:45 +0800260{
261 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800262 memset(&unlock_msg_info->info, 0, sizeof(struct menu_info));
263
lijuangf55ad052018-04-23 18:30:50 +0800264 display_fbcon_menu_message("<!>\n\n",
lijuang7d235f42015-07-16 20:19:45 +0800265 FBCON_UNLOCK_TITLE_MSG, big_factor);
lijuang7d235f42015-07-16 20:19:45 +0800266
lijuangf55ad052018-04-23 18:30:50 +0800267 if (status) {
268 display_fbcon_menu_message((char*)unlock_menu_common_msg,
269 FBCON_COMMON_MSG, common_factor);
270 } else {
271 display_fbcon_menu_message((char*)lock_menu_common_msg,
272 FBCON_COMMON_MSG, common_factor);
273 }
274
lijuang4ece1e72015-08-14 21:02:36 +0800275 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800276 unlock_msg_info->info.option_start[0] = fbcon_get_current_line();
lijuangf55ad052018-04-23 18:30:50 +0800277 display_fbcon_menu_message((char *)munlock_option_msg[status].ignore_msg,
278 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800279 unlock_msg_info->info.option_bg[0] = fbcon_get_current_bg();
lijuang9a7d3b92015-11-30 14:41:24 +0800280 unlock_msg_info->info.option_end[0] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800281 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800282 unlock_msg_info->info.option_start[1] = fbcon_get_current_line();
lijuangf55ad052018-04-23 18:30:50 +0800283 display_fbcon_menu_message((char *)munlock_option_msg[status].comfirm_msg,
284 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800285 unlock_msg_info->info.option_bg[1] = fbcon_get_current_bg();
lijuang9a7d3b92015-11-30 14:41:24 +0800286 unlock_msg_info->info.option_end[1] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800287 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang7d235f42015-07-16 20:19:45 +0800288
lijuangf55ad052018-04-23 18:30:50 +0800289 if (type == UNLOCK) {
lijuang9a7d3b92015-11-30 14:41:24 +0800290 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK;
lijuangf55ad052018-04-23 18:30:50 +0800291 if (!status)
292 unlock_msg_info->info.msg_type = DISPLAY_MENU_LOCK;
293 } else if (type == UNLOCK_CRITICAL) {
lijuang9a7d3b92015-11-30 14:41:24 +0800294 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK_CRITICAL;
lijuangf55ad052018-04-23 18:30:50 +0800295 if (!status)
296 unlock_msg_info->info.msg_type = DISPLAY_MENU_LOCK_CRITICAL;
297 }
lijuang4ece1e72015-08-14 21:02:36 +0800298
lijuang9a7d3b92015-11-30 14:41:24 +0800299 unlock_msg_info->info.option_num = 2;
300
301 /* Initialize the option index */
302 unlock_msg_info->info.option_index= 2;
lijuang7d235f42015-07-16 20:19:45 +0800303}
304
Monika Singh5e170362018-03-14 00:48:36 +0530305#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800306/* msg_lock need to be holded when call this function. */
307void display_bootverify_menu_renew(struct select_msg_info *msg_info, int type)
lijuang7d235f42015-07-16 20:19:45 +0800308{
lijuang7d235f42015-07-16 20:19:45 +0800309 unsigned char* fp_buf = NULL;
310 char fp_str_temp[EVP_MAX_MD_SIZE] = {'\0'};
311 char fp_str[EVP_MAX_MD_SIZE*2] = {'\0'};
312 char str_temp[8];
313
314 char str1[]= "Start >";
315 char str2[] = "Continue boot";
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530316 char *str3 = NULL;
317
lijuang7d235f42015-07-16 20:19:45 +0800318 char *str_target = NULL;
319 uint32 fp_size = 0;
320 unsigned int i = 0;
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530321 uint32_t timeout = DELAY_5SEC;
lijuang7d235f42015-07-16 20:19:45 +0800322
323 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800324 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800325
lijuang7d235f42015-07-16 20:19:45 +0800326 /* Align Right */
327 str_target = str_align_right(str1, big_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800328 if(str_target != NULL) {
Sridhar Parasuram995a3552015-08-22 08:46:10 -0700329 display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, big_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800330 free(str_target);
331 }
lijuang7d235f42015-07-16 20:19:45 +0800332
333 str_target = str_align_right(str2, common_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800334 if(str_target != NULL) {
Sridhar Parasuram995a3552015-08-22 08:46:10 -0700335 display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, common_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800336 free(str_target);
337 }
lijuang7d235f42015-07-16 20:19:45 +0800338
339 display_fbcon_menu_message("\n< More options\n",
340 FBCON_COMMON_MSG, common_factor);
341 display_fbcon_menu_message("press VOLUME keys\n\n",
342 FBCON_SUBTITLE_MSG, common_factor);
lijuang4ece1e72015-08-14 21:02:36 +0800343 if(boot_verify_info[type].warning_msg != NULL)
344 display_fbcon_menu_message((char*)boot_verify_info[type].warning_msg,
345 FBCON_COMMON_MSG, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800346
Brahmaji K0c2d5982017-09-07 18:44:21 +0530347 if(boot_verify_info[type].url_msg != NULL)
348 display_fbcon_menu_message((char*)boot_verify_info[type].url_msg,
349 boot_verify_info[type].msg_type, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800350
lijuang7d235f42015-07-16 20:19:45 +0800351 if (type == DISPLAY_MENU_YELLOW) {
352 fp_buf = get_boot_fingerprint(&fp_size);
353 if (fp_buf != NULL) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530354 strlcpy(fp_str_temp, (char const *)fp_buf, fp_size);
lijuang7d235f42015-07-16 20:19:45 +0800355 for (i = 0; i < fp_size; i++) {
356 if(i == fp_size - 1)
Parth Dixit73d3bd02016-01-07 14:29:41 +0530357 snprintf(str_temp, sizeof(str_temp), "%02x", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800358 else
Parth Dixit73d3bd02016-01-07 14:29:41 +0530359 snprintf(str_temp, sizeof(str_temp), "%02x-", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800360
Parth Dixit73d3bd02016-01-07 14:29:41 +0530361 strlcat(fp_str, str_temp, sizeof(fp_str));
lijuang7d235f42015-07-16 20:19:45 +0800362 }
363 }
364 display_fbcon_menu_message("ID:", FBCON_COMMON_MSG, common_factor);
365 display_fbcon_menu_message(fp_str, FBCON_COMMON_MSG, common_factor);
366 }
lijuang7d235f42015-07-16 20:19:45 +0800367
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530368 str3 = "\n\nIf no key pressed:\n"\
369 "Your device will boot in 5 seconds\n\n";
370#if ENABLE_VB_ATTEST
371 if(type == DISPLAY_MENU_EIO)
372 {
373 str3 ="\n\nIf power key is not pressed:\n"\
374 "Your device will poweroff in 30 seconds\n\n";
375 timeout = DELAY_30SEC;
376 }
377#endif
378 display_fbcon_menu_message(str3, FBCON_COMMON_MSG, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800379
lijuang9a7d3b92015-11-30 14:41:24 +0800380 msg_info->info.msg_type = type;
lijuang9a7d3b92015-11-30 14:41:24 +0800381
382 /* Initialize the time out time */
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530383 msg_info->info.timeout_time = timeout; //5s
lijuang7d235f42015-07-16 20:19:45 +0800384}
lijuang4ece1e72015-08-14 21:02:36 +0800385#endif
lijuang7d235f42015-07-16 20:19:45 +0800386
lijuang9a7d3b92015-11-30 14:41:24 +0800387/* msg_lock need to be holded when call this function. */
388void display_bootverify_option_menu_renew(struct select_msg_info *msg_info)
lijuang7d235f42015-07-16 20:19:45 +0800389{
390 int i = 0;
lijuang4ece1e72015-08-14 21:02:36 +0800391 int len = 0;
lijuang9a7d3b92015-11-30 14:41:24 +0800392
lijuang7d235f42015-07-16 20:19:45 +0800393 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800394 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800395
lijuang4ece1e72015-08-14 21:02:36 +0800396 len = ARRAY_SIZE(verify_option_menu);
lijuang7d235f42015-07-16 20:19:45 +0800397 display_fbcon_menu_message("Options menu:\n\n",
398 FBCON_COMMON_MSG, big_factor);
399 display_fbcon_menu_message("Press volume key to select, and "\
400 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor);
401
lijuang4ece1e72015-08-14 21:02:36 +0800402 for (i = 0; i < len; i++) {
403 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800404 msg_info->info.option_start[i] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800405 display_fbcon_menu_message(verify_option_menu[i],
lijuang7d235f42015-07-16 20:19:45 +0800406 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800407 msg_info->info.option_bg[i]= fbcon_get_current_bg();
408 msg_info->info.option_end[i]= fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800409 }
410
lijuang4ece1e72015-08-14 21:02:36 +0800411 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800412 msg_info->info.msg_type = DISPLAY_MENU_MORE_OPTION;
413 msg_info->info.option_num = len;
414
415 /* Initialize the option index */
416 msg_info->info.option_index= len;
lijuang4ece1e72015-08-14 21:02:36 +0800417}
418
lijuang9a7d3b92015-11-30 14:41:24 +0800419/* msg_lock need to be holded when call this function. */
420void display_fastboot_menu_renew(struct select_msg_info *fastboot_msg_info)
lijuang4ece1e72015-08-14 21:02:36 +0800421{
422 int len;
423 int msg_type = FBCON_COMMON_MSG;
424 char msg_buf[64];
425 char msg[128];
426
lijuang9a7d3b92015-11-30 14:41:24 +0800427 /* The fastboot menu is switched base on the option index
428 * So it's need to store the index for the menu switching
429 */
430 uint32_t option_index = fastboot_msg_info->info.option_index;
431
lijuang4ece1e72015-08-14 21:02:36 +0800432 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800433 memset(&fastboot_msg_info->info, 0, sizeof(struct menu_info));
lijuang4ece1e72015-08-14 21:02:36 +0800434
435 len = ARRAY_SIZE(fastboot_option_menu);
436 switch(option_index) {
437 case 0:
438 msg_type = FBCON_GREEN_MSG;
439 break;
440 case 1:
441 case 2:
442 msg_type = FBCON_RED_MSG;
443 break;
444 case 3:
lijuang42aefaa2016-04-14 15:55:17 +0800445 case 4:
lijuang4ece1e72015-08-14 21:02:36 +0800446 msg_type = FBCON_COMMON_MSG;
447 break;
448 }
449 fbcon_draw_line(msg_type);
450 display_fbcon_menu_message(fastboot_option_menu[option_index],
451 msg_type, big_factor);
452 fbcon_draw_line(msg_type);
453 display_fbcon_menu_message("\n\nPress volume key to select, and "\
454 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor);
455
456 display_fbcon_menu_message("FASTBOOT MODE\n", FBCON_RED_MSG, common_factor);
457
458 get_product_name((unsigned char *) msg_buf);
459 snprintf(msg, sizeof(msg), "PRODUCT_NAME - %s\n", msg_buf);
460 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
461
462 memset(msg_buf, 0, sizeof(msg_buf));
463 smem_get_hw_platform_name((unsigned char *) msg_buf, sizeof(msg_buf));
464 snprintf(msg, sizeof(msg), "VARIANT - %s %s\n",
465 msg_buf, target_is_emmc_boot()? "eMMC":"UFS");
466 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
467
468 memset(msg_buf, 0, sizeof(msg_buf));
469 get_bootloader_version((unsigned char *) msg_buf);
470 snprintf(msg, sizeof(msg), "BOOTLOADER VERSION - %s\n",
471 msg_buf);
472 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
473
474 memset(msg_buf, 0, sizeof(msg_buf));
475 get_baseband_version((unsigned char *) msg_buf);
476 snprintf(msg, sizeof(msg), "BASEBAND VERSION - %s\n",
477 msg_buf);
478 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
479
480 memset(msg_buf, 0, sizeof(msg_buf));
481 target_serialno((unsigned char *) msg_buf);
482 snprintf(msg, sizeof(msg), "SERIAL NUMBER - %s\n", msg_buf);
483 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
484
485 snprintf(msg, sizeof(msg), "SECURE BOOT - %s\n",
486 is_secure_boot_enable()? "enabled":"disabled");
487 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
488
489 snprintf(msg, sizeof(msg), "DEVICE STATE - %s\n",
490 is_device_locked()? "locked":"unlocked");
491 display_fbcon_menu_message(msg, FBCON_RED_MSG, common_factor);
492
lijuang9a7d3b92015-11-30 14:41:24 +0800493 fastboot_msg_info->info.msg_type = DISPLAY_MENU_FASTBOOT;
494 fastboot_msg_info->info.option_num = len;
495 fastboot_msg_info->info.option_index = option_index;
496}
497
498void msg_lock_init()
499{
500 static bool is_msg_lock_init = false;
501 struct select_msg_info *msg_lock_info;
502 msg_lock_info = &msg_info;
503
504 if (!is_msg_lock_init) {
505 mutex_init(&msg_lock_info->msg_lock);
506 is_msg_lock_init = true;
507 }
lijuang7d235f42015-07-16 20:19:45 +0800508}
509
510static void display_menu_thread_start(struct select_msg_info *msg_info)
511{
512 thread_t *thr;
513
514 if (!is_thread_start) {
515 thr = thread_create("selectkeydetect", &select_msg_keys_detect,
516 (void*)msg_info, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
517 if (!thr) {
518 dprintf(CRITICAL, "ERROR: creat device status detect thread failed!!\n");
519 return;
520 }
521 thread_resume(thr);
lijuang9a7d3b92015-11-30 14:41:24 +0800522 is_thread_start = true;
lijuang7d235f42015-07-16 20:19:45 +0800523 }
lijuang7d235f42015-07-16 20:19:45 +0800524}
525
lijuang9a7d3b92015-11-30 14:41:24 +0800526/* The fuction be called after device in fastboot mode,
527 * so it's no need to initialize the msg_lock again
528 */
lijuangf55ad052018-04-23 18:30:50 +0800529void display_unlock_menu(int type, bool status)
lijuang7d235f42015-07-16 20:19:45 +0800530{
lijuang4ece1e72015-08-14 21:02:36 +0800531 struct select_msg_info *unlock_menu_msg_info;
532 unlock_menu_msg_info = &msg_info;
lijuang7d235f42015-07-16 20:19:45 +0800533
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530534 if (is_display_disabled())
535 return;
536
lijuang7d235f42015-07-16 20:19:45 +0800537 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800538
539 msg_lock_init();
540 mutex_acquire(&unlock_menu_msg_info->msg_lock);
541
542 /* Initialize the last_msg_type */
543 unlock_menu_msg_info->last_msg_type =
544 unlock_menu_msg_info->info.msg_type;
545
lijuangf55ad052018-04-23 18:30:50 +0800546 display_unlock_menu_renew(unlock_menu_msg_info, type, status);
lijuang9a7d3b92015-11-30 14:41:24 +0800547 mutex_release(&unlock_menu_msg_info->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800548
lijuangf55ad052018-04-23 18:30:50 +0800549 dprintf(INFO, "creating %s keys detect thread\n",
550 status ? "unlock":"lock");
lijuang4ece1e72015-08-14 21:02:36 +0800551 display_menu_thread_start(unlock_menu_msg_info);
lijuang7d235f42015-07-16 20:19:45 +0800552}
553
lijuang9a7d3b92015-11-30 14:41:24 +0800554void display_fastboot_menu()
lijuang4ece1e72015-08-14 21:02:36 +0800555{
556 struct select_msg_info *fastboot_menu_msg_info;
557 fastboot_menu_msg_info = &msg_info;
558
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530559 if (is_display_disabled())
560 return;
561
lijuang4ece1e72015-08-14 21:02:36 +0800562 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800563
564 msg_lock_init();
565 mutex_acquire(&fastboot_menu_msg_info->msg_lock);
566
567 /* There are 4 pages for fastboot menu:
568 * Page: Start/Fastboot/Recovery/Poweroff
569 * The menu is switched base on the option index
570 * Initialize the option index and last_msg_type
571 */
572 fastboot_menu_msg_info->info.option_index = 0;
573 fastboot_menu_msg_info->last_msg_type =
574 fastboot_menu_msg_info->info.msg_type;
575
576 display_fastboot_menu_renew(fastboot_menu_msg_info);
577 mutex_release(&fastboot_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800578
579 dprintf(INFO, "creating fastboot menu keys detect thread\n");
580 display_menu_thread_start(fastboot_menu_msg_info);
581}
582
Monika Singh5e170362018-03-14 00:48:36 +0530583#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800584void display_bootverify_menu(int type)
lijuang4ece1e72015-08-14 21:02:36 +0800585{
586 struct select_msg_info *bootverify_menu_msg_info;
587 bootverify_menu_msg_info = &msg_info;
588
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530589 if (is_display_disabled())
590 return;
591
lijuang4ece1e72015-08-14 21:02:36 +0800592 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800593
594 msg_lock_init();
595 mutex_acquire(&bootverify_menu_msg_info->msg_lock);
596
597 /* Initialize the last_msg_type */
598 bootverify_menu_msg_info->last_msg_type =
599 bootverify_menu_msg_info->info.msg_type;
600
601 display_bootverify_menu_renew(bootverify_menu_msg_info, type);
602 mutex_release(&bootverify_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800603
604 dprintf(INFO, "creating boot verify keys detect thread\n");
605 display_menu_thread_start(bootverify_menu_msg_info);
606}
607#endif