blob: b45b61fd1f8294ae6dc35ea9fafefff17a830838 [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;
lijuang9e73e5a2018-04-23 17:00:16 +0800159 uint32_t max_x_count = 0;
160 uint32_t max_x = 0;
161
162 if (fbcon_get_width() < fbcon_get_height())
163 max_x_count = CHAR_NUM_PERROW_POR;
164 else
165 max_x_count = CHAR_NUM_PERROW_HOR;
lijuang7d235f42015-07-16 20:19:45 +0800166
167 max_x = fbcon_get_max_x();
168 tmp_factor = max_x/max_x_count;
169
170 if(tmp_factor <= 1) {
171 big_factor = 2;
172 common_factor = 1;
173 } else {
174 big_factor = tmp_factor*2;
175 common_factor = tmp_factor;
176 }
177}
178
179static void display_fbcon_menu_message(char *str, unsigned type,
180 unsigned scale_factor)
181{
182 while(*str != 0) {
183 fbcon_putc_factor(*str++, type, scale_factor);
184 }
185}
186
187static char *str_align_right(char *str, int factor)
188{
189 uint32_t max_x = 0;
190 int diff = 0;
191 int i = 0;
192 char *str_target = NULL;
193
194 max_x = fbcon_get_max_x();
195 if (!str_target && max_x) {
196 str_target = malloc(max_x);
197 }
198
199 if (str_target) {
200 memset(str_target, 0, max_x);
201 if ( max_x/factor > strlen(str)) {
202 if (factor == 1)
203 diff = max_x/factor - strlen(str) - 1;
204 else
205 diff = max_x/factor - strlen(str);
206 for (i = 0; i < diff; i++) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530207 strlcat(str_target, " ", max_x);
lijuang7d235f42015-07-16 20:19:45 +0800208 }
lijuang7d235f42015-07-16 20:19:45 +0800209 }
lijuangbdb18ea2018-02-06 17:21:18 +0800210 strlcat(str_target, str, max_x);
lijuang7d235f42015-07-16 20:19:45 +0800211 }
lijuangbdb18ea2018-02-06 17:21:18 +0800212 return str_target;
lijuang7d235f42015-07-16 20:19:45 +0800213}
214
lijuang9a7d3b92015-11-30 14:41:24 +0800215/* msg_lock need to be holded when call this function. */
216void display_unlock_menu_renew(struct select_msg_info *unlock_msg_info, int type)
lijuang7d235f42015-07-16 20:19:45 +0800217{
218 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800219 memset(&unlock_msg_info->info, 0, sizeof(struct menu_info));
220
lijuang7d235f42015-07-16 20:19:45 +0800221 display_fbcon_menu_message("Unlock bootloader?\n",
222 FBCON_UNLOCK_TITLE_MSG, big_factor);
lijuang4ece1e72015-08-14 21:02:36 +0800223 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang7d235f42015-07-16 20:19:45 +0800224
lijuang4ece1e72015-08-14 21:02:36 +0800225 display_fbcon_menu_message((char*)unlock_menu_common_msg,
lijuang7d235f42015-07-16 20:19:45 +0800226 FBCON_COMMON_MSG, common_factor);
lijuang4ece1e72015-08-14 21:02:36 +0800227 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800228 unlock_msg_info->info.option_start[0] = fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800229 display_fbcon_menu_message("Yes\n",
230 FBCON_COMMON_MSG, big_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800231 unlock_msg_info->info.option_bg[0] = fbcon_get_current_bg();
lijuang7d235f42015-07-16 20:19:45 +0800232 display_fbcon_menu_message("Unlock bootloader(may void warranty)\n",
233 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800234 unlock_msg_info->info.option_end[0] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800235 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800236 unlock_msg_info->info.option_start[1] = fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800237 display_fbcon_menu_message("No\n",
238 FBCON_COMMON_MSG, big_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800239 unlock_msg_info->info.option_bg[1] = fbcon_get_current_bg();
lijuang7d235f42015-07-16 20:19:45 +0800240 display_fbcon_menu_message("Do not unlock bootloader and restart phone\n",
241 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800242 unlock_msg_info->info.option_end[1] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800243 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang7d235f42015-07-16 20:19:45 +0800244
lijuang4ece1e72015-08-14 21:02:36 +0800245 if (type == UNLOCK)
lijuang9a7d3b92015-11-30 14:41:24 +0800246 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK;
lijuang4ece1e72015-08-14 21:02:36 +0800247 else if (type == UNLOCK_CRITICAL)
lijuang9a7d3b92015-11-30 14:41:24 +0800248 unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK_CRITICAL;
lijuang4ece1e72015-08-14 21:02:36 +0800249
lijuang9a7d3b92015-11-30 14:41:24 +0800250 unlock_msg_info->info.option_num = 2;
251
252 /* Initialize the option index */
253 unlock_msg_info->info.option_index= 2;
lijuang7d235f42015-07-16 20:19:45 +0800254}
255
Monika Singh5e170362018-03-14 00:48:36 +0530256#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800257/* msg_lock need to be holded when call this function. */
258void display_bootverify_menu_renew(struct select_msg_info *msg_info, int type)
lijuang7d235f42015-07-16 20:19:45 +0800259{
lijuang7d235f42015-07-16 20:19:45 +0800260 unsigned char* fp_buf = NULL;
261 char fp_str_temp[EVP_MAX_MD_SIZE] = {'\0'};
262 char fp_str[EVP_MAX_MD_SIZE*2] = {'\0'};
263 char str_temp[8];
264
265 char str1[]= "Start >";
266 char str2[] = "Continue boot";
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530267 char *str3 = NULL;
268
lijuang7d235f42015-07-16 20:19:45 +0800269 char *str_target = NULL;
270 uint32 fp_size = 0;
271 unsigned int i = 0;
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530272 uint32_t timeout = DELAY_5SEC;
lijuang7d235f42015-07-16 20:19:45 +0800273
274 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800275 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800276
lijuang7d235f42015-07-16 20:19:45 +0800277 /* Align Right */
278 str_target = str_align_right(str1, big_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800279 if(str_target != NULL) {
Sridhar Parasuram995a3552015-08-22 08:46:10 -0700280 display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, big_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800281 free(str_target);
282 }
lijuang7d235f42015-07-16 20:19:45 +0800283
284 str_target = str_align_right(str2, common_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800285 if(str_target != NULL) {
Sridhar Parasuram995a3552015-08-22 08:46:10 -0700286 display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, common_factor);
lijuang514c2ce2016-05-12 11:37:19 +0800287 free(str_target);
288 }
lijuang7d235f42015-07-16 20:19:45 +0800289
290 display_fbcon_menu_message("\n< More options\n",
291 FBCON_COMMON_MSG, common_factor);
292 display_fbcon_menu_message("press VOLUME keys\n\n",
293 FBCON_SUBTITLE_MSG, common_factor);
lijuang4ece1e72015-08-14 21:02:36 +0800294 if(boot_verify_info[type].warning_msg != NULL)
295 display_fbcon_menu_message((char*)boot_verify_info[type].warning_msg,
296 FBCON_COMMON_MSG, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800297
Brahmaji K0c2d5982017-09-07 18:44:21 +0530298 if(boot_verify_info[type].url_msg != NULL)
299 display_fbcon_menu_message((char*)boot_verify_info[type].url_msg,
300 boot_verify_info[type].msg_type, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800301
lijuang7d235f42015-07-16 20:19:45 +0800302 if (type == DISPLAY_MENU_YELLOW) {
303 fp_buf = get_boot_fingerprint(&fp_size);
304 if (fp_buf != NULL) {
Parth Dixit73d3bd02016-01-07 14:29:41 +0530305 strlcpy(fp_str_temp, (char const *)fp_buf, fp_size);
lijuang7d235f42015-07-16 20:19:45 +0800306 for (i = 0; i < fp_size; i++) {
307 if(i == fp_size - 1)
Parth Dixit73d3bd02016-01-07 14:29:41 +0530308 snprintf(str_temp, sizeof(str_temp), "%02x", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800309 else
Parth Dixit73d3bd02016-01-07 14:29:41 +0530310 snprintf(str_temp, sizeof(str_temp), "%02x-", fp_str_temp[i]);
lijuang7d235f42015-07-16 20:19:45 +0800311
Parth Dixit73d3bd02016-01-07 14:29:41 +0530312 strlcat(fp_str, str_temp, sizeof(fp_str));
lijuang7d235f42015-07-16 20:19:45 +0800313 }
314 }
315 display_fbcon_menu_message("ID:", FBCON_COMMON_MSG, common_factor);
316 display_fbcon_menu_message(fp_str, FBCON_COMMON_MSG, common_factor);
317 }
lijuang7d235f42015-07-16 20:19:45 +0800318
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530319 str3 = "\n\nIf no key pressed:\n"\
320 "Your device will boot in 5 seconds\n\n";
321#if ENABLE_VB_ATTEST
322 if(type == DISPLAY_MENU_EIO)
323 {
324 str3 ="\n\nIf power key is not pressed:\n"\
325 "Your device will poweroff in 30 seconds\n\n";
326 timeout = DELAY_30SEC;
327 }
328#endif
329 display_fbcon_menu_message(str3, FBCON_COMMON_MSG, common_factor);
lijuang7d235f42015-07-16 20:19:45 +0800330
lijuang9a7d3b92015-11-30 14:41:24 +0800331 msg_info->info.msg_type = type;
lijuang9a7d3b92015-11-30 14:41:24 +0800332
333 /* Initialize the time out time */
Parth Dixit54ac3bb2017-03-07 15:52:48 +0530334 msg_info->info.timeout_time = timeout; //5s
lijuang7d235f42015-07-16 20:19:45 +0800335}
lijuang4ece1e72015-08-14 21:02:36 +0800336#endif
lijuang7d235f42015-07-16 20:19:45 +0800337
lijuang9a7d3b92015-11-30 14:41:24 +0800338/* msg_lock need to be holded when call this function. */
339void display_bootverify_option_menu_renew(struct select_msg_info *msg_info)
lijuang7d235f42015-07-16 20:19:45 +0800340{
341 int i = 0;
lijuang4ece1e72015-08-14 21:02:36 +0800342 int len = 0;
lijuang9a7d3b92015-11-30 14:41:24 +0800343
lijuang7d235f42015-07-16 20:19:45 +0800344 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800345 memset(&msg_info->info, 0, sizeof(struct menu_info));
lijuang7d235f42015-07-16 20:19:45 +0800346
lijuang4ece1e72015-08-14 21:02:36 +0800347 len = ARRAY_SIZE(verify_option_menu);
lijuang7d235f42015-07-16 20:19:45 +0800348 display_fbcon_menu_message("Options menu:\n\n",
349 FBCON_COMMON_MSG, big_factor);
350 display_fbcon_menu_message("Press volume key to select, and "\
351 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor);
352
lijuang4ece1e72015-08-14 21:02:36 +0800353 for (i = 0; i < len; i++) {
354 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800355 msg_info->info.option_start[i] = fbcon_get_current_line();
lijuang4ece1e72015-08-14 21:02:36 +0800356 display_fbcon_menu_message(verify_option_menu[i],
lijuang7d235f42015-07-16 20:19:45 +0800357 FBCON_COMMON_MSG, common_factor);
lijuang9a7d3b92015-11-30 14:41:24 +0800358 msg_info->info.option_bg[i]= fbcon_get_current_bg();
359 msg_info->info.option_end[i]= fbcon_get_current_line();
lijuang7d235f42015-07-16 20:19:45 +0800360 }
361
lijuang4ece1e72015-08-14 21:02:36 +0800362 fbcon_draw_line(FBCON_COMMON_MSG);
lijuang9a7d3b92015-11-30 14:41:24 +0800363 msg_info->info.msg_type = DISPLAY_MENU_MORE_OPTION;
364 msg_info->info.option_num = len;
365
366 /* Initialize the option index */
367 msg_info->info.option_index= len;
lijuang4ece1e72015-08-14 21:02:36 +0800368}
369
lijuang9a7d3b92015-11-30 14:41:24 +0800370/* msg_lock need to be holded when call this function. */
371void display_fastboot_menu_renew(struct select_msg_info *fastboot_msg_info)
lijuang4ece1e72015-08-14 21:02:36 +0800372{
373 int len;
374 int msg_type = FBCON_COMMON_MSG;
375 char msg_buf[64];
376 char msg[128];
377
lijuang9a7d3b92015-11-30 14:41:24 +0800378 /* The fastboot menu is switched base on the option index
379 * So it's need to store the index for the menu switching
380 */
381 uint32_t option_index = fastboot_msg_info->info.option_index;
382
lijuang4ece1e72015-08-14 21:02:36 +0800383 fbcon_clear();
lijuang9a7d3b92015-11-30 14:41:24 +0800384 memset(&fastboot_msg_info->info, 0, sizeof(struct menu_info));
lijuang4ece1e72015-08-14 21:02:36 +0800385
386 len = ARRAY_SIZE(fastboot_option_menu);
387 switch(option_index) {
388 case 0:
389 msg_type = FBCON_GREEN_MSG;
390 break;
391 case 1:
392 case 2:
393 msg_type = FBCON_RED_MSG;
394 break;
395 case 3:
lijuang42aefaa2016-04-14 15:55:17 +0800396 case 4:
lijuang4ece1e72015-08-14 21:02:36 +0800397 msg_type = FBCON_COMMON_MSG;
398 break;
399 }
400 fbcon_draw_line(msg_type);
401 display_fbcon_menu_message(fastboot_option_menu[option_index],
402 msg_type, big_factor);
403 fbcon_draw_line(msg_type);
404 display_fbcon_menu_message("\n\nPress volume key to select, and "\
405 "press power key to select\n\n", FBCON_COMMON_MSG, common_factor);
406
407 display_fbcon_menu_message("FASTBOOT MODE\n", FBCON_RED_MSG, common_factor);
408
409 get_product_name((unsigned char *) msg_buf);
410 snprintf(msg, sizeof(msg), "PRODUCT_NAME - %s\n", msg_buf);
411 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
412
413 memset(msg_buf, 0, sizeof(msg_buf));
414 smem_get_hw_platform_name((unsigned char *) msg_buf, sizeof(msg_buf));
415 snprintf(msg, sizeof(msg), "VARIANT - %s %s\n",
416 msg_buf, target_is_emmc_boot()? "eMMC":"UFS");
417 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
418
419 memset(msg_buf, 0, sizeof(msg_buf));
420 get_bootloader_version((unsigned char *) msg_buf);
421 snprintf(msg, sizeof(msg), "BOOTLOADER VERSION - %s\n",
422 msg_buf);
423 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
424
425 memset(msg_buf, 0, sizeof(msg_buf));
426 get_baseband_version((unsigned char *) msg_buf);
427 snprintf(msg, sizeof(msg), "BASEBAND VERSION - %s\n",
428 msg_buf);
429 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
430
431 memset(msg_buf, 0, sizeof(msg_buf));
432 target_serialno((unsigned char *) msg_buf);
433 snprintf(msg, sizeof(msg), "SERIAL NUMBER - %s\n", msg_buf);
434 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
435
436 snprintf(msg, sizeof(msg), "SECURE BOOT - %s\n",
437 is_secure_boot_enable()? "enabled":"disabled");
438 display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor);
439
440 snprintf(msg, sizeof(msg), "DEVICE STATE - %s\n",
441 is_device_locked()? "locked":"unlocked");
442 display_fbcon_menu_message(msg, FBCON_RED_MSG, common_factor);
443
lijuang9a7d3b92015-11-30 14:41:24 +0800444 fastboot_msg_info->info.msg_type = DISPLAY_MENU_FASTBOOT;
445 fastboot_msg_info->info.option_num = len;
446 fastboot_msg_info->info.option_index = option_index;
447}
448
449void msg_lock_init()
450{
451 static bool is_msg_lock_init = false;
452 struct select_msg_info *msg_lock_info;
453 msg_lock_info = &msg_info;
454
455 if (!is_msg_lock_init) {
456 mutex_init(&msg_lock_info->msg_lock);
457 is_msg_lock_init = true;
458 }
lijuang7d235f42015-07-16 20:19:45 +0800459}
460
461static void display_menu_thread_start(struct select_msg_info *msg_info)
462{
463 thread_t *thr;
464
465 if (!is_thread_start) {
466 thr = thread_create("selectkeydetect", &select_msg_keys_detect,
467 (void*)msg_info, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
468 if (!thr) {
469 dprintf(CRITICAL, "ERROR: creat device status detect thread failed!!\n");
470 return;
471 }
472 thread_resume(thr);
lijuang9a7d3b92015-11-30 14:41:24 +0800473 is_thread_start = true;
lijuang7d235f42015-07-16 20:19:45 +0800474 }
lijuang7d235f42015-07-16 20:19:45 +0800475}
476
lijuang9a7d3b92015-11-30 14:41:24 +0800477/* The fuction be called after device in fastboot mode,
478 * so it's no need to initialize the msg_lock again
479 */
480void display_unlock_menu(int type)
lijuang7d235f42015-07-16 20:19:45 +0800481{
lijuang4ece1e72015-08-14 21:02:36 +0800482 struct select_msg_info *unlock_menu_msg_info;
483 unlock_menu_msg_info = &msg_info;
lijuang7d235f42015-07-16 20:19:45 +0800484
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530485 if (is_display_disabled())
486 return;
487
lijuang7d235f42015-07-16 20:19:45 +0800488 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800489
490 msg_lock_init();
491 mutex_acquire(&unlock_menu_msg_info->msg_lock);
492
493 /* Initialize the last_msg_type */
494 unlock_menu_msg_info->last_msg_type =
495 unlock_menu_msg_info->info.msg_type;
496
497 display_unlock_menu_renew(unlock_menu_msg_info, type);
498 mutex_release(&unlock_menu_msg_info->msg_lock);
lijuang7d235f42015-07-16 20:19:45 +0800499
lijuang4ece1e72015-08-14 21:02:36 +0800500 dprintf(INFO, "creating unlock keys detect thread\n");
501 display_menu_thread_start(unlock_menu_msg_info);
lijuang7d235f42015-07-16 20:19:45 +0800502}
503
lijuang9a7d3b92015-11-30 14:41:24 +0800504void display_fastboot_menu()
lijuang4ece1e72015-08-14 21:02:36 +0800505{
506 struct select_msg_info *fastboot_menu_msg_info;
507 fastboot_menu_msg_info = &msg_info;
508
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530509 if (is_display_disabled())
510 return;
511
lijuang4ece1e72015-08-14 21:02:36 +0800512 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800513
514 msg_lock_init();
515 mutex_acquire(&fastboot_menu_msg_info->msg_lock);
516
517 /* There are 4 pages for fastboot menu:
518 * Page: Start/Fastboot/Recovery/Poweroff
519 * The menu is switched base on the option index
520 * Initialize the option index and last_msg_type
521 */
522 fastboot_menu_msg_info->info.option_index = 0;
523 fastboot_menu_msg_info->last_msg_type =
524 fastboot_menu_msg_info->info.msg_type;
525
526 display_fastboot_menu_renew(fastboot_menu_msg_info);
527 mutex_release(&fastboot_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800528
529 dprintf(INFO, "creating fastboot menu keys detect thread\n");
530 display_menu_thread_start(fastboot_menu_msg_info);
531}
532
Monika Singh5e170362018-03-14 00:48:36 +0530533#if VERIFIED_BOOT || VERIFIED_BOOT_2
lijuang9a7d3b92015-11-30 14:41:24 +0800534void display_bootverify_menu(int type)
lijuang4ece1e72015-08-14 21:02:36 +0800535{
536 struct select_msg_info *bootverify_menu_msg_info;
537 bootverify_menu_msg_info = &msg_info;
538
Krishna Manikandanf2c8be92017-12-05 18:07:56 +0530539 if (is_display_disabled())
540 return;
541
lijuang4ece1e72015-08-14 21:02:36 +0800542 set_message_factor();
lijuang9a7d3b92015-11-30 14:41:24 +0800543
544 msg_lock_init();
545 mutex_acquire(&bootverify_menu_msg_info->msg_lock);
546
547 /* Initialize the last_msg_type */
548 bootverify_menu_msg_info->last_msg_type =
549 bootverify_menu_msg_info->info.msg_type;
550
551 display_bootverify_menu_renew(bootverify_menu_msg_info, type);
552 mutex_release(&bootverify_menu_msg_info->msg_lock);
lijuang4ece1e72015-08-14 21:02:36 +0800553
554 dprintf(INFO, "creating boot verify keys detect thread\n");
555 display_menu_thread_start(bootverify_menu_msg_info);
556}
557#endif