lijuang | bdb18ea | 2018-02-06 17:21:18 +0800 | [diff] [blame] | 1 | /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 2 | * |
| 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> |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 40 | #include <smem.h> |
| 41 | #include <target.h> |
| 42 | #include <sys/types.h> |
| 43 | #include <../../../app/aboot/devinfo.h> |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 44 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 45 | static const char *unlock_menu_common_msg = "If you unlock the bootloader, "\ |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 46 | "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 "\ |
lijuang | 57d48b8 | 2016-01-20 17:23:50 +0800 | [diff] [blame] | 54 | "data from your phone(a \"factory data reset\").\n\n"\ |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 55 | "Press the Volume Up/Down buttons to select Yes "\ |
| 56 | "or No. Then press the Power button to continue.\n"; |
| 57 | |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 58 | #define YELLOW_WARNING_MSG "Your device has loaded a different operating system\n\n "\ |
Brahmaji K | 0c2d598 | 2017-09-07 18:44:21 +0530 | [diff] [blame] | 59 | "Visit this link on another device:\n" |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 60 | |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 61 | #define ORANGE_WARNING_MSG "Your device software can't be\n checked for corruption. Please lock the bootloader\n\n"\ |
Brahmaji K | 0c2d598 | 2017-09-07 18:44:21 +0530 | [diff] [blame] | 62 | "Visit this link on another device:\n" |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 63 | |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 64 | #define RED_WARNING_MSG "Your device is corrupt. It can't be\ntrusted and will not boot\n\n" \ |
Brahmaji K | 0c2d598 | 2017-09-07 18:44:21 +0530 | [diff] [blame] | 65 | "Visit this link on another device:\n" |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 66 | |
lijuang | bdd9bb4 | 2016-03-01 18:22:17 +0800 | [diff] [blame] | 67 | #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 Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 70 | #define EIO_WARNING_MSG "Your device is corrupt. It can't be\n trusted and may not work properly.\n\n"\ |
Brahmaji K | 0c2d598 | 2017-09-07 18:44:21 +0530 | [diff] [blame] | 71 | "Visit this link on another device:\n" |
| 72 | |
| 73 | #define URL_MSG "g.co/ABH\n" |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 74 | |
Parth Dixit | 54ac3bb | 2017-03-07 15:52:48 +0530 | [diff] [blame] | 75 | #define DELAY_5SEC 5000 |
| 76 | #define DELAY_30SEC 30000 |
| 77 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 78 | static bool is_thread_start = false; |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 79 | static struct select_msg_info msg_info; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 80 | |
Monika Singh | 5e17036 | 2018-03-14 00:48:36 +0530 | [diff] [blame] | 81 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 82 | struct boot_verify_info { |
| 83 | int msg_type; |
| 84 | const char *warning_msg; |
Brahmaji K | 0c2d598 | 2017-09-07 18:44:21 +0530 | [diff] [blame] | 85 | const char *url_msg; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | struct boot_verify_info boot_verify_info[] = { |
Brahmaji K | 0c2d598 | 2017-09-07 18:44:21 +0530 | [diff] [blame] | 89 | [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}}; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 94 | #endif |
| 95 | |
| 96 | static char *verify_option_menu[] = { |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 97 | [POWEROFF] = "Power off\n", |
| 98 | [RESTART] = "Restart\n", |
| 99 | [RECOVER] = "Recovery\n", |
| 100 | [FASTBOOT] = "Fastboot\n", |
| 101 | [BACK] = "Back to previous page\n"}; |
| 102 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 103 | static char *fastboot_option_menu[] = { |
| 104 | [0] = "START\n", |
| 105 | [1] = "Restart bootloader\n", |
| 106 | [2] = "Recovery mode\n", |
lijuang | 42aefaa | 2016-04-14 15:55:17 +0800 | [diff] [blame] | 107 | [3] = "Power off\n", |
| 108 | [4] = "Boot to FFBM\n"}; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 109 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 110 | static int big_factor = 2; |
| 111 | static int common_factor = 1; |
| 112 | |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 113 | static void wait_for_exit() |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 114 | { |
| 115 | struct select_msg_info *select_msg; |
| 116 | select_msg = &msg_info; |
| 117 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 118 | mutex_acquire(&select_msg->msg_lock); |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 119 | while(!select_msg->info.rel_exit == true) { |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 120 | mutex_release(&select_msg->msg_lock); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 121 | thread_sleep(10); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 122 | mutex_acquire(&select_msg->msg_lock); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 123 | } |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 124 | mutex_release(&select_msg->msg_lock); |
| 125 | |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 126 | is_thread_start = false; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 127 | fbcon_clear(); |
| 128 | display_image_on_screen(); |
| 129 | } |
| 130 | |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 131 | void wait_for_users_action() |
| 132 | { |
Krishna Manikandan | f2c8be9 | 2017-12-05 18:07:56 +0530 | [diff] [blame] | 133 | if (is_display_disabled()) |
| 134 | return; |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 135 | /* 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 | |
| 141 | void exit_menu_keys_detection() |
| 142 | { |
| 143 | struct select_msg_info *select_msg; |
| 144 | select_msg = &msg_info; |
| 145 | |
Krishna Manikandan | f2c8be9 | 2017-12-05 18:07:56 +0530 | [diff] [blame] | 146 | if (is_display_disabled()) |
| 147 | return; |
| 148 | |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 149 | 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 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 156 | static void set_message_factor() |
| 157 | { |
| 158 | uint32_t tmp_factor = 0; |
lijuang | 9e73e5a | 2018-04-23 17:00:16 +0800 | [diff] [blame^] | 159 | 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; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 166 | |
| 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 | |
| 179 | static 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 | |
| 187 | static 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 Dixit | 73d3bd0 | 2016-01-07 14:29:41 +0530 | [diff] [blame] | 207 | strlcat(str_target, " ", max_x); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 208 | } |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 209 | } |
lijuang | bdb18ea | 2018-02-06 17:21:18 +0800 | [diff] [blame] | 210 | strlcat(str_target, str, max_x); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 211 | } |
lijuang | bdb18ea | 2018-02-06 17:21:18 +0800 | [diff] [blame] | 212 | return str_target; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 213 | } |
| 214 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 215 | /* msg_lock need to be holded when call this function. */ |
| 216 | void display_unlock_menu_renew(struct select_msg_info *unlock_msg_info, int type) |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 217 | { |
| 218 | fbcon_clear(); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 219 | memset(&unlock_msg_info->info, 0, sizeof(struct menu_info)); |
| 220 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 221 | display_fbcon_menu_message("Unlock bootloader?\n", |
| 222 | FBCON_UNLOCK_TITLE_MSG, big_factor); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 223 | fbcon_draw_line(FBCON_COMMON_MSG); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 224 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 225 | display_fbcon_menu_message((char*)unlock_menu_common_msg, |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 226 | FBCON_COMMON_MSG, common_factor); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 227 | fbcon_draw_line(FBCON_COMMON_MSG); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 228 | unlock_msg_info->info.option_start[0] = fbcon_get_current_line(); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 229 | display_fbcon_menu_message("Yes\n", |
| 230 | FBCON_COMMON_MSG, big_factor); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 231 | unlock_msg_info->info.option_bg[0] = fbcon_get_current_bg(); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 232 | display_fbcon_menu_message("Unlock bootloader(may void warranty)\n", |
| 233 | FBCON_COMMON_MSG, common_factor); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 234 | unlock_msg_info->info.option_end[0] = fbcon_get_current_line(); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 235 | fbcon_draw_line(FBCON_COMMON_MSG); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 236 | unlock_msg_info->info.option_start[1] = fbcon_get_current_line(); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 237 | display_fbcon_menu_message("No\n", |
| 238 | FBCON_COMMON_MSG, big_factor); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 239 | unlock_msg_info->info.option_bg[1] = fbcon_get_current_bg(); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 240 | display_fbcon_menu_message("Do not unlock bootloader and restart phone\n", |
| 241 | FBCON_COMMON_MSG, common_factor); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 242 | unlock_msg_info->info.option_end[1] = fbcon_get_current_line(); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 243 | fbcon_draw_line(FBCON_COMMON_MSG); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 244 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 245 | if (type == UNLOCK) |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 246 | unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 247 | else if (type == UNLOCK_CRITICAL) |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 248 | unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK_CRITICAL; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 249 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 250 | unlock_msg_info->info.option_num = 2; |
| 251 | |
| 252 | /* Initialize the option index */ |
| 253 | unlock_msg_info->info.option_index= 2; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 254 | } |
| 255 | |
Monika Singh | 5e17036 | 2018-03-14 00:48:36 +0530 | [diff] [blame] | 256 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 257 | /* msg_lock need to be holded when call this function. */ |
| 258 | void display_bootverify_menu_renew(struct select_msg_info *msg_info, int type) |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 259 | { |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 260 | 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 Dixit | 54ac3bb | 2017-03-07 15:52:48 +0530 | [diff] [blame] | 267 | char *str3 = NULL; |
| 268 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 269 | char *str_target = NULL; |
| 270 | uint32 fp_size = 0; |
| 271 | unsigned int i = 0; |
Parth Dixit | 54ac3bb | 2017-03-07 15:52:48 +0530 | [diff] [blame] | 272 | uint32_t timeout = DELAY_5SEC; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 273 | |
| 274 | fbcon_clear(); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 275 | memset(&msg_info->info, 0, sizeof(struct menu_info)); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 276 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 277 | /* Align Right */ |
| 278 | str_target = str_align_right(str1, big_factor); |
lijuang | 514c2ce | 2016-05-12 11:37:19 +0800 | [diff] [blame] | 279 | if(str_target != NULL) { |
Sridhar Parasuram | 995a355 | 2015-08-22 08:46:10 -0700 | [diff] [blame] | 280 | display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, big_factor); |
lijuang | 514c2ce | 2016-05-12 11:37:19 +0800 | [diff] [blame] | 281 | free(str_target); |
| 282 | } |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 283 | |
| 284 | str_target = str_align_right(str2, common_factor); |
lijuang | 514c2ce | 2016-05-12 11:37:19 +0800 | [diff] [blame] | 285 | if(str_target != NULL) { |
Sridhar Parasuram | 995a355 | 2015-08-22 08:46:10 -0700 | [diff] [blame] | 286 | display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, common_factor); |
lijuang | 514c2ce | 2016-05-12 11:37:19 +0800 | [diff] [blame] | 287 | free(str_target); |
| 288 | } |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 289 | |
| 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); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 294 | 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); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 297 | |
Brahmaji K | 0c2d598 | 2017-09-07 18:44:21 +0530 | [diff] [blame] | 298 | 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); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 301 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 302 | if (type == DISPLAY_MENU_YELLOW) { |
| 303 | fp_buf = get_boot_fingerprint(&fp_size); |
| 304 | if (fp_buf != NULL) { |
Parth Dixit | 73d3bd0 | 2016-01-07 14:29:41 +0530 | [diff] [blame] | 305 | strlcpy(fp_str_temp, (char const *)fp_buf, fp_size); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 306 | for (i = 0; i < fp_size; i++) { |
| 307 | if(i == fp_size - 1) |
Parth Dixit | 73d3bd0 | 2016-01-07 14:29:41 +0530 | [diff] [blame] | 308 | snprintf(str_temp, sizeof(str_temp), "%02x", fp_str_temp[i]); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 309 | else |
Parth Dixit | 73d3bd0 | 2016-01-07 14:29:41 +0530 | [diff] [blame] | 310 | snprintf(str_temp, sizeof(str_temp), "%02x-", fp_str_temp[i]); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 311 | |
Parth Dixit | 73d3bd0 | 2016-01-07 14:29:41 +0530 | [diff] [blame] | 312 | strlcat(fp_str, str_temp, sizeof(fp_str)); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 313 | } |
| 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 | } |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 318 | |
Parth Dixit | 54ac3bb | 2017-03-07 15:52:48 +0530 | [diff] [blame] | 319 | 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); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 330 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 331 | msg_info->info.msg_type = type; |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 332 | |
| 333 | /* Initialize the time out time */ |
Parth Dixit | 54ac3bb | 2017-03-07 15:52:48 +0530 | [diff] [blame] | 334 | msg_info->info.timeout_time = timeout; //5s |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 335 | } |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 336 | #endif |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 337 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 338 | /* msg_lock need to be holded when call this function. */ |
| 339 | void display_bootverify_option_menu_renew(struct select_msg_info *msg_info) |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 340 | { |
| 341 | int i = 0; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 342 | int len = 0; |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 343 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 344 | fbcon_clear(); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 345 | memset(&msg_info->info, 0, sizeof(struct menu_info)); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 346 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 347 | len = ARRAY_SIZE(verify_option_menu); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 348 | 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 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 353 | for (i = 0; i < len; i++) { |
| 354 | fbcon_draw_line(FBCON_COMMON_MSG); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 355 | msg_info->info.option_start[i] = fbcon_get_current_line(); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 356 | display_fbcon_menu_message(verify_option_menu[i], |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 357 | FBCON_COMMON_MSG, common_factor); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 358 | msg_info->info.option_bg[i]= fbcon_get_current_bg(); |
| 359 | msg_info->info.option_end[i]= fbcon_get_current_line(); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 360 | } |
| 361 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 362 | fbcon_draw_line(FBCON_COMMON_MSG); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 363 | 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; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 368 | } |
| 369 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 370 | /* msg_lock need to be holded when call this function. */ |
| 371 | void display_fastboot_menu_renew(struct select_msg_info *fastboot_msg_info) |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 372 | { |
| 373 | int len; |
| 374 | int msg_type = FBCON_COMMON_MSG; |
| 375 | char msg_buf[64]; |
| 376 | char msg[128]; |
| 377 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 378 | /* 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 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 383 | fbcon_clear(); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 384 | memset(&fastboot_msg_info->info, 0, sizeof(struct menu_info)); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 385 | |
| 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: |
lijuang | 42aefaa | 2016-04-14 15:55:17 +0800 | [diff] [blame] | 396 | case 4: |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 397 | 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 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 444 | 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 | |
| 449 | void 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 | } |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | static 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); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 473 | is_thread_start = true; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 474 | } |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 475 | } |
| 476 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 477 | /* The fuction be called after device in fastboot mode, |
| 478 | * so it's no need to initialize the msg_lock again |
| 479 | */ |
| 480 | void display_unlock_menu(int type) |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 481 | { |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 482 | struct select_msg_info *unlock_menu_msg_info; |
| 483 | unlock_menu_msg_info = &msg_info; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 484 | |
Krishna Manikandan | f2c8be9 | 2017-12-05 18:07:56 +0530 | [diff] [blame] | 485 | if (is_display_disabled()) |
| 486 | return; |
| 487 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 488 | set_message_factor(); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 489 | |
| 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); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 499 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 500 | dprintf(INFO, "creating unlock keys detect thread\n"); |
| 501 | display_menu_thread_start(unlock_menu_msg_info); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 502 | } |
| 503 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 504 | void display_fastboot_menu() |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 505 | { |
| 506 | struct select_msg_info *fastboot_menu_msg_info; |
| 507 | fastboot_menu_msg_info = &msg_info; |
| 508 | |
Krishna Manikandan | f2c8be9 | 2017-12-05 18:07:56 +0530 | [diff] [blame] | 509 | if (is_display_disabled()) |
| 510 | return; |
| 511 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 512 | set_message_factor(); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 513 | |
| 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); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 528 | |
| 529 | dprintf(INFO, "creating fastboot menu keys detect thread\n"); |
| 530 | display_menu_thread_start(fastboot_menu_msg_info); |
| 531 | } |
| 532 | |
Monika Singh | 5e17036 | 2018-03-14 00:48:36 +0530 | [diff] [blame] | 533 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 534 | void display_bootverify_menu(int type) |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 535 | { |
| 536 | struct select_msg_info *bootverify_menu_msg_info; |
| 537 | bootverify_menu_msg_info = &msg_info; |
| 538 | |
Krishna Manikandan | f2c8be9 | 2017-12-05 18:07:56 +0530 | [diff] [blame] | 539 | if (is_display_disabled()) |
| 540 | return; |
| 541 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 542 | set_message_factor(); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 543 | |
| 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); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 553 | |
| 554 | dprintf(INFO, "creating boot verify keys detect thread\n"); |
| 555 | display_menu_thread_start(bootverify_menu_msg_info); |
| 556 | } |
| 557 | #endif |