blob: eb7f8b9e3ed6facc8fa8147959fea7a782f68af2 [file] [log] [blame]
Anuj Gargae409552020-06-03 19:21:55 +05301/* Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
lijuang593d7352016-07-27 19:31:04 +08002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
lijuang593d7352016-07-27 19:31:04 +080028#include <Library/BaseLib.h>
lijuang593d7352016-07-27 19:31:04 +080029#include <Library/BaseMemoryLib.h>
30#include <Library/DebugLib.h>
lijuang593d7352016-07-27 19:31:04 +080031#include <Library/DeviceInfo.h>
32#include <Library/DrawUI.h>
Jeevan Shriram17f173d2017-10-24 22:11:07 -070033#include <Library/MemoryAllocationLib.h>
lijuang593d7352016-07-27 19:31:04 +080034#include <Library/MenuKeysDetection.h>
Jeevan Shriram17f173d2017-10-24 22:11:07 -070035#include <Library/UefiBootServicesTableLib.h>
Jeevan Shriram17f173d2017-10-24 22:11:07 -070036#include <Library/UnlockMenu.h>
lijuang593d7352016-07-27 19:31:04 +080037#include <Library/UpdateDeviceTree.h>
Shivaprasad Hongal7fd6a522017-05-10 13:56:28 -070038#include <Library/VerifiedBoot.h>
lijuangc6c7dd02017-08-16 17:31:16 +080039#include <Library/VerifiedBootMenu.h>
Anuj Gargae409552020-06-03 19:21:55 +053040#include <Library/BootLinux.h>
Jeevan Shriram17f173d2017-10-24 22:11:07 -070041#include <Protocol/EFIVerifiedBoot.h>
42#include <Uefi.h>
lijuang593d7352016-07-27 19:31:04 +080043
lijuangc6c7dd02017-08-16 17:31:16 +080044#if VERIFIED_BOOT || VERIFIED_BOOT_2
Zhen Kong53e18a82016-11-30 11:15:37 -080045#define FINGERPRINT_LINE_LEN 16
Jeevan Shriram17f173d2017-10-24 22:11:07 -070046#define FINGERPRINT_FORMATED_LINE_LEN FINGERPRINT_LINE_LEN + 5
47#define VERIFIED_BOOT_OPTION_NUM 5
lijuang593d7352016-07-27 19:31:04 +080048STATIC OPTION_MENU_INFO gMenuInfo;
49
50typedef struct {
Jeevan Shriram17f173d2017-10-24 22:11:07 -070051 MENU_MSG_INFO WarningTitle;
52 MENU_MSG_INFO WarningMsg;
53 MENU_MSG_INFO UrlMsg;
54 MENU_MSG_INFO NoticeMsg;
55 MENU_MSG_INFO Fingerprint;
lijuang582d6422016-09-08 21:53:50 +080056} WARNING_MENU_MSG_INFO;
lijuang593d7352016-07-27 19:31:04 +080057
lijuang582d6422016-09-08 21:53:50 +080058STATIC WARNING_MENU_MSG_INFO mMenuMsgInfo[] = {
Jeevan Shriram17f173d2017-10-24 22:11:07 -070059 [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}},
lijuang593d7352016-07-27 19:31:04 +0800205};
206
207STATIC MENU_MSG_INFO mOptionMenuMsgInfo[] = {
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700208 {{"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},
lijuang593d7352016-07-27 19:31:04 +0800299};
300
301/**
Zhen Kong53e18a82016-11-30 11:15:37 -0800302Convert UINT8 array to a CHAR8 hex array.
303The caller of the function should allocate memory properly.
304Size 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 Shriram17f173d2017-10-24 22:11:07 -0700311STATIC VOID
312GetHexString (CHAR8 *Target, UINT8 *Source, UINTN Len)
Zhen Kong53e18a82016-11-30 11:15:37 -0800313{
314
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700315 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 Kong53e18a82016-11-30 11:15:37 -0800325}
326
327/**
328
329Construct display output array.
330The caller should allocate the buffer properly before invoking this function.
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700331The assumption is display output and finger print have larger size than 22 and
33216.
Zhen Kong53e18a82016-11-30 11:15:37 -0800333
334The target array starts with string "ID: " following with the fingerprint.
335Each 16 charcaters of fingerprint are shown in one line.
336If fingerprint size is too big, it only copies the number of characters
337that matches the output size.
338
339Eaxmple output:
340
341ID: 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 Shriram17f173d2017-10-24 22:11:07 -0700352STATIC VOID
353GetDisplayOutPut (CHAR8 *Target,
354 UINTN TargetLen,
355 CHAR8 *Source,
356 UINTN SourceLen)
Zhen Kong53e18a82016-11-30 11:15:37 -0800357{
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700358 UINTN LastLineCharsCount = 0;
359 UINTN TargetIndex = 0;
360 UINTN SourceIndex = 0;
361 UINTN LineNum = 0;
362 UINTN FinalLen = 0;
Zhen Kong53e18a82016-11-30 11:15:37 -0800363
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700364 /* 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 Kong53e18a82016-11-30 11:15:37 -0800369
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700370 /* 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 Kong53e18a82016-11-30 11:15:37 -0800374
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700375 /* each line contains 4 spaces at the beginning and one endline
376 character at the end */
377 FinalLen = (AsciiStrLen (Id) + 1) * (NumberOfLines) + SourceLen;
Zhen Kong53e18a82016-11-30 11:15:37 -0800378
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700379 /* 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 Kong53e18a82016-11-30 11:15:37 -0800387
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700388 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 Kong53e18a82016-11-30 11:15:37 -0800413}
414
415/**
416Draw 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.
lijuang593d7352016-07-27 19:31:04 +0800420 **/
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700421EFI_STATUS
422VerifiedBootOptionMenuShowScreen (OPTION_MENU_INFO *OptionMenuInfo)
lijuang593d7352016-07-27 19:31:04 +0800423{
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700424 EFI_STATUS Status = EFI_SUCCESS;
425 UINT32 Location = 0;
426 UINT32 Height = 0;
427 UINT32 i = 0;
428 UINT32 j = 0;
lijuang593d7352016-07-27 19:31:04 +0800429
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700430 /* 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));
lijuang593d7352016-07-27 19:31:04 +0800433
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700434 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 }
lijuang593d7352016-07-27 19:31:04 +0800448
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700449 OptionMenuInfo->Info.MenuType = DISPLAY_MENU_MORE_OPTION;
450 OptionMenuInfo->Info.OptionNum = VERIFIED_BOOT_OPTION_NUM;
lijuang593d7352016-07-27 19:31:04 +0800451
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700452 /* Initialize the option index */
453 OptionMenuInfo->Info.OptionIndex = VERIFIED_BOOT_OPTION_NUM;
lijuang4734bc82016-08-16 16:13:19 +0800454
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700455 return Status;
lijuang593d7352016-07-27 19:31:04 +0800456}
457
458/**
lijuang582d6422016-09-08 21:53:50 +0800459 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 Shriram17f173d2017-10-24 22:11:07 -0700464EFI_STATUS
465VerifiedBootMenuUpdateShowScreen (OPTION_MENU_INFO *OptionMenuInfo)
lijuang582d6422016-09-08 21:53:50 +0800466{
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700467 EFI_STATUS Status = EFI_SUCCESS;
468 UINT32 Location = OptionMenuInfo->Info.MsgInfo->Location;
469 UINT32 Height = 0;
470 MENU_MSG_INFO *MsgStrInfo = NULL;
lijuang582d6422016-09-08 21:53:50 +0800471
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700472 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 }
lijuang582d6422016-09-08 21:53:50 +0800478
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700479 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;
lijuang582d6422016-09-08 21:53:50 +0800484
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700485 OptionMenuInfo->Info.TimeoutTime = 60;
486 OptionMenuInfo->Info.MsgInfo->Action = POWEROFF;
lijuang582d6422016-09-08 21:53:50 +0800487
488Exit:
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700489 if (MsgStrInfo) {
490 FreePool (MsgStrInfo);
491 MsgStrInfo = NULL;
492 }
lijuang582d6422016-09-08 21:53:50 +0800493
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700494 return Status;
lijuang582d6422016-09-08 21:53:50 +0800495}
496
497/**
lijuang593d7352016-07-27 19:31:04 +0800498 Draw the verified boot menu
499 @param[in] Type The warning menu type
500 @param[out] OptionMenuInfo The option info
lijuang4734bc82016-08-16 16:13:19 +0800501 @retval EFI_SUCCESS The entry point is executed successfully.
502 @retval other Some error occurs when executing this entry point.
lijuang593d7352016-07-27 19:31:04 +0800503 **/
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700504EFI_STATUS
505VerifiedBootMenuShowScreen (OPTION_MENU_INFO *OptionMenuInfo,
506 DISPLAY_MENU_TYPE Type)
lijuang593d7352016-07-27 19:31:04 +0800507{
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700508 EFI_STATUS Status = EFI_SUCCESS;
509 UINT32 Location = 0;
510 UINT32 Height = 0;
lijuang593d7352016-07-27 19:31:04 +0800511
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700512 ZeroMem (&OptionMenuInfo->Info, sizeof (MENU_OPTION_ITEM_INFO));
lijuang593d7352016-07-27 19:31:04 +0800513
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700514 mMenuMsgInfo[Type].WarningTitle.Location = Location;
515 Status = DrawMenu (&mMenuMsgInfo[Type].WarningTitle, &Height);
516 if (Status != EFI_SUCCESS)
517 return Status;
518 Location += Height;
lijuang593d7352016-07-27 19:31:04 +0800519
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700520 mMenuMsgInfo[Type].WarningMsg.Location = Location;
521 Status = DrawMenu (&mMenuMsgInfo[Type].WarningMsg, &Height);
522 if (Status != EFI_SUCCESS)
523 return Status;
524 Location += Height;
lijuang582d6422016-09-08 21:53:50 +0800525
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700526 mMenuMsgInfo[Type].UrlMsg.Location = Location;
527 Status = DrawMenu (&mMenuMsgInfo[Type].UrlMsg, &Height);
528 if (Status != EFI_SUCCESS)
529 return Status;
530 Location += Height;
lijuang582d6422016-09-08 21:53:50 +0800531
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700532 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;
lijuang593d7352016-07-27 19:31:04 +0800538
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700539 if (Type == DISPLAY_MENU_YELLOW) {
540 UINT8 FingerPrint[MAX_MSG_SIZE];
541 UINTN FingerPrintLen = 0;
Zhen Kong53e18a82016-11-30 11:15:37 -0800542
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700543 mMenuMsgInfo[Type].Fingerprint.Location = Location;
Shivaprasad Hongal7fd6a522017-05-10 13:56:28 -0700544
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700545 Status = GetCertFingerPrint (FingerPrint, ARRAY_SIZE (FingerPrint),
546 &FingerPrintLen);
547 if (Status == EFI_SUCCESS) {
548 UINTN DisplayStrLen = 0;
549 CHAR8 *DisplayStr = NULL;
Zhen Kong53e18a82016-11-30 11:15:37 -0800550
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700551 /* Each bytes needs two characters to be shown on display */
552 DisplayStrLen = FingerPrintLen * 2;
Bhanuprakash Modem763cdd52018-11-01 14:49:55 +0530553 DisplayStr = AllocateZeroPool (DisplayStrLen);
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700554 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 }
lijuang593d7352016-07-27 19:31:04 +0800572
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700573 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;
lijuang4734bc82016-08-16 16:13:19 +0800579
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700580 return Status;
lijuang593d7352016-07-27 19:31:04 +0800581}
582
583/**
584 Draw the verified boot menu and start to detect the key's status
lijuang582d6422016-09-08 21:53:50 +0800585 @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.
lijuang593d7352016-07-27 19:31:04 +0800592**/
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700593EFI_STATUS
594DisplayVerifiedBootMenu (DISPLAY_MENU_TYPE Type)
lijuang593d7352016-07-27 19:31:04 +0800595{
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700596 EFI_STATUS Status = EFI_SUCCESS;
597 OPTION_MENU_INFO *OptionMenuInfo;
lijuang593d7352016-07-27 19:31:04 +0800598
Anuj Gargae409552020-06-03 19:21:55 +0530599 if (IsEnableDisplayMenuFlagSupported ()) {
600 OptionMenuInfo = &gMenuInfo;
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700601 DrawMenuInit ();
lijuang6e995df2017-05-12 18:46:04 +0800602
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700603 /* Initialize the last_msg_type */
604 OptionMenuInfo->LastMenuType = OptionMenuInfo->Info.MenuType;
lijuang593d7352016-07-27 19:31:04 +0800605
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700606 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 }
lijuang582d6422016-09-08 21:53:50 +0800619
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700620 return Status;
lijuang593d7352016-07-27 19:31:04 +0800621}
lijuangc6c7dd02017-08-16 17:31:16 +0800622#endif