blob: 9d85e9f059b3d90ca281b2516208604ae9924902 [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
lijuangf55ad052018-04-23 18:30:50 +080048static const char *unlock_menu_common_msg = "By unlocking the bootloader, you will be able to install "\
49 "custom operating system on this phone. "\
50 "A custom OS is not subject to the same level of testing "\
51 "as the original OS, and can cause your phone "\
52 "and installed applications to stop working properly.\n\n"\
53 "Software integrity cannot be guaranteed with a custom OS, "\
54 "so any data stored on the phone while the bootloader "\
55 "is unlocked may be at risk.\n\n"\
lijuang7d235f42015-07-16 20:19:45 +080056 "To prevent unauthorized access to your personal data, "\
57 "unlocking the bootloader will also delete all personal "\
lijuangf55ad052018-04-23 18:30:50 +080058 "data on your phone.\n\n"\
59 "Press the Volume keys to select whether to unlock the bootloader, "\
60 "then the Power Button to continue.\n\n";
61
62static const char *lock_menu_common_msg = "If you lock the bootloader, "\
63 "you will not be able to install "\
64 "custom operating system on this phone.\n\n"\
65 "To prevent unauthorized access to your personal data, "\
66 "locking the bootloader will also delete all personal "\
67 "data on your phone.\n\n"\
68 "Press the Volume keys to select whether to "\
69 "lock the bootloader, then the power button to continue.\n\n";
lijuang7d235f42015-07-16 20:19:45 +080070
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070071#define YELLOW_WARNING_MSG "Your device has loaded a different operating system\n\n "\
Brahmaji K0c2d5982017-09-07 18:44:21 +053072 "Visit this link on another device:\n"
lijuang7d235f42015-07-16 20:19:45 +080073
Monika Singh05fff3b2019-09-16 16:00:33 +053074#define ORANGE_WARNING_MSG "The boot loader is unlocked and software integrity cannot "\
75 "be guaranteed. Any data stored on the device may be available to attackers. "\
76 "Do not store any sensitive data on the device.\n\n"\
Brahmaji K0c2d5982017-09-07 18:44:21 +053077 "Visit this link on another device:\n"
lijuang7d235f42015-07-16 20:19:45 +080078
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070079#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 +053080 "Visit this link on another device:\n"
lijuang7d235f42015-07-16 20:19:45 +080081
lijuangbdd9bb42016-03-01 18:22:17 +080082#define LOGGING_WARNING_MSG "The dm-verity is not started in enforcing mode and may "\
83 "not work properly\n\nTo learn more, visit:\n"
84
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070085#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 +053086 "Visit this link on another device:\n"
87
Monika Singh05fff3b2019-09-16 16:00:33 +053088#define PAUSE_BOOT_MSG "PRESS POWER KEY TO PAUSE BOOT\n\n"
89
90#define CONTINUE_BOOT_MSG "PRESS POWER KEY TO CONTINUE\n\n"
91
92#define URL_MSG "g.co/ABH\n\n"
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070093
Parth Dixit54ac3bb2017-03-07 15:52:48 +053094#define DELAY_5SEC 5000
Monika Singh05fff3b2019-09-16 16:00:33 +053095#define DELAY_10SEC 10000
Parth Dixit54ac3bb2017-03-07 15:52:48 +053096#define DELAY_30SEC 30000
97
lijuang7d235f42015-07-16 20:19:45 +080098static bool is_thread_start = false;
lijuang9a7d3b92015-11-30 14:41:24 +080099static struct select_msg_info msg_info;
lijuang7d235f42015-07-16 20:19:45 +0800100
Monika Singh5e170362018-03-14 00:48:36 +0530101#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang4ece1e72015-08-14 21:02:36 +0800102struct boot_verify_info {
103 int msg_type;
Monika Singh05fff3b2019-09-16 16:00:33 +0530104 const char *title_msg;
lijuang4ece1e72015-08-14 21:02:36 +0800105 const char *warning_msg;
Brahmaji K0c2d5982017-09-07 18:44:21 +0530106 const char *url_msg;
Monika Singh05fff3b2019-09-16 16:00:33 +0530107 const char *notice_msg;
lijuang4ece1e72015-08-14 21:02:36 +0800108};
109
110struct boot_verify_info boot_verify_info[] = {
Monika Singh05fff3b2019-09-16 16:00:33 +0530111 [DISPLAY_MENU_RED] = {FBCON_RED_MSG, TITLE_MSG, RED_WARNING_MSG, URL_MSG, NULL},
112 [DISPLAY_MENU_YELLOW] = {FBCON_YELLOW_MSG, TITLE_MSG, YELLOW_WARNING_MSG, URL_MSG, PAUSE_BOOT_MSG},
113 [DISPLAY_MENU_ORANGE] = {FBCON_ORANGE_MSG, TITLE_MSG, ORANGE_WARNING_MSG, URL_MSG, PAUSE_BOOT_MSG},
114 [DISPLAY_MENU_LOGGING] = {FBCON_RED_MSG, TITLE_MSG, LOGGING_WARNING_MSG, NULL, NULL},
115 [DISPLAY_MENU_EIO] = {FBCON_RED_MSG, TITLE_MSG, EIO_WARNING_MSG, URL_MSG, CONTINUE_BOOT_MSG}};
lijuang4ece1e72015-08-14 21:02:36 +0800116#endif
117
118static char *verify_option_menu[] = {
lijuang7d235f42015-07-16 20:19:45 +0800119 [POWEROFF] = "Power off\n",
120 [RESTART] = "Restart\n",
121 [RECOVER] = "Recovery\n",
122 [FASTBOOT] = "Fastboot\n",
123 [BACK] = "Back to previous page\n"};
124
lijuang4ece1e72015-08-14 21:02:36 +0800125static char *fastboot_option_menu[] = {
126 [0] = "START\n",
127 [1] = "Restart bootloader\n",
128 [2] = "Recovery mode\n",
lijuang42aefaa2016-04-14 15:55:17 +0800129 [3] = "Power off\n",
130 [4] = "Boot to FFBM\n"};
lijuang4ece1e72015-08-14 21:02:36 +0800131
lijuangf55ad052018-04-23 18:30:50 +0800132static struct unlock_info munlock_info[] = {
133 [DISPLAY_MENU_LOCK] = {UNLOCK, FALSE},
134 [DISPLAY_MENU_UNLOCK] = {UNLOCK, TRUE},
135 [DISPLAY_MENU_LOCK_CRITICAL] = {UNLOCK_CRITICAL, FALSE},
136 [DISPLAY_MENU_UNLOCK_CRITICAL] = {UNLOCK_CRITICAL, TRUE},
137};
138
139struct unlock_option_msg munlock_option_msg[] = {
140 [TRUE] = {"DO NOT UNLOCK THE BOOTLOADER \n", "UNLOCK THE BOOTLOADER \n"},
141 [FALSE] = {"DO NOT LOCK THE BOOTLOADER \n", "LOCK THE BOOTLOADER \n"},
142};
143
lijuang7d235f42015-07-16 20:19:45 +0800144static int big_factor = 2;
145static int common_factor = 1;
146
lijuangde34d502016-02-26 16:04:50 +0800147static void wait_for_exit()
lijuang7d235f42015-07-16 20:19:45 +0800148{
149 struct select_msg_info *select_msg;
150 select_msg = &msg_info;
151
lijuang9a7d3b92015-11-30 14:41:24 +0800152 mutex_acquire(&select_msg->msg_lock);
lijuangde34d502016-02-26 16:04:50 +0800153 while(!select_msg->info.rel_exit == true) {
lijuang9a7d3b92015-11-30 14:41:24 +0800154 mutex_release(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800155 thread_sleep(10);
lijuang9a7d3b92015-11-30 14:41:24 +0800156 mutex_acquire(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800157 }
lijuang9a7d3b92015-11-30 14:41:24 +0800158 mutex_release(&select_msg->msg_lock);
159
lijuangde34d502016-02-26 16:04:50 +0800160 is_thread_start = false;
lijuang7d235f42015-07-16 20:19:45 +0800161 fbcon_clear();
162 display_image_on_screen();
163}
164
lijuangde34d502016-02-26 16:04:50 +0800165void wait_for_users_action()
166{
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530167 if (is_display_disabled())
168 return;
lijuangde34d502016-02-26 16:04:50 +0800169 /* Waiting for exit menu keys detection if there is no any usr action
170 * otherwise it will do the action base on the keys detection thread
171 */
172 wait_for_exit();
173}
174
175void exit_menu_keys_detection()
176{
177 struct select_msg_info *select_msg;
178 select_msg = &msg_info;
179
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530180 if (is_display_disabled())
181 return;
182
lijuangde34d502016-02-26 16:04:50 +0800183 mutex_acquire(&select_msg->msg_lock);
184 select_msg->info.is_exit = true;
185 mutex_release(&select_msg->msg_lock);
186
187 wait_for_exit();
188}
189
lijuang7d235f42015-07-16 20:19:45 +0800190static void set_message_factor()
191{
192 uint32_t tmp_factor = 0;
lijuang9e73e5a2018-04-23 17:00:16 +0800193 uint32_t max_x_count = 0;
194 uint32_t max_x = 0;
195
196 if (fbcon_get_width() < fbcon_get_height())
197 max_x_count = CHAR_NUM_PERROW_POR;
198 else
199 max_x_count = CHAR_NUM_PERROW_HOR;
lijuang7d235f42015-07-16 20:19:45 +0800200
201 max_x = fbcon_get_max_x();
202 tmp_factor = max_x/max_x_count;
203
204 if(tmp_factor <= 1) {
205 big_factor = 2;
206 common_factor = 1;
207 } else {
208 big_factor = tmp_factor*2;
209 common_factor = tmp_factor;
210 }
211}
212
Monika Singh05fff3b2019-09-16 16:00:33 +0530213/* If y_start == 0, it will draw message from the current Y axis location,
214 otherwise it will start from the the value of y_start. */
lijuang7d235f42015-07-16 20:19:45 +0800215static void display_fbcon_menu_message(char *str, unsigned type,
Monika Singh05fff3b2019-09-16 16:00:33 +0530216 unsigned scale_factor, int y_start)
lijuang7d235f42015-07-16 20:19:45 +0800217{
218 while(*str != 0) {
Monika Singh05fff3b2019-09-16 16:00:33 +0530219 fbcon_putc_factor(*str++, type, scale_factor, y_start);
220 y_start = 0;
lijuang7d235f42015-07-16 20:19:45 +0800221 }
222}
223
224static char *str_align_right(char *str, int factor)
225{
226 uint32_t max_x = 0;
227 int diff = 0;
228 int i = 0;
229 char *str_target = NULL;
230
231 max_x = fbcon_get_max_x();
232 if (!str_target && max_x) {
233 str_target = malloc(max_x);
234 }
235
236 if (str_target) {
237 memset(str_target, 0, max_x);
238 if ( max_x/factor > strlen(str)) {
239 if (factor == 1)
240 diff = max_x/factor - strlen(str) - 1;
241 else
242 diff = max_x/factor - strlen(str);
243 for (i = 0; i < diff; i++) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530244 strlcat(str_target, " ", max_x);
lijuang7d235f42015-07-16 20:19:45 +0800245 }
lijuang7d235f42015-07-16 20:19:45 +0800246 }
lijuangbdb18ea2018-02-06 17:21:18 +0800247 strlcat(str_target, str, max_x);
lijuang7d235f42015-07-16 20:19:45 +0800248 }
lijuangbdb18ea2018-02-06 17:21:18 +0800249 return str_target;
lijuang7d235f42015-07-16 20:19:45 +0800250}
251
lijuangf55ad052018-04-23 18:30:50 +0800252/**
253 Reset device unlock status
254 @param[in] Type The type of the unlock.
255 [DISPLAY_MENU_UNLOCK]: unlock the device
256 [DISPLAY_MENU_UNLOCK_CRITICAL]: critical unlock the device
257 [DISPLAY_MENU_LOCK]: lock the device
258 [DISPLAY_MENU_LOCK_CRITICAL]: critical lock the device
259 **/
260void reset_device_unlock_status (int type)
261{
262 struct recovery_message msg;
263
264 if (type == DISPLAY_MENU_LOCK ||
265 type == DISPLAY_MENU_UNLOCK ||
266 type == DISPLAY_MENU_LOCK_CRITICAL ||
267 type == DISPLAY_MENU_UNLOCK_CRITICAL) {
268 set_device_unlock_value (munlock_info[type].unlock_type,
269 munlock_info[type].unlock_value);
270 memset(&msg, 0, sizeof(msg));
271 snprintf(msg.recovery, sizeof(msg.recovery), "recovery\n--wipe_data");
272 write_misc(0, &msg, sizeof(msg));
273 }
274}
275
lijuang9a7d3b92015-11-30 14:41:24 +0800276/* msg_lock need to be holded when call this function. */
lijuangf55ad052018-04-23 18:30:50 +0800277static void display_unlock_menu_renew(struct select_msg_info *unlock_msg_info,
278 int type, bool status)
lijuang7d235f42015-07-16 20:19:45 +0800279{
280 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800281 memset(&unlock_msg_info->info, 0, sizeof(struct menu_info));
282
lijuangf55ad052018-04-23 18:30:50 +0800283 display_fbcon_menu_message("<!>\n\n",
Monika Singh05fff3b2019-09-16 16:00:33 +0530284 FBCON_UNLOCK_TITLE_MSG, big_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800285
lijuangf55ad052018-04-23 18:30:50 +0800286 if (status) {
287 display_fbcon_menu_message((char*)unlock_menu_common_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530288 FBCON_COMMON_MSG, common_factor, 0);
lijuangf55ad052018-04-23 18:30:50 +0800289 } else {
290 display_fbcon_menu_message((char*)lock_menu_common_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530291 FBCON_COMMON_MSG, common_factor, 0);
lijuangf55ad052018-04-23 18:30:50 +0800292 }
293
lijuang4ece1e72015-08-14 21:02:36 +0800294 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800295 unlock_msg_info->info.option_start[0] = fbcon_get_current_line();
lijuangf55ad052018-04-23 18:30:50 +0800296 display_fbcon_menu_message((char *)munlock_option_msg[status].ignore_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530297 FBCON_COMMON_MSG, common_factor, 0);
lijuang9a7d3b92015-11-30 14:41:24 +0800298 unlock_msg_info->info.option_bg[0] = fbcon_get_current_bg();
lijuang9a7d3b92015-11-30 14:41:24 +0800299 unlock_msg_info->info.option_end[0] = fbcon_get_current_line();
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[1] = fbcon_get_current_line();
lijuangf55ad052018-04-23 18:30:50 +0800302 display_fbcon_menu_message((char *)munlock_option_msg[status].comfirm_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[1] = fbcon_get_current_bg();
lijuang9a7d3b92015-11-30 14:41:24 +0800305 unlock_msg_info->info.option_end[1] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800306 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang7d235f42015-07-16 20:19:45 +0800307
lijuangf55ad052018-04-23 18:30:50 +0800308 if (type == UNLOCK) {
lijuang9a7d3b92015-11-30 14:41:24 +0800309 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK;
lijuangf55ad052018-04-23 18:30:50 +0800310 if (!status)
311 unlock_msg_info->info.msg_type = DISPLAY_MENU_LOCK;
312 } else if (type == UNLOCK_CRITICAL) {
lijuang9a7d3b92015-11-30 14:41:24 +0800313 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK_CRITICAL;
lijuangf55ad052018-04-23 18:30:50 +0800314 if (!status)
315 unlock_msg_info->info.msg_type = DISPLAY_MENU_LOCK_CRITICAL;
316 }
lijuang4ece1e72015-08-14 21:02:36 +0800317
lijuang9a7d3b92015-11-30 14:41:24 +0800318 unlock_msg_info->info.option_num = 2;
319
320 /* Initialize the option index */
321 unlock_msg_info->info.option_index= 2;
lijuang7d235f42015-07-16 20:19:45 +0800322}
323
Monika Singh5e170362018-03-14 00:48:36 +0530324#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800325/* msg_lock need to be holded when call this function. */
326void display_bootverify_menu_renew(struct select_msg_info *msg_info, int type)
lijuang7d235f42015-07-16 20:19:45 +0800327{
lijuang7d235f42015-07-16 20:19:45 +0800328 unsigned char* fp_buf = NULL;
329 char fp_str_temp[EVP_MAX_MD_SIZE] = {'\0'};
330 char fp_str[EVP_MAX_MD_SIZE*2] = {'\0'};
331 char str_temp[8];
lijuang7d235f42015-07-16 20:19:45 +0800332 uint32 fp_size = 0;
333 unsigned int i = 0;
Monika Singh05fff3b2019-09-16 16:00:33 +0530334 uint32_t timeout = DELAY_10SEC;
lijuang7d235f42015-07-16 20:19:45 +0800335
336 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800337 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800338
Monika Singh05fff3b2019-09-16 16:00:33 +0530339 if(boot_verify_info[type].title_msg != NULL)
340 display_fbcon_menu_message((char*)boot_verify_info[type].title_msg,
341 boot_verify_info[type].msg_type, big_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800342
lijuang4ece1e72015-08-14 21:02:36 +0800343 if(boot_verify_info[type].warning_msg != NULL)
344 display_fbcon_menu_message((char*)boot_verify_info[type].warning_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530345 FBCON_COMMON_MSG, common_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800346
Monika Singh05fff3b2019-09-16 16:00:33 +0530347 if(boot_verify_info[type].url_msg != NULL) {
348 dprintf(INFO, "display_fbcon_menu_message: Location=%d\n", fbcon_get_current_line());
Brahmaji K0c2d5982017-09-07 18:44:21 +0530349 display_fbcon_menu_message((char*)boot_verify_info[type].url_msg,
Monika Singh05fff3b2019-09-16 16:00:33 +0530350 boot_verify_info[type].msg_type, common_factor, 0);
351 dprintf(INFO, "display_fbcon_menu_message: Location=%d\n", fbcon_get_current_line());
352 }
353
354 if(boot_verify_info[type].notice_msg != NULL) {
355 msg_info->info.option_start[0] = fbcon_get_current_line();
356 dprintf(INFO, "display_fbcon_menu_message: Location=%d\n", msg_info->info.option_start[0]);
357 display_fbcon_menu_message((char*)boot_verify_info[type].notice_msg,
358 FBCON_COMMON_MSG, common_factor, 0);
359 msg_info->info.option_end[0] = fbcon_get_current_line();
360 }
lijuang7d235f42015-07-16 20:19:45 +0800361
lijuang7d235f42015-07-16 20:19:45 +0800362 if (type == DISPLAY_MENU_YELLOW) {
363 fp_buf = get_boot_fingerprint(&fp_size);
364 if (fp_buf != NULL) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530365 strlcpy(fp_str_temp, (char const *)fp_buf, fp_size);
lijuang7d235f42015-07-16 20:19:45 +0800366 for (i = 0; i < fp_size; i++) {
367 if(i == fp_size - 1)
Parth Dixit73d3bd02016-01-07 14:29:41 +0530368 snprintf(str_temp, sizeof(str_temp), "%02x", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800369 else
Parth Dixit73d3bd02016-01-07 14:29:41 +0530370 snprintf(str_temp, sizeof(str_temp), "%02x-", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800371
Parth Dixit73d3bd02016-01-07 14:29:41 +0530372 strlcat(fp_str, str_temp, sizeof(fp_str));
lijuang7d235f42015-07-16 20:19:45 +0800373 }
374 }
Monika Singh05fff3b2019-09-16 16:00:33 +0530375 display_fbcon_menu_message("ID:", FBCON_COMMON_MSG, common_factor, 0);
376 display_fbcon_menu_message(fp_str, FBCON_COMMON_MSG, common_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800377 }
lijuang7d235f42015-07-16 20:19:45 +0800378
Monika Singh05fff3b2019-09-16 16:00:33 +0530379 switch (type) {
380 case DISPLAY_MENU_RED:
381 timeout = DELAY_30SEC;
382 break;
383 case DISPLAY_MENU_EIO:
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530384#if ENABLE_VB_ATTEST
Monika Singh05fff3b2019-09-16 16:00:33 +0530385 timeout = DELAY_30SEC;
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530386#endif
Monika Singh05fff3b2019-09-16 16:00:33 +0530387 break;
388 default:
389 timeout = DELAY_10SEC;
390 break;
391 }
lijuang7d235f42015-07-16 20:19:45 +0800392
lijuang9a7d3b92015-11-30 14:41:24 +0800393 msg_info->info.msg_type = type;
lijuang9a7d3b92015-11-30 14:41:24 +0800394
395 /* Initialize the time out time */
Monika Singh05fff3b2019-09-16 16:00:33 +0530396 msg_info->info.timeout_time = timeout;
lijuang7d235f42015-07-16 20:19:45 +0800397}
Monika Singh05fff3b2019-09-16 16:00:33 +0530398
399void display_bootverify_menu_update (struct select_msg_info *msg_info)
400{
401 int location = msg_info->info.option_start[0];
402
403 /* clean the old msg */
404 fbcon_clear_msg (location, msg_info->info.option_end[0]);
405 display_fbcon_menu_message(CONTINUE_BOOT_MSG, FBCON_COMMON_MSG, common_factor, location);
406 msg_info->info.timeout_time = DELAY_30SEC;
407}
408
lijuang4ece1e72015-08-14 21:02:36 +0800409#endif
lijuang7d235f42015-07-16 20:19:45 +0800410
lijuang9a7d3b92015-11-30 14:41:24 +0800411/* msg_lock need to be holded when call this function. */
412void display_bootverify_option_menu_renew(struct select_msg_info *msg_info)
lijuang7d235f42015-07-16 20:19:45 +0800413{
414 int i = 0;
lijuang4ece1e72015-08-14 21:02:36 +0800415 int len = 0;
lijuang9a7d3b92015-11-30 14:41:24 +0800416
lijuang7d235f42015-07-16 20:19:45 +0800417 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800418 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800419
lijuang4ece1e72015-08-14 21:02:36 +0800420 len = ARRAY_SIZE(verify_option_menu);
lijuang7d235f42015-07-16 20:19:45 +0800421 display_fbcon_menu_message("Options menu:\n\n",
Monika Singh05fff3b2019-09-16 16:00:33 +0530422 FBCON_COMMON_MSG, big_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800423 display_fbcon_menu_message("Press volume key to select, and "\
Monika Singh05fff3b2019-09-16 16:00:33 +0530424 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor, 0);
lijuang7d235f42015-07-16 20:19:45 +0800425
lijuang4ece1e72015-08-14 21:02:36 +0800426 for (i = 0; i < len; i++) {
427 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800428 msg_info->info.option_start[i] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800429 display_fbcon_menu_message(verify_option_menu[i],
Monika Singh05fff3b2019-09-16 16:00:33 +0530430 FBCON_COMMON_MSG, common_factor, 0);
lijuang9a7d3b92015-11-30 14:41:24 +0800431 msg_info->info.option_bg[i]= fbcon_get_current_bg();
432 msg_info->info.option_end[i]= fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800433 }
434
lijuang4ece1e72015-08-14 21:02:36 +0800435 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800436 msg_info->info.msg_type = DISPLAY_MENU_MORE_OPTION;
437 msg_info->info.option_num = len;
438
439 /* Initialize the option index */
440 msg_info->info.option_index= len;
lijuang4ece1e72015-08-14 21:02:36 +0800441}
442
lijuang9a7d3b92015-11-30 14:41:24 +0800443/* msg_lock need to be holded when call this function. */
444void display_fastboot_menu_renew(struct select_msg_info *fastboot_msg_info)
lijuang4ece1e72015-08-14 21:02:36 +0800445{
446 int len;
447 int msg_type = FBCON_COMMON_MSG;
448 char msg_buf[64];
449 char msg[128];
450
lijuang9a7d3b92015-11-30 14:41:24 +0800451 /* The fastboot menu is switched base on the option index
452 * So it's need to store the index for the menu switching
453 */
454 uint32_t option_index = fastboot_msg_info->info.option_index;
455
lijuang4ece1e72015-08-14 21:02:36 +0800456 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800457 memset(&fastboot_msg_info->info, 0, sizeof(struct menu_info));
lijuang4ece1e72015-08-14 21:02:36 +0800458
459 len = ARRAY_SIZE(fastboot_option_menu);
460 switch(option_index) {
461 case 0:
462 msg_type = FBCON_GREEN_MSG;
463 break;
464 case 1:
465 case 2:
466 msg_type = FBCON_RED_MSG;
467 break;
468 case 3:
lijuang42aefaa2016-04-14 15:55:17 +0800469 case 4:
lijuang4ece1e72015-08-14 21:02:36 +0800470 msg_type = FBCON_COMMON_MSG;
471 break;
472 }
473 fbcon_draw_line(msg_type);
474 display_fbcon_menu_message(fastboot_option_menu[option_index],
Monika Singh05fff3b2019-09-16 16:00:33 +0530475 msg_type, big_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800476 fbcon_draw_line(msg_type);
477 display_fbcon_menu_message("\n\nPress volume key to select, and "\
Monika Singh05fff3b2019-09-16 16:00:33 +0530478 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800479
Monika Singh05fff3b2019-09-16 16:00:33 +0530480 display_fbcon_menu_message("FASTBOOT MODE\n", FBCON_RED_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800481
482 get_product_name((unsigned char *) msg_buf);
483 snprintf(msg, sizeof(msg), "PRODUCT_NAME - %s\n", msg_buf);
Monika Singh05fff3b2019-09-16 16:00:33 +0530484 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800485
486 memset(msg_buf, 0, sizeof(msg_buf));
487 smem_get_hw_platform_name((unsigned char *) msg_buf, sizeof(msg_buf));
488 snprintf(msg, sizeof(msg), "VARIANT - %s %s\n",
489 msg_buf, target_is_emmc_boot()? "eMMC":"UFS");
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 get_bootloader_version((unsigned char *) msg_buf);
494 snprintf(msg, sizeof(msg), "BOOTLOADER VERSION - %s\n",
495 msg_buf);
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_baseband_version((unsigned char *) msg_buf);
500 snprintf(msg, sizeof(msg), "BASEBAND 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 target_serialno((unsigned char *) msg_buf);
506 snprintf(msg, sizeof(msg), "SERIAL NUMBER - %s\n", msg_buf);
Monika Singh05fff3b2019-09-16 16:00:33 +0530507 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800508
509 snprintf(msg, sizeof(msg), "SECURE BOOT - %s\n",
510 is_secure_boot_enable()? "enabled":"disabled");
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 snprintf(msg, sizeof(msg), "DEVICE STATE - %s\n",
514 is_device_locked()? "locked":"unlocked");
Monika Singh05fff3b2019-09-16 16:00:33 +0530515 display_fbcon_menu_message(msg, FBCON_RED_MSG, common_factor, 0);
lijuang4ece1e72015-08-14 21:02:36 +0800516
lijuang9a7d3b92015-11-30 14:41:24 +0800517 fastboot_msg_info->info.msg_type = DISPLAY_MENU_FASTBOOT;
518 fastboot_msg_info->info.option_num = len;
519 fastboot_msg_info->info.option_index = option_index;
520}
521
522void msg_lock_init()
523{
524 static bool is_msg_lock_init = false;
525 struct select_msg_info *msg_lock_info;
526 msg_lock_info = &msg_info;
527
528 if (!is_msg_lock_init) {
529 mutex_init(&msg_lock_info->msg_lock);
530 is_msg_lock_init = true;
531 }
lijuang7d235f42015-07-16 20:19:45 +0800532}
533
534static void display_menu_thread_start(struct select_msg_info *msg_info)
535{
536 thread_t *thr;
537
538 if (!is_thread_start) {
539 thr = thread_create("selectkeydetect", &select_msg_keys_detect,
540 (void*)msg_info, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
541 if (!thr) {
542 dprintf(CRITICAL, "ERROR: creat device status detect thread failed!!\n");
543 return;
544 }
545 thread_resume(thr);
lijuang9a7d3b92015-11-30 14:41:24 +0800546 is_thread_start = true;
lijuang7d235f42015-07-16 20:19:45 +0800547 }
lijuang7d235f42015-07-16 20:19:45 +0800548}
549
lijuang9a7d3b92015-11-30 14:41:24 +0800550/* The fuction be called after device in fastboot mode,
551 * so it's no need to initialize the msg_lock again
552 */
lijuangf55ad052018-04-23 18:30:50 +0800553void display_unlock_menu(int type, bool status)
lijuang7d235f42015-07-16 20:19:45 +0800554{
lijuang4ece1e72015-08-14 21:02:36 +0800555 struct select_msg_info *unlock_menu_msg_info;
556 unlock_menu_msg_info = &msg_info;
lijuang7d235f42015-07-16 20:19:45 +0800557
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530558 if (is_display_disabled())
559 return;
560
lijuang7d235f42015-07-16 20:19:45 +0800561 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800562
563 msg_lock_init();
564 mutex_acquire(&unlock_menu_msg_info->msg_lock);
565
566 /* Initialize the last_msg_type */
567 unlock_menu_msg_info->last_msg_type =
568 unlock_menu_msg_info->info.msg_type;
569
lijuangf55ad052018-04-23 18:30:50 +0800570 display_unlock_menu_renew(unlock_menu_msg_info, type, status);
lijuang9a7d3b92015-11-30 14:41:24 +0800571 mutex_release(&unlock_menu_msg_info->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800572
lijuangf55ad052018-04-23 18:30:50 +0800573 dprintf(INFO, "creating %s keys detect thread\n",
574 status ? "unlock":"lock");
lijuang4ece1e72015-08-14 21:02:36 +0800575 display_menu_thread_start(unlock_menu_msg_info);
lijuang7d235f42015-07-16 20:19:45 +0800576}
577
lijuang9a7d3b92015-11-30 14:41:24 +0800578void display_fastboot_menu()
lijuang4ece1e72015-08-14 21:02:36 +0800579{
580 struct select_msg_info *fastboot_menu_msg_info;
581 fastboot_menu_msg_info = &msg_info;
582
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530583 if (is_display_disabled())
584 return;
585
lijuang4ece1e72015-08-14 21:02:36 +0800586 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800587
588 msg_lock_init();
589 mutex_acquire(&fastboot_menu_msg_info->msg_lock);
590
591 /* There are 4 pages for fastboot menu:
592 * Page: Start/Fastboot/Recovery/Poweroff
593 * The menu is switched base on the option index
594 * Initialize the option index and last_msg_type
595 */
596 fastboot_menu_msg_info->info.option_index = 0;
597 fastboot_menu_msg_info->last_msg_type =
598 fastboot_menu_msg_info->info.msg_type;
599
600 display_fastboot_menu_renew(fastboot_menu_msg_info);
601 mutex_release(&fastboot_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800602
603 dprintf(INFO, "creating fastboot menu keys detect thread\n");
604 display_menu_thread_start(fastboot_menu_msg_info);
605}
606
Monika Singh5e170362018-03-14 00:48:36 +0530607#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800608void display_bootverify_menu(int type)
lijuang4ece1e72015-08-14 21:02:36 +0800609{
610 struct select_msg_info *bootverify_menu_msg_info;
611 bootverify_menu_msg_info = &msg_info;
612
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530613 if (is_display_disabled())
614 return;
615
lijuang4ece1e72015-08-14 21:02:36 +0800616 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800617
618 msg_lock_init();
619 mutex_acquire(&bootverify_menu_msg_info->msg_lock);
620
621 /* Initialize the last_msg_type */
622 bootverify_menu_msg_info->last_msg_type =
623 bootverify_menu_msg_info->info.msg_type;
624
625 display_bootverify_menu_renew(bootverify_menu_msg_info, type);
626 mutex_release(&bootverify_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800627
628 dprintf(INFO, "creating boot verify keys detect thread\n");
629 display_menu_thread_start(bootverify_menu_msg_info);
630}
631#endif