Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OvmfPkg: include serial redirection opt by default #91

Merged
merged 15 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/scripts/build-qemu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

make -C BaseTools
source ./edksetup.sh

export EDK2_PLATFORMS_PATH="$WORKSPACE/edk2-platforms"
export PACKAGES_PATH="$WORKSPACE:\
$EDK2_PLATFORMS_PATH/Platform/Intel:\
$EDK2_PLATFORMS_PATH/Silicon/Intel:\
$EDK2_PLATFORMS_PATH/Features/Intel:\
$EDK2_PLATFORMS_PATH/Features/Intel/Debugging:\
$EDK2_PLATFORMS_PATH/Features/Intel/Network:\
$EDK2_PLATFORMS_PATH/Features/Intel/OutOfBandManagement:\
$EDK2_PLATFORMS_PATH/Features/Intel/PowerManagement:\
$EDK2_PLATFORMS_PATH/Features/Intel/SystemInformation:\
$EDK2_PLATFORMS_PATH/Features/Intel/UserInterface"

build -a IA32 -a X64 -t GCC5 -b RELEASE -p OvmfPkg/OvmfPkgX64.dsc
build -a IA32 -a X64 -t GCC5 -b DEBUG -p OvmfPkg/OvmfPkgX64.dsc
19 changes: 19 additions & 0 deletions .github/scripts/run-qemu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

cp ./Build/OvmfX64/RELEASE_GCC5/FV/OVMF_VARS.fd /tmp/OVMF_VARS.fd

q35_params="-machine q35,smm=on \
-global driver=cfi.pflash01,property=secure,value=on \
-drive if=pflash,format=raw,unit=0,file=Build/OvmfX64/RELEASE_GCC5/FV/OVMF_CODE.fd,readonly=on \
-drive if=pflash,format=raw,unit=1,file=/tmp/OVMF_VARS.fd \
-debugcon file:debug.log -global isa-debugcon.iobase=0x402 \
-global ICH9-LPC.disable_s3=1 \
-qmp unix:/tmp/qmp-socket,server,nowait \
-net none \
-serial telnet:localhost:1234,server,nowait"

if [ "$1" == "nographic" ]; then
qemu-system-x86_64 $q35_params -nographic
else
qemu-system-x86_64 $q35_params
fi
61 changes: 61 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Check EDK2 QEMU Build

on:
push:
branches:
- dasharo
pull_request:
branches:
- dasharo

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2
with:
submodules: 'recursive' # Checkout submodules recursively.

- name: Clone edk2-platforms Repository
run: |
git clone https://github.com/Dasharo/edk2-platforms.git && \
cd edk2-platforms && \
git checkout 3323ed481d35096fb6a7eae7b49f35eff00f86cf && \
cd -

- name: Build OVMF Firmware Image
run: |
docker run --rm -i -v $PWD:/home/coreboot/coreboot:rw \
-u $(id -u):$(id -g) -w /home/coreboot/coreboot \
coreboot/coreboot-sdk:2021-09-23_b0d87f753c \
./.github/scripts/build-qemu.sh

- name: Check RELEASE build Artifacts
run: |
if [ -f "Build/OvmfX64/RELEASE_GCC5/FV/OVMF_CODE.fd" ] && [ -f "Build/OvmfX64/RELEASE_GCC5/FV/OVMF_VARS.fd" ]; then
echo "RELEASE build successful. OVMF firmware image files found."
else
echo "RELEASE build failed. OVMF firmware image files not found."
exit 1
fi

- name: Check DEBUG build Artifacts
run: |
if [ -f "Build/OvmfX64/DEBUG_GCC5/FV/OVMF_CODE.fd" ] && [ -f "Build/OvmfX64/DEBUG_GCC5/FV/OVMF_VARS.fd" ]; then
echo "DEBUG build successful. OVMF firmware image files found."
else
echo "DEBUG build failed. OVMF firmware image files not found."
exit 1
fi

- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: ovmf-artifacts # Name for the artifact
path: |
Build/OvmfX64/RELEASE_GCC5/FV/OVMF_CODE.fd
Build/OvmfX64/RELEASE_GCC5/FV/OVMF_VARS.fd
Build/OvmfX64/DEBUG_GCC5/FV/OVMF_CODE.fd
Build/OvmfX64/DEBUG_GCC5/FV/OVMF_VARS.fd
165 changes: 162 additions & 3 deletions OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
#include <Library/PlatformBmPrintScLib.h>
#include <Library/Tcg2PhysicalPresenceLib.h>
#include <Library/XenPlatformLib.h>
#include <Guid/TtyTerm.h>

EFI_GUID mBootMenuFile = {
0xEEC25BDC, 0x67F2, 0x4D95, { 0xB1, 0xD5, 0xF8, 0x1B, 0x20, 0x39, 0xD1, 0x1D }
};

//
// Global data
Expand Down Expand Up @@ -79,6 +83,148 @@ InstallDevicePathCallback (
VOID
);

EFI_DEVICE_PATH *
FvFilePath (
EFI_GUID *FileGuid
)
{

EFI_STATUS Status;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;

EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);

Status = gBS->HandleProtocol (
gImageHandle,
&gEfiLoadedImageProtocolGuid,
(VOID **) &LoadedImage
);
ASSERT_EFI_ERROR (Status);
return AppendDevicePathNode (
DevicePathFromHandle (LoadedImage->DeviceHandle),
(EFI_DEVICE_PATH_PROTOCOL *) &FileNode
);
}

/**
Create one boot option for BootManagerMenuApp.

@param FileGuid Input file guid for the BootManagerMenuApp.
@param Description Description of the BootManagerMenuApp boot option.
@param Position Position of the new load option to put in the ****Order variable.
@param IsBootCategory Whether this is a boot category.


@retval OptionNumber Return the option number info.

**/
UINTN
RegisterBootManagerMenuAppBootOption (
EFI_GUID *FileGuid,
CHAR16 *Description,
UINTN Position,
BOOLEAN IsBootCategory
)
{
EFI_STATUS Status;
EFI_BOOT_MANAGER_LOAD_OPTION NewOption;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
UINTN OptionNumber;

DevicePath = FvFilePath (FileGuid);
Status = EfiBootManagerInitializeLoadOption (
&NewOption,
LoadOptionNumberUnassigned,
LoadOptionTypeBoot,
IsBootCategory ? LOAD_OPTION_ACTIVE : LOAD_OPTION_CATEGORY_APP,
Description,
DevicePath,
NULL,
0
);
ASSERT_EFI_ERROR (Status);
FreePool (DevicePath);

Status = EfiBootManagerAddLoadOptionVariable (&NewOption, Position);
ASSERT_EFI_ERROR (Status);

OptionNumber = NewOption.OptionNumber;

EfiBootManagerFreeLoadOption (&NewOption);

return OptionNumber;
}

/**
Check if it's a Device Path pointing to BootManagerMenuApp.

@param DevicePath Input device path.

@retval TRUE The device path is BootManagerMenuApp File Device Path.
@retval FALSE The device path is NOT BootManagerMenuApp File Device Path.
**/
BOOLEAN
IsBootManagerMenuAppFilePath (
EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
EFI_HANDLE FvHandle;
VOID *NameGuid;
EFI_STATUS Status;

Status = gBS->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &DevicePath, &FvHandle);
if (!EFI_ERROR (Status)) {
NameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) DevicePath);
if (NameGuid != NULL) {
return CompareGuid (NameGuid, &mBootMenuFile);
}
}

return FALSE;
}

/**
Return the boot option number to the BootManagerMenuApp.

If not found it in the current boot option, create a new one.

@retval OptionNumber Return the boot option number to the BootManagerMenuApp.

**/
UINTN
GetBootManagerMenuAppOption (
VOID
)
{
UINTN BootOptionCount;
EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
UINTN Index;
UINTN OptionNumber;

OptionNumber = 0;

BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);

for (Index = 0; Index < BootOptionCount; Index++) {
if (IsBootManagerMenuAppFilePath (BootOptions[Index].FilePath)) {
OptionNumber = BootOptions[Index].OptionNumber;
break;
}
}

EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);

if (Index >= BootOptionCount) {
//
// If not found the BootManagerMenuApp, create it.
//
OptionNumber = (UINT16) RegisterBootManagerMenuAppBootOption (&mBootMenuFile, L"UEFI BootManagerMenuApp", (UINTN) -1, FALSE);
}

