Set EFI ReadKey timeout to 15 seconds

This commit is contained in:
Lauri Kenttä
2023-09-02 23:31:02 +03:00
parent e44ce9f5ee
commit ad0b71c49b
3 changed files with 19 additions and 14 deletions

View File

@@ -393,14 +393,14 @@ EFI_STATUS EFIAPI EfiMain(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *ST_) {
} }
} }
Print(L"HackBGRT: Reverting to %s.\n", config.boot_path); Print(L"HackBGRT: Reverting to %s.\n", config.boot_path);
Print(L"Press escape to cancel, any other key to boot.\n"); Print(L"Press escape to cancel or any other key (or wait 15 seconds) to boot.\n");
if (ReadKey().ScanCode == SCAN_ESC) { if (ReadKey(15000).ScanCode == SCAN_ESC) {
goto fail; goto fail;
} }
} } else if (config.debug) {
if (config.debug) { Print(L"HackBGRT: Ready to boot. Disable debug mode to skip this screen.\n");
Print(L"HackBGRT: Ready to boot.\nPress escape to cancel, any other key to boot.\n"); Print(L"Press escape to cancel or any other key (or wait 15 seconds) to boot.\n");
if (ReadKey().ScanCode == SCAN_ESC) { if (ReadKey(15000).ScanCode == SCAN_ESC) {
return 0; return 0;
} }
} }
@@ -409,6 +409,7 @@ EFI_STATUS EFIAPI EfiMain(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *ST_) {
goto fail; goto fail;
} }
Print(L"HackBGRT: Started %s. Why are we still here?!\n", config.boot_path); Print(L"HackBGRT: Started %s. Why are we still here?!\n", config.boot_path);
Print(L"Please check that %s is not actually HackBGRT!\n", config.boot_path);
goto fail; goto fail;
fail: { fail: {
@@ -419,8 +420,8 @@ EFI_STATUS EFIAPI EfiMain(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *ST_) {
#else #else
Print(L"HackBGRT version: unknown; not an official release?\n"); Print(L"HackBGRT version: unknown; not an official release?\n");
#endif #endif
Print(L"Press any key to exit.\n"); Print(L"Press any key (or wait 15 seconds) to exit.\n");
ReadKey(); ReadKey(15000);
return 1; return 1;
} }
} }

View File

@@ -68,14 +68,15 @@ void RandomSeedAuto(void) {
RandomSeed(a, b), Random(), Random(); RandomSeed(a, b), Random(), Random();
} }
void WaitKey(void) { EFI_STATUS WaitKey(UINT64 timeout_ms) {
ST->ConIn->Reset(ST->ConIn, FALSE); ST->ConIn->Reset(ST->ConIn, FALSE);
WaitForSingleEvent(ST->ConIn->WaitForKey, 0); const int ms_to_100ns = 10000;
return WaitForSingleEvent(ST->ConIn->WaitForKey, timeout_ms * ms_to_100ns);
} }
EFI_INPUT_KEY ReadKey(void) { EFI_INPUT_KEY ReadKey(UINT64 timeout_ms) {
WaitKey();
EFI_INPUT_KEY key = {0}; EFI_INPUT_KEY key = {0};
WaitKey(timeout_ms);
ST->ConIn->ReadKeyStroke(ST->ConIn, &key); ST->ConIn->ReadKeyStroke(ST->ConIn, &key);
return key; return key;
} }

View File

@@ -82,15 +82,18 @@ extern void RandomSeedAuto(void);
/** /**
* Wait for a key press. It will still remain in the buffer. * Wait for a key press. It will still remain in the buffer.
*
* @param timeout_ms The timeout in milliseconds, or 0 for no timeout.
*/ */
extern void WaitKey(void); extern EFI_STATUS WaitKey(UINT64 timeout_ms);
/** /**
* Wait for a key press and read it. * Wait for a key press and read it.
* *
* @param timeout_ms The timeout in milliseconds, or 0 for no timeout.
* @return The pressed key. * @return The pressed key.
*/ */
extern EFI_INPUT_KEY ReadKey(void); extern EFI_INPUT_KEY ReadKey(UINT64 timeout_ms);
/** /**
* Load a file, allocate some extra bytes as well. * Load a file, allocate some extra bytes as well.