blob: c9a58a8afec7969ddec7d0584f9465fb580ce9fe [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>
lijuang7d235f42015-07-16 20:19:45 +080044
lijuang4ece1e72015-08-14 21:02:36 +080045static const char *unlock_menu_common_msg = "If you unlock the bootloader, "\
lijuang7d235f42015-07-16 20:19:45 +080046 "you will be able to install "\
47 "custom operating system on this phone.\n\n"\
48 "A custom OS is not subject to the same testing "\
49 "as the original OS, "\
50 "and can cause your phone and installed "\
51 "applications to stop working properly.\n\n"\
52 "To prevent unauthorized access to your personal data, "\
53 "unlocking the bootloader will also delete all personal "\
lijuang57d48b82016-01-20 17:23:50 +080054 "data from your phone(a \"factory data reset\").\n\n"\
lijuang7d235f42015-07-16 20:19:45 +080055 "Press the Volume Up/Down buttons to select Yes "\
56 "or No. Then press the Power button to continue.\n";
57
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070058#define YELLOW_WARNING_MSG "Your device has loaded a different operating system\n\n "\
Brahmaji K0c2d5982017-09-07 18:44:21 +053059 "Visit this link on another device:\n"
lijuang7d235f42015-07-16 20:19:45 +080060
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070061#define ORANGE_WARNING_MSG "Your device software can't be\n checked for corruption. Please lock the bootloader\n\n"\
Brahmaji K0c2d5982017-09-07 18:44:21 +053062 "Visit this link on another device:\n"
lijuang7d235f42015-07-16 20:19:45 +080063
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070064#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 +053065 "Visit this link on another device:\n"
lijuang7d235f42015-07-16 20:19:45 +080066
lijuangbdd9bb42016-03-01 18:22:17 +080067#define LOGGING_WARNING_MSG "The dm-verity is not started in enforcing mode and may "\
68 "not work properly\n\nTo learn more, visit:\n"
69
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070070#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 +053071 "Visit this link on another device:\n"
72
73#define URL_MSG "g.co/ABH\n"
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070074
Parth Dixit54ac3bb2017-03-07 15:52:48 +053075#define DELAY_5SEC 5000
76#define DELAY_30SEC 30000
77
lijuang7d235f42015-07-16 20:19:45 +080078static bool is_thread_start = false;
lijuang9a7d3b92015-11-30 14:41:24 +080079static struct select_msg_info msg_info;
lijuang7d235f42015-07-16 20:19:45 +080080
Monika Singh5e170362018-03-14 00:48:36 +053081#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang4ece1e72015-08-14 21:02:36 +080082struct boot_verify_info {
83 int msg_type;
84 const char *warning_msg;
Brahmaji K0c2d5982017-09-07 18:44:21 +053085 const char *url_msg;
lijuang4ece1e72015-08-14 21:02:36 +080086};
87
88struct boot_verify_info boot_verify_info[] = {
Brahmaji K0c2d5982017-09-07 18:44:21 +053089 [DISPLAY_MENU_RED] = {FBCON_RED_MSG, RED_WARNING_MSG, URL_MSG},
90 [DISPLAY_MENU_YELLOW] = {FBCON_YELLOW_MSG, YELLOW_WARNING_MSG, URL_MSG},
91 [DISPLAY_MENU_ORANGE] = {FBCON_ORANGE_MSG, ORANGE_WARNING_MSG, URL_MSG},
92 [DISPLAY_MENU_LOGGING] = {FBCON_RED_MSG, LOGGING_WARNING_MSG, NULL},
93 [DISPLAY_MENU_EIO] = {FBCON_RED_MSG, EIO_WARNING_MSG, URL_MSG}};
lijuang4ece1e72015-08-14 21:02:36 +080094#endif
95
96static char *verify_option_menu[] = {
lijuang7d235f42015-07-16 20:19:45 +080097 [POWEROFF] = "Power off\n",
98 [RESTART] = "Restart\n",
99 [RECOVER] = "Recovery\n",
100 [FASTBOOT] = "Fastboot\n",
101 [BACK] = "Back to previous page\n"};
102
lijuang4ece1e72015-08-14 21:02:36 +0800103static char *fastboot_option_menu[] = {
104 [0] = "START\n",
105 [1] = "Restart bootloader\n",
106 [2] = "Recovery mode\n",
lijuang42aefaa2016-04-14 15:55:17 +0800107 [3] = "Power off\n",
108 [4] = "Boot to FFBM\n"};
lijuang4ece1e72015-08-14 21:02:36 +0800109
lijuang7d235f42015-07-16 20:19:45 +0800110static int big_factor = 2;
111static int common_factor = 1;
112
lijuangde34d502016-02-26 16:04:50 +0800113static void wait_for_exit()
lijuang7d235f42015-07-16 20:19:45 +0800114{
115 struct select_msg_info *select_msg;
116 select_msg = &msg_info;
117
lijuang9a7d3b92015-11-30 14:41:24 +0800118 mutex_acquire(&select_msg->msg_lock);
lijuangde34d502016-02-26 16:04:50 +0800119 while(!select_msg->info.rel_exit == true) {
lijuang9a7d3b92015-11-30 14:41:24 +0800120 mutex_release(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800121 thread_sleep(10);
lijuang9a7d3b92015-11-30 14:41:24 +0800122 mutex_acquire(&select_msg->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800123 }
lijuang9a7d3b92015-11-30 14:41:24 +0800124 mutex_release(&select_msg->msg_lock);
125
lijuangde34d502016-02-26 16:04:50 +0800126 is_thread_start = false;
lijuang7d235f42015-07-16 20:19:45 +0800127 fbcon_clear();
128 display_image_on_screen();
129}
130
lijuangde34d502016-02-26 16:04:50 +0800131void wait_for_users_action()
132{
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530133 if (is_display_disabled())
134 return;
lijuangde34d502016-02-26 16:04:50 +0800135 /* Waiting for exit menu keys detection if there is no any usr action
136 * otherwise it will do the action base on the keys detection thread
137 */
138 wait_for_exit();
139}
140
141void exit_menu_keys_detection()
142{
143 struct select_msg_info *select_msg;
144 select_msg = &msg_info;
145
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530146 if (is_display_disabled())
147 return;
148
lijuangde34d502016-02-26 16:04:50 +0800149 mutex_acquire(&select_msg->msg_lock);
150 select_msg->info.is_exit = true;
151 mutex_release(&select_msg->msg_lock);
152
153 wait_for_exit();
154}
155
lijuang7d235f42015-07-16 20:19:45 +0800156static void set_message_factor()
157{
158 uint32_t tmp_factor = 0;
159 uint32_t max_x_count = 40;
160 uint32_t max_x = fbcon_get_max_x();
161
162 max_x = fbcon_get_max_x();
163 tmp_factor = max_x/max_x_count;
164
165 if(tmp_factor <= 1) {
166 big_factor = 2;
167 common_factor = 1;
168 } else {
169 big_factor = tmp_factor*2;
170 common_factor = tmp_factor;
171 }
172}
173
174static void display_fbcon_menu_message(char *str, unsigned type,
175 unsigned scale_factor)
176{
177 while(*str != 0) {
178 fbcon_putc_factor(*str++, type, scale_factor);
179 }
180}
181
182static char *str_align_right(char *str, int factor)
183{
184 uint32_t max_x = 0;
185 int diff = 0;
186 int i = 0;
187 char *str_target = NULL;
188
189 max_x = fbcon_get_max_x();
190 if (!str_target && max_x) {
191 str_target = malloc(max_x);
192 }
193
194 if (str_target) {
195 memset(str_target, 0, max_x);
196 if ( max_x/factor > strlen(str)) {
197 if (factor == 1)
198 diff = max_x/factor - strlen(str) - 1;
199 else
200 diff = max_x/factor - strlen(str);
201 for (i = 0; i < diff; i++) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530202 strlcat(str_target, " ", max_x);
lijuang7d235f42015-07-16 20:19:45 +0800203 }
lijuang7d235f42015-07-16 20:19:45 +0800204 }
lijuangbdb18ea2018-02-06 17:21:18 +0800205 strlcat(str_target, str, max_x);
lijuang7d235f42015-07-16 20:19:45 +0800206 }
lijuangbdb18ea2018-02-06 17:21:18 +0800207 return str_target;
lijuang7d235f42015-07-16 20:19:45 +0800208}
209
lijuang9a7d3b92015-11-30 14:41:24 +0800210/* msg_lock need to be holded when call this function. */
211void display_unlock_menu_renew(struct select_msg_info *unlock_msg_info, int type)
lijuang7d235f42015-07-16 20:19:45 +0800212{
213 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800214 memset(&unlock_msg_info->info, 0, sizeof(struct menu_info));
215
lijuang7d235f42015-07-16 20:19:45 +0800216 display_fbcon_menu_message("Unlock bootloader?\n",
217 FBCON_UNLOCK_TITLE_MSG, big_factor);
lijuang4ece1e72015-08-14 21:02:36 +0800218 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang7d235f42015-07-16 20:19:45 +0800219
lijuang4ece1e72015-08-14 21:02:36 +0800220 display_fbcon_menu_message((char*)unlock_menu_common_msg,
lijuang7d235f42015-07-16 20:19:45 +0800221 FBCON_COMMON_MSG, common_factor);
lijuang4ece1e72015-08-14 21:02:36 +0800222 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800223 unlock_msg_info->info.option_start[0] = fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800224 display_fbcon_menu_message("Yes\n",
225 FBCON_COMMON_MSG, big_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800226 unlock_msg_info->info.option_bg[0] = fbcon_get_current_bg();
lijuang7d235f42015-07-16 20:19:45 +0800227 display_fbcon_menu_message("Unlock bootloader(may void warranty)\n",
228 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800229 unlock_msg_info->info.option_end[0] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800230 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800231 unlock_msg_info->info.option_start[1] = fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800232 display_fbcon_menu_message("No\n",
233 FBCON_COMMON_MSG, big_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800234 unlock_msg_info->info.option_bg[1] = fbcon_get_current_bg();
lijuang7d235f42015-07-16 20:19:45 +0800235 display_fbcon_menu_message("Do not unlock bootloader and restart phone\n",
236 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800237 unlock_msg_info->info.option_end[1] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800238 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang7d235f42015-07-16 20:19:45 +0800239
lijuang4ece1e72015-08-14 21:02:36 +0800240 if (type == UNLOCK)
lijuang9a7d3b92015-11-30 14:41:24 +0800241 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK;
lijuang4ece1e72015-08-14 21:02:36 +0800242 else if (type == UNLOCK_CRITICAL)
lijuang9a7d3b92015-11-30 14:41:24 +0800243 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK_CRITICAL;
lijuang4ece1e72015-08-14 21:02:36 +0800244
lijuang9a7d3b92015-11-30 14:41:24 +0800245 unlock_msg_info->info.option_num = 2;
246
247 /* Initialize the option index */
248 unlock_msg_info->info.option_index= 2;
lijuang7d235f42015-07-16 20:19:45 +0800249}
250
Monika Singh5e170362018-03-14 00:48:36 +0530251#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800252/* msg_lock need to be holded when call this function. */
253void display_bootverify_menu_renew(struct select_msg_info *msg_info, int type)
lijuang7d235f42015-07-16 20:19:45 +0800254{
lijuang7d235f42015-07-16 20:19:45 +0800255 unsigned char* fp_buf = NULL;
256 char fp_str_temp[EVP_MAX_MD_SIZE] = {'\0'};
257 char fp_str[EVP_MAX_MD_SIZE*2] = {'\0'};
258 char str_temp[8];
259
260 char str1[]= "Start >";
261 char str2[] = "Continue boot";
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530262 char *str3 = NULL;
263
lijuang7d235f42015-07-16 20:19:45 +0800264 char *str_target = NULL;
265 uint32 fp_size = 0;
266 unsigned int i = 0;
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530267 uint32_t timeout = DELAY_5SEC;
lijuang7d235f42015-07-16 20:19:45 +0800268
269 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800270 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800271
lijuang7d235f42015-07-16 20:19:45 +0800272 /* Align Right */
273 str_target = str_align_right(str1, big_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800274 if(str_target != NULL) {
Sridhar Parasuram995a3552015-08-22 08:46:10 -0700275 display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, big_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800276 free(str_target);
277 }
lijuang7d235f42015-07-16 20:19:45 +0800278
279 str_target = str_align_right(str2, common_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800280 if(str_target != NULL) {
Sridhar Parasuram995a3552015-08-22 08:46:10 -0700281 display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, common_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800282 free(str_target);
283 }
lijuang7d235f42015-07-16 20:19:45 +0800284
285 display_fbcon_menu_message("\n< More options\n",
286 FBCON_COMMON_MSG, common_factor);
287 display_fbcon_menu_message("press VOLUME keys\n\n",
288 FBCON_SUBTITLE_MSG, common_factor);
lijuang4ece1e72015-08-14 21:02:36 +0800289 if(boot_verify_info[type].warning_msg != NULL)
290 display_fbcon_menu_message((char*)boot_verify_info[type].warning_msg,
291 FBCON_COMMON_MSG, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800292
Brahmaji K0c2d5982017-09-07 18:44:21 +0530293 if(boot_verify_info[type].url_msg != NULL)
294 display_fbcon_menu_message((char*)boot_verify_info[type].url_msg,
295 boot_verify_info[type].msg_type, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800296
lijuang7d235f42015-07-16 20:19:45 +0800297 if (type == DISPLAY_MENU_YELLOW) {
298 fp_buf = get_boot_fingerprint(&fp_size);
299 if (fp_buf != NULL) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530300 strlcpy(fp_str_temp, (char const *)fp_buf, fp_size);
lijuang7d235f42015-07-16 20:19:45 +0800301 for (i = 0; i < fp_size; i++) {
302 if(i == fp_size - 1)
Parth Dixit73d3bd02016-01-07 14:29:41 +0530303 snprintf(str_temp, sizeof(str_temp), "%02x", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800304 else
Parth Dixit73d3bd02016-01-07 14:29:41 +0530305 snprintf(str_temp, sizeof(str_temp), "%02x-", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800306
Parth Dixit73d3bd02016-01-07 14:29:41 +0530307 strlcat(fp_str, str_temp, sizeof(fp_str));
lijuang7d235f42015-07-16 20:19:45 +0800308 }
309 }
310 display_fbcon_menu_message("ID:", FBCON_COMMON_MSG, common_factor);
311 display_fbcon_menu_message(fp_str, FBCON_COMMON_MSG, common_factor);
312 }
lijuang7d235f42015-07-16 20:19:45 +0800313
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530314 str3 = "\n\nIf no key pressed:\n"\
315 "Your device will boot in 5 seconds\n\n";
316#if ENABLE_VB_ATTEST
317 if(type == DISPLAY_MENU_EIO)
318 {
319 str3 ="\n\nIf power key is not pressed:\n"\
320 "Your device will poweroff in 30 seconds\n\n";
321 timeout = DELAY_30SEC;
322 }
323#endif
324 display_fbcon_menu_message(str3, FBCON_COMMON_MSG, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800325
lijuang9a7d3b92015-11-30 14:41:24 +0800326 msg_info->info.msg_type = type;
lijuang9a7d3b92015-11-30 14:41:24 +0800327
328 /* Initialize the time out time */
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530329 msg_info->info.timeout_time = timeout; //5s
lijuang7d235f42015-07-16 20:19:45 +0800330}
lijuang4ece1e72015-08-14 21:02:36 +0800331#endif
lijuang7d235f42015-07-16 20:19:45 +0800332
lijuang9a7d3b92015-11-30 14:41:24 +0800333/* msg_lock need to be holded when call this function. */
334void display_bootverify_option_menu_renew(struct select_msg_info *msg_info)
lijuang7d235f42015-07-16 20:19:45 +0800335{
336 int i = 0;
lijuang4ece1e72015-08-14 21:02:36 +0800337 int len = 0;
lijuang9a7d3b92015-11-30 14:41:24 +0800338
lijuang7d235f42015-07-16 20:19:45 +0800339 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800340 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800341
lijuang4ece1e72015-08-14 21:02:36 +0800342 len = ARRAY_SIZE(verify_option_menu);
lijuang7d235f42015-07-16 20:19:45 +0800343 display_fbcon_menu_message("Options menu:\n\n",
344 FBCON_COMMON_MSG, big_factor);
345 display_fbcon_menu_message("Press volume key to select, and "\
346 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor);
347
lijuang4ece1e72015-08-14 21:02:36 +0800348 for (i = 0; i < len; i++) {
349 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800350 msg_info->info.option_start[i] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800351 display_fbcon_menu_message(verify_option_menu[i],
lijuang7d235f42015-07-16 20:19:45 +0800352 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800353 msg_info->info.option_bg[i]= fbcon_get_current_bg();
354 msg_info->info.option_end[i]= fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800355 }
356
lijuang4ece1e72015-08-14 21:02:36 +0800357 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800358 msg_info->info.msg_type = DISPLAY_MENU_MORE_OPTION;
359 msg_info->info.option_num = len;
360
361 /* Initialize the option index */
362 msg_info->info.option_index= len;
lijuang4ece1e72015-08-14 21:02:36 +0800363}
364
lijuang9a7d3b92015-11-30 14:41:24 +0800365/* msg_lock need to be holded when call this function. */
366void display_fastboot_menu_renew(struct select_msg_info *fastboot_msg_info)
lijuang4ece1e72015-08-14 21:02:36 +0800367{
368 int len;
369 int msg_type = FBCON_COMMON_MSG;
370 char msg_buf[64];
371 char msg[128];
372
lijuang9a7d3b92015-11-30 14:41:24 +0800373 /* The fastboot menu is switched base on the option index
374 * So it's need to store the index for the menu switching
375 */
376 uint32_t option_index = fastboot_msg_info->info.option_index;
377
lijuang4ece1e72015-08-14 21:02:36 +0800378 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800379 memset(&fastboot_msg_info->info, 0, sizeof(struct menu_info));
lijuang4ece1e72015-08-14 21:02:36 +0800380
381 len = ARRAY_SIZE(fastboot_option_menu);
382 switch(option_index) {
383 case 0:
384 msg_type = FBCON_GREEN_MSG;
385 break;
386 case 1:
387 case 2:
388 msg_type = FBCON_RED_MSG;
389 break;
390 case 3:
lijuang42aefaa2016-04-14 15:55:17 +0800391 case 4:
lijuang4ece1e72015-08-14 21:02:36 +0800392 msg_type = FBCON_COMMON_MSG;
393 break;
394 }
395 fbcon_draw_line(msg_type);
396 display_fbcon_menu_message(fastboot_option_menu[option_index],
397 msg_type, big_factor);
398 fbcon_draw_line(msg_type);
399 display_fbcon_menu_message("\n\nPress volume key to select, and "\
400 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor);
401
402 display_fbcon_menu_message("FASTBOOT MODE\n", FBCON_RED_MSG, common_factor);
403
404 get_product_name((unsigned char *) msg_buf);
405 snprintf(msg, sizeof(msg), "PRODUCT_NAME - %s\n", msg_buf);
406 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
407
408 memset(msg_buf, 0, sizeof(msg_buf));
409 smem_get_hw_platform_name((unsigned char *) msg_buf, sizeof(msg_buf));
410 snprintf(msg, sizeof(msg), "VARIANT - %s %s\n",
411 msg_buf, target_is_emmc_boot()? "eMMC":"UFS");
412 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
413
414 memset(msg_buf, 0, sizeof(msg_buf));
415 get_bootloader_version((unsigned char *) msg_buf);
416 snprintf(msg, sizeof(msg), "BOOTLOADER VERSION - %s\n",
417 msg_buf);
418 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
419
420 memset(msg_buf, 0, sizeof(msg_buf));
421 get_baseband_version((unsigned char *) msg_buf);
422 snprintf(msg, sizeof(msg), "BASEBAND VERSION - %s\n",
423 msg_buf);
424 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
425
426 memset(msg_buf, 0, sizeof(msg_buf));
427 target_serialno((unsigned char *) msg_buf);
428 snprintf(msg, sizeof(msg), "SERIAL NUMBER - %s\n", msg_buf);
429 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
430
431 snprintf(msg, sizeof(msg), "SECURE BOOT - %s\n",
432 is_secure_boot_enable()? "enabled":"disabled");
433 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
434
435 snprintf(msg, sizeof(msg), "DEVICE STATE - %s\n",
436 is_device_locked()? "locked":"unlocked");
437 display_fbcon_menu_message(msg, FBCON_RED_MSG, common_factor);
438
lijuang9a7d3b92015-11-30 14:41:24 +0800439 fastboot_msg_info->info.msg_type = DISPLAY_MENU_FASTBOOT;
440 fastboot_msg_info->info.option_num = len;
441 fastboot_msg_info->info.option_index = option_index;
442}
443
444void msg_lock_init()
445{
446 static bool is_msg_lock_init = false;
447 struct select_msg_info *msg_lock_info;
448 msg_lock_info = &msg_info;
449
450 if (!is_msg_lock_init) {
451 mutex_init(&msg_lock_info->msg_lock);
452 is_msg_lock_init = true;
453 }
lijuang7d235f42015-07-16 20:19:45 +0800454}
455
456static void display_menu_thread_start(struct select_msg_info *msg_info)
457{
458 thread_t *thr;
459
460 if (!is_thread_start) {
461 thr = thread_create("selectkeydetect", &select_msg_keys_detect,
462 (void*)msg_info, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
463 if (!thr) {
464 dprintf(CRITICAL, "ERROR: creat device status detect thread failed!!\n");
465 return;
466 }
467 thread_resume(thr);
lijuang9a7d3b92015-11-30 14:41:24 +0800468 is_thread_start = true;
lijuang7d235f42015-07-16 20:19:45 +0800469 }
lijuang7d235f42015-07-16 20:19:45 +0800470}
471
lijuang9a7d3b92015-11-30 14:41:24 +0800472/* The fuction be called after device in fastboot mode,
473 * so it's no need to initialize the msg_lock again
474 */
475void display_unlock_menu(int type)
lijuang7d235f42015-07-16 20:19:45 +0800476{
lijuang4ece1e72015-08-14 21:02:36 +0800477 struct select_msg_info *unlock_menu_msg_info;
478 unlock_menu_msg_info = &msg_info;
lijuang7d235f42015-07-16 20:19:45 +0800479
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530480 if (is_display_disabled())
481 return;
482
lijuang7d235f42015-07-16 20:19:45 +0800483 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800484
485 msg_lock_init();
486 mutex_acquire(&unlock_menu_msg_info->msg_lock);
487
488 /* Initialize the last_msg_type */
489 unlock_menu_msg_info->last_msg_type =
490 unlock_menu_msg_info->info.msg_type;
491
492 display_unlock_menu_renew(unlock_menu_msg_info, type);
493 mutex_release(&unlock_menu_msg_info->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800494
lijuang4ece1e72015-08-14 21:02:36 +0800495 dprintf(INFO, "creating unlock keys detect thread\n");
496 display_menu_thread_start(unlock_menu_msg_info);
lijuang7d235f42015-07-16 20:19:45 +0800497}
498
lijuang9a7d3b92015-11-30 14:41:24 +0800499void display_fastboot_menu()
lijuang4ece1e72015-08-14 21:02:36 +0800500{
501 struct select_msg_info *fastboot_menu_msg_info;
502 fastboot_menu_msg_info = &msg_info;
503
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530504 if (is_display_disabled())
505 return;
506
lijuang4ece1e72015-08-14 21:02:36 +0800507 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800508
509 msg_lock_init();
510 mutex_acquire(&fastboot_menu_msg_info->msg_lock);
511
512 /* There are 4 pages for fastboot menu:
513 * Page: Start/Fastboot/Recovery/Poweroff
514 * The menu is switched base on the option index
515 * Initialize the option index and last_msg_type
516 */
517 fastboot_menu_msg_info->info.option_index = 0;
518 fastboot_menu_msg_info->last_msg_type =
519 fastboot_menu_msg_info->info.msg_type;
520
521 display_fastboot_menu_renew(fastboot_menu_msg_info);
522 mutex_release(&fastboot_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800523
524 dprintf(INFO, "creating fastboot menu keys detect thread\n");
525 display_menu_thread_start(fastboot_menu_msg_info);
526}
527
Monika Singh5e170362018-03-14 00:48:36 +0530528#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800529void display_bootverify_menu(int type)
lijuang4ece1e72015-08-14 21:02:36 +0800530{
531 struct select_msg_info *bootverify_menu_msg_info;
532 bootverify_menu_msg_info = &msg_info;
533
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530534 if (is_display_disabled())
535 return;
536
lijuang4ece1e72015-08-14 21:02:36 +0800537 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800538
539 msg_lock_init();
540 mutex_acquire(&bootverify_menu_msg_info->msg_lock);
541
542 /* Initialize the last_msg_type */
543 bootverify_menu_msg_info->last_msg_type =
544 bootverify_menu_msg_info->info.msg_type;
545
546 display_bootverify_menu_renew(bootverify_menu_msg_info, type);
547 mutex_release(&bootverify_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800548
549 dprintf(INFO, "creating boot verify keys detect thread\n");
550 display_menu_thread_start(bootverify_menu_msg_info);
551}
552#endif