lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016, 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 | |
lijuang | 57d48b8 | 2016-01-20 17:23:50 +0800 | [diff] [blame] | 58 | #define YELLOW_WARNING_MSG "Your device has loaded a different operating "\ |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 59 | "system\n\nTo learn more, visit:\n" |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 60 | |
lijuang | 57d48b8 | 2016-01-20 17:23:50 +0800 | [diff] [blame] | 61 | #define ORANGE_WARNING_MSG "Your device has been unlocked and can't "\ |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 62 | "be trusted\n\nTo learn more, visit:\n" |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 63 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 64 | #define RED_WARNING_MSG "Your device has failed verification and may "\ |
| 65 | "not work properly\n\nTo learn more, visit:\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 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 70 | static bool is_thread_start = false; |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 71 | static struct select_msg_info msg_info; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 72 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 73 | #if VERIFIED_BOOT |
| 74 | struct boot_verify_info { |
| 75 | int msg_type; |
| 76 | const char *warning_msg; |
| 77 | }; |
| 78 | |
| 79 | struct boot_verify_info boot_verify_info[] = { |
| 80 | [DISPLAY_MENU_RED] = {FBCON_RED_MSG, RED_WARNING_MSG}, |
| 81 | [DISPLAY_MENU_YELLOW] = {FBCON_YELLOW_MSG, YELLOW_WARNING_MSG}, |
lijuang | bdd9bb4 | 2016-03-01 18:22:17 +0800 | [diff] [blame] | 82 | [DISPLAY_MENU_ORANGE] = {FBCON_ORANGE_MSG, ORANGE_WARNING_MSG}, |
| 83 | [DISPLAY_MENU_LOGGING] = {FBCON_RED_MSG, LOGGING_WARNING_MSG}}; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 84 | #endif |
| 85 | |
| 86 | static char *verify_option_menu[] = { |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 87 | [POWEROFF] = "Power off\n", |
| 88 | [RESTART] = "Restart\n", |
| 89 | [RECOVER] = "Recovery\n", |
| 90 | [FASTBOOT] = "Fastboot\n", |
| 91 | [BACK] = "Back to previous page\n"}; |
| 92 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 93 | static char *fastboot_option_menu[] = { |
| 94 | [0] = "START\n", |
| 95 | [1] = "Restart bootloader\n", |
| 96 | [2] = "Recovery mode\n", |
lijuang | 42aefaa | 2016-04-14 15:55:17 +0800 | [diff] [blame] | 97 | [3] = "Power off\n", |
| 98 | [4] = "Boot to FFBM\n"}; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 99 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 100 | static int big_factor = 2; |
| 101 | static int common_factor = 1; |
| 102 | |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 103 | static void wait_for_exit() |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 104 | { |
| 105 | struct select_msg_info *select_msg; |
| 106 | select_msg = &msg_info; |
| 107 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 108 | mutex_acquire(&select_msg->msg_lock); |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 109 | while(!select_msg->info.rel_exit == true) { |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 110 | mutex_release(&select_msg->msg_lock); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 111 | thread_sleep(10); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 112 | mutex_acquire(&select_msg->msg_lock); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 113 | } |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 114 | mutex_release(&select_msg->msg_lock); |
| 115 | |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 116 | is_thread_start = false; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 117 | fbcon_clear(); |
| 118 | display_image_on_screen(); |
| 119 | } |
| 120 | |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 121 | void wait_for_users_action() |
| 122 | { |
| 123 | /* Waiting for exit menu keys detection if there is no any usr action |
| 124 | * otherwise it will do the action base on the keys detection thread |
| 125 | */ |
| 126 | wait_for_exit(); |
| 127 | } |
| 128 | |
| 129 | void exit_menu_keys_detection() |
| 130 | { |
| 131 | struct select_msg_info *select_msg; |
| 132 | select_msg = &msg_info; |
| 133 | |
| 134 | mutex_acquire(&select_msg->msg_lock); |
| 135 | select_msg->info.is_exit = true; |
| 136 | mutex_release(&select_msg->msg_lock); |
| 137 | |
| 138 | wait_for_exit(); |
| 139 | } |
| 140 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 141 | static void set_message_factor() |
| 142 | { |
| 143 | uint32_t tmp_factor = 0; |
| 144 | uint32_t max_x_count = 40; |
| 145 | uint32_t max_x = fbcon_get_max_x(); |
| 146 | |
| 147 | max_x = fbcon_get_max_x(); |
| 148 | tmp_factor = max_x/max_x_count; |
| 149 | |
| 150 | if(tmp_factor <= 1) { |
| 151 | big_factor = 2; |
| 152 | common_factor = 1; |
| 153 | } else { |
| 154 | big_factor = tmp_factor*2; |
| 155 | common_factor = tmp_factor; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | static void display_fbcon_menu_message(char *str, unsigned type, |
| 160 | unsigned scale_factor) |
| 161 | { |
| 162 | while(*str != 0) { |
| 163 | fbcon_putc_factor(*str++, type, scale_factor); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | static char *str_align_right(char *str, int factor) |
| 168 | { |
| 169 | uint32_t max_x = 0; |
| 170 | int diff = 0; |
| 171 | int i = 0; |
| 172 | char *str_target = NULL; |
| 173 | |
| 174 | max_x = fbcon_get_max_x(); |
| 175 | if (!str_target && max_x) { |
| 176 | str_target = malloc(max_x); |
| 177 | } |
| 178 | |
| 179 | if (str_target) { |
| 180 | memset(str_target, 0, max_x); |
| 181 | if ( max_x/factor > strlen(str)) { |
| 182 | if (factor == 1) |
| 183 | diff = max_x/factor - strlen(str) - 1; |
| 184 | else |
| 185 | diff = max_x/factor - strlen(str); |
| 186 | for (i = 0; i < diff; i++) { |
Parth Dixit | 73d3bd0 | 2016-01-07 14:29:41 +0530 | [diff] [blame] | 187 | strlcat(str_target, " ", max_x); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 188 | } |
Parth Dixit | 73d3bd0 | 2016-01-07 14:29:41 +0530 | [diff] [blame] | 189 | strlcat(str_target, str, max_x); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 190 | return str_target; |
| 191 | } else { |
| 192 | free(str_target); |
| 193 | return str; |
| 194 | } |
| 195 | } |
| 196 | return str; |
| 197 | } |
| 198 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 199 | /* msg_lock need to be holded when call this function. */ |
| 200 | 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] | 201 | { |
| 202 | fbcon_clear(); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 203 | memset(&unlock_msg_info->info, 0, sizeof(struct menu_info)); |
| 204 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 205 | display_fbcon_menu_message("Unlock bootloader?\n", |
| 206 | FBCON_UNLOCK_TITLE_MSG, big_factor); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 207 | fbcon_draw_line(FBCON_COMMON_MSG); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 208 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 209 | display_fbcon_menu_message((char*)unlock_menu_common_msg, |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 210 | FBCON_COMMON_MSG, common_factor); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 211 | fbcon_draw_line(FBCON_COMMON_MSG); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 212 | unlock_msg_info->info.option_start[0] = fbcon_get_current_line(); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 213 | display_fbcon_menu_message("Yes\n", |
| 214 | FBCON_COMMON_MSG, big_factor); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 215 | unlock_msg_info->info.option_bg[0] = fbcon_get_current_bg(); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 216 | display_fbcon_menu_message("Unlock bootloader(may void warranty)\n", |
| 217 | FBCON_COMMON_MSG, common_factor); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 218 | unlock_msg_info->info.option_end[0] = fbcon_get_current_line(); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 219 | fbcon_draw_line(FBCON_COMMON_MSG); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 220 | unlock_msg_info->info.option_start[1] = fbcon_get_current_line(); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 221 | display_fbcon_menu_message("No\n", |
| 222 | FBCON_COMMON_MSG, big_factor); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 223 | unlock_msg_info->info.option_bg[1] = fbcon_get_current_bg(); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 224 | display_fbcon_menu_message("Do not unlock bootloader and restart phone\n", |
| 225 | FBCON_COMMON_MSG, common_factor); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 226 | unlock_msg_info->info.option_end[1] = fbcon_get_current_line(); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 227 | fbcon_draw_line(FBCON_COMMON_MSG); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 228 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 229 | if (type == UNLOCK) |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 230 | unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 231 | else if (type == UNLOCK_CRITICAL) |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 232 | unlock_msg_info->info.msg_type = DISPLAY_MENU_UNLOCK_CRITICAL; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 233 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 234 | unlock_msg_info->info.option_num = 2; |
| 235 | |
| 236 | /* Initialize the option index */ |
| 237 | unlock_msg_info->info.option_index= 2; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 238 | } |
| 239 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 240 | #if VERIFIED_BOOT |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 241 | /* msg_lock need to be holded when call this function. */ |
| 242 | void display_bootverify_menu_renew(struct select_msg_info *msg_info, int type) |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 243 | { |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 244 | unsigned char* fp_buf = NULL; |
| 245 | char fp_str_temp[EVP_MAX_MD_SIZE] = {'\0'}; |
| 246 | char fp_str[EVP_MAX_MD_SIZE*2] = {'\0'}; |
| 247 | char str_temp[8]; |
| 248 | |
| 249 | char str1[]= "Start >"; |
| 250 | char str2[] = "Continue boot"; |
| 251 | char *str_target = NULL; |
| 252 | uint32 fp_size = 0; |
| 253 | unsigned int i = 0; |
| 254 | |
| 255 | fbcon_clear(); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 256 | memset(&msg_info->info, 0, sizeof(struct menu_info)); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 257 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 258 | /* Align Right */ |
| 259 | str_target = str_align_right(str1, big_factor); |
lijuang | 514c2ce | 2016-05-12 11:37:19 +0800 | [diff] [blame^] | 260 | if(str_target != NULL) { |
Sridhar Parasuram | 995a355 | 2015-08-22 08:46:10 -0700 | [diff] [blame] | 261 | display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, big_factor); |
lijuang | 514c2ce | 2016-05-12 11:37:19 +0800 | [diff] [blame^] | 262 | free(str_target); |
| 263 | } |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 264 | |
| 265 | str_target = str_align_right(str2, common_factor); |
lijuang | 514c2ce | 2016-05-12 11:37:19 +0800 | [diff] [blame^] | 266 | if(str_target != NULL) { |
Sridhar Parasuram | 995a355 | 2015-08-22 08:46:10 -0700 | [diff] [blame] | 267 | display_fbcon_menu_message(str_target, FBCON_TITLE_MSG, common_factor); |
lijuang | 514c2ce | 2016-05-12 11:37:19 +0800 | [diff] [blame^] | 268 | free(str_target); |
| 269 | } |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 270 | |
| 271 | display_fbcon_menu_message("\n< More options\n", |
| 272 | FBCON_COMMON_MSG, common_factor); |
| 273 | display_fbcon_menu_message("press VOLUME keys\n\n", |
| 274 | FBCON_SUBTITLE_MSG, common_factor); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 275 | if(boot_verify_info[type].warning_msg != NULL) |
| 276 | display_fbcon_menu_message((char*)boot_verify_info[type].warning_msg, |
| 277 | FBCON_COMMON_MSG, common_factor); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 278 | |
| 279 | display_fbcon_menu_message("g.co/placeholder\n", |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 280 | boot_verify_info[type].msg_type, common_factor); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 281 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 282 | if (type == DISPLAY_MENU_YELLOW) { |
| 283 | fp_buf = get_boot_fingerprint(&fp_size); |
| 284 | if (fp_buf != NULL) { |
Parth Dixit | 73d3bd0 | 2016-01-07 14:29:41 +0530 | [diff] [blame] | 285 | strlcpy(fp_str_temp, (char const *)fp_buf, fp_size); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 286 | for (i = 0; i < fp_size; i++) { |
| 287 | if(i == fp_size - 1) |
Parth Dixit | 73d3bd0 | 2016-01-07 14:29:41 +0530 | [diff] [blame] | 288 | snprintf(str_temp, sizeof(str_temp), "%02x", fp_str_temp[i]); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 289 | else |
Parth Dixit | 73d3bd0 | 2016-01-07 14:29:41 +0530 | [diff] [blame] | 290 | snprintf(str_temp, sizeof(str_temp), "%02x-", fp_str_temp[i]); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 291 | |
Parth Dixit | 73d3bd0 | 2016-01-07 14:29:41 +0530 | [diff] [blame] | 292 | strlcat(fp_str, str_temp, sizeof(fp_str)); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | display_fbcon_menu_message("ID:", FBCON_COMMON_MSG, common_factor); |
| 296 | display_fbcon_menu_message(fp_str, FBCON_COMMON_MSG, common_factor); |
| 297 | } |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 298 | |
| 299 | display_fbcon_menu_message("\n\nIf no key pressed:\n"\ |
| 300 | "Your device will boot in 5 seconds\n\n", FBCON_COMMON_MSG, common_factor); |
| 301 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 302 | msg_info->info.msg_type = type; |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 303 | |
| 304 | /* Initialize the time out time */ |
| 305 | msg_info->info.timeout_time = 5000; //5s |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 306 | } |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 307 | #endif |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 308 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 309 | /* msg_lock need to be holded when call this function. */ |
| 310 | void display_bootverify_option_menu_renew(struct select_msg_info *msg_info) |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 311 | { |
| 312 | int i = 0; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 313 | int len = 0; |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 314 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 315 | fbcon_clear(); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 316 | memset(&msg_info->info, 0, sizeof(struct menu_info)); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 317 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 318 | len = ARRAY_SIZE(verify_option_menu); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 319 | display_fbcon_menu_message("Options menu:\n\n", |
| 320 | FBCON_COMMON_MSG, big_factor); |
| 321 | display_fbcon_menu_message("Press volume key to select, and "\ |
| 322 | "press power key to select\n\n", FBCON_COMMON_MSG, common_factor); |
| 323 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 324 | for (i = 0; i < len; i++) { |
| 325 | fbcon_draw_line(FBCON_COMMON_MSG); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 326 | msg_info->info.option_start[i] = fbcon_get_current_line(); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 327 | display_fbcon_menu_message(verify_option_menu[i], |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 328 | FBCON_COMMON_MSG, common_factor); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 329 | msg_info->info.option_bg[i]= fbcon_get_current_bg(); |
| 330 | msg_info->info.option_end[i]= fbcon_get_current_line(); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 331 | } |
| 332 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 333 | fbcon_draw_line(FBCON_COMMON_MSG); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 334 | msg_info->info.msg_type = DISPLAY_MENU_MORE_OPTION; |
| 335 | msg_info->info.option_num = len; |
| 336 | |
| 337 | /* Initialize the option index */ |
| 338 | msg_info->info.option_index= len; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 339 | } |
| 340 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 341 | /* msg_lock need to be holded when call this function. */ |
| 342 | void display_fastboot_menu_renew(struct select_msg_info *fastboot_msg_info) |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 343 | { |
| 344 | int len; |
| 345 | int msg_type = FBCON_COMMON_MSG; |
| 346 | char msg_buf[64]; |
| 347 | char msg[128]; |
| 348 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 349 | /* The fastboot menu is switched base on the option index |
| 350 | * So it's need to store the index for the menu switching |
| 351 | */ |
| 352 | uint32_t option_index = fastboot_msg_info->info.option_index; |
| 353 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 354 | fbcon_clear(); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 355 | memset(&fastboot_msg_info->info, 0, sizeof(struct menu_info)); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 356 | |
| 357 | len = ARRAY_SIZE(fastboot_option_menu); |
| 358 | switch(option_index) { |
| 359 | case 0: |
| 360 | msg_type = FBCON_GREEN_MSG; |
| 361 | break; |
| 362 | case 1: |
| 363 | case 2: |
| 364 | msg_type = FBCON_RED_MSG; |
| 365 | break; |
| 366 | case 3: |
lijuang | 42aefaa | 2016-04-14 15:55:17 +0800 | [diff] [blame] | 367 | case 4: |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 368 | msg_type = FBCON_COMMON_MSG; |
| 369 | break; |
| 370 | } |
| 371 | fbcon_draw_line(msg_type); |
| 372 | display_fbcon_menu_message(fastboot_option_menu[option_index], |
| 373 | msg_type, big_factor); |
| 374 | fbcon_draw_line(msg_type); |
| 375 | display_fbcon_menu_message("\n\nPress volume key to select, and "\ |
| 376 | "press power key to select\n\n", FBCON_COMMON_MSG, common_factor); |
| 377 | |
| 378 | display_fbcon_menu_message("FASTBOOT MODE\n", FBCON_RED_MSG, common_factor); |
| 379 | |
| 380 | get_product_name((unsigned char *) msg_buf); |
| 381 | snprintf(msg, sizeof(msg), "PRODUCT_NAME - %s\n", msg_buf); |
| 382 | display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor); |
| 383 | |
| 384 | memset(msg_buf, 0, sizeof(msg_buf)); |
| 385 | smem_get_hw_platform_name((unsigned char *) msg_buf, sizeof(msg_buf)); |
| 386 | snprintf(msg, sizeof(msg), "VARIANT - %s %s\n", |
| 387 | msg_buf, target_is_emmc_boot()? "eMMC":"UFS"); |
| 388 | display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor); |
| 389 | |
| 390 | memset(msg_buf, 0, sizeof(msg_buf)); |
| 391 | get_bootloader_version((unsigned char *) msg_buf); |
| 392 | snprintf(msg, sizeof(msg), "BOOTLOADER VERSION - %s\n", |
| 393 | msg_buf); |
| 394 | display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor); |
| 395 | |
| 396 | memset(msg_buf, 0, sizeof(msg_buf)); |
| 397 | get_baseband_version((unsigned char *) msg_buf); |
| 398 | snprintf(msg, sizeof(msg), "BASEBAND VERSION - %s\n", |
| 399 | msg_buf); |
| 400 | display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor); |
| 401 | |
| 402 | memset(msg_buf, 0, sizeof(msg_buf)); |
| 403 | target_serialno((unsigned char *) msg_buf); |
| 404 | snprintf(msg, sizeof(msg), "SERIAL NUMBER - %s\n", msg_buf); |
| 405 | display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor); |
| 406 | |
| 407 | snprintf(msg, sizeof(msg), "SECURE BOOT - %s\n", |
| 408 | is_secure_boot_enable()? "enabled":"disabled"); |
| 409 | display_fbcon_menu_message(msg, FBCON_COMMON_MSG, common_factor); |
| 410 | |
| 411 | snprintf(msg, sizeof(msg), "DEVICE STATE - %s\n", |
| 412 | is_device_locked()? "locked":"unlocked"); |
| 413 | display_fbcon_menu_message(msg, FBCON_RED_MSG, common_factor); |
| 414 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 415 | fastboot_msg_info->info.msg_type = DISPLAY_MENU_FASTBOOT; |
| 416 | fastboot_msg_info->info.option_num = len; |
| 417 | fastboot_msg_info->info.option_index = option_index; |
| 418 | } |
| 419 | |
| 420 | void msg_lock_init() |
| 421 | { |
| 422 | static bool is_msg_lock_init = false; |
| 423 | struct select_msg_info *msg_lock_info; |
| 424 | msg_lock_info = &msg_info; |
| 425 | |
| 426 | if (!is_msg_lock_init) { |
| 427 | mutex_init(&msg_lock_info->msg_lock); |
| 428 | is_msg_lock_init = true; |
| 429 | } |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | static void display_menu_thread_start(struct select_msg_info *msg_info) |
| 433 | { |
| 434 | thread_t *thr; |
| 435 | |
| 436 | if (!is_thread_start) { |
| 437 | thr = thread_create("selectkeydetect", &select_msg_keys_detect, |
| 438 | (void*)msg_info, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE); |
| 439 | if (!thr) { |
| 440 | dprintf(CRITICAL, "ERROR: creat device status detect thread failed!!\n"); |
| 441 | return; |
| 442 | } |
| 443 | thread_resume(thr); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 444 | is_thread_start = true; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 445 | } |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 446 | } |
| 447 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 448 | /* The fuction be called after device in fastboot mode, |
| 449 | * so it's no need to initialize the msg_lock again |
| 450 | */ |
| 451 | void display_unlock_menu(int type) |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 452 | { |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 453 | struct select_msg_info *unlock_menu_msg_info; |
| 454 | unlock_menu_msg_info = &msg_info; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 455 | |
| 456 | set_message_factor(); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 457 | |
| 458 | msg_lock_init(); |
| 459 | mutex_acquire(&unlock_menu_msg_info->msg_lock); |
| 460 | |
| 461 | /* Initialize the last_msg_type */ |
| 462 | unlock_menu_msg_info->last_msg_type = |
| 463 | unlock_menu_msg_info->info.msg_type; |
| 464 | |
| 465 | display_unlock_menu_renew(unlock_menu_msg_info, type); |
| 466 | mutex_release(&unlock_menu_msg_info->msg_lock); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 467 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 468 | dprintf(INFO, "creating unlock keys detect thread\n"); |
| 469 | display_menu_thread_start(unlock_menu_msg_info); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 470 | } |
| 471 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 472 | void display_fastboot_menu() |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 473 | { |
| 474 | struct select_msg_info *fastboot_menu_msg_info; |
| 475 | fastboot_menu_msg_info = &msg_info; |
| 476 | |
| 477 | set_message_factor(); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 478 | |
| 479 | msg_lock_init(); |
| 480 | mutex_acquire(&fastboot_menu_msg_info->msg_lock); |
| 481 | |
| 482 | /* There are 4 pages for fastboot menu: |
| 483 | * Page: Start/Fastboot/Recovery/Poweroff |
| 484 | * The menu is switched base on the option index |
| 485 | * Initialize the option index and last_msg_type |
| 486 | */ |
| 487 | fastboot_menu_msg_info->info.option_index = 0; |
| 488 | fastboot_menu_msg_info->last_msg_type = |
| 489 | fastboot_menu_msg_info->info.msg_type; |
| 490 | |
| 491 | display_fastboot_menu_renew(fastboot_menu_msg_info); |
| 492 | mutex_release(&fastboot_menu_msg_info->msg_lock); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 493 | |
| 494 | dprintf(INFO, "creating fastboot menu keys detect thread\n"); |
| 495 | display_menu_thread_start(fastboot_menu_msg_info); |
| 496 | } |
| 497 | |
| 498 | #if VERIFIED_BOOT |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 499 | void display_bootverify_menu(int type) |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 500 | { |
| 501 | struct select_msg_info *bootverify_menu_msg_info; |
| 502 | bootverify_menu_msg_info = &msg_info; |
| 503 | |
| 504 | set_message_factor(); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 505 | |
| 506 | msg_lock_init(); |
| 507 | mutex_acquire(&bootverify_menu_msg_info->msg_lock); |
| 508 | |
| 509 | /* Initialize the last_msg_type */ |
| 510 | bootverify_menu_msg_info->last_msg_type = |
| 511 | bootverify_menu_msg_info->info.msg_type; |
| 512 | |
| 513 | display_bootverify_menu_renew(bootverify_menu_msg_info, type); |
| 514 | mutex_release(&bootverify_menu_msg_info->msg_lock); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 515 | |
| 516 | dprintf(INFO, "creating boot verify keys detect thread\n"); |
| 517 | display_menu_thread_start(bootverify_menu_msg_info); |
| 518 | } |
| 519 | #endif |