Anuj Garg | ae40955 | 2020-06-03 19:21:55 +0530 | [diff] [blame^] | 1 | /* Copyright (c) 2016-2020, The Linux Foundation. All rights reserved. |
lijuang | 593d735 | 2016-07-27 19:31:04 +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 | */ |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 28 | #include <Library/BaseLib.h> |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 29 | #include <Library/BaseMemoryLib.h> |
| 30 | #include <Library/DebugLib.h> |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 31 | #include <Library/DeviceInfo.h> |
| 32 | #include <Library/DrawUI.h> |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 33 | #include <Library/MemoryAllocationLib.h> |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 34 | #include <Library/MenuKeysDetection.h> |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 35 | #include <Library/UefiBootServicesTableLib.h> |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 36 | #include <Library/UnlockMenu.h> |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 37 | #include <Library/UpdateDeviceTree.h> |
Shivaprasad Hongal | 7fd6a52 | 2017-05-10 13:56:28 -0700 | [diff] [blame] | 38 | #include <Library/VerifiedBoot.h> |
lijuang | c6c7dd0 | 2017-08-16 17:31:16 +0800 | [diff] [blame] | 39 | #include <Library/VerifiedBootMenu.h> |
Anuj Garg | ae40955 | 2020-06-03 19:21:55 +0530 | [diff] [blame^] | 40 | #include <Library/BootLinux.h> |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 41 | #include <Protocol/EFIVerifiedBoot.h> |
| 42 | #include <Uefi.h> |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 43 | |
lijuang | c6c7dd0 | 2017-08-16 17:31:16 +0800 | [diff] [blame] | 44 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Zhen Kong | 53e18a8 | 2016-11-30 11:15:37 -0800 | [diff] [blame] | 45 | #define FINGERPRINT_LINE_LEN 16 |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 46 | #define FINGERPRINT_FORMATED_LINE_LEN FINGERPRINT_LINE_LEN + 5 |
| 47 | #define VERIFIED_BOOT_OPTION_NUM 5 |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 48 | STATIC OPTION_MENU_INFO gMenuInfo; |
| 49 | |
| 50 | typedef struct { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 51 | MENU_MSG_INFO WarningTitle; |
| 52 | MENU_MSG_INFO WarningMsg; |
| 53 | MENU_MSG_INFO UrlMsg; |
| 54 | MENU_MSG_INFO NoticeMsg; |
| 55 | MENU_MSG_INFO Fingerprint; |
lijuang | 582d642 | 2016-09-08 21:53:50 +0800 | [diff] [blame] | 56 | } WARNING_MENU_MSG_INFO; |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 57 | |
lijuang | 582d642 | 2016-09-08 21:53:50 +0800 | [diff] [blame] | 58 | STATIC WARNING_MENU_MSG_INFO mMenuMsgInfo[] = { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 59 | [DISPLAY_MENU_YELLOW] = |
| 60 | {{{"<!>"}, |
| 61 | BIG_FACTOR, |
| 62 | BGR_YELLOW, |
| 63 | BGR_BLACK, |
| 64 | COMMON, |
| 65 | 0, |
| 66 | NOACTION}, |
| 67 | {{"\n\nYour device has loaded a different operating system\n\n" |
| 68 | "Visit this link on another device:\n"}, |
| 69 | COMMON_FACTOR, |
| 70 | BGR_WHITE, |
| 71 | BGR_BLACK, |
| 72 | COMMON, |
| 73 | 0, |
| 74 | NOACTION}, |
| 75 | {{"g.co/ABH\n\n\n"}, |
| 76 | COMMON_FACTOR, |
| 77 | BGR_YELLOW, |
| 78 | BGR_BLACK, |
| 79 | COMMON, |
| 80 | 0, |
| 81 | NOACTION}, |
| 82 | {{"PRESS POWER KEY TO PAUSE BOOT\n\n\n\n"}, |
| 83 | COMMON_FACTOR, |
| 84 | BGR_WHITE, |
| 85 | BGR_BLACK, |
| 86 | ALIGN_LEFT, |
| 87 | 0, |
| 88 | NOACTION}, |
| 89 | {{""}, |
| 90 | COMMON_FACTOR, |
| 91 | BGR_WHITE, |
| 92 | BGR_BLACK, |
| 93 | COMMON, |
| 94 | 0, |
| 95 | NOACTION}}, |
| 96 | [DISPLAY_MENU_ORANGE] = |
| 97 | {{{"<!>"}, |
| 98 | BIG_FACTOR, |
| 99 | BGR_ORANGE, |
| 100 | BGR_BLACK, |
| 101 | COMMON, |
| 102 | 0, |
| 103 | NOACTION}, |
| 104 | {{"\n\nThe boot loader is unlocked and software integrity cannot " |
| 105 | "be guaranteed. Any data stored on the device may be available " |
| 106 | "to attackers. " |
| 107 | "Do not store any sensitive data on the device.\n\n" |
| 108 | "Visit this link on another device:\n"}, |
| 109 | COMMON_FACTOR, |
| 110 | BGR_WHITE, |
| 111 | BGR_BLACK, |
| 112 | COMMON, |
| 113 | 0, |
| 114 | NOACTION}, |
| 115 | {{"g.co/ABH\n\n\n"}, |
| 116 | COMMON_FACTOR, |
| 117 | BGR_ORANGE, |
| 118 | BGR_BLACK, |
| 119 | COMMON, |
| 120 | 0, |
| 121 | NOACTION}, |
| 122 | {{"PRESS POWER KEY TO PAUSE BOOT\n\n\n\n"}, |
| 123 | COMMON_FACTOR, |
| 124 | BGR_WHITE, |
| 125 | BGR_BLACK, |
| 126 | ALIGN_LEFT, |
| 127 | 0, |
| 128 | NOACTION}, |
| 129 | {{""}, |
| 130 | COMMON_FACTOR, |
| 131 | BGR_WHITE, |
| 132 | BGR_BLACK, |
| 133 | COMMON, |
| 134 | 0, |
| 135 | NOACTION}}, |
| 136 | [DISPLAY_MENU_RED] = |
| 137 | {{{"<!>"}, |
| 138 | BIG_FACTOR, |
| 139 | BGR_RED, |
| 140 | BGR_BLACK, |
| 141 | COMMON, |
| 142 | 0, |
| 143 | NOACTION}, |
| 144 | {{"\n\nYour device is corrupt. It can't be trusted and will not " |
| 145 | "boot\n\n" |
| 146 | "Visit this link on another device:\n"}, |
| 147 | COMMON_FACTOR, |
| 148 | BGR_WHITE, |
| 149 | BGR_BLACK, |
| 150 | COMMON, |
| 151 | 0, |
| 152 | NOACTION}, |
| 153 | {{"g.co/ABH\n\n\n"}, |
| 154 | COMMON_FACTOR, |
| 155 | BGR_RED, |
| 156 | BGR_BLACK, |
| 157 | COMMON, |
| 158 | 0, |
| 159 | NOACTION}, |
| 160 | {{""}, |
| 161 | COMMON_FACTOR, |
| 162 | BGR_WHITE, |
| 163 | BGR_BLACK, |
| 164 | COMMON, |
| 165 | 0, |
| 166 | NOACTION}}, |
| 167 | [DISPLAY_MENU_EIO] = |
| 168 | {{{"<!>"}, |
| 169 | BIG_FACTOR, |
| 170 | BGR_RED, |
| 171 | BGR_BLACK, |
| 172 | COMMON, |
| 173 | 0, |
| 174 | NOACTION}, |
| 175 | {{"\n\nYour device is corrupt. It can't be trusted and may " |
| 176 | "not work properly\n\n" |
| 177 | "Visit this link on another device:\n"}, |
| 178 | COMMON_FACTOR, |
| 179 | BGR_WHITE, |
| 180 | BGR_BLACK, |
| 181 | COMMON, |
| 182 | 0, |
| 183 | NOACTION}, |
| 184 | {{"g.co/ABH\n\n\n"}, |
| 185 | COMMON_FACTOR, |
| 186 | BGR_RED, |
| 187 | BGR_BLACK, |
| 188 | COMMON, |
| 189 | 0, |
| 190 | NOACTION}, |
| 191 | {{"PRESS POWER KEY TO CONTINUE\n\n\n\n"}, |
| 192 | COMMON_FACTOR, |
| 193 | BGR_WHITE, |
| 194 | BGR_BLACK, |
| 195 | ALIGN_LEFT, |
| 196 | 0, |
| 197 | NOACTION}, |
| 198 | {{""}, |
| 199 | COMMON_FACTOR, |
| 200 | BGR_WHITE, |
| 201 | BGR_BLACK, |
| 202 | COMMON, |
| 203 | 0, |
| 204 | NOACTION}}, |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 205 | }; |
| 206 | |
| 207 | STATIC MENU_MSG_INFO mOptionMenuMsgInfo[] = { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 208 | {{"Options menu:\n"}, |
| 209 | BIG_FACTOR, |
| 210 | BGR_WHITE, |
| 211 | BGR_BLACK, |
| 212 | COMMON, |
| 213 | 0, |
| 214 | NOACTION}, |
| 215 | {{"\nPress volume key to select, and press power key to select\n\n"}, |
| 216 | COMMON_FACTOR, |
| 217 | BGR_WHITE, |
| 218 | BGR_BLACK, |
| 219 | COMMON, |
| 220 | 0, |
| 221 | NOACTION}, |
| 222 | {{"____________________"}, |
| 223 | COMMON_FACTOR, |
| 224 | BGR_WHITE, |
| 225 | BGR_BLACK, |
| 226 | LINEATION, |
| 227 | 0, |
| 228 | NOACTION}, |
| 229 | {{"Power off"}, |
| 230 | COMMON_FACTOR, |
| 231 | BGR_WHITE, |
| 232 | BGR_BLACK, |
| 233 | OPTION_ITEM, |
| 234 | 0, |
| 235 | POWEROFF}, |
| 236 | {{"____________________"}, |
| 237 | COMMON_FACTOR, |
| 238 | BGR_WHITE, |
| 239 | BGR_BLACK, |
| 240 | LINEATION, |
| 241 | 0, |
| 242 | NOACTION}, |
| 243 | {{"Restart"}, |
| 244 | COMMON_FACTOR, |
| 245 | BGR_WHITE, |
| 246 | BGR_BLACK, |
| 247 | OPTION_ITEM, |
| 248 | 0, |
| 249 | RESTART}, |
| 250 | {{"____________________"}, |
| 251 | COMMON_FACTOR, |
| 252 | BGR_WHITE, |
| 253 | BGR_BLACK, |
| 254 | LINEATION, |
| 255 | 0, |
| 256 | NOACTION}, |
| 257 | {{"Recovery"}, |
| 258 | COMMON_FACTOR, |
| 259 | BGR_WHITE, |
| 260 | BGR_BLACK, |
| 261 | OPTION_ITEM, |
| 262 | 0, |
| 263 | RECOVER}, |
| 264 | {{"____________________"}, |
| 265 | COMMON_FACTOR, |
| 266 | BGR_WHITE, |
| 267 | BGR_BLACK, |
| 268 | LINEATION, |
| 269 | 0, |
| 270 | NOACTION}, |
| 271 | {{"Fastboot"}, |
| 272 | COMMON_FACTOR, |
| 273 | BGR_WHITE, |
| 274 | BGR_BLACK, |
| 275 | OPTION_ITEM, |
| 276 | 0, |
| 277 | FASTBOOT}, |
| 278 | {{"____________________"}, |
| 279 | COMMON_FACTOR, |
| 280 | BGR_WHITE, |
| 281 | BGR_BLACK, |
| 282 | LINEATION, |
| 283 | 0, |
| 284 | NOACTION}, |
| 285 | {{"Back to previous page"}, |
| 286 | COMMON_FACTOR, |
| 287 | BGR_WHITE, |
| 288 | BGR_BLACK, |
| 289 | OPTION_ITEM, |
| 290 | 0, |
| 291 | BACK}, |
| 292 | {{"____________________"}, |
| 293 | COMMON_FACTOR, |
| 294 | BGR_WHITE, |
| 295 | BGR_BLACK, |
| 296 | LINEATION, |
| 297 | 0, |
| 298 | NOACTION}, |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 299 | }; |
| 300 | |
| 301 | /** |
Zhen Kong | 53e18a8 | 2016-11-30 11:15:37 -0800 | [diff] [blame] | 302 | Convert UINT8 array to a CHAR8 hex array. |
| 303 | The caller of the function should allocate memory properly. |
| 304 | Size of target should be at least twice than the source size (len). |
| 305 | |
| 306 | @param[out] *target Pointer to the output array |
| 307 | @param[in] *source Pointer to the source array |
| 308 | @param[in] len Size of the source array |
| 309 | |
| 310 | **/ |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 311 | STATIC VOID |
| 312 | GetHexString (CHAR8 *Target, UINT8 *Source, UINTN Len) |
Zhen Kong | 53e18a8 | 2016-11-30 11:15:37 -0800 | [diff] [blame] | 313 | { |
| 314 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 315 | UINTN TargetIndex = 0; |
| 316 | UINTN SourceIndex = 0; |
| 317 | UINTN TargetLen = Len * 2; |
| 318 | CHAR8 HexBuf[3]; |
| 319 | for (TargetIndex = 0; TargetIndex < TargetLen; |
| 320 | TargetIndex = TargetIndex + 2) { |
| 321 | AsciiSPrint (HexBuf, sizeof (HexBuf), "%02x", Source[SourceIndex]); |
| 322 | gBS->CopyMem (Target + TargetIndex, HexBuf, 2); |
| 323 | SourceIndex++; |
| 324 | } |
Zhen Kong | 53e18a8 | 2016-11-30 11:15:37 -0800 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | /** |
| 328 | |
| 329 | Construct display output array. |
| 330 | The caller should allocate the buffer properly before invoking this function. |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 331 | The assumption is display output and finger print have larger size than 22 and |
| 332 | 16. |
Zhen Kong | 53e18a8 | 2016-11-30 11:15:37 -0800 | [diff] [blame] | 333 | |
| 334 | The target array starts with string "ID: " following with the fingerprint. |
| 335 | Each 16 charcaters of fingerprint are shown in one line. |
| 336 | If fingerprint size is too big, it only copies the number of characters |
| 337 | that matches the output size. |
| 338 | |
| 339 | Eaxmple output: |
| 340 | |
| 341 | ID: 3F957EBAD2EE02F2 |
| 342 | CD23ED905C51913D |
| 343 | 4E9AAA2C5A4A1AE8 |
| 344 | 0F9D6BF727593F14 |
| 345 | |
| 346 | @param[out] *target Pointer to the output array |
| 347 | @param[in] target_len Size of output |
| 348 | @param[in] *source Pointer to the input array |
| 349 | @param[in] source_len Size of input |
| 350 | |
| 351 | **/ |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 352 | STATIC VOID |
| 353 | GetDisplayOutPut (CHAR8 *Target, |
| 354 | UINTN TargetLen, |
| 355 | CHAR8 *Source, |
| 356 | UINTN SourceLen) |
Zhen Kong | 53e18a8 | 2016-11-30 11:15:37 -0800 | [diff] [blame] | 357 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 358 | UINTN LastLineCharsCount = 0; |
| 359 | UINTN TargetIndex = 0; |
| 360 | UINTN SourceIndex = 0; |
| 361 | UINTN LineNum = 0; |
| 362 | UINTN FinalLen = 0; |
Zhen Kong | 53e18a8 | 2016-11-30 11:15:37 -0800 | [diff] [blame] | 363 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 364 | /* First line starts with 4 characters of "ID: ", |
| 365 | other lines start with 4 spaces to make the length of each line 21 |
| 366 | */ |
| 367 | CONST CHAR8 Id[] = "ID: "; |
| 368 | CONST CHAR8 StartlineSpace[] = " "; |
Zhen Kong | 53e18a8 | 2016-11-30 11:15:37 -0800 | [diff] [blame] | 369 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 370 | /* Each line contains 21 characters (4 spaces in the beginning), |
| 371 | 16 characters from fingerprint, one character for endline */ |
| 372 | UINTN NumberOfLines = SourceLen / FINGERPRINT_LINE_LEN + |
| 373 | ((SourceLen % FINGERPRINT_LINE_LEN == 0 ? 0 : 1)); |
Zhen Kong | 53e18a8 | 2016-11-30 11:15:37 -0800 | [diff] [blame] | 374 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 375 | /* each line contains 4 spaces at the beginning and one endline |
| 376 | character at the end */ |
| 377 | FinalLen = (AsciiStrLen (Id) + 1) * (NumberOfLines) + SourceLen; |
Zhen Kong | 53e18a8 | 2016-11-30 11:15:37 -0800 | [diff] [blame] | 378 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 379 | /* if final size is bigger that display output size, |
| 380 | reduce the numbe of lines, |
| 381 | one character is needed for NULL character */ |
| 382 | while (FinalLen > TargetLen - 1) { |
| 383 | NumberOfLines--; |
| 384 | FinalLen = FinalLen - FINGERPRINT_FORMATED_LINE_LEN; |
| 385 | SourceLen = SourceLen - FINGERPRINT_LINE_LEN; |
| 386 | } |
Zhen Kong | 53e18a8 | 2016-11-30 11:15:37 -0800 | [diff] [blame] | 387 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 388 | for (LineNum = 0; LineNum < NumberOfLines; LineNum++) { |
| 389 | if (LineNum == 0) { |
| 390 | gBS->CopyMem (Target + TargetIndex, (VOID *)Id, AsciiStrLen (Id)); |
| 391 | } else { |
| 392 | gBS->CopyMem (Target + TargetIndex, (VOID *)StartlineSpace, |
| 393 | AsciiStrLen (StartlineSpace)); |
| 394 | } |
| 395 | TargetIndex = TargetIndex + AsciiStrLen (Id); |
| 396 | if ((SourceLen - SourceIndex) >= FINGERPRINT_LINE_LEN) { |
| 397 | gBS->CopyMem (Target + TargetIndex, Source + SourceIndex, |
| 398 | FINGERPRINT_LINE_LEN); |
| 399 | TargetIndex = TargetIndex + FINGERPRINT_LINE_LEN; |
| 400 | SourceIndex = SourceIndex + FINGERPRINT_LINE_LEN; |
| 401 | } else { |
| 402 | LastLineCharsCount = SourceLen % FINGERPRINT_LINE_LEN; |
| 403 | gBS->CopyMem (Target + TargetIndex, Source + SourceIndex, |
| 404 | LastLineCharsCount); |
| 405 | TargetIndex = TargetIndex + LastLineCharsCount; |
| 406 | SourceIndex = SourceIndex + LastLineCharsCount; |
| 407 | } |
| 408 | Target[TargetIndex] = '\n'; |
| 409 | TargetIndex = TargetIndex + 1; |
| 410 | } |
| 411 | /* NULL terminat the target array */ |
| 412 | Target[TargetIndex] = '\0'; |
Zhen Kong | 53e18a8 | 2016-11-30 11:15:37 -0800 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | /** |
| 416 | Draw the verified boot option menu |
| 417 | @param[out] OptionMenuInfo The option info |
| 418 | @retval EFI_SUCCESS The entry point is executed successfully. |
| 419 | @retval other Some error occurs when executing this entry point. |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 420 | **/ |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 421 | EFI_STATUS |
| 422 | VerifiedBootOptionMenuShowScreen (OPTION_MENU_INFO *OptionMenuInfo) |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 423 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 424 | EFI_STATUS Status = EFI_SUCCESS; |
| 425 | UINT32 Location = 0; |
| 426 | UINT32 Height = 0; |
| 427 | UINT32 i = 0; |
| 428 | UINT32 j = 0; |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 429 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 430 | /* Clear the screen before launch the verified boot option menu */ |
| 431 | gST->ConOut->ClearScreen (gST->ConOut); |
| 432 | ZeroMem (&OptionMenuInfo->Info, sizeof (MENU_OPTION_ITEM_INFO)); |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 433 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 434 | OptionMenuInfo->Info.MsgInfo = mOptionMenuMsgInfo; |
| 435 | for (i = 0; i < ARRAY_SIZE (mOptionMenuMsgInfo); i++) { |
| 436 | if (OptionMenuInfo->Info.MsgInfo[i].Attribute == OPTION_ITEM) { |
| 437 | if (j < VERIFIED_BOOT_OPTION_NUM) { |
| 438 | OptionMenuInfo->Info.OptionItems[j] = i; |
| 439 | j++; |
| 440 | } |
| 441 | } |
| 442 | OptionMenuInfo->Info.MsgInfo[i].Location = Location; |
| 443 | Status = DrawMenu (&OptionMenuInfo->Info.MsgInfo[i], &Height); |
| 444 | if (Status != EFI_SUCCESS) |
| 445 | return Status; |
| 446 | Location += Height; |
| 447 | } |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 448 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 449 | OptionMenuInfo->Info.MenuType = DISPLAY_MENU_MORE_OPTION; |
| 450 | OptionMenuInfo->Info.OptionNum = VERIFIED_BOOT_OPTION_NUM; |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 451 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 452 | /* Initialize the option index */ |
| 453 | OptionMenuInfo->Info.OptionIndex = VERIFIED_BOOT_OPTION_NUM; |
lijuang | 4734bc8 | 2016-08-16 16:13:19 +0800 | [diff] [blame] | 454 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 455 | return Status; |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | /** |
lijuang | 582d642 | 2016-09-08 21:53:50 +0800 | [diff] [blame] | 459 | Update the verified boot menu |
| 460 | @param[out] OptionMenuInfo The option info |
| 461 | @retval EFI_SUCCESS The entry point is executed successfully. |
| 462 | @retval other Some error occurs when executing this entry point. |
| 463 | **/ |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 464 | EFI_STATUS |
| 465 | VerifiedBootMenuUpdateShowScreen (OPTION_MENU_INFO *OptionMenuInfo) |
lijuang | 582d642 | 2016-09-08 21:53:50 +0800 | [diff] [blame] | 466 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 467 | EFI_STATUS Status = EFI_SUCCESS; |
| 468 | UINT32 Location = OptionMenuInfo->Info.MsgInfo->Location; |
| 469 | UINT32 Height = 0; |
| 470 | MENU_MSG_INFO *MsgStrInfo = NULL; |
lijuang | 582d642 | 2016-09-08 21:53:50 +0800 | [diff] [blame] | 471 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 472 | MsgStrInfo = AllocateZeroPool (sizeof (MENU_MSG_INFO)); |
| 473 | if (MsgStrInfo == NULL) { |
| 474 | DEBUG ((EFI_D_ERROR, "Failed to allocate zero pool.\n")); |
| 475 | Status = EFI_OUT_OF_RESOURCES; |
| 476 | goto Exit; |
| 477 | } |
lijuang | 582d642 | 2016-09-08 21:53:50 +0800 | [diff] [blame] | 478 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 479 | SetMenuMsgInfo (MsgStrInfo, "PRESS POWER KEY TO CONTINUE", COMMON_FACTOR, |
| 480 | BGR_WHITE, BGR_BLACK, ALIGN_LEFT, Location, 0); |
| 481 | Status = DrawMenu (MsgStrInfo, &Height); |
| 482 | if (Status != EFI_SUCCESS) |
| 483 | goto Exit; |
lijuang | 582d642 | 2016-09-08 21:53:50 +0800 | [diff] [blame] | 484 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 485 | OptionMenuInfo->Info.TimeoutTime = 60; |
| 486 | OptionMenuInfo->Info.MsgInfo->Action = POWEROFF; |
lijuang | 582d642 | 2016-09-08 21:53:50 +0800 | [diff] [blame] | 487 | |
| 488 | Exit: |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 489 | if (MsgStrInfo) { |
| 490 | FreePool (MsgStrInfo); |
| 491 | MsgStrInfo = NULL; |
| 492 | } |
lijuang | 582d642 | 2016-09-08 21:53:50 +0800 | [diff] [blame] | 493 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 494 | return Status; |
lijuang | 582d642 | 2016-09-08 21:53:50 +0800 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | /** |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 498 | Draw the verified boot menu |
| 499 | @param[in] Type The warning menu type |
| 500 | @param[out] OptionMenuInfo The option info |
lijuang | 4734bc8 | 2016-08-16 16:13:19 +0800 | [diff] [blame] | 501 | @retval EFI_SUCCESS The entry point is executed successfully. |
| 502 | @retval other Some error occurs when executing this entry point. |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 503 | **/ |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 504 | EFI_STATUS |
| 505 | VerifiedBootMenuShowScreen (OPTION_MENU_INFO *OptionMenuInfo, |
| 506 | DISPLAY_MENU_TYPE Type) |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 507 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 508 | EFI_STATUS Status = EFI_SUCCESS; |
| 509 | UINT32 Location = 0; |
| 510 | UINT32 Height = 0; |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 511 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 512 | ZeroMem (&OptionMenuInfo->Info, sizeof (MENU_OPTION_ITEM_INFO)); |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 513 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 514 | mMenuMsgInfo[Type].WarningTitle.Location = Location; |
| 515 | Status = DrawMenu (&mMenuMsgInfo[Type].WarningTitle, &Height); |
| 516 | if (Status != EFI_SUCCESS) |
| 517 | return Status; |
| 518 | Location += Height; |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 519 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 520 | mMenuMsgInfo[Type].WarningMsg.Location = Location; |
| 521 | Status = DrawMenu (&mMenuMsgInfo[Type].WarningMsg, &Height); |
| 522 | if (Status != EFI_SUCCESS) |
| 523 | return Status; |
| 524 | Location += Height; |
lijuang | 582d642 | 2016-09-08 21:53:50 +0800 | [diff] [blame] | 525 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 526 | mMenuMsgInfo[Type].UrlMsg.Location = Location; |
| 527 | Status = DrawMenu (&mMenuMsgInfo[Type].UrlMsg, &Height); |
| 528 | if (Status != EFI_SUCCESS) |
| 529 | return Status; |
| 530 | Location += Height; |
lijuang | 582d642 | 2016-09-08 21:53:50 +0800 | [diff] [blame] | 531 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 532 | OptionMenuInfo->Info.MsgInfo = &mMenuMsgInfo[Type].NoticeMsg; |
| 533 | OptionMenuInfo->Info.MsgInfo->Location = Location; |
| 534 | Status = DrawMenu (OptionMenuInfo->Info.MsgInfo, &Height); |
| 535 | if (Status != EFI_SUCCESS) |
| 536 | return Status; |
| 537 | Location += Height; |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 538 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 539 | if (Type == DISPLAY_MENU_YELLOW) { |
| 540 | UINT8 FingerPrint[MAX_MSG_SIZE]; |
| 541 | UINTN FingerPrintLen = 0; |
Zhen Kong | 53e18a8 | 2016-11-30 11:15:37 -0800 | [diff] [blame] | 542 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 543 | mMenuMsgInfo[Type].Fingerprint.Location = Location; |
Shivaprasad Hongal | 7fd6a52 | 2017-05-10 13:56:28 -0700 | [diff] [blame] | 544 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 545 | Status = GetCertFingerPrint (FingerPrint, ARRAY_SIZE (FingerPrint), |
| 546 | &FingerPrintLen); |
| 547 | if (Status == EFI_SUCCESS) { |
| 548 | UINTN DisplayStrLen = 0; |
| 549 | CHAR8 *DisplayStr = NULL; |
Zhen Kong | 53e18a8 | 2016-11-30 11:15:37 -0800 | [diff] [blame] | 550 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 551 | /* Each bytes needs two characters to be shown on display */ |
| 552 | DisplayStrLen = FingerPrintLen * 2; |
Bhanuprakash Modem | 763cdd5 | 2018-11-01 14:49:55 +0530 | [diff] [blame] | 553 | DisplayStr = AllocateZeroPool (DisplayStrLen); |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 554 | if (DisplayStr == NULL) { |
| 555 | return EFI_OUT_OF_RESOURCES; |
| 556 | } |
| 557 | /* Convert the fingerprint to a charcater string */ |
| 558 | GetHexString (DisplayStr, FingerPrint, FingerPrintLen); |
| 559 | /* Save fingerprint in a formated string for display */ |
| 560 | GetDisplayOutPut (mMenuMsgInfo[Type].Fingerprint.Msg, MAX_MSG_SIZE, |
| 561 | DisplayStr, DisplayStrLen); |
| 562 | FreePool (DisplayStr); |
| 563 | DisplayStr = NULL; |
| 564 | } else { |
| 565 | AsciiSPrint (mMenuMsgInfo[Type].Fingerprint.Msg, MAX_MSG_SIZE, "ID: %a\n", |
| 566 | "unsupported"); |
| 567 | } |
| 568 | Status = DrawMenu (&mMenuMsgInfo[Type].Fingerprint, &Height); |
| 569 | if (Status != EFI_SUCCESS) |
| 570 | return Status; |
| 571 | } |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 572 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 573 | OptionMenuInfo->Info.MenuType = Type; |
| 574 | /* Initialize the time out time */ |
| 575 | if (Type == DISPLAY_MENU_RED || Type == DISPLAY_MENU_EIO) |
| 576 | OptionMenuInfo->Info.TimeoutTime = 30; |
| 577 | else |
| 578 | OptionMenuInfo->Info.TimeoutTime = 10; |
lijuang | 4734bc8 | 2016-08-16 16:13:19 +0800 | [diff] [blame] | 579 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 580 | return Status; |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | /** |
| 584 | Draw the verified boot menu and start to detect the key's status |
lijuang | 582d642 | 2016-09-08 21:53:50 +0800 | [diff] [blame] | 585 | @param[in] Type The type of the warning menu: |
| 586 | [DISPLAY_MENU_YELLOW] ----- Yellow warning menu |
| 587 | [DISPLAY_MENU_ORANGE] ----- Orange warning menu |
| 588 | [DISPLAY_MENU_RED] ----- Red warning menu |
| 589 | [DISPLAY_MENU_EIO] ----- dm-verity EIO warning menu |
| 590 | @retval EFI_SUCCESS The entry point is executed successfully. |
| 591 | @retval other Some error occurs when executing this entry point. |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 592 | **/ |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 593 | EFI_STATUS |
| 594 | DisplayVerifiedBootMenu (DISPLAY_MENU_TYPE Type) |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 595 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 596 | EFI_STATUS Status = EFI_SUCCESS; |
| 597 | OPTION_MENU_INFO *OptionMenuInfo; |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 598 | |
Anuj Garg | ae40955 | 2020-06-03 19:21:55 +0530 | [diff] [blame^] | 599 | if (IsEnableDisplayMenuFlagSupported ()) { |
| 600 | OptionMenuInfo = &gMenuInfo; |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 601 | DrawMenuInit (); |
lijuang | 6e995df | 2017-05-12 18:46:04 +0800 | [diff] [blame] | 602 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 603 | /* Initialize the last_msg_type */ |
| 604 | OptionMenuInfo->LastMenuType = OptionMenuInfo->Info.MenuType; |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 605 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 606 | Status = VerifiedBootMenuShowScreen (OptionMenuInfo, Type); |
| 607 | if (Status != EFI_SUCCESS) { |
| 608 | DEBUG ((EFI_D_ERROR, "Unable to show verified menu on screen: %r\n", |
| 609 | Status)); |
| 610 | return Status; |
| 611 | } |
| 612 | if (Type != DISPLAY_MENU_RED) { |
| 613 | MenuKeysDetectionInit (OptionMenuInfo); |
| 614 | } |
| 615 | } else { |
| 616 | DEBUG ((EFI_D_INFO, "Display menu is not enabled!\n")); |
| 617 | Status = EFI_NOT_STARTED; |
| 618 | } |
lijuang | 582d642 | 2016-09-08 21:53:50 +0800 | [diff] [blame] | 619 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 620 | return Status; |
lijuang | 593d735 | 2016-07-27 19:31:04 +0800 | [diff] [blame] | 621 | } |
lijuang | c6c7dd0 | 2017-08-16 17:31:16 +0800 | [diff] [blame] | 622 | #endif |