From nobody Mon Feb 9 02:12:17 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43069+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43069+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1561949769; cv=none; d=zoho.com; s=zohoarc; b=OJa6p/qGe/Ha9OreLEoT9yWn98TnPvKQfYl0QI5XwI7pqXDSOcqh/8CsmM520offRQ28eVN3Kx2RSsqeNl8EuEfCmqi2hhJCSBwmjVmjNpaSdw7BBA5wGL9YQB7BSFVkkqmlFDAnFabkASvQvhZDpzukPT+AqaWiVDPRWpOeSO4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561949769; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=NIEs+nQ4aVWcuD+8iz2NzIgKOaE3DXLhmRxWYlcm3cg=; b=J6N4yTGt87tQvqxmvDtz8b8QWJ3UloZO3pFaksLbGdVb9lTgxuGn6//ZczGgR59xOZ3cbNIyL2OaJWCmryYTeD1CfK1ayjZDLNd54c4V8Jqvs/3LmklLZXJ2OKi7XA1JHePjtdsNGrtMsuqO3xif6Ipie411Q53YDTRfKXhWiJ0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43069+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1561949769770236.39248380627782; Sun, 30 Jun 2019 19:56:09 -0700 (PDT) Return-Path: X-Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by groups.io with SMTP; Sun, 30 Jun 2019 19:56:08 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jun 2019 19:56:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,437,1557212400"; d="scan'208";a="338480239" X-Received: from mdkinney-mobl2.amr.corp.intel.com ([10.251.143.61]) by orsmga005.jf.intel.com with ESMTP; 30 Jun 2019 19:56:05 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Zailiang Sun , Yi Qian Subject: [edk2-devel] [edk2-platforms Patch 10/14] Vlv2TbltDevicePkg: Switch to MdeModulePkg BdsDxe Date: Sun, 30 Jun 2019 19:55:49 -0700 Message-Id: <20190701025553.18596-11-michael.d.kinney@intel.com> In-Reply-To: <20190701025553.18596-1-michael.d.kinney@intel.com> References: <20190701025553.18596-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,michael.d.kinney@intel.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1561949769; bh=+v1AjApOPB8EJZtqm95NQqvXNhdFDQUBHOkZTC2pDqo=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=rQ2OmK+OO7Fu/BYx6Bxc33CNGoQBD982XQq3Rxmns986Z730awimWwAZV0b/bCB0j8p kjnFa5hXIvjx+QDDQNZpNdmf0ajK8OgIA0KMGF0xwB35bIry232SMrIxh3xI+9pL33HJF trACkyTaFTQdYYYtTzSzWZB9QRXXje2DAyc= X-ZohoMail-DKIM: pass (identity @groups.io) Switch from Intel Framework BDS module and libraries to the MdeModulePkg BdsDxe module and libraries. Update FLASH map for full 8MB FLASH size Cc: Zailiang Sun Cc: Yi Qian Signed-off-by: Michael D Kinney --- .../Library/FmpDeviceLib/FmpDeviceLib.c | 12 +- .../DxePlatformBootManagerLib/BdsPlatform.c | 1409 ++++++ .../DxePlatformBootManagerLib/BdsPlatform.h | 253 + .../DxePlatformBootManagerLib.inf | 95 + .../DxePlatformBootManagerLib/MemoryTest.c | 83 + .../PlatformBootOption.c | 559 ++ .../Library/PlatformBdsLib/BdsPlatform.c | 3092 ------------ .../Library/PlatformBdsLib/BdsPlatform.h | 516 -- .../Library/PlatformBdsLib/PlatformBdsLib.inf | 128 - .../PlatformBdsLib/PlatformBdsStrings.uni | 30 - .../Library/PlatformBdsLib/PlatformData.c | 306 -- .../Library/GenericBdsLib/BdsBoot.c | 4490 ----------------- .../Library/GenericBdsLib/BdsConnect.c | 429 -- .../Library/GenericBdsLib/BdsConsole.c | 1061 ---- .../Library/GenericBdsLib/BdsMisc.c | 1575 ------ .../Library/GenericBdsLib/DevicePath.c | 27 - .../Library/GenericBdsLib/GenericBdsLib.inf | 143 - .../Library/GenericBdsLib/GenericBdsLib.uni | 19 - .../GenericBdsLib/GenericBdsStrings.uni | 30 - .../Library/GenericBdsLib/InternalBdsLib.h | 173 - .../Library/GenericBdsLib/String.c | 26 - .../Library/GenericBdsLib/String.h | 42 - .../Intel/Vlv2TbltDevicePkg/PlatformPkg.fdf | 26 +- .../Vlv2TbltDevicePkg/PlatformPkgGcc.fdf | 53 +- .../Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc | 22 +- .../Vlv2TbltDevicePkg/PlatformPkgIA32.dsc | 22 +- .../Vlv2TbltDevicePkg/PlatformPkgX64.dsc | 22 +- .../Intel/Vlv2TbltDevicePkg/UiApp/FrontPage.c | 33 - .../Intel/Vlv2TbltDevicePkg/UiApp/UiApp.inf | 32 - 29 files changed, 2477 insertions(+), 12231 deletions(-) create mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBoo= tManagerLib/BdsPlatform.c create mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBoo= tManagerLib/BdsPlatform.h create mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBoo= tManagerLib/DxePlatformBootManagerLib.inf create mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBoo= tManagerLib/MemoryTest.c create mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBoo= tManagerLib/PlatformBootOption.c delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib= /BdsPlatform.c delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib= /BdsPlatform.h delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib= /PlatformBdsLib.inf delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib= /PlatformBdsStrings.uni delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib= /PlatformData.c delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFramewor= kModulePkg/Library/GenericBdsLib/BdsBoot.c delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFramewor= kModulePkg/Library/GenericBdsLib/BdsConnect.c delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFramewor= kModulePkg/Library/GenericBdsLib/BdsConsole.c delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFramewor= kModulePkg/Library/GenericBdsLib/BdsMisc.c delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFramewor= kModulePkg/Library/GenericBdsLib/DevicePath.c delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFramewor= kModulePkg/Library/GenericBdsLib/GenericBdsLib.inf delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFramewor= kModulePkg/Library/GenericBdsLib/GenericBdsLib.uni delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFramewor= kModulePkg/Library/GenericBdsLib/GenericBdsStrings.uni delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFramewor= kModulePkg/Library/GenericBdsLib/InternalBdsLib.h delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFramewor= kModulePkg/Library/GenericBdsLib/String.c delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFramewor= kModulePkg/Library/GenericBdsLib/String.h delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/UiApp/FrontPage.c delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/UiApp/UiApp.inf diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Feature/Capsule/Library/FmpDe= viceLib/FmpDeviceLib.c b/Platform/Intel/Vlv2TbltDevicePkg/Feature/Capsule/L= ibrary/FmpDeviceLib/FmpDeviceLib.c index a863d69381..57185d8d09 100644 --- a/Platform/Intel/Vlv2TbltDevicePkg/Feature/Capsule/Library/FmpDeviceLib= /FmpDeviceLib.c +++ b/Platform/Intel/Vlv2TbltDevicePkg/Feature/Capsule/Library/FmpDeviceLib= /FmpDeviceLib.c @@ -32,11 +32,11 @@ typedef struct { } UPDATE_CONFIG_DATA; =20 UPDATE_CONFIG_DATA mUpdateConfigData[] =3D { - { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0= x00000000, 0x00040000, 0x00000000 }, - { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0= x000C0000, 0x00050000, 0x000C0000 }, - { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0= x00110000, 0x00210000, 0x00110000 }, - { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0= x00320000, 0x00070000, 0x00320000 }, - { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0= x00390000, 0x00070000, 0x00390000 } + { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0= x00400000, 0x00040000, 0x00400000 }, + { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0= x004C0000, 0x00050000, 0x004C0000 }, + { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0= x00510000, 0x00210000, 0x00510000 }, + { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0= x00720000, 0x00070000, 0x00720000 }, + { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0= x00790000, 0x00070000, 0x00790000 } }; =20 /** @@ -95,7 +95,7 @@ FmpDeviceGetSize ( if (Size =3D=3D NULL) { return EFI_INVALID_PARAMETER; } - *Size =3D PcdGet32 (PcdBiosRomBase); + *Size =3D PcdGet32 (PcdBiosRomSize); return EFI_SUCCESS; } =20 diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManage= rLib/BdsPlatform.c b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBo= otManagerLib/BdsPlatform.c new file mode 100644 index 0000000000..4dd3827a6e --- /dev/null +++ b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/Bd= sPlatform.c @@ -0,0 +1,1409 @@ +/** @file + This file include all platform action which can be customized by IBV/OEM. + +Copyright (c) 2017, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "BdsPlatform.h" +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include + +GLOBAL_REMOVE_IF_UNREFERENCED EFI_BOOT_MODE gBootMode; + +BOOLEAN gPPRequireUIConfirm; + +extern UINTN mBootMenuOptionNumber; + +GLOBAL_REMOVE_IF_UNREFERENCED USB_CLASS_FORMAT_DEVICE_PATH gUsbClassKeyboa= rdDevicePath =3D { + { + { + MESSAGING_DEVICE_PATH, + MSG_USB_CLASS_DP, + { + (UINT8) (sizeof (USB_CLASS_DEVICE_PATH)), + (UINT8) ((sizeof (USB_CLASS_DEVICE_PATH)) >> 8) + } + }, + 0xffff, // VendorId + 0xffff, // ProductId + CLASS_HID, // DeviceClass + SUBCLASS_BOOT, // DeviceSubClass + PROTOCOL_KEYBOARD // DeviceProtocol + }, + gEndEntire +}; + +// +// Platform specific ISA serial device path +// +GLOBAL_REMOVE_IF_UNREFERENCED PLATFORM_ISA_SERIAL_DEVICE_PATH gIsaSerialDe= vicePath =3D { + gPciRootBridge, + gPciIsaBridge, + gPnp16550ComPort, + gUart(115200, 8, 1, 1), + gPcAnsiTerminal, + gEndEntire +}; + +// +// Internal shell mode +// +GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mShellModeColumn; +GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mShellModeRow; +GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mShellHorizontalResolution; +GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mShellVerticalResolution; +// +// BDS Platform Functions +// + +BOOLEAN +IsMorBitSet ( + VOID + ) +{ + UINTN MorControl; + EFI_STATUS Status; + UINTN DataSize; + + // + // Check if the MOR bit is set. + // + DataSize =3D sizeof (MorControl); + Status =3D gRT->GetVariable ( + MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, + &gEfiMemoryOverwriteControlDataGuid, + NULL, + &DataSize, + &MorControl + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, " PlatformBootMangerLib: gEfiMemoryOverwriteContro= lDataGuid doesn't exist!!***\n")); + MorControl =3D 0; + } else { + DEBUG ((DEBUG_INFO, " PlatformBootMangerLib: Get the gEfiMemoryOverwri= teControlDataGuid =3D %x!!***\n", MorControl)); + } + + return (BOOLEAN) (MorControl & 0x01); +} + +VOID +DumpDevicePath ( + IN CHAR16 *Name, + IN EFI_DEVICE_PATH *DevicePath + ) +{ + CHAR16 *Str; + + Str =3D ConvertDevicePathToText(DevicePath, TRUE, TRUE); + DEBUG ((DEBUG_INFO, "%s: %s\n", Name, Str)); + if (Str !=3D NULL) { + FreePool (Str); + } +} + +/** + An empty function to pass error checking of CreateEventEx (). + + This empty function ensures that EVT_NOTIFY_SIGNAL_ALL is error + checked correctly since it is now mapped into CreateEventEx() in UEFI 2.= 0. + + @param Event Event whose notification function is being= invoked. + @param Context The pointer to the notification function's= context, + which is implementation-dependent. +**/ +VOID +EFIAPI +InternalBdsEmptyCallbackFuntion ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + return; +} + +VOID +ExitPmAuth ( + VOID + ) +{ + EFI_HANDLE Handle; + EFI_STATUS Status; + EFI_EVENT EndOfDxeEvent; + + DEBUG((DEBUG_INFO,"ExitPmAuth ()- Start\n")); + // + // Prepare S3 information, this MUST be done before ExitPmAuth/EndOfDxe + // + // + // Since PI1.2.1, we need signal EndOfDxe as ExitPmAuth + // + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + InternalBdsEmptyCallbackFuntion, + NULL, + &gEfiEndOfDxeEventGroupGuid, + &EndOfDxeEvent + ); + ASSERT_EFI_ERROR (Status); + gBS->SignalEvent (EndOfDxeEvent); + gBS->CloseEvent (EndOfDxeEvent); + DEBUG((DEBUG_INFO,"All EndOfDxe callbacks have returned successfully\n")= ); + + // + // NOTE: We need install DxeSmmReadyToLock directly here because many bo= ot script is added via ExitPmAuth/EndOfDxe callback. + // If we install them at same callback, these boot script will be reject= ed because BootScript Driver runs first to lock them done. + // So we seperate them to be 2 different events, ExitPmAuth is last chan= ce to let platform add boot script. DxeSmmReadyToLock will + // make boot script save driver lock down the interface. + // + Handle =3D NULL; + Status =3D gBS->InstallProtocolInterface ( + &Handle, + &gEfiDxeSmmReadyToLockProtocolGuid, + EFI_NATIVE_INTERFACE, + NULL + ); + ASSERT_EFI_ERROR (Status); + DEBUG((DEBUG_INFO,"ExitPmAuth ()- End\n")); +} + +VOID +ConnectRootBridge ( + BOOLEAN Recursive + ) +{ + UINTN RootBridgeHandleCount; + EFI_HANDLE *RootBridgeHandleBuffer; + UINTN RootBridgeIndex; + + RootBridgeHandleCount =3D 0; + gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiPciRootBridgeIoProtocolGuid, + NULL, + &RootBridgeHandleCount, + &RootBridgeHandleBuffer + ); + for (RootBridgeIndex =3D 0; RootBridgeIndex < RootBridgeHandleCount; Roo= tBridgeIndex++) { + gBS->ConnectController (RootBridgeHandleBuffer[RootBridgeIndex], NULL,= NULL, Recursive); + } +} + + +/** + Return whether the device is trusted console. + + @param Device The device to be tested. + + @retval TRUE The device can be trusted. + @retval FALSE The device cannot be trusted. +**/ +BOOLEAN +IsTrustedConsole ( + IN CONSOLE_TYPE ConsoleType, + IN EFI_DEVICE_PATH_PROTOCOL *Device + ) +{ + VOID *TrustedConsoleDevicepath; + EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; + EFI_DEVICE_PATH_PROTOCOL *Instance; + UINTN Size; + EFI_DEVICE_PATH_PROTOCOL *ConsoleDevice; + + if (Device =3D=3D NULL) { + return FALSE; + } + + ConsoleDevice =3D DuplicateDevicePath(Device); + + TrustedConsoleDevicepath =3D NULL; + + switch (ConsoleType) { + case ConIn: + TrustedConsoleDevicepath =3D PcdGetPtr (PcdTrustedConsoleInputDevicePa= th); + break; + case ConOut: + // + // Check GOP and remove last node + // + TempDevicePath =3D ConsoleDevice; + while (!IsDevicePathEndType (TempDevicePath)) { + if (DevicePathType (TempDevicePath) =3D=3D ACPI_DEVICE_PATH && + DevicePathSubType (TempDevicePath) =3D=3D ACPI_ADR_DP) { + SetDevicePathEndNode (TempDevicePath); + break; + } + TempDevicePath =3D NextDevicePathNode (TempDevicePath); + } + + TrustedConsoleDevicepath =3D PcdGetPtr (PcdTrustedConsoleOutputDeviceP= ath); + break; + default: + ASSERT(FALSE); + break; + } + + TempDevicePath =3D TrustedConsoleDevicepath; + do { + Instance =3D GetNextDevicePathInstance (&TempDevicePath, &Size); + if (Instance =3D=3D NULL) { + break; + } + + if (CompareMem (ConsoleDevice, Instance, Size - END_DEVICE_PATH_LENGTH= ) =3D=3D 0) { + FreePool (Instance); + FreePool (ConsoleDevice); + return TRUE; + } + + FreePool (Instance); + } while (TempDevicePath !=3D NULL); + + FreePool (ConsoleDevice); + + return FALSE; +} + +BOOLEAN +IsUsbShortForm ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + if ((DevicePathType (DevicePath) =3D=3D MESSAGING_DEVICE_PATH) && + ((DevicePathSubType (DevicePath) =3D=3D MSG_USB_CLASS_DP) || (Device= PathSubType (DevicePath) =3D=3D MSG_USB_WWID_DP)) ) { + return TRUE; + } + + return FALSE; +} + +/** + Connect the USB short form device path. + + @param DevicePath USB short form device path + + @retval EFI_SUCCESS Successfully connected the USB device + @retval EFI_NOT_FOUND Cannot connect the USB device + @retval EFI_INVALID_PARAMETER The device path is invalid. +**/ +EFI_STATUS +ConnectUsbShortFormDevicePath ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + EFI_STATUS Status; + EFI_HANDLE *Handles; + UINTN HandleCount; + UINTN Index; + EFI_PCI_IO_PROTOCOL *PciIo; + UINT8 Class[3]; + BOOLEAN AtLeastOneConnected; + + // + // Check the passed in parameters + // + if (DevicePath =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (!IsUsbShortForm (DevicePath)) { + return EFI_INVALID_PARAMETER; + } + + // + // Find the usb host controller firstly, then connect with the remaining= device path + // + AtLeastOneConnected =3D FALSE; + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiPciIoProtocolGuid, + NULL, + &HandleCount, + &Handles + ); + for (Index =3D 0; Index < HandleCount; Index++) { + Status =3D gBS->HandleProtocol ( + Handles[Index], + &gEfiPciIoProtocolGuid, + (VOID **) &PciIo + ); + if (!EFI_ERROR (Status)) { + // + // Check whether the Pci device is the wanted usb host controller + // + Status =3D PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Cla= ss); + if (!EFI_ERROR (Status) && + ((PCI_CLASS_SERIAL =3D=3D Class[2]) && (PCI_CLASS_SERIAL_USB =3D= =3D Class[1])) + ) { + Status =3D gBS->ConnectController ( + Handles[Index], + NULL, + DevicePath, + FALSE + ); + if (!EFI_ERROR(Status)) { + AtLeastOneConnected =3D TRUE; + } + } + } + } + + return AtLeastOneConnected ? EFI_SUCCESS : EFI_NOT_FOUND; +} + +/** + Update the ConIn/ConOut variable with ISA Serial device path,if its not = already exists in ConIn/ConOut +**/ +VOID +EnumIsaSerial ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "[EnumIsaSerial]\n")); + EfiBootManagerUpdateConsoleVariable (ConIn, (EFI_DEVICE_PATH_PROTOCOL *)= &gIsaSerialDevicePath, NULL); + EfiBootManagerUpdateConsoleVariable (ConOut, (EFI_DEVICE_PATH_PROTOCOL *= ) &gIsaSerialDevicePath, NULL); + + // + // Append ISA Serial DevicePath to "ConInDev" and "ConOutDev" + // + EfiBootManagerUpdateConsoleVariable (ConInDev, (EFI_DEVICE_PATH_PROTOCOL= *) &gIsaSerialDevicePath, NULL); + EfiBootManagerUpdateConsoleVariable (ConOutDev, (EFI_DEVICE_PATH_PROTOCO= L *) &gIsaSerialDevicePath, NULL); +} + +/** + Update the ConIn variable with USB Keyboard device path,if its not alrea= dy exists in ConIn +**/ +VOID +EnumUsbKeyboard ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "[EnumUsbKeyboard]\n")); + EfiBootManagerUpdateConsoleVariable (ConIn, (EFI_DEVICE_PATH_PROTOCOL *)= &gUsbClassKeyboardDevicePath, NULL); + + // + // Append Usb Keyboard short form DevicePath into "ConInDev" + // + EfiBootManagerUpdateConsoleVariable (ConInDev, (EFI_DEVICE_PATH_PROTOCOL= *) &gUsbClassKeyboardDevicePath, NULL); +} + +BOOLEAN +IsVgaHandle ( + IN EFI_HANDLE Handle + ) +{ + EFI_PCI_IO_PROTOCOL *PciIo; + PCI_TYPE00 Pci; + EFI_STATUS Status; + + Status =3D gBS->HandleProtocol ( + Handle, + &gEfiPciIoProtocolGuid, + (VOID **)&PciIo + ); + if (!EFI_ERROR (Status)) { + Status =3D PciIo->Pci.Read ( + PciIo, + EfiPciIoWidthUint32, + 0, + sizeof (Pci) / sizeof (UINT32), + &Pci + ); + if (!EFI_ERROR (Status)) { + if (IS_PCI_VGA (&Pci) || IS_PCI_OLD_VGA (&Pci)) { + return TRUE; + } + } + } + return FALSE; +} + +EFI_HANDLE +IsVideoController ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + EFI_DEVICE_PATH_PROTOCOL *DupDevicePath; + EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; + EFI_STATUS Status; + EFI_HANDLE DeviceHandle; + + DupDevicePath =3D DuplicateDevicePath (DevicePath); + ASSERT (DupDevicePath !=3D NULL); + if (DupDevicePath =3D=3D NULL) { + return NULL; + } + + TempDevicePath =3D DupDevicePath; + Status =3D gBS->LocateDevicePath ( + &gEfiDevicePathProtocolGuid, + &TempDevicePath, + &DeviceHandle + ); + FreePool (DupDevicePath); + if (EFI_ERROR (Status)) { + return NULL; + } + + if (IsVgaHandle (DeviceHandle)) { + return DeviceHandle; + } else { + return NULL; + } +} + +BOOLEAN +IsGopDevicePath ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + while (!IsDevicePathEndType (DevicePath)) { + if (DevicePathType (DevicePath) =3D=3D ACPI_DEVICE_PATH && + DevicePathSubType (DevicePath) =3D=3D ACPI_ADR_DP) { + return TRUE; + } + DevicePath =3D NextDevicePathNode (DevicePath); + } + return FALSE; +} + +/** + Remove all GOP device path instance from DevicePath and add the Gop to t= he DevicePath. +**/ +EFI_DEVICE_PATH_PROTOCOL * +UpdateGopDevicePath ( + EFI_DEVICE_PATH_PROTOCOL *DevicePath, + EFI_DEVICE_PATH_PROTOCOL *Gop + ) +{ + UINTN Size; + UINTN GopSize; + EFI_DEVICE_PATH_PROTOCOL *Temp; + EFI_DEVICE_PATH_PROTOCOL *Return; + EFI_DEVICE_PATH_PROTOCOL *Instance; + BOOLEAN Exist; + + Exist =3D FALSE; + Return =3D NULL; + GopSize =3D GetDevicePathSize (Gop); + do { + Instance =3D GetNextDevicePathInstance (&DevicePath, &Size); + if (Instance =3D=3D NULL) { + break; + } + if (!IsGopDevicePath (Instance) || + (Size =3D=3D GopSize && CompareMem (Instance, Gop, GopSize) =3D=3D= 0) + ) { + if (Size =3D=3D GopSize && CompareMem (Instance, Gop, GopSize) =3D= =3D 0) { + Exist =3D TRUE; + } + Temp =3D Return; + Return =3D AppendDevicePathInstance (Return, Instance); + if (Temp !=3D NULL) { + FreePool (Temp); + } + } + FreePool (Instance); + } while (DevicePath !=3D NULL); + + if (!Exist) { + Temp =3D Return; + Return =3D AppendDevicePathInstance (Return, Gop); + if (Temp !=3D NULL) { + FreePool (Temp); + } + } + return Return; +} + +/** + Get Graphics Controller Handle. + + @retval GraphicsController Successfully located + @retval NULL Failed to locate +**/ +EFI_HANDLE +EFIAPI +GetGraphicsController ( + IN BOOLEAN NeedTrustedConsole + ) +{ + EFI_STATUS Status; + UINTN Index; + EFI_HANDLE *PciHandles; + UINTN PciHandlesSize; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiPciIoProtocolGuid, + NULL, + &PciHandlesSize, + &PciHandles + ); + if (EFI_ERROR (Status)) { + return NULL; + } + + for (Index =3D 0; Index < PciHandlesSize; Index++) { + Status =3D gBS->HandleProtocol ( + PciHandles[Index], + &gEfiDevicePathProtocolGuid, + (VOID **) &DevicePath + ); + if (EFI_ERROR(Status)) { + continue; + } + if (!IsVgaHandle (PciHandles[Index])) { + continue; + } + if ((NeedTrustedConsole && IsTrustedConsole (ConOut, DevicePath)) || + ((!NeedTrustedConsole) && (!IsTrustedConsole (ConOut, DevicePath))= )) { + return PciHandles[Index]; + } + } + + return NULL; +} + +VOID +UpdateGraphicConOut ( + IN BOOLEAN NeedTrustedConsole + ) +{ + EFI_HANDLE GraphicsControllerHandle; + EFI_DEVICE_PATH_PROTOCOL *GopDevicePath; + EFI_DEVICE_PATH_PROTOCOL *ConOutDevicePath; + EFI_DEVICE_PATH_PROTOCOL *UpdatedConOutDevicePath; + + // + // Update ConOut variable + // + GraphicsControllerHandle =3D GetGraphicsController (NeedTrustedConsole); + if (GraphicsControllerHandle !=3D NULL) { + // + // Connect the GOP driver + // + gBS->ConnectController (GraphicsControllerHandle, NULL, NULL, TRUE); + + // + // Get the GOP device path + // NOTE: We may get a device path that contains Controller node in it. + // + GopDevicePath =3D EfiBootManagerGetGopDevicePath (GraphicsControllerHa= ndle); + if (GopDevicePath !=3D NULL) { + GetEfiGlobalVariable2 (L"ConOut", (VOID **)&ConOutDevicePath, NULL); + UpdatedConOutDevicePath =3D UpdateGopDevicePath (ConOutDevicePath, G= opDevicePath); + if (ConOutDevicePath !=3D NULL) { + FreePool (ConOutDevicePath); + } + FreePool (GopDevicePath); + gRT->SetVariable ( + L"ConOut", + &gEfiGlobalVariableGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACC= ESS | EFI_VARIABLE_BOOTSERVICE_ACCESS, + GetDevicePathSize (UpdatedConOutDevicePath), + UpdatedConOutDevicePath + ); + } + } +} + +VOID +AddConsoleVariable ( + IN CONSOLE_TYPE ConsoleType, + IN EFI_DEVICE_PATH *ConsoleDevicePath + ) +{ + EFI_DEVICE_PATH *TempDevicePath; + EFI_DEVICE_PATH *Instance; + UINTN Size; + EFI_HANDLE GraphicsControllerHandle; + EFI_DEVICE_PATH *GopDevicePath; + + TempDevicePath =3D ConsoleDevicePath; + do { + Instance =3D GetNextDevicePathInstance (&TempDevicePath, &Size); + if (Instance =3D=3D NULL) { + break; + } + + switch (ConsoleType) { + case ConIn: + if (IsUsbShortForm (Instance)) { + // + // Append Usb Keyboard short form DevicePath into "ConInDev" + // + EfiBootManagerUpdateConsoleVariable (ConInDev, Instance, NULL); + } + EfiBootManagerUpdateConsoleVariable (ConsoleType, Instance, NULL); + break; + case ConOut: + GraphicsControllerHandle =3D IsVideoController (Instance); + if (GraphicsControllerHandle =3D=3D NULL) { + EfiBootManagerUpdateConsoleVariable (ConsoleType, Instance, NULL); + } else { + // + // Connect the GOP driver + // + gBS->ConnectController (GraphicsControllerHandle, NULL, NULL, TRUE= ); + // + // Get the GOP device path + // NOTE: We may get a device path that contains Controller node in= it. + // + GopDevicePath =3D EfiBootManagerGetGopDevicePath (GraphicsControll= erHandle); + if (GopDevicePath !=3D NULL) { + EfiBootManagerUpdateConsoleVariable (ConsoleType, GopDevicePath,= NULL); + } + } + break; + default: + ASSERT(FALSE); + break; + } + + FreePool (Instance); + } while (TempDevicePath !=3D NULL); +} + +/** + The function connects the trusted consoles. +**/ +VOID +ConnectTrustedConsole ( + VOID + ) +{ + EFI_DEVICE_PATH_PROTOCOL *Consoles; + EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; + EFI_DEVICE_PATH_PROTOCOL *Instance; + EFI_DEVICE_PATH_PROTOCOL *Next; + UINTN Size; + UINTN Index; + EFI_HANDLE Handle; + EFI_STATUS Status; + CHAR16 *ConsoleVar[] =3D {L"ConIn", L"ConOut"}; + VOID *TrustedConsoleDevicepath; + + TrustedConsoleDevicepath =3D PcdGetPtr (PcdTrustedConsoleInputDevicePath= ); + DumpDevicePath (L"TrustedConsoleIn", TrustedConsoleDevicepath); + TrustedConsoleDevicepath =3D PcdGetPtr (PcdTrustedConsoleOutputDevicePat= h); + DumpDevicePath (L"TrustedConsoleOut", TrustedConsoleDevicepath); + + for (Index =3D 0; Index < sizeof (ConsoleVar) / sizeof (ConsoleVar[0]); = Index++) { + + GetEfiGlobalVariable2 (ConsoleVar[Index], (VOID **)&Consoles, NULL); + + TempDevicePath =3D Consoles; + do { + Instance =3D GetNextDevicePathInstance (&TempDevicePath, &Size); + if (Instance =3D=3D NULL) { + break; + } + if (IsTrustedConsole (Index, Instance)) { + if (IsUsbShortForm (Instance)) { + ConnectUsbShortFormDevicePath (Instance); + } else { + for (Next =3D Instance; !IsDevicePathEnd (Next); Next =3D NextDe= vicePathNode (Next)) { + if (DevicePathType (Next) =3D=3D ACPI_DEVICE_PATH && DevicePat= hSubType (Next) =3D=3D ACPI_ADR_DP) { + break; + } else if (DevicePathType (Next) =3D=3D HARDWARE_DEVICE_PATH && + DevicePathSubType (Next) =3D=3D HW_CONTROLLER_DP && + DevicePathType (NextDevicePathNode (Next)) =3D=3D A= CPI_DEVICE_PATH && + DevicePathSubType (NextDevicePathNode (Next)) =3D= =3D ACPI_ADR_DP + ) { + break; + } + } + if (!IsDevicePathEnd (Next)) { + SetDevicePathEndNode (Next); + Status =3D EfiBootManagerConnectDevicePath (Instance, &Handle); + if (!EFI_ERROR (Status)) { + gBS->ConnectController (Handle, NULL, NULL, TRUE); + } + } else { + EfiBootManagerConnectDevicePath (Instance, NULL); + } + } + } + FreePool (Instance); + } while (TempDevicePath !=3D NULL); + + if (Consoles !=3D NULL) { + FreePool (Consoles); + } + } +} + +/** + The function connects the trusted Storages. +**/ +VOID +ConnectTrustedStorage ( + VOID + ) +{ + VOID *TrustedStorageDevicepath; + EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; + EFI_DEVICE_PATH_PROTOCOL *Instance; + UINTN Size; + EFI_DEVICE_PATH_PROTOCOL *TempStorageDevicePath; + EFI_STATUS Status; + EFI_HANDLE DeviceHandle; + + TrustedStorageDevicepath =3D PcdGetPtr (PcdTrustedStorageDevicePath); + DumpDevicePath (L"TrustedStorage", TrustedStorageDevicepath); + + TempDevicePath =3D TrustedStorageDevicepath; + do { + Instance =3D GetNextDevicePathInstance (&TempDevicePath, &Size); + if (Instance =3D=3D NULL) { + break; + } + + EfiBootManagerConnectDevicePath (Instance, NULL); + + TempStorageDevicePath =3D Instance; + + Status =3D gBS->LocateDevicePath ( + &gEfiDevicePathProtocolGuid, + &TempStorageDevicePath, + &DeviceHandle + ); + if (!EFI_ERROR (Status)) { + gBS->ConnectController (DeviceHandle, NULL, NULL, FALSE); + } + + FreePool (Instance); + } while (TempDevicePath !=3D NULL); +} + +/** + The function connects the trusted consoles and then call the PP processi= ng library interface. +**/ +VOID +ProcessTcgPp ( + VOID + ) +{ + gPPRequireUIConfirm |=3D Tcg2PhysicalPresenceLibNeedUserConfirm(); + + if (gPPRequireUIConfirm) { + ConnectTrustedConsole (); + } + + Tcg2PhysicalPresenceLibProcessRequest (NULL); +} + +/** + The function connects the trusted storage to perform TPerReset. +**/ +VOID +ProcessTcgMor ( + VOID + ) +{ + if (IsMorBitSet ()) { + ConnectTrustedConsole(); + ConnectTrustedStorage(); + } +} + +/** + Check if current BootCurrent variable is internal shell boot option. + + @retval TRUE BootCurrent is internal shell. + @retval FALSE BootCurrent is not internal shell. +**/ +BOOLEAN +BootCurrentIsInternalShell ( + VOID + ) +{ + UINTN VarSize; + UINT16 BootCurrent; + CHAR16 BootOptionName[16]; + UINT8 *BootOption; + UINT8 *Ptr; + BOOLEAN Result; + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; + EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode; + EFI_GUID *GuidPoint; + + BootOption =3D NULL; + Result =3D FALSE; + + // + // Get BootCurrent variable + // + VarSize =3D sizeof (UINT16); + Status =3D gRT->GetVariable ( + L"BootCurrent", + &gEfiGlobalVariableGuid, + NULL, + &VarSize, + &BootCurrent + ); + if (EFI_ERROR (Status)) { + return FALSE; + } + + // + // Create boot option Bootxxxx from BootCurrent + // + UnicodeSPrint (BootOptionName, sizeof(BootOptionName), L"Boot%04X", Boot= Current); + + GetEfiGlobalVariable2 (BootOptionName, (VOID **) &BootOption, &VarSize); + if (BootOption =3D=3D NULL || VarSize =3D=3D 0) { + return FALSE; + } + + Ptr =3D BootOption; + Ptr +=3D sizeof (UINT32); + Ptr +=3D sizeof (UINT16); + Ptr +=3D StrSize ((CHAR16 *) Ptr); + TempDevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *) Ptr; + LastDeviceNode =3D TempDevicePath; + while (!IsDevicePathEnd (TempDevicePath)) { + LastDeviceNode =3D TempDevicePath; + TempDevicePath =3D NextDevicePathNode (TempDevicePath); + } + GuidPoint =3D EfiGetNameGuidFromFwVolDevicePathNode ( + (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode + ); + if ((GuidPoint !=3D NULL) && + ((CompareGuid (GuidPoint, &gUefiShellFileGuid))) + ) { + // + // if this option is internal shell, return TRUE + // + Result =3D TRUE; + } + + if (BootOption !=3D NULL) { + FreePool (BootOption); + BootOption =3D NULL; + } + + return Result; +} + +/** + This function will change video resolution and text mode + for internl shell when internal shell is launched. + + @param None. + + @retval EFI_SUCCESS Mode is changed successfully. + @retval Others Mode failed to changed. +**/ +EFI_STATUS +EFIAPI +ChangeModeForInternalShell ( + VOID + ) +{ + EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut; + UINTN SizeOfInfo; + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info; + UINT32 MaxGopMode; + UINT32 MaxTextMode; + UINT32 ModeNumber; + UINTN HandleCount; + EFI_HANDLE *HandleBuffer; + EFI_STATUS Status; + UINTN Index; + UINTN CurrentColumn; + UINTN CurrentRow; + + Status =3D gBS->HandleProtocol ( + gST->ConsoleOutHandle, + &gEfiGraphicsOutputProtocolGuid, + (VOID**)&GraphicsOutput + ); + if (EFI_ERROR (Status)) { + GraphicsOutput =3D NULL; + } + + Status =3D gBS->HandleProtocol ( + gST->ConsoleOutHandle, + &gEfiSimpleTextOutProtocolGuid, + (VOID**)&SimpleTextOut + ); + if (EFI_ERROR (Status)) { + SimpleTextOut =3D NULL; + } + + if ((GraphicsOutput =3D=3D NULL) || (SimpleTextOut =3D=3D NULL)) { + return EFI_UNSUPPORTED; + } + + MaxGopMode =3D GraphicsOutput->Mode->MaxMode; + MaxTextMode =3D SimpleTextOut->Mode->MaxMode; + + // + // 1. If current video resolution is same with new video resolution, + // video resolution need not be changed. + // 1.1. If current text mode is same with new text mode, text mode ne= ed not be change. + // 1.2. If current text mode is different with new text mode, text mo= de need be change to new text mode. + // 2. If current video resolution is different with new video resolution= , we need restart whole console drivers. + // + for (ModeNumber =3D 0; ModeNumber < MaxGopMode; ModeNumber++) { + Status =3D GraphicsOutput->QueryMode ( + GraphicsOutput, + ModeNumber, + &SizeOfInfo, + &Info + ); + if (!EFI_ERROR (Status)) { + if ((Info->HorizontalResolution =3D=3D mShellHorizontalResolution) && + (Info->VerticalResolution =3D=3D mShellVerticalResolution)) { + if ((GraphicsOutput->Mode->Info->HorizontalResolution =3D=3D mShel= lHorizontalResolution) && + (GraphicsOutput->Mode->Info->VerticalResolution =3D=3D mShellV= erticalResolution)) { + // + // If current video resolution is same with new resolution, + // then check if current text mode is same with new text mode. + // + Status =3D SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOu= t->Mode->Mode, &CurrentColumn, &CurrentRow); + ASSERT_EFI_ERROR (Status); + if (CurrentColumn =3D=3D mShellModeColumn && CurrentRow =3D=3D m= ShellModeRow) { + // + // Current text mode is same with new text mode, text mode nee= d not be change. + // + FreePool (Info); + return EFI_SUCCESS; + } else { + // + // Current text mode is different with new text mode, text mod= e need be change to new text mode. + // + for (Index =3D 0; Index < MaxTextMode; Index++) { + Status =3D SimpleTextOut->QueryMode (SimpleTextOut, Index, &= CurrentColumn, &CurrentRow); + if (!EFI_ERROR(Status)) { + if ((CurrentColumn =3D=3D mShellModeColumn) && (CurrentRow= =3D=3D mShellModeRow)) { + // + // New text mode is supported, set it. + // + Status =3D SimpleTextOut->SetMode (SimpleTextOut, Index); + ASSERT_EFI_ERROR (Status); + // + // Update text mode PCD. + // + Status =3D PcdSet32S (PcdConOutColumn, mShellModeColumn); + ASSERT_EFI_ERROR (Status); + + Status =3D PcdSet32S (PcdConOutRow, mShellModeRow); + ASSERT_EFI_ERROR (Status); + + FreePool (Info); + return EFI_SUCCESS; + } + } + } + if (Index =3D=3D MaxTextMode) { + // + // If new text mode is not supported, return error. + // + FreePool (Info); + return EFI_UNSUPPORTED; + } + } + } else { + FreePool (Info); + // + // If current video resolution is not same with the new one, set= new video resolution. + // In this case, the driver which produces simple text out need = be restarted. + // + Status =3D GraphicsOutput->SetMode (GraphicsOutput, ModeNumber); + if (!EFI_ERROR (Status)) { + // + // Set PCD to restart GraphicsConsole and Consplitter to chang= e video resolution + // and produce new text mode based on new resolution. + // + Status =3D PcdSet32S (PcdVideoHorizontalResolution, mShellHori= zontalResolution); + ASSERT_EFI_ERROR (Status); + + Status =3D PcdSet32S (PcdVideoVerticalResolution, mShellVertic= alResolution); + ASSERT_EFI_ERROR (Status); + + Status =3D PcdSet32S (PcdConOutColumn, mShellModeColumn); + ASSERT_EFI_ERROR (Status); + + Status =3D PcdSet32S (PcdConOutRow, mShellModeRow); + ASSERT_EFI_ERROR (Status); + + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiSimpleTextOutProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (!EFI_ERROR (Status)) { + for (Index =3D 0; Index < HandleCount; Index++) { + gBS->DisconnectController (HandleBuffer[Index], NULL, NULL= ); + } + for (Index =3D 0; Index < HandleCount; Index++) { + gBS->ConnectController (HandleBuffer[Index], NULL, NULL, T= RUE); + } + if (HandleBuffer !=3D NULL) { + FreePool (HandleBuffer); + } + break; + } + } + } + } + FreePool (Info); + } + } + + if (ModeNumber =3D=3D MaxGopMode) { + // + // If the new resolution is not supported, return error. + // + return EFI_UNSUPPORTED; + } + + return EFI_SUCCESS; +} + +/** + ReadyToBoot callback to set video and text mode for internal shell boot. + That will not connect USB controller while CSM and FastBoot are disabled= , we need to connect them + before booting to Shell for showing USB devices in Shell. + + When FastBoot is enabled and Windows Console is the chosen Console behav= ior, input devices will not be connected + by default. Hence, when booting to EFI shell, connecting input consoles = are required. + + @param Event Pointer to this event + @param Context Event hanlder private data + + @retval None. +**/ +VOID +EFIAPI +OnReadyToBootCallBack ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + DEBUG ((DEBUG_INFO, "OnReadyToBootCallBack\n")); + + if (BootCurrentIsInternalShell ()) { + + ChangeModeForInternalShell (); + EfiBootManagerConnectAllDefaultConsoles(); + gDS->Dispatch (); + } +} + +/** + Platform Bds init. Incude the platform firmware vendor, revision + and so crc check. +**/ +VOID +EFIAPI +PlatformBootManagerBeforeConsole ( + VOID + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *VarConOut; + EFI_DEVICE_PATH_PROTOCOL *VarConIn; + EFI_EVENT Event; + + DEBUG ((DEBUG_INFO, "PlatformBootManagerBeforeConsole\n")); + + Status =3D EFI_SUCCESS; + + // + // Get user defined text mode for internal shell only once. + // + mShellHorizontalResolution =3D PcdGet32 (PcdSetupVideoHorizontalResoluti= on); + mShellVerticalResolution =3D PcdGet32 (PcdSetupVideoVerticalResolution= ); + mShellModeColumn =3D PcdGet32 (PcdSetupConOutColumn); + mShellModeRow =3D PcdGet32 (PcdSetupConOutRow); + + // + // Create event to set proper video resolution and text mode for interna= l shell. + // + Status =3D EfiCreateEventReadyToBootEx ( + TPL_CALLBACK, + OnReadyToBootCallBack, + NULL, + &Event + ); + ASSERT_EFI_ERROR (Status); + + // + // Connect Root Bridge to make PCI BAR resource allocated and all PciIo = created + // + ConnectRootBridge (FALSE); + + // + // Fill ConIn/ConOut in Full Configuration boot mode + // + gBootMode =3D GetBootModeHob(); + DEBUG ((DEBUG_INFO, "PlatformBootManagerInit - %x\n", gBootMode)); + + if (gBootMode =3D=3D BOOT_WITH_FULL_CONFIGURATION || + gBootMode =3D=3D BOOT_WITH_DEFAULT_SETTINGS || + gBootMode =3D=3D BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS || + gBootMode =3D=3D BOOT_IN_RECOVERY_MODE) { + + GetEfiGlobalVariable2 (L"ConOut", (VOID **)&VarConOut, NULL); if (Va= rConOut !=3D NULL) { FreePool (VarConOut); } + GetEfiGlobalVariable2 (L"ConIn", (VOID **)&VarConIn, NULL); if (Var= ConIn !=3D NULL) { FreePool (VarConIn); } + + // + // Only fill ConIn/ConOut when ConIn/ConOut is empty because we may dr= op to Full Configuration boot mode in non-first boot + // + if (VarConOut =3D=3D NULL || VarConIn =3D=3D NULL) { + if (PcdGetSize (PcdTrustedConsoleOutputDevicePath) >=3D sizeof(EFI_D= EVICE_PATH_PROTOCOL)) { + AddConsoleVariable (ConOut, PcdGetPtr (PcdTrustedConsoleOutputDevi= cePath)); + } + if (PcdGetSize (PcdTrustedConsoleInputDevicePath) >=3D sizeof(EFI_DE= VICE_PATH_PROTOCOL)) { + AddConsoleVariable (ConIn, PcdGetPtr (PcdTrustedConsoleInputDevice= Path)); + } + } + } + + EnumIsaSerial (); + + EnumUsbKeyboard (); + // + // For trusted console it must be handled here. + // + UpdateGraphicConOut (TRUE); + + if (gBootMode =3D=3D BOOT_ON_FLASH_UPDATE) { + // + // Logo show + // + BootLogoEnableLogo (); + + DEBUG((DEBUG_INFO, "ProcessCapsules Before EndOfDxe......\n")); + ProcessCapsules (); + DEBUG((DEBUG_INFO, "ProcessCapsules Done\n")); + } + + // + // Dynamically register hot key: F2/F7/Enter + // + RegisterDefaultBootOption (); + RegisterStaticHotkey (); + + PERF_START_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7010); + if (PcdGetBool (PcdTpm2Enable)) { + ProcessTcgPp (); + ProcessTcgMor (); + } + PERF_END_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7011); + + // + // We should make all UEFI memory and GCD information populated before E= xitPmAuth. + // SMM may consume these information. + // + MemoryTest((EXTENDMEM_COVERAGE_LEVEL) PcdGet32 (PcdPlatformMemoryCheckLe= vel)); + + PERF_START_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7020); + ExitPmAuth (); + PERF_END_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7021); + + // + // Dispatch the deferred 3rd party images. + // + EfiBootManagerDispatchDeferredImages (); + + // + // For non-trusted console it must be handled here. + // + UpdateGraphicConOut (FALSE); + + if (gBootMode =3D=3D BOOT_ON_FLASH_UPDATE) { + // + // Logo show + // + BootLogoEnableLogo (); + + DEBUG((DEBUG_INFO, "ProcessCapsules After ConnectAll......\n")); + ProcessCapsules(); + DEBUG((DEBUG_INFO, "ProcessCapsules Done\n")); + } +} + + +/** + Connect with predeined platform connect sequence, + the OEM/IBV can customize with their own connect sequence. + + @param[in] BootMode Boot mode of this boot. +**/ +VOID +ConnectSequence ( + IN EFI_BOOT_MODE BootMode + ) +{ + EfiBootManagerConnectAll (); +} + +/** + The function is to consider the boot order which is not in our expectati= on. + In the case that we need to re-sort the boot option. + + @retval TRUE Need to sort Boot Option. + @retval FALSE Don't need to sort Boot Option. +**/ +BOOLEAN +IsNeedSortBootOption ( + VOID + ) +{ + EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions; + UINTN BootOptionCount; + + BootOptions =3D EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOpti= onTypeBoot); + + // + // If setup is the first priority in boot option, we need to sort boot o= ption. + // + if ((BootOptionCount > 1) && + (((StrnCmp (BootOptions->Description, L"Enter Setup", StrLen (L"Ente= r Setup"))) =3D=3D 0) || + ((StrnCmp (BootOptions->Description, L"BootManagerMenuApp", StrLen = (L"BootManagerMenuApp"))) =3D=3D 0))) { + return TRUE; + } + + return FALSE; +} + +/** + The function will excute with as the platform policy, current policy + is driven by boot mode. IBV/OEM can customize this code for their specif= ic + policy action. + + @param DriverOptionList - The header of the driver option link list + @param BootOptionList - The header of the boot option link list + @param ProcessCapsules - A pointer to ProcessCapsules() + @param BaseMemoryTest - A pointer to BaseMemoryTest() +**/ +VOID +EFIAPI +PlatformBootManagerAfterConsole ( + VOID + ) +{ + EFI_BOOT_MODE LocalBootMode; + + DEBUG ((DEBUG_INFO, "PlatformBootManagerAfterConsole\n")); + + // + // Get current Boot Mode + // + LocalBootMode =3D gBootMode; + DEBUG ((DEBUG_INFO, "Current local bootmode - %x\n", LocalBootMode)); + + // + // Logo show + // + BootLogoEnableLogo (); + + // + // Go the different platform policy with different boot mode + // Notes: this part code can be change with the table policy + // + switch (LocalBootMode) { + + + case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES: + case BOOT_WITH_MINIMAL_CONFIGURATION: + case BOOT_ON_S4_RESUME: + // + // Perform some platform specific connect sequence + // + PERF_START_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7050); + ConnectSequence (LocalBootMode); + PERF_END_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7051); + + break; + + case BOOT_WITH_FULL_CONFIGURATION: + case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS: + case BOOT_WITH_DEFAULT_SETTINGS: + default: + // + // Perform some platform specific connect sequence + // + ConnectSequence (LocalBootMode); + + // + // Only in Full Configuration boot mode we do the enumeration of boot = device + // + // + // Dispatch all but Storage Oprom explicitly, because we assume Int13T= hunk driver is there. + // + EfiBootManagerRefreshAllBootOption (); + + if (IsNeedSortBootOption()) { + EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, CompareBoo= tOption); + } + // + // PXE boot option may appear after boot option enumeration + // + + break; + } + + Print (L"Press F7 for BootMenu!\n"); + + EfiBootManagerRefreshAllBootOption (); + EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, CompareBootOpt= ion); +} + +/** + The function is called when no boot option could be launched, + including platform recovery options and options pointing to applications + built into firmware volumes. + + If this function returns, BDS attempts to enter an infinite loop. +**/ +VOID +EFIAPI +PlatformBootManagerUnableToBoot ( + VOID + ) +{ + EFI_STATUS Status; + EFI_BOOT_MANAGER_LOAD_OPTION BootDeviceList; + CHAR16 OptionName[sizeof ("Boot####")]; + + if (mBootMenuOptionNumber =3D=3D LoadOptionNumberUnassigned) { + return; + } + UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", mBootMenuOp= tionNumber); + Status =3D EfiBootManagerVariableToLoadOption (OptionName, &BootDeviceLi= st); + if (EFI_ERROR (Status)) { + return; + } + for (;;) { + EfiBootManagerBoot (&BootDeviceList); + } +} diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManage= rLib/BdsPlatform.h b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBo= otManagerLib/BdsPlatform.h new file mode 100644 index 0000000000..0bdc11bdd8 --- /dev/null +++ b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/Bd= sPlatform.h @@ -0,0 +1,253 @@ +/** @file + Header file for BDS Platform specific code + +Copyright (c) 2017, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _BDS_PLATFORM_H +#define _BDS_PLATFORM_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/// +/// ConnectType +/// +#define CONSOLE_OUT 0x00000001 +#define STD_ERROR 0x00000002 +#define CONSOLE_IN 0x00000004 +#define CONSOLE_ALL (CONSOLE_OUT | CONSOLE_IN | STD_ERROR) + +extern EFI_GUID gUefiShellFileGuid; +extern EFI_BOOT_MODE gBootMode; + +#define PCI_DEVICE_PATH_NODE(Func, Dev) \ + { \ + HARDWARE_DEVICE_PATH, \ + HW_PCI_DP, \ + { \ + (UINT8) (sizeof (PCI_DEVICE_PATH)), \ + (UINT8) ((sizeof (PCI_DEVICE_PATH)) >> 8) \ + }, \ + (Func), \ + (Dev) \ + } + +#define PNPID_DEVICE_PATH_NODE(PnpId) \ + { \ + { \ + ACPI_DEVICE_PATH, \ + ACPI_DP, \ + { \ + (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), \ + (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) \ + } \ + }, \ + EISA_PNP_ID((PnpId)), \ + 0 \ + } + +#define gPciRootBridge \ + { \ + { \ + ACPI_DEVICE_PATH, \ + ACPI_DP, \ + { \ + (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), \ + (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) \ + }, \ + }, \ + EISA_PNP_ID (0x0A03), \ + 0 \ + } + +#define gPciIsaBridge \ + PCI_DEVICE_PATH_NODE(0, 0x1f) + +#define gPnp16550ComPort \ + PNPID_DEVICE_PATH_NODE(0x0501) + +#define gUart(BaudRate, DataBits, Parity, StopBits) \ + { \ + { \ + MESSAGING_DEVICE_PATH, \ + MSG_UART_DP, \ + { \ + (UINT8) (sizeof (UART_DEVICE_PATH)), \ + (UINT8) ((sizeof (UART_DEVICE_PATH)) >> 8) \ + } \ + }, \ + 0, \ + (BaudRate), \ + (DataBits), \ + (Parity), \ + (StopBits) \ + } + +#define gPcAnsiTerminal \ + { \ + { \ + MESSAGING_DEVICE_PATH, \ + MSG_VENDOR_DP, \ + { \ + (UINT8) (sizeof (VENDOR_DEVICE_PATH)), \ + (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) \ + } \ + }, \ + DEVICE_PATH_MESSAGING_PC_ANSI \ + } + +#define gEndEntire \ + { \ + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, { END_DEVICE_PAT= H_LENGTH, 0 } \ + } + +typedef struct { + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + UINTN ConnectType; +} BDS_CONSOLE_CONNECT_ENTRY; + +// +// Platform Root Bridge +// +typedef struct { + ACPI_HID_DEVICE_PATH PciRootBridge; + EFI_DEVICE_PATH_PROTOCOL End; +} PLATFORM_ROOT_BRIDGE_DEVICE_PATH; + +// +// Below is the platform console device path +// +typedef struct { + ACPI_HID_DEVICE_PATH PciRootBridge; + PCI_DEVICE_PATH IsaBridge; + ACPI_HID_DEVICE_PATH Keyboard; + EFI_DEVICE_PATH_PROTOCOL End; +} PLATFORM_KEYBOARD_DEVICE_PATH; + +typedef struct { + ACPI_HID_DEVICE_PATH PciRootBridge; + PCI_DEVICE_PATH PciDevice; + EFI_DEVICE_PATH_PROTOCOL End; +} PLATFORM_ONBOARD_CONTROLLER_DEVICE_PATH; + +typedef struct { + ACPI_HID_DEVICE_PATH PciRootBridge; + PCI_DEVICE_PATH Pci0Device; + EFI_DEVICE_PATH_PROTOCOL End; +} PLATFORM_PEG_ROOT_CONTROLLER_DEVICE_PATH; + +typedef struct { + ACPI_HID_DEVICE_PATH PciRootBridge; + PCI_DEVICE_PATH PciBridge; + PCI_DEVICE_PATH PciDevice; + EFI_DEVICE_PATH_PROTOCOL End; +} PLATFORM_PCI_CONTROLLER_DEVICE_PATH; + +// +// Below is the boot option device path +// + +#define CLASS_HID 3 +#define SUBCLASS_BOOT 1 +#define PROTOCOL_KEYBOARD 1 + +typedef struct { + USB_CLASS_DEVICE_PATH UsbClass; + EFI_DEVICE_PATH_PROTOCOL End; +} USB_CLASS_FORMAT_DEVICE_PATH; + +typedef struct { + ACPI_HID_DEVICE_PATH PciRootBridge; + PCI_DEVICE_PATH IsaBridge; + ACPI_HID_DEVICE_PATH IsaSerial; + UART_DEVICE_PATH Uart; + VENDOR_DEVICE_PATH TerminalType; + EFI_DEVICE_PATH_PROTOCOL End; +} PLATFORM_ISA_SERIAL_DEVICE_PATH; + +// +// Platform BDS Functions +// + + +/** + Perform the memory test base on the memory test intensive level, + and update the memory resource. + + @param Level The memory test intensive level. + + @retval EFI_STATUS Success test all the system memory and update + the memory resource + +**/ +EFI_STATUS +MemoryTest ( + IN EXTENDMEM_COVERAGE_LEVEL Level + ); + +VOID +ConnectSequence ( + IN EFI_BOOT_MODE BootMode + ); + + +INTN +EFIAPI +CompareBootOption ( + CONST VOID *Left, + CONST VOID *Right + ); + + +VOID +RegisterStaticHotkey ( + VOID + ); +VOID +RegisterDefaultBootOption ( + VOID + ); + +#endif diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManage= rLib/DxePlatformBootManagerLib.inf b/Platform/Intel/Vlv2TbltDevicePkg/Libra= ry/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf new file mode 100644 index 0000000000..b04169ad33 --- /dev/null +++ b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/Dx= ePlatformBootManagerLib.inf @@ -0,0 +1,95 @@ +### @file +# Component name for module DxePlatformBootManagerLib +# +# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +### + +[Defines] + INF_VERSION =3D 0x00010017 + BASE_NAME =3D DxePlatformBootManagerLib + FILE_GUID =3D A6BC385D-59E5-4B77-87D7-200ABAA83C15 + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D DXE_DRIVER + UEFI_SPECIFICATION_VERSION =3D 2.10 + LIBRARY_CLASS =3D PlatformBootManagerLib|DXE_DRIVER +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 EBC +# + +[LibraryClasses] + BaseLib + MemoryAllocationLib + UefiBootServicesTableLib + UefiRuntimeServicesTableLib + BaseMemoryLib + DebugLib + PcdLib + PrintLib + DevicePathLib + UefiLib + HobLib + DxeServicesLib + DxeServicesTableLib + HiiLib + UefiBootManagerLib + PerformanceLib + TimerLib + Tcg2PhysicalPresenceLib + CapsuleLib + BootLogoLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + SecurityPkg/SecurityPkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[Pcd] + gMinPlatformPkgTokenSpaceGuid.PcdTpm2Enable ## CONSUM= ES + gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut ## PRO= DUCES + gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution ## PRO= DUCES + gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution ## PRO= DUCES + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow ## PRO= DUCES + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn ## PRO= DUCES + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupConOutColumn ## CON= SUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupConOutRow ## CON= SUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution ## CON= SUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution ## CON= SUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand ## PRO= DUCES + gMinPlatformPkgTokenSpaceGuid.PcdPlatformMemoryCheckLevel ## CONSUM= ES + gMinPlatformPkgTokenSpaceGuid.PcdBootToShellOnly ## CONSUM= ES + gMinPlatformPkgTokenSpaceGuid.PcdTrustedConsoleInputDevicePath ## CONSU= MES + gMinPlatformPkgTokenSpaceGuid.PcdTrustedConsoleOutputDevicePath ## CONSU= MES + gMinPlatformPkgTokenSpaceGuid.PcdTrustedStorageDevicePath ## CONSU= MES + +[Sources] + BdsPlatform.c + BdsPlatform.h + PlatformBootOption.c + MemoryTest.c + +[Protocols] + gEfiPciRootBridgeIoProtocolGuid ## CONSUMES + gEfiPciIoProtocolGuid ## CONSUMES + gEfiCpuIo2ProtocolGuid ## CONSUMES + gEfiDxeSmmReadyToLockProtocolGuid ## PRODUCES + gEfiGenericMemTestProtocolGuid ## CONSUMES + gEfiDiskInfoProtocolGuid ## CONSUMES + gEfiDevicePathToTextProtocolGuid ## CONSUMES + gEfiSimpleTextInputExProtocolGuid ## CONSUMES + gEfiFirmwareVolume2ProtocolGuid ## CONSUMES + gEfiFormBrowser2ProtocolGuid ## CONSUMES + gEfiGenericMemTestProtocolGuid ## CONSUMES + +[Guids] + gEfiGlobalVariableGuid ## PRODUCES + gEfiMemoryOverwriteControlDataGuid ## PRODUCES + gEfiEndOfDxeEventGroupGuid ## CONSUMES + +[Depex.common.DXE_DRIVER] + gEfiVariableArchProtocolGuid diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManage= rLib/MemoryTest.c b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBoo= tManagerLib/MemoryTest.c new file mode 100644 index 0000000000..654845349a --- /dev/null +++ b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/Me= moryTest.c @@ -0,0 +1,83 @@ +/** @file + Perform the platform memory test + +Copyright (c) 2017, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "BdsPlatform.h" +#include + +/** + Perform the memory test base on the memory test intensive level, + and update the memory resource. + + @param Level The memory test intensive level. + + @retval EFI_STATUS Success test all the system memory and update + the memory resource + +**/ +EFI_STATUS +MemoryTest ( + IN EXTENDMEM_COVERAGE_LEVEL Level + ) +{ + EFI_STATUS Status; + BOOLEAN RequireSoftECCInit; + EFI_GENERIC_MEMORY_TEST_PROTOCOL *GenMemoryTest; + UINT64 TestedMemorySize; + UINT64 TotalMemorySize; + BOOLEAN ErrorOut; + BOOLEAN TestAbort; + + TestedMemorySize =3D 0; + TotalMemorySize =3D 0; + ErrorOut =3D FALSE; + TestAbort =3D FALSE; + + RequireSoftECCInit =3D FALSE; + + Status =3D gBS->LocateProtocol ( + &gEfiGenericMemTestProtocolGuid, + NULL, + (VOID **) &GenMemoryTest + ); + if (EFI_ERROR (Status)) { + return EFI_SUCCESS; + } + + Status =3D GenMemoryTest->MemoryTestInit ( + GenMemoryTest, + Level, + &RequireSoftECCInit + ); + if (Status =3D=3D EFI_NO_MEDIA) { + // + // The PEI codes also have the relevant memory test code to check the = memory, + // it can select to test some range of the memory or all of them. If P= EI code + // checks all the memory, this BDS memory test will has no not-test me= mory to + // do the test, and then the status of EFI_NO_MEDIA will be returned by + // "MemoryTestInit". So it does not need to test memory again, just re= turn. + // + return EFI_SUCCESS; + } + + do { + Status =3D GenMemoryTest->PerformMemoryTest ( + GenMemoryTest, + &TestedMemorySize, + &TotalMemorySize, + &ErrorOut, + TestAbort + ); + if (ErrorOut && (Status =3D=3D EFI_DEVICE_ERROR)) { + ASSERT (0); + } + } while (Status !=3D EFI_NOT_FOUND); + + Status =3D GenMemoryTest->Finished (GenMemoryTest); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManage= rLib/PlatformBootOption.c b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePla= tformBootManagerLib/PlatformBootOption.c new file mode 100644 index 0000000000..84aa097d58 --- /dev/null +++ b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/Pl= atformBootOption.c @@ -0,0 +1,559 @@ +/** @file + Driver for Platform Boot Options support. + +Copyright (c) 2017, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "BdsPlatform.h" + +#include + +BOOLEAN mContinueBoot =3D FALSE; +BOOLEAN mBootMenuBoot =3D FALSE; +BOOLEAN mPxeBoot =3D FALSE; +BOOLEAN mHotKeypressed =3D FALSE; +EFI_EVENT HotKeyEvent =3D NULL; + +UINTN mBootMenuOptionNumber; + +EFI_DEVICE_PATH_PROTOCOL * +BdsCreateShellDevicePath ( + VOID + ) +/*++ + +Routine Description: + + This function will create a SHELL BootOption to boot. + +Arguments: + + None. + +Returns: + + Shell Device path for booting. + +--*/ +{ + UINTN FvHandleCount; + EFI_HANDLE *FvHandleBuffer; + UINTN Index; + EFI_STATUS Status; + EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv; + UINTN Size; + UINT32 AuthenticationStatus; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + VOID *Buffer; + + DevicePath =3D NULL; + Status =3D EFI_SUCCESS; + + DEBUG ((DEBUG_INFO, "BdsCreateShellDevicePath\n")); + gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiFirmwareVolume2ProtocolGuid, + NULL, + &FvHandleCount, + &FvHandleBuffer + ); + + for (Index =3D 0; Index < FvHandleCount; Index++) { + gBS->HandleProtocol ( + FvHandleBuffer[Index], + &gEfiFirmwareVolume2ProtocolGuid, + (VOID **) &Fv + ); + + Buffer =3D NULL; + Size =3D 0; + Status =3D Fv->ReadSection ( + Fv, + &gUefiShellFileGuid, + EFI_SECTION_PE32, + 0, + &Buffer, + &Size, + &AuthenticationStatus + ); + if (EFI_ERROR (Status)) { + // + // Skip if no shell file in the FV + // + continue; + } else { + // + // Found the shell + // + break; + } + } + + if (EFI_ERROR (Status)) { + // + // No shell present + // + if (FvHandleCount) { + FreePool (FvHandleBuffer); + } + return NULL; + } + // + // Build the shell boot option + // + DevicePath =3D DevicePathFromHandle (FvHandleBuffer[Index]); + + if (FvHandleCount) { + FreePool (FvHandleBuffer); + } + + return DevicePath; +} + + +EFI_STATUS +CreateFvBootOption ( + EFI_GUID *FileGuid, + CHAR16 *Description, + EFI_BOOT_MANAGER_LOAD_OPTION *BootOption, + UINT32 Attributes, + UINT8 *OptionalData, OPTIONAL + UINT32 OptionalDataSize + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode; + EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv; + UINT32 AuthenticationStatus; + VOID *Buffer; + UINTN Size; + + if ((BootOption =3D=3D NULL) || (FileGuid =3D=3D NULL) || (Description = =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid); + + if (!CompareGuid (&gUefiShellFileGuid, FileGuid)) { + Status =3D gBS->HandleProtocol ( + gImageHandle, + &gEfiLoadedImageProtocolGuid, + (VOID **) &LoadedImage + ); + if (!EFI_ERROR (Status)) { + Status =3D gBS->HandleProtocol ( + LoadedImage->DeviceHandle, + &gEfiFirmwareVolume2ProtocolGuid, + (VOID **) &Fv + ); + if (!EFI_ERROR (Status)) { + Buffer =3D NULL; + Size =3D 0; + Status =3D Fv->ReadSection ( + Fv, + FileGuid, + EFI_SECTION_PE32, + 0, + &Buffer, + &Size, + &AuthenticationStatus + ); + if (Buffer !=3D NULL) { + FreePool (Buffer); + } + } + } + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + + DevicePath =3D AppendDevicePathNode ( + DevicePathFromHandle (LoadedImage->DeviceHandle), + (EFI_DEVICE_PATH_PROTOCOL *) &FileNode + ); + } else { + DevicePath =3D AppendDevicePathNode ( + BdsCreateShellDevicePath (), + (EFI_DEVICE_PATH_PROTOCOL *) &FileNode + ); + } + + Status =3D EfiBootManagerInitializeLoadOption ( + BootOption, + LoadOptionNumberUnassigned, + LoadOptionTypeBoot, + Attributes, + Description, + DevicePath, + OptionalData, + OptionalDataSize + ); + FreePool (DevicePath); + return Status; +} + +EFI_GUID mUiFile =3D { + 0x462CAA21, 0x7614, 0x4503, { 0x83, 0x6E, 0x8A, 0xB6, 0xF4, 0x66, 0x23, = 0x31 } +}; +EFI_GUID mBootMenuFile =3D { + 0xEEC25BDC, 0x67F2, 0x4D95, { 0xB1, 0xD5, 0xF8, 0x1B, 0x20, 0x39, 0xD1, = 0x1D } +}; + + +/** + Return the index of the load option in the load option array. + + The function consider two load options are equal when the + OptionType, Attributes, Description, FilePath and OptionalData are equal. + + @param Key Pointer to the load option to be found. + @param Array Pointer to the array of load options to be found. + @param Count Number of entries in the Array. + + @retval -1 Key wasn't found in the Array. + @retval 0 ~ Count-1 The index of the Key in the Array. +**/ +INTN +PlatformFindLoadOption ( + IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key, + IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array, + IN UINTN Count + ) +{ + UINTN Index; + + for (Index =3D 0; Index < Count; Index++) { + if ((Key->OptionType =3D=3D Array[Index].OptionType) && + (Key->Attributes =3D=3D Array[Index].Attributes) && + (StrCmp (Key->Description, Array[Index].Description) =3D=3D 0) && + (CompareMem (Key->FilePath, Array[Index].FilePath, GetDevicePathSi= ze (Key->FilePath)) =3D=3D 0) && + (Key->OptionalDataSize =3D=3D Array[Index].OptionalDataSize) && + (CompareMem (Key->OptionalData, Array[Index].OptionalData, Key->Op= tionalDataSize) =3D=3D 0)) { + return (INTN) Index; + } + } + + return -1; +} + +UINTN +RegisterFvBootOption ( + EFI_GUID *FileGuid, + CHAR16 *Description, + UINTN Position, + UINT32 Attributes, + UINT8 *OptionalData, OPTIONAL + UINT32 OptionalDataSize + ) +{ + EFI_STATUS Status; + UINTN OptionIndex; + EFI_BOOT_MANAGER_LOAD_OPTION NewOption; + EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions; + UINTN BootOptionCount; + + NewOption.OptionNumber =3D LoadOptionNumberUnassigned; + Status =3D CreateFvBootOption (FileGuid, Description, &NewOption, Attrib= utes, OptionalData, OptionalDataSize); + if (!EFI_ERROR (Status)) { + BootOptions =3D EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOp= tionTypeBoot); + + OptionIndex =3D PlatformFindLoadOption (&NewOption, BootOptions, BootO= ptionCount); + + if (OptionIndex =3D=3D -1) { + Status =3D EfiBootManagerAddLoadOptionVariable (&NewOption, Position= ); + ASSERT_EFI_ERROR (Status); + } else { + NewOption.OptionNumber =3D BootOptions[OptionIndex].OptionNumber; + } + EfiBootManagerFreeLoadOption (&NewOption); + EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); + } + + return NewOption.OptionNumber; +} + + + +VOID +EFIAPI +PlatformBootManagerWaitCallback ( + UINT16 TimeoutRemain + ) +{ + EFI_STATUS Status; + EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx; + EFI_KEY_DATA KeyData; + BOOLEAN PausePressed; + + // + // Pause on PAUSE key + // + Status =3D gBS->HandleProtocol (gST->ConsoleInHandle, &gEfiSimpleTextInp= utExProtocolGuid, (VOID **) &TxtInEx); + ASSERT_EFI_ERROR (Status); + + PausePressed =3D FALSE; + + while (TRUE) { + Status =3D TxtInEx->ReadKeyStrokeEx (TxtInEx, &KeyData); + if (EFI_ERROR (Status)) { + break; + } + + if (KeyData.Key.ScanCode =3D=3D SCAN_PAUSE) { + PausePressed =3D TRUE; + break; + } + } + + // + // Loop until non-PAUSE key pressed + // + while (PausePressed) { + Status =3D TxtInEx->ReadKeyStrokeEx (TxtInEx, &KeyData); + if (!EFI_ERROR (Status)) { + DEBUG (( + DEBUG_INFO, "[PauseCallback] %x/%x %x/%x\n", + KeyData.Key.ScanCode, KeyData.Key.UnicodeChar, + KeyData.KeyState.KeyShiftState, KeyData.KeyState.KeyToggleState + )); + PausePressed =3D (BOOLEAN) (KeyData.Key.ScanCode =3D=3D SCAN_PAUSE); + } + } +} + + +EFI_GUID gUefiShellFileGuid =3D { 0x7C04A583, 0x9E3E, 0x4f1c, { 0xAD, 0x65= , 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 } }; + +#define INTERNAL_UEFI_SHELL_NAME L"Internal UEFI Shell 2.0" +#define UEFI_HARD_DRIVE_NAME L"UEFI Hard Drive" + +VOID +RegisterDefaultBootOption ( + VOID + ) +{ +#if 0 + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode; +#endif + UINT16 *ShellData; + UINT32 ShellDataSize; + + ShellData =3D NULL; + ShellDataSize =3D 0; + RegisterFvBootOption (&gUefiShellFileGuid, INTERNAL_UEFI_SHELL_NA= ME, (UINTN) -1, LOAD_OPTION_ACTIVE, (UINT8 *)ShellData, ShellDataSize); + + // + // Boot Menu + // + mBootMenuOptionNumber =3D RegisterFvBootOption (&mBootMenuFile, L"Boot D= evice List", (UINTN) -1, LOAD_OPTION_CATEGORY_APP | LOAD_OPTION_ACTIVE | = LOAD_OPTION_HIDDEN, NULL, 0); + + if (mBootMenuOptionNumber =3D=3D LoadOptionNumberUnassigned) { + DEBUG ((DEBUG_INFO, "BootMenuOptionNumber (%d) should not be same to L= oadOptionNumberUnassigned(%d).\n", mBootMenuOptionNumber, LoadOptionNumberU= nassigned)); + } +#if 0 + // + // Boot Manager Menu + // + EfiInitializeFwVolDevicepathNode (&FileNode, &mUiFile); + + gBS->HandleProtocol ( + gImageHandle, + &gEfiLoadedImageProtocolGuid, + (VOID **) &LoadedImage + ); + DevicePath =3D AppendDevicePathNode (DevicePathFromHandle (LoadedImage->= DeviceHandle), (EFI_DEVICE_PATH_PROTOCOL *) &FileNode); +#endif + +} + +VOID +RegisterBootOptionHotkey ( + UINT16 OptionNumber, + EFI_INPUT_KEY *Key, + BOOLEAN Add + ) +{ + EFI_STATUS Status; + + if (!Add) { + // + // No enter hotkey when force to setup or there is no boot option + // + Status =3D EfiBootManagerDeleteKeyOptionVariable (NULL, 0, Key, NULL); + ASSERT (Status =3D=3D EFI_SUCCESS || Status =3D=3D EFI_NOT_FOUND); + } else { + // + // Register enter hotkey for the first boot option + // + Status =3D EfiBootManagerAddKeyOptionVariable (NULL, OptionNumber, 0, = Key,NULL); + ASSERT (Status =3D=3D EFI_SUCCESS || Status =3D=3D EFI_ALREADY_STARTED= ); + } +} + +EFI_STATUS +EFIAPI +DetectKeypressCallback ( + IN EFI_KEY_DATA *KeyData +) +{ + mHotKeypressed =3D TRUE; + + if (HotKeyEvent !=3D NULL) { + gBS->SignalEvent(HotKeyEvent); + } + + return EFI_SUCCESS; +} + +/** + This function is called after all the boot options are enumerated and or= dered properly. +**/ +VOID +RegisterStaticHotkey ( + VOID + ) +{ + + EFI_INPUT_KEY Enter; + EFI_KEY_DATA F2; + EFI_KEY_DATA F7; + BOOLEAN EnterSetup; + EFI_STATUS Status; + EFI_BOOT_MANAGER_LOAD_OPTION BootOption; + + EnterSetup =3D FALSE; + + // + // [Enter] + // + mContinueBoot =3D !EnterSetup; + if (mContinueBoot) { + Enter.ScanCode =3D SCAN_NULL; + Enter.UnicodeChar =3D CHAR_CARRIAGE_RETURN; + EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL); + } + + + // + // [F2]/[F7] + // + F2.Key.ScanCode =3D SCAN_F2; + F2.Key.UnicodeChar =3D CHAR_NULL; + F2.KeyState.KeyShiftState =3D EFI_SHIFT_STATE_VALID; + F2.KeyState.KeyToggleState =3D 0; + Status =3D EfiBootManagerGetBootManagerMenu (&BootOption); + ASSERT_EFI_ERROR (Status); + RegisterBootOptionHotkey ((UINT16) BootOption.OptionNumber, &F2.Key, TRU= E); + EfiBootManagerFreeLoadOption (&BootOption); + + F7.Key.ScanCode =3D SCAN_F7; + F7.Key.UnicodeChar =3D CHAR_NULL; + F7.KeyState.KeyShiftState =3D EFI_SHIFT_STATE_VALID; + F7.KeyState.KeyToggleState =3D 0; + mBootMenuBoot =3D !EnterSetup; + RegisterBootOptionHotkey ((UINT16) mBootMenuOptionNumber, &F7.Key, mBoot= MenuBoot); + +} + +UINT8 +BootOptionType ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + EFI_DEVICE_PATH_PROTOCOL *Node; + EFI_DEVICE_PATH_PROTOCOL *NextNode; + + for (Node =3D DevicePath; !IsDevicePathEndType (Node); Node =3D NextDevi= cePathNode (Node)) { + if (DevicePathType (Node) =3D=3D MESSAGING_DEVICE_PATH) { + // + // Make sure the device path points to the driver device. + // + NextNode =3D NextDevicePathNode (Node); + if (DevicePathSubType(NextNode) =3D=3D MSG_DEVICE_LOGICAL_UNIT_DP) { + // + // if the next node type is Device Logical Unit, which specify the= Logical Unit Number (LUN), + // skip it + // + NextNode =3D NextDevicePathNode (NextNode); + } + if (IsDevicePathEndType (NextNode)) { + if ((DevicePathType (Node) =3D=3D MESSAGING_DEVICE_PATH)) { + return DevicePathSubType (Node); + } else { + return MSG_SATA_DP; + } + } + } + } + + return (UINT8) -1; +} + +/** + Returns the priority number. + OptionType EFI + ------------------------------------ + PXE 2 + DVD 4 + USB 6 + NVME 7 + HDD 8 + EFI Shell 9 + Others 100 + + @param BootOption +**/ +UINTN +BootOptionPriority ( + CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOption + ) +{ + // + // EFI boot options + // + switch (BootOptionType (BootOption->FilePath)) { + case MSG_MAC_ADDR_DP: + case MSG_VLAN_DP: + case MSG_IPv4_DP: + case MSG_IPv6_DP: + return 2; + + case MSG_SATA_DP: + case MSG_ATAPI_DP: + case MSG_UFS_DP: + case MSG_NVME_NAMESPACE_DP: + return 4; + + case MSG_USB_DP: + return 6; + + } + if (StrCmp (BootOption->Description, INTERNAL_UEFI_SHELL_NAME) =3D=3D = 0) { + if (PcdGetBool (PcdBootToShellOnly)) { + return 0; + } + return 9; + } + if (StrCmp (BootOption->Description, UEFI_HARD_DRIVE_NAME) =3D=3D 0) { + return 8; + } + return 100; +} + +INTN +EFIAPI +CompareBootOption ( + CONST VOID *Left, + CONST VOID *Right + ) +{ + return BootOptionPriority ((EFI_BOOT_MANAGER_LOAD_OPTION *) Left) - + BootOptionPriority ((EFI_BOOT_MANAGER_LOAD_OPTION *) Right); +} + diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPla= tform.c b/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatfo= rm.c deleted file mode 100644 index 4adca1b465..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.c +++ /dev/null @@ -1,3092 +0,0 @@ -/** @file - - Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.
- = =20 - SPDX-License-Identifier: BSD-2-Clause-Patent - = =20 - - -Module Name: - - BdsPlatform.c - -Abstract: - - This file include all platform action which can be customized - by IBV/OEM. - ---*/ - -#include "BdsPlatform.h" -#include "SetupMode.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "PchAccess.h" -#include "PchRegs/PchRegsSata.h" -#include -#include - -#include -#include -#include - -#include -#include - -EFI_GUID *ConnectDriverTable[] =3D { - &gEfiMmioDeviceProtocolGuid, - &gEfiI2cMasterProtocolGuid, - &gEfiI2cHostProtocolGuid -}; - -#define SHELL_ENVIRONMENT_INTERFACE_PROTOCOL \ - { \ - 0x47c7b221, 0xc42a, 0x11d2, 0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0= x3b \ - } -VOID *mShellImageCallbackReg =3D NULL; - - - -EFI_USER_PROFILE_HANDLE mCurrentUser =3D NULL; -EFI_EVENT mHotKeyTimerEvent =3D NU= LL; -EFI_EVENT mHitHotkeyEvent =3D NULL; -EFI_EVENT mUsbKeyboardConnectEvent= =3D NULL; -BOOLEAN mHotKeyPressed =3D FALSE; -VOID *mHitHotkeyRegistration; -#define KEYBOARD_TIMER_INTERVAL 20000 // 0.02s - -VOID -ConnectUSBController ( - VOID - ); - -EFI_STATUS -PlatformBdsConnectSimpleConsole ( - IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole -); - -VOID=20 -BootIntoFirmwareInterface( - VOID - ); - =20 -VOID -EFIAPI -PlatformBdsInitHotKeyEvent ( - VOID - ); - -VOID -EFIAPI -DisableAhciCtlr ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - UINT32 PmcDisableAddress; - UINT8 SataStorageAmount; - UINT32 SataBase; - UINT16 SataPortStatus; - - - DEBUG ((EFI_D_INFO, "Disable AHCI event is signalled\n")); - SataStorageAmount =3D 0; - SataBase =3D *(UINT32*) Context; - - // - // BayTrail-M EDS chapter 16 ---- PCI IO Register Offset 92 (SATA Port C= ontrol and Status) - // - SataPortStatus =3D MmioRead16 (SataBase + R_PCH_SATA_PCS); - - // - // Bit 8 EN: Port 0 Present - // - if ((SataPortStatus & 0x100) =3D=3D 0x100) { - SataStorageAmount++; - } - - // - // Bit 9 EN: Port 1 Present - // - if ((SataPortStatus & 0x200) =3D=3D 0x200) { - SataStorageAmount++; - } - - // - // Disable SATA controller when it sets to AHCI mode without carrying an= y devices - // in order to prevent AHCI yellow bang under Win device manager. - // - if (SataStorageAmount =3D=3D 0) { - PmcDisableAddress =3D (MmioRead32 ((PCH_PCI_EXPRESS_BASE_ADDRESS + (UI= NT32) (31 << 15)) + R_PCH_LPC_PMC_BASE) & B_PCH_LPC_PMC_BASE_BAR) + R_PCH_P= MC_FUNC_DIS; - MmioOr32 (PmcDisableAddress, B_PCH_PMC_FUNC_DIS_SATA); - S3BootScriptSaveMemWrite ( - EfiBootScriptWidthUint32, - (UINTN) PmcDisableAddress, - 1, - (VOID *) (UINTN) PmcDisableAddress - ); - } -} - -VOID -InstallReadyToLock ( - VOID - ) -{ - EFI_STATUS Status; - EFI_HANDLE Handle; - EFI_SMM_ACCESS2_PROTOCOL *SmmAccess; - EFI_ACPI_S3_SAVE_PROTOCOL *AcpiS3Save; - - // - // Install DxeSmmReadyToLock protocol prior to the processing of boot op= tions - // - Status =3D gBS->LocateProtocol ( - &gEfiSmmAccess2ProtocolGuid, - NULL, - (VOID **) &SmmAccess - ); - if (!EFI_ERROR (Status)) { - - // - // Prepare S3 information, this MUST be done before DxeSmmReadyToLock - // - Status =3D gBS->LocateProtocol ( - &gEfiAcpiS3SaveProtocolGuid, - NULL, - (VOID **)&AcpiS3Save - ); - if (!EFI_ERROR (Status)) { - AcpiS3Save->S3Save (AcpiS3Save, NULL); - } - - Handle =3D NULL; - Status =3D gBS->InstallProtocolInterface ( - &Handle, - &gExitPmAuthProtocolGuid, - EFI_NATIVE_INTERFACE, - NULL - ); - ASSERT_EFI_ERROR (Status); - - // - // Signal EndOfDxe PI Event - // - EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid); - - Handle =3D NULL; - Status =3D gBS->InstallProtocolInterface ( - &Handle, - &gEfiDxeSmmReadyToLockProtocolGuid, - EFI_NATIVE_INTERFACE, - NULL - ); - ASSERT_EFI_ERROR (Status); - } - - return ; -} - -VOID -EFIAPI -ShellImageCallback ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - BdsSetConsoleMode (TRUE); - DEBUG ((EFI_D_INFO, "BdsEntry ShellImageCallback \n")); -} - -// -// BDS Platform Functions -// -/** - Platform Bds init. Include the platform firmware vendor, revision - and so crc check. - - @param VOID - - @retval None. - -**/ -VOID -EFIAPI -PlatformBdsInit ( - VOID - ) -{ - EFI_STATUS Status; - EFI_EVENT ShellImageEvent; - EFI_GUID ShellEnvProtocol =3D SHELL_ENVIRONMENT_INTERFACE_PROTOCOL; - - #ifdef __GNUC__ - SerialPortWrite((UINT8 *)">>>>BdsEntry[GCC]\r\n", 19); - #else - SerialPortWrite((UINT8 *)">>>>BdsEntry\r\n", 14); - #endif - BdsLibSaveMemoryTypeInformation (); - - // - // Before user authentication, the user identification devices need be c= onnected - // from the platform customized device paths - // - PlatformBdsConnectAuthDevice (); - - // - // As console is not ready, the auto logon user will be identified. - // - BdsLibUserIdentify (&mCurrentUser); - - // - // Change Gop mode when boot into Shell - // - if (mShellImageCallbackReg =3D=3D NULL) { - Status =3D gBS->CreateEvent ( - EFI_EVENT_NOTIFY_SIGNAL, - EFI_TPL_CALLBACK, - ShellImageCallback, - NULL, - &ShellImageEvent - ); - if (!EFI_ERROR (Status)) { - Status =3D gBS->RegisterProtocolNotify ( - &ShellEnvProtocol, - ShellImageEvent, - &mShellImageCallbackReg - ); - - DEBUG ((EFI_D_INFO, "BdsEntry ShellImageCallback \n")); - } - } -} - -EFI_STATUS -GetGopDevicePath ( - IN EFI_DEVICE_PATH_PROTOCOL *PciDevicePath, - OUT EFI_DEVICE_PATH_PROTOCOL **GopDevicePath - ) -{ - UINTN Index; - EFI_STATUS Status; - EFI_HANDLE PciDeviceHandle; - EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; - EFI_DEVICE_PATH_PROTOCOL *TempPciDevicePath; - UINTN GopHandleCount; - EFI_HANDLE *GopHandleBuffer; - - UINTN VarSize; - SYSTEM_CONFIGURATION mSystemConfiguration; - - if (PciDevicePath =3D=3D NULL || GopDevicePath =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // Initialize the GopDevicePath to be PciDevicePath - // - *GopDevicePath =3D PciDevicePath; - TempPciDevicePath =3D PciDevicePath; - - Status =3D gBS->LocateDevicePath ( - &gEfiDevicePathProtocolGuid, - &TempPciDevicePath, - &PciDeviceHandle - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Try to connect this handle, so that GOP driver could start on this - // device and create child handles with GraphicsOutput Protocol installed - // on them, then we get device paths of these child handles and select - // them as possible console device. - // - - // - // Select display devices - // - VarSize =3D sizeof(SYSTEM_CONFIGURATION); - Status =3D gRT->GetVariable( - L"Setup", - &gEfiNormalSetupGuid, - NULL, - &VarSize, - &mSystemConfiguration - ); - if (EFI_ERROR (Status) || VarSize !=3D sizeof(SYSTEM_CONFIGURATION)) { - //The setup variable is corrupted - VarSize =3D sizeof(SYSTEM_CONFIGURATION); - Status =3D gRT->GetVariable( - L"SetupRecovery", - &gEfiNormalSetupGuid, - NULL, - &VarSize, - &mSystemConfiguration - ); - ASSERT_EFI_ERROR (Status); - } =20 - - if(mSystemConfiguration.BootDisplayDevice !=3D 0x0) - { - ACPI_ADR_DEVICE_PATH AcpiAdr; - EFI_DEVICE_PATH_PROTOCOL *MyDevicePath =3D NULL; - - AcpiAdr.Header.Type =3D ACPI_DEVICE_PATH; - AcpiAdr.Header.SubType =3D ACPI_ADR_DP; - - switch (mSystemConfiguration.BootDisplayDevice) { - case 1: - AcpiAdr.ADR=3D ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYP= E_VGA, PORT_CRT, 0); //CRT Device - break; - case 2: - AcpiAdr.ADR=3D ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYP= E_EXTERNAL_DIGITAL, PORT_B_HDMI, 0); //HDMI Device Port B - break; - case 3: - AcpiAdr.ADR=3D ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYP= E_EXTERNAL_DIGITAL, PORT_B_DP, 0); //DP PortB - break; - case 4: - AcpiAdr.ADR=3D ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYP= E_EXTERNAL_DIGITAL, PORT_C_DP, 0); //DP PortC - break; - case 5: - AcpiAdr.ADR=3D ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYP= E_INTERNAL_DIGITAL, PORT_C_DP, 0); //eDP Port C - break; - case 6: - AcpiAdr.ADR=3D ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYP= E_INTERNAL_DIGITAL, PORT_MIPI_A, 0); //DSI Port A - break; - case 7: - AcpiAdr.ADR=3D ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYP= E_INTERNAL_DIGITAL, PORT_MIPI_C, 0); //DSI Port C - break; - default: - AcpiAdr.ADR=3D ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYP= E_VGA, PORT_CRT, 0); - break; - } - - SetDevicePathNodeLength (&AcpiAdr.Header, sizeof (ACPI_ADR_DEVICE_PATH= )); - - MyDevicePath =3D AppendDevicePathNode(MyDevicePath, (EFI_DEVICE_PATH_P= ROTOCOL*)&AcpiAdr); - - gBS->ConnectController ( - PciDeviceHandle, - NULL, - MyDevicePath, - FALSE - ); - - FreePool(MyDevicePath); - } - else - { - gBS->ConnectController ( - PciDeviceHandle, - NULL, - NULL, - FALSE - ); - } - - Status =3D gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiGraphicsOutputProtocolGuid, - NULL, - &GopHandleCount, - &GopHandleBuffer - ); - if (!EFI_ERROR (Status)) { - // - // Add all the child handles as possible Console Device - // - for (Index =3D 0; Index < GopHandleCount; Index++) { - Status =3D gBS->HandleProtocol ( - GopHandleBuffer[Index], - &gEfiDevicePathProtocolGuid, - (VOID**)&TempDevicePath - ); - if (EFI_ERROR (Status)) { - continue; - } - if (CompareMem ( - PciDevicePath, - TempDevicePath, - GetDevicePathSize (PciDevicePath) - END_DEVICE_PATH_LENGTH - ) =3D=3D 0) { - // - // In current implementation, we only enable one of the child hand= les - // as console device, i.e. sotre one of the child handle's device - // path to variable "ConOut" - // In future, we could select all child handles to be console devi= ce - // - *GopDevicePath =3D TempDevicePath; - } - } - gBS->FreePool (GopHandleBuffer); - } - - return EFI_SUCCESS; -} - -/** - - Search out all the platform pci or agp video device. The function may wi= ll - find multiple video device, and return all enabled device path. - - @param PlugInPciVgaDevicePath Return the platform plug in pci video d= evice - path if the system have plug in pci vid= eo device. - @param OnboardPciVgaDevicePath Return the platform active agp video de= vice path - if the system have plug in agp video de= vice or on - chip agp device. - - @retval EFI_SUCCSS Get all platform active video device pa= th. - @retval EFI_STATUS Return the status of gBS->LocateDeviceP= ath (), - gBS->ConnectController (), - and gBS->LocateHandleBuffer (). - -**/ -EFI_STATUS -GetPlugInPciVgaDevicePath ( - IN OUT EFI_DEVICE_PATH_PROTOCOL **PlugInPciVgaDevicePath, - IN OUT EFI_DEVICE_PATH_PROTOCOL **OnboardPciVgaDevicePath - ) -{ - EFI_STATUS Status; - EFI_HANDLE RootHandle; - UINTN HandleCount; - EFI_HANDLE *HandleBuffer; - UINTN Index; - UINTN Index1; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - BOOLEAN PlugInPciVga; - EFI_PCI_IO_PROTOCOL *PciIo; - PCI_TYPE00 Pci; - - DevicePath =3D NULL; - PlugInPciVga =3D TRUE; - HandleCount =3D 0; - HandleBuffer =3D NULL; - - // - // Make all the PCI_IO protocols on PCI Seg 0 show up - // - BdsLibConnectDevicePath (gPlatformRootBridges[0]); - - Status =3D gBS->LocateDevicePath ( - &gEfiDevicePathProtocolGuid, - &gPlatformRootBridges[0], - &RootHandle - ); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D gBS->ConnectController ( - RootHandle, - NULL, - NULL, - FALSE - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Start to check all the pci io to find all possible VGA device - // - HandleCount =3D 0; - HandleBuffer =3D NULL; - Status =3D gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiPciIoProtocolGuid, - NULL, - &HandleCount, - &HandleBuffer - ); - if (EFI_ERROR (Status)) { - return Status; - } - - for (Index =3D 0; Index < HandleCount; Index++) { - Status =3D gBS->HandleProtocol ( - HandleBuffer[Index], - &gEfiPciIoProtocolGuid, - (VOID**)&PciIo - ); - if (!EFI_ERROR (Status)) { - - // - // Check for all VGA device - // - Status =3D PciIo->Pci.Read ( - PciIo, - EfiPciIoWidthUint32, - 0, - sizeof (Pci) / sizeof (UINT32), - &Pci - ); - if (EFI_ERROR (Status)) { - continue; - } - - // - // Here we decide which VGA device to enable in PCI bus - // - // The first plugin PCI VGA card device will be present as PCI VGA - // The onchip AGP or AGP card will be present as AGP VGA - // - if (!IS_PCI_VGA (&Pci)) { - continue; - } - - // - // Set the device as the possible console out device, - // - // Below code will make every VGA device to be one - // of the possibe console out device - // - PlugInPciVga =3D TRUE; - gBS->HandleProtocol ( - HandleBuffer[Index], - &gEfiDevicePathProtocolGuid, - (VOID**)&DevicePath - ); - - Index1 =3D 0; - - while (gPlatformAllPossiblePciVgaConsole[Index1] !=3D NULL) { - if (CompareMem ( - DevicePath, - gPlatformAllPossiblePciVgaConsole[Index1], - GetDevicePathSize (gPlatformAllPossiblePciVgaConsole[Index1]) - ) =3D=3D 0) { - - // - // This device is an AGP device - // - *OnboardPciVgaDevicePath =3D DevicePath; - PlugInPciVga =3D FALSE; - break; - } - - Index1 ++; - } - - if (PlugInPciVga) { - *PlugInPciVgaDevicePath =3D DevicePath; - } - } - } - - FreePool (HandleBuffer); - - return EFI_SUCCESS; -} - -/** - - Find the platform active vga, and base on the policy to enable the vga = as - the console out device. The policy is driven by one setup variable "VBIO= S". - - None. - - @param EFI_UNSUPPORTED There is no active vga device - - @retval EFI_STATUS Return the status of BdsLibGetVariableAnd= Size () - -**/ -EFI_STATUS -PlatformBdsForceActiveVga ( - VOID - ) -{ - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *PlugInPciVgaDevicePath; - EFI_DEVICE_PATH_PROTOCOL *OnboardPciVgaDevicePath; - EFI_DEVICE_PATH_PROTOCOL *DevicePathFirst; - EFI_DEVICE_PATH_PROTOCOL *DevicePathSecond; - EFI_DEVICE_PATH_PROTOCOL *GopDevicePath; - UINTN VarSize; - SYSTEM_CONFIGURATION mSystemConfiguration; - - Status =3D EFI_SUCCESS; - PlugInPciVgaDevicePath =3D NULL; - OnboardPciVgaDevicePath =3D NULL; - - // - // Check the policy which is the first enabled VGA - // - GetPlugInPciVgaDevicePath (&PlugInPciVgaDevicePath, &OnboardPciVgaDevice= Path); - - if (PlugInPciVgaDevicePath =3D=3D NULL && OnboardPciVgaDevicePath =3D=3D= NULL) { - return EFI_UNSUPPORTED; - } - - VarSize =3D sizeof(SYSTEM_CONFIGURATION); - Status =3D gRT->GetVariable( - L"Setup", - &gEfiNormalSetupGuid, - NULL, - &VarSize, - &mSystemConfiguration - ); - if (EFI_ERROR (Status) || VarSize !=3D sizeof(SYSTEM_CONFIGURATION)) { - //The setup variable is corrupted - VarSize =3D sizeof(SYSTEM_CONFIGURATION); - Status =3D gRT->GetVariable( - L"SetupRecovery", - &gEfiNormalSetupGuid, - NULL, - &VarSize, - &mSystemConfiguration - ); - ASSERT_EFI_ERROR (Status); - } =20 - - - if ((PlugInPciVgaDevicePath =3D=3D NULL && OnboardPciVgaDevicePath !=3D = NULL) ) { - DEBUG ((EFI_D_ERROR,"Update onboard PCI VGA ...\n")); - DevicePathFirst =3D OnboardPciVgaDevicePath; - DevicePathSecond =3D PlugInPciVgaDevicePath; - goto UpdateConOut; - } - if(OnboardPciVgaDevicePath !=3D NULL && mSystemConfiguration.PrimaryVide= oAdaptor =3D=3D 0) { - DEBUG ((EFI_D_ERROR,"Update onboard PCI VGA When set primary!!!...\n")= ); - DevicePathFirst =3D OnboardPciVgaDevicePath; - DevicePathSecond =3D PlugInPciVgaDevicePath; - goto UpdateConOut; - } - - DEBUG ((EFI_D_ERROR,"Update plug in PCI VGA ...\n")); - DevicePathFirst =3D PlugInPciVgaDevicePath; - DevicePathSecond =3D OnboardPciVgaDevicePath; - -UpdateConOut: - GetGopDevicePath (DevicePathFirst, &GopDevicePath); - DevicePathFirst =3D GopDevicePath; - - Status =3D BdsLibUpdateConsoleVariable ( - L"ConOut", - DevicePathFirst, - DevicePathSecond - ); - - return Status; -} - -VOID -UpdateConsoleResolution( - VOID - ) -{ - UINT32 HorizontalResolution; - UINT32 VerticalResolution; - SYSTEM_CONFIGURATION SystemConfiguration; - UINTN VarSize; - EFI_STATUS Status; - - - HorizontalResolution =3D PcdGet32 (PcdSetupVideoHorizontalResolution); - VerticalResolution =3D PcdGet32 (PcdSetupVideoVerticalResolution); - - VarSize =3D sizeof(SYSTEM_CONFIGURATION); - Status =3D gRT->GetVariable( - L"Setup", - &gEfiNormalSetupGuid, - NULL, - &VarSize, - &SystemConfiguration - ); - if (EFI_ERROR (Status) || VarSize !=3D sizeof(SYSTEM_CONFIGURATION)) { - //The setup variable is corrupted - VarSize =3D sizeof(SYSTEM_CONFIGURATION); - Status =3D gRT->GetVariable( - L"SetupRecovery", - &gEfiNormalSetupGuid, - NULL, - &VarSize, - &SystemConfiguration - ); - ASSERT_EFI_ERROR (Status); - } =20 - - switch (SystemConfiguration.IgdFlatPanel) { - - case 0: - // - // Use the detault PCD values. - // - break; - - case 1: - HorizontalResolution =3D 640; - VerticalResolution =3D 480; - break; - - case 2: - HorizontalResolution =3D 800; - VerticalResolution =3D 600; - break; - - case 3: - HorizontalResolution =3D 1024; - VerticalResolution =3D 768; - break; - - case 4: - HorizontalResolution =3D 1280; - VerticalResolution =3D 1024; - break; - - case 5: - HorizontalResolution =3D 1366; - VerticalResolution =3D 768; - break; - - case 6: - HorizontalResolution =3D 1680; - VerticalResolution =3D 1050; - break; - - case 7: - HorizontalResolution =3D 1920; - VerticalResolution =3D 1200; - break; - - case 8: - HorizontalResolution =3D 1280; - VerticalResolution =3D 800; - break; - } - - PcdSet32 (PcdSetupVideoHorizontalResolution, HorizontalResolution); - PcdSet32 (PcdSetupVideoVerticalResolution, VerticalResolution); - DEBUG ((EFI_D_ERROR, "HorizontalResolution =3D %x; VerticalResolution = =3D %x", HorizontalResolution, VerticalResolution)); - - return; -} - -/** - Connect the predefined platform default console device. Always try to fi= nd - and enable the vga device if have. - - @param PlatformConsole Predefined platform default console device arr= ay. - - @retval EFI_SUCCESS Success connect at least one ConIn and ConOut - device, there must have one ConOut device is - active vga device. - - @retval EFI_STATUS Return the status of - BdsLibConnectAllDefaultConsoles () - -**/ -EFI_STATUS -PlatformBdsConnectConsole ( - IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole -) -{ - EFI_STATUS Status; - UINTN Index; - EFI_DEVICE_PATH_PROTOCOL *VarConout; - EFI_DEVICE_PATH_PROTOCOL *VarConin; - UINTN DevicePathSize; - - UpdateConsoleResolution(); - - Index =3D 0; - Status =3D EFI_SUCCESS; - DevicePathSize =3D 0; - VarConout =3D BdsLibGetVariableAndSize ( - L"ConOut", - &gEfiGlobalVariableGuid, - &DevicePathSize - ); - VarConin =3D BdsLibGetVariableAndSize ( - L"ConIn", - &gEfiGlobalVariableGuid, - &DevicePathSize - ); - if (VarConout =3D=3D NULL || VarConin =3D=3D NULL) { - // - // Have chance to connect the platform default console, - // the platform default console is the minimum device group - // the platform should support - // - while (PlatformConsole[Index].DevicePath !=3D NULL) { - - // - // Update the console variable with the connect type - // - if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) =3D=3D CONSOLE= _IN) { - BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].Devi= cePath, NULL); - } - - if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) =3D=3D CONSOL= E_OUT) { - BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].Dev= icePath, NULL); - } - - if ((PlatformConsole[Index].ConnectType & STD_ERROR) =3D=3D STD_ERRO= R) { - BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].Dev= icePath, NULL); - } - - Index ++; - } - } - - // - // Make sure we have at least one active VGA, and have the right - // active VGA in console variable - // - Status =3D PlatformBdsForceActiveVga (); - if (EFI_ERROR (Status)) { - return Status; - } - - DEBUG ((EFI_D_INFO, "DISPLAY INIT DONE\n")); - - // - // Connect the all the default console with current console variable - // - Status =3D BdsLibConnectAllDefaultConsoles (); - if (EFI_ERROR (Status)) { - return Status; - } - - return EFI_SUCCESS; -} - -/** - Connect with predefined platform connect sequence, - the OEM/IBV can customize with their own connect sequence. - - @param None. - - @retval None. - -**/ -VOID -PlatformBdsConnectSequence ( - VOID - ) -{ - UINTN Index; - - Index =3D 0; - - // - // Here we can get the customized platform connect sequence - // Notes: we can connect with new variable which record the - // last time boots connect device path sequence - // - while (gPlatformConnectSequence[Index] !=3D NULL) { - - // - // Build the platform boot option - // - BdsLibConnectDevicePath (gPlatformConnectSequence[Index]); - Index ++; - } - - // - // Just use the simple policy to connect all devices - // There should be no difference between debug tip and release tip, or i= t will be extremely hard to debug. - // - // There is case that IdeController driver will write boot script in dri= ver model Start() function. It will be rejected by boot script save. - // It is only found when DEBUG disabled, because we are using BdsLibConn= ectAll() when DEBUG enabled. - // - // So we use BdsLibConnectAll() here to make sure IdeController.Start() = is invoked before InstallReadyToLock(). - // We may also consider to connect SataController only later if needed. - // - BdsLibConnectAll (); -} - -/** - - Load the predefined driver option, OEM/IBV can customize this - to load their own drivers - - @param BdsDriverLists The header of the driver option link list. - - @retval None. - -**/ -VOID -PlatformBdsGetDriverOption ( - IN OUT LIST_ENTRY *BdsDriverLists - ) -{ - UINTN Index; - - Index =3D 0; - - // - // Here we can get the customized platform driver option - // - while (gPlatformDriverOption[Index] !=3D NULL) { - - // - // Build the platform boot option - // - BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index],= NULL, L"DriverOrder"); - Index ++; - } - -} - -/** - This function is used for some critical time if the the system - have no any boot option, and there is no time out for user to add - the new boot option. This can also treat as the platform default - boot option. - - @param BdsBootOptionList The header of the boot option link list. - - @retval None. - -**/ -VOID -PlatformBdsPredictBootOption ( - IN OUT LIST_ENTRY *BdsBootOptionList - ) -{ - UINTN Index; - - Index =3D 0; - - // - // Here give chance to get platform boot option data - // - while (gPlatformBootOption[Index] !=3D NULL) { - - // - // Build the platform boot option - // - BdsLibRegisterNewOption (BdsBootOptionList, gPlatformBootOption[Index]= , NULL, L"BootOrder"); - Index ++; - } -} - -/** - Perform the platform diagnostic, such like test memory. OEM/IBV also - can customize this fuction to support specific platform diagnostic. - - @param MemoryTestLevel The memory test intensive level - @param QuietBoot Indicate if need to enable the quiet boot - @param BaseMemoryTest A pointer to BdsMemoryTest() - - @retval None. - -**/ -VOID -PlatformBdsDiagnostics ( - IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel, - IN BOOLEAN QuietBoot, - IN BASEM_MEMORY_TEST BaseMemoryTest - ) -{ - EFI_STATUS Status; - - // - // Here we can decide if we need to show - // the diagnostics screen - // Notes: this quiet boot code should be remove - // from the graphic lib - // - if (QuietBoot) { - EnableQuietBoot (PcdGetPtr(PcdLogoFile)); - - // - // Perform system diagnostic - // - Status =3D BaseMemoryTest (MemoryTestLevel); - if (EFI_ERROR (Status)) { - DisableQuietBoot (); - } - - return; - } - - // - // Perform system diagnostic - // - Status =3D BaseMemoryTest (MemoryTestLevel); -} - - -/** - For EFI boot option, BDS separate them as six types: - 1. Network - The boot option points to the SimpleNetworkProtocol device. - Bds will try to automatically create this type boot option = when enumerate. - 2. Shell - The boot option points to internal flash shell. - Bds will try to automatically create this type boot option = when enumerate. - 3. Removable BlockIo - The boot option only points to the removable= media - device, like USB flash disk, DVD, Floppy etc. - These device should contain a *removable* bl= ockIo - protocol in their device handle. - Bds will try to automatically create this ty= pe boot option - when enumerate. - 4. Fixed BlockIo - The boot option only points to a Fixed block= Io device, - like HardDisk. - These device should contain a *fixed* blockIo - protocol in their device handle. - BDS will skip fixed blockIo devices, and NOT - automatically create boot option for them. B= ut BDS - will help to delete those fixed blockIo boot= option, - whose description rule conflict with other a= uto-created - boot options. - 5. Non-BlockIo Simplefile - The boot option points to a device whose han= dle - has SimpleFileSystem Protocol, but has no bl= ockio - protocol. These devices do not offer blockIo - protocol, but BDS still can get the - \EFI\BOOT\boot{machinename}.EFI by SimpleFil= eSystem - Protocol. - 6. File - The boot option points to a file. These boot options are us= ually - created by user manually or OS loader. BDS will not delete = or modify - these boot options. - - This function will enumerate all possible boot device in the system, and - automatically create boot options for Network, Shell, Removable BlockIo, - and Non-BlockIo Simplefile devices. - It will only execute once of every boot. - - @param BdsBootOptionList The header of the link list which indexed= all - current boot options - - @retval EFI_SUCCESS Finished all the boot device enumerate an= d create - the boot option base on that boot device - - @retval EFI_OUT_OF_RESOURCES Failed to enumerate the boot device and c= reate the boot option list -**/ -EFI_STATUS -EFIAPI -PlatformBdsLibEnumerateAllBootOption ( - IN OUT LIST_ENTRY *BdsBootOptionList - ) -{ - EFI_STATUS Status; - UINT16 FloppyNumber; - UINT16 HarddriveNumber; - UINT16 CdromNumber; - UINT16 UsbNumber; - UINT16 MiscNumber; - UINT16 ScsiNumber; - UINT16 NonBlockNumber; - UINTN NumberBlockIoHandles; - EFI_HANDLE *BlockIoHandles; - EFI_BLOCK_IO_PROTOCOL *BlkIo; - BOOLEAN Removable[2]; - UINTN RemovableIndex; - UINTN Index; - UINTN NumOfLoadFileHandles; - EFI_HANDLE *LoadFileHandles; - UINTN FvHandleCount; - EFI_HANDLE *FvHandleBuffer; - EFI_FV_FILETYPE Type; - UINTN Size; - EFI_FV_FILE_ATTRIBUTES Attributes; - UINT32 AuthenticationStatus; - EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - UINTN DevicePathType; - CHAR16 Buffer[40]; - EFI_HANDLE *FileSystemHandles; - UINTN NumberFileSystemHandles; - BOOLEAN NeedDelete; - EFI_IMAGE_DOS_HEADER DosHeader; - CHAR8 *PlatLang; - CHAR8 *LastLang; - EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData; - EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; - CHAR16 *MacStr; - CHAR16 *IPverStr; - EFI_HANDLE *NetworkHandles; - UINTN BufferSize; - - FloppyNumber =3D 0; - HarddriveNumber =3D 0; - CdromNumber =3D 0; - UsbNumber =3D 0; - MiscNumber =3D 0; - ScsiNumber =3D 0; - PlatLang =3D NULL; - LastLang =3D NULL; - ZeroMem (Buffer, sizeof (Buffer)); - - // - // If the boot device enumerate happened, just get the boot - // device from the boot order variable - // - if (mEnumBootDevice) { - GetVariable2 (LAST_ENUM_LANGUAGE_VARIABLE_NAME, &gLastEnumLangGuid, (V= OID**)&LastLang, NULL); - GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatLang, NULL); - ASSERT (PlatLang !=3D NULL); - if ((LastLang !=3D NULL) && (AsciiStrCmp (LastLang, PlatLang) =3D=3D 0= )) { - Status =3D BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder"= ); - FreePool (LastLang); - FreePool (PlatLang); - return Status; - } else { - Status =3D gRT->SetVariable ( - LAST_ENUM_LANGUAGE_VARIABLE_NAME, - &gLastEnumLangGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, - AsciiStrSize (PlatLang), - PlatLang - ); - // - // Failure to set the variable only impacts the performance next tim= e enumerating the boot options. - // - - if (LastLang !=3D NULL) { - FreePool (LastLang); - } - FreePool (PlatLang); - } - } - - // - // Notes: this dirty code is to get the legacy boot option from the - // BBS table and create to variable as the EFI boot option, it should - // be removed after the CSM can provide legacy boot option directly - // - REFRESH_LEGACY_BOOT_OPTIONS; - - // - // Delete invalid boot option - // - BdsDeleteAllInvalidEfiBootOption (); - - // - // Parse removable media followed by fixed media. - // The Removable[] array is used by the for-loop below to create removab= le media boot options=20 - // at first, and then to create fixed media boot options. - // - Removable[0] =3D FALSE; - Removable[1] =3D TRUE; - - gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiBlockIoProtocolGuid, - NULL, - &NumberBlockIoHandles, - &BlockIoHandles - ); - - for (RemovableIndex =3D 0; RemovableIndex < 2; RemovableIndex++) { - for (Index =3D 0; Index < NumberBlockIoHandles; Index++) { - Status =3D gBS->HandleProtocol ( - BlockIoHandles[Index], - &gEfiBlockIoProtocolGuid, - (VOID **) &BlkIo - ); - // - // skip the logical partition - // - if (EFI_ERROR (Status) || BlkIo->Media->LogicalPartition) { - continue; - } - - // - // firstly fixed block io then the removable block io - // - if (BlkIo->Media->RemovableMedia =3D=3D Removable[RemovableIndex]) { - continue; - } - DevicePath =3D DevicePathFromHandle (BlockIoHandles[Index]); - DevicePathType =3D BdsGetBootTypeFromDevicePath (DevicePath); - - switch (DevicePathType) { - case BDS_EFI_ACPI_FLOPPY_BOOT: - if (FloppyNumber !=3D 0) { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStrin= gById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)), FloppyNumber); - } else { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringBy= Id (STRING_TOKEN (STR_DESCRIPTION_FLOPPY))); - } - BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionL= ist, Buffer); - FloppyNumber++; - break; - - // - // Assume a removable SATA device should be the DVD/CD device, a fix= ed SATA device should be the Hard Drive device. - // - case BDS_EFI_MESSAGE_ATAPI_BOOT: - case BDS_EFI_MESSAGE_SATA_BOOT: - if (BlkIo->Media->RemovableMedia) { - if (CdromNumber !=3D 0) { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStr= ingById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)), CdromNumber); - } else { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetString= ById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD))); - } - CdromNumber++; - } else { - if (HarddriveNumber !=3D 0) { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStr= ingById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE)), HarddriveNumber); - } else { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetString= ById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE))); - } - HarddriveNumber++; - } - DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Buffer: %S\n", Buffer)); - BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionL= ist, Buffer); - break; - - case BDS_EFI_MESSAGE_USB_DEVICE_BOOT: - if (UsbNumber !=3D 0) { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStrin= gById (STRING_TOKEN (STR_DESCRIPTION_USB)), UsbNumber); - } else { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringBy= Id (STRING_TOKEN (STR_DESCRIPTION_USB))); - } - BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionL= ist, Buffer); - UsbNumber++; - break; - - case BDS_EFI_MESSAGE_SCSI_BOOT: - if (ScsiNumber !=3D 0) { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStrin= gById (STRING_TOKEN (STR_DESCRIPTION_SCSI)), ScsiNumber); - } else { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringBy= Id (STRING_TOKEN (STR_DESCRIPTION_SCSI))); - } - BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionL= ist, Buffer); - ScsiNumber++; - break; - - case BDS_EFI_MESSAGE_MISC_BOOT: - default: - if (MiscNumber !=3D 0) { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStrin= gById (STRING_TOKEN (STR_DESCRIPTION_MISC)), MiscNumber); - } else { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringBy= Id (STRING_TOKEN (STR_DESCRIPTION_MISC))); - } - BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionL= ist, Buffer); - MiscNumber++; - break; - } - } - } - - if (NumberBlockIoHandles !=3D 0) { - FreePool (BlockIoHandles); - } - - // - // If there is simple file protocol which does not consume block Io prot= ocol, create a boot option for it here. - // - NonBlockNumber =3D 0; - gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiSimpleFileSystemProtocolGuid, - NULL, - &NumberFileSystemHandles, - &FileSystemHandles - ); - for (Index =3D 0; Index < NumberFileSystemHandles; Index++) { - Status =3D gBS->HandleProtocol ( - FileSystemHandles[Index], - &gEfiBlockIoProtocolGuid, - (VOID **) &BlkIo - ); - if (!EFI_ERROR (Status)) { - // - // Skip if the file system handle supports a BlkIo protocol, - // - continue; - } - - // - // Do the removable Media thing. \EFI\BOOT\boot{machinename}.EFI - // machinename is ia32, ia64, x64, ... - // - Hdr.Union =3D &HdrData; - NeedDelete =3D TRUE; - Status =3D BdsLibGetImageHeader ( - FileSystemHandles[Index], - EFI_REMOVABLE_MEDIA_FILE_NAME, - &DosHeader, - Hdr - ); - if (!EFI_ERROR (Status) && - EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) && - Hdr.Pe32->OptionalHeader.Subsystem =3D=3D EFI_IMAGE_SUBSYSTEM_EFI_= APPLICATION) { - NeedDelete =3D FALSE; - } - - if (NeedDelete) { - // - // No such file or the file is not a EFI application, delete this bo= ot option - // - BdsLibDeleteOptionFromHandle (FileSystemHandles[Index]); - } else { - if (NonBlockNumber !=3D 0) { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringB= yId (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)), NonBlockNumber); - } else { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById= (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK))); - } - BdsLibBuildOptionFromHandle (FileSystemHandles[Index], BdsBootOption= List, Buffer); - NonBlockNumber++; - } - } - - if (NumberFileSystemHandles !=3D 0) { - FreePool (FileSystemHandles); - } - - // - // Check if we have on flash shell - // - gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiFirmwareVolume2ProtocolGuid, - NULL, - &FvHandleCount, - &FvHandleBuffer - ); - for (Index =3D 0; Index < FvHandleCount; Index++) { - gBS->HandleProtocol ( - FvHandleBuffer[Index], - &gEfiFirmwareVolume2ProtocolGuid, - (VOID **) &Fv - ); - - Status =3D Fv->ReadFile ( - Fv, - &gUefiShellFileGuid, - NULL, - &Size, - &Type, - &Attributes, - &AuthenticationStatus - ); - if (EFI_ERROR (Status)) { - // - // Skip if no shell file in the FV - // - continue; - } - // - // Build the shell boot option - // - BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList); - } - - if (FvHandleCount !=3D 0) { - FreePool (FvHandleBuffer); - } - - // - // Parse Network Boot Device - // - NumOfLoadFileHandles =3D 0; - // - // Search Load File protocol for PXE boot option. - // - gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiLoadFileProtocolGuid, - NULL, - &NumOfLoadFileHandles, - &LoadFileHandles - ); - - for (Index =3D 0; Index < NumOfLoadFileHandles; Index++) { - -// -//Locate EFI_DEVICE_PATH_PROTOCOL to dynamically get IPv4/IPv6 protocol in= formation. -// - - Status =3D gBS->HandleProtocol ( - LoadFileHandles[Index], - &gEfiDevicePathProtocolGuid, - (VOID **) &DevicePath - ); - =20 - ASSERT_EFI_ERROR (Status); - - while (!IsDevicePathEnd (DevicePath)) { - if ((DevicePath->Type =3D=3D MESSAGING_DEVICE_PATH) && - (DevicePath->SubType =3D=3D MSG_IPv4_DP)) { - - // - //Get handle infomation - // - BufferSize =3D 0; - NetworkHandles =3D NULL; - Status =3D gBS->LocateHandle ( - ByProtocol,=20 - &gEfiSimpleNetworkProtocolGuid, - NULL, - &BufferSize, - NetworkHandles - ); - - if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { - NetworkHandles =3D AllocateZeroPool(BufferSize); - if (NetworkHandles =3D=3D NULL) { - return (EFI_OUT_OF_RESOURCES); - } - Status =3D gBS->LocateHandle( - ByProtocol, - &gEfiSimpleNetworkProtocolGuid, - NULL, - &BufferSize, - NetworkHandles - ); - } - =20 - // - //Get the MAC string - // - Status =3D NetLibGetMacString ( - *NetworkHandles, - NULL, - &MacStr - ); - if (EFI_ERROR (Status)) {=09 - return Status; - } - IPverStr =3D L" IPv4"; - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%s%s", BdsLibGetStringById (= STRING_TOKEN (STR_DESCRIPTION_NETWORK)),MacStr,IPverStr); - break; - } - if((DevicePath->Type =3D=3D MESSAGING_DEVICE_PATH) && - (DevicePath->SubType =3D=3D MSG_IPv6_DP)) { - - // - //Get handle infomation - // - BufferSize =3D 0; - NetworkHandles =3D NULL; - Status =3D gBS->LocateHandle ( - ByProtocol,=20 - &gEfiSimpleNetworkProtocolGuid, - NULL, - &BufferSize, - NetworkHandles - ); - - if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { - NetworkHandles =3D AllocateZeroPool(BufferSize); - if (NetworkHandles =3D=3D NULL) { - return (EFI_OUT_OF_RESOURCES); - } - Status =3D gBS->LocateHandle( - ByProtocol, - &gEfiSimpleNetworkProtocolGuid, - NULL, - &BufferSize, - NetworkHandles - ); - } - =20 - // - //Get the MAC string - // - Status =3D NetLibGetMacString ( - *NetworkHandles, - NULL, - &MacStr - ); - if (EFI_ERROR (Status)) {=09 - return Status; - } - IPverStr =3D L" IPv6"; - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%s%s", BdsLibGetStringBy= Id (STRING_TOKEN (STR_DESCRIPTION_NETWORK)),MacStr,IPverStr); - break; - } - DevicePath =3D NextDevicePathNode (DevicePath); - } - =20 - BdsLibBuildOptionFromHandle (LoadFileHandles[Index], BdsBootOptionList= , Buffer); - } - - if (NumOfLoadFileHandles !=3D 0) { - FreePool (LoadFileHandles); - } - - // - // Check if we have on flash shell - // - /* gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiFirmwareVolume2ProtocolGuid, - NULL, - &FvHandleCount, - &FvHandleBuffer - ); - for (Index =3D 0; Index < FvHandleCount; Index++) { - gBS->HandleProtocol ( - FvHandleBuffer[Index], - &gEfiFirmwareVolume2ProtocolGuid, - (VOID **) &Fv - ); - - Status =3D Fv->ReadFile ( - Fv, - &gUefiShellFileGuid, - NULL, - &Size, - &Type, - &Attributes, - &AuthenticationStatus - ); - if (EFI_ERROR (Status)) { - // - // Skip if no shell file in the FV - // - continue; - } - // - // Build the shell boot option - // - BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList); - } - - if (FvHandleCount !=3D 0) { - FreePool (FvHandleBuffer); - } */ - =20 - // - // Make sure every boot only have one time - // boot device enumerate - // - Status =3D BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder"); - mEnumBootDevice =3D TRUE; - - return Status; -}=20 - - - -/** - - The function will execute with as the platform policy, current policy - is driven by boot mode. IBV/OEM can customize this code for their specif= ic - policy action. - - @param DriverOptionList - The header of the driver option link list - @param BootOptionList - The header of the boot option link list - @param ProcessCapsules - A pointer to ProcessCapsules() - @param BaseMemoryTest - A pointer to BaseMemoryTest() - - @retval None. - -**/ -VOID -EFIAPI -PlatformBdsPolicyBehavior ( - IN OUT LIST_ENTRY *DriverOptionList, - IN OUT LIST_ENTRY *BootOptionList, - IN PROCESS_CAPSULES BdsProcessCapsules, - IN BASEM_MEMORY_TEST BaseMemoryTest - ) -{ - EFI_STATUS Status; - UINT16 Timeout; - EFI_BOOT_MODE BootMode; - BOOLEAN DeferredImageExist; - UINTN Index; - SYSTEM_CONFIGURATION SystemConfiguration; - UINTN VarSize; - PLATFORM_PCI_DEVICE_PATH *EmmcBootDevPath; - EFI_GLOBAL_NVS_AREA_PROTOCOL *GlobalNvsArea; - EFI_HANDLE FvProtocolHandle; - UINTN HandleCount; - EFI_HANDLE *HandleBuffer; - UINTN Index1; - UINTN SataPciRegBase =3D 0; - UINT16 SataModeSelect =3D 0; - VOID *RegistrationExitPmAuth =3D NULL; - EFI_EVENT Event; - BOOLEAN IsFirstBoot; - UINT16 *BootOrder; - UINTN BootOrderSize; - ESRT_MANAGEMENT_PROTOCOL *EsrtManagement; - - Timeout =3D PcdGet16 (PcdPlatformBootTimeOut); - if (Timeout > 10 ) { - //we think the Timeout variable is corrupted - Timeout =3D 10; - } - - VarSize =3D sizeof(SYSTEM_CONFIGURATION); - Status =3D gRT->GetVariable( - NORMAL_SETUP_NAME, - &gEfiNormalSetupGuid, - NULL, - &VarSize, - &SystemConfiguration - ); - - if (EFI_ERROR (Status) || VarSize !=3D sizeof(SYSTEM_CONFIGURATION)) { - //The setup variable is corrupted - VarSize =3D sizeof(SYSTEM_CONFIGURATION); - Status =3D gRT->GetVariable( - L"SetupRecovery", - &gEfiNormalSetupGuid, - NULL, - &VarSize, - &SystemConfiguration - ); - ASSERT_EFI_ERROR (Status); - } - - // - // Load the driver option as the driver option list - // - PlatformBdsGetDriverOption (DriverOptionList); - - // - // Get current Boot Mode - // - BootMode =3D GetBootModeHob(); - - // - // No deferred images exist by default - // - DeferredImageExist =3D FALSE; - if ((BootMode !=3D BOOT_WITH_MINIMAL_CONFIGURATION) && (PcdGet32(PcdFlas= hFvShellSize) > 0)){ - gDS->ProcessFirmwareVolume ( - (VOID *)(UINTN)PcdGet32(PcdFlashFvShellBase), - PcdGet32(PcdFlashFvShellSize), - &FvProtocolHandle - ); - } - - if (SystemConfiguration.FastBoot =3D=3D 1) { - BootOrder =3D BdsLibGetVariableAndSize ( - L"BootOrder", - &gEfiGlobalVariableGuid, - &BootOrderSize - ); - if ((BootOrder !=3D NULL) && (BootMode !=3D BOOT_ON_FLASH_UPDATE)) { - // - // BootOrder exist, it means system has boot before. We can do fast = boot. - // - BootMode =3D BOOT_WITH_MINIMAL_CONFIGURATION; - } - } - - - // - // Use eMMC to boot OS and turn on AHCI, when SATA HDD is diconnected, - // SATA AHCI CTLR device will show yellow bang, implement this solution = to solve it. - // - SataPciRegBase =3D MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, 0, 0= ); - SataModeSelect =3D MmioRead16 (SataPciRegBase + R_PCH_SATA_MAP) & B_PCH= _SATA_MAP_SMS_MASK; - Status =3D EFI_SUCCESS; - if (SataModeSelect !=3D V_PCH_SATA_MAP_SMS_IDE) { - Status =3D gBS->CreateEvent ( - EVT_NOTIFY_SIGNAL, - TPL_CALLBACK, - DisableAhciCtlr, - &SataPciRegBase, - &Event - ); - if (!EFI_ERROR (Status)) { - Status =3D gBS->RegisterProtocolNotify ( - &gExitPmAuthProtocolGuid, - Event, - &RegistrationExitPmAuth - ); - } - } - - Status =3D gBS->LocateProtocol(&gEsrtManagementProtocolGuid, NULL, (VOID= **)&EsrtManagement); - if (EFI_ERROR(Status)) { - EsrtManagement =3D NULL; - } - - DEBUG ((DEBUG_INFO, "BDS: BootMode=3D%02x\n", BootMode)); - - switch (BootMode) { - - case BOOT_WITH_MINIMAL_CONFIGURATION: - PlatformBdsInitHotKeyEvent (); - PlatformBdsConnectSimpleConsole (gPlatformSimpleConsole); - - - // - // Check to see if it's needed to dispatch more DXE drivers. - // - for (Index =3D 0; Index < sizeof(ConnectDriverTable)/sizeof(EFI_GUID *= ); Index++) { - Status =3D gBS->LocateHandleBuffer ( - ByProtocol, - ConnectDriverTable[Index], - NULL, - &HandleCount, - &HandleBuffer - ); - if (!EFI_ERROR (Status)) { - for (Index1 =3D 0; Index1 < HandleCount; Index1++) { - gBS->ConnectController ( - HandleBuffer[Index1], - NULL, - NULL, - TRUE - ); - } - } - - if (HandleBuffer !=3D NULL) { - FreePool (HandleBuffer); - } - - gDS->Dispatch (); - } - - // - // Locate the Global NVS Protocol. - // - Status =3D gBS->LocateProtocol ( - &gEfiGlobalNvsAreaProtocolGuid, - NULL, - (void **)&GlobalNvsArea - ); - if (GlobalNvsArea->Area->emmcVersion =3D=3D 0){ - EmmcBootDevPath =3D (PLATFORM_PCI_DEVICE_PATH *)gPlatformSimpleBootO= ption[0]; - EmmcBootDevPath->PciDevice.Device =3D 0x10; - } - - // - // Connect boot device here to give time to read keyboard. - // - BdsLibConnectDevicePath (gPlatformSimpleBootOption[0]); - - // - // This is a workround for dectecting hotkey from USB keyboard. - // - gBS->Stall(KEYBOARD_TIMER_INTERVAL); - - if (mHotKeyTimerEvent !=3D NULL) { - gBS->SetTimer ( - mHotKeyTimerEvent, - TimerCancel, - 0 - ); - gBS->CloseEvent (mHotKeyTimerEvent); - mHotKeyTimerEvent =3D NULL; - } - if (mHotKeyPressed) { - // - // Skip show progress count down - // - Timeout =3D 0xFFFF; - goto FULL_CONFIGURATION; - } - - EnableQuietBoot (PcdGetPtr(PcdLogoFile)); - if (!SystemConfiguration.QuietBoot) { - PlatformBdsDiagnostics (IGNORE, FALSE, BaseMemoryTest); - } - - - #ifdef TPM_ENABLED - TcgPhysicalPresenceLibProcessRequest(); - #endif - - if (EsrtManagement !=3D NULL) { - EsrtManagement->LockEsrtRepository(); - } - - // - // Close boot script and install ready to lock - // - InstallReadyToLock (); - - // - // Give one chance to enter the setup if we - // select Gummiboot "Reboot Into Firmware Interface" and Fast Boot is = enabled. - // - BootIntoFirmwareInterface(); - break; - - case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES: - - // - // In no-configuration boot mode, we can connect the - // console directly. - // - BdsLibConnectAllDefaultConsoles (); - PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest); - - // - // Perform some platform specific connect sequence - // - PlatformBdsConnectSequence (); - - // - // As console is ready, perform user identification again. - // - if (mCurrentUser =3D=3D NULL) { - PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist); - if (DeferredImageExist) { - // - // After user authentication, the deferred drivers was loaded agai= n. - // Here, need to ensure the deferred images are connected. - // - BdsLibConnectAllDefaultConsoles (); - PlatformBdsConnectSequence (); - } - } - - if (EsrtManagement !=3D NULL) { - EsrtManagement->LockEsrtRepository(); - } - - // - // Close boot script and install ready to lock - // - InstallReadyToLock (); - - // - // Notes: current time out =3D 0 can not enter the - // front page - // - PlatformBdsEnterFrontPageWithHotKey (Timeout, FALSE); - - // - // Check the boot option with the boot option list - // - BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder"); - break; - - case BOOT_ON_FLASH_UPDATE: - - // - // Boot with the specific configuration - // - PlatformBdsConnectConsole (gPlatformConsole); - PlatformBdsDiagnostics (EXTENSIVE, TRUE, BaseMemoryTest); - - DEBUG((DEBUG_INFO, "ProcessCapsules Before EndOfDxe......\n")); - ProcessCapsules (); - DEBUG((DEBUG_INFO, "ProcessCapsules Done\n")); - - // - // Close boot script and install ready to lock - // - InstallReadyToLock (); - - BdsLibConnectAll (); - - // - // Perform user identification - // - if (mCurrentUser =3D=3D NULL) { - PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist); - if (DeferredImageExist) { - // - // After user authentication, the deferred drivers was loaded agai= n. - // Here, need to ensure the deferred images are connected. - // - BdsLibConnectAll (); - } - } - - if (EsrtManagement !=3D NULL) { - EsrtManagement->SyncEsrtFmp(); - } - - DEBUG((DEBUG_INFO, "ProcessCapsules After ConnectAll......\n")); - ProcessCapsules(); - DEBUG((DEBUG_INFO, "ProcessCapsules Done\n")); - break; - - case BOOT_IN_RECOVERY_MODE: - - // - // In recovery mode, just connect platform console - // and show up the front page - // - PlatformBdsConnectConsole (gPlatformConsole); - PlatformBdsDiagnostics (EXTENSIVE, FALSE, BaseMemoryTest); - BdsLibConnectAll (); - - // - // Perform user identification - // - if (mCurrentUser =3D=3D NULL) { - PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist); - if (DeferredImageExist) { - // - // After user authentication, the deferred drivers was loaded agai= n. - // Here, need to ensure the deferred drivers are connected. - // - BdsLibConnectAll (); - } - } - - // - // Close boot script and install ready to lock - // - InstallReadyToLock (); - - // - // In recovery boot mode, we still enter to the - // frong page now - // - PlatformBdsEnterFrontPageWithHotKey (Timeout, FALSE); - break; - -FULL_CONFIGURATION: - case BOOT_WITH_FULL_CONFIGURATION: - case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS: - case BOOT_WITH_DEFAULT_SETTINGS: - default: - - // - // Connect platform console - // - Status =3D PlatformBdsConnectConsole (gPlatformConsole); - if (EFI_ERROR (Status)) { - - // - // Here OEM/IBV can customize with defined action - // - PlatformBdsNoConsoleAction (); - } - - // - // Chenyunh[TODO]: This is Workgroud to show the fs for uSDcard, - // Need to root cause this issue. - // - DEBUG ((DEBUG_ERROR, "Start to reconnect all driver.\n")); - BdsLibDisconnectAllEfi(); - BdsLibConnectAll (); - DEBUG ((DEBUG_ERROR, "End to reconnect all driver.\n")); - - // - // Perform some platform specific connect sequence - // - PlatformBdsConnectSequence (); - EnableQuietBoot (PcdGetPtr(PcdLogoFile)); - if (!SystemConfiguration.QuietBoot) { - PlatformBdsDiagnostics (IGNORE, FALSE, BaseMemoryTest); - } - - // - // Do a pre-delay so Hard Disk can spin up and see more logo. - // - gBS->Stall(SystemConfiguration.HddPredelay * 1000000); - - // - // Perform user identification - // - if (mCurrentUser =3D=3D NULL) { - PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist); - if (DeferredImageExist) { - // - // After user authentication, the deferred drivers was loaded agai= n. - // Here, need to ensure the deferred drivers are connected. - // - Status =3D PlatformBdsConnectConsole (gPlatformConsole); - if (EFI_ERROR (Status)) { - PlatformBdsNoConsoleAction (); - } - PlatformBdsConnectSequence (); - } - } - #ifdef TPM_ENABLED - TcgPhysicalPresenceLibProcessRequest(); - #endif - - if (EsrtManagement !=3D NULL) { - EsrtManagement->SyncEsrtFmp(); - } - // - // Close boot script and install ready to lock - // - InstallReadyToLock (); - - // - // Here we have enough time to do the enumeration of boot device - // - PlatformBdsLibEnumerateAllBootOption (BootOptionList); - - // - // Give one chance to enter the setup if we - // have the time out - // - PlatformBdsEnterFrontPageWithHotKey (Timeout, FALSE); - - // - // Give one chance to enter the setup if we - // select Gummiboot "Reboot Into Firmware Interface" - // - BootIntoFirmwareInterface(); - - // - // In default boot mode, always find all boot - // option and do enumerate all the default boot option - // - if (Timeout =3D=3D 0) { - BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder"); - if (IsListEmpty(BootOptionList)) { - PlatformBdsPredictBootOption (BootOptionList); - } - - return; - } - - - break; - } - - - IsFirstBoot =3D PcdGetBool(PcdBootState); - if (IsFirstBoot) { - PcdSetBool(PcdBootState, FALSE); - } - return; - -} - -/** - Hook point after a boot attempt succeeds. We don't expect a boot option = to - return, so the UEFI 2.0 specification defines that you will default to an - interactive mode and stop processing the BootOrder list in this case. Th= is - is alos a platform implementation and can be customized by IBV/OEM. - - @param Option Pointer to Boot Option that succeeded to boot. - - @retval None. - -**/ -VOID -EFIAPI -PlatformBdsBootSuccess ( - IN BDS_COMMON_OPTION *Option - ) -{ - CHAR16 *TmpStr; - - // - // If Boot returned with EFI_SUCCESS and there is not in the boot device - // select loop then we need to pop up a UI and wait for user input. - // - TmpStr =3D Option->StatusString; - if (TmpStr !=3D NULL) { - BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r"= , NULL); - FreePool(TmpStr); - } -} - -/** - Hook point after a boot attempt fails. - - @param Option - Pointer to Boot Option that failed to boot. - @param Status - Status returned from failed boot. - @param ExitData - Exit data returned from failed boot. - @param ExitDataSize - Exit data size returned from failed boot. - - @retval None. - -**/ -VOID -EFIAPI -PlatformBdsBootFail ( - IN BDS_COMMON_OPTION *Option, - IN EFI_STATUS Status, - IN CHAR16 *ExitData, - IN UINTN ExitDataSize - ) -{ - CHAR16 *TmpStr; - EFI_HANDLE FvProtocolHandle; - - // - // If Boot returned with failed status then we need to pop up a UI and w= ait - // for user input. - // - TmpStr =3D Option->StatusString; - if (TmpStr !=3D NULL) { - BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r"= , NULL); - FreePool(TmpStr); - } - if (PcdGet32(PcdFlashFvShellSize) > 0){ - gDS->ProcessFirmwareVolume ( - (VOID *)(UINTN)PcdGet32(PcdFlashFvShellBase), - PcdGet32(PcdFlashFvShellSize), - &FvProtocolHandle - ); - } - PlatformBdsConnectSequence (); -} - -/** - This function is remained for IBV/OEM to do some platform action, - if there no console device can be connected. - - @param None. - - @retval EFI_SUCCESS Direct return success now. - -**/ -EFI_STATUS -PlatformBdsNoConsoleAction ( - VOID - ) -{ - return EFI_SUCCESS; -} - -/** - This function locks the block - - @param Base The base address flash region to be locked. - -**/ -VOID -BdsLockFv ( - IN EFI_PHYSICAL_ADDRESS Base - ) -{ - EFI_FV_BLOCK_MAP_ENTRY *BlockMap; - EFI_FIRMWARE_VOLUME_HEADER *FvHeader; - EFI_PHYSICAL_ADDRESS BaseAddress; - UINT32 BlockLength; - UINTN Index; - - BaseAddress =3D Base - 0x400000 + 2; - FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) (Base)); - BlockMap =3D &(FvHeader->BlockMap[0]); - - while ((BlockMap->NumBlocks !=3D 0) && (BlockMap->Length !=3D 0)) { - BlockLength =3D BlockMap->Length; - for (Index =3D 0; Index < BlockMap->NumBlocks; Index++) { - MmioOr8 ((UINTN) BaseAddress, 0x03); - BaseAddress +=3D BlockLength; - } - BlockMap++; - } -} - -VOID -EFIAPI -PlatformBdsLockNonUpdatableFlash ( - VOID - ) -{ - EFI_PHYSICAL_ADDRESS Base; - - Base =3D (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashFvMainBase); - if (Base > 0) { - BdsLockFv (Base); - } - - Base =3D (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashFvRecoveryBase); - if (Base > 0) { - BdsLockFv (Base); - } -} - -/** - Lock the ConsoleIn device in system table. All key - presses will be ignored until the Password is typed in. The only way to - disable the password is to type it in to a ConIn device. - - @param Password Password used to lock ConIn device. - - @retval EFI_SUCCESS lock the Console In Spliter virtual handle succe= ssfully. - @retval EFI_UNSUPPORTED Password not found - -**/ -EFI_STATUS -EFIAPI -LockKeyboards ( - IN CHAR16 *Password - ) -{ - return EFI_UNSUPPORTED; -} - -/** - Connect the predefined platform default authentication devices. - - This function connects the predefined device path for authentication dev= ice, - and if the predefined device path has child device path, the child handl= e will - be connected too. But the child handle of the child will not be connecte= d. - -**/ -VOID -EFIAPI -PlatformBdsConnectAuthDevice ( - VOID - ) -{ - EFI_STATUS Status; - UINTN Index; - UINTN HandleIndex; - UINTN HandleCount; - EFI_HANDLE *HandleBuffer; - EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath; - EFI_USER_MANAGER_PROTOCOL *Manager; - - Status =3D gBS->LocateProtocol ( - &gEfiUserManagerProtocolGuid, - NULL, - (VOID **) &Manager - ); - if (EFI_ERROR (Status)) { - // - // As user manager protocol is not installed, the authentication devic= es - // should not be connected. - // - return ; - } - - Index =3D 0; - while (gUserAuthenticationDevice[Index] !=3D NULL) { - // - // Connect the platform customized device paths - // - BdsLibConnectDevicePath (gUserAuthenticationDevice[Index]); - Index++; - } - - // - // Find and connect the child device paths of the platform customized de= vice paths - // - HandleBuffer =3D NULL; - for (Index =3D 0; gUserAuthenticationDevice[Index] !=3D NULL; Index++) { - HandleCount =3D 0; - Status =3D gBS->LocateHandleBuffer ( - AllHandles, - NULL, - NULL, - &HandleCount, - &HandleBuffer - ); - ASSERT (!EFI_ERROR (Status)); - - // - // Find and connect the child device paths of gUserIdentificationDevic= e[Index] - // - for (HandleIndex =3D 0; HandleIndex < HandleCount; HandleIndex++) { - ChildDevicePath =3D NULL; - Status =3D gBS->HandleProtocol ( - HandleBuffer[HandleIndex], - &gEfiDevicePathProtocolGuid, - (VOID **) &ChildDevicePath - ); - if (EFI_ERROR (Status) || ChildDevicePath =3D=3D NULL) { - continue; - } - - if (CompareMem ( - ChildDevicePath, - gUserAuthenticationDevice[Index], - (GetDevicePathSize (gUserAuthenticationDevice[Index]) - sizeof= (EFI_DEVICE_PATH_PROTOCOL)) - ) !=3D 0) { - continue; - } - gBS->ConnectController ( - HandleBuffer[HandleIndex], - NULL, - NULL, - TRUE - ); - } - } - - if (HandleBuffer !=3D NULL) { - FreePool (HandleBuffer); - } -} - -/** - This function is to identify a user, and return whether deferred images = exist. - - @param[out] User Point to user profile handle. - @param[out] DeferredImageExist On return, points to TRUE if the deferre= d image - exist or FALSE if it did not exist. - -**/ -VOID -EFIAPI -PlatformBdsUserIdentify ( - OUT EFI_USER_PROFILE_HANDLE *User, - OUT BOOLEAN *DeferredImageExist - ) -{ - EFI_STATUS Status; - EFI_DEFERRED_IMAGE_LOAD_PROTOCOL *DeferredImage; - UINTN HandleCount; - EFI_HANDLE *HandleBuf; - UINTN Index; - UINTN DriverIndex; - EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath; - VOID *DriverImage; - UINTN ImageSize; - BOOLEAN BootOption; - - // - // Perform user identification - // - do { - Status =3D BdsLibUserIdentify (User); - } while (EFI_ERROR (Status)); - - // - // After user authentication now, try to find whether deferred image exi= sts - // - HandleCount =3D 0; - HandleBuf =3D NULL; - *DeferredImageExist =3D FALSE; - Status =3D gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiDeferredImageLoadProtocolGuid, - NULL, - &HandleCount, - &HandleBuf - ); - if (EFI_ERROR (Status)) { - return ; - } - - for (Index =3D 0; Index < HandleCount; Index++) { - Status =3D gBS->HandleProtocol ( - HandleBuf[Index], - &gEfiDeferredImageLoadProtocolGuid, - (VOID **) &DeferredImage - ); - if (!EFI_ERROR (Status)) { - // - // Find whether deferred image exists in this instance. - // - DriverIndex =3D 0; - Status =3D DeferredImage->GetImageInfo( - DeferredImage, - DriverIndex, - &ImageDevicePath, - (VOID **) &DriverImage, - &ImageSize, - &BootOption - ); - if (!EFI_ERROR (Status)) { - // - // The deferred image is found. - // - FreePool (HandleBuf); - *DeferredImageExist =3D TRUE; - return ; - } - } - } - - FreePool (HandleBuf); -} - -UINTN gHotKey =3D 0; - - -EFI_STATUS -ShowProgressHotKey ( - IN UINT16 TimeoutDefault - ) -{ - CHAR16 *TmpStr; - UINT16 TimeoutRemain; - EFI_STATUS Status; - EFI_INPUT_KEY Key; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color; - UINT32 GpioValue; - CHAR16 *TmpStr1; - CHAR16 *TmpStr2; - CHAR16 *TmpStr3; - UINTN TmpStrSize; - VOID *Buffer; - UINTN Size; - - if (TimeoutDefault =3D=3D 0) { - return EFI_TIMEOUT; - } - - gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI= _BLACK)); - =20 - if (DebugAssertEnabled()) - { - DEBUG ((EFI_D_INFO, "\n\nStart showing progress bar... Press any key t= o stop it, or press or to enter setup page! ...Zzz....\n")); - } - else - { =20 - #ifdef __GNUC__ - SerialPortWrite((UINT8 *)"\n\n>>>>Start boot option, Press or to enter setup page(5 Sec)[GCC]", 76); - #else - SerialPortWrite((UINT8 *)"\n\n>>>>Start boot option, Press or to enter setup page(5 Sec)", 71); - #endif - }=20 - SetMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff); - SetMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0); - SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff); - - TmpStr2 =3D NULL; - TmpStr3 =3D NULL; - - // - // Check if the platform is using test key. - // - Status =3D GetSectionFromAnyFv( - PcdGetPtr(PcdEdkiiRsa2048Sha256TestPublicKeyFileGuid), - EFI_SECTION_RAW, - 0, - &Buffer, - &Size - ); - if (!EFI_ERROR(Status)) { - if ((Size =3D=3D PcdGetSize(PcdRsa2048Sha256PublicKeyBuffer)) && - (CompareMem(Buffer, PcdGetPtr(PcdRsa2048Sha256PublicKeyBuffer), Si= ze) =3D=3D 0)) { - TmpStr2 =3D L"WARNING: Recovery Test Key is used.\r\n"; - if (DebugAssertEnabled()) { - DEBUG ((DEBUG_INFO, "\n\nWARNING: Recovery Test Key is used.\n")); - } else { - SerialPortWrite((UINT8 *)"\n\nWARNING: Recovery Test Key is used."= , sizeof("\n\nWARNING: Recovery Test Key is used.")); - } - PcdSetBoolS(PcdTestKeyUsed, TRUE); - } - FreePool(Buffer); - } - Status =3D GetSectionFromAnyFv( - PcdGetPtr(PcdEdkiiPkcs7TestPublicKeyFileGuid), - EFI_SECTION_RAW, - 0, - &Buffer, - &Size - ); - if (!EFI_ERROR(Status)) { - if ((Size =3D=3D PcdGetSize(PcdPkcs7CertBuffer)) && - (CompareMem(Buffer, PcdGetPtr(PcdPkcs7CertBuffer), Size) =3D=3D 0)= ) { - TmpStr3 =3D L"WARNING: Capsule Test Key is used.\r\n"; - if (DebugAssertEnabled()) { - DEBUG ((DEBUG_INFO, "\n\nWARNING: Capsule Test Key is used.\r\n")); - } else { - SerialPortWrite((UINT8 *)"\n\nWARNING: Capsule Test Key is used.",= sizeof("\n\nWARNING: Capsule Test Key is used.")); - } - PcdSetBoolS(PcdTestKeyUsed, TRUE); - } - FreePool(Buffer); - } - - // - // Clear the progress status bar first - // - TmpStr1 =3D L"Start boot option, Press or to enter setup page= .\r\n"; - TmpStrSize =3D StrSize(TmpStr1); - if (TmpStr2 !=3D NULL) { - TmpStrSize +=3D StrSize(TmpStr2); - } - if (TmpStr3 !=3D NULL) { - TmpStrSize +=3D StrSize(TmpStr3); - } - TmpStr =3D AllocatePool (TmpStrSize); - if (TmpStr =3D=3D NULL) { - TmpStr =3D TmpStr1; - } else { - StrCpyS(TmpStr, TmpStrSize/sizeof(CHAR16), TmpStr1); - if (TmpStr2 !=3D NULL) { - StrCatS(TmpStr, TmpStrSize/sizeof(CHAR16), TmpStr2); - } - if (TmpStr3 !=3D NULL) { - StrCatS(TmpStr, TmpStrSize/sizeof(CHAR16), TmpStr3); - } - } - PlatformBdsShowProgress (Foreground, Background, TmpStr, Color, 0, 0); - - TimeoutRemain =3D TimeoutDefault; - while (TimeoutRemain !=3D 0) { - if (DebugAssertEnabled()) - { - DEBUG ((EFI_D_INFO, "Showing progress bar...Remaining %d second!\n", T= imeoutRemain)); - } - else - {=09 - SerialPortWrite ((UINT8 *)".", 1); - } - Status =3D WaitForSingleEvent (gST->ConIn->WaitForKey, ONE_SECOND); - if (Status !=3D EFI_TIMEOUT) { - break; - } - TimeoutRemain--; - - // - // Show progress - // - if (TmpStr !=3D NULL) { - PlatformBdsShowProgress ( - Foreground, - Background, - TmpStr, - Color, - ((TimeoutDefault - TimeoutRemain) * 100 / TimeoutDefault), - 0 - ); - } - } - - // - // Timeout expired - // - if (TimeoutRemain =3D=3D 0) { - if (DebugAssertEnabled()) - { - } - else - {=09 - SerialPortWrite ((UINT8 *)"\r\n", 2); - } - return EFI_TIMEOUT; - } - - // - // User pressed some key - // - Status =3D gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Check Volume Up Key to enter Setup - // - GpioValue =3D MmioRead32 (IO_BASE_ADDRESS + 0x0668); // The value of GP= IOC_5 - if (((GpioValue & BIT0) =3D=3D 0) && (Key.ScanCode =3D=3D SCAN_UP)) { - gHotKey =3D 0; - return EFI_SUCCESS; - } - - if (Key.UnicodeChar =3D=3D CHAR_CARRIAGE_RETURN) { - // - // User pressed enter, equivalent to select "continue" - // - return EFI_TIMEOUT; - } - - // - //F2 -- Front Page - //F5 -- Device Manager - //F7 -- Boot Manager - // do not use F8. generally people assume it is windows safe mode key. - //F9 -- Boot order - // - DEBUG ((EFI_D_INFO, "[Key Pressed]: ScanCode 0x%x\n", Key.ScanCode)); - switch(Key.ScanCode) { - case SCAN_F2: - gHotKey =3D 0; - break; - - case SCAN_DELETE: - gHotKey =3D 0; - break; - - case SCAN_F5: - gHotKey =3D FRONT_PAGE_KEY_DEVICE_MANAGER; - break; - - case SCAN_F7: - gHotKey =3D FRONT_PAGE_KEY_BOOT_MANAGER; - break; - - case SCAN_F9: - gHotKey =3D FRONT_PAGE_KEY_BOOT_MAINTAIN; - break; - - default: - //set gHotKey to continue so that flow will not go into CallFron= tPage - gHotKey =3D FRONT_PAGE_KEY_CONTINUE; - return EFI_TIMEOUT; - break; - } - - return EFI_SUCCESS; -} - - - -/** - This function is the main entry of the platform setup entry. - The function will present the main menu of the system setup, - this is the platform reference part and can be customize. - - - @param TimeoutDefault The fault time out value before the system - continue to boot. - @param ConnectAllHappened The indicater to check if the connect all have - already happened. - -**/ -VOID -PlatformBdsEnterFrontPageWithHotKey ( - IN UINT16 TimeoutDefault, - IN BOOLEAN ConnectAllHappened - ) -{ - EFI_STATUS Status; - - EFI_STATUS LogoStatus; - EFI_BOOT_LOGO_PROTOCOL *BootLogo; - EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; - EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut; - UINTN BootTextColumn; - UINTN BootTextRow; - - GraphicsOutput =3D NULL; - SimpleTextOut =3D NULL; - - PERF_START (NULL, "BdsTimeOut", "BDS", 0); - - // - // Indicate if we need connect all in the platform setup - // - if (ConnectAllHappened) { - gConnectAllHappened =3D TRUE; - } - - if (!mModeInitialized) { - // - // After the console is ready, get current video resolution - // and text mode before launching setup at first time. - // - Status =3D gBS->HandleProtocol ( - gST->ConsoleOutHandle, - &gEfiGraphicsOutputProtocolGuid, - (VOID**)&GraphicsOutput - ); - if (EFI_ERROR (Status)) { - GraphicsOutput =3D NULL; - } - - Status =3D gBS->HandleProtocol ( - gST->ConsoleOutHandle, - &gEfiSimpleTextOutProtocolGuid, - (VOID**)&SimpleTextOut - ); - if (EFI_ERROR (Status)) { - SimpleTextOut =3D NULL; - } - - if (GraphicsOutput !=3D NULL) { - // - // Get current video resolution and text mode. - // - mBootHorizontalResolution =3D GraphicsOutput->Mode->Info->Horizontal= Resolution; - mBootVerticalResolution =3D GraphicsOutput->Mode->Info->VerticalRe= solution; - } - - if (SimpleTextOut !=3D NULL) { - Status =3D SimpleTextOut->QueryMode ( - SimpleTextOut, - SimpleTextOut->Mode->Mode, - &BootTextColumn, - &BootTextRow - ); - mBootTextModeColumn =3D (UINT32)BootTextColumn; - mBootTextModeRow =3D (UINT32)BootTextRow; - } - - // - // Get user defined text mode for setup. - // - mSetupHorizontalResolution =3D PcdGet32 (PcdSetupVideoHorizontalResolu= tion); - mSetupVerticalResolution =3D PcdGet32 (PcdSetupVideoVerticalResoluti= on); - mSetupTextModeColumn =3D PcdGet32 (PcdSetupConOutColumn); - mSetupTextModeRow =3D PcdGet32 (PcdSetupConOutRow); - - mModeInitialized =3D TRUE; - } - - if (TimeoutDefault !=3D 0xffff) { - Status =3D ShowProgressHotKey (TimeoutDefault); - - // - // Ensure screen is clear when switch Console from Graphics mode to Te= xt mode - // - gST->ConOut->EnableCursor (gST->ConOut, TRUE); - gST->ConOut->ClearScreen (gST->ConOut); - - // - // Boot Logo is corrupted, report it using Boot Logo protocol. - // - LogoStatus =3D gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (= VOID **) &BootLogo); - if (!EFI_ERROR (LogoStatus) && (BootLogo !=3D NULL)) { - BootLogo->SetBootLogo (BootLogo, NULL, 0, 0, 0, 0); - } - - if (EFI_ERROR (Status)) { - // - // Timeout or user press enter to continue - // - goto Exit; - } - } - - // - // Install BM HiiPackages.=20 - // Keep BootMaint HiiPackage, so that it can be covered by global settin= g.=20 - // - InitBMPackage (); - do { - - BdsSetConsoleMode (TRUE); - - InitializeFrontPage (FALSE); - - // - // Update Front Page strings - // - UpdateFrontPageStrings (); - - Status =3D EFI_SUCCESS; - gCallbackKey =3D 0; - if (gHotKey =3D=3D 0) { - Status =3D CallFrontPage (); - } else { - gCallbackKey =3D gHotKey; - gHotKey =3D 0; - } - - // - // If gCallbackKey is greater than 1 and less or equal to 5, - // it will launch configuration utilities. - // 2 =3D set language - // 3 =3D boot manager - // 4 =3D device manager - // 5 =3D boot maintenance manager - // - if (gCallbackKey !=3D 0) { - REPORT_STATUS_CODE ( - EFI_PROGRESS_CODE, - (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_USER_SETUP) - ); - } - - // - // Based on the key that was set, we can determine what to do - // - switch (gCallbackKey) { - // - // The first 4 entries in the Front Page are to be GUARANTEED to remai= n constant so IHV's can - // describe to their customers in documentation how to find their setu= p information (namely - // under the device manager and specific buckets) - // - // These entries consist of the Continue, Select language, Boot Manage= r, and Device Manager - // - case FRONT_PAGE_KEY_CONTINUE: - - // - // User hit continue - // - break; - - case FRONT_PAGE_KEY_LANGUAGE: - - // - // User made a language setting change - display front page again - // - break; - - case FRONT_PAGE_KEY_BOOT_MANAGER: - // - // Remove the installed BootMaint HiiPackages when exit. - // - FreeBMPackage (); - - // - // User chose to run the Boot Manager - // - CallBootManager (); - =20 - // - // Reinstall BootMaint HiiPackages after exiting from Boot Manager. - // - InitBMPackage (); - break; - - case FRONT_PAGE_KEY_DEVICE_MANAGER: - - // - // Display the Device Manager - // - do { - CallDeviceManager (); - } while (gCallbackKey =3D=3D FRONT_PAGE_KEY_DEVICE_MANAGER); - break; - - case FRONT_PAGE_KEY_BOOT_MAINTAIN: - - // - // Display the Boot Maintenance Manager - // - BdsStartBootMaint (); - break; - } - - } while (((UINTN)gCallbackKey) !=3D FRONT_PAGE_KEY_CONTINUE); - - // - //Will leave browser, check any reset required change is applied? if yes= , reset system - // - SetupResetReminder (); - // - // Remove the installed BootMaint HiiPackages when exit. - // - FreeBMPackage (); - -Exit: - // - // Automatically load current entry - // Note: The following lines of code only execute when Auto boot - // takes affect - // - PERF_END (NULL, "BdsTimeOut", "BDS", 0); -} - - -VOID=20 -BootIntoFirmwareInterface( -VOID -) -{ - EFI_STATUS Status; - UINTN DataSize; - UINT16 Timeout; =20 - UINT64 OsIndication; - - =20 - OsIndication =3D 0; - DataSize =3D sizeof(UINT64); - Status =3D gRT->GetVariable ( - L"OsIndications", - &gEfiGlobalVariableGuid, - NULL, - &DataSize, - &OsIndication - ); - =20 - DEBUG ((EFI_D_INFO, "OSIndication Variable Value %d\n", OsIndication)); - // - //Goto FrontPage directly when bit EFI_OS_INDICATIONS_BOOT_TO_FW_UI in O= SIndication Variable is setted. - // =20 - if (!EFI_ERROR(Status) && (OsIndication !=3D 0)) { =20 - Timeout =3D 0xffff; - PlatformBdsEnterFrontPage (Timeout, FALSE); - } -} - - -EFI_STATUS -PlatformBdsConnectSimpleConsole ( - IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole -) -{ - EFI_STATUS Status; - UINTN Index; - EFI_DEVICE_PATH_PROTOCOL *VarConout; - EFI_DEVICE_PATH_PROTOCOL *VarConin; - UINTN DevicePathSize; - - - Index =3D 0; - Status =3D EFI_SUCCESS; - DevicePathSize =3D 0; - VarConout =3D BdsLibGetVariableAndSize ( - L"ConOut", - &gEfiGlobalVariableGuid, - &DevicePathSize - ); - VarConin =3D BdsLibGetVariableAndSize ( - L"ConIn", - &gEfiGlobalVariableGuid, - &DevicePathSize - ); - if (VarConout =3D=3D NULL || VarConin =3D=3D NULL) { - // - // Have chance to connect the platform default console, - // the platform default console is the minimum device group - // the platform should support - // - while (PlatformConsole[Index].DevicePath !=3D NULL) { - - // - // Update the console variable with the connect type - // - if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) =3D=3D CONSOLE= _IN) { - BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].Devi= cePath, NULL); - } - - if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) =3D=3D CONSOL= E_OUT) { - BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].Dev= icePath, NULL); - } - - if ((PlatformConsole[Index].ConnectType & STD_ERROR) =3D=3D STD_ERRO= R) { - BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].Dev= icePath, NULL); - } - - Index ++; - } - } - - // - // Connect ConIn first to give keyboard time to parse hot key event. - // - Status =3D BdsLibConnectConsoleVariable (L"ConIn"); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Make sure we have at least one active VGA, and have the right - // active VGA in console variable - // - Status =3D PlatformBdsForceActiveVga (); - - // - // It seems impossible not to have any ConOut device on platform, - // so we check the status here. - // - Status =3D BdsLibConnectConsoleVariable (L"ConOut"); - if (EFI_ERROR (Status)) { - return Status; - } - - return EFI_SUCCESS; -} - - -/** - Timer handler to convert the key from USB. - - @param Event Indicates the event that invoke this fu= nction. - @param Context Indicates the calling context. -**/ -VOID -EFIAPI -HotKeyTimerHandler ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - EFI_STATUS Status; - EFI_INPUT_KEY Key; - - Status =3D gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); - if (EFI_ERROR (Status)) { - return; - } - - switch(Key.ScanCode) { - case SCAN_F2: - gHotKey =3D 0; - mHotKeyPressed =3D TRUE; - break; - - case SCAN_F5: - gHotKey =3D FRONT_PAGE_KEY_DEVICE_MANAGER; - mHotKeyPressed =3D TRUE; - break; - - case SCAN_F7: - gHotKey =3D FRONT_PAGE_KEY_BOOT_MANAGER; - mHotKeyPressed =3D TRUE; - break; - - case SCAN_F9: - gHotKey =3D FRONT_PAGE_KEY_BOOT_MAINTAIN; - mHotKeyPressed =3D TRUE; - break; - } - - if (mHotKeyPressed) { - gBS->SetTimer ( - mHotKeyTimerEvent, - TimerCancel, - 0 - ); - gBS->CloseEvent (mHotKeyTimerEvent); - mHotKeyTimerEvent =3D NULL; - } - - return; -} - - -/** - Callback function for SimpleTextInEx protocol install events - - @param Event the event that is signaled. - @param Context not used here. - -**/ -VOID -EFIAPI -HitHotkeyEvent ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - EFI_STATUS Status; - - Status =3D gBS->CloseEvent(mHitHotkeyEvent); - if (EFI_ERROR (Status)) { - return; - } - Status =3D gBS->CreateEvent ( - EVT_TIMER | EVT_NOTIFY_SIGNAL, - TPL_NOTIFY, - HotKeyTimerHandler, - NULL, - &mHotKeyTimerEvent - ); - if (EFI_ERROR (Status)) { - return; - } - Status =3D gBS->SetTimer ( - mHotKeyTimerEvent, - TimerPeriodic, - KEYBOARD_TIMER_INTERVAL - ); - if (EFI_ERROR (Status)) { - return; - } - - return; -} - - -VOID -EFIAPI -PlatformBdsInitHotKeyEvent ( - VOID - ) -{ - EFI_STATUS Status; - - // - // Register Protocol notify for Hotkey service - // - Status =3D gBS->CreateEvent ( - EVT_NOTIFY_SIGNAL, - TPL_CALLBACK, - HitHotkeyEvent, - NULL, - &mHitHotkeyEvent - ); - ASSERT_EFI_ERROR (Status); - - // - // Register for protocol notifications on this event - // - Status =3D gBS->RegisterProtocolNotify ( - &gEfiSimpleTextInputExProtocolGuid, - mHitHotkeyEvent, - &mHitHotkeyRegistration - ); - ASSERT_EFI_ERROR (Status); -} diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPla= tform.h b/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatfo= rm.h deleted file mode 100644 index b5bb519747..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.h +++ /dev/null @@ -1,516 +0,0 @@ -/*++ - - Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
- = =20 - SPDX-License-Identifier: BSD-2-Clause-Patent - - = =20 - - -Module Name: - - BdsPlatform.h - -Abstract: - - Head file for BDS Platform specific code - ---*/ - -#ifndef _BDS_PLATFORM_H -#define _BDS_PLATFORM_H - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -extern EFI_DEVICE_PATH_PROTOCOL *gPlatformRootBridges []; -extern BDS_CONSOLE_CONNECT_ENTRY gPlatformConsole []; -extern EFI_DEVICE_PATH_PROTOCOL *gPlatformAllPossiblePciVgaConsole []; -extern EFI_DEVICE_PATH_PROTOCOL *gPlatformConnectSequence []; -extern EFI_DEVICE_PATH_PROTOCOL *gPlatformDriverOption []; -extern EFI_DEVICE_PATH_PROTOCOL *gPlatformBootOption []; -extern EFI_DEVICE_PATH_PROTOCOL *gUserAuthenticationDevice[]; -extern BDS_CONSOLE_CONNECT_ENTRY gPlatformSimpleConsole []; -extern EFI_DEVICE_PATH_PROTOCOL *gPlatformSimpleBootOption []; - -extern BOOLEAN mEnumBootDevice; - - -// -// the short form device path for Usb keyboard -// -#define CLASS_HID 3 -#define SUBCLASS_BOOT 1 -#define PROTOCOL_KEYBOARD 1 - -#define PCI_DEVICE_PATH_NODE(Func, Dev) \ - { \ - HARDWARE_DEVICE_PATH, \ - HW_PCI_DP, \ - { \ - (UINT8) (sizeof (PCI_DEVICE_PATH)), \ - (UINT8) ((sizeof (PCI_DEVICE_PATH)) >> 8) \ - }, \ - (Func), \ - (Dev) \ - } - -#define PNPID_DEVICE_PATH_NODE(PnpId) \ - { \ - { \ - ACPI_DEVICE_PATH, \ - ACPI_DP, \ - { \ - (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), \ - (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) \ - } \ - }, \ - EISA_PNP_ID((PnpId)), \ - 0 \ - } - -#define gUart(BaudRate, DataBits, Parity, StopBits) \ - { \ - { \ - MESSAGING_DEVICE_PATH, \ - MSG_UART_DP, \ - { \ - (UINT8) (sizeof (UART_DEVICE_PATH)), \ - (UINT8) ((sizeof (UART_DEVICE_PATH)) >> 8) \ - } \ - }, \ - 0, \ - (BaudRate), \ - (DataBits), \ - (Parity), \ - (StopBits) \ - } - -#define gPcAnsiTerminal \ - { \ - { \ - MESSAGING_DEVICE_PATH, \ - MSG_VENDOR_DP, \ - { \ - (UINT8) (sizeof (VENDOR_DEVICE_PATH)), \ - (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) \ - } \ - }, \ - DEVICE_PATH_MESSAGING_PC_ANSI \ - } - -#define gUsbKeyboardMouse \ - { \ - { \ - MESSAGING_DEVICE_PATH, \ - MSG_USB_CLASS_DP, \ - (UINT8) (sizeof (USB_CLASS_DEVICE_PATH)), \ - (UINT8) ((sizeof (USB_CLASS_DEVICE_PATH)) >> 8) \ - }, \ - 0xffff, \ - 0xffff, \ - CLASS_HID, \ - SUBCLASS_BOOT, \ - PROTOCOL_KEYBOARD \ - } - -#define gEndEntire \ - { \ - END_DEVICE_PATH_TYPE, \ - END_ENTIRE_DEVICE_PATH_SUBTYPE, \ - { \ - END_DEVICE_PATH_LENGTH, \ - 0 \ - } \ - } - -#define gPciRootBridge \ - PNPID_DEVICE_PATH_NODE(0x0A03) - -#define gPnpPs2Keyboard \ - PNPID_DEVICE_PATH_NODE(0x0303) - -#define gPnp16550ComPort \ - PNPID_DEVICE_PATH_NODE(0x0501) - -#define gPciePort0Bridge \ - PCI_DEVICE_PATH_NODE(0, 0x1C) - -#define gPciePort1Bridge \ - PCI_DEVICE_PATH_NODE(1, 0x1C) - -#define gPciePort2Bridge \ - PCI_DEVICE_PATH_NODE(2, 0x1C) - -#define gPciePort3Bridge \ - PCI_DEVICE_PATH_NODE(3, 0x1C) - -#define gPciIsaBridge \ - PCI_DEVICE_PATH_NODE(0, 0x1f) - -// -// Platform Root Bridge -// -typedef struct { - ACPI_HID_DEVICE_PATH PciRootBridge; - EFI_DEVICE_PATH_PROTOCOL End; -} PLATFORM_ROOT_BRIDGE_DEVICE_PATH; - -// -// Below is the platform console device path -// -typedef struct { - ACPI_HID_DEVICE_PATH PciRootBridge; - PCI_DEVICE_PATH IsaBridge; - ACPI_HID_DEVICE_PATH Keyboard; - EFI_DEVICE_PATH_PROTOCOL End; -} PLATFORM_ISA_KEYBOARD_DEVICE_PATH; - -typedef struct { - VENDOR_DEVICE_PATH VendorDevicePath; - EFI_DEVICE_PATH_PROTOCOL End; -} HII_VENDOR_DEVICE_PATH; - -typedef struct { - USB_CLASS_DEVICE_PATH UsbClass; - EFI_DEVICE_PATH_PROTOCOL End; -} USB_CLASS_FORMAT_DEVICE_PATH; - -typedef struct { - ACPI_HID_DEVICE_PATH PciRootBridge; - PCI_DEVICE_PATH OnboardVga; - EFI_DEVICE_PATH_PROTOCOL End; -} PLATFORM_ONBOARD_VGA_DEVICE_PATH; - -typedef struct { - ACPI_HID_DEVICE_PATH PciRootBridge; - PCI_DEVICE_PATH AgpBridge; - PCI_DEVICE_PATH AgpDevice; - EFI_DEVICE_PATH_PROTOCOL End; -} PLATFORM_OFFBOARD_VGA_DEVICE_PATH; - -typedef struct { - ACPI_HID_DEVICE_PATH PciRootBridge; - PCI_DEVICE_PATH IsaBridge; - ACPI_HID_DEVICE_PATH IsaSerial; - UART_DEVICE_PATH Uart; - VENDOR_DEVICE_PATH TerminalType; - EFI_DEVICE_PATH_PROTOCOL End; -} PLATFORM_ISA_SERIAL_DEVICE_PATH; - -// -// Below is the boot option device path -// -typedef struct { - BBS_BBS_DEVICE_PATH LegacyHD; - EFI_DEVICE_PATH_PROTOCOL End; -} LEGACY_HD_DEVICE_PATH; - -// -// Below is the platform IDE device path -// -typedef struct { - ACPI_HID_DEVICE_PATH PciRootBridge; - PCI_DEVICE_PATH IsaBridge; - ATAPI_DEVICE_PATH Ide; - EFI_DEVICE_PATH_PROTOCOL End; -} PLATFORM_IDE_DEVICE_PATH; - -// -// Floppy device path definition -// -typedef struct { - ACPI_HID_DEVICE_PATH PciRootBridge; - PCI_DEVICE_PATH IsaBridge; - ACPI_HID_DEVICE_PATH Floppy; - EFI_DEVICE_PATH_PROTOCOL End; -} PLATFORM_FLOPPY_DEVICE_PATH; - -// -// Below is the platform USB controller device path for -// USB disk as user authentication device. -// -typedef struct { - ACPI_HID_DEVICE_PATH PciRootBridge; - PCI_DEVICE_PATH PciDevice; - EFI_DEVICE_PATH_PROTOCOL End; -} PLATFORM_USB_DEVICE_PATH; - -// -// Debug Agent UART Console device path definition -// -typedef struct { - VENDOR_DEVICE_PATH VendorHardware; - UART_DEVICE_PATH Uart; - VENDOR_DEVICE_PATH TerminalType; - EFI_DEVICE_PATH_PROTOCOL End; -} VENDOR_UART_DEVICE_PATH; - -// -// Below is the platform PCI device path -// -typedef struct { - ACPI_HID_DEVICE_PATH PciRootBridge; - PCI_DEVICE_PATH PciDevice; - EFI_DEVICE_PATH_PROTOCOL End; -} PLATFORM_PCI_DEVICE_PATH; - -typedef enum { - PMIC_Equal =3D 0, // =3D 0 - PMIC_Greater_Than, // > 1 - PMIC_Smaller_Than, // < 2 - PMIC_Greater_Equal, // >=3D 3 - PMIC_Smaller_Equal, // <=3D 4 - PMIC_Any // don't care 5 -} PMIC_Condition_list; - -typedef enum { - PMIC_White_List =3D 0, //White list - PMIC_Black_List =3D 1 //Black list -} PMIC_Compliance_mode; - -typedef struct { - UINT8 Cond_Choice; // PMIC_Condition_list - UINT8 Cond_Number; // the number -}PMIC_Condition_Item; - -typedef struct { - PMIC_Condition_Item PMIC_BoardID; - PMIC_Condition_Item PMIC_FabID; - PMIC_Condition_Item Soc_Stepping;//define PMIC type, 1:Dialog , 2= :Rohm - PMIC_Condition_Item PMIC_VendID; - PMIC_Condition_Item PMIC_RevID; - PMIC_Compliance_mode mode; //if 1, blacklist; if 0, w= hite list. -} PMIC_Compliance_Item; - -// -// Platform BDS Functions -// -VOID -PlatformBdsGetDriverOption ( - IN LIST_ENTRY *BdsDriverLists - ); - -VOID -PlatformBdsPredictBootOption ( - IN LIST_ENTRY *BdsBootOptionList - ); - -EFI_STATUS -PlatformBdsShowProgress ( - EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground, - EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground, - CHAR16 *Title, - EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor, - UINTN Progress, - UINTN PreviousValue - ); - -VOID -PlatformBdsConnectSequence ( - VOID - ); - -EFI_STATUS -PlatformBdsConnectConsole ( - IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole - ); - -EFI_STATUS -PlatformBdsNoConsoleAction ( - VOID - ); - -VOID -PlatformBdsEnterFrontPage ( - IN UINT16 TimeoutDefault, - IN BOOLEAN ConnectAllHappened - ); - -VOID -EFIAPI -PlatformBdsUserIdentify ( - OUT EFI_USER_PROFILE_HANDLE *User, - OUT BOOLEAN *DeferredImage - ); - -VOID -EFIAPI -PlatformBdsConnectAuthDevice ( - VOID - ); - -VOID -PlatformBdsEnterFrontPageWithHotKey ( - IN UINT16 TimeoutDefault, - IN BOOLEAN ConnectAllHappened - ); - - EFI_STATUS - ShowProgress ( - IN UINT16 TimeoutDefault - ); - - EFI_STATUS - InitializeFrontPage ( - IN BOOLEAN InitializeHiiData - ); - - VOID - UpdateFrontPageStrings ( - VOID - ); - =20 - =20 - EFI_STATUS - InitBMPackage ( - VOID - ); - =20 - =20 - VOID - FreeBMPackage ( - VOID - ); - =20 - =20 - EFI_STATUS - CallFrontPage ( - VOID - ); - - - VOID - CallBootManager ( - VOID - ); - -VOID -CallDeviceManager ( - VOID - ); - -VOID -BdsStartBootMaint ( - VOID - ); - -CHAR16 * -GetStringById ( - IN EFI_STRING_ID Id - ); - -EFI_STATUS -WaitForSingleEvent ( - IN EFI_EVENT Event, - IN UINT64 Timeout OPTIONAL - ); - -EFI_STATUS -BdsLibDeleteOptionFromHandle ( - IN EFI_HANDLE Handle - ); - -EFI_STATUS -BdsDeleteAllInvalidEfiBootOption ( - VOID - ); - - -#define ONE_SECOND 10000000 -#define FRONT_PAGE_KEY_CONTINUE 0x1000 -#define FRONT_PAGE_KEY_LANGUAGE 0x1234 -#define FRONT_PAGE_KEY_BOOT_MANAGER 0x1064 -#define FRONT_PAGE_KEY_DEVICE_MANAGER 0x8567 -#define FRONT_PAGE_KEY_BOOT_MAINTAIN 0x9876 - -#define PORT_A_DVO 0 // ; DVO A -#define PORT_B_DVO 1 // ; DVO B -#define PORT_C_DVO 2 // ; DVO C -#define PORT_D_DVO 3 // ; DVO D -#define PORT_LVDS 4 // ; Integrated LVDS po= rt -#define PORT_ANALOG_TV 5 // ; Integrated TV port -#define PORT_CRT 6 // ; integrated Analog = port -#define PORT_B_DP 7 // ; DisplayPort B -#define PORT_C_DP 8 // ; DisplayPort C -#define PORT_D_DP 9 // ; DisplayPort D -#define PORT_A_DP 10 // ; DisplayPort A (for= eDP on ILK) -#define PORT_B_HDMI 11 // ; HDMI B -#define PORT_C_HDMI 12 // ; HDMI C -#define PORT_D_HDMI 13 // ; HDMI D -#define PORT_B_DVI 14 // ; DVI B -#define PORT_C_DVI 15 // ; DVI C -#define PORT_D_DVI 16 // ; DVI D -#define PORT_MIPI_A 21 // ; MIPI -#define PORT_MIPI_B 22 -#define PORT_MIPI_C 23 - - -extern BOOLEAN gConnectAllHappened; -extern UINTN gCallbackKey; - -VOID -BdsBootDeviceSelect ( - VOID -); -VOID FastBoot(VOID); - -extern BOOLEAN mModeInitialized; - -// -// Boot video resolution and text mode. -// -extern UINT32 mBootHorizontalResolution ; -extern UINT32 mBootVerticalResolution ; -extern UINT32 mBootTextModeColumn ; -extern UINT32 mBootTextModeRow ; - -// -// BIOS setup video resolution and text mode. -// -extern UINT32 mSetupTextModeColumn ; -extern UINT32 mSetupTextModeRow ; -extern UINT32 mSetupHorizontalResolution ; -extern UINT32 mSetupVerticalResolution ; -extern EFI_STATUS BdsSetConsoleMode (BOOLEAN); -#endif // _BDS_PLATFORM_H diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/Platfo= rmBdsLib.inf b/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/Plat= formBdsLib.inf deleted file mode 100644 index 66d11c6cda..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformBdsLi= b.inf +++ /dev/null @@ -1,128 +0,0 @@ -#/** @file -# Component name for module PlatformBootManagerLib -# -# Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.
-# - -# SPDX-License-Identifier: BSD-2-Clause-Patent - -# - -# -# -# -#**/ - -[Defines] - INF_VERSION =3D 0x00010005 - BASE_NAME =3D PlatformBdsLib - FILE_GUID =3D A6BC385D-59E5-4b77-87D7-200ABAA83C15 - MODULE_TYPE =3D DXE_DRIVER - VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D PlatformBootManagerLib|DXE_DRIVER - EDK_RELEASE_VERSION =3D 0x00020000 - EFI_SPECIFICATION_VERSION =3D 0x0002000A - - -# -# The following information is for reference only and not required by the = build tools. -# -# VALID_ARCHITECTURES =3D IA32 X64 EBC -# - -[Sources] - BdsPlatform.c - BdsPlatform.h - PlatformData.c - PlatformBdsStrings.uni - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - IntelFrameworkPkg/IntelFrameworkPkg.dec - IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec - Vlv2TbltDevicePkg/PlatformPkg.dec - Vlv2DeviceRefCodePkg/Vlv2DeviceRefCodePkg.dec - ShellPkg/ShellPkg.dec - CryptoPkg/CryptoPkg.dec - SecurityPkg/SecurityPkg.dec - SignedCapsulePkg/SignedCapsulePkg.dec - SourceLevelDebugPkg/SourceLevelDebugPkg.dec - NetworkPkg/NetworkPkg.dec - -[LibraryClasses] - DxeServicesTableLib - BaseLib - MemoryAllocationLib - UefiBootServicesTableLib - UefiRuntimeServicesTableLib - BaseMemoryLib - DebugLib - PcdLib - GenericBdsLib - DevicePathLib - NetLib - UefiLib - HobLib - PciLib - PrintLib - BaseCryptLib -# TcgPhysicalPresenceLib - Tcg2PhysicalPresenceLib =20 - FileHandleLib - S3BootScriptLib - SerialPortLib - CapsuleLib - -[Protocols] - gEfiFirmwareVolume2ProtocolGuid - gEfiSimpleNetworkProtocolGuid - gEfiLoadFileProtocolGuid - gEfiPciIoProtocolGuid - gEfiSmmAccess2ProtocolGuid - gEfiDxeSmmReadyToLockProtocolGuid - gEfiUserManagerProtocolGuid - gEfiDeferredImageLoadProtocolGuid - gEfiAcpiS3SaveProtocolGuid - gEfiSpiProtocolGuid ## PROTOCOL CONSUMES - gExitPmAuthProtocolGuid - gEfiTdtOperationProtocolGuid - gEfiGlobalNvsAreaProtocolGuid - gEfiMmioDeviceProtocolGuid - gEfiI2cMasterProtocolGuid - gEfiI2cHostProtocolGuid - gEsrtManagementProtocolGuid - -[Guids] - gEfiMemoryTypeInformationGuid - gEfiCapsuleVendorGuid - gEfiGlobalVariableGuid - gEfiNormalSetupGuid - gEfiPartTypeSystemPartGuid - gEfiEndOfDxeEventGroupGuid - gUefiShellFileGuid - -[Pcd] - gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiRsa2048Sha256TestPublicKeyFil= eGuid - gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiPkcs7TestPublicKeyFileGuid - gEfiSecurityPkgTokenSpaceGuid.PcdRsa2048Sha256PublicKeyBuffer - gEfiSecurityPkgTokenSpaceGuid.PcdPkcs7CertBuffer - gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed - gPlatformModuleTokenSpaceGuid.PcdFlashFvRecovery2Base - gPlatformModuleTokenSpaceGuid.PcdFlashFvMainBase - gPlatformModuleTokenSpaceGuid.PcdFlashFvRecoveryBase - gPlatformModuleTokenSpaceGuid.PcdFlashFvShellBase - gPlatformModuleTokenSpaceGuid.PcdFlashFvShellSize - gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut - gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile - gPlatformModuleTokenSpaceGuid.PcdIFWISigBaseAddress - gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow - gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn - gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution - gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution - gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress - gEfiMdeModulePkgTokenSpaceGuid.PcdSetupConOutColumn - gEfiMdeModulePkgTokenSpaceGuid.PcdSetupConOutRow - gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution - gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution - gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdBootState diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/Platfo= rmBdsStrings.uni b/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/= PlatformBdsStrings.uni deleted file mode 100644 index 101106f9f4..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformBdsSt= rings.uni +++ /dev/null @@ -1,30 +0,0 @@ -///** @file -// =20 -// String definitions for Boot Option description. -// =20 -// Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.
-// SPDX-License-Identifier: BSD-2-Clause-Patent -// =20 -//**/ - -/=3D# - -#langdef en-US "English" -#langdef fr-FR "Fran=C3=A7ais" - -#string STR_DESCRIPTION_FLOPPY #language en-US "EFI Floppy" - #language fr-FR "fr-FR: EFI Floppy" -#string STR_DESCRIPTION_CD_DVD #language en-US "EFI DVD/CDROM" - #language fr-FR "fr-FR: EFI DVD/CD= ROM" -#string STR_DESCRIPTION_HARDDRIVE #language en-US "EFI Hard Drive" - #language fr-FR "fr-FR: EFI Hard D= rive" -#string STR_DESCRIPTION_USB #language en-US "EFI USB Device" - #language fr-FR "fr-FR: EFI USB De= vice" -#string STR_DESCRIPTION_SCSI #language en-US "EFI SCSI Device" - #language fr-FR "fr-FR: EFI SCSI D= evice" -#string STR_DESCRIPTION_MISC #language en-US "EFI Misc Device" - #language fr-FR "fr-FR: EFI Misc D= evice" -#string STR_DESCRIPTION_NETWORK #language en-US "EFI Network" - #language fr-FR "fr-FR: EFI Networ= k" -#string STR_DESCRIPTION_NON_BLOCK #language en-US "EFI Non-Block Boo= t Device" - #language fr-FR "fr-FR: EFI Non-Bl= ock Boot Device" diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/Platfo= rmData.c b/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/Platform= Data.c deleted file mode 100644 index 9dff93f52b..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformData.c +++ /dev/null @@ -1,306 +0,0 @@ -/** @file - - Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
- = =20 - SPDX-License-Identifier: BSD-2-Clause-Patent - - = =20 - -Module Name: - - PlatformData.c - -Abstract: - - Defined the platform specific device path which will be used by - platform Bbd to perform the platform policy connect. - ---*/ - -#include "BdsPlatform.h" - -// -// Predefined platform default time out value -// -UINT16 gPlatformBootTimeOutDefault =3D 10; - -// -// Predefined platform root bridge -// -PLATFORM_ROOT_BRIDGE_DEVICE_PATH gPlatformRootBridge0 =3D { - gPciRootBridge, - gEndEntire -}; - -EFI_DEVICE_PATH_PROTOCOL* gPlatformRootBridges [] =3D { - (EFI_DEVICE_PATH_PROTOCOL*)&gPlatformRootBridge0, - NULL -}; - -// -// Platform specific ISA keyboard device path -// -PLATFORM_ISA_KEYBOARD_DEVICE_PATH gIsaKeyboardDevicePath =3D { - gPciRootBridge, - gPciIsaBridge, - gPnpPs2Keyboard, - gEndEntire -}; - -// -// Platform specific on chip PCI VGA device path -// -PLATFORM_ONBOARD_VGA_DEVICE_PATH gOnChipPciVgaDevicePath =3D { - gPciRootBridge, - PCI_DEVICE_PATH_NODE(0, 0x2), - gEndEntire -}; - -// -// Platform specific plug in PCI VGA device path -// -PLATFORM_OFFBOARD_VGA_DEVICE_PATH gPlugInPciVgaDevicePath =3D { - gPciRootBridge, - PCI_DEVICE_PATH_NODE(0, 0x1), - PCI_DEVICE_PATH_NODE(0, 0x0), - gEndEntire -}; - -// -// Platform specific ISA serial device path -// -PLATFORM_ISA_SERIAL_DEVICE_PATH gIsaSerialDevicePath =3D { - gPciRootBridge, - gPciIsaBridge, - gPnp16550ComPort, - gUart(115200, 8, 1, 1), - gPcAnsiTerminal, - gEndEntire -}; - - -// -// Platform specific Button Array device path -// -HII_VENDOR_DEVICE_PATH gHiiVendorDevicePath0 =3D { - { - { - HARDWARE_DEVICE_PATH, - HW_VENDOR_DP, - { - (UINT8) (sizeof (VENDOR_DEVICE_PATH)), - (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) - } - }, - - // - // {C8752FDE-B5C8-4528-897D-6920FE771E38} - // - { 0xC8752FDE, 0xB5C8, 0x4528, { 0x89, 0x7D, 0x69, 0x20, 0xFE, 0x77, 0x= 1E, 0x38 } } - }, - { - END_DEVICE_PATH_TYPE, - END_ENTIRE_DEVICE_PATH_SUBTYPE, - { - (UINT8) (END_DEVICE_PATH_LENGTH), - (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8) - } - } -}; - -USB_CLASS_FORMAT_DEVICE_PATH gUsbClassKeyboardDevicePath =3D { - gUsbKeyboardMouse, - gEndEntire -}; - -// -// Debug Agent UART Console device path=20 -// -VENDOR_UART_DEVICE_PATH gDebugAgentUartDevicePath =3D { - { - { - HARDWARE_DEVICE_PATH, - HW_VENDOR_DP, - { - (UINT8) (sizeof (VENDOR_DEVICE_PATH)), - (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) - } - }, - EFI_DEBUG_AGENT_GUID, - }, - { - { - MESSAGING_DEVICE_PATH, - MSG_UART_DP, - { - (UINT8) (sizeof (UART_DEVICE_PATH)), - (UINT8) ((sizeof (UART_DEVICE_PATH)) >> 8) - } - }, - 0, // Reserved - 0, // BaudRate - Default - 0, // DataBits - Default - 0, // Parity - Default - 0, // StopBits - Default - }, - { - { - MESSAGING_DEVICE_PATH, - MSG_VENDOR_DP, - { - (UINT8)(sizeof (VENDOR_DEVICE_PATH)), - (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8) - } - }, - DEVICE_PATH_MESSAGING_PC_ANSI - }, - gEndEntire -}; - -// -// Predefined platform default console device path -// -BDS_CONSOLE_CONNECT_ENTRY gPlatformConsole [] =3D { - {(EFI_DEVICE_PATH_PROTOCOL*)&gIsaSerialDevicePath, CONSOLE_ALL}, - {(EFI_DEVICE_PATH_PROTOCOL*)&gHiiVendorDevicePath0, CONSOLE_IN}, - {(EFI_DEVICE_PATH_PROTOCOL*)&gIsaKeyboardDevicePath, CONSOLE_IN}, - {(EFI_DEVICE_PATH_PROTOCOL*)&gDebugAgentUartDevicePath, CONSOLE_ALL}, - {(EFI_DEVICE_PATH_PROTOCOL*)&gUsbClassKeyboardDevicePath, CONSOLE_IN}, - {NULL, 0} -}; - -// -// All the possible platform PCI VGA device path -// -EFI_DEVICE_PATH_PROTOCOL* gPlatformAllPossiblePciVgaConsole [] =3D { - (EFI_DEVICE_PATH_PROTOCOL*)&gOnChipPciVgaDevicePath, - (EFI_DEVICE_PATH_PROTOCOL*)&gPlugInPciVgaDevicePath, - NULL -}; - -// -// Legacy hard disk boot option -// -LEGACY_HD_DEVICE_PATH gLegacyHd =3D { - { - BBS_DEVICE_PATH, - BBS_BBS_DP, - (UINT8)(sizeof(BBS_BBS_DEVICE_PATH)), - (UINT8)((sizeof(BBS_BBS_DEVICE_PATH)) >> 8), - BBS_TYPE_HARDDRIVE, - 0, - 0 - }, - gEndEntire -}; - -// -// Legacy cdrom boot option -// -LEGACY_HD_DEVICE_PATH gLegacyCdrom =3D { - { - BBS_DEVICE_PATH, - BBS_BBS_DP, - (UINT8)(sizeof(BBS_BBS_DEVICE_PATH)), - (UINT8)((sizeof(BBS_BBS_DEVICE_PATH)) >> 8), - BBS_TYPE_CDROM, - 0, - 0 - }, - gEndEntire -}; - -// -// Predefined platform specific perdict boot option -// -EFI_DEVICE_PATH_PROTOCOL* gPlatformBootOption [] =3D { - (EFI_DEVICE_PATH_PROTOCOL*)&gLegacyHd, - (EFI_DEVICE_PATH_PROTOCOL*)&gLegacyCdrom, - NULL -}; - -// -// Predefined platform specific driver option -// -EFI_DEVICE_PATH_PROTOCOL* gPlatformDriverOption [] =3D { - NULL -}; - -// -// Predefined platform connect sequence -// -EFI_DEVICE_PATH_PROTOCOL* gPlatformConnectSequence [] =3D { - (EFI_DEVICE_PATH_PROTOCOL *)&gPlatformRootBridge0, // Force PCI enumer = before Legacy OpROM shadow - NULL -}; - -// -// Platform specific USB controller device path -// -PLATFORM_USB_DEVICE_PATH gUsbDevicePath0 =3D { - gPciRootBridge, - PCI_DEVICE_PATH_NODE(0, 0x1D), - gEndEntire -}; - -PLATFORM_USB_DEVICE_PATH gUsbDevicePath1 =3D { - gPciRootBridge, - PCI_DEVICE_PATH_NODE(1, 0x1D), - gEndEntire -}; - -PLATFORM_USB_DEVICE_PATH gUsbDevicePath2 =3D { - gPciRootBridge, - PCI_DEVICE_PATH_NODE(2, 0x1D), - gEndEntire -}; - -PLATFORM_USB_DEVICE_PATH gUsbDevicePath3 =3D { - gPciRootBridge, - PCI_DEVICE_PATH_NODE(3, 0x1D), - gEndEntire -}; - -// -// Predefined platform device path for user authtication -// -EFI_DEVICE_PATH_PROTOCOL* gUserAuthenticationDevice[] =3D { - // - // Predefined device path for secure card (USB disk). - // - (EFI_DEVICE_PATH_PROTOCOL*)&gUsbDevicePath0, - (EFI_DEVICE_PATH_PROTOCOL*)&gUsbDevicePath1, - (EFI_DEVICE_PATH_PROTOCOL*)&gUsbDevicePath2, - (EFI_DEVICE_PATH_PROTOCOL*)&gUsbDevicePath3, - NULL -}; - -// -// Predefined platform console device path -// -BDS_CONSOLE_CONNECT_ENTRY gPlatformSimpleConsole [] =3D { - {(EFI_DEVICE_PATH_PROTOCOL*)&gOnChipPciVgaDevicePath, CONSOLE_OUT}, - {(EFI_DEVICE_PATH_PROTOCOL*)&gIsaSerialDevicePath, CONSOLE_ALL}, - {(EFI_DEVICE_PATH_PROTOCOL*)&gHiiVendorDevicePath0, CONSOLE_IN}, - {(EFI_DEVICE_PATH_PROTOCOL*)&gDebugAgentUartDevicePath, CONSOLE_ALL}, - {(EFI_DEVICE_PATH_PROTOCOL*)&gUsbClassKeyboardDevicePath, CONSOLE_IN}, - {NULL, 0} -}; - -// -// eMMC device at BDF(0x0, 0x17, 0x0) -// -PLATFORM_PCI_DEVICE_PATH gEmmcBootDevPath0 =3D { - gPciRootBridge, - PCI_DEVICE_PATH_NODE (0x00, 0x10), - gEndEntire -}; - -// -// Predefined platform specific perdict boot option -// -EFI_DEVICE_PATH_PROTOCOL* gPlatformSimpleBootOption [] =3D { - (EFI_DEVICE_PATH_PROTOCOL*)&gEmmcBootDevPath0, - NULL -}; - diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModule= Pkg/Library/GenericBdsLib/BdsBoot.c b/Platform/Intel/Vlv2TbltDevicePkg/Over= ride/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c deleted file mode 100644 index 3034853695..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Lib= rary/GenericBdsLib/BdsBoot.c +++ /dev/null @@ -1,4490 +0,0 @@ -/** @file - BDS Lib functions which relate with create or process the boot option. - -Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "InternalBdsLib.h" -#include "String.h" -#include -#include "Library/DebugLib.h" - -BOOLEAN mEnumBootDevice =3D FALSE; -EFI_HII_HANDLE gBdsLibStringPackHandle =3D NULL; - -/** - - End Perf entry of BDS - - @param Event The triggered event. - @param Context Context for this event. - -**/ -VOID -EFIAPI -BmEndOfBdsPerfCode ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - // - // Record the performance data for End of BDS - // - PERF_END(NULL, "BDS", NULL, 0); - - return ; -} - -/** - The constructor function register UNI strings into imageHandle. - =20 - It will ASSERT() if that operation fails and it will always return EFI_S= UCCESS.=20 - - @param ImageHandle The firmware allocated handle for the EFI image. - @param SystemTable A pointer to the EFI System Table. - =20 - @retval EFI_SUCCESS The constructor successfully added string package. - @retval Other value The constructor can't add string package. - -**/ -EFI_STATUS -EFIAPI -GenericBdsLibConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - - gBdsLibStringPackHandle =3D HiiAddPackages ( - &gBdsLibStringPackageGuid, - ImageHandle, - GenericBdsLibStrings, - NULL - ); - - ASSERT (gBdsLibStringPackHandle !=3D NULL); - - return EFI_SUCCESS; -} - -/** - Deletete the Boot Option from EFI Variable. The Boot Order Arrray - is also updated. - - @param OptionNumber The number of Boot option want to be deleted. - @param BootOrder The Boot Order array. - @param BootOrderSize The size of the Boot Order Array. - - @retval EFI_SUCCESS The Boot Option Variable was found and re= moved - @retval EFI_UNSUPPORTED The Boot Option Variable store was inacce= ssible - @retval EFI_NOT_FOUND The Boot Option Variable was not found -**/ -EFI_STATUS -EFIAPI -BdsDeleteBootOption ( - IN UINTN OptionNumber, - IN OUT UINT16 *BootOrder, - IN OUT UINTN *BootOrderSize - ) -{ - CHAR16 BootOption[9]; - UINTN Index; - EFI_STATUS Status; - - UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", OptionNumbe= r); - Status =3D gRT->SetVariable ( - BootOption, - &gEfiGlobalVariableGuid, - 0, - 0, - NULL - ); - // - // Deleting variable with existing variable implementation shouldn't fai= l. - // - ASSERT_EFI_ERROR (Status); - - // - // adjust boot order array - // - for (Index =3D 0; Index < *BootOrderSize / sizeof (UINT16); Index++) { - if (BootOrder[Index] =3D=3D OptionNumber) { - CopyMem (&BootOrder[Index], &BootOrder[Index+1], *BootOrderSize - (I= ndex+1) * sizeof (UINT16)); - *BootOrderSize -=3D sizeof (UINT16); - break; - } - } - - return Status; -} -/** - - Translate the first n characters of an Ascii string to - Unicode characters. The count n is indicated by parameter - Size. If Size is greater than the length of string, then - the entire string is translated. - - - @param AStr Pointer to input Ascii string. - @param Size The number of characters to translate. - @param UStr Pointer to output Unicode string buffer. - -**/ -VOID -AsciiToUnicodeSize ( - IN UINT8 *AStr, - IN UINTN Size, - OUT UINT16 *UStr - ) -{ - UINTN Idx; - - Idx =3D 0; - while (AStr[Idx] !=3D 0) { - UStr[Idx] =3D (CHAR16) AStr[Idx]; - if (Idx =3D=3D Size) { - break; - } - - Idx++; - } - UStr[Idx] =3D 0; -} - -/** - Build Legacy Device Name String according. - - @param CurBBSEntry BBS Table. - @param Index Index. - @param BufSize The buffer size. - @param BootString The output string. - -**/ -VOID -BdsBuildLegacyDevNameString ( - IN BBS_TABLE *CurBBSEntry, - IN UINTN Index, - IN UINTN BufSize, - OUT CHAR16 *BootString - ) -{ - CHAR16 *Fmt; - CHAR16 *Type; - UINT8 *StringDesc; - CHAR16 Temp[80]; - - switch (Index) { - // - // Primary Master - // - case 1: - Fmt =3D L"Primary Master %s"; - break; - - // - // Primary Slave - // - case 2: - Fmt =3D L"Primary Slave %s"; - break; - - // - // Secondary Master - // - case 3: - Fmt =3D L"Secondary Master %s"; - break; - - // - // Secondary Slave - // - case 4: - Fmt =3D L"Secondary Slave %s"; - break; - - default: - Fmt =3D L"%s"; - break; - } - - switch (CurBBSEntry->DeviceType) { - case BBS_FLOPPY: - Type =3D L"Floppy"; - break; - - case BBS_HARDDISK: - Type =3D L"Harddisk"; - break; - - case BBS_CDROM: - Type =3D L"CDROM"; - break; - - case BBS_PCMCIA: - Type =3D L"PCMCIAe"; - break; - - case BBS_USB: - Type =3D L"USB"; - break; - - case BBS_EMBED_NETWORK: - Type =3D L"Network"; - break; - - case BBS_BEV_DEVICE: - Type =3D L"BEVe"; - break; - - case BBS_UNKNOWN: - default: - Type =3D L"Unknown"; - break; - } - // - // If current BBS entry has its description then use it. - // - StringDesc =3D (UINT8 *) (UINTN) ((CurBBSEntry->DescStringSegment << 4) = + CurBBSEntry->DescStringOffset); - if (NULL !=3D StringDesc) { - // - // Only get fisrt 32 characters, this is suggested by BBS spec - // - AsciiToUnicodeSize (StringDesc, 32, Temp); - Fmt =3D L"%s"; - Type =3D Temp; - } - - // - // BbsTable 16 entries are for onboard IDE. - // Set description string for SATA harddisks, Harddisk 0 ~ Harddisk 11 - // - if (Index >=3D 5 && Index <=3D 16 && (CurBBSEntry->DeviceType =3D=3D BBS= _HARDDISK || CurBBSEntry->DeviceType =3D=3D BBS_CDROM)) { - Fmt =3D L"%s %d"; - UnicodeSPrint (BootString, BufSize, Fmt, Type, Index - 5); - } else { - UnicodeSPrint (BootString, BufSize, Fmt, Type); - } -} - -/** - - Create a legacy boot option for the specified entry of - BBS table, save it as variable, and append it to the boot - order list. - - - @param CurrentBbsEntry Pointer to current BBS table. - @param CurrentBbsDevPath Pointer to the Device Path Protocol instance o= f BBS - @param Index Index of the specified entry in BBS table. - @param BootOrderList On input, the original boot order list. - On output, the new boot order list attached wi= th the - created node. - @param BootOrderListSize On input, the original size of boot order list. - On output, the size of new boot order list. - - @retval EFI_SUCCESS Boot Option successfully created. - @retval EFI_OUT_OF_RESOURCES Fail to allocate necessary memory. - @retval Other Error occurs while setting variable. - -**/ -EFI_STATUS -BdsCreateLegacyBootOption ( - IN BBS_TABLE *CurrentBbsEntry, - IN EFI_DEVICE_PATH_PROTOCOL *CurrentBbsDevPath, - IN UINTN Index, - IN OUT UINT16 **BootOrderList, - IN OUT UINTN *BootOrderListSize - ) -{ - EFI_STATUS Status; - UINT16 CurrentBootOptionNo; - UINT16 BootString[10]; - CHAR16 BootDesc[100]; - CHAR8 HelpString[100]; - UINT16 *NewBootOrderList; - UINTN BufferSize; - UINTN StringLen; - VOID *Buffer; - UINT8 *Ptr; - UINT16 CurrentBbsDevPathSize; - UINTN BootOrderIndex; - UINTN BootOrderLastIndex; - UINTN ArrayIndex; - BOOLEAN IndexNotFound; - BBS_BBS_DEVICE_PATH *NewBbsDevPathNode; - - if ((*BootOrderList) =3D=3D NULL) { - CurrentBootOptionNo =3D 0; - } else { - for (ArrayIndex =3D 0; ArrayIndex < (UINTN) (*BootOrderListSize / size= of (UINT16)); ArrayIndex++) { - IndexNotFound =3D TRUE; - for (BootOrderIndex =3D 0; BootOrderIndex < (UINTN) (*BootOrderListS= ize / sizeof (UINT16)); BootOrderIndex++) { - if ((*BootOrderList)[BootOrderIndex] =3D=3D ArrayIndex) { - IndexNotFound =3D FALSE; - break; - } - } - - if (!IndexNotFound) { - continue; - } else { - break; - } - } - - CurrentBootOptionNo =3D (UINT16) ArrayIndex; - } - - UnicodeSPrint ( - BootString, - sizeof (BootString), - L"Boot%04x", - CurrentBootOptionNo - ); - - BdsBuildLegacyDevNameString (CurrentBbsEntry, Index, sizeof (BootDesc), = BootDesc); - - // - // Create new BBS device path node with description string - // - UnicodeStrToAsciiStr (BootDesc, HelpString); - - StringLen =3D AsciiStrLen (HelpString); - NewBbsDevPathNode =3D AllocateZeroPool (sizeof (BBS_BBS_DEVICE_PATH) + S= tringLen); - if (NewBbsDevPathNode =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - CopyMem (NewBbsDevPathNode, CurrentBbsDevPath, sizeof (BBS_BBS_DEVICE_PA= TH)); - CopyMem (NewBbsDevPathNode->String, HelpString, StringLen + 1); - SetDevicePathNodeLength (&(NewBbsDevPathNode->Header), sizeof (BBS_BBS_D= EVICE_PATH) + StringLen); - - // - // Create entire new CurrentBbsDevPath with end node - // - CurrentBbsDevPath =3D AppendDevicePathNode ( - NULL, - (EFI_DEVICE_PATH_PROTOCOL *) NewBbsDevPathNode - ); - if (CurrentBbsDevPath =3D=3D NULL) { - FreePool (NewBbsDevPathNode); - return EFI_OUT_OF_RESOURCES; - } - - CurrentBbsDevPathSize =3D (UINT16) (GetDevicePathSize (CurrentBbsDevPath= )); - - BufferSize =3D sizeof (UINT32) + - sizeof (UINT16) + - StrSize (BootDesc) + - CurrentBbsDevPathSize + - sizeof (BBS_TABLE) + - sizeof (UINT16); - - Buffer =3D AllocateZeroPool (BufferSize); - if (Buffer =3D=3D NULL) { - FreePool (NewBbsDevPathNode); - FreePool (CurrentBbsDevPath); - return EFI_OUT_OF_RESOURCES; - } - - Ptr =3D (UINT8 *) Buffer; - - *((UINT32 *) Ptr) =3D LOAD_OPTION_ACTIVE; - Ptr +=3D sizeof (UINT32); - - *((UINT16 *) Ptr) =3D CurrentBbsDevPathSize; - Ptr +=3D sizeof (UINT16); - - CopyMem ( - Ptr, - BootDesc, - StrSize (BootDesc) - ); - Ptr +=3D StrSize (BootDesc); - - CopyMem ( - Ptr, - CurrentBbsDevPath, - CurrentBbsDevPathSize - ); - Ptr +=3D CurrentBbsDevPathSize; - - CopyMem ( - Ptr, - CurrentBbsEntry, - sizeof (BBS_TABLE) - ); - - Ptr +=3D sizeof (BBS_TABLE); - *((UINT16 *) Ptr) =3D (UINT16) Index; - - Status =3D gRT->SetVariable ( - BootString, - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_A= CCESS | EFI_VARIABLE_NON_VOLATILE, - BufferSize, - Buffer - ); - - FreePool (Buffer); - =20 - Buffer =3D NULL; - - NewBootOrderList =3D AllocateZeroPool (*BootOrderListSize + sizeof (UINT= 16)); - if (NULL =3D=3D NewBootOrderList) { - FreePool (NewBbsDevPathNode); - FreePool (CurrentBbsDevPath); - return EFI_OUT_OF_RESOURCES; - } - - if (*BootOrderList !=3D NULL) { - CopyMem (NewBootOrderList, *BootOrderList, *BootOrderListSize); - FreePool (*BootOrderList); - } - - BootOrderLastIndex =3D (UINTN) (*BootOrderListSize / = sizeof (UINT16)); - NewBootOrderList[BootOrderLastIndex] =3D CurrentBootOptionNo; - *BootOrderListSize +=3D sizeof (UINT16); - *BootOrderList =3D NewBootOrderList; - - FreePool (NewBbsDevPathNode); - FreePool (CurrentBbsDevPath); - return Status; -} - -/** - Check if the boot option is a legacy one. - - @param BootOptionVar The boot option data payload. - @param BbsEntry The BBS Table. - @param BbsIndex The table index. - - @retval TRUE It is a legacy boot option. - @retval FALSE It is not a legacy boot option. - -**/ -BOOLEAN -BdsIsLegacyBootOption ( - IN UINT8 *BootOptionVar, - OUT BBS_TABLE **BbsEntry, - OUT UINT16 *BbsIndex - ) -{ - UINT8 *Ptr; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - BOOLEAN Ret; - UINT16 DevPathLen; - - Ptr =3D BootOptionVar; - Ptr +=3D sizeof (UINT32); - DevPathLen =3D *(UINT16 *) Ptr; - Ptr +=3D sizeof (UINT16); - Ptr +=3D StrSize ((UINT16 *) Ptr); - DevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *) Ptr; - if ((BBS_DEVICE_PATH =3D=3D DevicePath->Type) && (BBS_BBS_DP =3D=3D Devi= cePath->SubType)) { - Ptr +=3D DevPathLen; - *BbsEntry =3D (BBS_TABLE *) Ptr; - Ptr +=3D sizeof (BBS_TABLE); - *BbsIndex =3D *(UINT16 *) Ptr; - Ret =3D TRUE; - } else { - *BbsEntry =3D NULL; - Ret =3D FALSE; - } - - return Ret; -} - -/** - Delete all the invalid legacy boot options. - - @retval EFI_SUCCESS All invalide legacy boot options are del= eted. - @retval EFI_OUT_OF_RESOURCES Fail to allocate necessary memory. - @retval EFI_NOT_FOUND Fail to retrive variable of boot order. -**/ -EFI_STATUS -EFIAPI -BdsDeleteAllInvalidLegacyBootOptions ( - VOID - ) -{ - UINT16 *BootOrder; - UINT8 *BootOptionVar; - UINTN BootOrderSize; - UINTN BootOptionSize; - EFI_STATUS Status; - UINT16 HddCount; - UINT16 BbsCount; - HDD_INFO *LocalHddInfo; - BBS_TABLE *LocalBbsTable; - BBS_TABLE *BbsEntry; - UINT16 BbsIndex; - EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - UINTN Index; - UINT16 BootOption[10]; - UINT16 BootDesc[100]; - BOOLEAN DescStringMatch; - - Status =3D EFI_SUCCESS; - BootOrder =3D NULL; - BootOrderSize =3D 0; - HddCount =3D 0; - BbsCount =3D 0; - LocalHddInfo =3D NULL; - LocalBbsTable =3D NULL; - BbsEntry =3D NULL; - - Status =3D gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL= , (VOID **) &LegacyBios); - if (EFI_ERROR (Status)) { - return Status; - } - - BootOrder =3D BdsLibGetVariableAndSize ( - L"BootOrder", - &gEfiGlobalVariableGuid, - &BootOrderSize - ); - if (BootOrder =3D=3D NULL) { - return EFI_NOT_FOUND; - } - - LegacyBios->GetBbsInfo ( - LegacyBios, - &HddCount, - &LocalHddInfo, - &BbsCount, - &LocalBbsTable - ); - - Index =3D 0; - while (Index < BootOrderSize / sizeof (UINT16)) { - UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder= [Index]); - BootOptionVar =3D BdsLibGetVariableAndSize ( - BootOption, - &gEfiGlobalVariableGuid, - &BootOptionSize - ); - if (NULL =3D=3D BootOptionVar) { - BootOptionSize =3D 0; - Status =3D gRT->GetVariable ( - BootOption, - &gEfiGlobalVariableGuid, - NULL, - &BootOptionSize, - BootOptionVar - ); - if (Status =3D=3D EFI_NOT_FOUND) { - // - // Update BootOrder - // - BdsDeleteBootOption ( - BootOrder[Index], - BootOrder, - &BootOrderSize - ); - continue; - } else { - FreePool (BootOrder); - return EFI_OUT_OF_RESOURCES; - } - } - =20 - // - // Skip Non-Legacy boot option - //=20 - if (!BdsIsLegacyBootOption (BootOptionVar, &BbsEntry, &BbsIndex)) { - if (BootOptionVar!=3D NULL) { - FreePool (BootOptionVar); - } - Index++; - continue; - } - - if (BbsIndex < BbsCount) { - // - // Check if BBS Description String is changed - // - DescStringMatch =3D FALSE; - BdsBuildLegacyDevNameString ( - &LocalBbsTable[BbsIndex], - BbsIndex, - sizeof (BootDesc), - BootDesc - ); - - if (StrCmp (BootDesc, (UINT16*)(BootOptionVar + sizeof (UINT32) + si= zeof (UINT16))) =3D=3D 0) { - DescStringMatch =3D TRUE; - } - - if (!((LocalBbsTable[BbsIndex].BootPriority =3D=3D BBS_IGNORE_ENTRY)= || - (LocalBbsTable[BbsIndex].BootPriority =3D=3D BBS_DO_NOT_BOOT_F= ROM)) && - (LocalBbsTable[BbsIndex].DeviceType =3D=3D BbsEntry->DeviceType)= && - DescStringMatch) { - Index++; - continue; - } - } - - if (BootOptionVar !=3D NULL) { - FreePool (BootOptionVar); - } - // - // should delete - // - BdsDeleteBootOption ( - BootOrder[Index], - BootOrder, - &BootOrderSize - ); - } - - // - // Adjust the number of boot options. - // - Status =3D gRT->SetVariable ( - L"BootOrder", - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_A= CCESS | EFI_VARIABLE_NON_VOLATILE, - BootOrderSize, - BootOrder - ); - // - // Shrinking variable with existing variable implementation shouldn't fa= il. - // - ASSERT_EFI_ERROR (Status); - FreePool (BootOrder); - - return Status; -} - -/** - Find all legacy boot option by device type. - - @param BootOrder The boot order array. - @param BootOptionNum The number of boot option. - @param DevType Device type. - @param DevName Device name. - @param Attribute The boot option attribute. - @param BbsIndex The BBS table index. - @param OptionNumber The boot option index. - - @retval TRUE The Legacy boot option is found. - @retval FALSE The legacy boot option is not found. - -**/ -BOOLEAN -BdsFindLegacyBootOptionByDevTypeAndName ( - IN UINT16 *BootOrder, - IN UINTN BootOptionNum, - IN UINT16 DevType, - IN CHAR16 *DevName, - OUT UINT32 *Attribute, - OUT UINT16 *BbsIndex, - OUT UINT16 *OptionNumber - ) -{ - UINTN Index; - CHAR16 BootOption[9]; - UINTN BootOptionSize; - UINT8 *BootOptionVar; - BBS_TABLE *BbsEntry; - BOOLEAN Found; - - BbsEntry =3D NULL; - Found =3D FALSE; - - if (NULL =3D=3D BootOrder) { - return Found; - } - - // - // Loop all boot option from variable - // - for (Index =3D 0; Index < BootOptionNum; Index++) { - UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", (UINTN) B= ootOrder[Index]); - BootOptionVar =3D BdsLibGetVariableAndSize ( - BootOption, - &gEfiGlobalVariableGuid, - &BootOptionSize - ); - if (NULL =3D=3D BootOptionVar) { - continue; - } - - // - // Skip Non-legacy boot option - // - if (!BdsIsLegacyBootOption (BootOptionVar, &BbsEntry, BbsIndex)) { - FreePool (BootOptionVar); - continue; - } - - if ( - (BbsEntry->DeviceType !=3D DevType) || - (StrCmp (DevName, (CHAR16*)(BootOptionVar + sizeof (UINT32) + size= of (UINT16))) !=3D 0) - ) { - FreePool (BootOptionVar); - continue; - } - - *Attribute =3D *(UINT32 *) BootOptionVar; - *OptionNumber =3D BootOrder[Index]; - Found =3D TRUE; - FreePool (BootOptionVar); - break; - } - - return Found; -} - -/** - Create a legacy boot option. - - @param BbsItem The BBS Table entry. - @param Index Index of the specified entry in BBS table. - @param BootOrderList The boot order list. - @param BootOrderListSize The size of boot order list. - - @retval EFI_OUT_OF_RESOURCE No enough memory. - @retval EFI_SUCCESS The function complete successfully. - @return Other value if the legacy boot option is not created. - -**/ -EFI_STATUS -BdsCreateOneLegacyBootOption ( - IN BBS_TABLE *BbsItem, - IN UINTN Index, - IN OUT UINT16 **BootOrderList, - IN OUT UINTN *BootOrderListSize - ) -{ - BBS_BBS_DEVICE_PATH BbsDevPathNode; - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *DevPath; - - DevPath =3D NULL; - - // - // Create device path node. - // - BbsDevPathNode.Header.Type =3D BBS_DEVICE_PATH; - BbsDevPathNode.Header.SubType =3D BBS_BBS_DP; - SetDevicePathNodeLength (&BbsDevPathNode.Header, sizeof (BBS_BBS_DEVICE_= PATH)); - BbsDevPathNode.DeviceType =3D BbsItem->DeviceType; - CopyMem (&BbsDevPathNode.StatusFlag, &BbsItem->StatusFlags, sizeof (UINT= 16)); - - DevPath =3D AppendDevicePathNode ( - NULL, - (EFI_DEVICE_PATH_PROTOCOL *) &BbsDevPathNode - ); - if (NULL =3D=3D DevPath) { - return EFI_OUT_OF_RESOURCES; - } - - Status =3D BdsCreateLegacyBootOption ( - BbsItem, - DevPath, - Index, - BootOrderList, - BootOrderListSize - ); - BbsItem->BootPriority =3D 0x00; - - FreePool (DevPath); - - return Status; -} - -/** - Add the legacy boot options from BBS table if they do not exist. - - @retval EFI_SUCCESS The boot options are added successfully=20 - or they are already in boot options. - @retval EFI_NOT_FOUND No legacy boot options is found. - @retval EFI_OUT_OF_RESOURCE No enough memory. - @return Other value LegacyBoot options are not added. -**/ -EFI_STATUS -EFIAPI -BdsAddNonExistingLegacyBootOptions ( - VOID - ) -{ - UINT16 *BootOrder; - UINTN BootOrderSize; - EFI_STATUS Status; - CHAR16 Desc[100]; - UINT16 HddCount; - UINT16 BbsCount; - HDD_INFO *LocalHddInfo; - BBS_TABLE *LocalBbsTable; - UINT16 BbsIndex; - EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - UINT16 Index; - UINT32 Attribute; - UINT16 OptionNumber; - BOOLEAN Exist; - - HddCount =3D 0; - BbsCount =3D 0; - LocalHddInfo =3D NULL; - LocalBbsTable =3D NULL; - - Status =3D gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL= , (VOID **) &LegacyBios); - if (EFI_ERROR (Status)) { - return Status; - } - - LegacyBios->GetBbsInfo ( - LegacyBios, - &HddCount, - &LocalHddInfo, - &BbsCount, - &LocalBbsTable - ); - - BootOrder =3D BdsLibGetVariableAndSize ( - L"BootOrder", - &gEfiGlobalVariableGuid, - &BootOrderSize - ); - if (BootOrder =3D=3D NULL) { - BootOrderSize =3D 0; - } - - for (Index =3D 0; Index < BbsCount; Index++) { - if ((LocalBbsTable[Index].BootPriority =3D=3D BBS_IGNORE_ENTRY) || - (LocalBbsTable[Index].BootPriority =3D=3D BBS_DO_NOT_BOOT_FROM) - ) { - continue; - } - - BdsBuildLegacyDevNameString (&LocalBbsTable[Index], Index, sizeof (Des= c), Desc); - - Exist =3D BdsFindLegacyBootOptionByDevTypeAndName ( - BootOrder, - BootOrderSize / sizeof (UINT16), - LocalBbsTable[Index].DeviceType, - Desc, - &Attribute, - &BbsIndex, - &OptionNumber - ); - if (!Exist) { - // - // Not found such type of legacy device in boot options or we found = but it's disabled - // so we have to create one and put it to the tail of boot order list - // - Status =3D BdsCreateOneLegacyBootOption ( - &LocalBbsTable[Index], - Index, - &BootOrder, - &BootOrderSize - ); - if (!EFI_ERROR (Status)) { - ASSERT (BootOrder !=3D NULL); - BbsIndex =3D Index; - OptionNumber =3D BootOrder[BootOrderSize / sizeof (UINT16) - 1]; - } - } - - ASSERT (BbsIndex =3D=3D Index); - } - - Status =3D gRT->SetVariable ( - L"BootOrder", - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_A= CCESS | EFI_VARIABLE_NON_VOLATILE, - BootOrderSize, - BootOrder - ); - if (BootOrder !=3D NULL) { - FreePool (BootOrder); - } - - return Status; -} - -/** - Fill the device order buffer. - - @param BbsTable The BBS table. - @param BbsType The BBS Type. - @param BbsCount The BBS Count. - @param Buf device order buffer. - - @return The device order buffer. - -**/ -UINT16 * -BdsFillDevOrderBuf ( - IN BBS_TABLE *BbsTable, - IN BBS_TYPE BbsType, - IN UINTN BbsCount, - OUT UINT16 *Buf - ) -{ - UINTN Index; - - for (Index =3D 0; Index < BbsCount; Index++) { - if (BbsTable[Index].BootPriority =3D=3D BBS_IGNORE_ENTRY) { - continue; - } - - if (BbsTable[Index].DeviceType !=3D BbsType) { - continue; - } - - *Buf =3D (UINT16) (Index & 0xFF); - Buf++; - } - - return Buf; -} - -/** - Create the device order buffer. - - @param BbsTable The BBS table. - @param BbsCount The BBS Count. - - @retval EFI_SUCCES The buffer is created and the EFI variabl= e named=20 - VAR_LEGACY_DEV_ORDER and gEfiLegacyDevOrd= erVariableGuid is - set correctly. - @retval EFI_OUT_OF_RESOURCES Memmory or storage is not enough. - @retval EFI_DEVICE_ERROR Fail to add the device order into EFI var= iable fail - because of hardware error. -**/ -EFI_STATUS -BdsCreateDevOrder ( - IN BBS_TABLE *BbsTable, - IN UINT16 BbsCount - ) -{ - UINTN Index; - UINTN FDCount; - UINTN HDCount; - UINTN CDCount; - UINTN NETCount; - UINTN BEVCount; - UINTN TotalSize; - UINTN HeaderSize; - LEGACY_DEV_ORDER_ENTRY *DevOrder; - LEGACY_DEV_ORDER_ENTRY *DevOrderPtr; - EFI_STATUS Status; - - FDCount =3D 0; - HDCount =3D 0; - CDCount =3D 0; - NETCount =3D 0; - BEVCount =3D 0; - TotalSize =3D 0; - HeaderSize =3D sizeof (BBS_TYPE) + sizeof (UINT16); - DevOrder =3D NULL; - Status =3D EFI_SUCCESS; - - // - // Count all boot devices - // - for (Index =3D 0; Index < BbsCount; Index++) { - if (BbsTable[Index].BootPriority =3D=3D BBS_IGNORE_ENTRY) { - continue; - } - - switch (BbsTable[Index].DeviceType) { - case BBS_FLOPPY: - FDCount++; - break; - - case BBS_HARDDISK: - HDCount++; - break; - - case BBS_CDROM: - CDCount++; - break; - - case BBS_EMBED_NETWORK: - NETCount++; - break; - - case BBS_BEV_DEVICE: - BEVCount++; - break; - - default: - break; - } - } - - TotalSize +=3D (HeaderSize + sizeof (UINT16) * FDCount); - TotalSize +=3D (HeaderSize + sizeof (UINT16) * HDCount); - TotalSize +=3D (HeaderSize + sizeof (UINT16) * CDCount); - TotalSize +=3D (HeaderSize + sizeof (UINT16) * NETCount); - TotalSize +=3D (HeaderSize + sizeof (UINT16) * BEVCount); - - // - // Create buffer to hold all boot device order - // - DevOrder =3D AllocateZeroPool (TotalSize); - if (NULL =3D=3D DevOrder) { - return EFI_OUT_OF_RESOURCES; - } - DevOrderPtr =3D DevOrder; - - DevOrderPtr->BbsType =3D BBS_FLOPPY; - DevOrderPtr->Length =3D (UINT16) (sizeof (DevOrderPtr->Length) + FDCoun= t * sizeof (UINT16)); - DevOrderPtr =3D (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (= BbsTable, BBS_FLOPPY, BbsCount, DevOrderPtr->Data); - - DevOrderPtr->BbsType =3D BBS_HARDDISK; - DevOrderPtr->Length =3D (UINT16) (sizeof (UINT16) + HDCount * sizeof (U= INT16)); - DevOrderPtr =3D (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (= BbsTable, BBS_HARDDISK, BbsCount, DevOrderPtr->Data); - =20 - DevOrderPtr->BbsType =3D BBS_CDROM; - DevOrderPtr->Length =3D (UINT16) (sizeof (UINT16) + CDCount * sizeof (U= INT16)); - DevOrderPtr =3D (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (= BbsTable, BBS_CDROM, BbsCount, DevOrderPtr->Data); - =20 - DevOrderPtr->BbsType =3D BBS_EMBED_NETWORK; - DevOrderPtr->Length =3D (UINT16) (sizeof (UINT16) + NETCount * sizeof (= UINT16)); - DevOrderPtr =3D (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (= BbsTable, BBS_EMBED_NETWORK, BbsCount, DevOrderPtr->Data); - - DevOrderPtr->BbsType =3D BBS_BEV_DEVICE; - DevOrderPtr->Length =3D (UINT16) (sizeof (UINT16) + BEVCount * sizeof (= UINT16)); - DevOrderPtr =3D (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (= BbsTable, BBS_BEV_DEVICE, BbsCount, DevOrderPtr->Data); - - ASSERT (TotalSize =3D=3D (UINTN) ((UINT8 *) DevOrderPtr - (UINT8 *) DevO= rder)); - - // - // Save device order for legacy boot device to variable. - // - Status =3D gRT->SetVariable ( - VAR_LEGACY_DEV_ORDER, - &gEfiLegacyDevOrderVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLAT= ILE, - TotalSize, - DevOrder - ); - FreePool (DevOrder); - - return Status; -} - -/** - Add the legacy boot devices from BBS table into=20 - the legacy device boot order. - - @retval EFI_SUCCESS The boot devices are added successfully. - @retval EFI_NOT_FOUND The legacy boot devices are not found. - @retval EFI_OUT_OF_RESOURCES Memmory or storage is not enough. - @retval EFI_DEVICE_ERROR Fail to add the legacy device boot order i= nto EFI variable - because of hardware error. -**/ -EFI_STATUS -EFIAPI -BdsUpdateLegacyDevOrder ( - VOID - ) -{ - LEGACY_DEV_ORDER_ENTRY *DevOrder; - LEGACY_DEV_ORDER_ENTRY *NewDevOrder; - LEGACY_DEV_ORDER_ENTRY *Ptr; - LEGACY_DEV_ORDER_ENTRY *NewPtr; - UINTN DevOrderSize; - EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - EFI_STATUS Status; - UINT16 HddCount; - UINT16 BbsCount; - HDD_INFO *LocalHddInfo; - BBS_TABLE *LocalBbsTable; - UINTN Index; - UINTN Index2; - UINTN *Idx; - UINTN FDCount; - UINTN HDCount; - UINTN CDCount; - UINTN NETCount; - UINTN BEVCount; - UINTN TotalSize; - UINTN HeaderSize; - UINT16 *NewFDPtr; - UINT16 *NewHDPtr; - UINT16 *NewCDPtr; - UINT16 *NewNETPtr; - UINT16 *NewBEVPtr; - UINT16 *NewDevPtr; - UINTN FDIndex; - UINTN HDIndex; - UINTN CDIndex; - UINTN NETIndex; - UINTN BEVIndex; - - Idx =3D NULL; - FDCount =3D 0; - HDCount =3D 0; - CDCount =3D 0; - NETCount =3D 0; - BEVCount =3D 0; - TotalSize =3D 0; - HeaderSize =3D sizeof (BBS_TYPE) + sizeof (UINT16); - FDIndex =3D 0; - HDIndex =3D 0; - CDIndex =3D 0; - NETIndex =3D 0; - BEVIndex =3D 0; - NewDevPtr =3D NULL; - - Status =3D gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL= , (VOID **) &LegacyBios); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D LegacyBios->GetBbsInfo ( - LegacyBios, - &HddCount, - &LocalHddInfo, - &BbsCount, - &LocalBbsTable - ); - if (EFI_ERROR (Status)) { - return Status; - } - - DevOrder =3D BdsLibGetVariableAndSize ( - VAR_LEGACY_DEV_ORDER, - &gEfiLegacyDevOrderVariableGuid, - &DevOrderSize - ); - if (NULL =3D=3D DevOrder) { - return BdsCreateDevOrder (LocalBbsTable, BbsCount); - } - // - // First we figure out how many boot devices with same device type respe= ctively - // - for (Index =3D 0; Index < BbsCount; Index++) { - if ((LocalBbsTable[Index].BootPriority =3D=3D BBS_IGNORE_ENTRY) || - (LocalBbsTable[Index].BootPriority =3D=3D BBS_DO_NOT_BOOT_FROM) - ) { - continue; - } - - switch (LocalBbsTable[Index].DeviceType) { - case BBS_FLOPPY: - FDCount++; - break; - - case BBS_HARDDISK: - HDCount++; - break; - - case BBS_CDROM: - CDCount++; - break; - - case BBS_EMBED_NETWORK: - NETCount++; - break; - - case BBS_BEV_DEVICE: - BEVCount++; - break; - - default: - break; - } - } - - TotalSize +=3D (HeaderSize + FDCount * sizeof (UINT16)); - TotalSize +=3D (HeaderSize + HDCount * sizeof (UINT16)); - TotalSize +=3D (HeaderSize + CDCount * sizeof (UINT16)); - TotalSize +=3D (HeaderSize + NETCount * sizeof (UINT16)); - TotalSize +=3D (HeaderSize + BEVCount * sizeof (UINT16)); - - NewDevOrder =3D AllocateZeroPool (TotalSize); - if (NULL =3D=3D NewDevOrder) { - return EFI_OUT_OF_RESOURCES; - } - - - - // - // copy FD - // - Ptr =3D DevOrder; - NewPtr =3D NewDevOrder; - NewPtr->BbsType =3D Ptr->BbsType; - NewPtr->Length =3D (UINT16) (sizeof (UINT16) + FDCount * sizeof (UINT16= )); - for (Index =3D 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) { - if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority =3D=3D BBS_IGN= ORE_ENTRY || - LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority =3D=3D BBS_DO_= NOT_BOOT_FROM || - LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType !=3D BBS_FLOPPY - ) { - continue; - } - - NewPtr->Data[FDIndex] =3D Ptr->Data[Index]; - FDIndex++; - } - NewFDPtr =3D NewPtr->Data; - - // - // copy HD - // - Ptr =3D (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length /= sizeof (UINT16) - 1]); - NewPtr =3D (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Le= ngth / sizeof (UINT16) -1]); - NewPtr->BbsType =3D Ptr->BbsType; - NewPtr->Length =3D (UINT16) (sizeof (UINT16) + HDCount * sizeof (UINT16= )); - for (Index =3D 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) { - if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority =3D=3D BBS_IGN= ORE_ENTRY || - LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority =3D=3D BBS_DO_= NOT_BOOT_FROM || - LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority =3D=3D BBS_LOW= EST_PRIORITY || - LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType !=3D BBS_HARDDISK - ) { - continue; - } - - NewPtr->Data[HDIndex] =3D Ptr->Data[Index]; - HDIndex++; - } - NewHDPtr =3D NewPtr->Data; - - // - // copy CD - // - Ptr =3D (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length / sizeof (= UINT16) - 1]); - NewPtr =3D (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Length / si= zeof (UINT16) -1]); - NewPtr->BbsType =3D Ptr->BbsType; - NewPtr->Length =3D (UINT16) (sizeof (UINT16) + CDCount * sizeof (UINT16= )); - for (Index =3D 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) { - if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority =3D=3D BBS_IGN= ORE_ENTRY || - LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority =3D=3D BBS_DO_= NOT_BOOT_FROM || - LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority =3D=3D BBS_LOW= EST_PRIORITY || - LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType !=3D BBS_CDROM - ) { - continue; - } - - NewPtr->Data[CDIndex] =3D Ptr->Data[Index]; - CDIndex++; - } - NewCDPtr =3D NewPtr->Data; - - // - // copy NET - // - Ptr =3D (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length / sizeof (= UINT16) - 1]); - NewPtr =3D (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Length / si= zeof (UINT16) -1]); - NewPtr->BbsType =3D Ptr->BbsType; - NewPtr->Length =3D (UINT16) (sizeof (UINT16) + NETCount * sizeof (UINT1= 6)); - for (Index =3D 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) { - if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority =3D=3D BBS_IGN= ORE_ENTRY || - LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority =3D=3D BBS_DO_= NOT_BOOT_FROM || - LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority =3D=3D BBS_LOW= EST_PRIORITY || - LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType !=3D BBS_EMBED_N= ETWORK - ) { - continue; - } - - NewPtr->Data[NETIndex] =3D Ptr->Data[Index]; - NETIndex++; - } - NewNETPtr =3D NewPtr->Data; - =20 - // - // copy BEV - // - Ptr =3D (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length / sizeof (= UINT16) - 1]); - NewPtr =3D (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Length / si= zeof (UINT16) -1]); - NewPtr->BbsType =3D Ptr->BbsType; - NewPtr->Length =3D (UINT16) (sizeof (UINT16) + BEVCount * sizeof (UINT1= 6)); - for (Index =3D 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) { - if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority =3D=3D BBS_IGN= ORE_ENTRY || - LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority =3D=3D BBS_DO_= NOT_BOOT_FROM || - LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority =3D=3D BBS_LOW= EST_PRIORITY || - LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType !=3D BBS_BEV_DEV= ICE - ) { - continue; - } - - NewPtr->Data[BEVIndex] =3D Ptr->Data[Index]; - BEVIndex++; - } - NewBEVPtr =3D NewPtr->Data; - - for (Index =3D 0; Index < BbsCount; Index++) { - if ((LocalBbsTable[Index].BootPriority =3D=3D BBS_IGNORE_ENTRY) || - (LocalBbsTable[Index].BootPriority =3D=3D BBS_DO_NOT_BOOT_FROM) - ) { - continue; - } - - switch (LocalBbsTable[Index].DeviceType) { - case BBS_FLOPPY: - Idx =3D &FDIndex; - NewDevPtr =3D NewFDPtr; - break; - - case BBS_HARDDISK: - Idx =3D &HDIndex; - NewDevPtr =3D NewHDPtr; - break; - - case BBS_CDROM: - Idx =3D &CDIndex; - NewDevPtr =3D NewCDPtr; - break; - - case BBS_EMBED_NETWORK: - Idx =3D &NETIndex; - NewDevPtr =3D NewNETPtr; - break; - - case BBS_BEV_DEVICE: - Idx =3D &BEVIndex; - NewDevPtr =3D NewBEVPtr; - break; - - default: - Idx =3D NULL; - break; - } - // - // at this point we have copied those valid indexes to new buffer - // and we should check if there is any new appeared boot device - // - if (Idx !=3D NULL) { - for (Index2 =3D 0; Index2 < *Idx; Index2++) { - if ((NewDevPtr[Index2] & 0xFF) =3D=3D (UINT16) Index) { - break; - } - } - - if (Index2 =3D=3D *Idx) { - // - // Index2 =3D=3D *Idx means we didn't find Index - // so Index is a new appeared device's index in BBS table - // insert it before disabled indexes. - // - for (Index2 =3D 0; Index2 < *Idx; Index2++) { - if ((NewDevPtr[Index2] & 0xFF00) =3D=3D 0xFF00) { - break; - } - } - CopyMem (&NewDevPtr[Index2 + 1], &NewDevPtr[Index2], (*Idx - Index= 2) * sizeof (UINT16)); - NewDevPtr[Index2] =3D (UINT16) (Index & 0xFF); - (*Idx)++; - } - } - } - - FreePool (DevOrder); - - Status =3D gRT->SetVariable ( - VAR_LEGACY_DEV_ORDER, - &gEfiLegacyDevOrderVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLAT= ILE, - TotalSize, - NewDevOrder - ); - FreePool (NewDevOrder); - - return Status; -} - -/** - Set Boot Priority for specified device type. - - @param DeviceType The device type. - @param BbsIndex The BBS index to set the highest priority. Ignore= when -1. - @param LocalBbsTable The BBS table. - @param Priority The prority table. - - @retval EFI_SUCCESS The function completes successfully. - @retval EFI_NOT_FOUND Failed to find device. - @retval EFI_OUT_OF_RESOURCES Failed to get the efi variable of device o= rder. - -**/ -EFI_STATUS -BdsSetBootPriority4SameTypeDev ( - IN UINT16 DeviceType, - IN UINTN BbsIndex, - IN OUT BBS_TABLE *LocalBbsTable, - IN OUT UINT16 *Priority - ) -{ - LEGACY_DEV_ORDER_ENTRY *DevOrder; - LEGACY_DEV_ORDER_ENTRY *DevOrderPtr; - UINTN DevOrderSize; - UINTN Index; - - DevOrder =3D BdsLibGetVariableAndSize ( - VAR_LEGACY_DEV_ORDER, - &gEfiLegacyDevOrderVariableGuid, - &DevOrderSize - ); - if (NULL =3D=3D DevOrder) { - return EFI_OUT_OF_RESOURCES; - } - - DevOrderPtr =3D DevOrder; - while ((UINT8 *) DevOrderPtr < (UINT8 *) DevOrder + DevOrderSize) { - if (DevOrderPtr->BbsType =3D=3D DeviceType) { - break; - } - - DevOrderPtr =3D (LEGACY_DEV_ORDER_ENTRY *) ((UINTN) DevOrderPtr + size= of (BBS_TYPE) + DevOrderPtr->Length); - } - - if ((UINT8 *) DevOrderPtr >=3D (UINT8 *) DevOrder + DevOrderSize) { - FreePool (DevOrder); - return EFI_NOT_FOUND; - } - - if (BbsIndex !=3D (UINTN) -1) { - LocalBbsTable[BbsIndex].BootPriority =3D *Priority; - (*Priority)++; - } - // - // If the high byte of the DevIndex is 0xFF, it indicates that this devi= ce has been disabled. - // - for (Index =3D 0; Index < DevOrderPtr->Length / sizeof (UINT16) - 1; Ind= ex++) { - if ((DevOrderPtr->Data[Index] & 0xFF00) =3D=3D 0xFF00) { - // - // LocalBbsTable[DevIndex[Index] & 0xFF].BootPriority =3D BBS_DISABL= ED_ENTRY; - // - } else if (DevOrderPtr->Data[Index] !=3D BbsIndex) { - LocalBbsTable[DevOrderPtr->Data[Index]].BootPriority =3D *Priority; - (*Priority)++; - } - } - - FreePool (DevOrder); - return EFI_SUCCESS; -} - -/** - Print the BBS Table. - - @param LocalBbsTable The BBS table. - @param BbsCount The count of entry in BBS table. -**/ -VOID -PrintBbsTable ( - IN BBS_TABLE *LocalBbsTable, - IN UINT16 BbsCount - ) -{ - UINT16 Idx; - - DEBUG ((DEBUG_ERROR, "\n")); - DEBUG ((DEBUG_ERROR, " NO Prio bb/dd/ff cl/sc Type Stat segm:offs\n")); - DEBUG ((DEBUG_ERROR, "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D\n")); - for (Idx =3D 0; Idx < BbsCount; Idx++) { - if ((LocalBbsTable[Idx].BootPriority =3D=3D BBS_IGNORE_ENTRY) || - (LocalBbsTable[Idx].BootPriority =3D=3D BBS_DO_NOT_BOOT_FROM) || - (LocalBbsTable[Idx].BootPriority =3D=3D BBS_LOWEST_PRIORITY) - ) { - continue; - } - - DEBUG ( - (DEBUG_ERROR, - " %02x: %04x %02x/%02x/%02x %02x/%02x %04x %04x %04x:%04x\n", - (UINTN) Idx, - (UINTN) LocalBbsTable[Idx].BootPriority, - (UINTN) LocalBbsTable[Idx].Bus, - (UINTN) LocalBbsTable[Idx].Device, - (UINTN) LocalBbsTable[Idx].Function, - (UINTN) LocalBbsTable[Idx].Class, - (UINTN) LocalBbsTable[Idx].SubClass, - (UINTN) LocalBbsTable[Idx].DeviceType, - (UINTN) * (UINT16 *) &LocalBbsTable[Idx].StatusFlags, - (UINTN) LocalBbsTable[Idx].BootHandlerSegment, - (UINTN) LocalBbsTable[Idx].BootHandlerOffset, - (UINTN) ((LocalBbsTable[Idx].MfgStringSegment << 4) + LocalBbsTable[= Idx].MfgStringOffset), - (UINTN) ((LocalBbsTable[Idx].DescStringSegment << 4) + LocalBbsTable= [Idx].DescStringOffset)) - ); - } - - DEBUG ((DEBUG_ERROR, "\n")); -} - -/** - Set the boot priority for BBS entries based on boot option entry and boo= t order. - - @param Entry The boot option is to be checked for refresh B= BS table. - =20 - @retval EFI_SUCCESS The boot priority for BBS entries is refre= shed successfully. - @retval EFI_NOT_FOUND BBS entries can't be found. - @retval EFI_OUT_OF_RESOURCES Failed to get the legacy device boot order. -**/ -EFI_STATUS -EFIAPI -BdsRefreshBbsTableForBoot ( - IN BDS_COMMON_OPTION *Entry - ) -{ - EFI_STATUS Status; - UINT16 BbsIndex; - UINT16 HddCount; - UINT16 BbsCount; - HDD_INFO *LocalHddInfo; - BBS_TABLE *LocalBbsTable; - UINT16 DevType; - EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - UINTN Index; - UINT16 Priority; - UINT16 *BootOrder; - UINTN BootOrderSize; - UINT8 *BootOptionVar; - UINTN BootOptionSize; - CHAR16 BootOption[9]; - UINT8 *Ptr; - UINT16 DevPathLen; - EFI_DEVICE_PATH_PROTOCOL *DevPath; - UINT16 *DeviceType; - UINTN DeviceTypeCount; - UINTN DeviceTypeIndex; - - HddCount =3D 0; - BbsCount =3D 0; - LocalHddInfo =3D NULL; - LocalBbsTable =3D NULL; - DevType =3D BBS_UNKNOWN; - - Status =3D gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL= , (VOID **) &LegacyBios); - if (EFI_ERROR (Status)) { - return Status; - } - - LegacyBios->GetBbsInfo ( - LegacyBios, - &HddCount, - &LocalHddInfo, - &BbsCount, - &LocalBbsTable - ); - // - // First, set all the present devices' boot priority to BBS_UNPRIORITIZE= D_ENTRY - // We will set them according to the settings setup by user - // - for (Index =3D 0; Index < BbsCount; Index++) { - if (!((BBS_IGNORE_ENTRY =3D=3D LocalBbsTable[Index].BootPriority) || - (BBS_DO_NOT_BOOT_FROM =3D=3D LocalBbsTable[Index].BootPriority) || - (BBS_LOWEST_PRIORITY =3D=3D LocalBbsTable[Index].BootPriority))) { - LocalBbsTable[Index].BootPriority =3D BBS_UNPRIORITIZED_ENTRY; - } - } - // - // boot priority always starts at 0 - // - Priority =3D 0; - if (Entry->LoadOptionsSize =3D=3D sizeof (BBS_TABLE) + sizeof (UINT16)) { - // - // If Entry stands for a legacy boot option, we prioritize the devices= with the same type first. - // - DevType =3D ((BBS_TABLE *) Entry->LoadOptions)->DeviceType; - BbsIndex =3D *(UINT16 *) ((BBS_TABLE *) Entry->LoadOptions + 1); - Status =3D BdsSetBootPriority4SameTypeDev ( - DevType, - BbsIndex, - LocalBbsTable, - &Priority - ); - if (EFI_ERROR (Status)) { - return Status; - } - } - // - // we have to set the boot priority for other BBS entries with different= device types - // - BootOrder =3D BdsLibGetVariableAndSize ( - L"BootOrder", - &gEfiGlobalVariableGuid, - &BootOrderSize - ); - DeviceType =3D AllocatePool (BootOrderSize + sizeof (UINT16)); - ASSERT (DeviceType !=3D NULL); - - DeviceType[0] =3D DevType; - DeviceTypeCount =3D 1; - for (Index =3D 0; ((BootOrder !=3D NULL) && (Index < BootOrderSize / siz= eof (UINT16))); Index++) { - UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder= [Index]); - BootOptionVar =3D BdsLibGetVariableAndSize ( - BootOption, - &gEfiGlobalVariableGuid, - &BootOptionSize - ); - if (NULL =3D=3D BootOptionVar) { - continue; - } - - Ptr =3D BootOptionVar; - - Ptr +=3D sizeof (UINT32); - DevPathLen =3D *(UINT16 *) Ptr; - Ptr +=3D sizeof (UINT16); - Ptr +=3D StrSize ((UINT16 *) Ptr); - DevPath =3D (EFI_DEVICE_PATH_PROTOCOL *) Ptr; - if (BBS_DEVICE_PATH !=3D DevPath->Type || BBS_BBS_DP !=3D DevPath->Sub= Type) { - FreePool (BootOptionVar); - continue; - } - - Ptr +=3D DevPathLen; - DevType =3D ((BBS_TABLE *) Ptr)->DeviceType; - for (DeviceTypeIndex =3D 0; DeviceTypeIndex < DeviceTypeCount; DeviceT= ypeIndex++) { - if (DeviceType[DeviceTypeIndex] =3D=3D DevType) { - break; - } - } - if (DeviceTypeIndex < DeviceTypeCount) { - // - // We don't want to process twice for a device type - // - FreePool (BootOptionVar); - continue; - } - - DeviceType[DeviceTypeCount] =3D DevType; - DeviceTypeCount++; - - Status =3D BdsSetBootPriority4SameTypeDev ( - DevType, - (UINTN) -1, - LocalBbsTable, - &Priority - ); - FreePool (BootOptionVar); - if (EFI_ERROR (Status)) { - break; - } - } - - FreePool (DeviceType); - - if (BootOrder !=3D NULL) { - FreePool (BootOrder); - } - - DEBUG_CODE_BEGIN(); - PrintBbsTable (LocalBbsTable, BbsCount); - DEBUG_CODE_END(); - - return Status; -} - -/** - Boot the legacy system with the boot option - - @param Option The legacy boot option which have BBS dev= ice path - - @retval EFI_UNSUPPORTED There is no legacybios protocol, do not s= upport - legacy boot. - @retval EFI_STATUS Return the status of LegacyBios->LegacyBo= ot (). - -**/ -EFI_STATUS -BdsLibDoLegacyBoot ( - IN BDS_COMMON_OPTION *Option - ) -{ - EFI_STATUS Status; - EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - EFI_EVENT LegacyBootEvent; - - Status =3D gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID= **) &LegacyBios); - if (EFI_ERROR (Status)) { - // - // If no LegacyBios protocol we do not support legacy boot - // - return EFI_UNSUPPORTED; - } - // - // Notes: if we separate the int 19, then we don't need to refresh BBS - // - BdsRefreshBbsTableForBoot (Option); - - // - // Write boot to OS performance data for legacy boot. - // - PERF_CODE ( - // - // Create an event to be signalled when Legacy Boot occurs to write pe= rformance data. - // - Status =3D EfiCreateEventLegacyBootEx( - TPL_NOTIFY, - BmEndOfBdsPerfCode, - NULL,=20 - &LegacyBootEvent - ); - ASSERT_EFI_ERROR (Status); - ); - - DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Legacy Boot: %S\n", Option->Descriptio= n)); - return LegacyBios->LegacyBoot ( - LegacyBios, - (BBS_BBS_DEVICE_PATH *) Option->DevicePath, - Option->LoadOptionsSize, - Option->LoadOptions - ); -} - -/** - Internal function to check if the input boot option is a valid EFI NV Bo= ot####. - - @param OptionToCheck Boot option to be checked. - - @retval TRUE This boot option matches a valid EFI NV Boot####. - @retval FALSE If not. - -**/ -BOOLEAN -IsBootOptionValidNVVarialbe ( - IN BDS_COMMON_OPTION *OptionToCheck - ) -{ - LIST_ENTRY TempList; - BDS_COMMON_OPTION *BootOption; - BOOLEAN Valid; - CHAR16 OptionName[20]; - - Valid =3D FALSE; - - InitializeListHead (&TempList); - UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", OptionToChe= ck->BootCurrent); - - BootOption =3D BdsLibVariableToOption (&TempList, OptionName); - if (BootOption =3D=3D NULL) { - return FALSE; - } - - // - // If the Boot Option Number and Device Path matches, OptionToCheck matc= hes a - // valid EFI NV Boot####. - // - if ((OptionToCheck->BootCurrent =3D=3D BootOption->BootCurrent) && - (CompareMem (OptionToCheck->DevicePath, BootOption->DevicePath, GetD= evicePathSize (OptionToCheck->DevicePath)) =3D=3D 0)) - { - Valid =3D TRUE; - } - - FreePool (BootOption); - - return Valid; -} - -/** - Check whether a USB device match the specified USB Class device path. Th= is - function follows "Load Option Processing" behavior in UEFI specification. - - @param UsbIo USB I/O protocol associated with the USB device. - @param UsbClass The USB Class device path to match. - - @retval TRUE The USB device match the USB Class device path. - @retval FALSE The USB device does not match the USB Class device pa= th. - -**/ -BOOLEAN -BdsMatchUsbClass ( - IN EFI_USB_IO_PROTOCOL *UsbIo, - IN USB_CLASS_DEVICE_PATH *UsbClass - ) -{ - EFI_STATUS Status; - EFI_USB_DEVICE_DESCRIPTOR DevDesc; - EFI_USB_INTERFACE_DESCRIPTOR IfDesc; - UINT8 DeviceClass; - UINT8 DeviceSubClass; - UINT8 DeviceProtocol; - - if ((DevicePathType (UsbClass) !=3D MESSAGING_DEVICE_PATH) || - (DevicePathSubType (UsbClass) !=3D MSG_USB_CLASS_DP)){ - return FALSE; - } - - // - // Check Vendor Id and Product Id. - // - Status =3D UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc); - if (EFI_ERROR (Status)) { - return FALSE; - } - - if ((UsbClass->VendorId !=3D 0xffff) && - (UsbClass->VendorId !=3D DevDesc.IdVendor)) { - return FALSE; - } - - if ((UsbClass->ProductId !=3D 0xffff) && - (UsbClass->ProductId !=3D DevDesc.IdProduct)) { - return FALSE; - } - - DeviceClass =3D DevDesc.DeviceClass; - DeviceSubClass =3D DevDesc.DeviceSubClass; - DeviceProtocol =3D DevDesc.DeviceProtocol; - if (DeviceClass =3D=3D 0) { - // - // If Class in Device Descriptor is set to 0, use the Class, SubClass = and - // Protocol in Interface Descriptor instead. - // - Status =3D UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc); - if (EFI_ERROR (Status)) { - return FALSE; - } - - DeviceClass =3D IfDesc.InterfaceClass; - DeviceSubClass =3D IfDesc.InterfaceSubClass; - DeviceProtocol =3D IfDesc.InterfaceProtocol; - } - - // - // Check Class, SubClass and Protocol. - // - if ((UsbClass->DeviceClass !=3D 0xff) && - (UsbClass->DeviceClass !=3D DeviceClass)) { - return FALSE; - } - - if ((UsbClass->DeviceSubClass !=3D 0xff) && - (UsbClass->DeviceSubClass !=3D DeviceSubClass)) { - return FALSE; - } - - if ((UsbClass->DeviceProtocol !=3D 0xff) && - (UsbClass->DeviceProtocol !=3D DeviceProtocol)) { - return FALSE; - } - - return TRUE; -} - -/** - Check whether a USB device match the specified USB WWID device path. This - function follows "Load Option Processing" behavior in UEFI specification. - - @param UsbIo USB I/O protocol associated with the USB device. - @param UsbWwid The USB WWID device path to match. - - @retval TRUE The USB device match the USB WWID device path. - @retval FALSE The USB device does not match the USB WWID device pat= h. - -**/ -BOOLEAN -BdsMatchUsbWwid ( - IN EFI_USB_IO_PROTOCOL *UsbIo, - IN USB_WWID_DEVICE_PATH *UsbWwid - ) -{ - EFI_STATUS Status; - EFI_USB_DEVICE_DESCRIPTOR DevDesc; - EFI_USB_INTERFACE_DESCRIPTOR IfDesc; - UINT16 *LangIdTable; - UINT16 TableSize; - UINT16 Index; - CHAR16 *CompareStr; - UINTN CompareLen; - CHAR16 *SerialNumberStr; - UINTN Length; - - if ((DevicePathType (UsbWwid) !=3D MESSAGING_DEVICE_PATH) || - (DevicePathSubType (UsbWwid) !=3D MSG_USB_WWID_DP )){ - return FALSE; - } - - // - // Check Vendor Id and Product Id. - // - Status =3D UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc); - if (EFI_ERROR (Status)) { - return FALSE; - } - if ((DevDesc.IdVendor !=3D UsbWwid->VendorId) || - (DevDesc.IdProduct !=3D UsbWwid->ProductId)) { - return FALSE; - } - - // - // Check Interface Number. - // - Status =3D UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc); - if (EFI_ERROR (Status)) { - return FALSE; - } - if (IfDesc.InterfaceNumber !=3D UsbWwid->InterfaceNumber) { - return FALSE; - } - - // - // Check Serial Number. - // - if (DevDesc.StrSerialNumber =3D=3D 0) { - return FALSE; - } - - // - // Get all supported languages. - // - TableSize =3D 0; - LangIdTable =3D NULL; - Status =3D UsbIo->UsbGetSupportedLanguages (UsbIo, &LangIdTable, &TableS= ize); - if (EFI_ERROR (Status) || (TableSize =3D=3D 0) || (LangIdTable =3D=3D NU= LL)) { - return FALSE; - } - - // - // Serial number in USB WWID device path is the last 64-or-less UTF-16 c= haracters. - // - CompareStr =3D (CHAR16 *) (UINTN) (UsbWwid + 1); - CompareLen =3D (DevicePathNodeLength (UsbWwid) - sizeof (USB_WWID_DEVICE= _PATH)) / sizeof (CHAR16); - if (CompareStr[CompareLen - 1] =3D=3D L'\0') { - CompareLen--; - } - - // - // Compare serial number in each supported language. - // - for (Index =3D 0; Index < TableSize / sizeof (UINT16); Index++) { - SerialNumberStr =3D NULL; - Status =3D UsbIo->UsbGetStringDescriptor ( - UsbIo, - LangIdTable[Index], - DevDesc.StrSerialNumber, - &SerialNumberStr - ); - if (EFI_ERROR (Status) || (SerialNumberStr =3D=3D NULL)) { - continue; - } - - Length =3D StrLen (SerialNumberStr); - if ((Length >=3D CompareLen) && - (CompareMem (SerialNumberStr + Length - CompareLen, CompareStr, Co= mpareLen * sizeof (CHAR16)) =3D=3D 0)) { - FreePool (SerialNumberStr); - return TRUE; - } - - FreePool (SerialNumberStr); - } - - return FALSE; -} - -/** - Find a USB device path which match the specified short-form device path = start - with USB Class or USB WWID device path and load the boot file then retur= n the=20 - image handle. If ParentDevicePath is NULL, this function will search in = all USB - devices of the platform. If ParentDevicePath is not NULL,this function w= ill only - search in its child devices. - - @param ParentDevicePath The device path of the parent. - @param ShortFormDevicePath The USB Class or USB WWID device path to ma= tch. - - @return The image Handle if find load file from specified short-form de= vice path - or NULL if not found. - -**/ -EFI_HANDLE * -BdsFindUsbDevice ( - IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath, - IN EFI_DEVICE_PATH_PROTOCOL *ShortFormDevicePath - ) -{ - EFI_STATUS Status; - UINTN UsbIoHandleCount; - EFI_HANDLE *UsbIoHandleBuffer; - EFI_DEVICE_PATH_PROTOCOL *UsbIoDevicePath; - EFI_USB_IO_PROTOCOL *UsbIo; - UINTN Index; - UINTN ParentSize; - UINTN Size; - EFI_HANDLE ImageHandle; - EFI_HANDLE Handle; - EFI_DEVICE_PATH_PROTOCOL *FullDevicePath; - EFI_DEVICE_PATH_PROTOCOL *NextDevicePath; - - FullDevicePath =3D NULL; - ImageHandle =3D NULL; - - // - // Get all UsbIo Handles. - // - UsbIoHandleCount =3D 0; - UsbIoHandleBuffer =3D NULL; - Status =3D gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiUsbIoProtocolGuid, - NULL, - &UsbIoHandleCount, - &UsbIoHandleBuffer - ); - if (EFI_ERROR (Status) || (UsbIoHandleCount =3D=3D 0) || (UsbIoHandleBuf= fer =3D=3D NULL)) { - return NULL; - } - - ParentSize =3D (ParentDevicePath =3D=3D NULL) ? 0 : GetDevicePathSize (P= arentDevicePath); - for (Index =3D 0; Index < UsbIoHandleCount; Index++) { - // - // Get the Usb IO interface. - // - Status =3D gBS->HandleProtocol( - UsbIoHandleBuffer[Index], - &gEfiUsbIoProtocolGuid, - (VOID **) &UsbIo - ); - if (EFI_ERROR (Status)) { - continue; - } - - UsbIoDevicePath =3D DevicePathFromHandle (UsbIoHandleBuffer[Index]); - if (UsbIoDevicePath =3D=3D NULL) { - continue; - } - - if (ParentDevicePath !=3D NULL) { - // - // Compare starting part of UsbIoHandle's device path with ParentDev= icePath. - // - Size =3D GetDevicePathSize (UsbIoDevicePath); - if ((Size < ParentSize) || - (CompareMem (UsbIoDevicePath, ParentDevicePath, ParentSize - END= _DEVICE_PATH_LENGTH) !=3D 0)) { - continue; - } - } - - if (BdsMatchUsbClass (UsbIo, (USB_CLASS_DEVICE_PATH *) ShortFormDevice= Path) || - BdsMatchUsbWwid (UsbIo, (USB_WWID_DEVICE_PATH *) ShortFormDevicePa= th)) { - // - // Try to find if there is the boot file in this DevicePath - // - NextDevicePath =3D NextDevicePathNode (ShortFormDevicePath); - if (!IsDevicePathEnd (NextDevicePath)) { - FullDevicePath =3D AppendDevicePath (UsbIoDevicePath, NextDevicePa= th); - // - // Connect the full device path, so that Simple File System protoc= ol - // could be installed for this USB device. - // - BdsLibConnectDevicePath (FullDevicePath); - REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOs= LoaderLoad)); - Status =3D gBS->LoadImage ( - TRUE, - gImageHandle, - FullDevicePath, - NULL, - 0, - &ImageHandle - ); - FreePool (FullDevicePath); - } else { - FullDevicePath =3D UsbIoDevicePath; - Status =3D EFI_NOT_FOUND; - } - - // - // If we didn't find an image directly, we need to try as if it is a= removable device boot option - // and load the image according to the default boot behavior for rem= ovable device. - // - if (EFI_ERROR (Status)) { - // - // check if there is a bootable removable media could be found in = this device path , - // and get the bootable media handle - // - Handle =3D BdsLibGetBootableHandle(UsbIoDevicePath); - if (Handle =3D=3D NULL) { - continue; - } - // - // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from= removable Media - // machinename is ia32, ia64, x64, ... - // - FullDevicePath =3D FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FIL= E_NAME); - if (FullDevicePath !=3D NULL) { - REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCode= OsLoaderLoad)); - Status =3D gBS->LoadImage ( - TRUE, - gImageHandle, - FullDevicePath, - NULL, - 0, - &ImageHandle - ); - if (EFI_ERROR (Status)) { - // - // The DevicePath failed, and it's not a valid - // removable media device. - // - continue; - } - } else { - continue; - } - } - break; - } - } - - FreePool (UsbIoHandleBuffer); - return ImageHandle; -} - -/** - Expand USB Class or USB WWID device path node to be full device path of = a USB - device in platform then load the boot file on this full device path and = return the=20 - image handle. - - This function support following 4 cases: - 1) Boot Option device path starts with a USB Class or USB WWID device pa= th, - and there is no Media FilePath device path in the end. - In this case, it will follow Removable Media Boot Behavior. - 2) Boot Option device path starts with a USB Class or USB WWID device pa= th, - and ended with Media FilePath device path. - 3) Boot Option device path starts with a full device path to a USB Host = Controller, - contains a USB Class or USB WWID device path node, while not ended wi= th Media - FilePath device path. In this case, it will follow Removable Media Bo= ot Behavior. - 4) Boot Option device path starts with a full device path to a USB Host = Controller, - contains a USB Class or USB WWID device path node, and ended with Med= ia - FilePath device path. - - @param DevicePath The Boot Option device path. - - @return The image handle of boot file, or NULL if there is no boot file= found in - the specified USB Class or USB WWID device path. - -**/ -EFI_HANDLE * -BdsExpandUsbShortFormDevicePath ( - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath - ) -{ - EFI_HANDLE *ImageHandle; - EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; - EFI_DEVICE_PATH_PROTOCOL *ShortFormDevicePath; - - // - // Search for USB Class or USB WWID device path node. - // - ShortFormDevicePath =3D NULL; - ImageHandle =3D NULL; - TempDevicePath =3D DevicePath; - while (!IsDevicePathEnd (TempDevicePath)) { - if ((DevicePathType (TempDevicePath) =3D=3D MESSAGING_DEVICE_PATH) && - ((DevicePathSubType (TempDevicePath) =3D=3D MSG_USB_CLASS_DP) || - (DevicePathSubType (TempDevicePath) =3D=3D MSG_USB_WWID_DP))) { - ShortFormDevicePath =3D TempDevicePath; - break; - } - TempDevicePath =3D NextDevicePathNode (TempDevicePath); - } - - if (ShortFormDevicePath =3D=3D NULL) { - // - // No USB Class or USB WWID device path node found, do nothing. - // - return NULL; - } - - if (ShortFormDevicePath =3D=3D DevicePath) { - // - // Boot Option device path starts with USB Class or USB WWID device pa= th. - // - ImageHandle =3D BdsFindUsbDevice (NULL, ShortFormDevicePath); - if (ImageHandle =3D=3D NULL) { - // - // Failed to find a match in existing devices, connect the short for= m USB - // device path and try again. - // - BdsLibConnectUsbDevByShortFormDP (0xff, ShortFormDevicePath); - ImageHandle =3D BdsFindUsbDevice (NULL, ShortFormDevicePath); - } - } else { - // - // Boot Option device path contains USB Class or USB WWID device path = node. - // - - // - // Prepare the parent device path for search. - // - TempDevicePath =3D DuplicateDevicePath (DevicePath); - ASSERT (TempDevicePath !=3D NULL); - SetDevicePathEndNode (((UINT8 *) TempDevicePath) + ((UINTN) ShortFormD= evicePath - (UINTN) DevicePath)); - - // - // The USB Host Controller device path is already in Boot Option devic= e path - // and USB Bus driver already support RemainingDevicePath starts with = USB - // Class or USB WWID device path, so just search in existing USB devic= es and - // doesn't perform ConnectController here. - // - ImageHandle =3D BdsFindUsbDevice (TempDevicePath, ShortFormDevicePath); - FreePool (TempDevicePath); - } - - return ImageHandle; -} - -/** - Process the boot option follow the UEFI specification and - special treat the legacy boot option with BBS_DEVICE_PATH. - - @param Option The boot option need to be processed - @param DevicePath The device path which describe where to l= oad the - boot image or the legacy BBS device path = to boot - the legacy OS - @param ExitDataSize The size of exit data. - @param ExitData Data returned when Boot image failed. - - @retval EFI_SUCCESS Boot from the input boot option successfu= lly. - @retval EFI_NOT_FOUND If the Device Path is not found in the sy= stem - -**/ -EFI_STATUS -EFIAPI -BdsLibBootViaBootOption ( - IN BDS_COMMON_OPTION *Option, - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, - OUT UINTN *ExitDataSize, - OUT CHAR16 **ExitData OPTIONAL - ) -{ - EFI_STATUS Status; - EFI_STATUS StatusLogo; - EFI_HANDLE Handle; - EFI_HANDLE ImageHandle; - EFI_DEVICE_PATH_PROTOCOL *FilePath; - EFI_LOADED_IMAGE_PROTOCOL *ImageInfo; - EFI_DEVICE_PATH_PROTOCOL *WorkingDevicePath; - EFI_ACPI_S3_SAVE_PROTOCOL *AcpiS3Save; - LIST_ENTRY TempBootLists; - EFI_BOOT_LOGO_PROTOCOL *BootLogo; - - *ExitDataSize =3D 0; - *ExitData =3D NULL; - - // - // Notes: this code can be remove after the s3 script table - // hook on the event EVT_SIGNAL_READY_TO_BOOT or - // EVT_SIGNAL_LEGACY_BOOT - // - Status =3D gBS->LocateProtocol (&gEfiAcpiS3SaveProtocolGuid, NULL, (VOID= **) &AcpiS3Save); - if (!EFI_ERROR (Status)) { - AcpiS3Save->S3Save (AcpiS3Save, NULL); - } - // - // If it's Device Path that starts with a hard drive path, append it wit= h the front part to compose a - // full device path - // - WorkingDevicePath =3D NULL; - if ((DevicePathType (DevicePath) =3D=3D MEDIA_DEVICE_PATH) && - (DevicePathSubType (DevicePath) =3D=3D MEDIA_HARDDRIVE_DP)) { - WorkingDevicePath =3D BdsExpandPartitionPartialDevicePathToFull ( - (HARDDRIVE_DEVICE_PATH *)DevicePath - ); - if (WorkingDevicePath !=3D NULL) { - DevicePath =3D WorkingDevicePath; - } - } - - // - // Set Boot Current - // - if (IsBootOptionValidNVVarialbe (Option)) { - // - // For a temporary boot (i.e. a boot by selected a EFI Shell using "Bo= ot From File"), Boot Current is actually not valid. - // In this case, "BootCurrent" is not created. - // Only create the BootCurrent variable when it points to a valid Boot= #### variable. - // - SetVariableAndReportStatusCodeOnError ( - L"BootCurrent", - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - sizeof (UINT16), - &Option->BootCurrent - ); - } - - // - // Report Status Code to indicate ReadyToBoot event will be signalled - // - REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI= _SW_DXE_BS_PC_READY_TO_BOOT_EVENT)); - - // - // Signal the EVT_SIGNAL_READY_TO_BOOT event - // - EfiSignalEventReadyToBoot(); - - // - // Expand USB Class or USB WWID device path node to be full device path = of a USB - // device in platform then load the boot file on this full device path a= nd get the - // image handle. - // - ImageHandle =3D BdsExpandUsbShortFormDevicePath (DevicePath); - - // - // Adjust the different type memory page number just before booting - // and save the updated info into the variable for next boot to use - // - BdsSetMemoryTypeInformationVariable (); - - // - // By expanding the USB Class or WWID device path, the ImageHandle has r= eturnned. - // Here get the ImageHandle for the non USB class or WWID device path. - // - if (ImageHandle =3D=3D NULL) { - ASSERT (Option->DevicePath !=3D NULL); - if ((DevicePathType (Option->DevicePath) =3D=3D BBS_DEVICE_PATH) && - (DevicePathSubType (Option->DevicePath) =3D=3D BBS_BBS_DP) - ) { - // - // Check to see if we should legacy BOOT. If yes then do the legacy = boot - // - return BdsLibDoLegacyBoot (Option); - } - - // - // If the boot option point to Internal FV shell, make sure it is valid - // - Status =3D BdsLibUpdateFvFileDevicePath (&DevicePath, &gUefiShellFileG= uid); - if (!EFI_ERROR(Status)) { - if (Option->DevicePath !=3D NULL) { - FreePool(Option->DevicePath); - } - Option->DevicePath =3D AllocateZeroPool (GetDevicePathSize (DeviceP= ath)); - ASSERT(Option->DevicePath !=3D NULL); - CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePa= th)); - // - // Update the shell boot option - // - InitializeListHead (&TempBootLists); - BdsLibRegisterNewOption (&TempBootLists, DevicePath, L"EFI Internal = Shell", L"BootOrder"); - - // - // free the temporary device path created by BdsLibUpdateFvFileDevic= ePath() - // - FreePool (DevicePath); - DevicePath =3D Option->DevicePath; - } - - DEBUG_CODE_BEGIN(); - - if (Option->Description =3D=3D NULL) { - DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Booting from unknown device path\n= ")); - } else { - DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Booting %S\n", Option->Description= )); - } - =20 - DEBUG_CODE_END(); - =20 - // - // Report status code for OS Loader LoadImage. - // - REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoad= erLoad)); - Status =3D gBS->LoadImage ( - TRUE, - gImageHandle, - DevicePath, - NULL, - 0, - &ImageHandle - ); - - // - // If we didn't find an image directly, we need to try as if it is a r= emovable device boot option - // and load the image according to the default boot behavior for remov= able device. - // - if (EFI_ERROR (Status)) { - // - // check if there is a bootable removable media could be found in th= is device path , - // and get the bootable media handle - // - Handle =3D BdsLibGetBootableHandle(DevicePath); - if (Handle !=3D NULL) { - // - // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from= removable Media - // machinename is ia32, ia64, x64, ... - // - FilePath =3D FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME= ); - if (FilePath !=3D NULL) { - REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCode= OsLoaderLoad)); - Status =3D gBS->LoadImage ( - TRUE, - gImageHandle, - FilePath, - NULL, - 0, - &ImageHandle - ); - } - } - } - } - // - // Provide the image with it's load options - // - if ((ImageHandle =3D=3D NULL) || (EFI_ERROR(Status))) { - // - // Report Status Code to indicate that the failure to load boot option - // - REPORT_STATUS_CODE ( - EFI_ERROR_CODE | EFI_ERROR_MINOR, - (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_BOOT_OPTION_LOAD_ERRO= R) - ); =20 - goto Done; - } - - Status =3D gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGui= d, (VOID **) &ImageInfo); - ASSERT_EFI_ERROR (Status); - - if (Option->LoadOptionsSize !=3D 0) { - ImageInfo->LoadOptionsSize =3D Option->LoadOptionsSize; - ImageInfo->LoadOptions =3D Option->LoadOptions; - } - - // - // Clean to NULL because the image is loaded directly from the firmwares= boot manager. - // - ImageInfo->ParentHandle =3D NULL; - - // - // Before calling the image, enable the Watchdog Timer for - // the 5 Minute period - // - gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL); - - // - // Write boot to OS performance data for UEFI boot - // - PERF_CODE ( - BmEndOfBdsPerfCode (NULL, NULL); - ); - - // - // Report status code for OS Loader StartImage. - // - REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoader= Start)); - - Status =3D gBS->StartImage (ImageHandle, ExitDataSize, ExitData); - DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Image Return Status =3D %r\n", Status)= ); - if (EFI_ERROR (Status)) { - // - // Report Status Code to indicate that boot failure - // - REPORT_STATUS_CODE ( - EFI_ERROR_CODE | EFI_ERROR_MINOR, - (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_BOOT_OPTION_FAILED) - ); - } - - // - // Clear the Watchdog Timer after the image returns - // - gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL); - -Done: - // - // Set Logo status invalid after trying one boot option - // - BootLogo =3D NULL; - StatusLogo =3D gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VO= ID **) &BootLogo); - if (!EFI_ERROR (StatusLogo) && (BootLogo !=3D NULL)) { - BootLogo->SetBootLogo (BootLogo, NULL, 0, 0, 0, 0); - } - - // - // Clear Boot Current - // Deleting variable with current implementation shouldn't fail. - // - gRT->SetVariable ( - L"BootCurrent", - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - 0, - NULL - ); - - return Status; -} - - -/** - Expand a device path that starts with a hard drive media device path nod= e to be a - full device path that includes the full hardware path to the device. We = need - to do this so it can be booted. As an optimization the front match (the = part point - to the partition node. E.g. ACPI() /PCI()/ATA()/Partition() ) is saved i= n a variable - so a connect all is not required on every boot. All successful history d= evice path - which point to partition node (the front part) will be saved. - - @param HardDriveDevicePath EFI Device Path to boot, if it starts wit= h a hard - drive media device path. - @return A Pointer to the full device path or NULL if a valid Hard Drive = devic path - cannot be found. - -**/ -EFI_DEVICE_PATH_PROTOCOL * -EFIAPI -BdsExpandPartitionPartialDevicePathToFull ( - IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath - ) -{ - EFI_STATUS Status; - UINTN BlockIoHandleCount; - EFI_HANDLE *BlockIoBuffer; - EFI_DEVICE_PATH_PROTOCOL *FullDevicePath; - EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - UINTN Index; - UINTN InstanceNum; - EFI_DEVICE_PATH_PROTOCOL *CachedDevicePath; - EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath; - UINTN CachedDevicePathSize; - BOOLEAN DeviceExist; - BOOLEAN NeedAdjust; - EFI_DEVICE_PATH_PROTOCOL *Instance; - UINTN Size; - - FullDevicePath =3D NULL; - // - // Check if there is prestore HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable. - // If exist, search the front path which point to partition node in the = variable instants. - // If fail to find or HD_BOOT_DEVICE_PATH_VARIABLE_NAME not exist, recon= nect all and search in all system - // - GetVariable2 ( - HD_BOOT_DEVICE_PATH_VARIABLE_NAME, - &gHdBootDevicePathVariablGuid, - (VOID **) &CachedDevicePath, - &CachedDevicePathSize - ); - - // - // Delete the invalid HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable. - // - if ((CachedDevicePath !=3D NULL) && !IsDevicePathValid (CachedDevicePath= , CachedDevicePathSize)) { - FreePool (CachedDevicePath); - CachedDevicePath =3D NULL; - Status =3D gRT->SetVariable ( - HD_BOOT_DEVICE_PATH_VARIABLE_NAME, - &gHdBootDevicePathVariablGuid, - 0, - 0, - NULL - ); - ASSERT_EFI_ERROR (Status); - } - - if (CachedDevicePath !=3D NULL) { - TempNewDevicePath =3D CachedDevicePath; - DeviceExist =3D FALSE; - NeedAdjust =3D FALSE; - do { - // - // Check every instance of the variable - // First, check whether the instance contain the partition node, whi= ch is needed for distinguishing multi - // partial partition boot option. Second, check whether the instance= could be connected. - // - Instance =3D GetNextDevicePathInstance (&TempNewDevicePath, &Size); - if (MatchPartitionDevicePathNode (Instance, HardDriveDevicePath)) { - // - // Connect the device path instance, the device path point to hard= drive media device path node - // e.g. ACPI() /PCI()/ATA()/Partition() - // - Status =3D BdsLibConnectDevicePath (Instance); - if (!EFI_ERROR (Status)) { - DeviceExist =3D TRUE; - break; - } - } - // - // Come here means the first instance is not matched - // - NeedAdjust =3D TRUE; - FreePool(Instance); - } while (TempNewDevicePath !=3D NULL); - - if (DeviceExist) { - // - // Find the matched device path. - // Append the file path information from the boot option and return = the fully expanded device path. - // - DevicePath =3D NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) = HardDriveDevicePath); - FullDevicePath =3D AppendDevicePath (Instance, DevicePath); - - // - // Adjust the HD_BOOT_DEVICE_PATH_VARIABLE_NAME instances sequence i= f the matched one is not first one. - // - if (NeedAdjust) { - // - // First delete the matched instance. - // - TempNewDevicePath =3D CachedDevicePath; - CachedDevicePath =3D BdsLibDelPartMatchInstance (CachedDevicePath= , Instance ); - FreePool (TempNewDevicePath); - - // - // Second, append the remaining path after the matched instance - // - TempNewDevicePath =3D CachedDevicePath; - CachedDevicePath =3D AppendDevicePathInstance (Instance, CachedDev= icePath ); - FreePool (TempNewDevicePath); - // - // Save the matching Device Path so we don't need to do a connect = all next time - // Failure to set the variable only impacts the performance when n= ext time expanding the short-form device path. - // - Status =3D gRT->SetVariable ( - HD_BOOT_DEVICE_PATH_VARIABLE_NAME, - &gHdBootDevicePathVariablGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON= _VOLATILE, - GetDevicePathSize (CachedDevicePath), - CachedDevicePath - ); - } - - FreePool (Instance); - FreePool (CachedDevicePath); - return FullDevicePath; - } - } - - // - // If we get here we fail to find or HD_BOOT_DEVICE_PATH_VARIABLE_NAME n= ot exist, and now we need - // to search all devices in the system for a matched partition - // - BdsLibConnectAllDriversToAllControllers (); - Status =3D gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid= , NULL, &BlockIoHandleCount, &BlockIoBuffer); - if (EFI_ERROR (Status) || BlockIoHandleCount =3D=3D 0 || BlockIoBuffer = =3D=3D NULL) { - // - // If there was an error or there are no device handles that support - // the BLOCK_IO Protocol, then return. - // - return NULL; - } - // - // Loop through all the device handles that support the BLOCK_IO Protocol - // - for (Index =3D 0; Index < BlockIoHandleCount; Index++) { - - Status =3D gBS->HandleProtocol (BlockIoBuffer[Index], &gEfiDevicePathP= rotocolGuid, (VOID *) &BlockIoDevicePath); - if (EFI_ERROR (Status) || BlockIoDevicePath =3D=3D NULL) { - continue; - } - - if (MatchPartitionDevicePathNode (BlockIoDevicePath, HardDriveDevicePa= th)) { - // - // Find the matched partition device path - // - DevicePath =3D NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) H= ardDriveDevicePath); - FullDevicePath =3D AppendDevicePath (BlockIoDevicePath, DevicePath); - - // - // Save the matched partition device path in HD_BOOT_DEVICE_PATH_VAR= IABLE_NAME variable - // - if (CachedDevicePath !=3D NULL) { - // - // Save the matched partition device path as first instance of HD_= BOOT_DEVICE_PATH_VARIABLE_NAME variable - // - if (BdsLibMatchDevicePaths (CachedDevicePath, BlockIoDevicePath)) { - TempNewDevicePath =3D CachedDevicePath; - CachedDevicePath =3D BdsLibDelPartMatchInstance (CachedDevicePat= h, BlockIoDevicePath); - FreePool(TempNewDevicePath); - } - - if (CachedDevicePath !=3D NULL) { - TempNewDevicePath =3D CachedDevicePath; - CachedDevicePath =3D AppendDevicePathInstance (BlockIoDevicePath= , CachedDevicePath); - FreePool(TempNewDevicePath); - } else { - CachedDevicePath =3D DuplicateDevicePath (BlockIoDevicePath); - } - - // - // Here limit the device path instance number to 12, which is max = number for a system support 3 IDE controller - // If the user try to boot many OS in different HDs or partitions,= in theory,=20 - // the HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable maybe become lar= ger and larger. - // - InstanceNum =3D 0; - ASSERT (CachedDevicePath !=3D NULL); - TempNewDevicePath =3D CachedDevicePath; - while (!IsDevicePathEnd (TempNewDevicePath)) { - TempNewDevicePath =3D NextDevicePathNode (TempNewDevicePath); - // - // Parse one instance - // - while (!IsDevicePathEndType (TempNewDevicePath)) { - TempNewDevicePath =3D NextDevicePathNode (TempNewDevicePath); - } - InstanceNum++; - // - // If the CachedDevicePath variable contain too much instance, o= nly remain 12 instances. - // - if (InstanceNum >=3D 12) { - SetDevicePathEndNode (TempNewDevicePath); - break; - } - } - } else { - CachedDevicePath =3D DuplicateDevicePath (BlockIoDevicePath); - } - - // - // Save the matching Device Path so we don't need to do a connect al= l next time - // Failure to set the variable only impacts the performance when nex= t time expanding the short-form device path. - // - Status =3D gRT->SetVariable ( - HD_BOOT_DEVICE_PATH_VARIABLE_NAME, - &gHdBootDevicePathVariablGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_V= OLATILE, - GetDevicePathSize (CachedDevicePath), - CachedDevicePath - ); - - break; - } - } - - if (CachedDevicePath !=3D NULL) { - FreePool (CachedDevicePath); - } - if (BlockIoBuffer !=3D NULL) { - FreePool (BlockIoBuffer); - } - return FullDevicePath; -} - -/** - Check whether there is a instance in BlockIoDevicePath, which contain mu= lti device path - instances, has the same partition node with HardDriveDevicePath device p= ath - - @param BlockIoDevicePath Multi device path instances which need to= check - @param HardDriveDevicePath A device path which starts with a hard dr= ive media - device path. - - @retval TRUE There is a matched device path instance. - @retval FALSE There is no matched device path instance. - -**/ -BOOLEAN -EFIAPI -MatchPartitionDevicePathNode ( - IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath, - IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath - ) -{ - HARDDRIVE_DEVICE_PATH *TmpHdPath; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - BOOLEAN Match; - EFI_DEVICE_PATH_PROTOCOL *BlockIoHdDevicePathNode; - - if ((BlockIoDevicePath =3D=3D NULL) || (HardDriveDevicePath =3D=3D NULL)= ) { - return FALSE; - } - - // - // Make PreviousDevicePath =3D=3D the device path node before the end no= de - // - DevicePath =3D BlockIoDevicePath; - BlockIoHdDevicePathNode =3D NULL; - - // - // find the partition device path node - // - while (!IsDevicePathEnd (DevicePath)) { - if ((DevicePathType (DevicePath) =3D=3D MEDIA_DEVICE_PATH) && - (DevicePathSubType (DevicePath) =3D=3D MEDIA_HARDDRIVE_DP) - ) { - BlockIoHdDevicePathNode =3D DevicePath; - break; - } - - DevicePath =3D NextDevicePathNode (DevicePath); - } - - if (BlockIoHdDevicePathNode =3D=3D NULL) { - return FALSE; - } - // - // See if the harddrive device path in blockio matches the orig Hard Dri= ve Node - // - TmpHdPath =3D (HARDDRIVE_DEVICE_PATH *) BlockIoHdDevicePathNode; - Match =3D FALSE; - - // - // Check for the match - // - if ((TmpHdPath->MBRType =3D=3D HardDriveDevicePath->MBRType) && - (TmpHdPath->SignatureType =3D=3D HardDriveDevicePath->SignatureType)= ) { - switch (TmpHdPath->SignatureType) { - case SIGNATURE_TYPE_GUID: - Match =3D CompareGuid ((EFI_GUID *)TmpHdPath->Signature, (EFI_GUID *= )HardDriveDevicePath->Signature); - break; - case SIGNATURE_TYPE_MBR: - Match =3D (BOOLEAN)(*((UINT32 *)(&(TmpHdPath->Signature[0]))) =3D=3D= ReadUnaligned32((UINT32 *)(&(HardDriveDevicePath->Signature[0])))); - break; - default: - Match =3D FALSE; - break; - } - } - - return Match; -} - -/** - Delete the boot option associated with the handle passed in. - - @param Handle The handle which present the device path = to create - boot option - - @retval EFI_SUCCESS Delete the boot option success - @retval EFI_NOT_FOUND If the Device Path is not found in the sy= stem - @retval EFI_OUT_OF_RESOURCES Lack of memory resource - @retval Other Error return value from SetVariable() - -**/ -EFI_STATUS -BdsLibDeleteOptionFromHandle ( - IN EFI_HANDLE Handle - ) -{ - UINT16 *BootOrder; - UINT8 *BootOptionVar; - UINTN BootOrderSize; - UINTN BootOptionSize; - EFI_STATUS Status; - UINTN Index; - UINT16 BootOption[BOOT_OPTION_MAX_CHAR]; - UINTN DevicePathSize; - UINTN OptionDevicePathSize; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath; - UINT8 *TempPtr; - - Status =3D EFI_SUCCESS; - BootOrder =3D NULL; - BootOrderSize =3D 0; - - // - // Check "BootOrder" variable, if no, means there is no any boot order. - // - BootOrder =3D BdsLibGetVariableAndSize ( - L"BootOrder", - &gEfiGlobalVariableGuid, - &BootOrderSize - ); - if (BootOrder =3D=3D NULL) { - return EFI_NOT_FOUND; - } - - // - // Convert device handle to device path protocol instance - // - DevicePath =3D DevicePathFromHandle (Handle); - if (DevicePath =3D=3D NULL) { - return EFI_NOT_FOUND; - } - DevicePathSize =3D GetDevicePathSize (DevicePath); - - // - // Loop all boot order variable and find the matching device path - // - Index =3D 0; - while (Index < BootOrderSize / sizeof (UINT16)) { - UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder= [Index]); - BootOptionVar =3D BdsLibGetVariableAndSize ( - BootOption, - &gEfiGlobalVariableGuid, - &BootOptionSize - ); - - if (BootOptionVar =3D=3D NULL) { - FreePool (BootOrder); - return EFI_OUT_OF_RESOURCES; - } - - if (!ValidateOption(BootOptionVar, BootOptionSize)) { - BdsDeleteBootOption (BootOrder[Index], BootOrder, &BootOrderSize); - FreePool (BootOptionVar); - Index++; - continue; - } - - TempPtr =3D BootOptionVar; - TempPtr +=3D sizeof (UINT32) + sizeof (UINT16); - TempPtr +=3D StrSize ((CHAR16 *) TempPtr); - OptionDevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *) TempPtr; - OptionDevicePathSize =3D GetDevicePathSize (OptionDevicePath); - - // - // Check whether the device path match - // - if ((OptionDevicePathSize =3D=3D DevicePathSize) && - (CompareMem (DevicePath, OptionDevicePath, DevicePathSize) =3D=3D = 0)) { - BdsDeleteBootOption (BootOrder[Index], BootOrder, &BootOrderSize); - FreePool (BootOptionVar); - break; - } - - FreePool (BootOptionVar); - Index++; - } - - // - // Adjust number of boot option for "BootOrder" variable. - // - Status =3D gRT->SetVariable ( - L"BootOrder", - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_A= CCESS | EFI_VARIABLE_NON_VOLATILE, - BootOrderSize, - BootOrder - ); - // - // Shrinking variable with existing variable implementation shouldn't fa= il. - // - ASSERT_EFI_ERROR (Status); - - FreePool (BootOrder); - - return Status; -} - - -/** - Delete all invalid EFI boot options. - - @retval EFI_SUCCESS Delete all invalid boot option success - @retval EFI_NOT_FOUND Variable "BootOrder" is not found - @retval EFI_OUT_OF_RESOURCES Lack of memory resource - @retval Other Error return value from SetVariable() - -**/ -EFI_STATUS -BdsDeleteAllInvalidEfiBootOption ( - VOID - ) -{ - UINT16 *BootOrder; - UINT8 *BootOptionVar; - UINTN BootOrderSize; - UINTN BootOptionSize; - EFI_STATUS Status; - UINTN Index; - UINTN Index2; - UINT16 BootOption[BOOT_OPTION_MAX_CHAR]; - EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath; - UINT8 *TempPtr; - CHAR16 *Description; - BOOLEAN Corrupted; - - Status =3D EFI_SUCCESS; - BootOrder =3D NULL; - Description =3D NULL; - OptionDevicePath =3D NULL; - BootOrderSize =3D 0; - Corrupted =3D FALSE; - - // - // Check "BootOrder" variable firstly, this variable hold the number of = boot options - // - BootOrder =3D BdsLibGetVariableAndSize ( - L"BootOrder", - &gEfiGlobalVariableGuid, - &BootOrderSize - ); - if (NULL =3D=3D BootOrder) { - return EFI_NOT_FOUND; - } - - Index =3D 0; - while (Index < BootOrderSize / sizeof (UINT16)) { - UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder= [Index]); - BootOptionVar =3D BdsLibGetVariableAndSize ( - BootOption, - &gEfiGlobalVariableGuid, - &BootOptionSize - ); - if (NULL =3D=3D BootOptionVar) { - FreePool (BootOrder); - return EFI_OUT_OF_RESOURCES; - } - - if (!ValidateOption(BootOptionVar, BootOptionSize)) { - Corrupted =3D TRUE; - } else { - TempPtr =3D BootOptionVar; - TempPtr +=3D sizeof (UINT32) + sizeof (UINT16); - Description =3D (CHAR16 *) TempPtr; - TempPtr +=3D StrSize ((CHAR16 *) TempPtr); - OptionDevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *) TempPtr; - - // - // Skip legacy boot option (BBS boot device) - // - if ((DevicePathType (OptionDevicePath) =3D=3D BBS_DEVICE_PATH) && - (DevicePathSubType (OptionDevicePath) =3D=3D BBS_BBS_DP)) { - FreePool (BootOptionVar); - Index++; - continue; - } - } - - if (Corrupted || !BdsLibIsValidEFIBootOptDevicePathExt (OptionDevicePa= th, FALSE, Description)) { - // - // Delete this invalid boot option "Boot####" - // - Status =3D gRT->SetVariable ( - BootOption, - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTI= ME_ACCESS | EFI_VARIABLE_NON_VOLATILE, - 0, - NULL - ); - // - // Deleting variable with current variable implementation shouldn't = fail. - // - ASSERT_EFI_ERROR (Status); - // - // Mark this boot option in boot order as deleted - // - BootOrder[Index] =3D 0xffff; - Corrupted =3D FALSE; - } - - FreePool (BootOptionVar); - Index++; - } - - // - // Adjust boot order array - // - Index2 =3D 0; - for (Index =3D 0; Index < BootOrderSize / sizeof (UINT16); Index++) { - if (BootOrder[Index] !=3D 0xffff) { - BootOrder[Index2] =3D BootOrder[Index]; - Index2 ++; - } - } - Status =3D gRT->SetVariable ( - L"BootOrder", - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_A= CCESS | EFI_VARIABLE_NON_VOLATILE, - Index2 * sizeof (UINT16), - BootOrder - ); - // - // Shrinking variable with current variable implementation shouldn't fai= l. - // - ASSERT_EFI_ERROR (Status); - - FreePool (BootOrder); - - return Status; -} - - -/** - For EFI boot option, BDS separate them as six types: - 1. Network - The boot option points to the SimpleNetworkProtocol device. - Bds will try to automatically create this type boot option = when enumerate. - 2. Shell - The boot option points to internal flash shell. - Bds will try to automatically create this type boot option = when enumerate. - 3. Removable BlockIo - The boot option only points to the removable= media - device, like USB flash disk, DVD, Floppy etc. - These device should contain a *removable* bl= ockIo - protocol in their device handle. - Bds will try to automatically create this ty= pe boot option - when enumerate. - 4. Fixed BlockIo - The boot option only points to a Fixed block= Io device, - like HardDisk. - These device should contain a *fixed* blockIo - protocol in their device handle. - BDS will skip fixed blockIo devices, and NOT - automatically create boot option for them. B= ut BDS - will help to delete those fixed blockIo boot= option, - whose description rule conflict with other a= uto-created - boot options. - 5. Non-BlockIo Simplefile - The boot option points to a device whose han= dle - has SimpleFileSystem Protocol, but has no bl= ockio - protocol. These devices do not offer blockIo - protocol, but BDS still can get the - \EFI\BOOT\boot{machinename}.EFI by SimpleFil= eSystem - Protocol. - 6. File - The boot option points to a file. These boot options are us= ually - created by user manually or OS loader. BDS will not delete = or modify - these boot options. - - This function will enumerate all possible boot device in the system, and - automatically create boot options for Network, Shell, Removable BlockIo, - and Non-BlockIo Simplefile devices. - It will only execute once of every boot. - - @param BdsBootOptionList The header of the link list which indexed= all - current boot options - - @retval EFI_SUCCESS Finished all the boot device enumerate an= d create - the boot option base on that boot device - - @retval EFI_OUT_OF_RESOURCES Failed to enumerate the boot device and c= reate the boot option list -**/ -EFI_STATUS -EFIAPI -BdsLibEnumerateAllBootOption ( - IN OUT LIST_ENTRY *BdsBootOptionList - ) -{ - EFI_STATUS Status; - UINT16 FloppyNumber; - UINT16 HarddriveNumber; - UINT16 CdromNumber; - UINT16 UsbNumber; - UINT16 MiscNumber; - UINT16 ScsiNumber; - UINT16 NonBlockNumber; - UINTN NumberBlockIoHandles; - EFI_HANDLE *BlockIoHandles; - EFI_BLOCK_IO_PROTOCOL *BlkIo; - BOOLEAN Removable[2]; - UINTN RemovableIndex; - UINTN Index; - UINTN NumOfLoadFileHandles; - EFI_HANDLE *LoadFileHandles; - UINTN FvHandleCount; - EFI_HANDLE *FvHandleBuffer; - EFI_FV_FILETYPE Type; - UINTN Size; - EFI_FV_FILE_ATTRIBUTES Attributes; - UINT32 AuthenticationStatus; - EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - UINTN DevicePathType; - CHAR16 Buffer[40]; - EFI_HANDLE *FileSystemHandles; - UINTN NumberFileSystemHandles; - BOOLEAN NeedDelete; - EFI_IMAGE_DOS_HEADER DosHeader; - CHAR8 *PlatLang; - CHAR8 *LastLang; - EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData; - EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; - CHAR16 *MacStr; - CHAR16 *IPverStr; - EFI_HANDLE *NetworkHandles; - UINTN BufferSize; - - FloppyNumber =3D 0; - HarddriveNumber =3D 0; - CdromNumber =3D 0; - UsbNumber =3D 0; - MiscNumber =3D 0; - ScsiNumber =3D 0; - PlatLang =3D NULL; - LastLang =3D NULL; - ZeroMem (Buffer, sizeof (Buffer)); - - // - // If the boot device enumerate happened, just get the boot - // device from the boot order variable - // - if (mEnumBootDevice) { - GetVariable2 (LAST_ENUM_LANGUAGE_VARIABLE_NAME, &gLastEnumLangGuid, (V= OID**)&LastLang, NULL); - GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatLang, NULL); - ASSERT (PlatLang !=3D NULL); - if ((LastLang !=3D NULL) && (AsciiStrCmp (LastLang, PlatLang) =3D=3D 0= )) { - Status =3D BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder"= ); - FreePool (LastLang); - FreePool (PlatLang); - return Status; - } else { - Status =3D gRT->SetVariable ( - LAST_ENUM_LANGUAGE_VARIABLE_NAME, - &gLastEnumLangGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, - AsciiStrSize (PlatLang), - PlatLang - ); - // - // Failure to set the variable only impacts the performance next tim= e enumerating the boot options. - // - - if (LastLang !=3D NULL) { - FreePool (LastLang); - } - FreePool (PlatLang); - } - } - - // - // Notes: this dirty code is to get the legacy boot option from the - // BBS table and create to variable as the EFI boot option, it should - // be removed after the CSM can provide legacy boot option directly - // - REFRESH_LEGACY_BOOT_OPTIONS; - - // - // Delete invalid boot option - // - BdsDeleteAllInvalidEfiBootOption (); - - // - // Parse removable media followed by fixed media. - // The Removable[] array is used by the for-loop below to create removab= le media boot options=20 - // at first, and then to create fixed media boot options. - // - Removable[0] =3D FALSE; - Removable[1] =3D TRUE; - - gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiBlockIoProtocolGuid, - NULL, - &NumberBlockIoHandles, - &BlockIoHandles - ); - - for (RemovableIndex =3D 0; RemovableIndex < 2; RemovableIndex++) { - for (Index =3D 0; Index < NumberBlockIoHandles; Index++) { - Status =3D gBS->HandleProtocol ( - BlockIoHandles[Index], - &gEfiBlockIoProtocolGuid, - (VOID **) &BlkIo - ); - // - // skip the logical partition - // - if (EFI_ERROR (Status) || BlkIo->Media->LogicalPartition) { - continue; - } - - // - // firstly fixed block io then the removable block io - // - if (BlkIo->Media->RemovableMedia =3D=3D Removable[RemovableIndex]) { - continue; - } - DevicePath =3D DevicePathFromHandle (BlockIoHandles[Index]); - DevicePathType =3D BdsGetBootTypeFromDevicePath (DevicePath); - - switch (DevicePathType) { - case BDS_EFI_ACPI_FLOPPY_BOOT: - if (FloppyNumber !=3D 0) { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStrin= gById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)), FloppyNumber); - } else { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringBy= Id (STRING_TOKEN (STR_DESCRIPTION_FLOPPY))); - } - BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionL= ist, Buffer); - FloppyNumber++; - break; - - // - // Assume a removable SATA device should be the DVD/CD device, a fix= ed SATA device should be the Hard Drive device. - // - case BDS_EFI_MESSAGE_ATAPI_BOOT: - case BDS_EFI_MESSAGE_SATA_BOOT: - if (BlkIo->Media->RemovableMedia) { - if (CdromNumber !=3D 0) { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStr= ingById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)), CdromNumber); - } else { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetString= ById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD))); - } - CdromNumber++; - } else { - if (HarddriveNumber !=3D 0) { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStr= ingById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE)), HarddriveNumber); - } else { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetString= ById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE))); - } - HarddriveNumber++; - } - DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Buffer: %S\n", Buffer)); - BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionL= ist, Buffer); - break; - - case BDS_EFI_MESSAGE_USB_DEVICE_BOOT: - if (UsbNumber !=3D 0) { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStrin= gById (STRING_TOKEN (STR_DESCRIPTION_USB)), UsbNumber); - } else { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringBy= Id (STRING_TOKEN (STR_DESCRIPTION_USB))); - } - BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionL= ist, Buffer); - UsbNumber++; - break; - - case BDS_EFI_MESSAGE_SCSI_BOOT: - if (ScsiNumber !=3D 0) { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStrin= gById (STRING_TOKEN (STR_DESCRIPTION_SCSI)), ScsiNumber); - } else { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringBy= Id (STRING_TOKEN (STR_DESCRIPTION_SCSI))); - } - BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionL= ist, Buffer); - ScsiNumber++; - break; - - case BDS_EFI_MESSAGE_MISC_BOOT: - default: - if (MiscNumber !=3D 0) { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStrin= gById (STRING_TOKEN (STR_DESCRIPTION_MISC)), MiscNumber); - } else { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringBy= Id (STRING_TOKEN (STR_DESCRIPTION_MISC))); - } - BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionL= ist, Buffer); - MiscNumber++; - break; - } - } - } - - if (NumberBlockIoHandles !=3D 0) { - FreePool (BlockIoHandles); - } - - // - // If there is simple file protocol which does not consume block Io prot= ocol, create a boot option for it here. - // - NonBlockNumber =3D 0; - gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiSimpleFileSystemProtocolGuid, - NULL, - &NumberFileSystemHandles, - &FileSystemHandles - ); - for (Index =3D 0; Index < NumberFileSystemHandles; Index++) { - Status =3D gBS->HandleProtocol ( - FileSystemHandles[Index], - &gEfiBlockIoProtocolGuid, - (VOID **) &BlkIo - ); - if (!EFI_ERROR (Status)) { - // - // Skip if the file system handle supports a BlkIo protocol, - // - continue; - } - - // - // Do the removable Media thing. \EFI\BOOT\boot{machinename}.EFI - // machinename is ia32, ia64, x64, ... - // - Hdr.Union =3D &HdrData; - NeedDelete =3D TRUE; - Status =3D BdsLibGetImageHeader ( - FileSystemHandles[Index], - EFI_REMOVABLE_MEDIA_FILE_NAME, - &DosHeader, - Hdr - ); - if (!EFI_ERROR (Status) && - EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) && - Hdr.Pe32->OptionalHeader.Subsystem =3D=3D EFI_IMAGE_SUBSYSTEM_EFI_= APPLICATION) { - NeedDelete =3D FALSE; - } - - if (NeedDelete) { - // - // No such file or the file is not a EFI application, delete this bo= ot option - // - BdsLibDeleteOptionFromHandle (FileSystemHandles[Index]); - } else { - if (NonBlockNumber !=3D 0) { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringB= yId (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)), NonBlockNumber); - } else { - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById= (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK))); - } - BdsLibBuildOptionFromHandle (FileSystemHandles[Index], BdsBootOption= List, Buffer); - NonBlockNumber++; - } - } - - if (NumberFileSystemHandles !=3D 0) { - FreePool (FileSystemHandles); - } - - // - // Parse Network Boot Device - // - NumOfLoadFileHandles =3D 0; - // - // Search Load File protocol for PXE boot option. - // - gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiLoadFileProtocolGuid, - NULL, - &NumOfLoadFileHandles, - &LoadFileHandles - ); - - for (Index =3D 0; Index < NumOfLoadFileHandles; Index++) { - -// -//Locate EFI_DEVICE_PATH_PROTOCOL to dynamically get IPv4/IPv6 protocol in= formation. -// - - Status =3D gBS->HandleProtocol ( - LoadFileHandles[Index], - &gEfiDevicePathProtocolGuid, - (VOID **) &DevicePath - ); - =20 - ASSERT_EFI_ERROR (Status); - - while (!IsDevicePathEnd (DevicePath)) { - if ((DevicePath->Type =3D=3D MESSAGING_DEVICE_PATH) && - (DevicePath->SubType =3D=3D MSG_IPv4_DP)) { - - // - //Get handle infomation - // - BufferSize =3D 0; - NetworkHandles =3D NULL; - Status =3D gBS->LocateHandle ( - ByProtocol,=20 - &gEfiSimpleNetworkProtocolGuid, - NULL, - &BufferSize, - NetworkHandles - ); - - if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { - NetworkHandles =3D AllocateZeroPool(BufferSize); - if (NetworkHandles =3D=3D NULL) { - return (EFI_OUT_OF_RESOURCES); - } - Status =3D gBS->LocateHandle( - ByProtocol, - &gEfiSimpleNetworkProtocolGuid, - NULL, - &BufferSize, - NetworkHandles - ); - } - =20 - // - //Get the MAC string - // - Status =3D NetLibGetMacString ( - *NetworkHandles, - NULL, - &MacStr - ); - if (EFI_ERROR (Status)) {=09 - return Status; - } - IPverStr =3D L" IPv4"; - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%s%s", BdsLibGetStringById (= STRING_TOKEN (STR_DESCRIPTION_NETWORK)),MacStr,IPverStr); - break; - } - if((DevicePath->Type =3D=3D MESSAGING_DEVICE_PATH) && - (DevicePath->SubType =3D=3D MSG_IPv6_DP)) { - - // - //Get handle infomation - // - BufferSize =3D 0; - NetworkHandles =3D NULL; - Status =3D gBS->LocateHandle ( - ByProtocol,=20 - &gEfiSimpleNetworkProtocolGuid, - NULL, - &BufferSize, - NetworkHandles - ); - - if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { - NetworkHandles =3D AllocateZeroPool(BufferSize); - if (NetworkHandles =3D=3D NULL) { - return (EFI_OUT_OF_RESOURCES); - } - Status =3D gBS->LocateHandle( - ByProtocol, - &gEfiSimpleNetworkProtocolGuid, - NULL, - &BufferSize, - NetworkHandles - ); - } - =20 - // - //Get the MAC string - // - Status =3D NetLibGetMacString ( - *NetworkHandles, - NULL, - &MacStr - ); - if (EFI_ERROR (Status)) {=09 - return Status; - } - IPverStr =3D L" IPv6"; - UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%s%s", BdsLibGetStringBy= Id (STRING_TOKEN (STR_DESCRIPTION_NETWORK)),MacStr,IPverStr); - break; - } - DevicePath =3D NextDevicePathNode (DevicePath); - } - =20 - BdsLibBuildOptionFromHandle (LoadFileHandles[Index], BdsBootOptionList= , Buffer); - } - - if (NumOfLoadFileHandles !=3D 0) { - FreePool (LoadFileHandles); - } - - // - // Check if we have on flash shell - // - gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiFirmwareVolume2ProtocolGuid, - NULL, - &FvHandleCount, - &FvHandleBuffer - ); - for (Index =3D 0; Index < FvHandleCount; Index++) { - gBS->HandleProtocol ( - FvHandleBuffer[Index], - &gEfiFirmwareVolume2ProtocolGuid, - (VOID **) &Fv - ); - - Status =3D Fv->ReadFile ( - Fv, - &gUefiShellFileGuid, - NULL, - &Size, - &Type, - &Attributes, - &AuthenticationStatus - ); - if (EFI_ERROR (Status)) { - // - // Skip if no shell file in the FV - // - continue; - } - // - // Build the shell boot option - // - BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList); - } - - if (FvHandleCount !=3D 0) { - FreePool (FvHandleBuffer); - } - // - // Make sure every boot only have one time - // boot device enumerate - // - Status =3D BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder"); - mEnumBootDevice =3D TRUE; - - return Status; -} - -/** - Build the boot option with the handle parsed in - - @param Handle The handle which present the device path = to create - boot option - @param BdsBootOptionList The header of the link list which indexed= all - current boot options - @param String The description of the boot option. - -**/ -VOID -EFIAPI -BdsLibBuildOptionFromHandle ( - IN EFI_HANDLE Handle, - IN LIST_ENTRY *BdsBootOptionList, - IN CHAR16 *String - ) -{ - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - - DevicePath =3D DevicePathFromHandle (Handle); - - // - // Create and register new boot option - // - BdsLibRegisterNewOption (BdsBootOptionList, DevicePath, String, L"BootOr= der"); -} - - -/** - Build the on flash shell boot option with the handle parsed in. - - @param Handle The handle which present the device path = to create - on flash shell boot option - @param BdsBootOptionList The header of the link list which indexed= all - current boot options - -**/ -VOID -EFIAPI -BdsLibBuildOptionFromShell ( - IN EFI_HANDLE Handle, - IN OUT LIST_ENTRY *BdsBootOptionList - ) -{ - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - MEDIA_FW_VOL_FILEPATH_DEVICE_PATH ShellNode; - - DevicePath =3D DevicePathFromHandle (Handle); - - // - // Build the shell device path - // - EfiInitializeFwVolDevicepathNode (&ShellNode, &gUefiShellFileGuid); - - DevicePath =3D AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOC= OL *) &ShellNode); - - // - // Create and register the shell boot option - // - BdsLibRegisterNewOption (BdsBootOptionList, DevicePath, L"EFI Internal S= hell", L"BootOrder"); - -} - -/** - Boot from the UEFI spec defined "BootNext" variable. - -**/ -VOID -EFIAPI -BdsLibBootNext ( - VOID - ) -{ - EFI_STATUS Status; - UINT16 *BootNext; - UINTN BootNextSize; - CHAR16 Buffer[20]; - BDS_COMMON_OPTION *BootOption; - LIST_ENTRY TempList; - UINTN ExitDataSize; - CHAR16 *ExitData; - - // - // Init the boot option name buffer and temp link list - // - InitializeListHead (&TempList); - ZeroMem (Buffer, sizeof (Buffer)); - - BootNext =3D BdsLibGetVariableAndSize ( - L"BootNext", - &gEfiGlobalVariableGuid, - &BootNextSize - ); - - // - // Clear the boot next variable first - // - if (BootNext !=3D NULL) { - Status =3D gRT->SetVariable ( - L"BootNext", - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME= _ACCESS | EFI_VARIABLE_NON_VOLATILE, - 0, - NULL - ); - // - // Deleting variable with current variable implementation shouldn't fa= il. - // - ASSERT_EFI_ERROR (Status); - - // - // Start to build the boot option and try to boot - // - UnicodeSPrint (Buffer, sizeof (Buffer), L"Boot%04x", *BootNext); - BootOption =3D BdsLibVariableToOption (&TempList, Buffer); - ASSERT (BootOption !=3D NULL); - BdsLibConnectDevicePath (BootOption->DevicePath); - BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitData= Size, &ExitData); - FreePool(BootOption); - FreePool(BootNext); - } - -} - -/** - Return the bootable media handle. - First, check the device is connected - Second, check whether the device path point to a device which support Si= mpleFileSystemProtocol, - Third, detect the the default boot file in the Media, and return the rem= ovable Media handle. - - @param DevicePath Device Path to a bootable device - - @return The bootable media handle. If the media on the DevicePath is no= t bootable, NULL will return. - -**/ -EFI_HANDLE -EFIAPI -BdsLibGetBootableHandle ( - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath - ) -{ - EFI_STATUS Status; - EFI_TPL OldTpl; - EFI_DEVICE_PATH_PROTOCOL *UpdatedDevicePath; - EFI_DEVICE_PATH_PROTOCOL *DupDevicePath; - EFI_HANDLE Handle; - EFI_BLOCK_IO_PROTOCOL *BlockIo; - VOID *Buffer; - EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; - UINTN Size; - UINTN TempSize; - EFI_HANDLE ReturnHandle; - EFI_HANDLE *SimpleFileSystemHandles; - - UINTN NumberSimpleFileSystemHandles; - UINTN Index; - EFI_IMAGE_DOS_HEADER DosHeader; - EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData; - EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; - - UpdatedDevicePath =3D DevicePath; - - // - // Enter to critical section to protect the acquired BlockIo instance=20 - // from getting released due to the USB mass storage hotplug event - // - OldTpl =3D gBS->RaiseTPL (TPL_CALLBACK); - - // - // Check whether the device is connected - // - Status =3D gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &UpdatedDevi= cePath, &Handle); - if (EFI_ERROR (Status)) { - // - // Skip the case that the boot option point to a simple file protocol = which does not consume block Io protocol, - // - Status =3D gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &= UpdatedDevicePath, &Handle); - if (EFI_ERROR (Status)) { - // - // Fail to find the proper BlockIo and simple file protocol, maybe b= ecause device not present, we need to connect it firstly - // - UpdatedDevicePath =3D DevicePath; - Status =3D gBS->LocateDevicePath (&gEfiDevicePathProtocol= Guid, &UpdatedDevicePath, &Handle); - gBS->ConnectController (Handle, NULL, NULL, TRUE); - } - } else { - // - // For removable device boot option, its contained device path only po= int to the removable device handle,=20 - // should make sure all its children handles (its child partion or med= ia handles) are created and connected.=20 - // - gBS->ConnectController (Handle, NULL, NULL, TRUE);=20 - // - // Get BlockIo protocol and check removable attribute - // - Status =3D gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOI= D **)&BlockIo); - ASSERT_EFI_ERROR (Status); - - // - // Issue a dummy read to the device to check for media change. - // When the removable media is changed, any Block IO read/write will - // cause the BlockIo protocol be reinstalled and EFI_MEDIA_CHANGED is - // returned. After the Block IO protocol is reinstalled, subsequent - // Block IO read/write will success. - // - Buffer =3D AllocatePool (BlockIo->Media->BlockSize); - if (Buffer !=3D NULL) { - BlockIo->ReadBlocks ( - BlockIo, - BlockIo->Media->MediaId, - 0, - BlockIo->Media->BlockSize, - Buffer - ); - FreePool(Buffer); - } - } - - // - // Detect the the default boot file from removable Media - // - - // - // If fail to get bootable handle specified by a USB boot option, the BD= S should try to find other bootable device in the same USB bus - // Try to locate the USB node device path first, if fail then use its pr= evious PCI node to search - // - DupDevicePath =3D DuplicateDevicePath (DevicePath); - ASSERT (DupDevicePath !=3D NULL); - - UpdatedDevicePath =3D DupDevicePath; - Status =3D gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &UpdatedD= evicePath, &Handle); - // - // if the resulting device path point to a usb node, and the usb node is= a dummy node, should only let device path only point to the previous Pci n= ode - // Acpi()/Pci()/Usb() --> Acpi()/Pci() - // - if ((DevicePathType (UpdatedDevicePath) =3D=3D MESSAGING_DEVICE_PATH) && - (DevicePathSubType (UpdatedDevicePath) =3D=3D MSG_USB_DP)) { - // - // Remove the usb node, let the device path only point to PCI node - // - SetDevicePathEndNode (UpdatedDevicePath); - UpdatedDevicePath =3D DupDevicePath; - } else { - UpdatedDevicePath =3D DevicePath; - } - - // - // Get the device path size of boot option - // - Size =3D GetDevicePathSize(UpdatedDevicePath) - sizeof (EFI_DEVICE_PATH_= PROTOCOL); // minus the end node - ReturnHandle =3D NULL; - gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiSimpleFileSystemProtocolGuid, - NULL, - &NumberSimpleFileSystemHandles, - &SimpleFileSystemHandles - ); - for (Index =3D 0; Index < NumberSimpleFileSystemHandles; Index++) { - // - // Get the device path size of SimpleFileSystem handle - // - TempDevicePath =3D DevicePathFromHandle (SimpleFileSystemHandles[Index= ]); - TempSize =3D GetDevicePathSize (TempDevicePath)- sizeof (EFI_DEVICE_PA= TH_PROTOCOL); // minus the end node - // - // Check whether the device path of boot option is part of the Simple= FileSystem handle's device path - // - if (Size <=3D TempSize && CompareMem (TempDevicePath, UpdatedDevicePat= h, Size)=3D=3D0) { - // - // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from r= emovable Media - // machinename is ia32, ia64, x64, ... - // - Hdr.Union =3D &HdrData; - Status =3D BdsLibGetImageHeader ( - SimpleFileSystemHandles[Index], - EFI_REMOVABLE_MEDIA_FILE_NAME, - &DosHeader, - Hdr - ); - if (!EFI_ERROR (Status) && - EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) && - Hdr.Pe32->OptionalHeader.Subsystem =3D=3D EFI_IMAGE_SUBSYSTEM_EFI_= APPLICATION) { - ReturnHandle =3D SimpleFileSystemHandles[Index]; - break; - } - } - } - - FreePool(DupDevicePath); - - if (SimpleFileSystemHandles !=3D NULL) { - FreePool(SimpleFileSystemHandles); - } - - gBS->RestoreTPL (OldTpl); - - return ReturnHandle; -} - -/** - Check to see if the network cable is plugged in. If the DevicePath is not - connected it will be connected. - - @param DevicePath Device Path to check - - @retval TRUE DevicePath points to an Network that is c= onnected - @retval FALSE DevicePath does not point to a bootable n= etwork - -**/ -BOOLEAN -BdsLibNetworkBootWithMediaPresent ( - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath - ) -{ - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *UpdatedDevicePath; - EFI_HANDLE Handle; - EFI_SIMPLE_NETWORK_PROTOCOL *Snp; - BOOLEAN MediaPresent; - UINT32 InterruptStatus; - - MediaPresent =3D FALSE; - - UpdatedDevicePath =3D DevicePath; - // - // Locate Load File Protocol for PXE boot option first - // - Status =3D gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &UpdatedDev= icePath, &Handle); - if (EFI_ERROR (Status)) { - // - // Device not present so see if we need to connect it - // - Status =3D BdsLibConnectDevicePath (DevicePath); - if (!EFI_ERROR (Status)) { - // - // This one should work after we did the connect - // - Status =3D gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &Update= dDevicePath, &Handle); - } - } - - if (!EFI_ERROR (Status)) { - Status =3D gBS->HandleProtocol (Handle, &gEfiSimpleNetworkProtocolGuid= , (VOID **)&Snp); - if (EFI_ERROR (Status)) { - // - // Failed to open SNP from this handle, try to get SNP from parent h= andle - // - UpdatedDevicePath =3D DevicePathFromHandle (Handle); - if (UpdatedDevicePath !=3D NULL) { - Status =3D gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, = &UpdatedDevicePath, &Handle); - if (!EFI_ERROR (Status)) { - // - // SNP handle found, get SNP from it - // - Status =3D gBS->HandleProtocol (Handle, &gEfiSimpleNetworkProtoc= olGuid, (VOID **) &Snp); - } - } - } - - if (!EFI_ERROR (Status)) { - if (Snp->Mode->MediaPresentSupported) { - if (Snp->Mode->State =3D=3D EfiSimpleNetworkInitialized) { - // - // Invoke Snp->GetStatus() to refresh the media status - // - Snp->GetStatus (Snp, &InterruptStatus, NULL); - - // - // In case some one else is using the SNP check to see if it's c= onnected - // - MediaPresent =3D Snp->Mode->MediaPresent; - } else { - // - // No one is using SNP so we need to Start and Initialize so - // MediaPresent will be valid. - // - Status =3D Snp->Start (Snp); - if (!EFI_ERROR (Status)) { - Status =3D Snp->Initialize (Snp, 0, 0); - if (!EFI_ERROR (Status)) { - MediaPresent =3D Snp->Mode->MediaPresent; - Snp->Shutdown (Snp); - } - Snp->Stop (Snp); - } - } - } else { - MediaPresent =3D TRUE; - } - } - } - - return MediaPresent; -} - -/** - For a bootable Device path, return its boot type. - - @param DevicePath The bootable device Path to check - - @retval BDS_EFI_MEDIA_HD_BOOT If given device path contains ME= DIA_DEVICE_PATH type device path node - which subtype is MEDIA_HARDDRIVE= _DP - @retval BDS_EFI_MEDIA_CDROM_BOOT If given device path contains ME= DIA_DEVICE_PATH type device path node - which subtype is MEDIA_CDROM_DP - @retval BDS_EFI_ACPI_FLOPPY_BOOT If given device path contains AC= PI_DEVICE_PATH type device path node - which HID is floppy device. - @retval BDS_EFI_MESSAGE_ATAPI_BOOT If given device path contains ME= SSAGING_DEVICE_PATH type device path node - and its last device path node's = subtype is MSG_ATAPI_DP. - @retval BDS_EFI_MESSAGE_SCSI_BOOT If given device path contains ME= SSAGING_DEVICE_PATH type device path node - and its last device path node's = subtype is MSG_SCSI_DP. - @retval BDS_EFI_MESSAGE_USB_DEVICE_BOOT If given device path contains ME= SSAGING_DEVICE_PATH type device path node - and its last device path node's = subtype is MSG_USB_DP. - @retval BDS_EFI_MESSAGE_MISC_BOOT If the device path not contains = any media device path node, and - its last device path node point = to a message device path node. - @retval BDS_LEGACY_BBS_BOOT If given device path contains BB= S_DEVICE_PATH type device path node. - @retval BDS_EFI_UNSUPPORT An EFI Removable BlockIO device = path not point to a media and message device, - -**/ -UINT32 -EFIAPI -BdsGetBootTypeFromDevicePath ( - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath - ) -{ - ACPI_HID_DEVICE_PATH *Acpi; - EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; - EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode; - UINT32 BootType; - - if (NULL =3D=3D DevicePath) { - return BDS_EFI_UNSUPPORT; - } - - TempDevicePath =3D DevicePath; - - while (!IsDevicePathEndType (TempDevicePath)) { - switch (DevicePathType (TempDevicePath)) { - case BBS_DEVICE_PATH: - return BDS_LEGACY_BBS_BOOT; - case MEDIA_DEVICE_PATH: - if (DevicePathSubType (TempDevicePath) =3D=3D MEDIA_HARDDRIVE_DP) { - return BDS_EFI_MEDIA_HD_BOOT; - } else if (DevicePathSubType (TempDevicePath) =3D=3D MEDIA_CDROM_D= P) { - return BDS_EFI_MEDIA_CDROM_BOOT; - } - break; - case ACPI_DEVICE_PATH: - Acpi =3D (ACPI_HID_DEVICE_PATH *) TempDevicePath; - if (EISA_ID_TO_NUM (Acpi->HID) =3D=3D 0x0604) { - return BDS_EFI_ACPI_FLOPPY_BOOT; - } - break; - case MESSAGING_DEVICE_PATH: - // - // Get the last device path node - // - LastDeviceNode =3D NextDevicePathNode (TempDevicePath); - if (DevicePathSubType(LastDeviceNode) =3D=3D MSG_DEVICE_LOGICAL_UN= IT_DP) { - // - // if the next node type is Device Logical Unit, which specify t= he Logical Unit Number (LUN), - // skip it - // - LastDeviceNode =3D NextDevicePathNode (LastDeviceNode); - } - // - // if the device path not only point to driver device, it is not a= messaging device path, - // - if (!IsDevicePathEndType (LastDeviceNode)) { - break; - } - - switch (DevicePathSubType (TempDevicePath)) { - case MSG_ATAPI_DP: - BootType =3D BDS_EFI_MESSAGE_ATAPI_BOOT; - break; - - case MSG_USB_DP: - BootType =3D BDS_EFI_MESSAGE_USB_DEVICE_BOOT; - break; - - case MSG_SCSI_DP: - BootType =3D BDS_EFI_MESSAGE_SCSI_BOOT; - break; - - case MSG_SATA_DP: - BootType =3D BDS_EFI_MESSAGE_SATA_BOOT; - break; - - case MSG_MAC_ADDR_DP: - case MSG_VLAN_DP: - case MSG_IPv4_DP: - case MSG_IPv6_DP: - BootType =3D BDS_EFI_MESSAGE_MAC_BOOT; - break; - - default: - BootType =3D BDS_EFI_MESSAGE_MISC_BOOT; - break; - } - return BootType; - - default: - break; - } - TempDevicePath =3D NextDevicePathNode (TempDevicePath); - } - - return BDS_EFI_UNSUPPORT; -} - -/** - Check whether the Device path in a boot option point to a valid bootable= device, - And if CheckMedia is true, check the device is ready to boot now. - - @param DevPath the Device path in a boot option - @param CheckMedia if true, check the device is ready to boot now. - - @retval TRUE the Device path is valid - @retval FALSE the Device path is invalid . - -**/ -BOOLEAN -EFIAPI -BdsLibIsValidEFIBootOptDevicePath ( - IN EFI_DEVICE_PATH_PROTOCOL *DevPath, - IN BOOLEAN CheckMedia - ) -{ - return BdsLibIsValidEFIBootOptDevicePathExt (DevPath, CheckMedia, NULL); -} - -/** - Check whether the Device path in a boot option point to a valid bootable= device, - And if CheckMedia is true, check the device is ready to boot now. - If Description is not NULL and the device path point to a fixed BlockIo - device, check the description whether conflict with other auto-created - boot options. - - @param DevPath the Device path in a boot option - @param CheckMedia if true, check the device is ready to boot now. - @param Description the description in a boot option - - @retval TRUE the Device path is valid - @retval FALSE the Device path is invalid . - -**/ -BOOLEAN -EFIAPI -BdsLibIsValidEFIBootOptDevicePathExt ( - IN EFI_DEVICE_PATH_PROTOCOL *DevPath, - IN BOOLEAN CheckMedia, - IN CHAR16 *Description - ) -{ - EFI_STATUS Status; - EFI_HANDLE Handle; - EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; - EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode; - EFI_BLOCK_IO_PROTOCOL *BlockIo; - - TempDevicePath =3D DevPath; - LastDeviceNode =3D DevPath; - - // - // Check if it's a valid boot option for network boot device. - // Check if there is EfiLoadFileProtocol installed.=20 - // If yes, that means there is a boot option for network. - // - Status =3D gBS->LocateDevicePath ( - &gEfiLoadFileProtocolGuid, - &TempDevicePath, - &Handle - ); - if (EFI_ERROR (Status)) { - // - // Device not present so see if we need to connect it - // - TempDevicePath =3D DevPath; - BdsLibConnectDevicePath (TempDevicePath); - Status =3D gBS->LocateDevicePath ( - &gEfiLoadFileProtocolGuid, - &TempDevicePath, - &Handle - ); - } - - if (!EFI_ERROR (Status)) { - if (!IsDevicePathEnd (TempDevicePath)) { - // - // LoadFile protocol is not installed on handle with exactly the sam= e DevPath - // - return FALSE; - } - - if (CheckMedia) { - // - // Test if it is ready to boot now - // - if (BdsLibNetworkBootWithMediaPresent(DevPath)) { - return TRUE; - } - } else { - return TRUE; - } =20 - } - - // - // If the boot option point to a file, it is a valid EFI boot option, - // and assume it is ready to boot now - // - while (!IsDevicePathEnd (TempDevicePath)) { - // - // If there is USB Class or USB WWID device path node, treat it as val= id EFI - // Boot Option. BdsExpandUsbShortFormDevicePath () will be used to exp= and it - // to full device path. - // - if ((DevicePathType (TempDevicePath) =3D=3D MESSAGING_DEVICE_PATH) && - ((DevicePathSubType (TempDevicePath) =3D=3D MSG_USB_CLASS_DP) || - (DevicePathSubType (TempDevicePath) =3D=3D MSG_USB_WWID_DP))) { - return TRUE; - } - - LastDeviceNode =3D TempDevicePath; - TempDevicePath =3D NextDevicePathNode (TempDevicePath); - } - if ((DevicePathType (LastDeviceNode) =3D=3D MEDIA_DEVICE_PATH) && - (DevicePathSubType (LastDeviceNode) =3D=3D MEDIA_FILEPATH_DP)) { - return TRUE; - } - - // - // Check if it's a valid boot option for internal FV application - // - if (EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE= _PATH *) LastDeviceNode) !=3D NULL) { - // - // If the boot option point to internal FV application, make sure it i= s valid - // - TempDevicePath =3D DevPath; - Status =3D BdsLibUpdateFvFileDevicePath ( - &TempDevicePath, - EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPA= TH_DEVICE_PATH *) LastDeviceNode) - ); - if (Status =3D=3D EFI_ALREADY_STARTED) { - return TRUE; - } else { - if (Status =3D=3D EFI_SUCCESS) { - FreePool (TempDevicePath); - } - return FALSE; - } - } - - // - // If the boot option point to a blockIO device: - // if it is a removable blockIo device, it is valid. - // if it is a fixed blockIo device, check its description confliction. - // - TempDevicePath =3D DevPath; - Status =3D gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDeviceP= ath, &Handle); - if (EFI_ERROR (Status)) { - // - // Device not present so see if we need to connect it - // - Status =3D BdsLibConnectDevicePath (DevPath); - if (!EFI_ERROR (Status)) { - // - // Try again to get the Block Io protocol after we did the connect - // - TempDevicePath =3D DevPath; - Status =3D gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDev= icePath, &Handle); - } - } - - if (!EFI_ERROR (Status)) { - Status =3D gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOI= D **)&BlockIo); - if (!EFI_ERROR (Status)) { - if (CheckMedia) { - // - // Test if it is ready to boot now - // - if (BdsLibGetBootableHandle (DevPath) !=3D NULL) { - return TRUE; - } - } else { - return TRUE; - } - } - } else { - // - // if the boot option point to a simple file protocol which does not c= onsume block Io protocol, it is also a valid EFI boot option, - // - Status =3D gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &= TempDevicePath, &Handle); - if (!EFI_ERROR (Status)) { - if (CheckMedia) { - // - // Test if it is ready to boot now - // - if (BdsLibGetBootableHandle (DevPath) !=3D NULL) { - return TRUE; - } - } else { - return TRUE; - } - } - } - - return FALSE; -} - - -/** - According to a file guild, check a Fv file device path is valid. If it i= s invalid, - try to return the valid device path. - FV address maybe changes for memory layout adjust from time to time, use= this function - could promise the Fv file device path is right. - - @param DevicePath on input, the Fv file device path need to= check on - output, the updated valid Fv file device = path - @param FileGuid the Fv file guild - - @retval EFI_INVALID_PARAMETER the input DevicePath or FileGuid is inval= id - parameter - @retval EFI_UNSUPPORTED the input DevicePath does not contain Fv = file - guild at all - @retval EFI_ALREADY_STARTED the input DevicePath has pointed to Fv fi= le, it is - valid - @retval EFI_SUCCESS has successfully updated the invalid Devi= cePath, - and return the updated device path in Dev= icePath - -**/ -EFI_STATUS -EFIAPI -BdsLibUpdateFvFileDevicePath ( - IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePath, - IN EFI_GUID *FileGuid - ) -{ - EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; - EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode; - EFI_STATUS Status; - EFI_GUID *GuidPoint; - UINTN Index; - UINTN FvHandleCount; - EFI_HANDLE *FvHandleBuffer; - EFI_FV_FILETYPE Type; - UINTN Size; - EFI_FV_FILE_ATTRIBUTES Attributes; - UINT32 AuthenticationStatus; - BOOLEAN FindFvFile; - EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; - EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv; - MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FvFileNode; - EFI_HANDLE FoundFvHandle; - EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; - - if ((DevicePath =3D=3D NULL) || (*DevicePath =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - if (FileGuid =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // Check whether the device path point to the default the input Fv file - // - TempDevicePath =3D *DevicePath; - LastDeviceNode =3D TempDevicePath; - while (!IsDevicePathEnd (TempDevicePath)) { - LastDeviceNode =3D TempDevicePath; - TempDevicePath =3D NextDevicePathNode (TempDevicePath); - } - GuidPoint =3D EfiGetNameGuidFromFwVolDevicePathNode ( - (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode - ); - if (GuidPoint =3D=3D NULL) { - // - // if this option does not points to a Fv file, just return EFI_UNSUPP= ORTED - // - return EFI_UNSUPPORTED; - } - if (!CompareGuid (GuidPoint, FileGuid)) { - // - // If the Fv file is not the input file guid, just return EFI_UNSUPPOR= TED - // - return EFI_UNSUPPORTED; - } - - // - // Check whether the input Fv file device path is valid - // - TempDevicePath =3D *DevicePath; - FoundFvHandle =3D NULL; - Status =3D gBS->LocateDevicePath ( - &gEfiFirmwareVolume2ProtocolGuid, - &TempDevicePath, - &FoundFvHandle - ); - if (!EFI_ERROR (Status)) { - Status =3D gBS->HandleProtocol ( - FoundFvHandle, - &gEfiFirmwareVolume2ProtocolGuid, - (VOID **) &Fv - ); - if (!EFI_ERROR (Status)) { - // - // Set FV ReadFile Buffer as NULL, only need to check whether input = Fv file exist there - // - Status =3D Fv->ReadFile ( - Fv, - FileGuid, - NULL, - &Size, - &Type, - &Attributes, - &AuthenticationStatus - ); - if (!EFI_ERROR (Status)) { - return EFI_ALREADY_STARTED; - } - } - } - - // - // Look for the input wanted FV file in current FV - // First, try to look for in Bds own FV. Bds and input wanted FV file us= ually are in the same FV - // - FindFvFile =3D FALSE; - FoundFvHandle =3D NULL; - Status =3D gBS->HandleProtocol ( - gImageHandle, - &gEfiLoadedImageProtocolGuid, - (VOID **) &LoadedImage - ); - if (!EFI_ERROR (Status)) { - Status =3D gBS->HandleProtocol ( - LoadedImage->DeviceHandle, - &gEfiFirmwareVolume2ProtocolGuid, - (VOID **) &Fv - ); - if (!EFI_ERROR (Status)) { - Status =3D Fv->ReadFile ( - Fv, - FileGuid, - NULL, - &Size, - &Type, - &Attributes, - &AuthenticationStatus - ); - if (!EFI_ERROR (Status)) { - FindFvFile =3D TRUE; - FoundFvHandle =3D LoadedImage->DeviceHandle; - } - } - } - // - // Second, if fail to find, try to enumerate all FV - // - if (!FindFvFile) { - FvHandleBuffer =3D NULL; - gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiFirmwareVolume2ProtocolGuid, - NULL, - &FvHandleCount, - &FvHandleBuffer - ); - for (Index =3D 0; Index < FvHandleCount; Index++) { - gBS->HandleProtocol ( - FvHandleBuffer[Index], - &gEfiFirmwareVolume2ProtocolGuid, - (VOID **) &Fv - ); - - Status =3D Fv->ReadFile ( - Fv, - FileGuid, - NULL, - &Size, - &Type, - &Attributes, - &AuthenticationStatus - ); - if (EFI_ERROR (Status)) { - // - // Skip if input Fv file not in the FV - // - continue; - } - FindFvFile =3D TRUE; - FoundFvHandle =3D FvHandleBuffer[Index]; - break; - } - - if (FvHandleBuffer !=3D NULL) { - FreePool (FvHandleBuffer); - } - } - - if (FindFvFile) { - // - // Build the shell device path - // - NewDevicePath =3D DevicePathFromHandle (FoundFvHandle); - EfiInitializeFwVolDevicepathNode (&FvFileNode, FileGuid); - NewDevicePath =3D AppendDevicePathNode (NewDevicePath, (EFI_DEVICE_PAT= H_PROTOCOL *) &FvFileNode); - ASSERT (NewDevicePath !=3D NULL); - *DevicePath =3D NewDevicePath; - return EFI_SUCCESS; - } - return EFI_NOT_FOUND; -} diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModule= Pkg/Library/GenericBdsLib/BdsConnect.c b/Platform/Intel/Vlv2TbltDevicePkg/O= verride/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConnect.c deleted file mode 100644 index dfeefc01b8..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Lib= rary/GenericBdsLib/BdsConnect.c +++ /dev/null @@ -1,429 +0,0 @@ -/** @file - BDS Lib functions which relate with connect the device - -Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "InternalBdsLib.h" - - -/** - This function will connect all the system driver to controller - first, and then special connect the default console, this make - sure all the system controller available and the platform default - console connected. - -**/ -VOID -EFIAPI -BdsLibConnectAll ( - VOID - ) -{ - // - // Connect the platform console first - // - BdsLibConnectAllDefaultConsoles (); - - // - // Generic way to connect all the drivers - // - BdsLibConnectAllDriversToAllControllers (); - - // - // Here we have the assumption that we have already had - // platform default console - // - BdsLibConnectAllDefaultConsoles (); -} - - -/** - This function will connect all the system drivers to all controllers - first, and then connect all the console devices the system current - have. After this we should get all the device work and console available - if the system have console device. - -**/ -VOID -BdsLibGenericConnectAll ( - VOID - ) -{ - // - // Most generic way to connect all the drivers - // - BdsLibConnectAllDriversToAllControllers (); - BdsLibConnectAllConsoles (); -} - -/** - This function will create all handles associate with every device - path node. If the handle associate with one device path node can not - be created successfully, then still give chance to do the dispatch, - which load the missing drivers if possible. - - @param DevicePathToConnect The device path which will be connected, i= t can be - a multi-instance device path - - @retval EFI_SUCCESS All handles associate with every device pa= th node - have been created - @retval EFI_OUT_OF_RESOURCES There is no resource to create new handles - @retval EFI_NOT_FOUND Create the handle associate with one devic= e path - node failed - -**/ -EFI_STATUS -EFIAPI -BdsLibConnectDevicePath ( - IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect - ) -{ - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath; - EFI_DEVICE_PATH_PROTOCOL *Instance; - EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath; - EFI_DEVICE_PATH_PROTOCOL *Next; - EFI_HANDLE Handle; - EFI_HANDLE PreviousHandle; - UINTN Size; - EFI_TPL CurrentTpl; - - if (DevicePathToConnect =3D=3D NULL) { - return EFI_SUCCESS; - } - - CurrentTpl =3D EfiGetCurrentTpl (); - - DevicePath =3D DuplicateDevicePath (DevicePathToConnect); - if (DevicePath =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - CopyOfDevicePath =3D DevicePath; - =20 - do { - // - // The outer loop handles multi instance device paths. - // Only console variables contain multiple instance device paths. - // - // After this call DevicePath points to the next Instance - // - Instance =3D GetNextDevicePathInstance (&DevicePath, &Size); - if (Instance =3D=3D NULL) { - FreePool (CopyOfDevicePath); - return EFI_OUT_OF_RESOURCES; - } - =20 - Next =3D Instance; - while (!IsDevicePathEndType (Next)) { - Next =3D NextDevicePathNode (Next); - } - - SetDevicePathEndNode (Next); - - // - // Start the real work of connect with RemainingDevicePath - // - PreviousHandle =3D NULL; - do { - // - // Find the handle that best matches the Device Path. If it is only a - // partial match the remaining part of the device path is returned in - // RemainingDevicePath. - // - RemainingDevicePath =3D Instance; - Status =3D gBS->LocateDevicePath (&gEfiDevicePathProtoc= olGuid, &RemainingDevicePath, &Handle); - - if (!EFI_ERROR (Status)) { - if (Handle =3D=3D PreviousHandle) { - // - // If no forward progress is made try invoking the Dispatcher. - // A new FV may have been added to the system an new drivers - // may now be found. - // Status =3D=3D EFI_SUCCESS means a driver was dispatched - // Status =3D=3D EFI_NOT_FOUND means no new drivers were dispatc= hed - // - if (CurrentTpl =3D=3D TPL_APPLICATION) { - // - // Dispatch calls LoadImage/StartImage which cannot run at TPL= > TPL_APPLICATION - // - Status =3D gDS->Dispatch (); - } else { - // - // Always return EFI_NOT_FOUND here - // to prevent dead loop when control handle is found but conne= ction failded case - // - Status =3D EFI_NOT_FOUND; - } - } - - if (!EFI_ERROR (Status)) { - PreviousHandle =3D Handle; - // - // Connect all drivers that apply to Handle and RemainingDeviceP= ath, - // the Recursive flag is FALSE so only one level will be expande= d. - // - // Do not check the connect status here, if the connect controll= er fail, - // then still give the chance to do dispatch, because partial - // RemainingDevicepath may be in the new FV - // - // 1. If the connect fail, RemainingDevicepath and handle will n= ot - // change, so next time will do the dispatch, then dispatch's= status - // will take effect - // 2. If the connect success, the RemainingDevicepath and handle= will - // change, then avoid the dispatch, we have chance to continu= e the - // next connection - // - gBS->ConnectController (Handle, NULL, RemainingDevicePath, FALSE= ); - } - } - // - // Loop until RemainingDevicePath is an empty device path - // - } while (!EFI_ERROR (Status) && !IsDevicePathEnd (RemainingDevicePath)= ); - - } while (DevicePath !=3D NULL); - - if (CopyOfDevicePath !=3D NULL) { - FreePool (CopyOfDevicePath); - } - // - // All handle with DevicePath exists in the handle database - // - return Status; -} - -/** - This function will connect all current system handles recursively.=20 - =20 - gBS->ConnectController() service is invoked for each handle exist in sys= tem handler buffer. - If the handle is bus type handler, all childrens also will be connected = recursively - by gBS->ConnectController(). - - @retval EFI_SUCCESS All handles and it's child handle have bee= n connected - @retval EFI_STATUS Error status returned by of gBS->LocateHan= dleBuffer(). - -**/ -EFI_STATUS -EFIAPI -BdsLibConnectAllEfi ( - VOID - ) -{ - EFI_STATUS Status; - UINTN HandleCount; - EFI_HANDLE *HandleBuffer; - UINTN Index; - - Status =3D gBS->LocateHandleBuffer ( - AllHandles, - NULL, - NULL, - &HandleCount, - &HandleBuffer - ); - if (EFI_ERROR (Status)) { - return Status; - } - - for (Index =3D 0; Index < HandleCount; Index++) { - Status =3D gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TR= UE); - } - - if (HandleBuffer !=3D NULL) { - FreePool (HandleBuffer); - } - - return EFI_SUCCESS; -} - -/** - This function will disconnect all current system handles.=20 - =20 - gBS->DisconnectController() is invoked for each handle exists in system = handle buffer. - If handle is a bus type handle, all childrens also are disconnected recu= rsively by - gBS->DisconnectController(). - - @retval EFI_SUCCESS All handles have been disconnected - @retval EFI_STATUS Error status returned by of gBS->LocateHan= dleBuffer(). - -**/ -EFI_STATUS -EFIAPI -BdsLibDisconnectAllEfi ( - VOID - ) -{ - EFI_STATUS Status; - UINTN HandleCount; - EFI_HANDLE *HandleBuffer; - UINTN Index; - - // - // Disconnect all - // - Status =3D gBS->LocateHandleBuffer ( - AllHandles, - NULL, - NULL, - &HandleCount, - &HandleBuffer - ); - if (EFI_ERROR (Status)) { - return Status; - } - - for (Index =3D 0; Index < HandleCount; Index++) { - Status =3D gBS->DisconnectController (HandleBuffer[Index], NULL, NULL); - } - - if (HandleBuffer !=3D NULL) { - FreePool (HandleBuffer); - } - - return EFI_SUCCESS; -} - - -/** - Connects all drivers to all controllers. - This function make sure all the current system driver will manage - the correspoinding controllers if have. And at the same time, make - sure all the system controllers have driver to manage it if have. - -**/ -VOID -EFIAPI -BdsLibConnectAllDriversToAllControllers ( - VOID - ) -{ - EFI_STATUS Status; - - do { - // - // Connect All EFI 1.10 drivers following EFI 1.10 algorithm - // - BdsLibConnectAllEfi (); - - // - // Check to see if it's possible to dispatch an more DXE drivers. - // The BdsLibConnectAllEfi () may have made new DXE drivers show up. - // If anything is Dispatched Status =3D=3D EFI_SUCCESS and we will try - // the connect again. - // - Status =3D gDS->Dispatch (); - - } while (!EFI_ERROR (Status)); - -} - - -/** - Connect the specific Usb device which match the short form device path, - and whose bus is determined by Host Controller (Uhci or Ehci). - - @param HostControllerPI Uhci (0x00) or Ehci (0x20) or Both uhci an= d ehci - (0xFF) - @param RemainingDevicePath a short-form device path that starts with = the first - element being a USB WWID or a USB Class d= evice - path - - @return EFI_INVALID_PARAMETER RemainingDevicePath is NULL pointer. - RemainingDevicePath is not a USB device p= ath. - Invalid HostControllerPI type. - @return EFI_SUCCESS Success to connect USB device - @return EFI_NOT_FOUND Fail to find handle for USB controller to= connect. - -**/ -EFI_STATUS -EFIAPI -BdsLibConnectUsbDevByShortFormDP( - IN UINT8 HostControllerPI, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath - ) -{ - EFI_STATUS Status; - EFI_HANDLE *HandleArray; - UINTN HandleArrayCount; - UINTN Index; - EFI_PCI_IO_PROTOCOL *PciIo; - UINT8 Class[3]; - BOOLEAN AtLeastOneConnected; - - // - // Check the passed in parameters - // - if (RemainingDevicePath =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - if ((DevicePathType (RemainingDevicePath) !=3D MESSAGING_DEVICE_PATH) || - ((DevicePathSubType (RemainingDevicePath) !=3D MSG_USB_CLASS_DP) - && (DevicePathSubType (RemainingDevicePath) !=3D MSG_USB_WWID_DP) - )) { - return EFI_INVALID_PARAMETER; - } - - if (HostControllerPI !=3D 0xFF && - HostControllerPI !=3D 0x00 && - HostControllerPI !=3D 0x20) { - return EFI_INVALID_PARAMETER; - } - - // - // Find the usb host controller firstly, then connect with the remaining= device path - // - AtLeastOneConnected =3D FALSE; - Status =3D gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiPciIoProtocolGuid, - NULL, - &HandleArrayCount, - &HandleArray - ); - if (!EFI_ERROR (Status)) { - for (Index =3D 0; Index < HandleArrayCount; Index++) { - Status =3D gBS->HandleProtocol ( - HandleArray[Index], - &gEfiPciIoProtocolGuid, - (VOID **)&PciIo - ); - if (!EFI_ERROR (Status)) { - // - // Check whether the Pci device is the wanted usb host controller - // - Status =3D PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &C= lass); - if (!EFI_ERROR (Status)) { - if ((PCI_CLASS_SERIAL =3D=3D Class[2]) && - (PCI_CLASS_SERIAL_USB =3D=3D Class[1])) { - if (HostControllerPI =3D=3D Class[0] || HostControllerPI =3D= =3D 0xFF) { - Status =3D gBS->ConnectController ( - HandleArray[Index], - NULL, - RemainingDevicePath, - FALSE - ); - if (!EFI_ERROR(Status)) { - AtLeastOneConnected =3D TRUE; - } - } - } - } - } - } - - if (HandleArray !=3D NULL) { - FreePool (HandleArray); - } - - if (AtLeastOneConnected) { - return EFI_SUCCESS; - } - } - - return EFI_NOT_FOUND; -} diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModule= Pkg/Library/GenericBdsLib/BdsConsole.c b/Platform/Intel/Vlv2TbltDevicePkg/O= verride/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c deleted file mode 100644 index 2fffd9e4bc..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Lib= rary/GenericBdsLib/BdsConsole.c +++ /dev/null @@ -1,1061 +0,0 @@ -/** @file - BDS Lib functions which contain all the code to connect console device - -Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "InternalBdsLib.h" - - -/** - Check if we need to save the EFI variable with "ConVarName" as name - as NV type - If ConVarName is NULL, then ASSERT(). - =20 - @param ConVarName The name of the EFI variable. - - @retval TRUE Set the EFI variable as NV type. - @retval FALSE EFI variable as NV type can be set NonNV. -**/ -BOOLEAN -IsNvNeed ( - IN CHAR16 *ConVarName - ) -{ - CHAR16 *Ptr; - - ASSERT (ConVarName !=3D NULL); - =20 - Ptr =3D ConVarName; - - // - // If the variable includes "Dev" at last, we consider - // it does not support NV attribute. - // - while (*Ptr !=3D L'\0') { - Ptr++; - } - - if (((INTN)((UINTN)Ptr - (UINTN)ConVarName) / sizeof (CHAR16)) <=3D 3) { - return TRUE; - } - =20 - if ((*(Ptr - 3) =3D=3D 'D') && (*(Ptr - 2) =3D=3D 'e') && (*(Ptr - 1) = =3D=3D 'v')) { - return FALSE; - } else { - return TRUE; - } -} - -/** - Fill console handle in System Table if there are no valid console handle= in. - - Firstly, check the validation of console handle in System Table. If it i= s invalid, - update it by the first console device handle from EFI console variable.=20 - - @param VarName The name of the EFI console variable. - @param ConsoleGuid Specified Console protocol GUID. - @param ConsoleHandle On IN, console handle in System Table to be = checked.=20 - On OUT, new console handle in system table. - @param ProtocolInterface On IN, console protocol on console handle in= System Table to be checked.=20 - On OUT, new console protocol on new console h= andle in system table. - - @retval TRUE System Table has been updated. - @retval FALSE System Table hasn't been updated. - -**/ -BOOLEAN=20 -UpdateSystemTableConsole ( - IN CHAR16 *VarName, - IN EFI_GUID *ConsoleGuid, - IN OUT EFI_HANDLE *ConsoleHandle, - IN OUT VOID **ProtocolInterface - ) -{ - EFI_STATUS Status; - UINTN DevicePathSize; - EFI_DEVICE_PATH_PROTOCOL *FullDevicePath; - EFI_DEVICE_PATH_PROTOCOL *VarConsole; - EFI_DEVICE_PATH_PROTOCOL *Instance; - VOID *Interface; - EFI_HANDLE NewHandle; - EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut; - - ASSERT (VarName !=3D NULL); - ASSERT (ConsoleHandle !=3D NULL); - ASSERT (ConsoleGuid !=3D NULL); - ASSERT (ProtocolInterface !=3D NULL); - - if (*ConsoleHandle !=3D NULL) { - Status =3D gBS->HandleProtocol ( - *ConsoleHandle, - ConsoleGuid, - &Interface - ); - if (Status =3D=3D EFI_SUCCESS && Interface =3D=3D *ProtocolInterface) { - // - // If ConsoleHandle is valid and console protocol on this handle also - // also matched, just return. - // - return FALSE; - } - } - =20 - // - // Get all possible consoles device path from EFI variable - // - VarConsole =3D BdsLibGetVariableAndSize ( - VarName, - &gEfiGlobalVariableGuid, - &DevicePathSize - ); - if (VarConsole =3D=3D NULL) { - // - // If there is no any console device, just return. - // - return FALSE; - } - - FullDevicePath =3D VarConsole; - - do { - // - // Check every instance of the console variable - // - Instance =3D GetNextDevicePathInstance (&VarConsole, &DevicePathSize); - if (Instance =3D=3D NULL) { - FreePool (FullDevicePath); - ASSERT (FALSE); - } - =20 - // - // Find console device handle by device path instance - // - Status =3D gBS->LocateDevicePath ( - ConsoleGuid, - &Instance, - &NewHandle - ); - if (!EFI_ERROR (Status)) { - // - // Get the console protocol on this console device handle - // - Status =3D gBS->HandleProtocol ( - NewHandle, - ConsoleGuid, - &Interface - ); - if (!EFI_ERROR (Status)) { - // - // Update new console handle in System Table. - // - *ConsoleHandle =3D NewHandle; - *ProtocolInterface =3D Interface; - if (CompareGuid (ConsoleGuid, &gEfiSimpleTextOutProtocolGuid)) { - // - // If it is console out device, set console mode 80x25 if curren= t mode is invalid. - // - TextOut =3D (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *) Interface; - if (TextOut->Mode->Mode =3D=3D -1) { - TextOut->SetMode (TextOut, 0); - } - } - return TRUE; - } - } - - } while (Instance !=3D NULL); - - // - // No any available console devcie found. - // - return FALSE; -} - -/** - This function update console variable based on ConVarName, it can - add or remove one specific console device path from the variable - - @param ConVarName Console related variable name, ConIn, C= onOut, - ErrOut. - @param CustomizedConDevicePath The console device path which will be a= dded to - the console variable ConVarName, this p= arameter - can not be multi-instance. - @param ExclusiveDevicePath The console device path which will be r= emoved - from the console variable ConVarName, t= his - parameter can not be multi-instance. - - @retval EFI_UNSUPPORTED The added device path is same to the re= moved one. - @retval EFI_SUCCESS Success add or remove the device path f= rom the - console variable. - -**/ -EFI_STATUS -EFIAPI -BdsLibUpdateConsoleVariable ( - IN CHAR16 *ConVarName, - IN EFI_DEVICE_PATH_PROTOCOL *CustomizedConDevicePath, - IN EFI_DEVICE_PATH_PROTOCOL *ExclusiveDevicePath - ) -{ - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *VarConsole; - UINTN DevicePathSize; - EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; - EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath; - UINT32 Attributes; - - VarConsole =3D NULL; - DevicePathSize =3D 0; - - // - // Notes: check the device path point, here should check - // with compare memory - // - if (CustomizedConDevicePath =3D=3D ExclusiveDevicePath) { - return EFI_UNSUPPORTED; - } - // - // Delete the ExclusiveDevicePath from current default console - // - VarConsole =3D BdsLibGetVariableAndSize ( - ConVarName, - &gEfiGlobalVariableGuid, - &DevicePathSize - ); - - // - // Initialize NewDevicePath - // - NewDevicePath =3D VarConsole; - - // - // If ExclusiveDevicePath is even the part of the instance in VarConsole= , delete it. - // In the end, NewDevicePath is the final device path. - // - if (ExclusiveDevicePath !=3D NULL && VarConsole !=3D NULL) { - NewDevicePath =3D BdsLibDelPartMatchInstance (VarConsole, ExclusiveD= evicePath); - } - // - // Try to append customized device path to NewDevicePath. - // - if (CustomizedConDevicePath !=3D NULL) { - if (!BdsLibMatchDevicePaths (NewDevicePath, CustomizedConDevicePath)) { - // - // Check if there is part of CustomizedConDevicePath in NewDevicePat= h, delete it. - // - NewDevicePath =3D BdsLibDelPartMatchInstance (NewDevicePath, Customi= zedConDevicePath); - // - // In the first check, the default console variable will be _ModuleE= ntryPoint, - // just append current customized device path - // - TempNewDevicePath =3D NewDevicePath; - NewDevicePath =3D AppendDevicePathInstance (NewDevicePath, Customize= dConDevicePath); - if (TempNewDevicePath !=3D NULL) { - FreePool(TempNewDevicePath); - } - } - } - - // - // The attribute for ConInDev, ConOutDev and ErrOutDev does not include = NV. - // - if (IsNvNeed(ConVarName)) { - // - // ConVarName has NV attribute. - // - Attributes =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_= ACCESS | EFI_VARIABLE_NON_VOLATILE; - } else { - // - // ConVarName does not have NV attribute. - // - Attributes =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_= ACCESS; - } - - // - // Finally, Update the variable of the default console by NewDevicePath - // - DevicePathSize =3D GetDevicePathSize (NewDevicePath); - Status =3D SetVariableAndReportStatusCodeOnError ( - ConVarName, - &gEfiGlobalVariableGuid, - Attributes, - DevicePathSize, - NewDevicePath - ); - if ((DevicePathSize =3D=3D 0) && (Status =3D=3D EFI_NOT_FOUND)) { - Status =3D EFI_SUCCESS; - } - - if (VarConsole =3D=3D NewDevicePath) { - if (VarConsole !=3D NULL) { - FreePool(VarConsole); - } - } else { - if (VarConsole !=3D NULL) { - FreePool(VarConsole); - } - if (NewDevicePath !=3D NULL) { - FreePool(NewDevicePath); - } - } - - return Status; - -} - - -/** - Connect the console device base on the variable ConVarName, if - device path of the ConVarName is multi-instance device path and - anyone of the instances is connected success, then this function - will return success. - If the handle associate with one device path node can not - be created successfully, then still give chance to do the dispatch, - which load the missing drivers if possible.. - - @param ConVarName Console related variable name, ConIn, C= onOut, - ErrOut. - - @retval EFI_NOT_FOUND There is not any console devices connec= ted - success - @retval EFI_SUCCESS Success connect any one instance of the= console - device path base on the variable ConVar= Name. - -**/ -EFI_STATUS -EFIAPI -BdsLibConnectConsoleVariable ( - IN CHAR16 *ConVarName - ) -{ - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *StartDevicePath; - UINTN VariableSize; - EFI_DEVICE_PATH_PROTOCOL *Instance; - EFI_DEVICE_PATH_PROTOCOL *Next; - EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath; - UINTN Size; - BOOLEAN DeviceExist; - - Status =3D EFI_SUCCESS; - DeviceExist =3D FALSE; - - // - // Check if the console variable exist - // - StartDevicePath =3D BdsLibGetVariableAndSize ( - ConVarName, - &gEfiGlobalVariableGuid, - &VariableSize - ); - if (StartDevicePath =3D=3D NULL) { - return EFI_UNSUPPORTED; - } - - CopyOfDevicePath =3D StartDevicePath; - do { - // - // Check every instance of the console variable - // - Instance =3D GetNextDevicePathInstance (&CopyOfDevicePath, &Size); - if (Instance =3D=3D NULL) { - FreePool (StartDevicePath); - return EFI_UNSUPPORTED; - } - =20 - Next =3D Instance; - while (!IsDevicePathEndType (Next)) { - Next =3D NextDevicePathNode (Next); - } - - SetDevicePathEndNode (Next); - // - // Connect the USB console - // USB console device path is a short-form device path that=20 - // starts with the first element being a USB WWID - // or a USB Class device path - // - if ((DevicePathType (Instance) =3D=3D MESSAGING_DEVICE_PATH) && - ((DevicePathSubType (Instance) =3D=3D MSG_USB_CLASS_DP) - || (DevicePathSubType (Instance) =3D=3D MSG_USB_WWID_DP) - )) { - Status =3D BdsLibConnectUsbDevByShortFormDP (0xFF, Instance); - if (!EFI_ERROR (Status)) { - DeviceExist =3D TRUE; - } - } else { - // - // Connect the instance device path - // - Status =3D BdsLibConnectDevicePath (Instance); - - if (EFI_ERROR (Status)) { - // - // Delete the instance from the console varialbe - // - BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance); - } else { - DeviceExist =3D TRUE; - } - } - FreePool(Instance); - } while (CopyOfDevicePath !=3D NULL); - - FreePool (StartDevicePath); - - if (!DeviceExist) { - return EFI_NOT_FOUND; - } - - return EFI_SUCCESS; -} - -/** - This function will search every simpletext device in current system, - and make every simpletext device as pertantial console device. - -**/ -VOID -EFIAPI -BdsLibConnectAllConsoles ( - VOID - ) -{ - UINTN Index; - EFI_DEVICE_PATH_PROTOCOL *ConDevicePath; - UINTN HandleCount; - EFI_HANDLE *HandleBuffer; - - Index =3D 0; - HandleCount =3D 0; - HandleBuffer =3D NULL; - ConDevicePath =3D NULL; - - // - // Update all the console variables - // - gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiSimpleTextInProtocolGuid, - NULL, - &HandleCount, - &HandleBuffer - ); - - for (Index =3D 0; Index < HandleCount; Index++) { - gBS->HandleProtocol ( - HandleBuffer[Index], - &gEfiDevicePathProtocolGuid, - (VOID **) &ConDevicePath - ); - BdsLibUpdateConsoleVariable (L"ConIn", ConDevicePath, NULL); - } - - if (HandleBuffer !=3D NULL) { - FreePool(HandleBuffer); - HandleBuffer =3D NULL; - } - - gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiSimpleTextOutProtocolGuid, - NULL, - &HandleCount, - &HandleBuffer - ); - for (Index =3D 0; Index < HandleCount; Index++) { - gBS->HandleProtocol ( - HandleBuffer[Index], - &gEfiDevicePathProtocolGuid, - (VOID **) &ConDevicePath - ); - BdsLibUpdateConsoleVariable (L"ConOut", ConDevicePath, NULL); - BdsLibUpdateConsoleVariable (L"ErrOut", ConDevicePath, NULL); - } - - if (HandleBuffer !=3D NULL) { - FreePool(HandleBuffer); - } - - // - // Connect all console variables - // - BdsLibConnectAllDefaultConsoles (); - -} - -/** - This function will connect console device base on the console - device variable ConIn, ConOut and ErrOut. - - @retval EFI_SUCCESS At least one of the ConIn and ConOut de= vice have - been connected success. - @retval EFI_STATUS Return the status of BdsLibConnectConso= leVariable (). - -**/ -EFI_STATUS -EFIAPI -BdsLibConnectAllDefaultConsoles ( - VOID - ) -{ - EFI_STATUS Status; - BOOLEAN SystemTableUpdated; - - // - // Connect all default console variables - // - - // - // It seems impossible not to have any ConOut device on platform, - // so we check the status here. - // - Status =3D BdsLibConnectConsoleVariable (L"ConOut"); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Insert the performance probe for Console Out - // - PERF_START (NULL, "ConOut", "BDS", 1); - PERF_END (NULL, "ConOut", "BDS", 0); - - // - // Because possibly the platform is legacy free, in such case, - // ConIn devices (Serial Port and PS2 Keyboard ) does not exist, - // so we need not check the status. - // - BdsLibConnectConsoleVariable (L"ConIn"); - - // - // The _ModuleEntryPoint err out var is legal. - // - BdsLibConnectConsoleVariable (L"ErrOut"); - - SystemTableUpdated =3D FALSE; - // - // Fill console handles in System Table if no console device assignd. - // - if (UpdateSystemTableConsole (L"ConIn", &gEfiSimpleTextInProtocolGuid, &= gST->ConsoleInHandle, (VOID **) &gST->ConIn)) { - SystemTableUpdated =3D TRUE; - } - if (UpdateSystemTableConsole (L"ConOut", &gEfiSimpleTextOutProtocolGuid,= &gST->ConsoleOutHandle, (VOID **) &gST->ConOut)) { - SystemTableUpdated =3D TRUE; - } - if (UpdateSystemTableConsole (L"ErrOut", &gEfiSimpleTextOutProtocolGuid,= &gST->StandardErrorHandle, (VOID **) &gST->StdErr)) { - SystemTableUpdated =3D TRUE; - } - - if (SystemTableUpdated) { - // - // Update the CRC32 in the EFI System Table header - // - gST->Hdr.CRC32 =3D 0; - gBS->CalculateCrc32 ( - (UINT8 *) &gST->Hdr, - gST->Hdr.HeaderSize, - &gST->Hdr.CRC32 - ); - } - - // - // If any component set PcdTestKeyUsed to TRUE because use of a test key - // was detected, then display a warning message on the debug log and the= console - // - if (PcdGetBool (PcdTestKeyUsed) =3D=3D TRUE) { - DEBUG ((DEBUG_ERROR, "**********************************\n")); - DEBUG ((DEBUG_ERROR, "** WARNING: Test Key is used. **\n")); - DEBUG ((DEBUG_ERROR, "**********************************\n")); - Print (L"** WARNING: Test Key is used. **\n"); - } - - return EFI_SUCCESS; - -} - -/** - This function will connect console device except ConIn base on the conso= le - device variable ConOut and ErrOut. - - @retval EFI_SUCCESS At least one of the ConOut device have - been connected success. - @retval EFI_STATUS Return the status of BdsLibConnectConso= leVariable (). - -**/ -EFI_STATUS -EFIAPI -BdsLibConnectAllDefaultConsolesWithOutConIn ( - VOID - ) -{ - EFI_STATUS Status; - BOOLEAN SystemTableUpdated; - - // - // Connect all default console variables except ConIn - // - - // - // It seems impossible not to have any ConOut device on platform, - // so we check the status here. - // - Status =3D BdsLibConnectConsoleVariable (L"ConOut"); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Insert the performance probe for Console Out - // - PERF_START (NULL, "ConOut", "BDS", 1); - PERF_END (NULL, "ConOut", "BDS", 0); - - // - // The _ModuleEntryPoint err out var is legal. - // - BdsLibConnectConsoleVariable (L"ErrOut"); - - SystemTableUpdated =3D FALSE; - // - // Fill console handles in System Table if no console device assignd. - // - if (UpdateSystemTableConsole (L"ConOut", &gEfiSimpleTextOutProtocolGuid,= &gST->ConsoleOutHandle, (VOID **) &gST->ConOut)) { - SystemTableUpdated =3D TRUE; - } - if (UpdateSystemTableConsole (L"ErrOut", &gEfiSimpleTextOutProtocolGuid,= &gST->StandardErrorHandle, (VOID **) &gST->StdErr)) { - SystemTableUpdated =3D TRUE; - } - - if (SystemTableUpdated) { - // - // Update the CRC32 in the EFI System Table header - // - gST->Hdr.CRC32 =3D 0; - gBS->CalculateCrc32 ( - (UINT8 *) &gST->Hdr, - gST->Hdr.HeaderSize, - &gST->Hdr.CRC32 - ); - } - - return EFI_SUCCESS; - -} - -/** - Use SystemTable Conout to stop video based Simple Text Out consoles from= going - to the video device. Put up LogoFile on every video device that is a con= sole. - - @param[in] LogoFile File name of logo to display on the center of the= screen. - - @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and = logo displayed. - @retval EFI_UNSUPPORTED Logo not found - -**/ -EFI_STATUS -EFIAPI -EnableQuietBoot ( - IN EFI_GUID *LogoFile - ) -{ - EFI_STATUS Status; - EFI_OEM_BADGING_PROTOCOL *Badging; - UINT32 SizeOfX; - UINT32 SizeOfY; - INTN DestX; - INTN DestY; - UINT8 *ImageData; - UINTN ImageSize; - UINTN BltSize; - UINT32 Instance; - EFI_BADGING_FORMAT Format; - EFI_BADGING_DISPLAY_ATTRIBUTE Attribute; - UINTN CoordinateX; - UINTN CoordinateY; - UINTN Height; - UINTN Width; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; - EFI_UGA_DRAW_PROTOCOL *UgaDraw; - UINT32 ColorDepth; - UINT32 RefreshRate; - EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; - EFI_BOOT_LOGO_PROTOCOL *BootLogo; - UINTN NumberOfLogos; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LogoBlt; - UINTN LogoDestX; - UINTN LogoDestY; - UINTN LogoHeight; - UINTN LogoWidth; - UINTN NewDestX; - UINTN NewDestY; - UINTN NewHeight; - UINTN NewWidth; - UINT64 BufferSize; - - UgaDraw =3D NULL; - // - // Try to open GOP first - // - Status =3D gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutp= utProtocolGuid, (VOID **) &GraphicsOutput); - if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) { - GraphicsOutput =3D NULL; - // - // Open GOP failed, try to open UGA - // - Status =3D gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawPro= tocolGuid, (VOID **) &UgaDraw); - } - if (EFI_ERROR (Status)) { - return EFI_UNSUPPORTED; - } - - // - // Try to open Boot Logo Protocol. - // - BootLogo =3D NULL; - gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLog= o); - - // - // Erase Cursor from screen - // - gST->ConOut->EnableCursor (gST->ConOut, FALSE); - - Badging =3D NULL; - Status =3D gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOI= D **) &Badging); - - if (GraphicsOutput !=3D NULL) { - SizeOfX =3D GraphicsOutput->Mode->Info->HorizontalResolution; - SizeOfY =3D GraphicsOutput->Mode->Info->VerticalResolution; - - } else if (UgaDraw !=3D NULL && FeaturePcdGet (PcdUgaConsumeSupport)) { - Status =3D UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth,= &RefreshRate); - if (EFI_ERROR (Status)) { - return EFI_UNSUPPORTED; - } - } else { - return EFI_UNSUPPORTED; - } - - Blt =3D NULL; - NumberOfLogos =3D 0; - LogoDestX =3D 0; - LogoDestY =3D 0; - LogoHeight =3D 0; - LogoWidth =3D 0; - NewDestX =3D 0; - NewDestY =3D 0; - NewHeight =3D 0; - NewWidth =3D 0; - Instance =3D 0; - while (1) { - ImageData =3D NULL; - ImageSize =3D 0; - - if (Badging !=3D NULL) { - // - // Get image from OEMBadging protocol. - // - Status =3D Badging->GetImage ( - Badging, - &Instance, - &Format, - &ImageData, - &ImageSize, - &Attribute, - &CoordinateX, - &CoordinateY - ); - if (EFI_ERROR (Status)) { - goto Done; - } - - // - // Currently only support BMP format. - // - if (Format !=3D EfiBadgingFormatBMP) { - if (ImageData !=3D NULL) { - FreePool (ImageData); - } - continue; - } - } else { - // - // Get the specified image from FV. - // - Status =3D GetSectionFromAnyFv (LogoFile, EFI_SECTION_RAW, 0, (VOID = **) &ImageData, &ImageSize); - if (EFI_ERROR (Status)) { - return EFI_UNSUPPORTED; - } - - CoordinateX =3D 0; - CoordinateY =3D 0; - if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) { - Attribute =3D EfiBadgingDisplayAttributeCenter; - } else { - Attribute =3D EfiBadgingDisplayAttributeCustomized; - }=20 - } - - if (Blt !=3D NULL) { - FreePool (Blt); - } - Blt =3D NULL; - Status =3D TranslateBmpToGopBlt ( - ImageData, - ImageSize, - &Blt, - &BltSize, - &Height, - &Width - ); - if (EFI_ERROR (Status)) { - FreePool (ImageData); - - if (Badging =3D=3D NULL) { - return Status; - } else { - continue; - } - } - - // - // Calculate the display position according to Attribute. - // - switch (Attribute) { - case EfiBadgingDisplayAttributeLeftTop: - DestX =3D CoordinateX; - DestY =3D CoordinateY; - break; - - case EfiBadgingDisplayAttributeCenterTop: - DestX =3D (SizeOfX - Width) / 2; - DestY =3D CoordinateY; - break; - - case EfiBadgingDisplayAttributeRightTop: - DestX =3D (SizeOfX - Width - CoordinateX); - DestY =3D CoordinateY;; - break; - - case EfiBadgingDisplayAttributeCenterRight: - DestX =3D (SizeOfX - Width - CoordinateX); - DestY =3D (SizeOfY - Height) / 2; - break; - - case EfiBadgingDisplayAttributeRightBottom: - DestX =3D (SizeOfX - Width - CoordinateX); - DestY =3D (SizeOfY - Height - CoordinateY); - break; - - case EfiBadgingDisplayAttributeCenterBottom: - DestX =3D (SizeOfX - Width) / 2; - DestY =3D (SizeOfY - Height - CoordinateY); - break; - - case EfiBadgingDisplayAttributeLeftBottom: - DestX =3D CoordinateX; - DestY =3D (SizeOfY - Height - CoordinateY); - break; - - case EfiBadgingDisplayAttributeCenterLeft: - DestX =3D CoordinateX; - DestY =3D (SizeOfY - Height) / 2; - break; - - case EfiBadgingDisplayAttributeCenter: - DestX =3D (SizeOfX - Width) / 2; - DestY =3D (SizeOfY - Height) / 2; - break; - - case EfiBadgingDisplayAttributeCustomized: - DestX =3D (SizeOfX - Width) / 2; - DestY =3D ((SizeOfY * 382) / 1000) - Height / 2; - break; - - default: - DestX =3D CoordinateX; - DestY =3D CoordinateY; - break; - } - - if ((DestX >=3D 0) && (DestY >=3D 0)) { - if (GraphicsOutput !=3D NULL) { - Status =3D GraphicsOutput->Blt ( - GraphicsOutput, - Blt, - EfiBltBufferToVideo, - 0, - 0, - (UINTN) DestX, - (UINTN) DestY, - Width, - Height, - Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) - ); - } else if (UgaDraw !=3D NULL && FeaturePcdGet (PcdUgaConsumeSupport)= ) { - Status =3D UgaDraw->Blt ( - UgaDraw, - (EFI_UGA_PIXEL *) Blt, - EfiUgaBltBufferToVideo, - 0, - 0, - (UINTN) DestX, - (UINTN) DestY, - Width, - Height, - Width * sizeof (EFI_UGA_PIXEL) - ); - } else { - Status =3D EFI_UNSUPPORTED; - } - - // - // Report displayed Logo information. - // - if (!EFI_ERROR (Status)) { - NumberOfLogos++; - - if (LogoWidth =3D=3D 0) { - // - // The first Logo. - // - LogoDestX =3D (UINTN) DestX; - LogoDestY =3D (UINTN) DestY; - LogoWidth =3D Width; - LogoHeight =3D Height; - } else { - // - // Merge new logo with old one. - // - NewDestX =3D MIN ((UINTN) DestX, LogoDestX); - NewDestY =3D MIN ((UINTN) DestY, LogoDestY); - NewWidth =3D MAX ((UINTN) DestX + Width, LogoDestX + LogoWidth) = - NewDestX; - NewHeight =3D MAX ((UINTN) DestY + Height, LogoDestY + LogoHeigh= t) - NewDestY; - - LogoDestX =3D NewDestX; - LogoDestY =3D NewDestY; - LogoWidth =3D NewWidth; - LogoHeight =3D NewHeight; - } - } - } - - FreePool (ImageData); - - if (Badging =3D=3D NULL) { - break; - } - } - -Done: - if (BootLogo =3D=3D NULL || NumberOfLogos =3D=3D 0) { - // - // No logo displayed. - // - if (Blt !=3D NULL) { - FreePool (Blt); - } - - return Status; - } - - // - // Advertise displayed Logo information. - // - if (NumberOfLogos =3D=3D 1) { - // - // Only one logo displayed, use its Blt buffer directly for BootLogo p= rotocol. - // - LogoBlt =3D Blt; - Status =3D EFI_SUCCESS; - } else { - // - // More than one Logo displayed, get merged BltBuffer using VideoToBuf= fer operation.=20 - // - if (Blt !=3D NULL) { - FreePool (Blt); - } - - // - // Ensure the LogoHeight * LogoWidth doesn't overflow - // - if (LogoHeight > DivU64x64Remainder ((UINTN) ~0, LogoWidth, NULL)) { - return EFI_UNSUPPORTED; - } - BufferSize =3D MultU64x64 (LogoWidth, LogoHeight); - - // - // Ensure the BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) does= n't overflow - // - if (BufferSize > DivU64x32 ((UINTN) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BL= T_PIXEL))) { - return EFI_UNSUPPORTED; - } - - LogoBlt =3D AllocateZeroPool ((UINTN)BufferSize * sizeof (EFI_GRAPHICS= _OUTPUT_BLT_PIXEL)); - if (LogoBlt =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - if (GraphicsOutput !=3D NULL) { - Status =3D GraphicsOutput->Blt ( - GraphicsOutput, - LogoBlt, - EfiBltVideoToBltBuffer, - LogoDestX, - LogoDestY, - 0, - 0, - LogoWidth, - LogoHeight, - LogoWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXE= L) - ); - } else if (UgaDraw !=3D NULL && FeaturePcdGet (PcdUgaConsumeSupport)) { - Status =3D UgaDraw->Blt ( - UgaDraw, - (EFI_UGA_PIXEL *) LogoBlt, - EfiUgaVideoToBltBuffer, - LogoDestX, - LogoDestY, - 0, - 0, - LogoWidth, - LogoHeight, - LogoWidth * sizeof (EFI_UGA_PIXEL) - ); - } else { - Status =3D EFI_UNSUPPORTED; - } - } - - if (!EFI_ERROR (Status)) { - BootLogo->SetBootLogo (BootLogo, LogoBlt, LogoDestX, LogoDestY, LogoWi= dth, LogoHeight); - } - FreePool (LogoBlt); - - return Status; -} - -/** - Use SystemTable Conout to turn on video based Simple Text Out consoles. = The=20 - Simple Text Out screens will now be synced up with all non video output = devices - - @retval EFI_SUCCESS UGA devices are back in text mode and synced up. - -**/ -EFI_STATUS -EFIAPI -DisableQuietBoot ( - VOID - ) -{ - - // - // Enable Cursor on Screen - // - gST->ConOut->EnableCursor (gST->ConOut, TRUE); - return EFI_SUCCESS; -} - diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModule= Pkg/Library/GenericBdsLib/BdsMisc.c b/Platform/Intel/Vlv2TbltDevicePkg/Over= ride/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c deleted file mode 100644 index 313a1ea9f6..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Lib= rary/GenericBdsLib/BdsMisc.c +++ /dev/null @@ -1,1575 +0,0 @@ -/** @file - Misc BDS library function - -Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "InternalBdsLib.h" - - -#define MAX_STRING_LEN 200 - -BOOLEAN mFeaturerSwitch =3D TRUE; -BOOLEAN mResetRequired =3D FALSE; - -extern UINT16 gPlatformBootTimeOutDefault; - -/** - The function will go through the driver option link list, load and start - every driver the driver option device path point to. - - @param BdsDriverLists The header of the current driver option li= nk list - -**/ -VOID -EFIAPI -BdsLibLoadDrivers ( - IN LIST_ENTRY *BdsDriverLists - ) -{ - EFI_STATUS Status; - LIST_ENTRY *Link; - BDS_COMMON_OPTION *Option; - EFI_HANDLE ImageHandle; - EFI_LOADED_IMAGE_PROTOCOL *ImageInfo; - UINTN ExitDataSize; - CHAR16 *ExitData; - BOOLEAN ReconnectAll; - - ReconnectAll =3D FALSE; - - // - // Process the driver option - // - for (Link =3D BdsDriverLists->ForwardLink; Link !=3D BdsDriverLists; Lin= k =3D Link->ForwardLink) { - Option =3D CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATUR= E); - =20 - // - // If a load option is not marked as LOAD_OPTION_ACTIVE, - // the boot manager will not automatically load the option. - // - if (!IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_ACTIVE)) { - continue; - } - =20 - // - // If a driver load option is marked as LOAD_OPTION_FORCE_RECONNECT, - // then all of the EFI drivers in the system will be disconnected and - // reconnected after the last driver load option is processed. - // - if (IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_FORCE_RECONNEC= T)) { - ReconnectAll =3D TRUE; - } - =20 - // - // Make sure the driver path is connected. - // - BdsLibConnectDevicePath (Option->DevicePath); - - // - // Load and start the image that Driver#### describes - // - Status =3D gBS->LoadImage ( - FALSE, - gImageHandle, - Option->DevicePath, - NULL, - 0, - &ImageHandle - ); - - if (!EFI_ERROR (Status)) { - gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOI= D **) &ImageInfo); - - // - // Verify whether this image is a driver, if not, - // exit it and continue to parse next load option - // - if (ImageInfo->ImageCodeType !=3D EfiBootServicesCode && ImageInfo->= ImageCodeType !=3D EfiRuntimeServicesCode) { - gBS->Exit (ImageHandle, EFI_INVALID_PARAMETER, 0, NULL); - continue; - } - - if (Option->LoadOptionsSize !=3D 0) { - ImageInfo->LoadOptionsSize =3D Option->LoadOptionsSize; - ImageInfo->LoadOptions =3D Option->LoadOptions; - } - // - // Before calling the image, enable the Watchdog Timer for - // the 5 Minute period - // - gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL); - - Status =3D gBS->StartImage (ImageHandle, &ExitDataSize, &ExitData); - DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Driver Return Status =3D %r\n", St= atus)); - - // - // Clear the Watchdog Timer after the image returns - // - gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL); - } - } - =20 - // - // Process the LOAD_OPTION_FORCE_RECONNECT driver option - // - if (ReconnectAll) { - BdsLibDisconnectAllEfi (); - BdsLibConnectAll (); - } - -} - -/** - Get the Option Number that does not used. - Try to locate the specific option variable one by one utile find a free = number. - - @param VariableName Indicate if the boot#### or driver#### opt= ion - - @return The Minimal Free Option Number - -**/ -UINT16 -BdsLibGetFreeOptionNumber ( - IN CHAR16 *VariableName - ) -{ - UINTN Index; - CHAR16 StrTemp[10]; - UINT16 *OptionBuffer; - UINTN OptionSize; - - // - // Try to find the minimum free number from 0, 1, 2, 3.... - // - Index =3D 0; - do { - if (*VariableName =3D=3D 'B') { - UnicodeSPrint (StrTemp, sizeof (StrTemp), L"Boot%04x", Index); - } else { - UnicodeSPrint (StrTemp, sizeof (StrTemp), L"Driver%04x", Index); - } - // - // try if the option number is used - // - OptionBuffer =3D BdsLibGetVariableAndSize ( - StrTemp, - &gEfiGlobalVariableGuid, - &OptionSize - ); - if (OptionBuffer =3D=3D NULL) { - break; - } - FreePool(OptionBuffer); - Index++; - } while (TRUE); - - return ((UINT16) Index); -} - - -/** - This function will register the new boot#### or driver#### option base on - the VariableName. The new registered boot#### or driver#### will be link= ed - to BdsOptionList and also update to the VariableName. After the boot####= or - driver#### updated, the BootOrder or DriverOrder will also be updated. - - @param BdsOptionList The header of the boot#### or driver#### l= ink list - @param DevicePath The device path which the boot#### or driv= er#### - option present - @param String The description of the boot#### or driver#= ### - @param VariableName Indicate if the boot#### or driver#### opt= ion - - @retval EFI_SUCCESS The boot#### or driver#### have been succe= ss - registered - @retval EFI_STATUS Return the status of gRT->SetVariable (). - -**/ -EFI_STATUS -EFIAPI -BdsLibRegisterNewOption ( - IN LIST_ENTRY *BdsOptionList, - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, - IN CHAR16 *String, - IN CHAR16 *VariableName - ) -{ - EFI_STATUS Status; - UINTN Index; - UINT16 RegisterOptionNumber; - UINT16 *TempOptionPtr; - UINTN TempOptionSize; - UINT16 *OptionOrderPtr; - VOID *OptionPtr; - UINTN OptionSize; - UINT8 *TempPtr; - EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath; - CHAR16 *Description; - CHAR16 OptionName[10]; - BOOLEAN UpdateDescription; - UINT16 BootOrderEntry; - UINTN OrderItemNum; - - if (DevicePath =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - OptionPtr =3D NULL; - OptionSize =3D 0; - TempPtr =3D NULL; - OptionDevicePath =3D NULL; - Description =3D NULL; - OptionOrderPtr =3D NULL; - UpdateDescription =3D FALSE; - Status =3D EFI_SUCCESS; - ZeroMem (OptionName, sizeof (OptionName)); - - TempOptionSize =3D 0; - TempOptionPtr =3D BdsLibGetVariableAndSize ( - VariableName, - &gEfiGlobalVariableGuid, - &TempOptionSize - ); - // - // Compare with current option variable if the previous option is set in= global variable. - // - for (Index =3D 0; Index < TempOptionSize / sizeof (UINT16); Index++) { - // - // TempOptionPtr must not be NULL if we have non-zero TempOptionSize. - // - ASSERT (TempOptionPtr !=3D NULL); - - if (*VariableName =3D=3D 'B') { - UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", TempOpt= ionPtr[Index]); - } else { - UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", TempO= ptionPtr[Index]); - } - - OptionPtr =3D BdsLibGetVariableAndSize ( - OptionName, - &gEfiGlobalVariableGuid, - &OptionSize - ); - if (OptionPtr =3D=3D NULL) { - continue; - } - - // - // Validate the variable. - // - if (!ValidateOption(OptionPtr, OptionSize)) { - FreePool(OptionPtr); - continue; - } - - TempPtr =3D OptionPtr; - TempPtr +=3D sizeof (UINT32) + sizeof (UINT16); - Description =3D (CHAR16 *) TempPtr; - TempPtr +=3D StrSize ((CHAR16 *) TempPtr); - OptionDevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *) TempPtr; - - // - // Notes: the description may will change base on the GetStringToken - // - if (CompareMem (OptionDevicePath, DevicePath, GetDevicePathSize (Optio= nDevicePath)) =3D=3D 0) { - if (CompareMem (Description, String, StrSize (Description)) =3D=3D 0= ) {=20 - // - // Got the option, so just return - // - FreePool (OptionPtr); - FreePool (TempOptionPtr); - return EFI_SUCCESS; - } else { - // - // Option description changed, need update. - // - UpdateDescription =3D TRUE; - FreePool (OptionPtr); - break; - } - } - - FreePool (OptionPtr); - } - - OptionSize =3D sizeof (UINT32) + sizeof (UINT16) + StrSize (Str= ing); - OptionSize +=3D GetDevicePathSize (DevicePath); - OptionPtr =3D AllocateZeroPool (OptionSize); - ASSERT (OptionPtr !=3D NULL); - =20 - TempPtr =3D OptionPtr; - *(UINT32 *) TempPtr =3D LOAD_OPTION_ACTIVE; - TempPtr +=3D sizeof (UINT32); - *(UINT16 *) TempPtr =3D (UINT16) GetDevicePathSize (DevicePath); - TempPtr +=3D sizeof (UINT16); - CopyMem (TempPtr, String, StrSize (String)); - TempPtr +=3D StrSize (String); - CopyMem (TempPtr, DevicePath, GetDevicePathSize (DevicePath)); - - if (UpdateDescription) { - // - // The number in option#### to be updated.=20 - // In this case, we must have non-NULL TempOptionPtr. - // - ASSERT (TempOptionPtr !=3D NULL); - RegisterOptionNumber =3D TempOptionPtr[Index]; - } else { - // - // The new option#### number - // - RegisterOptionNumber =3D BdsLibGetFreeOptionNumber(VariableName); - } - - if (*VariableName =3D=3D 'B') { - UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", RegisterO= ptionNumber); - } else { - UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", Registe= rOptionNumber); - } - - Status =3D gRT->SetVariable ( - OptionName, - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_A= CCESS | EFI_VARIABLE_NON_VOLATILE, - OptionSize, - OptionPtr - ); - // - // Return if only need to update a changed description or fail to set op= tion. - // - if (EFI_ERROR (Status) || UpdateDescription) { - FreePool (OptionPtr); - if (TempOptionPtr !=3D NULL) { - FreePool (TempOptionPtr); - } - return Status; - } - - FreePool (OptionPtr); - - // - // Update the option order variable - // - - // - // If no option order - // - if (TempOptionSize =3D=3D 0) { - BootOrderEntry =3D 0; - Status =3D gRT->SetVariable ( - VariableName, - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME= _ACCESS | EFI_VARIABLE_NON_VOLATILE, - sizeof (UINT16), - &BootOrderEntry - ); - if (TempOptionPtr !=3D NULL) { - FreePool (TempOptionPtr); - } - return Status; - } - =20 - // - // TempOptionPtr must not be NULL if TempOptionSize is not zero. - // - ASSERT (TempOptionPtr !=3D NULL); - // - // Append the new option number to the original option order - // - OrderItemNum =3D (TempOptionSize / sizeof (UINT16)) + 1 ; - OptionOrderPtr =3D AllocateZeroPool ( OrderItemNum * sizeof (UINT16)); - ASSERT (OptionOrderPtr!=3D NULL); - CopyMem (OptionOrderPtr, TempOptionPtr, (OrderItemNum - 1) * sizeof (UIN= T16)); - - OptionOrderPtr[Index] =3D RegisterOptionNumber; - - Status =3D gRT->SetVariable ( - VariableName, - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_A= CCESS | EFI_VARIABLE_NON_VOLATILE, - OrderItemNum * sizeof (UINT16), - OptionOrderPtr - ); - FreePool (TempOptionPtr); - FreePool (OptionOrderPtr); - - return Status; -} - -/** - Returns the size of a device path in bytes. - - This function returns the size, in bytes, of the device path data struct= ure=20 - specified by DevicePath including the end of device path node. If Device= Path=20 - is NULL, then 0 is returned. If the length of the device path is bigger = than - MaxSize, also return 0 to indicate this is an invalidate device path. - - @param DevicePath A pointer to a device path data structure. - @param MaxSize Max valid device path size. If big than this = size,=20 - return error. - =20 - @retval 0 An invalid device path. - @retval Others The size of a device path in bytes. - -**/ -UINTN -GetDevicePathSizeEx ( - IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, - IN UINTN MaxSize - ) -{ - UINTN Size; - UINTN NodeSize; - - if (DevicePath =3D=3D NULL) { - return 0; - } - - // - // Search for the end of the device path structure - // - Size =3D 0; - while (!IsDevicePathEnd (DevicePath)) { - NodeSize =3D DevicePathNodeLength (DevicePath); - if (NodeSize < END_DEVICE_PATH_LENGTH) { - return 0; - } - Size +=3D NodeSize; - if (Size > MaxSize) { - return 0; - } - DevicePath =3D NextDevicePathNode (DevicePath); - } - Size +=3D DevicePathNodeLength (DevicePath); - if (Size > MaxSize) { - return 0; - } - - return Size; -} - -/** - Returns the length of a Null-terminated Unicode string. If the length is=20 - bigger than MaxStringLen, return length 0 to indicate that this is an=20 - invalidate string. - - This function returns the byte length of Unicode characters in the Null-= terminated - Unicode string specified by String.=20 - - If String is NULL, then ASSERT(). - If String is not aligned on a 16-bit boundary, then ASSERT(). - - @param String A pointer to a Null-terminated Unicode string. - @param MaxStringLen Max string len in this string. - - @retval 0 An invalid string. - @retval Others The length of String. - -**/ -UINTN -StrSizeEx ( - IN CONST CHAR16 *String, - IN UINTN MaxStringLen - ) -{ - UINTN Length; - - ASSERT (String !=3D NULL && MaxStringLen !=3D 0); - ASSERT (((UINTN) String & BIT0) =3D=3D 0); - - for (Length =3D 0; *String !=3D L'\0' && MaxStringLen !=3D Length; Strin= g++, Length+=3D2); - - if (*String !=3D L'\0' && MaxStringLen =3D=3D Length) { - return 0; - } - - return Length + 2; -} - -/** - Validate the EFI Boot#### variable (VendorGuid/Name) - - @param Variable Boot#### variable data. - @param VariableSize Returns the size of the EFI variable that = was read - - @retval TRUE The variable data is correct. - @retval FALSE The variable data is corrupted. - -**/ -BOOLEAN=20 -ValidateOption ( - UINT8 *Variable, - UINTN VariableSize - ) -{ - UINT16 FilePathSize; - UINT8 *TempPtr; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - UINTN TempSize; - - if (VariableSize <=3D sizeof (UINT16) + sizeof (UINT32)) { - return FALSE; - } - - // - // Skip the option attribute - // - TempPtr =3D Variable; - TempPtr +=3D sizeof (UINT32); - - // - // Get the option's device path size - // - FilePathSize =3D *(UINT16 *) TempPtr; - TempPtr +=3D sizeof (UINT16); - - // - // Get the option's description string size - // - TempSize =3D StrSizeEx ((CHAR16 *) TempPtr, VariableSize - sizeof (UINT1= 6) - sizeof (UINT32)); - TempPtr +=3D TempSize; - - // - // Get the option's device path - // - DevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *) TempPtr; - TempPtr +=3D FilePathSize; - - // - // Validation boot option variable. - // - if ((FilePathSize =3D=3D 0) || (TempSize =3D=3D 0)) { - return FALSE; - } - - if (TempSize + FilePathSize + sizeof (UINT16) + sizeof (UINT32) > Variab= leSize) { - return FALSE; - } - - return (BOOLEAN) (GetDevicePathSizeEx (DevicePath, FilePathSize) !=3D 0); -} - -/** - Convert a single character to number. - It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F' - =20 - @param Char The input char which need to change to a hex number. - =20 -**/ -UINTN -CharToUint ( - IN CHAR16 Char - ) -{ - if ((Char >=3D L'0') && (Char <=3D L'9')) { - return (UINTN) (Char - L'0'); - } - - if ((Char >=3D L'A') && (Char <=3D L'F')) { - return (UINTN) (Char - L'A' + 0xA); - } - - ASSERT (FALSE); - return 0; -} - -/** - Build the boot#### or driver#### option from the VariableName, the - build boot#### or driver#### will also be linked to BdsCommonOptionList. - - @param BdsCommonOptionList The header of the boot#### or driver#### o= ption - link list - @param VariableName EFI Variable name indicate if it is boot##= ## or - driver#### - - @retval BDS_COMMON_OPTION Get the option just been created - @retval NULL Failed to get the new option - -**/ -BDS_COMMON_OPTION * -EFIAPI -BdsLibVariableToOption ( - IN OUT LIST_ENTRY *BdsCommonOptionList, - IN CHAR16 *VariableName - ) -{ - UINT32 Attribute; - UINT16 FilePathSize; - UINT8 *Variable; - UINT8 *TempPtr; - UINTN VariableSize; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - BDS_COMMON_OPTION *Option; - VOID *LoadOptions; - UINT32 LoadOptionsSize; - CHAR16 *Description; - UINT8 NumOff; - - // - // Read the variable. We will never free this data. - // - Variable =3D BdsLibGetVariableAndSize ( - VariableName, - &gEfiGlobalVariableGuid, - &VariableSize - ); - if (Variable =3D=3D NULL) { - return NULL; - } - - // - // Validate Boot#### variable data. - // - if (!ValidateOption(Variable, VariableSize)) { - FreePool (Variable); - return NULL; - } - - // - // Notes: careful defined the variable of Boot#### or - // Driver####, consider use some macro to abstract the code - // - // - // Get the option attribute - // - TempPtr =3D Variable; - Attribute =3D *(UINT32 *) Variable; - TempPtr +=3D sizeof (UINT32); - - // - // Get the option's device path size - // - FilePathSize =3D *(UINT16 *) TempPtr; - TempPtr +=3D sizeof (UINT16); - - // - // Get the option's description string - // - Description =3D (CHAR16 *) TempPtr; - - // - // Get the option's description string size - // - TempPtr +=3D StrSize((CHAR16 *) TempPtr); - - // - // Get the option's device path - // - DevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *) TempPtr; - TempPtr +=3D FilePathSize; - - // - // Get load opion data. - // - LoadOptions =3D TempPtr; - LoadOptionsSize =3D (UINT32) (VariableSize - (UINTN) (TempPtr - Variable= )); - - // - // The Console variables may have multiple device paths, so make - // an Entry for each one. - // - Option =3D AllocateZeroPool (sizeof (BDS_COMMON_OPTION)); - if (Option =3D=3D NULL) { - FreePool (Variable); - return NULL; - } - - Option->Signature =3D BDS_LOAD_OPTION_SIGNATURE; - Option->DevicePath =3D AllocateZeroPool (GetDevicePathSize (DevicePath)= ); - ASSERT(Option->DevicePath !=3D NULL); - CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath)); - - Option->Attribute =3D Attribute; - Option->Description =3D AllocateZeroPool (StrSize (Description)); - ASSERT(Option->Description !=3D NULL); - CopyMem (Option->Description, Description, StrSize (Description)); - - Option->LoadOptions =3D AllocateZeroPool (LoadOptionsSize); - ASSERT(Option->LoadOptions !=3D NULL); - CopyMem (Option->LoadOptions, LoadOptions, LoadOptionsSize); - Option->LoadOptionsSize =3D LoadOptionsSize; - - // - // Get the value from VariableName Unicode string - // since the ISO standard assumes ASCII equivalent abbreviations, we can= be safe in converting this - // Unicode stream to ASCII without any loss in meaning. - // - if (*VariableName =3D=3D 'B') { - NumOff =3D (UINT8) (sizeof (L"Boot") / sizeof (CHAR16) - 1); - Option->BootCurrent =3D (UINT16) (CharToUint (VariableName[NumOff+0]) = * 0x1000)=20 - + (UINT16) (CharToUint (VariableName[NumOff+1]) * 0x100) - + (UINT16) (CharToUint (VariableName[NumOff+2]) * 0x10) - + (UINT16) (CharToUint (VariableName[NumOff+3]) * 0x1); - } - InsertTailList (BdsCommonOptionList, &Option->Link); - FreePool (Variable); - return Option; -} - -/** - Process BootOrder, or DriverOrder variables, by calling - BdsLibVariableToOption () for each UINT16 in the variables. - - @param BdsCommonOptionList The header of the option list base on vari= able - VariableName - @param VariableName EFI Variable name indicate the BootOrder or - DriverOrder - - @retval EFI_SUCCESS Success create the boot option or driver o= ption - list - @retval EFI_OUT_OF_RESOURCES Failed to get the boot option or driver op= tion list - -**/ -EFI_STATUS -EFIAPI -BdsLibBuildOptionFromVar ( - IN LIST_ENTRY *BdsCommonOptionList, - IN CHAR16 *VariableName - ) -{ - UINT16 *OptionOrder; - UINTN OptionOrderSize; - UINTN Index; - BDS_COMMON_OPTION *Option; - CHAR16 OptionName[20]; - - // - // Zero Buffer in order to get all BOOT#### variables - // - ZeroMem (OptionName, sizeof (OptionName)); - - // - // Read the BootOrder, or DriverOrder variable. - // - OptionOrder =3D BdsLibGetVariableAndSize ( - VariableName, - &gEfiGlobalVariableGuid, - &OptionOrderSize - ); - if (OptionOrder =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - for (Index =3D 0; Index < OptionOrderSize / sizeof (UINT16); Index++) { - if (*VariableName =3D=3D 'B') { - UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", OptionO= rder[Index]); - } else { - UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", Optio= nOrder[Index]); - } - - Option =3D BdsLibVariableToOption (BdsCommonOptionList, O= ptionName); - if (Option !=3D NULL) { - Option->BootCurrent =3D OptionOrder[Index]; - } - } - - FreePool (OptionOrder); - - return EFI_SUCCESS; -} - -/** - Get boot mode by looking up configuration table and parsing HOB list - - @param BootMode Boot mode from PEI handoff HOB. - - @retval EFI_SUCCESS Successfully get boot mode - -**/ -EFI_STATUS -EFIAPI -BdsLibGetBootMode ( - OUT EFI_BOOT_MODE *BootMode - ) -{ - *BootMode =3D GetBootModeHob (); - - return EFI_SUCCESS; -} - -/** - Read the EFI variable (VendorGuid/Name) and return a dynamically allocat= ed - buffer, and the size of the buffer. If failure return NULL. - - @param Name String part of EFI variable name - @param VendorGuid GUID part of EFI variable name - @param VariableSize Returns the size of the EFI variable that = was read - - @return Dynamically allocated memory that contains= a copy of the EFI variable - Caller is responsible freeing the buffer. - @retval NULL Variable was not read - -**/ -VOID * -EFIAPI -BdsLibGetVariableAndSize ( - IN CHAR16 *Name, - IN EFI_GUID *VendorGuid, - OUT UINTN *VariableSize - ) -{ - EFI_STATUS Status; - UINTN BufferSize; - VOID *Buffer; - - Buffer =3D NULL; - - // - // Pass in a zero size buffer to find the required buffer size. - // - BufferSize =3D 0; - Status =3D gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, B= uffer); - if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { - // - // Allocate the buffer to return - // - Buffer =3D AllocateZeroPool (BufferSize); - if (Buffer =3D=3D NULL) { - *VariableSize =3D 0; - return NULL; - } - // - // Read variable into the allocated buffer. - // - Status =3D gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buff= er); - if (EFI_ERROR (Status)) { - FreePool (Buffer); - BufferSize =3D 0; - Buffer =3D NULL; - } - } - - ASSERT (((Buffer =3D=3D NULL) && (BufferSize =3D=3D 0)) || - ((Buffer !=3D NULL) && (BufferSize !=3D 0)) - ); - *VariableSize =3D BufferSize; - return Buffer; -} - -/** - Delete the instance in Multi which matches partly with Single instance - - @param Multi A pointer to a multi-instance device path = data - structure. - @param Single A pointer to a single-instance device path= data - structure. - - @return This function will remove the device path instances in Multi whi= ch partly - match with the Single, and return the result device path. If the= re is no - remaining device path as a result, this function will return NUL= L. - -**/ -EFI_DEVICE_PATH_PROTOCOL * -EFIAPI -BdsLibDelPartMatchInstance ( - IN EFI_DEVICE_PATH_PROTOCOL *Multi, - IN EFI_DEVICE_PATH_PROTOCOL *Single - ) -{ - EFI_DEVICE_PATH_PROTOCOL *Instance; - EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; - EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath; - UINTN InstanceSize; - UINTN SingleDpSize; - UINTN Size; - - NewDevicePath =3D NULL; - TempNewDevicePath =3D NULL; - - if (Multi =3D=3D NULL || Single =3D=3D NULL) { - return Multi; - } - - Instance =3D GetNextDevicePathInstance (&Multi, &InstanceSize); - SingleDpSize =3D GetDevicePathSize (Single) - END_DEVICE_PATH_LENGTH; - InstanceSize -=3D END_DEVICE_PATH_LENGTH; - - while (Instance !=3D NULL) { - - Size =3D (SingleDpSize < InstanceSize) ? SingleDpSize : InstanceSize; - - if ((CompareMem (Instance, Single, Size) !=3D 0)) { - // - // Append the device path instance which does not match with Single - // - TempNewDevicePath =3D NewDevicePath; - NewDevicePath =3D AppendDevicePathInstance (NewDevicePath, Instance); - if (TempNewDevicePath !=3D NULL) { - FreePool(TempNewDevicePath); - } - } - FreePool(Instance); - Instance =3D GetNextDevicePathInstance (&Multi, &InstanceSize); - InstanceSize -=3D END_DEVICE_PATH_LENGTH; - } - - return NewDevicePath; -} - -/** - Function compares a device path data structure to that of all the nodes = of a - second device path instance. - - @param Multi A pointer to a multi-instance device path = data - structure. - @param Single A pointer to a single-instance device path= data - structure. - - @retval TRUE If the Single device path is contained wit= hin Multi device path. - @retval FALSE The Single device path is not match within= Multi device path. - -**/ -BOOLEAN -EFIAPI -BdsLibMatchDevicePaths ( - IN EFI_DEVICE_PATH_PROTOCOL *Multi, - IN EFI_DEVICE_PATH_PROTOCOL *Single - ) -{ - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - EFI_DEVICE_PATH_PROTOCOL *DevicePathInst; - UINTN Size; - - if (Multi =3D=3D NULL || Single =3D=3D NULL) { - return FALSE; - } - - DevicePath =3D Multi; - DevicePathInst =3D GetNextDevicePathInstance (&DevicePath, &Size); - - // - // Search for the match of 'Single' in 'Multi' - // - while (DevicePathInst !=3D NULL) { - // - // If the single device path is found in multiple device paths, - // return success - // - if (CompareMem (Single, DevicePathInst, Size) =3D=3D 0) { - FreePool (DevicePathInst); - return TRUE; - } - - FreePool (DevicePathInst); - DevicePathInst =3D GetNextDevicePathInstance (&DevicePath, &Size); - } - - return FALSE; -} - -/** - This function prints a series of strings. - - @param ConOut Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL - @param ... A variable argument list containing series= of - strings, the last string must be NULL. - - @retval EFI_SUCCESS Success print out the string using ConOut. - @retval EFI_STATUS Return the status of the ConOut->OutputStr= ing (). - -**/ -EFI_STATUS -EFIAPI -BdsLibOutputStrings ( - IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut, - ... - ) -{ - VA_LIST Args; - EFI_STATUS Status; - CHAR16 *String; - - Status =3D EFI_SUCCESS; - VA_START (Args, ConOut); - - while (!EFI_ERROR (Status)) { - // - // If String is NULL, then it's the end of the list - // - String =3D VA_ARG (Args, CHAR16 *); - if (String =3D=3D NULL) { - break; - } - - Status =3D ConOut->OutputString (ConOut, String); - - if (EFI_ERROR (Status)) { - break; - } - } - =20 - VA_END(Args); - return Status; -} - -// -// Following are BDS Lib functions which contain all the code about setup= browser reset reminder feature. -// Setup Browser reset reminder feature is that an reset reminder will be= given before user leaves the setup browser if -// user change any option setting which needs a reset to be effective, an= d the reset will be applied according to the user selection. -// - - -/** - Enable the setup browser reset reminder feature. - This routine is used in platform tip. If the platform policy need the fe= ature, use the routine to enable it. - -**/ -VOID -EFIAPI -EnableResetReminderFeature ( - VOID - ) -{ - mFeaturerSwitch =3D TRUE; -} - - -/** - Disable the setup browser reset reminder feature. - This routine is used in platform tip. If the platform policy do not want= the feature, use the routine to disable it. - -**/ -VOID -EFIAPI -DisableResetReminderFeature ( - VOID - ) -{ - mFeaturerSwitch =3D FALSE; -} - - -/** - Record the info that a reset is required. - A module boolean variable is used to record whether a reset is required. - -**/ -VOID -EFIAPI -EnableResetRequired ( - VOID - ) -{ - mResetRequired =3D TRUE; -} - - -/** - Record the info that no reset is required. - A module boolean variable is used to record whether a reset is required. - -**/ -VOID -EFIAPI -DisableResetRequired ( - VOID - ) -{ - mResetRequired =3D FALSE; -} - - -/** - Check whether platform policy enable the reset reminder feature. The def= ault is enabled. - -**/ -BOOLEAN -EFIAPI -IsResetReminderFeatureEnable ( - VOID - ) -{ - return mFeaturerSwitch; -} - - -/** - Check if user changed any option setting which needs a system reset to = be effective. - -**/ -BOOLEAN -EFIAPI -IsResetRequired ( - VOID - ) -{ - return mResetRequired; -} - - -/** - Check whether a reset is needed, and finish the reset reminder feature. - If a reset is needed, Popup a menu to notice user, and finish the feature - according to the user selection. - -**/ -VOID -EFIAPI -SetupResetReminder ( - VOID - ) -{ - EFI_INPUT_KEY Key; - CHAR16 *StringBuffer1; - CHAR16 *StringBuffer2; - - - // - //check any reset required change is applied? if yes, reset system - // - if (IsResetReminderFeatureEnable ()) { - if (IsResetRequired ()) { - - StringBuffer1 =3D AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16)= ); - ASSERT (StringBuffer1 !=3D NULL); - StringBuffer2 =3D AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16)= ); - ASSERT (StringBuffer2 !=3D NULL); - StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it No= w."); - StrCpy (StringBuffer2, L"Press ENTER to reset"); - // - // Popup a menu to notice user - // - do { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuff= er1, StringBuffer2, NULL); - } while (Key.UnicodeChar !=3D CHAR_CARRIAGE_RETURN); - - FreePool (StringBuffer1); - FreePool (StringBuffer2); - - gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL); - } - } -} - -/** - Get the headers (dos, image, optional header) from an image - - @param Device SimpleFileSystem device handle - @param FileName File name for the image - @param DosHeader Pointer to dos header - @param Hdr The buffer in which to return the PE32, PE= 32+, or TE header. - - @retval EFI_SUCCESS Successfully get the machine type. - @retval EFI_NOT_FOUND The file is not found. - @retval EFI_LOAD_ERROR File is not a valid image file. - -**/ -EFI_STATUS -EFIAPI -BdsLibGetImageHeader ( - IN EFI_HANDLE Device, - IN CHAR16 *FileName, - OUT EFI_IMAGE_DOS_HEADER *DosHeader, - OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr - ) -{ - EFI_STATUS Status; - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume; - EFI_FILE_HANDLE Root; - EFI_FILE_HANDLE ThisFile; - UINTN BufferSize; - UINT64 FileSize; - EFI_FILE_INFO *Info; - - Root =3D NULL; - ThisFile =3D NULL; - // - // Handle the file system interface to the device - // - Status =3D gBS->HandleProtocol ( - Device, - &gEfiSimpleFileSystemProtocolGuid, - (VOID *) &Volume - ); - if (EFI_ERROR (Status)) { - goto Done; - } - - Status =3D Volume->OpenVolume ( - Volume, - &Root - ); - if (EFI_ERROR (Status)) { - Root =3D NULL; - goto Done; - } - ASSERT (Root !=3D NULL); - Status =3D Root->Open (Root, &ThisFile, FileName, EFI_FILE_MODE_READ, 0); - if (EFI_ERROR (Status)) { - goto Done; - } - ASSERT (ThisFile !=3D NULL); - - // - // Get file size - // - BufferSize =3D SIZE_OF_EFI_FILE_INFO + 200; - do { - Info =3D NULL; - Status =3D gBS->AllocatePool (EfiBootServicesData, BufferSize, (VOID *= *) &Info); - if (EFI_ERROR (Status)) { - goto Done; - } - Status =3D ThisFile->GetInfo ( - ThisFile, - &gEfiFileInfoGuid, - &BufferSize, - Info - ); - if (!EFI_ERROR (Status)) { - break; - } - if (Status !=3D EFI_BUFFER_TOO_SMALL) { - FreePool (Info); - goto Done; - } - FreePool (Info); - } while (TRUE); - - FileSize =3D Info->FileSize; - FreePool (Info); - - // - // Read dos header - // - BufferSize =3D sizeof (EFI_IMAGE_DOS_HEADER); - Status =3D ThisFile->Read (ThisFile, &BufferSize, DosHeader); - if (EFI_ERROR (Status) || - BufferSize < sizeof (EFI_IMAGE_DOS_HEADER) || - FileSize <=3D DosHeader->e_lfanew || - DosHeader->e_magic !=3D EFI_IMAGE_DOS_SIGNATURE) { - Status =3D EFI_LOAD_ERROR; - goto Done; - } - - // - // Move to PE signature - // - Status =3D ThisFile->SetPosition (ThisFile, DosHeader->e_lfanew); - if (EFI_ERROR (Status)) { - Status =3D EFI_LOAD_ERROR; - goto Done; - } - - // - // Read and check PE signature - // - BufferSize =3D sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION); - Status =3D ThisFile->Read (ThisFile, &BufferSize, Hdr.Pe32); - if (EFI_ERROR (Status) || - BufferSize < sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION) || - Hdr.Pe32->Signature !=3D EFI_IMAGE_NT_SIGNATURE) { - Status =3D EFI_LOAD_ERROR; - goto Done; - } - - // - // Check PE32 or PE32+ magic - // - if (Hdr.Pe32->OptionalHeader.Magic !=3D EFI_IMAGE_NT_OPTIONAL_HDR32_MAGI= C && - Hdr.Pe32->OptionalHeader.Magic !=3D EFI_IMAGE_NT_OPTIONAL_HDR64_MAGI= C) { - Status =3D EFI_LOAD_ERROR; - goto Done; - } - - Done: - if (ThisFile !=3D NULL) { - ThisFile->Close (ThisFile); - } - if (Root !=3D NULL) { - Root->Close (Root); - } - return Status; -} - -/** - This routine adjust the memory information for different memory type and=20 - save them into the variables for next boot. -**/ -VOID -BdsSetMemoryTypeInformationVariable ( - VOID - ) -{ - EFI_STATUS Status; - EFI_MEMORY_TYPE_INFORMATION *PreviousMemoryTypeInformation; - EFI_MEMORY_TYPE_INFORMATION *CurrentMemoryTypeInformation; - UINTN VariableSize; - UINTN Index; - UINTN Index1; - UINT32 Previous; - UINT32 Current; - UINT32 Next; - EFI_HOB_GUID_TYPE *GuidHob; - BOOLEAN MemoryTypeInformationModified; - BOOLEAN MemoryTypeInformationVariableExists; - EFI_BOOT_MODE BootMode; - - MemoryTypeInformationModified =3D FALSE; - MemoryTypeInformationVariableExists =3D FALSE; - - - BootMode =3D GetBootModeHob (); - // - // In BOOT_IN_RECOVERY_MODE, Variable region is not reliable. - // - if (BootMode =3D=3D BOOT_IN_RECOVERY_MODE) { - return; - } - - // - // Only check the the Memory Type Information variable in the boot mode=20 - // other than BOOT_WITH_DEFAULT_SETTINGS because the Memory Type - // Information is not valid in this boot mode. - // - if (BootMode !=3D BOOT_WITH_DEFAULT_SETTINGS) { - VariableSize =3D 0; - Status =3D gRT->GetVariable ( - EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME, - &gEfiMemoryTypeInformationGuid, - NULL,=20 - &VariableSize,=20 - NULL - ); - if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { - MemoryTypeInformationVariableExists =3D TRUE; - } - } - - // - // Retrieve the current memory usage statistics. If they are not found,= then - // no adjustments can be made to the Memory Type Information variable. - // - Status =3D EfiGetSystemConfigurationTable ( - &gEfiMemoryTypeInformationGuid, - (VOID **) &CurrentMemoryTypeInformation - ); - if (EFI_ERROR (Status) || CurrentMemoryTypeInformation =3D=3D NULL) { - return; - } - - // - // Get the Memory Type Information settings from Hob if they exist, - // PEI is responsible for getting them from variable and build a Hob to = save them. - // If the previous Memory Type Information is not available, then set de= faults - // - GuidHob =3D GetFirstGuidHob (&gEfiMemoryTypeInformationGuid); - if (GuidHob =3D=3D NULL) { - // - // If Platform has not built Memory Type Info into the Hob, just retur= n. - // - return; - } - PreviousMemoryTypeInformation =3D GET_GUID_HOB_DATA (GuidHob); - VariableSize =3D GET_GUID_HOB_DATA_SIZE (GuidHob); - - // - // Use a heuristic to adjust the Memory Type Information for the next bo= ot - // - DEBUG ((EFI_D_INFO, "Memory Previous Current Next \n")); - DEBUG ((EFI_D_INFO, " Type Pages Pages Pages \n")); - DEBUG ((EFI_D_INFO, "=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D =3D= =3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D\n")); - - for (Index =3D 0; PreviousMemoryTypeInformation[Index].Type !=3D EfiMaxM= emoryType; Index++) { - - for (Index1 =3D 0; CurrentMemoryTypeInformation[Index1].Type !=3D EfiM= axMemoryType; Index1++) { - if (PreviousMemoryTypeInformation[Index].Type =3D=3D CurrentMemoryTy= peInformation[Index1].Type) { - break; - } - } - if (CurrentMemoryTypeInformation[Index1].Type =3D=3D EfiMaxMemoryType)= { - continue; - } - - // - // Previous is the number of pages pre-allocated - // Current is the number of pages actually needed - // - Previous =3D PreviousMemoryTypeInformation[Index].NumberOfPages; - Current =3D CurrentMemoryTypeInformation[Index1].NumberOfPages; - Next =3D Previous; - - // - // Inconsistent Memory Reserved across bootings may lead to S4 fail - // Write next varible to 125% * current when the pre-allocated memory = is: - // 1. More than 150% of needed memory and boot mode is BOOT_WITH_DEFA= ULT_SETTING - // 2. Less than the needed memory - // - if ((Current + (Current >> 1)) < Previous) { - if (BootMode =3D=3D BOOT_WITH_DEFAULT_SETTINGS) { - Next =3D Current + (Current >> 2); - } - } else if (Current > Previous) { - Next =3D Current + (Current >> 2); - } - if (Next > 0 && Next < 4) { - Next =3D 4; - } - - if (Next !=3D Previous) { - PreviousMemoryTypeInformation[Index].NumberOfPages =3D Next; - MemoryTypeInformationModified =3D TRUE; - } - - DEBUG ((EFI_D_INFO, " %02x %08x %08x %08x\n", PreviousMemoryType= Information[Index].Type, Previous, Current, Next)); - } - - // - // If any changes were made to the Memory Type Information settings, the= n set the new variable value; - // Or create the variable in first boot. - // - if (MemoryTypeInformationModified || !MemoryTypeInformationVariableExist= s) { - Status =3D SetVariableAndReportStatusCodeOnError ( - EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME, - &gEfiMemoryTypeInformationGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCES= S, - VariableSize, - PreviousMemoryTypeInformation - ); - - if (!EFI_ERROR (Status)) { - // - // If the Memory Type Information settings have been modified, then = reset the platform - // so the new Memory Type Information setting will be used to guaran= tee that an S4 - // entry/resume cycle will not fail. - // - if (MemoryTypeInformationModified && PcdGetBool (PcdResetOnMemoryTyp= eInformationChange)) { - DEBUG ((EFI_D_INFO, "Memory Type Information settings change. Warm= Reset!!!\n")); - gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL); - } - } else { - DEBUG ((EFI_D_ERROR, "Memory Type Information settings cannot be sav= ed. OS S4 may fail!\n")); - } - } -} - -/** - This routine is kept for backward compatibility. -**/ -VOID -EFIAPI -BdsLibSaveMemoryTypeInformation ( - VOID - ) -{ -} - - -/** - Identify a user and, if authenticated, returns the current user profile = handle. - - @param[out] User Point to user profile handle. - =20 - @retval EFI_SUCCESS User is successfully identified, or user ide= ntification - is not supported. - @retval EFI_ACCESS_DENIED User is not successfully identified - -**/ -EFI_STATUS -EFIAPI -BdsLibUserIdentify ( - OUT EFI_USER_PROFILE_HANDLE *User - ) -{ - EFI_STATUS Status; - EFI_USER_MANAGER_PROTOCOL *Manager; - =20 - Status =3D gBS->LocateProtocol ( - &gEfiUserManagerProtocolGuid, - NULL, - (VOID **) &Manager - ); - if (EFI_ERROR (Status)) { - return EFI_SUCCESS; - } - - return Manager->Identify (Manager, User); -} - -/** - Set the variable and report the error through status code upon failure. - - @param VariableName A Null-terminated string that is the name= of the vendor's variable. - Each VariableName is unique for each Vend= orGuid. VariableName must - contain 1 or more characters. If Variable= Name is an empty string, - then EFI_INVALID_PARAMETER is returned. - @param VendorGuid A unique identifier for the vendor. - @param Attributes Attributes bitmask to set for the variabl= e. - @param DataSize The size in bytes of the Data buffer. Unl= ess the EFI_VARIABLE_APPEND_WRITE,=20 - EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, = or=20 - EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRI= TE_ACCESS attribute is set, a size of zero=20 - causes the variable to be deleted. When t= he EFI_VARIABLE_APPEND_WRITE attribute is=20 - set, then a SetVariable() call with a Dat= aSize of zero will not cause any change to=20 - the variable value (the timestamp associa= ted with the variable may be updated however=20 - even if no new data value is provided,see= the description of the=20 - EFI_VARIABLE_AUTHENTICATION_2 descriptor = below. In this case the DataSize will not=20 - be zero since the EFI_VARIABLE_AUTHENTICA= TION_2 descriptor will be populated).=20 - @param Data The contents for the variable. - - @retval EFI_SUCCESS The firmware has successfully stored the = variable and its data as - defined by the Attributes. - @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits,= name, and GUID was supplied, or the - DataSize exceeds the maximum allowed. - @retval EFI_INVALID_PARAMETER VariableName is an empty string. - @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold t= he variable and its data. - @retval EFI_DEVICE_ERROR The variable could not be retrieved due t= o a hardware error. - @retval EFI_WRITE_PROTECTED The variable in question is read-only. - @retval EFI_WRITE_PROTECTED The variable in question cannot be delete= d. - @retval EFI_SECURITY_VIOLATION The variable could not be written due to = EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS=20 - or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_= WRITE_ACESS being set, but the AuthInfo=20 - does NOT pass the validation check carrie= d out by the firmware. - - @retval EFI_NOT_FOUND The variable trying to be updated or dele= ted was not found. -**/ -EFI_STATUS -SetVariableAndReportStatusCodeOnError ( - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - IN UINT32 Attributes, - IN UINTN DataSize, - IN VOID *Data - ) -{ - EFI_STATUS Status; - EDKII_SET_VARIABLE_STATUS *SetVariableStatus; - UINTN NameSize; - - Status =3D gRT->SetVariable ( - VariableName, - VendorGuid, - Attributes, - DataSize, - Data - ); - if (EFI_ERROR (Status)) { - NameSize =3D StrSize (VariableName); - SetVariableStatus =3D AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS)= + NameSize + DataSize); - if (SetVariableStatus !=3D NULL) { - CopyGuid (&SetVariableStatus->Guid, VendorGuid); - SetVariableStatus->NameSize =3D NameSize; - SetVariableStatus->DataSize =3D DataSize; - SetVariableStatus->SetStatus =3D Status; - SetVariableStatus->Attributes =3D Attributes; - CopyMem (SetVariableStatus + 1, VariableNam= e, NameSize); - if ((Data !=3D NULL) && (DataSize !=3D 0)) { - CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Data, = DataSize); - } - - REPORT_STATUS_CODE_EX ( - EFI_ERROR_CODE, - PcdGet32 (PcdErrorCodeSetVariable), - 0, - NULL, - &gEdkiiStatusCodeDataTypeVariableGuid, - SetVariableStatus, - sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize - ); - - FreePool (SetVariableStatus); - } - } - - return Status; -} - diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModule= Pkg/Library/GenericBdsLib/DevicePath.c b/Platform/Intel/Vlv2TbltDevicePkg/O= verride/IntelFrameworkModulePkg/Library/GenericBdsLib/DevicePath.c deleted file mode 100644 index a0b9da880d..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Lib= rary/GenericBdsLib/DevicePath.c +++ /dev/null @@ -1,27 +0,0 @@ -/** @file - BDS internal function define the default device path string, it can be - replaced by platform device path. - -Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "InternalBdsLib.h" - -/** - This function converts an input device structure to a Unicode string. - - @param DevPath A pointer to the device path structure. - - @return A new allocated Unicode string that represents the device path. - -**/ -CHAR16 * -EFIAPI -DevicePathToStr ( - IN EFI_DEVICE_PATH_PROTOCOL *DevPath - ) -{ - return ConvertDevicePathToText (DevPath, TRUE, TRUE); -} diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModule= Pkg/Library/GenericBdsLib/GenericBdsLib.inf b/Platform/Intel/Vlv2TbltDevice= Pkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf deleted file mode 100644 index 795a9de4b8..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Lib= rary/GenericBdsLib/GenericBdsLib.inf +++ /dev/null @@ -1,143 +0,0 @@ -## @file -# General BDS library. -# =20 -# General BDS defines and produce general interfaces for platform BDS dri= ver including: -# 1) BDS boot policy interface; -# 2) BDS boot device connect interface; -# 3) BDS Misc interfaces for mainting boot variable, ouput string, etc. -# =20 -# Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: BSD-2-Clause-Patent -# =20 -## - -[Defines] - INF_VERSION =3D 0x00010005 - BASE_NAME =3D GenericBdsLib - MODULE_UNI_FILE =3D GenericBdsLib.uni - FILE_GUID =3D e405ec31-ccaa-4dd4-83e8-0aec01703f7e - MODULE_TYPE =3D DXE_DRIVER - VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D GenericBdsLib|DXE_DRIVER DXE_RUNTIME_= DRIVER UEFI_APPLICATION=20 - CONSTRUCTOR =3D GenericBdsLibConstructor - -# -# The following information is for reference only and not required by the = build tools. -# -# VALID_ARCHITECTURES =3D IA32 X64 EBC -# - -[Sources] - DevicePath.c - BdsConnect.c - BdsMisc.c - BdsConsole.c - BdsBoot.c - InternalBdsLib.h - String.h - String.c - GenericBdsStrings.uni - =20 -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - IntelFrameworkPkg/IntelFrameworkPkg.dec - IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec - ShellPkg/ShellPkg.dec - NetworkPkg/NetworkPkg.dec - -[LibraryClasses] - DevicePathLib - PeCoffGetEntryPointLib - BaseLib - HobLib - UefiRuntimeServicesTableLib - DxeServicesTableLib - MemoryAllocationLib - UefiLib - UefiBootServicesTableLib - BaseMemoryLib - DebugLib - PrintLib - PcdLib - PerformanceLib - TimerLib - DxeServicesLib - HiiLib - ReportStatusCodeLib - NetLib - BmpSupportLib - -[Guids] - ## SOMETIMES_CONSUMES ## HOB # The hob holding memory type infor= mation - ## SOMETIMES_CONSUMES ## SystemTable # The identifier of memory type inf= ormation type in system table - ## SOMETIMES_CONSUMES ## Variable:L"MemoryTypeInformation" - ## SOMETIMES_PRODUCES ## Variable:L"MemoryTypeInformation" - gEfiMemoryTypeInformationGuid =20 - ## SOMETIMES_CONSUMES ## Variable:L"BootXXXX" # Boot option variable - ## SOMETIMES_PRODUCES ## Variable:L"BootXXXX" # Boot option variable - ## SOMETIMES_CONSUMES ## Variable:L"DriverXXXX" # Driver load option. - ## SOMETIMES_PRODUCES ## Variable:L"DriverXXXX" # Driver load option. - ## SOMETIMES_CONSUMES ## Variable:L"BootNext" # Next Boot Option - ## SOMETIMES_PRODUCES ## Variable:L"BootNext" # Next Boot Option - ## SOMETIMES_CONSUMES ## Variable:L"BootOrder" # The boot option array - ## SOMETIMES_PRODUCES ## Variable:L"BootOrder" # The boot option array - ## SOMETIMES_CONSUMES ## Variable:L"DriverOrder" # The driver order list - ## SOMETIMES_CONSUMES ## Variable:L"ConIn" # The device path of co= nsole in device - ## SOMETIMES_PRODUCES ## Variable:L"ConIn" # The device path of co= nsole in device - ## SOMETIMES_CONSUMES ## Variable:L"ConOut" # The device path of co= nsole out device - ## SOMETIMES_PRODUCES ## Variable:L"ConOut" # The device path of co= nsole out device - ## SOMETIMES_CONSUMES ## Variable:L"ErrOut" # The device path of er= ror out device - ## SOMETIMES_PRODUCES ## Variable:L"ErrOut" # The device path of er= ror out device - ## SOMETIMES_PRODUCES ## Variable:L"BootCurrent" # The boot option of cu= rrent boot - ## SOMETIMES_PRODUCES ## Variable:L"BootNext" # The number of next bo= ot option - gEfiGlobalVariableGuid - gEfiFileInfoGuid ## SOMETIMES_CONSUMES ## G= UID - gLastEnumLangGuid ## SOMETIMES_PRODUCES ## V= ariable:L"LastEnumLang" # Platform language at last time enumeration. - gHdBootDevicePathVariablGuid ## SOMETIMES_PRODUCES ## V= ariable:L"HDDP" # The device path of Boot file on Hard device. - gBdsLibStringPackageGuid ## CONSUMES ## HII # HII S= tring PackageList Guid - ## SOMETIMES_PRODUCES ## Variable:L"LegacyDevOrder" - ## SOMETIMES_CONSUMES ## Variable:L"LegacyDevOrder" - gEfiLegacyDevOrderVariableGuid - gEdkiiStatusCodeDataTypeVariableGuid ## SOMETIMES_CONSUMES ## G= UID - gUefiShellFileGuid - -[Protocols] - gEfiSimpleFileSystemProtocolGuid ## SOMETIMES_CONSUMES - gEfiLoadFileProtocolGuid ## SOMETIMES_CONSUMES - gEfiSimpleTextOutProtocolGuid ## CONSUMES - gEfiPciIoProtocolGuid ## SOMETIMES_CONSUMES - gEfiLoadedImageProtocolGuid ## SOMETIMES_CONSUMES - gEfiSimpleNetworkProtocolGuid ## SOMETIMES_CONSUMES - gEfiDebugPortProtocolGuid ## SOMETIMES_CONSUMES - gEfiSimpleTextInProtocolGuid ## CONSUMES - gEfiBlockIoProtocolGuid ## SOMETIMES_CONSUMES - gEfiFirmwareVolume2ProtocolGuid ## SOMETIMES_CONSUMES - gEfiLegacyBiosProtocolGuid ## SOMETIMES_CONSUMES - gEfiCpuArchProtocolGuid ## CONSUMES - gEfiDevicePathProtocolGuid ## CONSUMES - gEfiAcpiS3SaveProtocolGuid ## SOMETIMES_CONSUMES - gEfiGraphicsOutputProtocolGuid ## SOMETIMES_CONSUMES - gEfiUgaDrawProtocolGuid |gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport #= # SOMETIMES_CONSUMES - gEfiOEMBadgingProtocolGuid ## SOMETIMES_CONSUMES - gEfiHiiFontProtocolGuid ## CONSUMES - gEfiUserManagerProtocolGuid ## SOMETIMES_CONSUMES - gEfiUsbIoProtocolGuid ## SOMETIMES_CONSUMES - gEfiBootLogoProtocolGuid ## SOMETIMES_CONSUMES - -[FeaturePcd] - gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport ## CONSU= MES - gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdBootlogoOnlyEnable ## CONSU= MES - -[Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange ## = SOMETIMES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderLoad ## SOMETIMES= _CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderStart ## SOMETIMES= _CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed ## C= ONSUMES - -# -# [BootMode]=20 -# RECOVERY_FULL ## SOMETIMES_CONSUMES # Memory Type Information varia= ble -# - diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModule= Pkg/Library/GenericBdsLib/GenericBdsLib.uni b/Platform/Intel/Vlv2TbltDevice= Pkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.uni deleted file mode 100644 index c853d3409e..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Lib= rary/GenericBdsLib/GenericBdsLib.uni +++ /dev/null @@ -1,19 +0,0 @@ -// /** @file -// General BDS library. -// -// General BDS defines and produce general interfaces for platform BDS dri= ver including: -// 1) BDS boot policy interface; -// 2) BDS boot device connect interface; -// 3) BDS Misc interfaces for mainting boot variable, ouput string, etc. -// -// Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
-// -// SPDX-License-Identifier: BSD-2-Clause-Patent -// -// **/ - - -#string STR_MODULE_ABSTRACT #language en-US "General BDS libra= ry" - -#string STR_MODULE_DESCRIPTION #language en-US "General BDS defin= es and produces general interfaces for a platform BDS driver including: 1) = BDS boot policy interface; 2) BDS boot device connect interface; 3) BDS Mis= c interfaces for maintaining boot variable, output string, etc." - diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModule= Pkg/Library/GenericBdsLib/GenericBdsStrings.uni b/Platform/Intel/Vlv2TbltDe= vicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsSt= rings.uni deleted file mode 100644 index 59a75e548b..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Lib= rary/GenericBdsLib/GenericBdsStrings.uni +++ /dev/null @@ -1,30 +0,0 @@ -///** @file -// =20 -// String definitions for Boot Option description. -// =20 -// Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.
-// SPDX-License-Identifier: BSD-2-Clause-Patent -// =20 -//**/ - -/=3D# - -#langdef en-US "English" -#langdef fr-FR "Fran=C3=A7ais" - -#string STR_DESCRIPTION_FLOPPY #language en-US "EFI Floppy" - #language fr-FR "fr-FR: EFI Floppy" -#string STR_DESCRIPTION_CD_DVD #language en-US "EFI DVD/CDROM" - #language fr-FR "fr-FR: EFI DVD/CD= ROM" -#string STR_DESCRIPTION_HARDDRIVE #language en-US "EFI Hard Drive" - #language fr-FR "fr-FR: EFI Hard D= rive" -#string STR_DESCRIPTION_USB #language en-US "EFI USB Device" - #language fr-FR "fr-FR: EFI USB De= vice" -#string STR_DESCRIPTION_SCSI #language en-US "EFI SCSI Device" - #language fr-FR "fr-FR: EFI SCSI D= evice" -#string STR_DESCRIPTION_MISC #language en-US "EFI Misc Device" - #language fr-FR "fr-FR: EFI Misc D= evice" -#string STR_DESCRIPTION_NETWORK #language en-US "EFI Network " - #language fr-FR "fr-FR: EFI Networ= k " -#string STR_DESCRIPTION_NON_BLOCK #language en-US "EFI Non-Block Boo= t Device" - #language fr-FR "fr-FR: EFI Non-Bl= ock Boot Device" diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModule= Pkg/Library/GenericBdsLib/InternalBdsLib.h b/Platform/Intel/Vlv2TbltDeviceP= kg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h deleted file mode 100644 index 025f06572b..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Lib= rary/GenericBdsLib/InternalBdsLib.h +++ /dev/null @@ -1,173 +0,0 @@ -/** @file - BDS library definition, include the file and data structure - -Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#ifndef _INTERNAL_BDS_LIB_H_ -#define _INTERNAL_BDS_LIB_H_ - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if !defined (EFI_REMOVABLE_MEDIA_FILE_NAME) - #if defined (MDE_CPU_EBC) - // - // Uefi specification only defines the default boot file name for = IA32, X64 - // and IPF processor, so need define boot file name for EBC archit= ecture here. - // - #define EFI_REMOVABLE_MEDIA_FILE_NAME L"\\EFI\\BOOT\\BOOTEBC.EFI" - #else - #error "Can not determine the default boot file name for unknown p= rocessor type!" - #endif -#endif - -/** - Get the headers (dos, image, optional header) from an image - - @param Device SimpleFileSystem device handle - @param FileName File name for the image - @param DosHeader Pointer to dos header - @param Hdr The buffer in which to return the PE32, PE= 32+, or TE header. - - @retval EFI_SUCCESS Successfully get the machine type. - @retval EFI_NOT_FOUND The file is not found. - @retval EFI_LOAD_ERROR File is not a valid image file. - -**/ -EFI_STATUS -EFIAPI -BdsLibGetImageHeader ( - IN EFI_HANDLE Device, - IN CHAR16 *FileName, - OUT EFI_IMAGE_DOS_HEADER *DosHeader, - OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr - ); - -/** - This routine adjust the memory information for different memory type and=20 - save them into the variables for next boot. -**/ -VOID -BdsSetMemoryTypeInformationVariable ( - VOID - ); - -/** - Validate the EFI Boot#### or Driver#### variable (VendorGuid/Name) - - @param Variable Boot#### variable data. - @param VariableSize Returns the size of the EFI variable that = was read - - @retval TRUE The variable data is correct. - @retval FALSE The variable data is corrupted. - -**/ -BOOLEAN=20 -ValidateOption ( - UINT8 *Variable, - UINTN VariableSize - ); - -/** - Set the variable and report the error through status code upon failure. - - @param VariableName A Null-terminated string that is the name= of the vendor's variable. - Each VariableName is unique for each Vend= orGuid. VariableName must - contain 1 or more characters. If Variable= Name is an empty string, - then EFI_INVALID_PARAMETER is returned. - @param VendorGuid A unique identifier for the vendor. - @param Attributes Attributes bitmask to set for the variabl= e. - @param DataSize The size in bytes of the Data buffer. Unl= ess the EFI_VARIABLE_APPEND_WRITE,=20 - EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, = or=20 - EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRI= TE_ACCESS attribute is set, a size of zero=20 - causes the variable to be deleted. When t= he EFI_VARIABLE_APPEND_WRITE attribute is=20 - set, then a SetVariable() call with a Dat= aSize of zero will not cause any change to=20 - the variable value (the timestamp associa= ted with the variable may be updated however=20 - even if no new data value is provided,see= the description of the=20 - EFI_VARIABLE_AUTHENTICATION_2 descriptor = below. In this case the DataSize will not=20 - be zero since the EFI_VARIABLE_AUTHENTICA= TION_2 descriptor will be populated).=20 - @param Data The contents for the variable. - - @retval EFI_SUCCESS The firmware has successfully stored the = variable and its data as - defined by the Attributes. - @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits,= name, and GUID was supplied, or the - DataSize exceeds the maximum allowed. - @retval EFI_INVALID_PARAMETER VariableName is an empty string. - @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold t= he variable and its data. - @retval EFI_DEVICE_ERROR The variable could not be retrieved due t= o a hardware error. - @retval EFI_WRITE_PROTECTED The variable in question is read-only. - @retval EFI_WRITE_PROTECTED The variable in question cannot be delete= d. - @retval EFI_SECURITY_VIOLATION The variable could not be written due to = EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS=20 - or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_= WRITE_ACESS being set, but the AuthInfo=20 - does NOT pass the validation check carrie= d out by the firmware. - - @retval EFI_NOT_FOUND The variable trying to be updated or dele= ted was not found. -**/ -EFI_STATUS -SetVariableAndReportStatusCodeOnError ( - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - IN UINT32 Attributes, - IN UINTN DataSize, - IN VOID *Data - ); - -#endif // _BDS_LIB_H_ diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModule= Pkg/Library/GenericBdsLib/String.c b/Platform/Intel/Vlv2TbltDevicePkg/Overr= ide/IntelFrameworkModulePkg/Library/GenericBdsLib/String.c deleted file mode 100644 index f36860d5a1..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Lib= rary/GenericBdsLib/String.c +++ /dev/null @@ -1,26 +0,0 @@ -/** @file - String support - -Copyright (c) 2010, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ -#include "String.h" - -/** - Get string by string id from HII Interface - - - @param Id String ID. - - @retval CHAR16 * String from ID. - @retval NULL If error occurs. - -**/ -CHAR16 * -BdsLibGetStringById ( - IN EFI_STRING_ID Id - ) -{ - return HiiGetString (gBdsLibStringPackHandle, Id, NULL); -} diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModule= Pkg/Library/GenericBdsLib/String.h b/Platform/Intel/Vlv2TbltDevicePkg/Overr= ide/IntelFrameworkModulePkg/Library/GenericBdsLib/String.h deleted file mode 100644 index 53cabe64a9..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Lib= rary/GenericBdsLib/String.h +++ /dev/null @@ -1,42 +0,0 @@ -/** @file - String support - -Copyright (c) 2010, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#ifndef _STRING_H_ -#define _STRING_H_ - -#include -#include -#include -#include -#include - -extern EFI_HII_HANDLE gBdsLibStringPackHandle; - -// -// This is the VFR compiler generated header file which defines the -// string identifiers. -// - -extern UINT8 GenericBdsLibStrings[]; - -/** - Get string by string id from HII Interface - - - @param Id String ID. - - @retval CHAR16 * String from ID. - @retval NULL If error occurs. - -**/ -CHAR16 * -BdsLibGetStringById ( - IN EFI_STRING_ID Id - ); - -#endif // _STRING_H_ diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkg.fdf b/Platform/In= tel/Vlv2TbltDevicePkg/PlatformPkg.fdf index 15a4251cf8..b0fbbdb9cb 100644 --- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkg.fdf +++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkg.fdf @@ -9,12 +9,10 @@ #**/ =20 [Defines] -DEFINE FLASH_BASE =3D 0xFF800000 #The base address of the 4Mb FL= ASH Device. -DEFINE FLASH_SIZE =3D 0x00800000 #The flash size in bytes of the= 4Mb FLASH Device. -DEFINE FLASH_BLOCK_SIZE =3D 0x1000 #The block size in bytes of the = 4Mb FLASH Device. -DEFINE FLASH_NUM_BLOCKS =3D 0x800 #The number of blocks in 4Mb F= LASH Device. -DEFINE FLASH_AREA_BASE_ADDRESS =3D 0xFF8000= 00 -DEFINE FLASH_AREA_SIZE =3D 0x008000= 00 +DEFINE FLASH_BASE =3D 0xFF800000 #The base address of the 8Mb FL= ASH Device. +DEFINE FLASH_SIZE =3D 0x00800000 #The flash size in bytes of the= 8Mb FLASH Device. +DEFINE FLASH_BLOCK_SIZE =3D 0x1000 #The block size in bytes of the= 8Mb FLASH Device. +DEFINE FLASH_NUM_BLOCKS =3D 0x800 #The number of blocks in 8Mb FL= ASH Device. =20 DEFINE FLASH_REGION_VLVMICROCODE_OFFSET =3D 0x004000= 00 DEFINE FLASH_REGION_VLVMICROCODE_SIZE =3D 0x000400= 00 @@ -62,8 +60,11 @@ [FD.Vlv] # #Flash location override based on actual flash map # -SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaBaseAddress =3D $= (FLASH_AREA_BASE_ADDRESS) -SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaSize =3D $= (FLASH_AREA_SIZE) +SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaBaseAddress =3D $= (FLASH_BASE) +SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaSize =3D $= (FLASH_SIZE) + +SET gPlatformModuleTokenSpaceGuid.PcdBiosRomBase =3D $= (FLASH_BASE) +SET gPlatformModuleTokenSpaceGuid.PcdBiosRomSize =3D $= (FLASH_SIZE) =20 SET gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress =3D $(FLASH_REGI= ON_VLVMICROCODE_BASE) + 0x60 SET gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize =3D $(FLASH_R= EGION_VLVMICROCODE_SIZE) - 0x60 @@ -401,12 +402,9 @@ [FV.FVMAIN] INF UefiCpuPkg/CpuDxe/CpuDxe.inf INF UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf INF MdeModulePkg/Universal/Metronome/Metronome.inf -INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf -!if $(ARCH) =3D=3D IA32 -INF USE=3DIA32 MdeModulePkg/Logo/Logo.inf -!else -INF USE=3DX64 MdeModulePkg/Logo/Logo.inf -!endif +INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf +INF MdeModulePkg/Logo/LogoDxe.inf +INF MdeModulePkg/Application/UiApp/UiApp.inf INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgGcc.fdf b/Platform= /Intel/Vlv2TbltDevicePkg/PlatformPkgGcc.fdf index b8ac61d710..107c160b76 100644 --- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgGcc.fdf +++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgGcc.fdf @@ -9,34 +9,32 @@ #**/ =20 [Defines] -DEFINE FLASH_BASE =3D 0xFFC00000 #The base address of the 4Mb FL= ASH Device. -DEFINE FLASH_SIZE =3D 0x00400000 #The flash size in bytes of the= 4Mb FLASH Device. -DEFINE FLASH_BLOCK_SIZE =3D 0x1000 #The block size in bytes of the = 4Mb FLASH Device. -DEFINE FLASH_NUM_BLOCKS =3D 0x400 #The number of blocks in 4Mb F= LASH Device. -DEFINE FLASH_AREA_BASE_ADDRESS =3D 0xFF8000= 00 -DEFINE FLASH_AREA_SIZE =3D 0x008000= 00 +DEFINE FLASH_BASE =3D 0xFF800000 #The base address of the 8Mb FL= ASH Device. +DEFINE FLASH_SIZE =3D 0x00800000 #The flash size in bytes of the= 8Mb FLASH Device. +DEFINE FLASH_BLOCK_SIZE =3D 0x1000 #The block size in bytes of the= 8Mb FLASH Device. +DEFINE FLASH_NUM_BLOCKS =3D 0x800 #The number of blocks in 8Mb FL= ASH Device. =20 -DEFINE FLASH_REGION_VLVMICROCODE_OFFSET =3D 0x000000= 00 +DEFINE FLASH_REGION_VLVMICROCODE_OFFSET =3D 0x004000= 00 DEFINE FLASH_REGION_VLVMICROCODE_SIZE =3D 0x000400= 00 DEFINE FLASH_REGION_VLVMICROCODE_BASE =3D 0xFFC000= 00 =20 -DEFINE FLASH_REGION_VPD_OFFSET =3D 0x000400= 00 +DEFINE FLASH_REGION_VPD_OFFSET =3D 0x004400= 00 DEFINE FLASH_REGION_VPD_SIZE =3D 0x0003E0= 00 =20 -DEFINE FLASH_REGION_NVSTORAGE_SUBREGION_NV_FTW_WORKING_OFFSET =3D 0x0007E0= 00 +DEFINE FLASH_REGION_NVSTORAGE_SUBREGION_NV_FTW_WORKING_OFFSET =3D 0x0047E0= 00 DEFINE FLASH_REGION_NVSTORAGE_SUBREGION_NV_FTW_WORKING_SIZE =3D 0x000020= 00 =20 =20 -DEFINE FLASH_REGION_NVSTORAGE_SUBREGION_NV_FTW_SPARE_OFFSET =3D 0x000800= 00 +DEFINE FLASH_REGION_NVSTORAGE_SUBREGION_NV_FTW_SPARE_OFFSET =3D 0x004800= 00 DEFINE FLASH_REGION_NVSTORAGE_SUBREGION_NV_FTW_SPARE_SIZE =3D 0x000400= 00 =20 -DEFINE FLASH_REGION_FVMAIN_OFFSET =3D 0x001100= 00 -DEFINE FLASH_REGION_FVMAIN_SIZE =3D 0x002150= 00 +DEFINE FLASH_REGION_FVMAIN_OFFSET =3D 0x005100= 00 +DEFINE FLASH_REGION_FVMAIN_SIZE =3D 0x002100= 00 =20 -DEFINE FLASH_REGION_FV_RECOVERY2_OFFSET =3D 0x003250= 00 -DEFINE FLASH_REGION_FV_RECOVERY2_SIZE =3D 0x0006B0= 00 +DEFINE FLASH_REGION_FV_RECOVERY2_OFFSET =3D 0x007200= 00 +DEFINE FLASH_REGION_FV_RECOVERY2_SIZE =3D 0x000700= 00 =20 -DEFINE FLASH_REGION_FV_RECOVERY_OFFSET =3D 0x003900= 00 +DEFINE FLASH_REGION_FV_RECOVERY_OFFSET =3D 0x007900= 00 DEFINE FLASH_REGION_FV_RECOVERY_SIZE =3D 0x000700= 00 =20 ##########################################################################= ###### @@ -62,8 +60,11 @@ [FD.Vlv] # #Flash location override based on actual flash map # -SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaBaseAddress =3D $= (FLASH_AREA_BASE_ADDRESS) -SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaSize =3D $= (FLASH_AREA_SIZE) +SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaBaseAddress =3D $= (FLASH_BASE) +SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaSize =3D $= (FLASH_SIZE) + +SET gPlatformModuleTokenSpaceGuid.PcdBiosRomBase =3D $= (FLASH_BASE) +SET gPlatformModuleTokenSpaceGuid.PcdBiosRomSize =3D $= (FLASH_SIZE) =20 SET gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress =3D $(FLASH_REGI= ON_VLVMICROCODE_BASE) + 0x60 SET gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize =3D $(FLASH_R= EGION_VLVMICROCODE_SIZE) - 0x60 @@ -84,9 +85,12 @@ [FD.Vlv] # Fv Size can be adjusted; FVMAIN_COMPACT can be reduced to 0x120000, and = FV_RECOVERY can be enlarged to 0x80000 # ##########################################################################= ###### -# Since the Fce tool don't have gcc version, we can't handle default varia= ble in Linux, -# so we hardcode the default value of variable here. -# Please note that we MUST update the binary once the default value is cha= nged. + + # + # IFWI Header + # +0x0000|0x1000 +FILE=3DVlv2TbltDevicePkg/Stitch/IFWIHeader/IFWI_HEADER.bin =20 # # CPU Microcodes @@ -347,12 +351,9 @@ [FV.FVMAIN] INF UefiCpuPkg/CpuDxe/CpuDxe.inf INF UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf INF MdeModulePkg/Universal/Metronome/Metronome.inf -INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf -!if $(ARCH) =3D=3D IA32 -INF USE=3DIA32 MdeModulePkg/Logo/Logo.inf -!else -INF USE=3DX64 MdeModulePkg/Logo/Logo.inf -!endif +INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf +INF MdeModulePkg/Logo/LogoDxe.inf +INF MdeModulePkg/Application/UiApp/UiApp.inf INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc b/Platf= orm/Intel/Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc index 3910281c49..e4c6750c70 100644 --- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc +++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc @@ -118,7 +118,6 @@ [LibraryClasses.common] DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableL= ib.inf UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf - GenericBdsLib|$(PLATFORM_PACKAGE)/Override/IntelFrameworkModulePkg/Libra= ry/GenericBdsLib/GenericBdsLib.inf BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.i= nf SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf FlashDeviceLib|Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLib.i= nf @@ -523,6 +522,8 @@ [PcdsFixedAtBuild.common] # gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackSize|0x4000 =20 + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c= , 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0= x31 } + # # Clear unused single certificate PCD # @@ -933,19 +934,18 @@ [Components.X64] } MdeModulePkg/Universal/Metronome/Metronome.inf =20 - IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf{ + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf { - OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf - IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf - BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf - PlatformBdsLib|$(PLATFORM_PACKAGE)/Library/PlatformBdsLib/PlatformBd= sLib.inf - DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPor= t.inf - PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerial= PortLib16550.inf + PlatformBootManagerLib|Vlv2TbltDevicePkg/Library/DxePlatformBootMana= gerLib/DxePlatformBootManagerLib.inf Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg= 2.inf } - - $(PLATFORM_PACKAGE)/UiApp/UiApp.inf + MdeModulePkg/Logo/LogoDxe.inf + MdeModulePkg/Application/UiApp/UiApp.inf { + + NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf + NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf + NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanc= eManagerUiLib.inf + } =20 MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc b/Platfor= m/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc index 2ae594e5be..f5795e5ab0 100644 --- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc +++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc @@ -116,7 +116,6 @@ [LibraryClasses.common] DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableL= ib.inf UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf - GenericBdsLib|$(PLATFORM_PACKAGE)/Override/IntelFrameworkModulePkg/Libra= ry/GenericBdsLib/GenericBdsLib.inf BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.i= nf SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf FlashDeviceLib|Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLib.i= nf @@ -520,6 +519,8 @@ [PcdsFixedAtBuild.common] # gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackSize|0x4000 =20 + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c= , 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0= x31 } + # # Clear unused single certificate PCD # @@ -917,19 +918,18 @@ [Components.IA32] } MdeModulePkg/Universal/Metronome/Metronome.inf =20 - IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf{ + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf { - OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf - IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf - BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf - PlatformBdsLib|$(PLATFORM_PACKAGE)/Library/PlatformBdsLib/PlatformBd= sLib.inf - DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPor= t.inf - PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerial= PortLib16550.inf + PlatformBootManagerLib|Vlv2TbltDevicePkg/Library/DxePlatformBootMana= gerLib/DxePlatformBootManagerLib.inf Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg= 2.inf } - - $(PLATFORM_PACKAGE)/UiApp/UiApp.inf + MdeModulePkg/Logo/LogoDxe.inf + MdeModulePkg/Application/UiApp/UiApp.inf { + + NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf + NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf + NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanc= eManagerUiLib.inf + } =20 MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc b/Platform= /Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc index 5cdc9bebc8..a930a85a35 100644 --- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc +++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc @@ -118,7 +118,6 @@ [LibraryClasses.common] DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableL= ib.inf UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf - GenericBdsLib|$(PLATFORM_PACKAGE)/Override/IntelFrameworkModulePkg/Libra= ry/GenericBdsLib/GenericBdsLib.inf BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.i= nf SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf FlashDeviceLib|Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLib.i= nf @@ -522,6 +521,8 @@ [PcdsFixedAtBuild.common] # gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackSize|0x4000 =20 + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c= , 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0= x31 } + # # Clear unused single certificate PCD # @@ -932,19 +933,18 @@ [Components.X64] } MdeModulePkg/Universal/Metronome/Metronome.inf =20 - IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf{ + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf { - OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf - IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf - BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf - PlatformBdsLib|$(PLATFORM_PACKAGE)/Library/PlatformBdsLib/PlatformBd= sLib.inf - DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPor= t.inf - PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerial= PortLib16550.inf + PlatformBootManagerLib|Vlv2TbltDevicePkg/Library/DxePlatformBootMana= gerLib/DxePlatformBootManagerLib.inf Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg= 2.inf } - - $(PLATFORM_PACKAGE)/UiApp/UiApp.inf + MdeModulePkg/Logo/LogoDxe.inf + MdeModulePkg/Application/UiApp/UiApp.inf { + + NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf + NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf + NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanc= eManagerUiLib.inf + } =20 MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf diff --git a/Platform/Intel/Vlv2TbltDevicePkg/UiApp/FrontPage.c b/Platform/= Intel/Vlv2TbltDevicePkg/UiApp/FrontPage.c deleted file mode 100644 index 3e58a6d22a..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/UiApp/FrontPage.c +++ /dev/null @@ -1,33 +0,0 @@ -/** @file - - Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.
- = =20 - SPDX-License-Identifier: BSD-2-Clause-Patent - - = =20 - - - -**/ - -/** - The user Entry Point for Application. The user code starts with this fun= ction - as the real entry point for the image goes into a library that calls this - function. - - @param[in] ImageHandle The firmware allocated handle for the EFI imag= e. - @param[in] SystemTable A pointer to the EFI System Table. - - @retval EFI_SUCCESS The entry point is executed successfully. - @retval other Some error occurs when executing this entry po= int. - -**/ -EFI_STATUS -EFIAPI -InitializeUserInterface ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - return EFI_SUCCESS; -} diff --git a/Platform/Intel/Vlv2TbltDevicePkg/UiApp/UiApp.inf b/Platform/In= tel/Vlv2TbltDevicePkg/UiApp/UiApp.inf deleted file mode 100644 index f7a0a83b80..0000000000 --- a/Platform/Intel/Vlv2TbltDevicePkg/UiApp/UiApp.inf +++ /dev/null @@ -1,32 +0,0 @@ -# -# -# Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.
-# = =20 -# SPDX-License-Identifier: BSD-2-Clause-Patent - -# = =20 -# -## - -[Defines] - INF_VERSION =3D 0x00010005 - BASE_NAME =3D UiApp - FILE_GUID =3D 462CAA21-7614-4503-836E-8AB6F4662331 - MODULE_TYPE =3D UEFI_APPLICATION - VERSION_STRING =3D 1.0 - ENTRY_POINT =3D InitializeUserInterface - -# -# The following information is for reference only and not required by the = build tools. -# -# VALID_ARCHITECTURES =3D IA32 X64 EBC -# - -[Sources] - FrontPage.c - -[Packages] - MdePkg/MdePkg.dec - -[LibraryClasses] - UefiApplicationEntryPoint --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#43069): https://edk2.groups.io/g/devel/message/43069 Mute This Topic: https://groups.io/mt/32267625/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-