blob: 17a5a410d88dfd4887827a3a972dd6ee32b1e854 [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
Monika Singh05fff3b2019-09-16 16:00:33 +053046#define TITLE_MSG "<!>\n\n"
47
jialongjhanb2dda0b2020-04-21 20:20:51 +080048//[Arima][8901][JialongJhan] Command mode update screen 20190516 Start
49extern int msm_display_flush();
50//[Arima][8901][JialongJhan] Command mode update screen 20190516 End
lijuangf55ad052018-04-23 18:30:50 +080051static const char *unlock_menu_common_msg = "By unlocking the bootloader, you will be able to install "\
52 "custom operating system on this phone. "\
53 "A custom OS is not subject to the same level of testing "\
54 "as the original OS, and can cause your phone "\
55 "and installed applications to stop working properly.\n\n"\
56 "Software integrity cannot be guaranteed with a custom OS, "\
57 "so any data stored on the phone while the bootloader "\
58 "is unlocked may be at risk.\n\n"\
lijuang7d235f42015-07-16 20:19:45 +080059 "To prevent unauthorized access to your personal data, "\
60 "unlocking the bootloader will also delete all personal "\
lijuangf55ad052018-04-23 18:30:50 +080061 "data on your phone.\n\n"\
62 "Press the Volume keys to select whether to unlock the bootloader, "\
63 "then the Power Button to continue.\n\n";
64
65static const char *lock_menu_common_msg = "If you lock the bootloader, "\
66 "you will not be able to install "\
67 "custom operating system on this phone.\n\n"\
68 "To prevent unauthorized access to your personal data, "\
69 "locking the bootloader will also delete all personal "\
70 "data on your phone.\n\n"\
71 "Press the Volume keys to select whether to "\
72 "lock the bootloader, then the power button to continue.\n\n";
lijuang7d235f42015-07-16 20:19:45 +080073
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070074#define YELLOW_WARNING_MSG "Your device has loaded a different operating system\n\n "\
Brahmaji K0c2d5982017-09-07 18:44:21 +053075 "Visit this link on another device:\n"
lijuang7d235f42015-07-16 20:19:45 +080076
Monika Singh05fff3b2019-09-16 16:00:33 +053077#define ORANGE_WARNING_MSG "The boot loader is unlocked and software integrity cannot "\
78 "be guaranteed. Any data stored on the device may be available to attackers. "\
79 "Do not store any sensitive data on the device.\n\n"\
Brahmaji K0c2d5982017-09-07 18:44:21 +053080 "Visit this link on another device:\n"
lijuang7d235f42015-07-16 20:19:45 +080081
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070082#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 +053083 "Visit this link on another device:\n"
lijuang7d235f42015-07-16 20:19:45 +080084
lijuangbdd9bb42016-03-01 18:22:17 +080085#define LOGGING_WARNING_MSG "The dm-verity is not started in enforcing mode and may "\
86 "not work properly\n\nTo learn more, visit:\n"
87
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070088#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 +053089 "Visit this link on another device:\n"
90
Monika Singh05fff3b2019-09-16 16:00:33 +053091#define PAUSE_BOOT_MSG "PRESS POWER KEY TO PAUSE BOOT\n\n"
92
93#define CONTINUE_BOOT_MSG "PRESS POWER KEY TO CONTINUE\n\n"
94
95#define URL_MSG "g.co/ABH\n\n"
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070096
Parth Dixit54ac3bb2017-03-07 15:52:48 +053097#define DELAY_5SEC 5000
Monika Singh05fff3b2019-09-16 16:00:33 +053098#define DELAY_10SEC 10000
Parth Dixit54ac3bb2017-03-07 15:52:48 +053099#define DELAY_30SEC 30000
100
lijuang7d235f42015-07-16 20:19:45 +0800101static bool is_thread_start = false;
lijuang9a7d3b92015-11-30 14:41:24 +0800102static struct select_msg_info msg_info;
lijuang7d235f42015-07-16 20:19:45 +0800103
Monika Singh5e170362018-03-14 00:48:36 +0530104#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang4ece1e72015-08-14 21:02:36 +0800105struct boot_verify_info {
106 int msg_type;
Monika Singh05fff3b2019-09-16 16:00:33 +0530107 const char *title_msg;
lijuang4ece1e72015-08-14 21:02:36 +0800108 const char *warning_msg;
Brahmaji K0c2d5982017-09-07 18:44:21 +0530109 const char *url_msg;
Monika Singh05fff3b2019-09-16 16:00:33 +0530110 const char *notice_msg;
lijuang4ece1e72015-08-14 21:02:36 +0800111};
112
113struct boot_verify_info boot_verify_info[] = {
Monika Singh05fff3b2019-09-16 16:00:33 +0530114 [DISPLAY_MENU_RED] = {FBCON_RED_MSG, TITLE_MSG, RED_WARNING_MSG, URL_MSG, NULL},
115 [DISPLAY_MENU_YELLOW] = {FBCON_YELLOW_MSG, TITLE_MSG, YELLOW_WARNING_MSG, URL_MSG, PAUSE_BOOT_MSG},
116 [DISPLAY_MENU_ORANGE] = {FBCON_ORANGE_MSG, TITLE_MSG, ORANGE_WARNING_MSG, URL_MSG, PAUSE_BOOT_MSG},
117 [DISPLAY_MENU_LOGGING] = {FBCON_RED_MSG, TITLE_MSG, LOGGING_WARNING_MSG, NULL, NULL},
118 [DISPLAY_MENU_EIO] = {FBCON_RED_MSG, TITLE_MSG, EIO_WARNING_MSG, URL_MSG, CONTINUE_BOOT_MSG}};
lijuang4ece1e72015-08-14 21:02:36 +0800119#endif
120
121static char *verify_option_menu[] = {
lijuang7d235f42015-07-16 20:19:45 +0800122 [POWEROFF] = "Power off\n",
123 [RESTART] = "Restart\n",
124 [RECOVER] = "Recovery\n",
125 [FASTBOOT] = "Fastboot\n",
126 [BACK] = "Back to previous page\n"};
127
tracychuif6dd8d72020-01-20 16:53:15 +0800128/*[20200120][TracyChui]Remove FFBM item in fastboot mode start */
lijuang4ece1e72015-08-14 21:02:36 +0800129static char *fastboot_option_menu[] = {
130 [0] = "START\n",
131 [1] = "Restart bootloader\n",
132 [2] = "Recovery mode\n",
tracychuif6dd8d72020-01-20 16:53:15 +0800133 [3] = "Power off\n"};
134/*[20200120][TracyChui]Remove FFBM item in fastboot mode end */
lijuang4ece1e72015-08-14 21:02:36 +0800135
lijuangf55ad052018-04-23 18:30:50 +0800136static struct unlock_info munlock_info[] = {
137 [DISPLAY_MENU_LOCK] = {UNLOCK, FALSE},
138 [DISPLAY_MENU_UNLOCK] = {UNLOCK, TRUE},
139 [DISPLAY_MENU_LOCK_CRITICAL] = {UNLOCK_CRITICAL, FALSE},
140 [DISPLAY_MENU_UNLOCK_CRITICAL] = {UNLOCK_CRITICAL, TRUE},
141};
142
143struct unlock_option_msg munlock_option_msg[] = {
144 [TRUE] = {"DO NOT UNLOCK THE BOOTLOADER \n", "UNLOCK THE BOOTLOADER \n"},
145 [FALSE] = {"DO NOT LOCK THE BOOTLOADER \n", "LOCK THE BOOTLOADER \n"},
146};
147
lijuang7d235f42015-07-16 20:19:45 +0800148static int big_factor = 2;
149static int common_factor = 1;
150
lijuangde34d502016-02-26 16:04:50 +0800151static void wait_for_exit()
lijuang7d235f42015-07-16 20:19:45 +0800152{
153 struct select_msg_info *select_msg;
154 select_msg = &msg_info;
155
lijuang9a7d3b92015-11-30 14:41:24 +0800156 mutex_acquire(&select_msg->msg_lock);
lijuangde34d502016-02-26 16:04:50 +0800157 while(!select_msg->info.rel_exit == true) {
lijuang9a7d3b92015-11-30 14:41:24 +0800158 mutex_release(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800159 thread_sleep(10);
lijuang9a7d3b92015-11-30 14:41:24 +0800160 mutex_acquire(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800161 }
lijuang9a7d3b92015-11-30 14:41:24 +0800162 mutex_release(&select_msg->msg_lock);
163
lijuangde34d502016-02-26 16:04:50 +0800164 is_thread_start = false;
lijuang7d235f42015-07-16 20:19:45 +0800165 fbcon_clear();
166 display_image_on_screen();
jialongjhanb2dda0b2020-04-21 20:20:51 +0800167 //[Arima][8901][JialongJhan] Command mode update screen 20190618 Start
168 msm_display_flush();
169 //[Arima][8901][JialongJhan] Command mode update screen 20190618 End
lijuang7d235f42015-07-16 20:19:45 +0800170}
171
lijuangde34d502016-02-26 16:04:50 +0800172void wait_for_users_action()
173{
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530174 if (is_display_disabled())
175 return;
lijuangde34d502016-02-26 16:04:50 +0800176 /* Waiting for exit menu keys detection if there is no any usr action
177 * otherwise it will do the action base on the keys detection thread
178 */
179 wait_for_exit();
180}
181
182void exit_menu_keys_detection()
183{
184 struct select_msg_info *select_msg;
185 select_msg = &msg_info;
186
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530187 if (is_display_disabled())
188 return;
189
lijuangde34d502016-02-26 16:04:50 +0800190 mutex_acquire(&select_msg->msg_lock);
191 select_msg->info.is_exit = true;
192 mutex_release(&select_msg->msg_lock);
193
194 wait_for_exit();
195}
196
lijuang7d235f42015-07-16 20:19:45 +0800197static void set_message_factor()
198{
199 uint32_t tmp_factor = 0;
lijuang9e73e5a2018-04-23 17:00:16 +0800200 uint32_t max_x_count = 0;
201 uint32_t max_x = 0;
202
203 if (fbcon_get_width() < fbcon_get_height())
204 max_x_count = CHAR_NUM_PERROW_POR;
205 else
206 max_x_count = CHAR_NUM_PERROW_HOR;
lijuang7d235f42015-07-16 20:19:45 +0800207
208 max_x = fbcon_get_max_x();
209 tmp_factor = max_x/max_x_count;
210
211 if(tmp_factor <= 1) {
212 big_factor = 2;
213 common_factor = 1;
214 } else {
215 big_factor = tmp_factor*2;
216 common_factor = tmp_factor;
217 }
218}
219
Monika Singh05fff3b2019-09-16 16:00:33 +0530220/* If y_start == 0, it will draw message from the current Y axis location,
221 otherwise it will start from the the value of y_start. */
lijuang7d235f42015-07-16 20:19:45 +0800222static void display_fbcon_menu_message(char *str, unsigned type,
Monika Singh05fff3b2019-09-16 16:00:33 +0530223 unsigned scale_factor, int y_start)
lijuang7d235f42015-07-16 20:19:45 +0800224{
225 while(*str != 0) {
Monika Singh05fff3b2019-09-16 16:00:33 +0530226 fbcon_putc_factor(*str++, type, scale_factor, y_start);
227 y_start = 0;
lijuang7d235f42015-07-16 20:19:45 +0800228 }
229}
230
231static char *str_align_right(char *str, int factor)
232{
233 uint32_t max_x = 0;
234 int diff = 0;
235 int i = 0;
236 char *str_target = NULL;
237
238 max_x = fbcon_get_max_x();
239 if (!str_target && max_x) {
240 str_target = malloc(max_x);
241 }
242
243 if (str_target) {
244 memset(str_target, 0, max_x);
245 if ( max_x/factor > strlen(str)) {
246 if (factor == 1)
247 diff = max_x/factor - strlen(str) - 1;
248 else
249 diff = max_x/factor - strlen(str);
250 for (i = 0; i < diff; i++) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530251 strlcat(str_target, " ", max_x);
lijuang7d235f42015-07-16 20:19:45 +0800252 }
lijuang7d235f42015-07-16 20:19:45 +0800253 }
lijuangbdb18ea2018-02-06 17:21:18 +0800254 strlcat(str_target, str, max_x);
lijuang7d235f42015-07-16 20:19:45 +0800255 }
lijuangbdb18ea2018-02-06 17:21:18 +0800256 return str_target;
lijuang7d235f42015-07-16 20:19:45 +0800257}
258
lijuangf55ad052018-04-23 18:30:50 +0800259/**
260 Reset device unlock status
261 @param[in] Type The type of the unlock.
262 [DISPLAY_MENU_UNLOCK]: unlock the device
263 [DISPLAY_MENU_UNLOCK_CRITICAL]: critical unlock the device
264 [DISPLAY_MENU_LOCK]: lock the device
265 [DISPLAY_MENU_LOCK_CRITICAL]: critical lock the device
266 **/
267void reset_device_unlock_status (int type)
268{
269 struct recovery_message msg;
270
271 if (type == DISPLAY_MENU_LOCK ||
272 type == DISPLAY_MENU_UNLOCK ||
273 type == DISPLAY_MENU_LOCK_CRITICAL ||
274 type == DISPLAY_MENU_UNLOCK_CRITICAL) {
275 set_device_unlock_value (munlock_info[type].unlock_type,
276 munlock_info[type].unlock_value);
277 memset(&msg, 0, sizeof(msg));
278 snprintf(msg.recovery, sizeof(msg.recovery), "recovery\n--wipe_data");
279 write_misc(0, &msg, sizeof(msg));
280 }
281}
282
lijuang9a7d3b92015-11-30 14:41:24 +0800283/* msg_lock need to be holded when call this function. */
lijuangf55ad052018-04-23 18:30:50 +0800284static void display_unlock_menu_renew(struct select_msg_info *unlock_msg_info,
285 int type, bool status)
lijuang7d235f42015-07-16 20:19:45 +0800286{
287 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800288 memset(&unlock_msg_info->info, 0, sizeof(struct menu_info));
289
lijuangf55ad052018-04-23 18:30:50 +0800290 display_fbcon_menu_message("<!>\n\n",
Monika Singh05fff3b2019-09-16 16:00:33 +0530291 FBCON_UNLOCK_TITLE_MSG, big_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800292
lijuangf55ad052018-04-23 18:30:50 +0800293 if (status) {
294 display_fbcon_menu_message((char*)unlock_menu_common_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530295 FBCON_COMMON_MSG, common_factor, 0);
lijuangf55ad052018-04-23 18:30:50 +0800296 } else {
297 display_fbcon_menu_message((char*)lock_menu_common_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530298 FBCON_COMMON_MSG, common_factor, 0);
lijuangf55ad052018-04-23 18:30:50 +0800299 }
300
lijuang4ece1e72015-08-14 21:02:36 +0800301 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800302 unlock_msg_info->info.option_start[0] = fbcon_get_current_line();
lijuangf55ad052018-04-23 18:30:50 +0800303 display_fbcon_menu_message((char *)munlock_option_msg[status].ignore_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530304 FBCON_COMMON_MSG, common_factor, 0);
lijuang9a7d3b92015-11-30 14:41:24 +0800305 unlock_msg_info->info.option_bg[0] = fbcon_get_current_bg();
lijuang9a7d3b92015-11-30 14:41:24 +0800306 unlock_msg_info->info.option_end[0] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800307 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800308 unlock_msg_info->info.option_start[1] = fbcon_get_current_line();
lijuangf55ad052018-04-23 18:30:50 +0800309 display_fbcon_menu_message((char *)munlock_option_msg[status].comfirm_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530310 FBCON_COMMON_MSG, common_factor, 0);
lijuang9a7d3b92015-11-30 14:41:24 +0800311 unlock_msg_info->info.option_bg[1] = fbcon_get_current_bg();
lijuang9a7d3b92015-11-30 14:41:24 +0800312 unlock_msg_info->info.option_end[1] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800313 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang7d235f42015-07-16 20:19:45 +0800314
lijuangf55ad052018-04-23 18:30:50 +0800315 if (type == UNLOCK) {
lijuang9a7d3b92015-11-30 14:41:24 +0800316 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK;
lijuangf55ad052018-04-23 18:30:50 +0800317 if (!status)
318 unlock_msg_info->info.msg_type = DISPLAY_MENU_LOCK;
319 } else if (type == UNLOCK_CRITICAL) {
lijuang9a7d3b92015-11-30 14:41:24 +0800320 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK_CRITICAL;
lijuangf55ad052018-04-23 18:30:50 +0800321 if (!status)
322 unlock_msg_info->info.msg_type = DISPLAY_MENU_LOCK_CRITICAL;
323 }
lijuang4ece1e72015-08-14 21:02:36 +0800324
lijuang9a7d3b92015-11-30 14:41:24 +0800325 unlock_msg_info->info.option_num = 2;
326
327 /* Initialize the option index */
328 unlock_msg_info->info.option_index= 2;
lijuang7d235f42015-07-16 20:19:45 +0800329}
330
Monika Singh5e170362018-03-14 00:48:36 +0530331#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800332/* msg_lock need to be holded when call this function. */
333void display_bootverify_menu_renew(struct select_msg_info *msg_info, int type)
lijuang7d235f42015-07-16 20:19:45 +0800334{
lijuang7d235f42015-07-16 20:19:45 +0800335 unsigned char* fp_buf = NULL;
336 char fp_str_temp[EVP_MAX_MD_SIZE] = {'\0'};
337 char fp_str[EVP_MAX_MD_SIZE*2] = {'\0'};
338 char str_temp[8];
lijuang7d235f42015-07-16 20:19:45 +0800339 uint32 fp_size = 0;
340 unsigned int i = 0;
Monika Singh05fff3b2019-09-16 16:00:33 +0530341 uint32_t timeout = DELAY_10SEC;
lijuang7d235f42015-07-16 20:19:45 +0800342
343 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800344 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800345
Monika Singh05fff3b2019-09-16 16:00:33 +0530346 if(boot_verify_info[type].title_msg != NULL)
347 display_fbcon_menu_message((char*)boot_verify_info[type].title_msg,
348 boot_verify_info[type].msg_type, big_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800349
lijuang4ece1e72015-08-14 21:02:36 +0800350 if(boot_verify_info[type].warning_msg != NULL)
351 display_fbcon_menu_message((char*)boot_verify_info[type].warning_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530352 FBCON_COMMON_MSG, common_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800353
Monika Singh05fff3b2019-09-16 16:00:33 +0530354 if(boot_verify_info[type].url_msg != NULL) {
355 dprintf(INFO, "display_fbcon_menu_message: Location=%d\n", fbcon_get_current_line());
Brahmaji K0c2d5982017-09-07 18:44:21 +0530356 display_fbcon_menu_message((char*)boot_verify_info[type].url_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530357 boot_verify_info[type].msg_type, common_factor, 0);
358 dprintf(INFO, "display_fbcon_menu_message: Location=%d\n", fbcon_get_current_line());
359 }
360
361 if(boot_verify_info[type].notice_msg != NULL) {
362 msg_info->info.option_start[0] = fbcon_get_current_line();
363 dprintf(INFO, "display_fbcon_menu_message: Location=%d\n", msg_info->info.option_start[0]);
364 display_fbcon_menu_message((char*)boot_verify_info[type].notice_msg,
365 FBCON_COMMON_MSG, common_factor, 0);
366 msg_info->info.option_end[0] = fbcon_get_current_line();
367 }
lijuang7d235f42015-07-16 20:19:45 +0800368
lijuang7d235f42015-07-16 20:19:45 +0800369 if (type == DISPLAY_MENU_YELLOW) {
370 fp_buf = get_boot_fingerprint(&fp_size);
371 if (fp_buf != NULL) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530372 strlcpy(fp_str_temp, (char const *)fp_buf, fp_size);
lijuang7d235f42015-07-16 20:19:45 +0800373 for (i = 0; i < fp_size; i++) {
374 if(i == fp_size - 1)
Parth Dixit73d3bd02016-01-07 14:29:41 +0530375 snprintf(str_temp, sizeof(str_temp), "%02x", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800376 else
Parth Dixit73d3bd02016-01-07 14:29:41 +0530377 snprintf(str_temp, sizeof(str_temp), "%02x-", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800378
Parth Dixit73d3bd02016-01-07 14:29:41 +0530379 strlcat(fp_str, str_temp, sizeof(fp_str));
lijuang7d235f42015-07-16 20:19:45 +0800380 }
381 }
Monika Singh05fff3b2019-09-16 16:00:33 +0530382 display_fbcon_menu_message("ID:", FBCON_COMMON_MSG, common_factor, 0);
383 display_fbcon_menu_message(fp_str, FBCON_COMMON_MSG, common_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800384 }
lijuang7d235f42015-07-16 20:19:45 +0800385
Monika Singh05fff3b2019-09-16 16:00:33 +0530386 switch (type) {
387 case DISPLAY_MENU_RED:
388 timeout = DELAY_30SEC;
389 break;
390 case DISPLAY_MENU_EIO:
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530391#if ENABLE_VB_ATTEST
Monika Singh05fff3b2019-09-16 16:00:33 +0530392 timeout = DELAY_30SEC;
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530393#endif
Monika Singh05fff3b2019-09-16 16:00:33 +0530394 break;
395 default:
396 timeout = DELAY_10SEC;
397 break;
398 }
lijuang7d235f42015-07-16 20:19:45 +0800399
lijuang9a7d3b92015-11-30 14:41:24 +0800400 msg_info->info.msg_type = type;
lijuang9a7d3b92015-11-30 14:41:24 +0800401
402 /* Initialize the time out time */
Monika Singh05fff3b2019-09-16 16:00:33 +0530403 msg_info->info.timeout_time = timeout;
lijuang7d235f42015-07-16 20:19:45 +0800404}
Monika Singh05fff3b2019-09-16 16:00:33 +0530405
406void display_bootverify_menu_update (struct select_msg_info *msg_info)
407{
408 int location = msg_info->info.option_start[0];
409
410 /* clean the old msg */
411 fbcon_clear_msg (location, msg_info->info.option_end[0]);
412 display_fbcon_menu_message(CONTINUE_BOOT_MSG, FBCON_COMMON_MSG, common_factor, location);
413 msg_info->info.timeout_time = DELAY_30SEC;
414}
415
lijuang4ece1e72015-08-14 21:02:36 +0800416#endif
lijuang7d235f42015-07-16 20:19:45 +0800417
lijuang9a7d3b92015-11-30 14:41:24 +0800418/* msg_lock need to be holded when call this function. */
419void display_bootverify_option_menu_renew(struct select_msg_info *msg_info)
lijuang7d235f42015-07-16 20:19:45 +0800420{
421 int i = 0;
lijuang4ece1e72015-08-14 21:02:36 +0800422 int len = 0;
lijuang9a7d3b92015-11-30 14:41:24 +0800423
lijuang7d235f42015-07-16 20:19:45 +0800424 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800425 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800426
lijuang4ece1e72015-08-14 21:02:36 +0800427 len = ARRAY_SIZE(verify_option_menu);
lijuang7d235f42015-07-16 20:19:45 +0800428 display_fbcon_menu_message("Options menu:\n\n",
Monika Singh05fff3b2019-09-16 16:00:33 +0530429 FBCON_COMMON_MSG, big_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800430 display_fbcon_menu_message("Press volume key to select, and "\
Monika Singh05fff3b2019-09-16 16:00:33 +0530431 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800432
lijuang4ece1e72015-08-14 21:02:36 +0800433 for (i = 0; i < len; i++) {
434 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800435 msg_info->info.option_start[i] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800436 display_fbcon_menu_message(verify_option_menu[i],
Monika Singh05fff3b2019-09-16 16:00:33 +0530437 FBCON_COMMON_MSG, common_factor, 0);
lijuang9a7d3b92015-11-30 14:41:24 +0800438 msg_info->info.option_bg[i]= fbcon_get_current_bg();
439 msg_info->info.option_end[i]= fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800440 }
441
lijuang4ece1e72015-08-14 21:02:36 +0800442 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800443 msg_info->info.msg_type = DISPLAY_MENU_MORE_OPTION;
444 msg_info->info.option_num = len;
445
446 /* Initialize the option index */
447 msg_info->info.option_index= len;
lijuang4ece1e72015-08-14 21:02:36 +0800448}
449
lijuang9a7d3b92015-11-30 14:41:24 +0800450/* msg_lock need to be holded when call this function. */
451void display_fastboot_menu_renew(struct select_msg_info *fastboot_msg_info)
lijuang4ece1e72015-08-14 21:02:36 +0800452{
453 int len;
454 int msg_type = FBCON_COMMON_MSG;
455 char msg_buf[64];
456 char msg[128];
457
lijuang9a7d3b92015-11-30 14:41:24 +0800458 /* The fastboot menu is switched base on the option index
459 * So it's need to store the index for the menu switching
460 */
461 uint32_t option_index = fastboot_msg_info->info.option_index;
462
lijuang4ece1e72015-08-14 21:02:36 +0800463 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800464 memset(&fastboot_msg_info->info, 0, sizeof(struct menu_info));
lijuang4ece1e72015-08-14 21:02:36 +0800465
466 len = ARRAY_SIZE(fastboot_option_menu);
467 switch(option_index) {
468 case 0:
469 msg_type = FBCON_GREEN_MSG;
470 break;
471 case 1:
472 case 2:
473 msg_type = FBCON_RED_MSG;
474 break;
475 case 3:
lijuang42aefaa2016-04-14 15:55:17 +0800476 case 4:
lijuang4ece1e72015-08-14 21:02:36 +0800477 msg_type = FBCON_COMMON_MSG;
478 break;
479 }
480 fbcon_draw_line(msg_type);
481 display_fbcon_menu_message(fastboot_option_menu[option_index],
Monika Singh05fff3b2019-09-16 16:00:33 +0530482 msg_type, big_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800483 fbcon_draw_line(msg_type);
484 display_fbcon_menu_message("\n\nPress volume key to select, and "\
Monika Singh05fff3b2019-09-16 16:00:33 +0530485 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800486
Monika Singh05fff3b2019-09-16 16:00:33 +0530487 display_fbcon_menu_message("FASTBOOT MODE\n", FBCON_RED_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800488
489 get_product_name((unsigned char *) msg_buf);
490 snprintf(msg, sizeof(msg), "PRODUCT_NAME - %s\n", msg_buf);
Monika Singh05fff3b2019-09-16 16:00:33 +0530491 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800492
493 memset(msg_buf, 0, sizeof(msg_buf));
494 smem_get_hw_platform_name((unsigned char *) msg_buf, sizeof(msg_buf));
495 snprintf(msg, sizeof(msg), "VARIANT - %s %s\n",
496 msg_buf, target_is_emmc_boot()? "eMMC":"UFS");
Monika Singh05fff3b2019-09-16 16:00:33 +0530497 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800498
499 memset(msg_buf, 0, sizeof(msg_buf));
500 get_bootloader_version((unsigned char *) msg_buf);
501 snprintf(msg, sizeof(msg), "BOOTLOADER VERSION - %s\n",
502 msg_buf);
Monika Singh05fff3b2019-09-16 16:00:33 +0530503 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800504
505 memset(msg_buf, 0, sizeof(msg_buf));
506 get_baseband_version((unsigned char *) msg_buf);
507 snprintf(msg, sizeof(msg), "BASEBAND VERSION - %s\n",
508 msg_buf);
Monika Singh05fff3b2019-09-16 16:00:33 +0530509 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800510
511 memset(msg_buf, 0, sizeof(msg_buf));
512 target_serialno((unsigned char *) msg_buf);
513 snprintf(msg, sizeof(msg), "SERIAL NUMBER - %s\n", msg_buf);
Monika Singh05fff3b2019-09-16 16:00:33 +0530514 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800515
516 snprintf(msg, sizeof(msg), "SECURE BOOT - %s\n",
517 is_secure_boot_enable()? "enabled":"disabled");
Monika Singh05fff3b2019-09-16 16:00:33 +0530518 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800519
520 snprintf(msg, sizeof(msg), "DEVICE STATE - %s\n",
521 is_device_locked()? "locked":"unlocked");
Monika Singh05fff3b2019-09-16 16:00:33 +0530522 display_fbcon_menu_message(msg, FBCON_RED_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800523
lijuang9a7d3b92015-11-30 14:41:24 +0800524 fastboot_msg_info->info.msg_type = DISPLAY_MENU_FASTBOOT;
525 fastboot_msg_info->info.option_num = len;
526 fastboot_msg_info->info.option_index = option_index;
527}
528
529void msg_lock_init()
530{
531 static bool is_msg_lock_init = false;
532 struct select_msg_info *msg_lock_info;
533 msg_lock_info = &msg_info;
534
535 if (!is_msg_lock_init) {
536 mutex_init(&msg_lock_info->msg_lock);
537 is_msg_lock_init = true;
538 }
lijuang7d235f42015-07-16 20:19:45 +0800539}
540
541static void display_menu_thread_start(struct select_msg_info *msg_info)
542{
543 thread_t *thr;
544
545 if (!is_thread_start) {
546 thr = thread_create("selectkeydetect", &select_msg_keys_detect,
547 (void*)msg_info, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
548 if (!thr) {
549 dprintf(CRITICAL, "ERROR: creat device status detect thread failed!!\n");
550 return;
551 }
552 thread_resume(thr);
lijuang9a7d3b92015-11-30 14:41:24 +0800553 is_thread_start = true;
lijuang7d235f42015-07-16 20:19:45 +0800554 }
lijuang7d235f42015-07-16 20:19:45 +0800555}
556
lijuang9a7d3b92015-11-30 14:41:24 +0800557/* The fuction be called after device in fastboot mode,
558 * so it's no need to initialize the msg_lock again
559 */
lijuangf55ad052018-04-23 18:30:50 +0800560void display_unlock_menu(int type, bool status)
lijuang7d235f42015-07-16 20:19:45 +0800561{
lijuang4ece1e72015-08-14 21:02:36 +0800562 struct select_msg_info *unlock_menu_msg_info;
563 unlock_menu_msg_info = &msg_info;
lijuang7d235f42015-07-16 20:19:45 +0800564
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530565 if (is_display_disabled())
566 return;
567
lijuang7d235f42015-07-16 20:19:45 +0800568 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800569
570 msg_lock_init();
571 mutex_acquire(&unlock_menu_msg_info->msg_lock);
572
573 /* Initialize the last_msg_type */
574 unlock_menu_msg_info->last_msg_type =
575 unlock_menu_msg_info->info.msg_type;
576
lijuangf55ad052018-04-23 18:30:50 +0800577 display_unlock_menu_renew(unlock_menu_msg_info, type, status);
jialongjhanb2dda0b2020-04-21 20:20:51 +0800578 //[Arima][8901][JialongJhan] Command mode update screen 20190618 Start
579 msm_display_flush();
580 //[Arima][8901][JialongJhan] Command mode update screen 20190618 End
lijuang9a7d3b92015-11-30 14:41:24 +0800581 mutex_release(&unlock_menu_msg_info->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800582
lijuangf55ad052018-04-23 18:30:50 +0800583 dprintf(INFO, "creating %s keys detect thread\n",
584 status ? "unlock":"lock");
lijuang4ece1e72015-08-14 21:02:36 +0800585 display_menu_thread_start(unlock_menu_msg_info);
lijuang7d235f42015-07-16 20:19:45 +0800586}
587
lijuang9a7d3b92015-11-30 14:41:24 +0800588void display_fastboot_menu()
lijuang4ece1e72015-08-14 21:02:36 +0800589{
590 struct select_msg_info *fastboot_menu_msg_info;
591 fastboot_menu_msg_info = &msg_info;
592
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530593 if (is_display_disabled())
594 return;
595
lijuang4ece1e72015-08-14 21:02:36 +0800596 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800597
598 msg_lock_init();
599 mutex_acquire(&fastboot_menu_msg_info->msg_lock);
600
601 /* There are 4 pages for fastboot menu:
602 * Page: Start/Fastboot/Recovery/Poweroff
603 * The menu is switched base on the option index
604 * Initialize the option index and last_msg_type
605 */
606 fastboot_menu_msg_info->info.option_index = 0;
607 fastboot_menu_msg_info->last_msg_type =
608 fastboot_menu_msg_info->info.msg_type;
609
610 display_fastboot_menu_renew(fastboot_menu_msg_info);
jialongjhanb2dda0b2020-04-21 20:20:51 +0800611 //[Arima][8901][JialongJhan] Command mode update screen 20190618 Start
612 msm_display_flush();
613 //[Arima][8901][JialongJhan] Command mode update screen 20190618 End
lijuang9a7d3b92015-11-30 14:41:24 +0800614 mutex_release(&fastboot_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800615
616 dprintf(INFO, "creating fastboot menu keys detect thread\n");
617 display_menu_thread_start(fastboot_menu_msg_info);
618}
619
Monika Singh5e170362018-03-14 00:48:36 +0530620#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800621void display_bootverify_menu(int type)
lijuang4ece1e72015-08-14 21:02:36 +0800622{
623 struct select_msg_info *bootverify_menu_msg_info;
624 bootverify_menu_msg_info = &msg_info;
625
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530626 if (is_display_disabled())
627 return;
628
lijuang4ece1e72015-08-14 21:02:36 +0800629 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800630
631 msg_lock_init();
632 mutex_acquire(&bootverify_menu_msg_info->msg_lock);
633
634 /* Initialize the last_msg_type */
635 bootverify_menu_msg_info->last_msg_type =
636 bootverify_menu_msg_info->info.msg_type;
637
638 display_bootverify_menu_renew(bootverify_menu_msg_info, type);
jialongjhanb2dda0b2020-04-21 20:20:51 +0800639 //[Arima][8901][JialongJhan] Command mode update screen 201906118 Start
640 msm_display_flush();
641 //[Arima][8901][JialongJhan] Command mode update screen 20190618 End
lijuang9a7d3b92015-11-30 14:41:24 +0800642 mutex_release(&bootverify_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800643
644 dprintf(INFO, "creating boot verify keys detect thread\n");
645 display_menu_thread_start(bootverify_menu_msg_info);
646}
647#endif