blob: 52d7c1ed8c037eac83d18b2ed818eebfac5d9639 [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
lijuang4ece1e72015-08-14 21:02:36 +0800128static char *fastboot_option_menu[] = {
129 [0] = "START\n",
130 [1] = "Restart bootloader\n",
131 [2] = "Recovery mode\n",
lijuang42aefaa2016-04-14 15:55:17 +0800132 [3] = "Power off\n",
133 [4] = "Boot to FFBM\n"};
lijuang4ece1e72015-08-14 21:02:36 +0800134
lijuangf55ad052018-04-23 18:30:50 +0800135static struct unlock_info munlock_info[] = {
136 [DISPLAY_MENU_LOCK] = {UNLOCK, FALSE},
137 [DISPLAY_MENU_UNLOCK] = {UNLOCK, TRUE},
138 [DISPLAY_MENU_LOCK_CRITICAL] = {UNLOCK_CRITICAL, FALSE},
139 [DISPLAY_MENU_UNLOCK_CRITICAL] = {UNLOCK_CRITICAL, TRUE},
140};
141
142struct unlock_option_msg munlock_option_msg[] = {
143 [TRUE] = {"DO NOT UNLOCK THE BOOTLOADER \n", "UNLOCK THE BOOTLOADER \n"},
144 [FALSE] = {"DO NOT LOCK THE BOOTLOADER \n", "LOCK THE BOOTLOADER \n"},
145};
146
lijuang7d235f42015-07-16 20:19:45 +0800147static int big_factor = 2;
148static int common_factor = 1;
149
lijuangde34d502016-02-26 16:04:50 +0800150static void wait_for_exit()
lijuang7d235f42015-07-16 20:19:45 +0800151{
152 struct select_msg_info *select_msg;
153 select_msg = &msg_info;
154
lijuang9a7d3b92015-11-30 14:41:24 +0800155 mutex_acquire(&select_msg->msg_lock);
lijuangde34d502016-02-26 16:04:50 +0800156 while(!select_msg->info.rel_exit == true) {
lijuang9a7d3b92015-11-30 14:41:24 +0800157 mutex_release(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800158 thread_sleep(10);
lijuang9a7d3b92015-11-30 14:41:24 +0800159 mutex_acquire(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800160 }
lijuang9a7d3b92015-11-30 14:41:24 +0800161 mutex_release(&select_msg->msg_lock);
162
lijuangde34d502016-02-26 16:04:50 +0800163 is_thread_start = false;
lijuang7d235f42015-07-16 20:19:45 +0800164 fbcon_clear();
165 display_image_on_screen();
jialongjhanb2dda0b2020-04-21 20:20:51 +0800166 //[Arima][8901][JialongJhan] Command mode update screen 20190618 Start
167 msm_display_flush();
168 //[Arima][8901][JialongJhan] Command mode update screen 20190618 End
lijuang7d235f42015-07-16 20:19:45 +0800169}
170
lijuangde34d502016-02-26 16:04:50 +0800171void wait_for_users_action()
172{
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530173 if (is_display_disabled())
174 return;
lijuangde34d502016-02-26 16:04:50 +0800175 /* Waiting for exit menu keys detection if there is no any usr action
176 * otherwise it will do the action base on the keys detection thread
177 */
178 wait_for_exit();
179}
180
181void exit_menu_keys_detection()
182{
183 struct select_msg_info *select_msg;
184 select_msg = &msg_info;
185
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530186 if (is_display_disabled())
187 return;
188
lijuangde34d502016-02-26 16:04:50 +0800189 mutex_acquire(&select_msg->msg_lock);
190 select_msg->info.is_exit = true;
191 mutex_release(&select_msg->msg_lock);
192
193 wait_for_exit();
194}
195
lijuang7d235f42015-07-16 20:19:45 +0800196static void set_message_factor()
197{
198 uint32_t tmp_factor = 0;
lijuang9e73e5a2018-04-23 17:00:16 +0800199 uint32_t max_x_count = 0;
200 uint32_t max_x = 0;
201
202 if (fbcon_get_width() < fbcon_get_height())
203 max_x_count = CHAR_NUM_PERROW_POR;
204 else
205 max_x_count = CHAR_NUM_PERROW_HOR;
lijuang7d235f42015-07-16 20:19:45 +0800206
207 max_x = fbcon_get_max_x();
208 tmp_factor = max_x/max_x_count;
209
210 if(tmp_factor <= 1) {
211 big_factor = 2;
212 common_factor = 1;
213 } else {
214 big_factor = tmp_factor*2;
215 common_factor = tmp_factor;
216 }
217}
218
Monika Singh05fff3b2019-09-16 16:00:33 +0530219/* If y_start == 0, it will draw message from the current Y axis location,
220 otherwise it will start from the the value of y_start. */
lijuang7d235f42015-07-16 20:19:45 +0800221static void display_fbcon_menu_message(char *str, unsigned type,
Monika Singh05fff3b2019-09-16 16:00:33 +0530222 unsigned scale_factor, int y_start)
lijuang7d235f42015-07-16 20:19:45 +0800223{
224 while(*str != 0) {
Monika Singh05fff3b2019-09-16 16:00:33 +0530225 fbcon_putc_factor(*str++, type, scale_factor, y_start);
226 y_start = 0;
lijuang7d235f42015-07-16 20:19:45 +0800227 }
228}
229
230static char *str_align_right(char *str, int factor)
231{
232 uint32_t max_x = 0;
233 int diff = 0;
234 int i = 0;
235 char *str_target = NULL;
236
237 max_x = fbcon_get_max_x();
238 if (!str_target && max_x) {
239 str_target = malloc(max_x);
240 }
241
242 if (str_target) {
243 memset(str_target, 0, max_x);
244 if ( max_x/factor > strlen(str)) {
245 if (factor == 1)
246 diff = max_x/factor - strlen(str) - 1;
247 else
248 diff = max_x/factor - strlen(str);
249 for (i = 0; i < diff; i++) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530250 strlcat(str_target, " ", max_x);
lijuang7d235f42015-07-16 20:19:45 +0800251 }
lijuang7d235f42015-07-16 20:19:45 +0800252 }
lijuangbdb18ea2018-02-06 17:21:18 +0800253 strlcat(str_target, str, max_x);
lijuang7d235f42015-07-16 20:19:45 +0800254 }
lijuangbdb18ea2018-02-06 17:21:18 +0800255 return str_target;
lijuang7d235f42015-07-16 20:19:45 +0800256}
257
lijuangf55ad052018-04-23 18:30:50 +0800258/**
259 Reset device unlock status
260 @param[in] Type The type of the unlock.
261 [DISPLAY_MENU_UNLOCK]: unlock the device
262 [DISPLAY_MENU_UNLOCK_CRITICAL]: critical unlock the device
263 [DISPLAY_MENU_LOCK]: lock the device
264 [DISPLAY_MENU_LOCK_CRITICAL]: critical lock the device
265 **/
266void reset_device_unlock_status (int type)
267{
268 struct recovery_message msg;
269
270 if (type == DISPLAY_MENU_LOCK ||
271 type == DISPLAY_MENU_UNLOCK ||
272 type == DISPLAY_MENU_LOCK_CRITICAL ||
273 type == DISPLAY_MENU_UNLOCK_CRITICAL) {
274 set_device_unlock_value (munlock_info[type].unlock_type,
275 munlock_info[type].unlock_value);
276 memset(&msg, 0, sizeof(msg));
277 snprintf(msg.recovery, sizeof(msg.recovery), "recovery\n--wipe_data");
278 write_misc(0, &msg, sizeof(msg));
279 }
280}
281
lijuang9a7d3b92015-11-30 14:41:24 +0800282/* msg_lock need to be holded when call this function. */
lijuangf55ad052018-04-23 18:30:50 +0800283static void display_unlock_menu_renew(struct select_msg_info *unlock_msg_info,
284 int type, bool status)
lijuang7d235f42015-07-16 20:19:45 +0800285{
286 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800287 memset(&unlock_msg_info->info, 0, sizeof(struct menu_info));
288
lijuangf55ad052018-04-23 18:30:50 +0800289 display_fbcon_menu_message("<!>\n\n",
Monika Singh05fff3b2019-09-16 16:00:33 +0530290 FBCON_UNLOCK_TITLE_MSG, big_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800291
lijuangf55ad052018-04-23 18:30:50 +0800292 if (status) {
293 display_fbcon_menu_message((char*)unlock_menu_common_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530294 FBCON_COMMON_MSG, common_factor, 0);
lijuangf55ad052018-04-23 18:30:50 +0800295 } else {
296 display_fbcon_menu_message((char*)lock_menu_common_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530297 FBCON_COMMON_MSG, common_factor, 0);
lijuangf55ad052018-04-23 18:30:50 +0800298 }
299
lijuang4ece1e72015-08-14 21:02:36 +0800300 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800301 unlock_msg_info->info.option_start[0] = fbcon_get_current_line();
lijuangf55ad052018-04-23 18:30:50 +0800302 display_fbcon_menu_message((char *)munlock_option_msg[status].ignore_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530303 FBCON_COMMON_MSG, common_factor, 0);
lijuang9a7d3b92015-11-30 14:41:24 +0800304 unlock_msg_info->info.option_bg[0] = fbcon_get_current_bg();
lijuang9a7d3b92015-11-30 14:41:24 +0800305 unlock_msg_info->info.option_end[0] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800306 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800307 unlock_msg_info->info.option_start[1] = fbcon_get_current_line();
lijuangf55ad052018-04-23 18:30:50 +0800308 display_fbcon_menu_message((char *)munlock_option_msg[status].comfirm_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530309 FBCON_COMMON_MSG, common_factor, 0);
lijuang9a7d3b92015-11-30 14:41:24 +0800310 unlock_msg_info->info.option_bg[1] = fbcon_get_current_bg();
lijuang9a7d3b92015-11-30 14:41:24 +0800311 unlock_msg_info->info.option_end[1] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800312 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang7d235f42015-07-16 20:19:45 +0800313
lijuangf55ad052018-04-23 18:30:50 +0800314 if (type == UNLOCK) {
lijuang9a7d3b92015-11-30 14:41:24 +0800315 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK;
lijuangf55ad052018-04-23 18:30:50 +0800316 if (!status)
317 unlock_msg_info->info.msg_type = DISPLAY_MENU_LOCK;
318 } else if (type == UNLOCK_CRITICAL) {
lijuang9a7d3b92015-11-30 14:41:24 +0800319 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK_CRITICAL;
lijuangf55ad052018-04-23 18:30:50 +0800320 if (!status)
321 unlock_msg_info->info.msg_type = DISPLAY_MENU_LOCK_CRITICAL;
322 }
lijuang4ece1e72015-08-14 21:02:36 +0800323
lijuang9a7d3b92015-11-30 14:41:24 +0800324 unlock_msg_info->info.option_num = 2;
325
326 /* Initialize the option index */
327 unlock_msg_info->info.option_index= 2;
lijuang7d235f42015-07-16 20:19:45 +0800328}
329
Monika Singh5e170362018-03-14 00:48:36 +0530330#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800331/* msg_lock need to be holded when call this function. */
332void display_bootverify_menu_renew(struct select_msg_info *msg_info, int type)
lijuang7d235f42015-07-16 20:19:45 +0800333{
lijuang7d235f42015-07-16 20:19:45 +0800334 unsigned char* fp_buf = NULL;
335 char fp_str_temp[EVP_MAX_MD_SIZE] = {'\0'};
336 char fp_str[EVP_MAX_MD_SIZE*2] = {'\0'};
337 char str_temp[8];
lijuang7d235f42015-07-16 20:19:45 +0800338 uint32 fp_size = 0;
339 unsigned int i = 0;
Monika Singh05fff3b2019-09-16 16:00:33 +0530340 uint32_t timeout = DELAY_10SEC;
lijuang7d235f42015-07-16 20:19:45 +0800341
342 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800343 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800344
Monika Singh05fff3b2019-09-16 16:00:33 +0530345 if(boot_verify_info[type].title_msg != NULL)
346 display_fbcon_menu_message((char*)boot_verify_info[type].title_msg,
347 boot_verify_info[type].msg_type, big_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800348
lijuang4ece1e72015-08-14 21:02:36 +0800349 if(boot_verify_info[type].warning_msg != NULL)
350 display_fbcon_menu_message((char*)boot_verify_info[type].warning_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530351 FBCON_COMMON_MSG, common_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800352
Monika Singh05fff3b2019-09-16 16:00:33 +0530353 if(boot_verify_info[type].url_msg != NULL) {
354 dprintf(INFO, "display_fbcon_menu_message: Location=%d\n", fbcon_get_current_line());
Brahmaji K0c2d5982017-09-07 18:44:21 +0530355 display_fbcon_menu_message((char*)boot_verify_info[type].url_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530356 boot_verify_info[type].msg_type, common_factor, 0);
357 dprintf(INFO, "display_fbcon_menu_message: Location=%d\n", fbcon_get_current_line());
358 }
359
360 if(boot_verify_info[type].notice_msg != NULL) {
361 msg_info->info.option_start[0] = fbcon_get_current_line();
362 dprintf(INFO, "display_fbcon_menu_message: Location=%d\n", msg_info->info.option_start[0]);
363 display_fbcon_menu_message((char*)boot_verify_info[type].notice_msg,
364 FBCON_COMMON_MSG, common_factor, 0);
365 msg_info->info.option_end[0] = fbcon_get_current_line();
366 }
lijuang7d235f42015-07-16 20:19:45 +0800367
lijuang7d235f42015-07-16 20:19:45 +0800368 if (type == DISPLAY_MENU_YELLOW) {
369 fp_buf = get_boot_fingerprint(&fp_size);
370 if (fp_buf != NULL) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530371 strlcpy(fp_str_temp, (char const *)fp_buf, fp_size);
lijuang7d235f42015-07-16 20:19:45 +0800372 for (i = 0; i < fp_size; i++) {
373 if(i == fp_size - 1)
Parth Dixit73d3bd02016-01-07 14:29:41 +0530374 snprintf(str_temp, sizeof(str_temp), "%02x", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800375 else
Parth Dixit73d3bd02016-01-07 14:29:41 +0530376 snprintf(str_temp, sizeof(str_temp), "%02x-", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800377
Parth Dixit73d3bd02016-01-07 14:29:41 +0530378 strlcat(fp_str, str_temp, sizeof(fp_str));
lijuang7d235f42015-07-16 20:19:45 +0800379 }
380 }
Monika Singh05fff3b2019-09-16 16:00:33 +0530381 display_fbcon_menu_message("ID:", FBCON_COMMON_MSG, common_factor, 0);
382 display_fbcon_menu_message(fp_str, FBCON_COMMON_MSG, common_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800383 }
lijuang7d235f42015-07-16 20:19:45 +0800384
Monika Singh05fff3b2019-09-16 16:00:33 +0530385 switch (type) {
386 case DISPLAY_MENU_RED:
387 timeout = DELAY_30SEC;
388 break;
389 case DISPLAY_MENU_EIO:
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530390#if ENABLE_VB_ATTEST
Monika Singh05fff3b2019-09-16 16:00:33 +0530391 timeout = DELAY_30SEC;
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530392#endif
Monika Singh05fff3b2019-09-16 16:00:33 +0530393 break;
394 default:
395 timeout = DELAY_10SEC;
396 break;
397 }
lijuang7d235f42015-07-16 20:19:45 +0800398
lijuang9a7d3b92015-11-30 14:41:24 +0800399 msg_info->info.msg_type = type;
lijuang9a7d3b92015-11-30 14:41:24 +0800400
401 /* Initialize the time out time */
Monika Singh05fff3b2019-09-16 16:00:33 +0530402 msg_info->info.timeout_time = timeout;
lijuang7d235f42015-07-16 20:19:45 +0800403}
Monika Singh05fff3b2019-09-16 16:00:33 +0530404
405void display_bootverify_menu_update (struct select_msg_info *msg_info)
406{
407 int location = msg_info->info.option_start[0];
408
409 /* clean the old msg */
410 fbcon_clear_msg (location, msg_info->info.option_end[0]);
411 display_fbcon_menu_message(CONTINUE_BOOT_MSG, FBCON_COMMON_MSG, common_factor, location);
412 msg_info->info.timeout_time = DELAY_30SEC;
413}
414
lijuang4ece1e72015-08-14 21:02:36 +0800415#endif
lijuang7d235f42015-07-16 20:19:45 +0800416
lijuang9a7d3b92015-11-30 14:41:24 +0800417/* msg_lock need to be holded when call this function. */
418void display_bootverify_option_menu_renew(struct select_msg_info *msg_info)
lijuang7d235f42015-07-16 20:19:45 +0800419{
420 int i = 0;
lijuang4ece1e72015-08-14 21:02:36 +0800421 int len = 0;
lijuang9a7d3b92015-11-30 14:41:24 +0800422
lijuang7d235f42015-07-16 20:19:45 +0800423 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800424 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800425
lijuang4ece1e72015-08-14 21:02:36 +0800426 len = ARRAY_SIZE(verify_option_menu);
lijuang7d235f42015-07-16 20:19:45 +0800427 display_fbcon_menu_message("Options menu:\n\n",
Monika Singh05fff3b2019-09-16 16:00:33 +0530428 FBCON_COMMON_MSG, big_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800429 display_fbcon_menu_message("Press volume key to select, and "\
Monika Singh05fff3b2019-09-16 16:00:33 +0530430 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800431
lijuang4ece1e72015-08-14 21:02:36 +0800432 for (i = 0; i < len; i++) {
433 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800434 msg_info->info.option_start[i] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800435 display_fbcon_menu_message(verify_option_menu[i],
Monika Singh05fff3b2019-09-16 16:00:33 +0530436 FBCON_COMMON_MSG, common_factor, 0);
lijuang9a7d3b92015-11-30 14:41:24 +0800437 msg_info->info.option_bg[i]= fbcon_get_current_bg();
438 msg_info->info.option_end[i]= fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800439 }
440
lijuang4ece1e72015-08-14 21:02:36 +0800441 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800442 msg_info->info.msg_type = DISPLAY_MENU_MORE_OPTION;
443 msg_info->info.option_num = len;
444
445 /* Initialize the option index */
446 msg_info->info.option_index= len;
lijuang4ece1e72015-08-14 21:02:36 +0800447}
448
lijuang9a7d3b92015-11-30 14:41:24 +0800449/* msg_lock need to be holded when call this function. */
450void display_fastboot_menu_renew(struct select_msg_info *fastboot_msg_info)
lijuang4ece1e72015-08-14 21:02:36 +0800451{
452 int len;
453 int msg_type = FBCON_COMMON_MSG;
454 char msg_buf[64];
455 char msg[128];
456
lijuang9a7d3b92015-11-30 14:41:24 +0800457 /* The fastboot menu is switched base on the option index
458 * So it's need to store the index for the menu switching
459 */
460 uint32_t option_index = fastboot_msg_info->info.option_index;
461
lijuang4ece1e72015-08-14 21:02:36 +0800462 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800463 memset(&fastboot_msg_info->info, 0, sizeof(struct menu_info));
lijuang4ece1e72015-08-14 21:02:36 +0800464
465 len = ARRAY_SIZE(fastboot_option_menu);
466 switch(option_index) {
467 case 0:
468 msg_type = FBCON_GREEN_MSG;
469 break;
470 case 1:
471 case 2:
472 msg_type = FBCON_RED_MSG;
473 break;
474 case 3:
lijuang42aefaa2016-04-14 15:55:17 +0800475 case 4:
lijuang4ece1e72015-08-14 21:02:36 +0800476 msg_type = FBCON_COMMON_MSG;
477 break;
478 }
479 fbcon_draw_line(msg_type);
480 display_fbcon_menu_message(fastboot_option_menu[option_index],
Monika Singh05fff3b2019-09-16 16:00:33 +0530481 msg_type, big_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800482 fbcon_draw_line(msg_type);
483 display_fbcon_menu_message("\n\nPress volume key to select, and "\
Monika Singh05fff3b2019-09-16 16:00:33 +0530484 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800485
Monika Singh05fff3b2019-09-16 16:00:33 +0530486 display_fbcon_menu_message("FASTBOOT MODE\n", FBCON_RED_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800487
488 get_product_name((unsigned char *) msg_buf);
489 snprintf(msg, sizeof(msg), "PRODUCT_NAME - %s\n", msg_buf);
Monika Singh05fff3b2019-09-16 16:00:33 +0530490 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800491
492 memset(msg_buf, 0, sizeof(msg_buf));
493 smem_get_hw_platform_name((unsigned char *) msg_buf, sizeof(msg_buf));
494 snprintf(msg, sizeof(msg), "VARIANT - %s %s\n",
495 msg_buf, target_is_emmc_boot()? "eMMC":"UFS");
Monika Singh05fff3b2019-09-16 16:00:33 +0530496 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800497
498 memset(msg_buf, 0, sizeof(msg_buf));
499 get_bootloader_version((unsigned char *) msg_buf);
500 snprintf(msg, sizeof(msg), "BOOTLOADER VERSION - %s\n",
501 msg_buf);
Monika Singh05fff3b2019-09-16 16:00:33 +0530502 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800503
504 memset(msg_buf, 0, sizeof(msg_buf));
505 get_baseband_version((unsigned char *) msg_buf);
506 snprintf(msg, sizeof(msg), "BASEBAND VERSION - %s\n",
507 msg_buf);
Monika Singh05fff3b2019-09-16 16:00:33 +0530508 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800509
510 memset(msg_buf, 0, sizeof(msg_buf));
511 target_serialno((unsigned char *) msg_buf);
512 snprintf(msg, sizeof(msg), "SERIAL NUMBER - %s\n", msg_buf);
Monika Singh05fff3b2019-09-16 16:00:33 +0530513 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800514
515 snprintf(msg, sizeof(msg), "SECURE BOOT - %s\n",
516 is_secure_boot_enable()? "enabled":"disabled");
Monika Singh05fff3b2019-09-16 16:00:33 +0530517 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800518
519 snprintf(msg, sizeof(msg), "DEVICE STATE - %s\n",
520 is_device_locked()? "locked":"unlocked");
Monika Singh05fff3b2019-09-16 16:00:33 +0530521 display_fbcon_menu_message(msg, FBCON_RED_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800522
lijuang9a7d3b92015-11-30 14:41:24 +0800523 fastboot_msg_info->info.msg_type = DISPLAY_MENU_FASTBOOT;
524 fastboot_msg_info->info.option_num = len;
525 fastboot_msg_info->info.option_index = option_index;
526}
527
528void msg_lock_init()
529{
530 static bool is_msg_lock_init = false;
531 struct select_msg_info *msg_lock_info;
532 msg_lock_info = &msg_info;
533
534 if (!is_msg_lock_init) {
535 mutex_init(&msg_lock_info->msg_lock);
536 is_msg_lock_init = true;
537 }
lijuang7d235f42015-07-16 20:19:45 +0800538}
539
540static void display_menu_thread_start(struct select_msg_info *msg_info)
541{
542 thread_t *thr;
543
544 if (!is_thread_start) {
545 thr = thread_create("selectkeydetect", &select_msg_keys_detect,
546 (void*)msg_info, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
547 if (!thr) {
548 dprintf(CRITICAL, "ERROR: creat device status detect thread failed!!\n");
549 return;
550 }
551 thread_resume(thr);
lijuang9a7d3b92015-11-30 14:41:24 +0800552 is_thread_start = true;
lijuang7d235f42015-07-16 20:19:45 +0800553 }
lijuang7d235f42015-07-16 20:19:45 +0800554}
555
lijuang9a7d3b92015-11-30 14:41:24 +0800556/* The fuction be called after device in fastboot mode,
557 * so it's no need to initialize the msg_lock again
558 */
lijuangf55ad052018-04-23 18:30:50 +0800559void display_unlock_menu(int type, bool status)
lijuang7d235f42015-07-16 20:19:45 +0800560{
lijuang4ece1e72015-08-14 21:02:36 +0800561 struct select_msg_info *unlock_menu_msg_info;
562 unlock_menu_msg_info = &msg_info;
lijuang7d235f42015-07-16 20:19:45 +0800563
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530564 if (is_display_disabled())
565 return;
566
lijuang7d235f42015-07-16 20:19:45 +0800567 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800568
569 msg_lock_init();
570 mutex_acquire(&unlock_menu_msg_info->msg_lock);
571
572 /* Initialize the last_msg_type */
573 unlock_menu_msg_info->last_msg_type =
574 unlock_menu_msg_info->info.msg_type;
575
lijuangf55ad052018-04-23 18:30:50 +0800576 display_unlock_menu_renew(unlock_menu_msg_info, type, status);
jialongjhanb2dda0b2020-04-21 20:20:51 +0800577 //[Arima][8901][JialongJhan] Command mode update screen 20190618 Start
578 msm_display_flush();
579 //[Arima][8901][JialongJhan] Command mode update screen 20190618 End
lijuang9a7d3b92015-11-30 14:41:24 +0800580 mutex_release(&unlock_menu_msg_info->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800581
lijuangf55ad052018-04-23 18:30:50 +0800582 dprintf(INFO, "creating %s keys detect thread\n",
583 status ? "unlock":"lock");
lijuang4ece1e72015-08-14 21:02:36 +0800584 display_menu_thread_start(unlock_menu_msg_info);
lijuang7d235f42015-07-16 20:19:45 +0800585}
586
lijuang9a7d3b92015-11-30 14:41:24 +0800587void display_fastboot_menu()
lijuang4ece1e72015-08-14 21:02:36 +0800588{
589 struct select_msg_info *fastboot_menu_msg_info;
590 fastboot_menu_msg_info = &msg_info;
591
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530592 if (is_display_disabled())
593 return;
594
lijuang4ece1e72015-08-14 21:02:36 +0800595 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800596
597 msg_lock_init();
598 mutex_acquire(&fastboot_menu_msg_info->msg_lock);
599
600 /* There are 4 pages for fastboot menu:
601 * Page: Start/Fastboot/Recovery/Poweroff
602 * The menu is switched base on the option index
603 * Initialize the option index and last_msg_type
604 */
605 fastboot_menu_msg_info->info.option_index = 0;
606 fastboot_menu_msg_info->last_msg_type =
607 fastboot_menu_msg_info->info.msg_type;
608
609 display_fastboot_menu_renew(fastboot_menu_msg_info);
jialongjhanb2dda0b2020-04-21 20:20:51 +0800610 //[Arima][8901][JialongJhan] Command mode update screen 20190618 Start
611 msm_display_flush();
612 //[Arima][8901][JialongJhan] Command mode update screen 20190618 End
lijuang9a7d3b92015-11-30 14:41:24 +0800613 mutex_release(&fastboot_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800614
615 dprintf(INFO, "creating fastboot menu keys detect thread\n");
616 display_menu_thread_start(fastboot_menu_msg_info);
617}
618
Monika Singh5e170362018-03-14 00:48:36 +0530619#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800620void display_bootverify_menu(int type)
lijuang4ece1e72015-08-14 21:02:36 +0800621{
622 struct select_msg_info *bootverify_menu_msg_info;
623 bootverify_menu_msg_info = &msg_info;
624
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530625 if (is_display_disabled())
626 return;
627
lijuang4ece1e72015-08-14 21:02:36 +0800628 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800629
630 msg_lock_init();
631 mutex_acquire(&bootverify_menu_msg_info->msg_lock);
632
633 /* Initialize the last_msg_type */
634 bootverify_menu_msg_info->last_msg_type =
635 bootverify_menu_msg_info->info.msg_type;
636
637 display_bootverify_menu_renew(bootverify_menu_msg_info, type);
jialongjhanb2dda0b2020-04-21 20:20:51 +0800638 //[Arima][8901][JialongJhan] Command mode update screen 201906118 Start
639 msm_display_flush();
640 //[Arima][8901][JialongJhan] Command mode update screen 20190618 End
lijuang9a7d3b92015-11-30 14:41:24 +0800641 mutex_release(&bootverify_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800642
643 dprintf(INFO, "creating boot verify keys detect thread\n");
644 display_menu_thread_start(bootverify_menu_msg_info);
645}
646#endif