From cc62e19d05d3e067a0262b4ad5e26cc3d366627e Mon Sep 17 00:00:00 2001 From: Gary Ching-Pang Lin Date: Thu, 18 Apr 2013 17:13:12 +0800 Subject: [PATCH] MokManager: draw the countdown screen --- MokManager.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/MokManager.c b/MokManager.c index aacef61..67c49ad 100644 --- a/MokManager.c +++ b/MokManager.c @@ -1375,6 +1375,63 @@ static BOOLEAN verify_pw(void) return TRUE; } +static int draw_countdown() +{ + SIMPLE_TEXT_OUTPUT_MODE SavedMode; + EFI_INPUT_KEY key; + EFI_STATUS status; + UINTN cols, rows; + CHAR16 *title[2]; + CHAR16 *message = L"Press any key to perform MOK management"; + int timeout = 10, wait = 10000000; + + CopyMem(&SavedMode, ST->ConOut->Mode, sizeof(SavedMode)); + uefi_call_wrapper(ST->ConOut->EnableCursor, 2, ST->ConOut, FALSE); + uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, + EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE); + + title[0] = PoolPrint (L"%s UEFI key management", SHIM_VENDOR); + title[1] = NULL; + + console_print_box_at(title, -1, 0, 0, -1, -1, 1, 1); + + uefi_call_wrapper(ST->ConOut->QueryMode, 4, ST->ConOut, + ST->ConOut->Mode->Mode, &cols, &rows); + + PrintAt((cols - StrLen(message))/2, rows/2, message); + while (1) { + if (timeout > 1) + PrintAt(2, rows - 3, L"Booting in %d seconds ", timeout); + else if (timeout) + PrintAt(2, rows - 3, L"Booting in %d second ", timeout); + + status = WaitForSingleEvent(ST->ConIn->WaitForKey, wait); + + if (status != EFI_TIMEOUT) { + /* Clear the key in the queue */ + uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, + ST->ConIn, &key); + break; + } + + timeout--; + if (!timeout) + break; + } + + FreePool(title[0]); + + /* Restore everything */ + uefi_call_wrapper(ST->ConOut->EnableCursor, 2, ST->ConOut, + SavedMode.CursorVisible); + uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, + SavedMode.CursorColumn, SavedMode.CursorRow); + uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, + SavedMode.Attribute); + + return timeout; +} + typedef enum { MOK_CONTINUE_BOOT, MOK_RESET_MOK, @@ -1492,6 +1549,9 @@ static EFI_STATUS enter_mok_menu(EFI_HANDLE image_handle, menu_strings[i] = NULL; + if (draw_countdown() == 0) + goto out; + while (choice >= 0) { choice = console_select((CHAR16 *[]){ L"Perform MOK management", NULL }, menu_strings, 0);