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