Skip to content

Commit

Permalink
HelloUefi: Add 30 second stall (#120)
Browse files Browse the repository at this point in the history
## Description

This application is the simplest UEFI application possible, with no
dependencies. These changes add a 30 second stall such that a platform
may boot directly to this application and see "Hello UEFI!" with no need
for a shell to run it (Such as ShellPkg). Futher This

- [ ] Impacts functionality?
- [ ] Impacts security?
- [ ] Breaking change?
- [ ] Includes tests?
- [X] Includes documentation?
  - readme.md

## How This Was Tested

Ran on a physical machine, QemuQ35,

built With GCC and VS2022
 
## Integration Instructions

<_Describe how these changes should be integrated. Use N/A if nothing is
required._>

---------

Co-authored-by: Michael Kubacki <[email protected]>
  • Loading branch information
Flickdm and makubacki authored Jul 14, 2023
1 parent bcd2bdc commit d479c88
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
25 changes: 22 additions & 3 deletions OemPkg/HelloUefi/HelloUefi.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @file
This sample application that is the simplest UEFI application possible.
It simply prints "Hello Uefi!" to the UEFI Console Out device.
It simply prints "Hello Uefi!" to the UEFI Console Out device and stalls the CPU for 30 seconds.
Copyright (C) Microsoft Corporation
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand All @@ -9,6 +9,9 @@
#include <Uefi.h>
#include <Library/UefiApplicationEntryPoint.h>

// 30 seconds in microseconds
#define STALL_30_SECONDS 30000000

/**
The user Entry Point for Application. The user code starts with this function
as the real entry point for the application.
Expand All @@ -30,14 +33,30 @@ UefiMain (
{
EFI_STATUS Status;

if ((SystemTable == NULL) || (SystemTable->ConOut == NULL) || (SystemTable->ConOut->OutputString == NULL)) {
if (SystemTable == NULL) {

return EFI_INVALID_PARAMETER;
}

Status = SystemTable->ConOut->OutputString (SystemTable->ConOut, L"Hello Uefi!\r\n");
if ((SystemTable->ConOut == NULL) || (SystemTable->ConOut->OutputString == NULL) || (SystemTable->ConOut->ClearScreen == NULL)) {
return EFI_INVALID_PARAMETER;
}

if ((SystemTable->BootServices == NULL) || (SystemTable->BootServices->Stall == NULL)) {
return EFI_INVALID_PARAMETER;
}

Status = SystemTable->ConOut->ClearScreen (SystemTable->ConOut);
if (EFI_ERROR (Status)) {
return Status;
}

Status = SystemTable->ConOut->OutputString (SystemTable->ConOut, L"\r\nHello Uefi!\r\n");
if (EFI_ERROR (Status)) {
return Status;
}

SystemTable->BootServices->Stall (STALL_30_SECONDS);

return EFI_SUCCESS;
}
2 changes: 1 addition & 1 deletion OemPkg/HelloUefi/HelloUefi.inf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Sample UEFI Application Reference Module.
#
# This sample application that is the simplest UEFI application possible.
# It simply prints "Hello Uefi!" to the UEFI Console Out device.
# It simply prints "Hello Uefi!" to the UEFI Console Out device and stalls the CPU for 30 seconds.
#
# Copyright (C) Microsoft Corporation
# SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down
19 changes: 19 additions & 0 deletions OemPkg/HelloUefi/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Simple Bootable Media Example

Barebones example of how to boot to an EFI Application with no dependencies.

## Boot Directions

1. Format a usb drive as FAT32
2. At the root of this usb drive create the following folders: `EFI/Boot/`
3. Build and rename `HelloUefi.efi` as `boot<arch>.efi` and place at `EFI/BOOT/`

* IA32 - `bootx86.efi`
* AMD64 - `bootx64.efi`
* AARCH64 - `bootaa64.efi`

4. On your platform, boot into UEFI Menu and change the boot order to boot USB first
5. Turn off your platform
6. Plug in usb drive
7. Reboot
8. If successful, you should now see `Hello Uefi!` in the top left corner

0 comments on commit d479c88

Please sign in to comment.