return OptionNumber;
}

VOID
PlatformRegisterFvBootOption (
EFI_GUID *FileGuid,
Expand Down Expand Up @@ -278,6 +424,7 @@ PlatformRegisterOptionsAndKeys (
EFI_INPUT_KEY F2;
EFI_INPUT_KEY Esc;
EFI_BOOT_MANAGER_LOAD_OPTION BootOption;
UINTN OptionNumber;

//
// Register ENTER as CONTINUE key
Expand All @@ -296,12 +443,13 @@ PlatformRegisterOptionsAndKeys (
Esc.UnicodeChar = CHAR_NULL;
Status = EfiBootManagerGetBootManagerMenu (&BootOption);
ASSERT_EFI_ERROR (Status);
OptionNumber = GetBootManagerMenuAppOption ();
Status = EfiBootManagerAddKeyOptionVariable (
NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL
NULL, (UINT16) OptionNumber, 0, &Esc, NULL
);
ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);
Status = EfiBootManagerAddKeyOptionVariable (
NULL, (UINT16) BootOption.OptionNumber, 0, &Esc, NULL
NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL
);
ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);
}
Expand Down Expand Up @@ -570,6 +718,7 @@ PrepareLpcBridgeDevicePath (
EFI_STATUS Status;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
EFI_GUID TerminalTypeGuid;
CHAR16 *DevPathStr;

DevicePath = NULL;
Expand Down Expand Up @@ -601,6 +750,10 @@ PrepareLpcBridgeDevicePath (
(EFI_DEVICE_PATH_PROTOCOL *)&gPnp16550ComPortDeviceNode);
DevicePath = AppendDevicePathNode (DevicePath,
(EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceNode);

TerminalTypeGuid = gEfiTtyTermGuid;
CopyGuid (&gTerminalTypeDeviceNode.Guid, &TerminalTypeGuid);

DevicePath = AppendDevicePathNode (DevicePath,
(EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);

Expand Down Expand Up @@ -1475,6 +1628,12 @@ PlatformBootManagerAfterConsole (

DEBUG ((EFI_D_INFO, "PlatformBootManagerAfterConsole\n"));

// This is probably the earliest we can print this, as before the console is
// not ready yet.
Print(L"F2 to enter Setup\n");
Print(L"ESC to enter Boot Manager Menu\n");
Print(L"ENTER to boot directly\n");

if (PcdGetBool (PcdOvmfFlashVariablesEnable)) {
DEBUG ((EFI_D_INFO, "PlatformBdsPolicyBehavior: not restoring NvVars "
"from disk since flash variables appear to be supported.\n"));
Expand Down Expand Up @@ -1529,7 +1688,7 @@ PlatformBootManagerAfterConsole (
// Register UEFI Shell
//
PlatformRegisterFvBootOption (
&gUefiShellFileGuid, L"EFI Internal Shell", LOAD_OPTION_ACTIVE
&gUefiShellFileGuid, L"UEFI Shell", LOAD_OPTION_ACTIVE
);

RemoveStaleFvFileOptions ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,4 @@
gEfiGlobalVariableGuid
gRootBridgesConnectedEventGroupGuid
gUefiShellFileGuid
gEfiTtyTermGuid
2 changes: 2 additions & 0 deletions OvmfPkg/OvmfPkgX64.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@
gDasharoSystemFeaturesTokenSpaceGuid.PcdDefaultNetworkBootEnable|FALSE
gDasharoSystemFeaturesTokenSpaceGuid.PcdDasharoEnterprise|TRUE
gDasharoSystemFeaturesTokenSpaceGuid.PcdShowIommuOptions|TRUE
gDasharoSystemFeaturesTokenSpaceGuid.PcdSerialRedirectionDefaultState|TRUE

################################################################################
#
Expand Down Expand Up @@ -791,6 +792,7 @@
!endif
<PcdsFixedAtBuild>
gDasharoSystemFeaturesTokenSpaceGuid.PcdShowMenu|$(DASHARO_SYSTEM_FEATURES_ENABLE)
gDasharoSystemFeaturesTokenSpaceGuid.PcdShowSerialPortMenu|TRUE
}

MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf
Expand Down
Loading