blob: 5f4582fd09e87cfb3d780ee5332c1194daf7ccb2 [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;
lijuang9e73e5a2018-04-23 17:00:16 +0800182 uint32_t max_x_count = 0;
183 uint32_t max_x = 0;
184
185 if (fbcon_get_width() < fbcon_get_height())
186 max_x_count = CHAR_NUM_PERROW_POR;
187 else
188 max_x_count = CHAR_NUM_PERROW_HOR;
lijuang7d235f42015-07-16 20:19:45 +0800189
190 max_x = fbcon_get_max_x();
191 tmp_factor = max_x/max_x_count;
192
193 if(tmp_factor <= 1) {
194 big_factor = 2;
195 common_factor = 1;
196 } else {
197 big_factor = tmp_factor*2;
198 common_factor = tmp_factor;
199 }
200}
201
202static void display_fbcon_menu_message(char *str, unsigned type,
203 unsigned scale_factor)
204{
205 while(*str != 0) {
206 fbcon_putc_factor(*str++, type, scale_factor);
207 }
208}
209
210static char *str_align_right(char *str, int factor)
211{
212 uint32_t max_x = 0;
213 int diff = 0;
214 int i = 0;
215 char *str_target = NULL;
216
217 max_x = fbcon_get_max_x();
218 if (!str_target && max_x) {
219 str_target = malloc(max_x);
220 }
221
222 if (str_target) {
223 memset(str_target, 0, max_x);
224 if ( max_x/factor > strlen(str)) {
225 if (factor == 1)
226 diff = max_x/factor - strlen(str) - 1;
227 else
228 diff = max_x/factor - strlen(str);
229 for (i = 0; i < diff; i++) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530230 strlcat(str_target, " ", max_x);
lijuang7d235f42015-07-16 20:19:45 +0800231 }
lijuang7d235f42015-07-16 20:19:45 +0800232 }
lijuangbdb18ea2018-02-06 17:21:18 +0800233 strlcat(str_target, str, max_x);
lijuang7d235f42015-07-16 20:19:45 +0800234 }
lijuangbdb18ea2018-02-06 17:21:18 +0800235 return str_target;
lijuang7d235f42015-07-16 20:19:45 +0800236}
237
lijuangf55ad052018-04-23 18:30:50 +0800238/**
239 Reset device unlock status
240 @param[in] Type The type of the unlock.
241 [DISPLAY_MENU_UNLOCK]: unlock the device
242 [DISPLAY_MENU_UNLOCK_CRITICAL]: critical unlock the device
243 [DISPLAY_MENU_LOCK]: lock the device
244 [DISPLAY_MENU_LOCK_CRITICAL]: critical lock the device
245 **/
246void reset_device_unlock_status (int type)
247{
248 struct recovery_message msg;
249
250 if (type == DISPLAY_MENU_LOCK ||
251 type == DISPLAY_MENU_UNLOCK ||
252 type == DISPLAY_MENU_LOCK_CRITICAL ||
253 type == DISPLAY_MENU_UNLOCK_CRITICAL) {
254 set_device_unlock_value (munlock_info[type].unlock_type,
255 munlock_info[type].unlock_value);
256 memset(&msg, 0, sizeof(msg));
257 snprintf(msg.recovery, sizeof(msg.recovery), "recovery\n--wipe_data");
258 write_misc(0, &msg, sizeof(msg));
259 }
260}
261
lijuang9a7d3b92015-11-30 14:41:24 +0800262/* msg_lock need to be holded when call this function. */
lijuangf55ad052018-04-23 18:30:50 +0800263static void display_unlock_menu_renew(struct select_msg_info *unlock_msg_info,
264 int type, bool status)
lijuang7d235f42015-07-16 20:19:45 +0800265{
266 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800267 memset(&unlock_msg_info->info, 0, sizeof(struct menu_info));
268
lijuangf55ad052018-04-23 18:30:50 +0800269 display_fbcon_menu_message("<!>\n\n",
lijuang7d235f42015-07-16 20:19:45 +0800270 FBCON_UNLOCK_TITLE_MSG, big_factor);
lijuang7d235f42015-07-16 20:19:45 +0800271
lijuangf55ad052018-04-23 18:30:50 +0800272 if (status) {
273 display_fbcon_menu_message((char*)unlock_menu_common_msg,
274 FBCON_COMMON_MSG, common_factor);
275 } else {
276 display_fbcon_menu_message((char*)lock_menu_common_msg,
277 FBCON_COMMON_MSG, common_factor);
278 }
279
lijuang4ece1e72015-08-14 21:02:36 +0800280 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800281 unlock_msg_info->info.option_start[0] = fbcon_get_current_line();
lijuangf55ad052018-04-23 18:30:50 +0800282 display_fbcon_menu_message((char *)munlock_option_msg[status].ignore_msg,
283 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800284 unlock_msg_info->info.option_bg[0] = fbcon_get_current_bg();
lijuang9a7d3b92015-11-30 14:41:24 +0800285 unlock_msg_info->info.option_end[0] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800286 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800287 unlock_msg_info->info.option_start[1] = fbcon_get_current_line();
lijuangf55ad052018-04-23 18:30:50 +0800288 display_fbcon_menu_message((char *)munlock_option_msg[status].comfirm_msg,
289 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800290 unlock_msg_info->info.option_bg[1] = fbcon_get_current_bg();
lijuang9a7d3b92015-11-30 14:41:24 +0800291 unlock_msg_info->info.option_end[1] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800292 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang7d235f42015-07-16 20:19:45 +0800293
lijuangf55ad052018-04-23 18:30:50 +0800294 if (type == UNLOCK) {
lijuang9a7d3b92015-11-30 14:41:24 +0800295 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK;
lijuangf55ad052018-04-23 18:30:50 +0800296 if (!status)
297 unlock_msg_info->info.msg_type = DISPLAY_MENU_LOCK;
298 } else if (type == UNLOCK_CRITICAL) {
lijuang9a7d3b92015-11-30 14:41:24 +0800299 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK_CRITICAL;
lijuangf55ad052018-04-23 18:30:50 +0800300 if (!status)
301 unlock_msg_info->info.msg_type = DISPLAY_MENU_LOCK_CRITICAL;
302 }
lijuang4ece1e72015-08-14 21:02:36 +0800303
lijuang9a7d3b92015-11-30 14:41:24 +0800304 unlock_msg_info->info.option_num = 2;
305
306 /* Initialize the option index */
307 unlock_msg_info->info.option_index= 2;
lijuang7d235f42015-07-16 20:19:45 +0800308}
309
Monika Singh5e170362018-03-14 00:48:36 +0530310#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800311/* msg_lock need to be holded when call this function. */
312void display_bootverify_menu_renew(struct select_msg_info *msg_info, int type)
lijuang7d235f42015-07-16 20:19:45 +0800313{
lijuang7d235f42015-07-16 20:19:45 +0800314 unsigned char* fp_buf = NULL;
315 char fp_str_temp[EVP_MAX_MD_SIZE] = {'\0'};
316 char fp_str[EVP_MAX_MD_SIZE*2] = {'\0'};
317 char str_temp[8];
318
319 char str1[]= "Start >";
320 char str2[] = "Continue boot";
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530321 char *str3 = NULL;
322
lijuang7d235f42015-07-16 20:19:45 +0800323 char *str_target = NULL;
324 uint32 fp_size = 0;
325 unsigned int i = 0;
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530326 uint32_t timeout = DELAY_5SEC;
lijuang7d235f42015-07-16 20:19:45 +0800327
328 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800329 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800330
lijuang7d235f42015-07-16 20:19:45 +0800331 /* Align Right */
332 str_target = str_align_right(str1, big_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800333 if(str_target != NULL) {
Sridhar Parasuram995a3552015-08-22 08:46:10 -0700334 display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, big_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800335 free(str_target);
336 }
lijuang7d235f42015-07-16 20:19:45 +0800337
338 str_target = str_align_right(str2, common_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800339 if(str_target != NULL) {
Sridhar Parasuram995a3552015-08-22 08:46:10 -0700340 display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, common_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800341 free(str_target);
342 }
lijuang7d235f42015-07-16 20:19:45 +0800343
344 display_fbcon_menu_message("\n< More options\n",
345 FBCON_COMMON_MSG, common_factor);
346 display_fbcon_menu_message("press VOLUME keys\n\n",
347 FBCON_SUBTITLE_MSG, common_factor);
lijuang4ece1e72015-08-14 21:02:36 +0800348 if(boot_verify_info[type].warning_msg != NULL)
349 display_fbcon_menu_message((char*)boot_verify_info[type].warning_msg,
350 FBCON_COMMON_MSG, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800351
Brahmaji K0c2d5982017-09-07 18:44:21 +0530352 if(boot_verify_info[type].url_msg != NULL)
353 display_fbcon_menu_message((char*)boot_verify_info[type].url_msg,
354 boot_verify_info[type].msg_type, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800355
lijuang7d235f42015-07-16 20:19:45 +0800356 if (type == DISPLAY_MENU_YELLOW) {
357 fp_buf = get_boot_fingerprint(&fp_size);
358 if (fp_buf != NULL) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530359 strlcpy(fp_str_temp, (char const *)fp_buf, fp_size);
lijuang7d235f42015-07-16 20:19:45 +0800360 for (i = 0; i < fp_size; i++) {
361 if(i == fp_size - 1)
Parth Dixit73d3bd02016-01-07 14:29:41 +0530362 snprintf(str_temp, sizeof(str_temp), "%02x", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800363 else
Parth Dixit73d3bd02016-01-07 14:29:41 +0530364 snprintf(str_temp, sizeof(str_temp), "%02x-", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800365
Parth Dixit73d3bd02016-01-07 14:29:41 +0530366 strlcat(fp_str, str_temp, sizeof(fp_str));
lijuang7d235f42015-07-16 20:19:45 +0800367 }
368 }
369 display_fbcon_menu_message("ID:", FBCON_COMMON_MSG, common_factor);
370 display_fbcon_menu_message(fp_str, FBCON_COMMON_MSG, common_factor);
371 }
lijuang7d235f42015-07-16 20:19:45 +0800372
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530373 str3 = "\n\nIf no key pressed:\n"\
374 "Your device will boot in 5 seconds\n\n";
375#if ENABLE_VB_ATTEST
376 if(type == DISPLAY_MENU_EIO)
377 {
378 str3 ="\n\nIf power key is not pressed:\n"\
379 "Your device will poweroff in 30 seconds\n\n";
380 timeout = DELAY_30SEC;
381 }
382#endif
383 display_fbcon_menu_message(str3, FBCON_COMMON_MSG, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800384
lijuang9a7d3b92015-11-30 14:41:24 +0800385 msg_info->info.msg_type = type;
lijuang9a7d3b92015-11-30 14:41:24 +0800386
387 /* Initialize the time out time */
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530388 msg_info->info.timeout_time = timeout; //5s
lijuang7d235f42015-07-16 20:19:45 +0800389}
lijuang4ece1e72015-08-14 21:02:36 +0800390#endif
lijuang7d235f42015-07-16 20:19:45 +0800391
lijuang9a7d3b92015-11-30 14:41:24 +0800392/* msg_lock need to be holded when call this function. */
393void display_bootverify_option_menu_renew(struct select_msg_info *msg_info)
lijuang7d235f42015-07-16 20:19:45 +0800394{
395 int i = 0;
lijuang4ece1e72015-08-14 21:02:36 +0800396 int len = 0;
lijuang9a7d3b92015-11-30 14:41:24 +0800397
lijuang7d235f42015-07-16 20:19:45 +0800398 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800399 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800400
lijuang4ece1e72015-08-14 21:02:36 +0800401 len = ARRAY_SIZE(verify_option_menu);
lijuang7d235f42015-07-16 20:19:45 +0800402 display_fbcon_menu_message("Options menu:\n\n",
403 FBCON_COMMON_MSG, big_factor);
404 display_fbcon_menu_message("Press volume key to select, and "\
405 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor);
406
lijuang4ece1e72015-08-14 21:02:36 +0800407 for (i = 0; i < len; i++) {
408 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800409 msg_info->info.option_start[i] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800410 display_fbcon_menu_message(verify_option_menu[i],
lijuang7d235f42015-07-16 20:19:45 +0800411 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800412 msg_info->info.option_bg[i]= fbcon_get_current_bg();
413 msg_info->info.option_end[i]= fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800414 }
415
lijuang4ece1e72015-08-14 21:02:36 +0800416 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800417 msg_info->info.msg_type = DISPLAY_MENU_MORE_OPTION;
418 msg_info->info.option_num = len;
419
420 /* Initialize the option index */
421 msg_info->info.option_index= len;
lijuang4ece1e72015-08-14 21:02:36 +0800422}
423
lijuang9a7d3b92015-11-30 14:41:24 +0800424/* msg_lock need to be holded when call this function. */
425void display_fastboot_menu_renew(struct select_msg_info *fastboot_msg_info)
lijuang4ece1e72015-08-14 21:02:36 +0800426{
427 int len;
428 int msg_type = FBCON_COMMON_MSG;
429 char msg_buf[64];
430 char msg[128];
431
lijuang9a7d3b92015-11-30 14:41:24 +0800432 /* The fastboot menu is switched base on the option index
433 * So it's need to store the index for the menu switching
434 */
435 uint32_t option_index = fastboot_msg_info->info.option_index;
436
lijuang4ece1e72015-08-14 21:02:36 +0800437 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800438 memset(&fastboot_msg_info->info, 0, sizeof(struct menu_info));
lijuang4ece1e72015-08-14 21:02:36 +0800439
440 len = ARRAY_SIZE(fastboot_option_menu);
441 switch(option_index) {
442 case 0:
443 msg_type = FBCON_GREEN_MSG;
444 break;
445 case 1:
446 case 2:
447 msg_type = FBCON_RED_MSG;
448 break;
449 case 3:
lijuang42aefaa2016-04-14 15:55:17 +0800450 case 4:
lijuang4ece1e72015-08-14 21:02:36 +0800451 msg_type = FBCON_COMMON_MSG;
452 break;
453 }
454 fbcon_draw_line(msg_type);
455 display_fbcon_menu_message(fastboot_option_menu[option_index],
456 msg_type, big_factor);
457 fbcon_draw_line(msg_type);
458 display_fbcon_menu_message("\n\nPress volume key to select, and "\
459 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor);
460
461 display_fbcon_menu_message("FASTBOOT MODE\n", FBCON_RED_MSG, common_factor);
462
463 get_product_name((unsigned char *) msg_buf);
464 snprintf(msg, sizeof(msg), "PRODUCT_NAME - %s\n", msg_buf);
465 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
466
467 memset(msg_buf, 0, sizeof(msg_buf));
468 smem_get_hw_platform_name((unsigned char *) msg_buf, sizeof(msg_buf));
469 snprintf(msg, sizeof(msg), "VARIANT - %s %s\n",
470 msg_buf, target_is_emmc_boot()? "eMMC":"UFS");
471 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
472
473 memset(msg_buf, 0, sizeof(msg_buf));
474 get_bootloader_version((unsigned char *) msg_buf);
475 snprintf(msg, sizeof(msg), "BOOTLOADER VERSION - %s\n",
476 msg_buf);
477 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
478
479 memset(msg_buf, 0, sizeof(msg_buf));
480 get_baseband_version((unsigned char *) msg_buf);
481 snprintf(msg, sizeof(msg), "BASEBAND VERSION - %s\n",
482 msg_buf);
483 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
484
485 memset(msg_buf, 0, sizeof(msg_buf));
486 target_serialno((unsigned char *) msg_buf);
487 snprintf(msg, sizeof(msg), "SERIAL NUMBER - %s\n", msg_buf);
488 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
489
490 snprintf(msg, sizeof(msg), "SECURE BOOT - %s\n",
491 is_secure_boot_enable()? "enabled":"disabled");
492 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
493
494 snprintf(msg, sizeof(msg), "DEVICE STATE - %s\n",
495 is_device_locked()? "locked":"unlocked");
496 display_fbcon_menu_message(msg, FBCON_RED_MSG, common_factor);
497
lijuang9a7d3b92015-11-30 14:41:24 +0800498 fastboot_msg_info->info.msg_type = DISPLAY_MENU_FASTBOOT;
499 fastboot_msg_info->info.option_num = len;
500 fastboot_msg_info->info.option_index = option_index;
501}
502
503void msg_lock_init()
504{
505 static bool is_msg_lock_init = false;
506 struct select_msg_info *msg_lock_info;
507 msg_lock_info = &msg_info;
508
509 if (!is_msg_lock_init) {
510 mutex_init(&msg_lock_info->msg_lock);
511 is_msg_lock_init = true;
512 }
lijuang7d235f42015-07-16 20:19:45 +0800513}
514
515static void display_menu_thread_start(struct select_msg_info *msg_info)
516{
517 thread_t *thr;
518
519 if (!is_thread_start) {
520 thr = thread_create("selectkeydetect", &select_msg_keys_detect,
521 (void*)msg_info, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
522 if (!thr) {
523 dprintf(CRITICAL, "ERROR: creat device status detect thread failed!!\n");
524 return;
525 }
526 thread_resume(thr);
lijuang9a7d3b92015-11-30 14:41:24 +0800527 is_thread_start = true;
lijuang7d235f42015-07-16 20:19:45 +0800528 }
lijuang7d235f42015-07-16 20:19:45 +0800529}
530
lijuang9a7d3b92015-11-30 14:41:24 +0800531/* The fuction be called after device in fastboot mode,
532 * so it's no need to initialize the msg_lock again
533 */
lijuangf55ad052018-04-23 18:30:50 +0800534void display_unlock_menu(int type, bool status)
lijuang7d235f42015-07-16 20:19:45 +0800535{
lijuang4ece1e72015-08-14 21:02:36 +0800536 struct select_msg_info *unlock_menu_msg_info;
537 unlock_menu_msg_info = &msg_info;
lijuang7d235f42015-07-16 20:19:45 +0800538
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530539 if (is_display_disabled())
540 return;
541
lijuang7d235f42015-07-16 20:19:45 +0800542 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800543
544 msg_lock_init();
545 mutex_acquire(&unlock_menu_msg_info->msg_lock);
546
547 /* Initialize the last_msg_type */
548 unlock_menu_msg_info->last_msg_type =
549 unlock_menu_msg_info->info.msg_type;
550
lijuangf55ad052018-04-23 18:30:50 +0800551 display_unlock_menu_renew(unlock_menu_msg_info, type, status);
lijuang9a7d3b92015-11-30 14:41:24 +0800552 mutex_release(&unlock_menu_msg_info->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800553
lijuangf55ad052018-04-23 18:30:50 +0800554 dprintf(INFO, "creating %s keys detect thread\n",
555 status ? "unlock":"lock");
lijuang4ece1e72015-08-14 21:02:36 +0800556 display_menu_thread_start(unlock_menu_msg_info);
lijuang7d235f42015-07-16 20:19:45 +0800557}
558
lijuang9a7d3b92015-11-30 14:41:24 +0800559void display_fastboot_menu()
lijuang4ece1e72015-08-14 21:02:36 +0800560{
561 struct select_msg_info *fastboot_menu_msg_info;
562 fastboot_menu_msg_info = &msg_info;
563
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530564 if (is_display_disabled())
565 return;
566
lijuang4ece1e72015-08-14 21:02:36 +0800567 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800568
569 msg_lock_init();
570 mutex_acquire(&fastboot_menu_msg_info->msg_lock);
571
572 /* There are 4 pages for fastboot menu:
573 * Page: Start/Fastboot/Recovery/Poweroff
574 * The menu is switched base on the option index
575 * Initialize the option index and last_msg_type
576 */
577 fastboot_menu_msg_info->info.option_index = 0;
578 fastboot_menu_msg_info->last_msg_type =
579 fastboot_menu_msg_info->info.msg_type;
580
581 display_fastboot_menu_renew(fastboot_menu_msg_info);
582 mutex_release(&fastboot_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800583
584 dprintf(INFO, "creating fastboot menu keys detect thread\n");
585 display_menu_thread_start(fastboot_menu_msg_info);
586}
587
Monika Singh5e170362018-03-14 00:48:36 +0530588#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800589void display_bootverify_menu(int type)
lijuang4ece1e72015-08-14 21:02:36 +0800590{
591 struct select_msg_info *bootverify_menu_msg_info;
592 bootverify_menu_msg_info = &msg_info;
593
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530594 if (is_display_disabled())
595 return;
596
lijuang4ece1e72015-08-14 21:02:36 +0800597 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800598
599 msg_lock_init();
600 mutex_acquire(&bootverify_menu_msg_info->msg_lock);
601
602 /* Initialize the last_msg_type */
603 bootverify_menu_msg_info->last_msg_type =
604 bootverify_menu_msg_info->info.msg_type;
605
606 display_bootverify_menu_renew(bootverify_menu_msg_info, type);
607 mutex_release(&bootverify_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800608
609 dprintf(INFO, "creating boot verify keys detect thread\n");
610 display_menu_thread_start(bootverify_menu_msg_info);
611}
612#endif