blob: e663bdd40d51335bb69844d2bb32b781acf56409 [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>
tracychuid19990d2020-06-12 13:22:29 +080045/*[TracyChui]Show memory information on fastboot screen 20200612 start */
46#include <mmu.h>
47/*[TracyChui]Show memory information on fastboot screen 20200612 end */
Monika Singh05fff3b2019-09-16 16:00:33 +053048#define TITLE_MSG "<!>\n\n"
49
jialongjhanb2dda0b2020-04-21 20:20:51 +080050//[Arima][8901][JialongJhan] Command mode update screen 20190516 Start
51extern int msm_display_flush();
52//[Arima][8901][JialongJhan] Command mode update screen 20190516 End
lijuangf55ad052018-04-23 18:30:50 +080053static const char *unlock_menu_common_msg = "By unlocking the bootloader, you will be able to install "\
54 "custom operating system on this phone. "\
55 "A custom OS is not subject to the same level of testing "\
56 "as the original OS, and can cause your phone "\
57 "and installed applications to stop working properly.\n\n"\
58 "Software integrity cannot be guaranteed with a custom OS, "\
59 "so any data stored on the phone while the bootloader "\
60 "is unlocked may be at risk.\n\n"\
lijuang7d235f42015-07-16 20:19:45 +080061 "To prevent unauthorized access to your personal data, "\
62 "unlocking the bootloader will also delete all personal "\
lijuangf55ad052018-04-23 18:30:50 +080063 "data on your phone.\n\n"\
64 "Press the Volume keys to select whether to unlock the bootloader, "\
65 "then the Power Button to continue.\n\n";
66
67static const char *lock_menu_common_msg = "If you lock the bootloader, "\
68 "you will not be able to install "\
69 "custom operating system on this phone.\n\n"\
70 "To prevent unauthorized access to your personal data, "\
71 "locking the bootloader will also delete all personal "\
72 "data on your phone.\n\n"\
73 "Press the Volume keys to select whether to "\
74 "lock the bootloader, then the power button to continue.\n\n";
lijuang7d235f42015-07-16 20:19:45 +080075
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070076#define YELLOW_WARNING_MSG "Your device has loaded a different operating system\n\n "\
Brahmaji K0c2d5982017-09-07 18:44:21 +053077 "Visit this link on another device:\n"
lijuang7d235f42015-07-16 20:19:45 +080078
Monika Singh05fff3b2019-09-16 16:00:33 +053079#define ORANGE_WARNING_MSG "The boot loader is unlocked and software integrity cannot "\
80 "be guaranteed. Any data stored on the device may be available to attackers. "\
81 "Do not store any sensitive data on the device.\n\n"\
Brahmaji K0c2d5982017-09-07 18:44:21 +053082 "Visit this link on another device:\n"
lijuang7d235f42015-07-16 20:19:45 +080083
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070084#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 +053085 "Visit this link on another device:\n"
lijuang7d235f42015-07-16 20:19:45 +080086
lijuangbdd9bb42016-03-01 18:22:17 +080087#define LOGGING_WARNING_MSG "The dm-verity is not started in enforcing mode and may "\
88 "not work properly\n\nTo learn more, visit:\n"
89
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070090#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 +053091 "Visit this link on another device:\n"
92
Monika Singh05fff3b2019-09-16 16:00:33 +053093#define PAUSE_BOOT_MSG "PRESS POWER KEY TO PAUSE BOOT\n\n"
94
95#define CONTINUE_BOOT_MSG "PRESS POWER KEY TO CONTINUE\n\n"
96
97#define URL_MSG "g.co/ABH\n\n"
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070098
Parth Dixit54ac3bb2017-03-07 15:52:48 +053099#define DELAY_5SEC 5000
Monika Singh05fff3b2019-09-16 16:00:33 +0530100#define DELAY_10SEC 10000
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530101#define DELAY_30SEC 30000
102
lijuang7d235f42015-07-16 20:19:45 +0800103static bool is_thread_start = false;
lijuang9a7d3b92015-11-30 14:41:24 +0800104static struct select_msg_info msg_info;
lijuang7d235f42015-07-16 20:19:45 +0800105
Monika Singh5e170362018-03-14 00:48:36 +0530106#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang4ece1e72015-08-14 21:02:36 +0800107struct boot_verify_info {
108 int msg_type;
Monika Singh05fff3b2019-09-16 16:00:33 +0530109 const char *title_msg;
lijuang4ece1e72015-08-14 21:02:36 +0800110 const char *warning_msg;
Brahmaji K0c2d5982017-09-07 18:44:21 +0530111 const char *url_msg;
Monika Singh05fff3b2019-09-16 16:00:33 +0530112 const char *notice_msg;
lijuang4ece1e72015-08-14 21:02:36 +0800113};
114
115struct boot_verify_info boot_verify_info[] = {
Monika Singh05fff3b2019-09-16 16:00:33 +0530116 [DISPLAY_MENU_RED] = {FBCON_RED_MSG, TITLE_MSG, RED_WARNING_MSG, URL_MSG, NULL},
117 [DISPLAY_MENU_YELLOW] = {FBCON_YELLOW_MSG, TITLE_MSG, YELLOW_WARNING_MSG, URL_MSG, PAUSE_BOOT_MSG},
118 [DISPLAY_MENU_ORANGE] = {FBCON_ORANGE_MSG, TITLE_MSG, ORANGE_WARNING_MSG, URL_MSG, PAUSE_BOOT_MSG},
119 [DISPLAY_MENU_LOGGING] = {FBCON_RED_MSG, TITLE_MSG, LOGGING_WARNING_MSG, NULL, NULL},
120 [DISPLAY_MENU_EIO] = {FBCON_RED_MSG, TITLE_MSG, EIO_WARNING_MSG, URL_MSG, CONTINUE_BOOT_MSG}};
lijuang4ece1e72015-08-14 21:02:36 +0800121#endif
122
123static char *verify_option_menu[] = {
lijuang7d235f42015-07-16 20:19:45 +0800124 [POWEROFF] = "Power off\n",
125 [RESTART] = "Restart\n",
126 [RECOVER] = "Recovery\n",
127 [FASTBOOT] = "Fastboot\n",
128 [BACK] = "Back to previous page\n"};
129
tracychuif6dd8d72020-01-20 16:53:15 +0800130/*[20200120][TracyChui]Remove FFBM item in fastboot mode start */
lijuang4ece1e72015-08-14 21:02:36 +0800131static char *fastboot_option_menu[] = {
132 [0] = "START\n",
133 [1] = "Restart bootloader\n",
134 [2] = "Recovery mode\n",
tracychuif6dd8d72020-01-20 16:53:15 +0800135 [3] = "Power off\n"};
136/*[20200120][TracyChui]Remove FFBM item in fastboot mode end */
lijuang4ece1e72015-08-14 21:02:36 +0800137
lijuangf55ad052018-04-23 18:30:50 +0800138static struct unlock_info munlock_info[] = {
139 [DISPLAY_MENU_LOCK] = {UNLOCK, FALSE},
140 [DISPLAY_MENU_UNLOCK] = {UNLOCK, TRUE},
141 [DISPLAY_MENU_LOCK_CRITICAL] = {UNLOCK_CRITICAL, FALSE},
142 [DISPLAY_MENU_UNLOCK_CRITICAL] = {UNLOCK_CRITICAL, TRUE},
143};
144
145struct unlock_option_msg munlock_option_msg[] = {
146 [TRUE] = {"DO NOT UNLOCK THE BOOTLOADER \n", "UNLOCK THE BOOTLOADER \n"},
147 [FALSE] = {"DO NOT LOCK THE BOOTLOADER \n", "LOCK THE BOOTLOADER \n"},
148};
149
lijuang7d235f42015-07-16 20:19:45 +0800150static int big_factor = 2;
151static int common_factor = 1;
152
lijuangde34d502016-02-26 16:04:50 +0800153static void wait_for_exit()
lijuang7d235f42015-07-16 20:19:45 +0800154{
155 struct select_msg_info *select_msg;
156 select_msg = &msg_info;
157
lijuang9a7d3b92015-11-30 14:41:24 +0800158 mutex_acquire(&select_msg->msg_lock);
lijuangde34d502016-02-26 16:04:50 +0800159 while(!select_msg->info.rel_exit == true) {
lijuang9a7d3b92015-11-30 14:41:24 +0800160 mutex_release(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800161 thread_sleep(10);
lijuang9a7d3b92015-11-30 14:41:24 +0800162 mutex_acquire(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800163 }
lijuang9a7d3b92015-11-30 14:41:24 +0800164 mutex_release(&select_msg->msg_lock);
165
lijuangde34d502016-02-26 16:04:50 +0800166 is_thread_start = false;
lijuang7d235f42015-07-16 20:19:45 +0800167 fbcon_clear();
168 display_image_on_screen();
jialongjhanb2dda0b2020-04-21 20:20:51 +0800169 //[Arima][8901][JialongJhan] Command mode update screen 20190618 Start
170 msm_display_flush();
171 //[Arima][8901][JialongJhan] Command mode update screen 20190618 End
lijuang7d235f42015-07-16 20:19:45 +0800172}
173
lijuangde34d502016-02-26 16:04:50 +0800174void wait_for_users_action()
175{
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530176 if (is_display_disabled())
177 return;
lijuangde34d502016-02-26 16:04:50 +0800178 /* Waiting for exit menu keys detection if there is no any usr action
179 * otherwise it will do the action base on the keys detection thread
180 */
181 wait_for_exit();
182}
183
184void exit_menu_keys_detection()
185{
186 struct select_msg_info *select_msg;
187 select_msg = &msg_info;
188
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530189 if (is_display_disabled())
190 return;
191
lijuangde34d502016-02-26 16:04:50 +0800192 mutex_acquire(&select_msg->msg_lock);
193 select_msg->info.is_exit = true;
194 mutex_release(&select_msg->msg_lock);
195
196 wait_for_exit();
197}
198
lijuang7d235f42015-07-16 20:19:45 +0800199static void set_message_factor()
200{
201 uint32_t tmp_factor = 0;
lijuang9e73e5a2018-04-23 17:00:16 +0800202 uint32_t max_x_count = 0;
203 uint32_t max_x = 0;
204
205 if (fbcon_get_width() < fbcon_get_height())
206 max_x_count = CHAR_NUM_PERROW_POR;
207 else
208 max_x_count = CHAR_NUM_PERROW_HOR;
lijuang7d235f42015-07-16 20:19:45 +0800209
210 max_x = fbcon_get_max_x();
211 tmp_factor = max_x/max_x_count;
212
213 if(tmp_factor <= 1) {
214 big_factor = 2;
215 common_factor = 1;
216 } else {
217 big_factor = tmp_factor*2;
218 common_factor = tmp_factor;
219 }
220}
221
Monika Singh05fff3b2019-09-16 16:00:33 +0530222/* If y_start == 0, it will draw message from the current Y axis location,
223 otherwise it will start from the the value of y_start. */
lijuang7d235f42015-07-16 20:19:45 +0800224static void display_fbcon_menu_message(char *str, unsigned type,
Monika Singh05fff3b2019-09-16 16:00:33 +0530225 unsigned scale_factor, int y_start)
lijuang7d235f42015-07-16 20:19:45 +0800226{
227 while(*str != 0) {
Monika Singh05fff3b2019-09-16 16:00:33 +0530228 fbcon_putc_factor(*str++, type, scale_factor, y_start);
229 y_start = 0;
lijuang7d235f42015-07-16 20:19:45 +0800230 }
231}
232
233static char *str_align_right(char *str, int factor)
234{
235 uint32_t max_x = 0;
236 int diff = 0;
237 int i = 0;
238 char *str_target = NULL;
239
240 max_x = fbcon_get_max_x();
241 if (!str_target && max_x) {
242 str_target = malloc(max_x);
243 }
244
245 if (str_target) {
246 memset(str_target, 0, max_x);
247 if ( max_x/factor > strlen(str)) {
248 if (factor == 1)
249 diff = max_x/factor - strlen(str) - 1;
250 else
251 diff = max_x/factor - strlen(str);
252 for (i = 0; i < diff; i++) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530253 strlcat(str_target, " ", max_x);
lijuang7d235f42015-07-16 20:19:45 +0800254 }
lijuang7d235f42015-07-16 20:19:45 +0800255 }
lijuangbdb18ea2018-02-06 17:21:18 +0800256 strlcat(str_target, str, max_x);
lijuang7d235f42015-07-16 20:19:45 +0800257 }
lijuangbdb18ea2018-02-06 17:21:18 +0800258 return str_target;
lijuang7d235f42015-07-16 20:19:45 +0800259}
260
lijuangf55ad052018-04-23 18:30:50 +0800261/**
262 Reset device unlock status
263 @param[in] Type The type of the unlock.
264 [DISPLAY_MENU_UNLOCK]: unlock the device
265 [DISPLAY_MENU_UNLOCK_CRITICAL]: critical unlock the device
266 [DISPLAY_MENU_LOCK]: lock the device
267 [DISPLAY_MENU_LOCK_CRITICAL]: critical lock the device
268 **/
269void reset_device_unlock_status (int type)
270{
271 struct recovery_message msg;
272
273 if (type == DISPLAY_MENU_LOCK ||
274 type == DISPLAY_MENU_UNLOCK ||
275 type == DISPLAY_MENU_LOCK_CRITICAL ||
276 type == DISPLAY_MENU_UNLOCK_CRITICAL) {
277 set_device_unlock_value (munlock_info[type].unlock_type,
278 munlock_info[type].unlock_value);
279 memset(&msg, 0, sizeof(msg));
280 snprintf(msg.recovery, sizeof(msg.recovery), "recovery\n--wipe_data");
281 write_misc(0, &msg, sizeof(msg));
282 }
283}
284
lijuang9a7d3b92015-11-30 14:41:24 +0800285/* msg_lock need to be holded when call this function. */
lijuangf55ad052018-04-23 18:30:50 +0800286static void display_unlock_menu_renew(struct select_msg_info *unlock_msg_info,
287 int type, bool status)
lijuang7d235f42015-07-16 20:19:45 +0800288{
289 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800290 memset(&unlock_msg_info->info, 0, sizeof(struct menu_info));
291
lijuangf55ad052018-04-23 18:30:50 +0800292 display_fbcon_menu_message("<!>\n\n",
Monika Singh05fff3b2019-09-16 16:00:33 +0530293 FBCON_UNLOCK_TITLE_MSG, big_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800294
lijuangf55ad052018-04-23 18:30:50 +0800295 if (status) {
296 display_fbcon_menu_message((char*)unlock_menu_common_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530297 FBCON_COMMON_MSG, common_factor, 0);
lijuangf55ad052018-04-23 18:30:50 +0800298 } else {
299 display_fbcon_menu_message((char*)lock_menu_common_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530300 FBCON_COMMON_MSG, common_factor, 0);
lijuangf55ad052018-04-23 18:30:50 +0800301 }
302
lijuang4ece1e72015-08-14 21:02:36 +0800303 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800304 unlock_msg_info->info.option_start[0] = fbcon_get_current_line();
lijuangf55ad052018-04-23 18:30:50 +0800305 display_fbcon_menu_message((char *)munlock_option_msg[status].ignore_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530306 FBCON_COMMON_MSG, common_factor, 0);
lijuang9a7d3b92015-11-30 14:41:24 +0800307 unlock_msg_info->info.option_bg[0] = fbcon_get_current_bg();
lijuang9a7d3b92015-11-30 14:41:24 +0800308 unlock_msg_info->info.option_end[0] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800309 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800310 unlock_msg_info->info.option_start[1] = fbcon_get_current_line();
lijuangf55ad052018-04-23 18:30:50 +0800311 display_fbcon_menu_message((char *)munlock_option_msg[status].comfirm_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530312 FBCON_COMMON_MSG, common_factor, 0);
lijuang9a7d3b92015-11-30 14:41:24 +0800313 unlock_msg_info->info.option_bg[1] = fbcon_get_current_bg();
lijuang9a7d3b92015-11-30 14:41:24 +0800314 unlock_msg_info->info.option_end[1] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800315 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang7d235f42015-07-16 20:19:45 +0800316
lijuangf55ad052018-04-23 18:30:50 +0800317 if (type == UNLOCK) {
lijuang9a7d3b92015-11-30 14:41:24 +0800318 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK;
lijuangf55ad052018-04-23 18:30:50 +0800319 if (!status)
320 unlock_msg_info->info.msg_type = DISPLAY_MENU_LOCK;
321 } else if (type == UNLOCK_CRITICAL) {
lijuang9a7d3b92015-11-30 14:41:24 +0800322 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK_CRITICAL;
lijuangf55ad052018-04-23 18:30:50 +0800323 if (!status)
324 unlock_msg_info->info.msg_type = DISPLAY_MENU_LOCK_CRITICAL;
325 }
lijuang4ece1e72015-08-14 21:02:36 +0800326
lijuang9a7d3b92015-11-30 14:41:24 +0800327 unlock_msg_info->info.option_num = 2;
328
329 /* Initialize the option index */
330 unlock_msg_info->info.option_index= 2;
lijuang7d235f42015-07-16 20:19:45 +0800331}
332
Monika Singh5e170362018-03-14 00:48:36 +0530333#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800334/* msg_lock need to be holded when call this function. */
335void display_bootverify_menu_renew(struct select_msg_info *msg_info, int type)
lijuang7d235f42015-07-16 20:19:45 +0800336{
lijuang7d235f42015-07-16 20:19:45 +0800337 unsigned char* fp_buf = NULL;
338 char fp_str_temp[EVP_MAX_MD_SIZE] = {'\0'};
339 char fp_str[EVP_MAX_MD_SIZE*2] = {'\0'};
340 char str_temp[8];
lijuang7d235f42015-07-16 20:19:45 +0800341 uint32 fp_size = 0;
342 unsigned int i = 0;
Monika Singh05fff3b2019-09-16 16:00:33 +0530343 uint32_t timeout = DELAY_10SEC;
lijuang7d235f42015-07-16 20:19:45 +0800344
345 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800346 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800347
Monika Singh05fff3b2019-09-16 16:00:33 +0530348 if(boot_verify_info[type].title_msg != NULL)
349 display_fbcon_menu_message((char*)boot_verify_info[type].title_msg,
350 boot_verify_info[type].msg_type, big_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800351
lijuang4ece1e72015-08-14 21:02:36 +0800352 if(boot_verify_info[type].warning_msg != NULL)
353 display_fbcon_menu_message((char*)boot_verify_info[type].warning_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530354 FBCON_COMMON_MSG, common_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800355
Monika Singh05fff3b2019-09-16 16:00:33 +0530356 if(boot_verify_info[type].url_msg != NULL) {
357 dprintf(INFO, "display_fbcon_menu_message: Location=%d\n", fbcon_get_current_line());
Brahmaji K0c2d5982017-09-07 18:44:21 +0530358 display_fbcon_menu_message((char*)boot_verify_info[type].url_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530359 boot_verify_info[type].msg_type, common_factor, 0);
360 dprintf(INFO, "display_fbcon_menu_message: Location=%d\n", fbcon_get_current_line());
361 }
362
363 if(boot_verify_info[type].notice_msg != NULL) {
364 msg_info->info.option_start[0] = fbcon_get_current_line();
365 dprintf(INFO, "display_fbcon_menu_message: Location=%d\n", msg_info->info.option_start[0]);
366 display_fbcon_menu_message((char*)boot_verify_info[type].notice_msg,
367 FBCON_COMMON_MSG, common_factor, 0);
368 msg_info->info.option_end[0] = fbcon_get_current_line();
369 }
lijuang7d235f42015-07-16 20:19:45 +0800370
lijuang7d235f42015-07-16 20:19:45 +0800371 if (type == DISPLAY_MENU_YELLOW) {
372 fp_buf = get_boot_fingerprint(&fp_size);
373 if (fp_buf != NULL) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530374 strlcpy(fp_str_temp, (char const *)fp_buf, fp_size);
lijuang7d235f42015-07-16 20:19:45 +0800375 for (i = 0; i < fp_size; i++) {
376 if(i == fp_size - 1)
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 else
Parth Dixit73d3bd02016-01-07 14:29:41 +0530379 snprintf(str_temp, sizeof(str_temp), "%02x-", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800380
Parth Dixit73d3bd02016-01-07 14:29:41 +0530381 strlcat(fp_str, str_temp, sizeof(fp_str));
lijuang7d235f42015-07-16 20:19:45 +0800382 }
383 }
Monika Singh05fff3b2019-09-16 16:00:33 +0530384 display_fbcon_menu_message("ID:", FBCON_COMMON_MSG, common_factor, 0);
385 display_fbcon_menu_message(fp_str, FBCON_COMMON_MSG, common_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800386 }
lijuang7d235f42015-07-16 20:19:45 +0800387
Monika Singh05fff3b2019-09-16 16:00:33 +0530388 switch (type) {
389 case DISPLAY_MENU_RED:
390 timeout = DELAY_30SEC;
391 break;
392 case DISPLAY_MENU_EIO:
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530393#if ENABLE_VB_ATTEST
Monika Singh05fff3b2019-09-16 16:00:33 +0530394 timeout = DELAY_30SEC;
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530395#endif
Monika Singh05fff3b2019-09-16 16:00:33 +0530396 break;
397 default:
398 timeout = DELAY_10SEC;
399 break;
400 }
lijuang7d235f42015-07-16 20:19:45 +0800401
lijuang9a7d3b92015-11-30 14:41:24 +0800402 msg_info->info.msg_type = type;
lijuang9a7d3b92015-11-30 14:41:24 +0800403
404 /* Initialize the time out time */
Monika Singh05fff3b2019-09-16 16:00:33 +0530405 msg_info->info.timeout_time = timeout;
lijuang7d235f42015-07-16 20:19:45 +0800406}
Monika Singh05fff3b2019-09-16 16:00:33 +0530407
408void display_bootverify_menu_update (struct select_msg_info *msg_info)
409{
410 int location = msg_info->info.option_start[0];
411
412 /* clean the old msg */
413 fbcon_clear_msg (location, msg_info->info.option_end[0]);
414 display_fbcon_menu_message(CONTINUE_BOOT_MSG, FBCON_COMMON_MSG, common_factor, location);
415 msg_info->info.timeout_time = DELAY_30SEC;
416}
417
lijuang4ece1e72015-08-14 21:02:36 +0800418#endif
lijuang7d235f42015-07-16 20:19:45 +0800419
lijuang9a7d3b92015-11-30 14:41:24 +0800420/* msg_lock need to be holded when call this function. */
421void display_bootverify_option_menu_renew(struct select_msg_info *msg_info)
lijuang7d235f42015-07-16 20:19:45 +0800422{
423 int i = 0;
lijuang4ece1e72015-08-14 21:02:36 +0800424 int len = 0;
lijuang9a7d3b92015-11-30 14:41:24 +0800425
lijuang7d235f42015-07-16 20:19:45 +0800426 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800427 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800428
lijuang4ece1e72015-08-14 21:02:36 +0800429 len = ARRAY_SIZE(verify_option_menu);
lijuang7d235f42015-07-16 20:19:45 +0800430 display_fbcon_menu_message("Options menu:\n\n",
Monika Singh05fff3b2019-09-16 16:00:33 +0530431 FBCON_COMMON_MSG, big_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800432 display_fbcon_menu_message("Press volume key to select, and "\
Monika Singh05fff3b2019-09-16 16:00:33 +0530433 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800434
lijuang4ece1e72015-08-14 21:02:36 +0800435 for (i = 0; i < len; i++) {
436 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800437 msg_info->info.option_start[i] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800438 display_fbcon_menu_message(verify_option_menu[i],
Monika Singh05fff3b2019-09-16 16:00:33 +0530439 FBCON_COMMON_MSG, common_factor, 0);
lijuang9a7d3b92015-11-30 14:41:24 +0800440 msg_info->info.option_bg[i]= fbcon_get_current_bg();
441 msg_info->info.option_end[i]= fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800442 }
443
lijuang4ece1e72015-08-14 21:02:36 +0800444 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800445 msg_info->info.msg_type = DISPLAY_MENU_MORE_OPTION;
446 msg_info->info.option_num = len;
447
448 /* Initialize the option index */
449 msg_info->info.option_index= len;
lijuang4ece1e72015-08-14 21:02:36 +0800450}
451
lijuang9a7d3b92015-11-30 14:41:24 +0800452/* msg_lock need to be holded when call this function. */
453void display_fastboot_menu_renew(struct select_msg_info *fastboot_msg_info)
lijuang4ece1e72015-08-14 21:02:36 +0800454{
455 int len;
456 int msg_type = FBCON_COMMON_MSG;
457 char msg_buf[64];
458 char msg[128];
459
lijuang9a7d3b92015-11-30 14:41:24 +0800460 /* The fastboot menu is switched base on the option index
461 * So it's need to store the index for the menu switching
462 */
463 uint32_t option_index = fastboot_msg_info->info.option_index;
464
lijuang4ece1e72015-08-14 21:02:36 +0800465 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800466 memset(&fastboot_msg_info->info, 0, sizeof(struct menu_info));
lijuang4ece1e72015-08-14 21:02:36 +0800467
468 len = ARRAY_SIZE(fastboot_option_menu);
469 switch(option_index) {
470 case 0:
471 msg_type = FBCON_GREEN_MSG;
472 break;
473 case 1:
474 case 2:
475 msg_type = FBCON_RED_MSG;
476 break;
477 case 3:
lijuang42aefaa2016-04-14 15:55:17 +0800478 case 4:
lijuang4ece1e72015-08-14 21:02:36 +0800479 msg_type = FBCON_COMMON_MSG;
480 break;
481 }
482 fbcon_draw_line(msg_type);
483 display_fbcon_menu_message(fastboot_option_menu[option_index],
Monika Singh05fff3b2019-09-16 16:00:33 +0530484 msg_type, big_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800485 fbcon_draw_line(msg_type);
486 display_fbcon_menu_message("\n\nPress volume key to select, and "\
Monika Singh05fff3b2019-09-16 16:00:33 +0530487 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800488
Monika Singh05fff3b2019-09-16 16:00:33 +0530489 display_fbcon_menu_message("FASTBOOT MODE\n", FBCON_RED_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800490
491 get_product_name((unsigned char *) msg_buf);
492 snprintf(msg, sizeof(msg), "PRODUCT_NAME - %s\n", msg_buf);
Monika Singh05fff3b2019-09-16 16:00:33 +0530493 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800494
495 memset(msg_buf, 0, sizeof(msg_buf));
496 smem_get_hw_platform_name((unsigned char *) msg_buf, sizeof(msg_buf));
497 snprintf(msg, sizeof(msg), "VARIANT - %s %s\n",
498 msg_buf, target_is_emmc_boot()? "eMMC":"UFS");
Monika Singh05fff3b2019-09-16 16:00:33 +0530499 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800500
501 memset(msg_buf, 0, sizeof(msg_buf));
502 get_bootloader_version((unsigned char *) msg_buf);
503 snprintf(msg, sizeof(msg), "BOOTLOADER VERSION - %s\n",
504 msg_buf);
Monika Singh05fff3b2019-09-16 16:00:33 +0530505 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800506
507 memset(msg_buf, 0, sizeof(msg_buf));
508 get_baseband_version((unsigned char *) msg_buf);
509 snprintf(msg, sizeof(msg), "BASEBAND VERSION - %s\n",
510 msg_buf);
Monika Singh05fff3b2019-09-16 16:00:33 +0530511 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800512
513 memset(msg_buf, 0, sizeof(msg_buf));
514 target_serialno((unsigned char *) msg_buf);
515 snprintf(msg, sizeof(msg), "SERIAL NUMBER - %s\n", msg_buf);
Monika Singh05fff3b2019-09-16 16:00:33 +0530516 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800517
tracychuid19990d2020-06-12 13:22:29 +0800518 /*[TracyChui]Show memory information on fastboot screen 20200612 start */
519 dprintf(CRITICAL,"smem_get_ddr_size=%llu\n", smem_get_ddr_size());
520 if (smem_get_ddr_size() == MEM_3GB) {
521 snprintf(msg, sizeof(msg), "INTERNAL STORAGE SIZE - 32G\n");
522 } else if (smem_get_ddr_size() > MEM_3GB) {
523 if (smem_get_ddr_size() < MEM_4GB)
524 {
525 snprintf(msg, sizeof(msg), "INTERNAL STORAGE SIZE - 64G\n");
526 }
527 else
528 {
529 snprintf(msg, sizeof(msg), "INTERNAL STORAGE SIZE - \n");
530 }
531 } else {
532 snprintf(msg, sizeof(msg), "INTERNAL STORAGE SIZE - UNKNOWN\n");
533 }
534 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
535
536 memset(msg_buf, 0, sizeof(msg_buf));
537 smem_get_ddr_manufacturer_id((unsigned char *) msg_buf);
538 dprintf(CRITICAL,"smem_get_ddr_size=%llu\n", smem_get_ddr_size());
539 if (smem_get_ddr_size() == MEM_3GB) {
540 snprintf(msg, sizeof(msg), "MAIN MEMORY SIZE AND VENDOR - 3G\n");
541 } else if (smem_get_ddr_size() > MEM_3GB) {
542 if (smem_get_ddr_size() < MEM_4GB)
543 {
544 snprintf(msg, sizeof(msg), "MAIN MEMORY SIZE AND VENDOR - 4G %s\n", msg_buf);
545 }
546 else
547 {
548 snprintf(msg, sizeof(msg), "MAIN MEMORY SIZE AND VENDOR - %s\n", msg_buf);
549 }
550 } else {
551 snprintf(msg, sizeof(msg), "MAIN MEMORY SIZE AND VENDOR - %s\n", msg_buf);
552 }
553 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
554
555 /*[TracyChui]Show memory information on fastboot screen 20200612 end */
556
lijuang4ece1e72015-08-14 21:02:36 +0800557 snprintf(msg, sizeof(msg), "SECURE BOOT - %s\n",
558 is_secure_boot_enable()? "enabled":"disabled");
Monika Singh05fff3b2019-09-16 16:00:33 +0530559 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800560
561 snprintf(msg, sizeof(msg), "DEVICE STATE - %s\n",
562 is_device_locked()? "locked":"unlocked");
Monika Singh05fff3b2019-09-16 16:00:33 +0530563 display_fbcon_menu_message(msg, FBCON_RED_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800564
lijuang9a7d3b92015-11-30 14:41:24 +0800565 fastboot_msg_info->info.msg_type = DISPLAY_MENU_FASTBOOT;
566 fastboot_msg_info->info.option_num = len;
567 fastboot_msg_info->info.option_index = option_index;
568}
569
570void msg_lock_init()
571{
572 static bool is_msg_lock_init = false;
573 struct select_msg_info *msg_lock_info;
574 msg_lock_info = &msg_info;
575
576 if (!is_msg_lock_init) {
577 mutex_init(&msg_lock_info->msg_lock);
578 is_msg_lock_init = true;
579 }
lijuang7d235f42015-07-16 20:19:45 +0800580}
581
582static void display_menu_thread_start(struct select_msg_info *msg_info)
583{
584 thread_t *thr;
585
586 if (!is_thread_start) {
587 thr = thread_create("selectkeydetect", &select_msg_keys_detect,
588 (void*)msg_info, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
589 if (!thr) {
590 dprintf(CRITICAL, "ERROR: creat device status detect thread failed!!\n");
591 return;
592 }
593 thread_resume(thr);
lijuang9a7d3b92015-11-30 14:41:24 +0800594 is_thread_start = true;
lijuang7d235f42015-07-16 20:19:45 +0800595 }
lijuang7d235f42015-07-16 20:19:45 +0800596}
597
lijuang9a7d3b92015-11-30 14:41:24 +0800598/* The fuction be called after device in fastboot mode,
599 * so it's no need to initialize the msg_lock again
600 */
lijuangf55ad052018-04-23 18:30:50 +0800601void display_unlock_menu(int type, bool status)
lijuang7d235f42015-07-16 20:19:45 +0800602{
lijuang4ece1e72015-08-14 21:02:36 +0800603 struct select_msg_info *unlock_menu_msg_info;
604 unlock_menu_msg_info = &msg_info;
lijuang7d235f42015-07-16 20:19:45 +0800605
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530606 if (is_display_disabled())
607 return;
608
lijuang7d235f42015-07-16 20:19:45 +0800609 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800610
611 msg_lock_init();
612 mutex_acquire(&unlock_menu_msg_info->msg_lock);
613
614 /* Initialize the last_msg_type */
615 unlock_menu_msg_info->last_msg_type =
616 unlock_menu_msg_info->info.msg_type;
617
lijuangf55ad052018-04-23 18:30:50 +0800618 display_unlock_menu_renew(unlock_menu_msg_info, type, status);
jialongjhanb2dda0b2020-04-21 20:20:51 +0800619 //[Arima][8901][JialongJhan] Command mode update screen 20190618 Start
620 msm_display_flush();
621 //[Arima][8901][JialongJhan] Command mode update screen 20190618 End
lijuang9a7d3b92015-11-30 14:41:24 +0800622 mutex_release(&unlock_menu_msg_info->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800623
lijuangf55ad052018-04-23 18:30:50 +0800624 dprintf(INFO, "creating %s keys detect thread\n",
625 status ? "unlock":"lock");
lijuang4ece1e72015-08-14 21:02:36 +0800626 display_menu_thread_start(unlock_menu_msg_info);
lijuang7d235f42015-07-16 20:19:45 +0800627}
628
lijuang9a7d3b92015-11-30 14:41:24 +0800629void display_fastboot_menu()
lijuang4ece1e72015-08-14 21:02:36 +0800630{
631 struct select_msg_info *fastboot_menu_msg_info;
632 fastboot_menu_msg_info = &msg_info;
633
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530634 if (is_display_disabled())
635 return;
636
lijuang4ece1e72015-08-14 21:02:36 +0800637 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800638
639 msg_lock_init();
640 mutex_acquire(&fastboot_menu_msg_info->msg_lock);
641
642 /* There are 4 pages for fastboot menu:
643 * Page: Start/Fastboot/Recovery/Poweroff
644 * The menu is switched base on the option index
645 * Initialize the option index and last_msg_type
646 */
647 fastboot_menu_msg_info->info.option_index = 0;
648 fastboot_menu_msg_info->last_msg_type =
649 fastboot_menu_msg_info->info.msg_type;
650
651 display_fastboot_menu_renew(fastboot_menu_msg_info);
jialongjhanb2dda0b2020-04-21 20:20:51 +0800652 //[Arima][8901][JialongJhan] Command mode update screen 20190618 Start
653 msm_display_flush();
654 //[Arima][8901][JialongJhan] Command mode update screen 20190618 End
lijuang9a7d3b92015-11-30 14:41:24 +0800655 mutex_release(&fastboot_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800656
657 dprintf(INFO, "creating fastboot menu keys detect thread\n");
658 display_menu_thread_start(fastboot_menu_msg_info);
659}
660
Monika Singh5e170362018-03-14 00:48:36 +0530661#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800662void display_bootverify_menu(int type)
lijuang4ece1e72015-08-14 21:02:36 +0800663{
664 struct select_msg_info *bootverify_menu_msg_info;
665 bootverify_menu_msg_info = &msg_info;
666
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530667 if (is_display_disabled())
668 return;
669
lijuang4ece1e72015-08-14 21:02:36 +0800670 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800671
672 msg_lock_init();
673 mutex_acquire(&bootverify_menu_msg_info->msg_lock);
674
675 /* Initialize the last_msg_type */
676 bootverify_menu_msg_info->last_msg_type =
677 bootverify_menu_msg_info->info.msg_type;
678
679 display_bootverify_menu_renew(bootverify_menu_msg_info, type);
jialongjhanb2dda0b2020-04-21 20:20:51 +0800680 //[Arima][8901][JialongJhan] Command mode update screen 201906118 Start
681 msm_display_flush();
682 //[Arima][8901][JialongJhan] Command mode update screen 20190618 End
lijuang9a7d3b92015-11-30 14:41:24 +0800683 mutex_release(&bootverify_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800684
685 dprintf(INFO, "creating boot verify keys detect thread\n");
686 display_menu_thread_start(bootverify_menu_msg_info);
687}
688#endif