summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Library
diff options
context:
space:
mode:
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>2009-01-23 07:23:46 +0000
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>2009-01-23 07:23:46 +0000
commitc516c7178a735366468dd4692d121213bb137888 (patch)
tree9dd5d725bcffb1a8b0ff9859608531755518c66a /MdeModulePkg/Library
parent6a3f4ef96dfd99ba62205dacc2938c436d279fa3 (diff)
downloadedk2-platforms-c516c7178a735366468dd4692d121213bb137888.tar.xz
Move BdsDxe and GenericBdsLib to IntelFrameworkModulePkg, these modules need dependent on gEfiLegacyBiosProtocol to provide legacy boot support. But legacy boot is not described by PI/UEFI specification.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7353 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Library')
-rw-r--r--MdeModulePkg/Library/GenericBdsLib/BdsBoot.c1911
-rw-r--r--MdeModulePkg/Library/GenericBdsLib/BdsConnect.c410
-rw-r--r--MdeModulePkg/Library/GenericBdsLib/BdsConsole.c896
-rw-r--r--MdeModulePkg/Library/GenericBdsLib/BdsMisc.c1272
-rw-r--r--MdeModulePkg/Library/GenericBdsLib/DevicePath.c1485
-rw-r--r--MdeModulePkg/Library/GenericBdsLib/GenericBdsLib.inf114
-rw-r--r--MdeModulePkg/Library/GenericBdsLib/InternalBdsLib.h106
-rw-r--r--MdeModulePkg/Library/GenericBdsLib/Ipf/ShadowRom.c46
-rw-r--r--MdeModulePkg/Library/GenericBdsLib/Performance.c316
-rw-r--r--MdeModulePkg/Library/PlatformBdsLibNull/BdsPlatform.h1
-rw-r--r--MdeModulePkg/Library/PlatformBdsLibNull/PlatformBdsLibNull.inf2
11 files changed, 2 insertions, 6557 deletions
diff --git a/MdeModulePkg/Library/GenericBdsLib/BdsBoot.c b/MdeModulePkg/Library/GenericBdsLib/BdsBoot.c
deleted file mode 100644
index d273e3f604..0000000000
--- a/MdeModulePkg/Library/GenericBdsLib/BdsBoot.c
+++ /dev/null
@@ -1,1911 +0,0 @@
-/** @file
- BDS Lib functions which relate with create or process the boot option.
-
-Copyright (c) 2004 - 2008, Intel Corporation. <BR>
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "InternalBdsLib.h"
-
-BOOLEAN mEnumBootDevice = FALSE;
-
-///
-/// This GUID is used for an EFI Variable that stores the front device pathes
-/// for a partial device path that starts with the HD node.
-///
-EFI_GUID mHdBootVariablePrivateGuid = { 0xfab7e9e1, 0x39dd, 0x4f2b, { 0x84, 0x8, 0xe2, 0xe, 0x90, 0x6c, 0xb6, 0xde } };
-
-
-
-/**
- Boot the legacy system with the boot option
-
- @param Option The legacy boot option which have BBS device path
-
- @retval EFI_UNSUPPORTED There is no legacybios protocol, do not support
- legacy boot.
- @retval EFI_STATUS Return the status of LegacyBios->LegacyBoot ().
-
-**/
-EFI_STATUS
-BdsLibDoLegacyBoot (
- IN BDS_COMMON_OPTION *Option
- )
-{
- EFI_STATUS Status;
- EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
-
- Status = 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 to a file
- //
- PERF_CODE (
- WriteBootToOsPerformanceData ();
- );
-
- DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Legacy Boot: %S\n", Option->Description));
- return LegacyBios->LegacyBoot (
- LegacyBios,
- (BBS_BBS_DEVICE_PATH *) Option->DevicePath,
- Option->LoadOptionsSize,
- Option->LoadOptions
- );
-}
-
-
-/**
- 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 load 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 successfully.
- @retval EFI_NOT_FOUND If the Device Path is not found in the system
-
-**/
-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_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;
-
- //
- // Record the performance data for End of BDS
- //
- PERF_END (0, BDS_TOK, NULL, 0);
-
- *ExitDataSize = 0;
- *ExitData = NULL;
-
- //
- // Notes: put EFI64 ROM Shadow Solution
- //
- EFI64_SHADOW_ALL_LEGACY_ROM ();
-
- //
- // 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 = 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 with the front part to compose a
- // full device path
- //
- WorkingDevicePath = NULL;
- if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&
- (DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)) {
- WorkingDevicePath = BdsExpandPartitionPartialDevicePathToFull (
- (HARDDRIVE_DEVICE_PATH *)DevicePath
- );
- if (WorkingDevicePath != NULL) {
- DevicePath = WorkingDevicePath;
- }
- }
- //
- // Signal the EVT_SIGNAL_READY_TO_BOOT event
- //
- EfiSignalEventReadyToBoot();
-
-
- //
- // Set Boot Current
- //
- gRT->SetVariable (
- L"BootCurrent",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- sizeof (UINT16),
- &Option->BootCurrent
- );
-
- ASSERT (Option->DevicePath != NULL);
- if ((DevicePathType (Option->DevicePath) == BBS_DEVICE_PATH) &&
- (DevicePathSubType (Option->DevicePath) == 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 = BdsLibUpdateFvFileDevicePath (&DevicePath, &gEfiShellFileGuid);
- if (!EFI_ERROR(Status)) {
- if (Option->DevicePath != NULL) {
- FreePool(Option->DevicePath);
- }
- Option->DevicePath = AllocateZeroPool (GetDevicePathSize (DevicePath));
- ASSERT(Option->DevicePath != NULL);
- CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));
- //
- // Update the shell boot option
- //
- InitializeListHead (&TempBootLists);
- BdsLibRegisterNewOption (&TempBootLists, DevicePath, L"EFI Internal Shell", L"BootOrder");
-
- //
- // free the temporary device path created by BdsLibUpdateFvFileDevicePath()
- //
- FreePool (DevicePath);
- DevicePath = Option->DevicePath;
- }
-
- DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Booting %S\n", Option->Description));
-
- Status = gBS->LoadImage (
- TRUE,
- mBdsImageHandle,
- DevicePath,
- NULL,
- 0,
- &ImageHandle
- );
-
- //
- // If we didn't find an image directly, we need to try as if it is a removable device boot opotion
- // and load the image according to the default boot behavior for removable 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 = BdsLibGetBootableHandle(DevicePath);
- if (Handle == NULL) {
- goto Done;
- }
- //
- // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media
- // machinename is ia32, ia64, x64, ...
- //
- FilePath = FileDevicePath (Handle, (CONST CHAR16*)PcdGetPtr(PcdDefaultBootFileName));
- if (FilePath != NULL) {
- Status = gBS->LoadImage (
- TRUE,
- mBdsImageHandle,
- FilePath,
- NULL,
- 0,
- &ImageHandle
- );
- if (EFI_ERROR (Status)) {
- //
- // The DevicePath failed, and it's not a valid
- // removable media device.
- //
- goto Done;
- }
- }
- }
-
- if (EFI_ERROR (Status)) {
- //
- // It there is any error from the Boot attempt exit now.
- //
- goto Done;
- }
- //
- // Provide the image with it's load options
- //
- Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &ImageInfo);
- ASSERT_EFI_ERROR (Status);
-
- if (Option->LoadOptionsSize != 0) {
- ImageInfo->LoadOptionsSize = Option->LoadOptionsSize;
- ImageInfo->LoadOptions = Option->LoadOptions;
- }
- //
- // Before calling the image, enable the Watchdog Timer for
- // the 5 Minute period
- //
- gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);
-
- Status = gBS->StartImage (ImageHandle, ExitDataSize, ExitData);
- DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Image Return Status = %r\n", Status));
-
- //
- // Clear the Watchdog Timer after the image returns
- //
- gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
-
-Done:
- //
- // Clear Boot Current
- //
- gRT->SetVariable (
- L"BootCurrent",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- 0,
- &Option->BootCurrent
- );
-
- return Status;
-}
-
-
-/**
- Expand a device path that starts with a hard drive media device path node 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 in a variable
- so a connect all is not required on every boot. All successful history device path
- which point to partition node (the front part) will be saved.
-
- @param HardDriveDevicePath EFI Device Path to boot, if it starts with 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 = NULL;
- //
- // Check if there is prestore 'HDDP' variable.
- // If exist, search the front path which point to partition node in the variable instants.
- // If fail to find or 'HDDP' not exist, reconnect all and search in all system
- //
- CachedDevicePath = BdsLibGetVariableAndSize (
- L"HDDP",
- &mHdBootVariablePrivateGuid,
- &CachedDevicePathSize
- );
-
- if (CachedDevicePath != NULL) {
- TempNewDevicePath = CachedDevicePath;
- DeviceExist = FALSE;
- NeedAdjust = FALSE;
- do {
- //
- // Check every instance of the variable
- // First, check whether the instance contain the partition node, which is needed for distinguishing multi
- // partial partition boot option. Second, check whether the instance could be connected.
- //
- Instance = 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 = BdsLibConnectDevicePath (Instance);
- if (!EFI_ERROR (Status)) {
- DeviceExist = TRUE;
- break;
- }
- }
- //
- // Come here means the first instance is not matched
- //
- NeedAdjust = TRUE;
- FreePool(Instance);
- } while (TempNewDevicePath != 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 = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);
- FullDevicePath = AppendDevicePath (Instance, DevicePath);
-
- //
- // Adjust the 'HDDP' instances sequence if the matched one is not first one.
- //
- if (NeedAdjust) {
- //
- // First delete the matched instance.
- //
- TempNewDevicePath = CachedDevicePath;
- CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, Instance );
- FreePool (TempNewDevicePath);
-
- //
- // Second, append the remaining path after the matched instance
- //
- TempNewDevicePath = CachedDevicePath;
- CachedDevicePath = AppendDevicePathInstance (Instance, CachedDevicePath );
- FreePool (TempNewDevicePath);
- //
- // Save the matching Device Path so we don't need to do a connect all next time
- //
- Status = gRT->SetVariable (
- L"HDDP",
- &mHdBootVariablePrivateGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- GetDevicePathSize (CachedDevicePath),
- CachedDevicePath
- );
- }
-
- FreePool (Instance);
- FreePool (CachedDevicePath);
- return FullDevicePath;
- }
- }
-
- //
- // If we get here we fail to find or 'HDDP' not exist, and now we need
- // to search all devices in the system for a matched partition
- //
- BdsLibConnectAllDriversToAllControllers ();
- Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &BlockIoHandleCount, &BlockIoBuffer);
- if (EFI_ERROR (Status) || BlockIoHandleCount == 0 || BlockIoBuffer == 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 = 0; Index < BlockIoHandleCount; Index++) {
-
- Status = gBS->HandleProtocol (BlockIoBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID *) &BlockIoDevicePath);
- if (EFI_ERROR (Status) || BlockIoDevicePath == NULL) {
- continue;
- }
-
- if (MatchPartitionDevicePathNode (BlockIoDevicePath, HardDriveDevicePath)) {
- //
- // Find the matched partition device path
- //
- DevicePath = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);
- FullDevicePath = AppendDevicePath (BlockIoDevicePath, DevicePath);
-
- //
- // Save the matched partition device path in 'HDDP' variable
- //
- if (CachedDevicePath != NULL) {
- //
- // Save the matched partition device path as first instance of 'HDDP' variable
- //
- if (BdsLibMatchDevicePaths (CachedDevicePath, BlockIoDevicePath)) {
- TempNewDevicePath = CachedDevicePath;
- CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, BlockIoDevicePath);
- FreePool(TempNewDevicePath);
-
- TempNewDevicePath = CachedDevicePath;
- CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath);
- FreePool(TempNewDevicePath);
- } else {
- TempNewDevicePath = CachedDevicePath;
- CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath);
- FreePool(TempNewDevicePath);
- }
- //
- // 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, the 'HDDP' variable maybe become larger and larger.
- //
- InstanceNum = 0;
- ASSERT (CachedDevicePath != NULL);
- TempNewDevicePath = CachedDevicePath;
- while (!IsDevicePathEnd (TempNewDevicePath)) {
- TempNewDevicePath = NextDevicePathNode (TempNewDevicePath);
- //
- // Parse one instance
- //
- while (!IsDevicePathEndType (TempNewDevicePath)) {
- TempNewDevicePath = NextDevicePathNode (TempNewDevicePath);
- }
- InstanceNum++;
- //
- // If the CachedDevicePath variable contain too much instance, only remain 12 instances.
- //
- if (InstanceNum >= 12) {
- SetDevicePathEndNode (TempNewDevicePath);
- break;
- }
- }
- } else {
- CachedDevicePath = DuplicateDevicePath (BlockIoDevicePath);
- }
-
- //
- // Save the matching Device Path so we don't need to do a connect all next time
- //
- Status = gRT->SetVariable (
- L"HDDP",
- &mHdBootVariablePrivateGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- GetDevicePathSize (CachedDevicePath),
- CachedDevicePath
- );
-
- break;
- }
- }
-
- FreePool (CachedDevicePath);
- if (BlockIoBuffer != NULL) {
- FreePool (BlockIoBuffer);
- }
- return FullDevicePath;
-}
-
-/**
- Check whether there is a instance in BlockIoDevicePath, which contain multi device path
- instances, has the same partition node with HardDriveDevicePath device path
-
- @param BlockIoDevicePath Multi device path instances which need to check
- @param HardDriveDevicePath A device path which starts with a hard drive 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 == NULL) || (HardDriveDevicePath == NULL)) {
- return FALSE;
- }
-
- //
- // Make PreviousDevicePath == the device path node before the end node
- //
- DevicePath = BlockIoDevicePath;
- BlockIoHdDevicePathNode = NULL;
-
- //
- // find the partition device path node
- //
- while (!IsDevicePathEnd (DevicePath)) {
- if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&
- (DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)
- ) {
- BlockIoHdDevicePathNode = DevicePath;
- break;
- }
-
- DevicePath = NextDevicePathNode (DevicePath);
- }
-
- if (BlockIoHdDevicePathNode == NULL) {
- return FALSE;
- }
- //
- // See if the harddrive device path in blockio matches the orig Hard Drive Node
- //
- TmpHdPath = (HARDDRIVE_DEVICE_PATH *) BlockIoHdDevicePathNode;
- Match = FALSE;
-
- //
- // Check for the match
- //
- if ((TmpHdPath->MBRType == HardDriveDevicePath->MBRType) &&
- (TmpHdPath->SignatureType == HardDriveDevicePath->SignatureType)) {
- switch (TmpHdPath->SignatureType) {
- case SIGNATURE_TYPE_GUID:
- Match = CompareGuid ((EFI_GUID *)TmpHdPath->Signature, (EFI_GUID *)HardDriveDevicePath->Signature);
- break;
- case SIGNATURE_TYPE_MBR:
- Match = (BOOLEAN)(*((UINT32 *)(&(TmpHdPath->Signature[0]))) == ReadUnaligned32((UINT32 *)(&(HardDriveDevicePath->Signature[0]))));
- break;
- default:
- Match = 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 system
- @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 = EFI_SUCCESS;
- BootOrder = NULL;
- BootOrderSize = 0;
-
- //
- // Check "BootOrder" variable, if no, means there is no any boot order.
- //
- BootOrder = BdsLibGetVariableAndSize (
- L"BootOrder",
- &gEfiGlobalVariableGuid,
- &BootOrderSize
- );
- if (BootOrder == NULL) {
- return EFI_NOT_FOUND;
- }
-
- //
- // Convert device handle to device path protocol instance
- //
- DevicePath = DevicePathFromHandle (Handle);
- if (DevicePath == NULL) {
- return EFI_NOT_FOUND;
- }
- DevicePathSize = GetDevicePathSize (DevicePath);
-
- //
- // Loop all boot order variable and find the matching device path
- //
- Index = 0;
- while (Index < BootOrderSize / sizeof (UINT16)) {
- UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);
- BootOptionVar = BdsLibGetVariableAndSize (
- BootOption,
- &gEfiGlobalVariableGuid,
- &BootOptionSize
- );
-
- if (BootOptionVar == NULL) {
- FreePool (BootOrder);
- return EFI_OUT_OF_RESOURCES;
- }
-
- TempPtr = BootOptionVar;
- TempPtr += sizeof (UINT32) + sizeof (UINT16);
- TempPtr += StrSize ((CHAR16 *) TempPtr);
- OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
- OptionDevicePathSize = GetDevicePathSize (OptionDevicePath);
-
- //
- // Check whether the device path match
- //
- if ((OptionDevicePathSize == DevicePathSize) &&
- (CompareMem (DevicePath, OptionDevicePath, DevicePathSize) == 0)) {
- BdsDeleteBootOption (BootOrder[Index], BootOrder, &BootOrderSize);
- FreePool (BootOptionVar);
- break;
- }
-
- FreePool (BootOptionVar);
- Index++;
- }
-
- //
- // Adjust number of boot option for "BootOrder" variable.
- //
- Status = gRT->SetVariable (
- L"BootOrder",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- BootOrderSize,
- BootOrder
- );
-
- FreePool (BootOrder);
-
- return Status;
-}
-
-
-/**
- Delete all invalid EFI boot options. The probable invalid boot option could
- be Removable media or Network boot device.
-
- @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;
-
- Status = EFI_SUCCESS;
- BootOrder = NULL;
- BootOrderSize = 0;
-
- //
- // Check "BootOrder" variable firstly, this variable hold the number of boot options
- //
- BootOrder = BdsLibGetVariableAndSize (
- L"BootOrder",
- &gEfiGlobalVariableGuid,
- &BootOrderSize
- );
- if (NULL == BootOrder) {
- return EFI_NOT_FOUND;
- }
-
- Index = 0;
- while (Index < BootOrderSize / sizeof (UINT16)) {
- UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);
- BootOptionVar = BdsLibGetVariableAndSize (
- BootOption,
- &gEfiGlobalVariableGuid,
- &BootOptionSize
- );
- if (NULL == BootOptionVar) {
- FreePool (BootOrder);
- return EFI_OUT_OF_RESOURCES;
- }
-
- TempPtr = BootOptionVar;
- TempPtr += sizeof (UINT32) + sizeof (UINT16);
- TempPtr += StrSize ((CHAR16 *) TempPtr);
- OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
-
- //
- // Skip legacy boot option (BBS boot device)
- //
- if ((DevicePathType (OptionDevicePath) == BBS_DEVICE_PATH) &&
- (DevicePathSubType (OptionDevicePath) == BBS_BBS_DP)) {
- FreePool (BootOptionVar);
- Index++;
- continue;
- }
-
- if (!BdsLibIsValidEFIBootOptDevicePath (OptionDevicePath, FALSE)) {
- //
- // Delete this invalid boot option "Boot####"
- //
- Status = gRT->SetVariable (
- BootOption,
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- 0,
- NULL
- );
- //
- // Mark this boot option in boot order as deleted
- //
- BootOrder[Index] = 0xffff;
- }
-
- FreePool (BootOptionVar);
- Index++;
- }
-
- //
- // Adjust boot order array
- //
- Index2 = 0;
- for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {
- if (BootOrder[Index] != 0xffff) {
- BootOrder[Index2] = BootOrder[Index];
- Index2 ++;
- }
- }
- Status = gRT->SetVariable (
- L"BootOrder",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- Index2 * sizeof (UINT16),
- BootOrder
- );
-
- FreePool (BootOrder);
-
- return Status;
-}
-
-
-/**
- This function will enumerate all possible boot device in the system,
- 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 and create
- the boot option base on that boot device
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibEnumerateAllBootOption (
- IN OUT LIST_ENTRY *BdsBootOptionList
- )
-{
- EFI_STATUS Status;
- UINT16 FloppyNumber;
- UINT16 CdromNumber;
- UINT16 UsbNumber;
- UINT16 MiscNumber;
- UINT16 NonBlockNumber;
- UINTN NumberBlockIoHandles;
- EFI_HANDLE *BlockIoHandles;
- EFI_BLOCK_IO_PROTOCOL *BlkIo;
- UINTN Index;
- UINTN NumberSimpleNetworkHandles;
- EFI_HANDLE *SimpleNetworkHandles;
- 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;
- EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData;
- EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
-
- FloppyNumber = 0;
- CdromNumber = 0;
- UsbNumber = 0;
- MiscNumber = 0;
- ZeroMem (Buffer, sizeof (Buffer));
-
- //
- // If the boot device enumerate happened, just get the boot
- // device from the boot order variable
- //
- if (mEnumBootDevice) {
- BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");
- return EFI_SUCCESS;
- }
-
- //
- // 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
- //
- gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiBlockIoProtocolGuid,
- NULL,
- &NumberBlockIoHandles,
- &BlockIoHandles
- );
-
- for (Index = 0; Index < NumberBlockIoHandles; Index++) {
- Status = gBS->HandleProtocol (
- BlockIoHandles[Index],
- &gEfiBlockIoProtocolGuid,
- (VOID **) &BlkIo
- );
- if (!EFI_ERROR (Status)) {
- if (!BlkIo->Media->RemovableMedia) {
- //
- // skip the non-removable block devices
- //
- continue;
- }
- }
- DevicePath = DevicePathFromHandle (BlockIoHandles[Index]);
- DevicePathType = BdsGetBootTypeFromDevicePath (DevicePath);
-
- switch (DevicePathType) {
- case BDS_EFI_ACPI_FLOPPY_BOOT:
- if (FloppyNumber == 0) {
- UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Floppy");
- } else {
- UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Floppy %d", FloppyNumber);
- }
- BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
- FloppyNumber++;
- break;
-
- case BDS_EFI_MESSAGE_ATAPI_BOOT:
- if (CdromNumber == 0) {
- UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI DVD/CDROM");
- } else {
- UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI DVD/CDROM %d", CdromNumber);
- }
- BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
- CdromNumber++;
- break;
-
- case BDS_EFI_MESSAGE_USB_DEVICE_BOOT:
- if (UsbNumber == 0) {
- UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI USB Device");
- } else {
- UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI USB Device %d", UsbNumber);
- }
- BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
- UsbNumber++;
- break;
-
- case BDS_EFI_MESSAGE_SCSI_BOOT:
- if (UsbNumber == 0) {
- UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI SCSI Device");
- } else {
- UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI SCSI Device %d", UsbNumber);
- }
- BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
- UsbNumber++;
- break;
-
- case BDS_EFI_MESSAGE_MISC_BOOT:
- if (MiscNumber == 0) {
- UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Misc Device");
- } else {
- UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Misc Device %d", MiscNumber);
- }
- BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
- MiscNumber++;
- break;
-
- default:
- break;
- }
- }
-
- if (NumberBlockIoHandles != 0) {
- FreePool (BlockIoHandles);
- }
-
- //
- // If there is simple file protocol which does not consume block Io protocol, create a boot option for it here.
- //
- NonBlockNumber = 0;
- gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiSimpleFileSystemProtocolGuid,
- NULL,
- &NumberFileSystemHandles,
- &FileSystemHandles
- );
- for (Index = 0; Index < NumberFileSystemHandles; Index++) {
- Status = 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 = &HdrData;
- NeedDelete = TRUE;
- Status = BdsLibGetImageHeader (
- FileSystemHandles[Index],
- (CHAR16*)PcdGetPtr (PcdDefaultBootFileName),
- &DosHeader,
- Hdr
- );
- if (!EFI_ERROR (Status) &&
- EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) &&
- Hdr.Pe32->OptionalHeader.Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
- NeedDelete = FALSE;
- }
-
- if (NeedDelete) {
- //
- // No such file or the file is not a EFI application, delete this boot option
- //
- BdsLibDeleteOptionFromHandle (FileSystemHandles[Index]);
- } else {
- if (NonBlockNumber == 0) {
- UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Non-Block Boot Device");
- } else {
- UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Non-Block Boot Device %d", NonBlockNumber);
- }
- BdsLibBuildOptionFromHandle (FileSystemHandles[Index], BdsBootOptionList, Buffer);
- NonBlockNumber++;
- }
- }
-
- if (NumberFileSystemHandles != 0) {
- FreePool (FileSystemHandles);
- }
-
- //
- // Parse Network Boot Device
- //
- gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiSimpleNetworkProtocolGuid,
- NULL,
- &NumberSimpleNetworkHandles,
- &SimpleNetworkHandles
- );
- for (Index = 0; Index < NumberSimpleNetworkHandles; Index++) {
- if (Index == 0) {
- UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Network");
- } else {
- UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Network %d", Index);
- }
- BdsLibBuildOptionFromHandle (SimpleNetworkHandles[Index], BdsBootOptionList, Buffer);
- }
-
- if (NumberSimpleNetworkHandles != 0) {
- FreePool (SimpleNetworkHandles);
- }
-
- //
- // Check if we have on flash shell
- //
- gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiFirmwareVolume2ProtocolGuid,
- NULL,
- &FvHandleCount,
- &FvHandleBuffer
- );
- for (Index = 0; Index < FvHandleCount; Index++) {
- //
- // Only care the dispatched FV. If no dispatch protocol on the FV, it is not dispatched, then skip it.
- //
- Status = gBS->HandleProtocol (
- FvHandleBuffer[Index],
- &gEfiFirmwareVolumeDispatchProtocolGuid,
- (VOID **) &Fv
- );
- if (EFI_ERROR (Status)) {
- continue;
- }
-
- gBS->HandleProtocol (
- FvHandleBuffer[Index],
- &gEfiFirmwareVolume2ProtocolGuid,
- (VOID **) &Fv
- );
-
- Status = Fv->ReadFile (
- Fv,
- &gEfiShellFileGuid,
- 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 != 0) {
- FreePool (FvHandleBuffer);
- }
- //
- // Make sure every boot only have one time
- // boot device enumerate
- //
- BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");
- mEnumBootDevice = TRUE;
-
- return EFI_SUCCESS;
-}
-
-/**
- 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 = DevicePathFromHandle (Handle);
-
- //
- // Create and register new boot option
- //
- BdsLibRegisterNewOption (BdsBootOptionList, DevicePath, String, L"BootOrder");
-}
-
-
-/**
- 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 = DevicePathFromHandle (Handle);
-
- //
- // Build the shell device path
- //
- EfiInitializeFwVolDevicepathNode (&ShellNode, &gEfiShellFileGuid);
-
- DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &ShellNode);
-
- //
- // Create and register the shell boot option
- //
- BdsLibRegisterNewOption (BdsBootOptionList, DevicePath, L"EFI Internal Shell", L"BootOrder");
-
-}
-
-/**
- Boot from the UEFI spec defined "BootNext" variable.
-
-**/
-VOID
-EFIAPI
-BdsLibBootNext (
- VOID
- )
-{
- 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 = BdsLibGetVariableAndSize (
- L"BootNext",
- &gEfiGlobalVariableGuid,
- &BootNextSize
- );
-
- //
- // Clear the boot next variable first
- //
- if (BootNext != NULL) {
- gRT->SetVariable (
- L"BootNext",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- 0,
- BootNext
- );
-
- //
- // Start to build the boot option and try to boot
- //
- UnicodeSPrint (Buffer, sizeof (Buffer), L"Boot%04x", *BootNext);
- BootOption = BdsLibVariableToOption (&TempList, Buffer);
- ASSERT (BootOption != NULL);
- BdsLibConnectDevicePath (BootOption->DevicePath);
- BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);
- }
-
-}
-
-/**
- Return the bootable media handle.
- First, check the device is connected
- Second, check whether the device path point to a device which support SimpleFileSystemProtocol,
- Third, detect the the default boot file in the Media, and return the removable Media handle.
-
- @param DevicePath Device Path to a bootable device
-
- @retval NULL The media on the DevicePath is not bootable
-
-**/
-EFI_HANDLE
-EFIAPI
-BdsLibGetBootableHandle (
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
- )
-{
- EFI_STATUS Status;
- 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 = DevicePath;
-
- //
- // Check whether the device is connected
- //
- Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &UpdatedDevicePath, &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 = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &UpdatedDevicePath, &Handle);
- if (EFI_ERROR (Status)) {
- //
- // Fail to find the proper BlockIo and simple file protocol, maybe because device not present, we need to connect it firstly
- //
- UpdatedDevicePath = DevicePath;
- Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &UpdatedDevicePath, &Handle);
- gBS->ConnectController (Handle, NULL, NULL, TRUE);
- }
- } else {
- //
- // Get BlockIo protocol and check removable attribute
- //
- Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);
- //
- // 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 = AllocatePool (BlockIo->Media->BlockSize);
- if (Buffer != 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 BDS 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 previous PCI node to search
- //
- DupDevicePath = DuplicateDevicePath (DevicePath);
- ASSERT (DupDevicePath != NULL);
-
- UpdatedDevicePath = DupDevicePath;
- Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &UpdatedDevicePath, &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 node
- // Acpi()/Pci()/Usb() --> Acpi()/Pci()
- //
- if ((DevicePathType (UpdatedDevicePath) == MESSAGING_DEVICE_PATH) &&
- (DevicePathSubType (UpdatedDevicePath) == MSG_USB_DP)) {
- //
- // Remove the usb node, let the device path only point to PCI node
- //
- SetDevicePathEndNode (UpdatedDevicePath);
- UpdatedDevicePath = DupDevicePath;
- } else {
- UpdatedDevicePath = DevicePath;
- }
-
- //
- // Get the device path size of boot option
- //
- Size = GetDevicePathSize(UpdatedDevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL); // minus the end node
- ReturnHandle = NULL;
- gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiSimpleFileSystemProtocolGuid,
- NULL,
- &NumberSimpleFileSystemHandles,
- &SimpleFileSystemHandles
- );
- for (Index = 0; Index < NumberSimpleFileSystemHandles; Index++) {
- //
- // Get the device path size of SimpleFileSystem handle
- //
- TempDevicePath = DevicePathFromHandle (SimpleFileSystemHandles[Index]);
- TempSize = GetDevicePathSize (TempDevicePath)- sizeof (EFI_DEVICE_PATH_PROTOCOL); // minus the end node
- //
- // Check whether the device path of boot option is part of the SimpleFileSystem handle's device path
- //
- if (Size <= TempSize && CompareMem (TempDevicePath, UpdatedDevicePath, Size)==0) {
- //
- // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media
- // machinename is ia32, ia64, x64, ...
- //
- Hdr.Union = &HdrData;
- Status = BdsLibGetImageHeader (
- SimpleFileSystemHandles[Index],
- (CHAR16*)PcdGetPtr(PcdDefaultBootFileName),
- &DosHeader,
- Hdr
- );
- if (!EFI_ERROR (Status) &&
- EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) &&
- Hdr.Pe32->OptionalHeader.Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
- ReturnHandle = SimpleFileSystemHandles[Index];
- break;
- }
- }
- }
-
- FreePool(DupDevicePath);
-
- if (SimpleFileSystemHandles != NULL) {
- FreePool(SimpleFileSystemHandles);
- }
-
- 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 connected
- @retval FALSE DevicePath does not point to a bootable network
-
-**/
-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;
-
- MediaPresent = FALSE;
-
- UpdatedDevicePath = DevicePath;
- Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &UpdatedDevicePath, &Handle);
- if (EFI_ERROR (Status)) {
- //
- // Device not present so see if we need to connect it
- //
- Status = BdsLibConnectDevicePath (DevicePath);
- if (!EFI_ERROR (Status)) {
- //
- // This one should work after we did the connect
- //
- Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &UpdatedDevicePath, &Handle);
- }
- }
-
- if (!EFI_ERROR (Status)) {
- Status = gBS->HandleProtocol (Handle, &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp);
- if (!EFI_ERROR (Status)) {
- if (Snp->Mode->MediaPresentSupported) {
- if (Snp->Mode->State == EfiSimpleNetworkInitialized) {
- //
- // In case some one else is using the SNP check to see if it's connected
- //
- MediaPresent = Snp->Mode->MediaPresent;
- } else {
- //
- // No one is using SNP so we need to Start and Initialize so
- // MediaPresent will be valid.
- //
- Status = Snp->Start (Snp);
- if (!EFI_ERROR (Status)) {
- Status = Snp->Initialize (Snp, 0, 0);
- if (!EFI_ERROR (Status)) {
- MediaPresent = Snp->Mode->MediaPresent;
- Snp->Shutdown (Snp);
- }
- Snp->Stop (Snp);
- }
- }
- } else {
- MediaPresent = 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 the device path contains any media device path node, it is media boot type
- For the floppy node, handle it as media node
- @retval BDS_EFI_MEDIA_CDROM_BOOT If the device path contains any media device path node, it is media boot type
- For the floppy node, handle it as media node
- @retval BDS_EFI_ACPI_FLOPPY_BOOT If the device path contains any media device path node, it is media boot type
- For the floppy node, handle it as media node
- @retval BDS_EFI_MESSAGE_ATAPI_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, it is
-
- @retval BDS_EFI_MESSAGE_SCSI_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, it is
- @retval BDS_EFI_MESSAGE_USB_DEVICE_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, it is
- @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, it is
- @retval BDS_LEGACY_BBS_BOOT Legacy boot type
- @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;
-
-
- if (NULL == DevicePath) {
- return BDS_EFI_UNSUPPORT;
- }
-
- TempDevicePath = DevicePath;
-
- while (!IsDevicePathEndType (TempDevicePath)) {
- switch (DevicePathType (TempDevicePath)) {
- case BBS_DEVICE_PATH:
- return BDS_LEGACY_BBS_BOOT;
- case MEDIA_DEVICE_PATH:
- if (DevicePathSubType (TempDevicePath) == MEDIA_HARDDRIVE_DP) {
- return BDS_EFI_MEDIA_HD_BOOT;
- } else if (DevicePathSubType (TempDevicePath) == MEDIA_CDROM_DP) {
- return BDS_EFI_MEDIA_CDROM_BOOT;
- }
- break;
- case ACPI_DEVICE_PATH:
- Acpi = (ACPI_HID_DEVICE_PATH *) TempDevicePath;
- if (EISA_ID_TO_NUM (Acpi->HID) == 0x0604) {
- return BDS_EFI_ACPI_FLOPPY_BOOT;
- }
- break;
- case MESSAGING_DEVICE_PATH:
- //
- // Get the last device path node
- //
- LastDeviceNode = NextDevicePathNode (TempDevicePath);
- if (DevicePathSubType(LastDeviceNode) == MSG_DEVICE_LOGICAL_UNIT_DP) {
- //
- // if the next node type is Device Logical Unit, which specify the Logical Unit Number (LUN),
- // skit it
- //
- LastDeviceNode = NextDevicePathNode (LastDeviceNode);
- }
- //
- // if the device path not only point to driver device, it is not a messaging device path,
- //
- if (!IsDevicePathEndType (LastDeviceNode)) {
- break;
- }
-
- if (DevicePathSubType(TempDevicePath) == MSG_ATAPI_DP) {
- return BDS_EFI_MESSAGE_ATAPI_BOOT;
- } else if (DevicePathSubType(TempDevicePath) == MSG_USB_DP) {
- return BDS_EFI_MESSAGE_USB_DEVICE_BOOT;
- } else if (DevicePathSubType(TempDevicePath) == MSG_SCSI_DP) {
- return BDS_EFI_MESSAGE_SCSI_BOOT;
- }
- return BDS_EFI_MESSAGE_MISC_BOOT;
- default:
- break;
- }
- TempDevicePath = 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
- )
-{
- EFI_STATUS Status;
- EFI_HANDLE Handle;
- EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
- EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode;
- EFI_BLOCK_IO_PROTOCOL *BlockIo;
-
- TempDevicePath = DevPath;
- LastDeviceNode = DevPath;
-
- //
- // Check if it's a valid boot option for network boot device
- // Only check if there is SimpleNetworkProtocol installed. If yes, that means
- // there is the network card there.
- //
- Status = gBS->LocateDevicePath (
- &gEfiSimpleNetworkProtocolGuid,
- &TempDevicePath,
- &Handle
- );
- if (EFI_ERROR (Status)) {
- //
- // Device not present so see if we need to connect it
- //
- TempDevicePath = DevPath;
- BdsLibConnectDevicePath (TempDevicePath);
- Status = gBS->LocateDevicePath (
- &gEfiSimpleNetworkProtocolGuid,
- &TempDevicePath,
- &Handle
- );
- }
-
- if (!EFI_ERROR (Status)) {
- if (CheckMedia) {
- //
- // Test if it is ready to boot now
- //
- if (BdsLibNetworkBootWithMediaPresent(DevPath)) {
- return TRUE;
- }
- } else {
- return TRUE;
- }
- }
-
- //
- // 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)) {
- LastDeviceNode = TempDevicePath;
- TempDevicePath = NextDevicePathNode (TempDevicePath);
- }
- if ((DevicePathType (LastDeviceNode) == MEDIA_DEVICE_PATH) &&
- (DevicePathSubType (LastDeviceNode) == MEDIA_FILEPATH_DP)) {
- return TRUE;
- }
-
- //
- // Check if it's a valid boot option for internal Shell
- //
- if (EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode) != NULL) {
- //
- // If the boot option point to Internal FV shell, make sure it is valid
- //
- TempDevicePath = DevPath;
- Status = BdsLibUpdateFvFileDevicePath (&TempDevicePath, &gEfiShellFileGuid);
- if (Status == EFI_ALREADY_STARTED) {
- return TRUE;
- } else {
- if (Status == EFI_SUCCESS) {
- FreePool (TempDevicePath);
- }
- return FALSE;
- }
- }
-
- //
- // If the boot option point to a blockIO device, no matter whether or not it is a removeable device, it is a valid EFI boot option
- //
- TempDevicePath = DevPath;
- Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDevicePath, &Handle);
- if (EFI_ERROR (Status)) {
- //
- // Device not present so see if we need to connect it
- //
- Status = BdsLibConnectDevicePath (DevPath);
- if (!EFI_ERROR (Status)) {
- //
- // Try again to get the Block Io protocol after we did the connect
- //
- TempDevicePath = DevPath;
- Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDevicePath, &Handle);
- }
- }
-
- if (!EFI_ERROR (Status)) {
- Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);
- if (!EFI_ERROR (Status)) {
- if (CheckMedia) {
- //
- // Test if it is ready to boot now
- //
- if (BdsLibGetBootableHandle (DevPath) != NULL) {
- return TRUE;
- }
- } else {
- return TRUE;
- }
- }
- } else {
- //
- // if the boot option point to a simple file protocol which does not consume block Io protocol, it is also a valid EFI boot option,
- //
- Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &TempDevicePath, &Handle);
- if (!EFI_ERROR (Status)) {
- if (CheckMedia) {
- //
- // Test if it is ready to boot now
- //
- if (BdsLibGetBootableHandle (DevPath) != NULL) {
- return TRUE;
- }
- } else {
- return TRUE;
- }
- }
- }
-
- return FALSE;
-}
-
-
-/**
- According to a file guild, check a Fv file device path is valid. If it is 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 invalid
- 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 file, it is
- valid
- @retval EFI_SUCCESS has successfully updated the invalid DevicePath,
- and return the updated device path in DevicePath
-
-**/
-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 == NULL) || (*DevicePath == NULL)) {
- return EFI_INVALID_PARAMETER;
- }
- if (FileGuid == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Check whether the device path point to the default the input Fv file
- //
- TempDevicePath = *DevicePath;
- LastDeviceNode = TempDevicePath;
- while (!IsDevicePathEnd (TempDevicePath)) {
- LastDeviceNode = TempDevicePath;
- TempDevicePath = NextDevicePathNode (TempDevicePath);
- }
- GuidPoint = EfiGetNameGuidFromFwVolDevicePathNode (
- (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode
- );
- if (GuidPoint == NULL) {
- //
- // if this option does not points to a Fv file, just return EFI_UNSUPPORTED
- //
- return EFI_UNSUPPORTED;
- }
- if (!CompareGuid (GuidPoint, FileGuid)) {
- //
- // If the Fv file is not the input file guid, just return EFI_UNSUPPORTED
- //
- return EFI_UNSUPPORTED;
- }
-
- //
- // Check whether the input Fv file device path is valid
- //
- TempDevicePath = *DevicePath;
- FoundFvHandle = NULL;
- Status = gBS->LocateDevicePath (
- &gEfiFirmwareVolume2ProtocolGuid,
- &TempDevicePath,
- &FoundFvHandle
- );
- if (!EFI_ERROR (Status)) {
- Status = 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 = 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 usually are in the same FV
- //
- FindFvFile = FALSE;
- FoundFvHandle = NULL;
- Status = gBS->HandleProtocol (
- mBdsImageHandle,
- &gEfiLoadedImageProtocolGuid,
- (VOID **) &LoadedImage
- );
- if (!EFI_ERROR (Status)) {
- Status = gBS->HandleProtocol (
- LoadedImage->DeviceHandle,
- &gEfiFirmwareVolume2ProtocolGuid,
- (VOID **) &Fv
- );
- if (!EFI_ERROR (Status)) {
- Status = Fv->ReadFile (
- Fv,
- FileGuid,
- NULL,
- &Size,
- &Type,
- &Attributes,
- &AuthenticationStatus
- );
- if (!EFI_ERROR (Status)) {
- FindFvFile = TRUE;
- FoundFvHandle = LoadedImage->DeviceHandle;
- }
- }
- }
- //
- // Second, if fail to find, try to enumerate all FV
- //
- if (!FindFvFile) {
- FvHandleBuffer = NULL;
- gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiFirmwareVolume2ProtocolGuid,
- NULL,
- &FvHandleCount,
- &FvHandleBuffer
- );
- for (Index = 0; Index < FvHandleCount; Index++) {
- gBS->HandleProtocol (
- FvHandleBuffer[Index],
- &gEfiFirmwareVolume2ProtocolGuid,
- (VOID **) &Fv
- );
-
- Status = Fv->ReadFile (
- Fv,
- FileGuid,
- NULL,
- &Size,
- &Type,
- &Attributes,
- &AuthenticationStatus
- );
- if (EFI_ERROR (Status)) {
- //
- // Skip if input Fv file not in the FV
- //
- continue;
- }
- FindFvFile = TRUE;
- FoundFvHandle = FvHandleBuffer[Index];
- break;
- }
-
- if (FvHandleBuffer != NULL) {
- FreePool (FvHandleBuffer);
- }
- }
-
- if (FindFvFile) {
- //
- // Build the shell device path
- //
- NewDevicePath = DevicePathFromHandle (FoundFvHandle);
- EfiInitializeFwVolDevicepathNode (&FvFileNode, FileGuid);
- NewDevicePath = AppendDevicePathNode (NewDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &FvFileNode);
- *DevicePath = NewDevicePath;
- return EFI_SUCCESS;
- }
- return EFI_NOT_FOUND;
-}
diff --git a/MdeModulePkg/Library/GenericBdsLib/BdsConnect.c b/MdeModulePkg/Library/GenericBdsLib/BdsConnect.c
deleted file mode 100644
index edbc368840..0000000000
--- a/MdeModulePkg/Library/GenericBdsLib/BdsConnect.c
+++ /dev/null
@@ -1,410 +0,0 @@
-/** @file
- BDS Lib functions which relate with connect the device
-
-Copyright (c) 2004 - 2008, Intel Corporation. <BR>
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#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 success, then still give one chance to do the dispatch,
- which load the missing drivers if possible.
-
- @param DevicePathToConnect The device path which will be connected, it can be
- a multi-instance device path
-
- @retval EFI_SUCCESS All handles associate with every device path 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 device 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;
-
- if (DevicePathToConnect == NULL) {
- return EFI_SUCCESS;
- }
-
- DevicePath = DuplicateDevicePath (DevicePathToConnect);
- CopyOfDevicePath = DevicePath;
- if (DevicePath == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- 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 = GetNextDevicePathInstance (&DevicePath, &Size);
- Next = Instance;
- while (!IsDevicePathEndType (Next)) {
- Next = NextDevicePathNode (Next);
- }
-
- SetDevicePathEndNode (Next);
-
- //
- // Start the real work of connect with RemainingDevicePath
- //
- PreviousHandle = 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 = Instance;
- Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &Handle);
-
- if (!EFI_ERROR (Status)) {
- if (Handle == 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 == EFI_SUCCESS means a driver was dispatched
- // Status == EFI_NOT_FOUND means no new drivers were dispatched
- //
- Status = gDS->Dispatch ();
- }
-
- if (!EFI_ERROR (Status)) {
- PreviousHandle = Handle;
- //
- // Connect all drivers that apply to Handle and RemainingDevicePath,
- // the Recursive flag is FALSE so only one level will be expanded.
- //
- // Do not check the connect status here, if the connect controller 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 not
- // 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 continue 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 != NULL);
-
- if (CopyOfDevicePath != NULL) {
- FreePool (CopyOfDevicePath);
- }
- //
- // All handle with DevicePath exists in the handle database
- //
- return Status;
-}
-
-
-/**
- This function will connect all current system handles recursively. The
- connection will finish until every handle's child handle created if it have.
-
- @retval EFI_SUCCESS All handles and it's child handle have been
- connected
- @retval EFI_STATUS Return the status of gBS->LocateHandleBuffer().
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibConnectAllEfi (
- VOID
- )
-{
- EFI_STATUS Status;
- UINTN HandleCount;
- EFI_HANDLE *HandleBuffer;
- UINTN Index;
-
- Status = gBS->LocateHandleBuffer (
- AllHandles,
- NULL,
- NULL,
- &HandleCount,
- &HandleBuffer
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- for (Index = 0; Index < HandleCount; Index++) {
- Status = gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
- }
-
- if (HandleBuffer != NULL) {
- FreePool (HandleBuffer);
- }
-
- return EFI_SUCCESS;
-}
-
-
-/**
- This function will disconnect all current system handles. The disconnection
- will finish until every handle have been disconnected.
-
- @retval EFI_SUCCESS All handles have been disconnected
- @retval EFI_STATUS Return the status of gBS->LocateHandleBuffer().
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibDisconnectAllEfi (
- VOID
- )
-{
- EFI_STATUS Status;
- UINTN HandleCount;
- EFI_HANDLE *HandleBuffer;
- UINTN Index;
-
- //
- // Disconnect all
- //
- Status = gBS->LocateHandleBuffer (
- AllHandles,
- NULL,
- NULL,
- &HandleCount,
- &HandleBuffer
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- for (Index = 0; Index < HandleCount; Index++) {
- Status = gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
- }
-
- if (HandleBuffer != 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 == EFI_SUCCESS and we will try
- // the connect again.
- //
- Status = 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 and ehci
- (0xFF)
- @param RemainingDevicePath a short-form device path that starts with the first
- element being a USB WWID or a USB Class device
- path
-
- @return EFI_INVALID_PARAMETER RemainingDevicePath is NULL pointer.
- RemainingDevicePath is not a USB device path.
- 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 == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- if ((DevicePathType (RemainingDevicePath) != MESSAGING_DEVICE_PATH) ||
- ((DevicePathSubType (RemainingDevicePath) != MSG_USB_CLASS_DP)
- && (DevicePathSubType (RemainingDevicePath) != MSG_USB_WWID_DP)
- )) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (HostControllerPI != 0xFF &&
- HostControllerPI != 0x00 &&
- HostControllerPI != 0x20) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Find the usb host controller firstly, then connect with the remaining device path
- //
- AtLeastOneConnected = FALSE;
- Status = gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiPciIoProtocolGuid,
- NULL,
- &HandleArrayCount,
- &HandleArray
- );
- if (!EFI_ERROR (Status)) {
- for (Index = 0; Index < HandleArrayCount; Index++) {
- Status = gBS->HandleProtocol (
- HandleArray[Index],
- &gEfiPciIoProtocolGuid,
- (VOID **)&PciIo
- );
- if (!EFI_ERROR (Status)) {
- //
- // Check whether the Pci device is the wanted usb host controller
- //
- Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class);
- if (!EFI_ERROR (Status)) {
- if ((PCI_CLASS_SERIAL == Class[2]) &&
- (PCI_CLASS_SERIAL_USB == Class[1])) {
- if (HostControllerPI == Class[0] || HostControllerPI == 0xFF) {
- Status = gBS->ConnectController (
- HandleArray[Index],
- NULL,
- RemainingDevicePath,
- FALSE
- );
- if (!EFI_ERROR(Status)) {
- AtLeastOneConnected = TRUE;
- }
- }
- }
- }
- }
- }
-
- if (AtLeastOneConnected) {
- return EFI_SUCCESS;
- }
- }
-
- return EFI_NOT_FOUND;
-}
diff --git a/MdeModulePkg/Library/GenericBdsLib/BdsConsole.c b/MdeModulePkg/Library/GenericBdsLib/BdsConsole.c
deleted file mode 100644
index 47de467509..0000000000
--- a/MdeModulePkg/Library/GenericBdsLib/BdsConsole.c
+++ /dev/null
@@ -1,896 +0,0 @@
-/** @file
- BDS Lib functions which contain all the code to connect console device
-
-Copyright (c) 2004 - 2008, Intel Corporation. <BR>
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "InternalBdsLib.h"
-
-/**
- Check if we need to save the EFI variable with "ConVarName" as name
- as NV type
-
- @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;
-
- Ptr = ConVarName;
-
- //
- // If the variable includes "Dev" at last, we consider
- // it does not support NV attribute.
- //
- while (*Ptr != L'\0') {
- Ptr++;
- }
-
- if ((*(Ptr - 3) == 'D') && (*(Ptr - 2) == 'e') && (*(Ptr - 1) == 'v')) {
- return FALSE;
- } else {
- return TRUE;
- }
-}
-
-/**
- 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, ConOut,
- ErrOut.
- @param CustomizedConDevicePath The console device path which will be added to
- the console variable ConVarName, this parameter
- can not be multi-instance.
- @param ExclusiveDevicePath The console device path which will be removed
- from the console variable ConVarName, this
- parameter can not be multi-instance.
-
- @retval EFI_UNSUPPORTED The added device path is same to the removed one.
- @retval EFI_SUCCESS Success add or remove the device path from the
- console variable.
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibUpdateConsoleVariable (
- IN CHAR16 *ConVarName,
- IN EFI_DEVICE_PATH_PROTOCOL *CustomizedConDevicePath,
- IN EFI_DEVICE_PATH_PROTOCOL *ExclusiveDevicePath
- )
-{
- EFI_DEVICE_PATH_PROTOCOL *VarConsole;
- UINTN DevicePathSize;
- EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
- EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;
- UINT32 Attributes;
-
- VarConsole = NULL;
- DevicePathSize = 0;
-
- //
- // Notes: check the device path point, here should check
- // with compare memory
- //
- if (CustomizedConDevicePath == ExclusiveDevicePath) {
- return EFI_UNSUPPORTED;
- }
- //
- // Delete the ExclusiveDevicePath from current default console
- //
- VarConsole = BdsLibGetVariableAndSize (
- ConVarName,
- &gEfiGlobalVariableGuid,
- &DevicePathSize
- );
-
- //
- // Initialize NewDevicePath
- //
- NewDevicePath = 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 != NULL && VarConsole != NULL) {
- NewDevicePath = BdsLibDelPartMatchInstance (VarConsole, ExclusiveDevicePath);
- }
- //
- // Try to append customized device path to NewDevicePath.
- //
- if (CustomizedConDevicePath != NULL) {
- if (!BdsLibMatchDevicePaths (NewDevicePath, CustomizedConDevicePath)) {
- //
- // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it.
- //
- NewDevicePath = BdsLibDelPartMatchInstance (NewDevicePath, CustomizedConDevicePath);
- //
- // In the first check, the default console variable will be _ModuleEntryPoint,
- // just append current customized device path
- //
- TempNewDevicePath = NewDevicePath;
- NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath);
- if (TempNewDevicePath != NULL) {
- FreePool(TempNewDevicePath);
- }
- }
- }
-
- //
- // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV.
- //
- if (IsNvNeed(ConVarName)) {
- //
- // ConVarName has NV attribute.
- //
- Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE;
- } else {
- //
- // ConVarName does not have NV attribute.
- //
- Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
- }
-
- //
- // Finally, Update the variable of the default console by NewDevicePath
- //
- gRT->SetVariable (
- ConVarName,
- &gEfiGlobalVariableGuid,
- Attributes,
- GetDevicePathSize (NewDevicePath),
- NewDevicePath
- );
-
- if (VarConsole == NewDevicePath) {
- if (VarConsole != NULL) {
- FreePool(VarConsole);
- }
- } else {
- if (VarConsole != NULL) {
- FreePool(VarConsole);
- }
- if (NewDevicePath != NULL) {
- FreePool(NewDevicePath);
- }
- }
-
- return EFI_SUCCESS;
-
-}
-
-
-/**
- Connect the console device base on the variable ConVarName, if
- device path of the ConVarName is multi-instance device path, if
- anyone of the instances is connected success, then this function
- will return success.
-
- @param ConVarName Console related variable name, ConIn, ConOut,
- ErrOut.
-
- @retval EFI_NOT_FOUND There is not any console devices connected
- success
- @retval EFI_SUCCESS Success connect any one instance of the console
- device path base on the variable ConVarName.
-
-**/
-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 = EFI_SUCCESS;
- DeviceExist = FALSE;
-
- //
- // Check if the console variable exist
- //
- StartDevicePath = BdsLibGetVariableAndSize (
- ConVarName,
- &gEfiGlobalVariableGuid,
- &VariableSize
- );
- if (StartDevicePath == NULL) {
- return EFI_UNSUPPORTED;
- }
-
- CopyOfDevicePath = StartDevicePath;
- do {
- //
- // Check every instance of the console variable
- //
- Instance = GetNextDevicePathInstance (&CopyOfDevicePath, &Size);
- Next = Instance;
- while (!IsDevicePathEndType (Next)) {
- Next = NextDevicePathNode (Next);
- }
-
- SetDevicePathEndNode (Next);
- //
- // Check USB1.1 console
- //
- if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) &&
- ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP)
- || (DevicePathSubType (Instance) == MSG_USB_WWID_DP)
- )) {
- //
- // Check the Usb console in Usb2.0 bus firstly, then Usb1.1 bus
- //
- Status = BdsLibConnectUsbDevByShortFormDP (PCI_CLASSC_PI_EHCI, Instance);
- if (!EFI_ERROR (Status)) {
- DeviceExist = TRUE;
- }
-
- Status = BdsLibConnectUsbDevByShortFormDP (PCI_CLASSC_PI_UHCI, Instance);
- if (!EFI_ERROR (Status)) {
- DeviceExist = TRUE;
- }
- } else {
- //
- // Connect the instance device path
- //
- Status = BdsLibConnectDevicePath (Instance);
- if (EFI_ERROR (Status)) {
- //
- // Delete the instance from the console varialbe
- //
- BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance);
- } else {
- DeviceExist = TRUE;
- }
- }
- FreePool(Instance);
- } while (CopyOfDevicePath != 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 = 0;
- HandleCount = 0;
- HandleBuffer = NULL;
- ConDevicePath = NULL;
-
- //
- // Update all the console variables
- //
- gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiSimpleTextInProtocolGuid,
- NULL,
- &HandleCount,
- &HandleBuffer
- );
-
- for (Index = 0; Index < HandleCount; Index++) {
- gBS->HandleProtocol (
- HandleBuffer[Index],
- &gEfiDevicePathProtocolGuid,
- (VOID **) &ConDevicePath
- );
- BdsLibUpdateConsoleVariable (L"ConIn", ConDevicePath, NULL);
- }
-
- if (HandleBuffer != NULL) {
- FreePool(HandleBuffer);
- HandleBuffer = NULL;
- }
-
- gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiSimpleTextOutProtocolGuid,
- NULL,
- &HandleCount,
- &HandleBuffer
- );
- for (Index = 0; Index < HandleCount; Index++) {
- gBS->HandleProtocol (
- HandleBuffer[Index],
- &gEfiDevicePathProtocolGuid,
- (VOID **) &ConDevicePath
- );
- BdsLibUpdateConsoleVariable (L"ConOut", ConDevicePath, NULL);
- BdsLibUpdateConsoleVariable (L"ErrOut", ConDevicePath, NULL);
- }
-
- if (HandleBuffer != 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 device have
- been connected success.
- @retval EFI_STATUS Return the status of BdsLibConnectConsoleVariable ().
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibConnectAllDefaultConsoles (
- VOID
- )
-{
- EFI_STATUS Status;
-
- //
- // Connect all default console variables
- //
-
- //
- // It seems impossible not to have any ConOut device on platform,
- // so we check the status here.
- //
- Status = 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");
-
- return EFI_SUCCESS;
-
-}
-
-/**
- Convert a *.BMP graphics image to a GOP blt buffer. If a NULL Blt buffer
- is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt
- buffer is passed in it will be used if it is big enough.
-
- @param BmpImage Pointer to BMP file
- @param BmpImageSize Number of bytes in BmpImage
- @param GopBlt Buffer containing GOP version of BmpImage.
- @param GopBltSize Size of GopBlt in bytes.
- @param PixelHeight Height of GopBlt/BmpImage in pixels
- @param PixelWidth Width of GopBlt/BmpImage in pixels
-
- @retval EFI_SUCCESS GopBlt and GopBltSize are returned.
- @retval EFI_UNSUPPORTED BmpImage is not a valid *.BMP image
- @retval EFI_BUFFER_TOO_SMALL The passed in GopBlt buffer is not big enough.
- GopBltSize will contain the required size.
- @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate.
-
-**/
-EFI_STATUS
-ConvertBmpToGopBlt (
- IN VOID *BmpImage,
- IN UINTN BmpImageSize,
- IN OUT VOID **GopBlt,
- IN OUT UINTN *GopBltSize,
- OUT UINTN *PixelHeight,
- OUT UINTN *PixelWidth
- )
-{
- UINT8 *Image;
- UINT8 *ImageHeader;
- BMP_IMAGE_HEADER *BmpHeader;
- BMP_COLOR_MAP *BmpColorMap;
- EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;
- EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
- UINTN BltBufferSize;
- UINTN Index;
- UINTN Height;
- UINTN Width;
- UINTN ImageIndex;
- BOOLEAN IsAllocated;
-
- BmpHeader = (BMP_IMAGE_HEADER *) BmpImage;
-
- if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') {
- return EFI_UNSUPPORTED;
- }
-
- //
- // Doesn't support compress.
- //
- if (BmpHeader->CompressionType != 0) {
- return EFI_UNSUPPORTED;
- }
-
- //
- // Calculate Color Map offset in the image.
- //
- Image = BmpImage;
- BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER));
-
- //
- // Calculate graphics image data address in the image
- //
- Image = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset;
- ImageHeader = Image;
-
- //
- // Calculate the BltBuffer needed size.
- //
- BltBufferSize = BmpHeader->PixelWidth * BmpHeader->PixelHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
- IsAllocated = FALSE;
- if (*GopBlt == NULL) {
- //
- // GopBlt is not allocated by caller.
- //
- *GopBltSize = BltBufferSize;
- *GopBlt = AllocatePool (*GopBltSize);
- IsAllocated = TRUE;
- if (*GopBlt == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
- } else {
- //
- // GopBlt has been allocated by caller.
- //
- if (*GopBltSize < BltBufferSize) {
- *GopBltSize = BltBufferSize;
- return EFI_BUFFER_TOO_SMALL;
- }
- }
-
- *PixelWidth = BmpHeader->PixelWidth;
- *PixelHeight = BmpHeader->PixelHeight;
-
- //
- // Convert image from BMP to Blt buffer format
- //
- BltBuffer = *GopBlt;
- for (Height = 0; Height < BmpHeader->PixelHeight; Height++) {
- Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth];
- for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) {
- switch (BmpHeader->BitPerPixel) {
- case 1:
- //
- // Convert 1-bit (2 colors) BMP to 24-bit color
- //
- for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) {
- Blt->Red = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red;
- Blt->Green = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green;
- Blt->Blue = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue;
- Blt++;
- Width++;
- }
-
- Blt--;
- Width--;
- break;
-
- case 4:
- //
- // Convert 4-bit (16 colors) BMP Palette to 24-bit color
- //
- Index = (*Image) >> 4;
- Blt->Red = BmpColorMap[Index].Red;
- Blt->Green = BmpColorMap[Index].Green;
- Blt->Blue = BmpColorMap[Index].Blue;
- if (Width < (BmpHeader->PixelWidth - 1)) {
- Blt++;
- Width++;
- Index = (*Image) & 0x0f;
- Blt->Red = BmpColorMap[Index].Red;
- Blt->Green = BmpColorMap[Index].Green;
- Blt->Blue = BmpColorMap[Index].Blue;
- }
- break;
-
- case 8:
- //
- // Convert 8-bit (256 colors) BMP Palette to 24-bit color
- //
- Blt->Red = BmpColorMap[*Image].Red;
- Blt->Green = BmpColorMap[*Image].Green;
- Blt->Blue = BmpColorMap[*Image].Blue;
- break;
-
- case 24:
- //
- // It is 24-bit BMP.
- //
- Blt->Blue = *Image++;
- Blt->Green = *Image++;
- Blt->Red = *Image;
- break;
-
- default:
- //
- // Other bit format BMP is not supported.
- //
- if (IsAllocated) {
- FreePool (*GopBlt);
- *GopBlt = NULL;
- }
- return EFI_UNSUPPORTED;
- break;
- };
-
- }
-
- ImageIndex = (UINTN) (Image - ImageHeader);
- if ((ImageIndex % 4) != 0) {
- //
- // Bmp Image starts each row on a 32-bit boundary!
- //
- Image = Image + (4 - (ImageIndex % 4));
- }
- }
-
- return EFI_SUCCESS;
-}
-
-
-/**
- Use Console Control Protocol to lock the Console In Spliter virtual handle.
- This is the ConInHandle and ConIn handle in the EFI 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 successfully.
- @retval EFI_UNSUPPORTED Password not found
-
-**/
-EFI_STATUS
-EFIAPI
-LockKeyboards (
- IN CHAR16 *Password
- )
-{
- EFI_STATUS Status;
- EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
-
- Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);
- if (EFI_ERROR (Status)) {
- return EFI_UNSUPPORTED;
- }
-
- Status = ConsoleControl->LockStdIn (ConsoleControl, Password);
- return Status;
-}
-
-
-/**
- Use Console Control to turn off UGA based Simple Text Out consoles from going
- to the UGA device. Put up LogoFile on every UGA device that is a console
-
- @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_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
- 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;
-
- Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);
- if (EFI_ERROR (Status)) {
- return EFI_UNSUPPORTED;
- }
-
- UgaDraw = NULL;
- //
- // Try to open GOP first
- //
- Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput);
- if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
- GraphicsOutput = NULL;
- //
- // Open GOP failed, try to open UGA
- //
- Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw);
- }
- if (EFI_ERROR (Status)) {
- return EFI_UNSUPPORTED;
- }
-
- Badging = NULL;
- Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging);
-
- //
- // Set console control to graphics mode.
- //
- Status = ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics);
- if (EFI_ERROR (Status)) {
- return EFI_UNSUPPORTED;
- }
-
- if (GraphicsOutput != NULL) {
- SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
- SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
-
- } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
- Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);
- if (EFI_ERROR (Status)) {
- return EFI_UNSUPPORTED;
- }
- } else {
- return EFI_UNSUPPORTED;
- }
-
- Instance = 0;
- while (1) {
- ImageData = NULL;
- ImageSize = 0;
-
- if (Badging != NULL) {
- //
- // Get image from OEMBadging protocol.
- //
- Status = Badging->GetImage (
- Badging,
- &Instance,
- &Format,
- &ImageData,
- &ImageSize,
- &Attribute,
- &CoordinateX,
- &CoordinateY
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // Currently only support BMP format.
- //
- if (Format != EfiBadgingFormatBMP) {
- if (ImageData != NULL) {
- FreePool (ImageData);
- }
- continue;
- }
- } else {
- //
- // Get the specified image from FV.
- //
- Status = GetSectionFromAnyFv (LogoFile, EFI_SECTION_RAW, 0, (VOID **) &ImageData, &ImageSize);
- if (EFI_ERROR (Status)) {
- return EFI_UNSUPPORTED;
- }
-
- CoordinateX = 0;
- CoordinateY = 0;
- Attribute = EfiBadgingDisplayAttributeCenter;
- }
-
- Blt = NULL;
- Status = ConvertBmpToGopBlt (
- ImageData,
- ImageSize,
- (VOID **) &Blt,
- &BltSize,
- &Height,
- &Width
- );
- if (EFI_ERROR (Status)) {
- FreePool (ImageData);
-
- if (Badging == NULL) {
- return Status;
- } else {
- continue;
- }
- }
-
- //
- // Calculate the display position according to Attribute.
- //
- switch (Attribute) {
- case EfiBadgingDisplayAttributeLeftTop:
- DestX = CoordinateX;
- DestY = CoordinateY;
- break;
-
- case EfiBadgingDisplayAttributeCenterTop:
- DestX = (SizeOfX - Width) / 2;
- DestY = CoordinateY;
- break;
-
- case EfiBadgingDisplayAttributeRightTop:
- DestX = (SizeOfX - Width - CoordinateX);
- DestY = CoordinateY;;
- break;
-
- case EfiBadgingDisplayAttributeCenterRight:
- DestX = (SizeOfX - Width - CoordinateX);
- DestY = (SizeOfY - Height) / 2;
- break;
-
- case EfiBadgingDisplayAttributeRightBottom:
- DestX = (SizeOfX - Width - CoordinateX);
- DestY = (SizeOfY - Height - CoordinateY);
- break;
-
- case EfiBadgingDisplayAttributeCenterBottom:
- DestX = (SizeOfX - Width) / 2;
- DestY = (SizeOfY - Height - CoordinateY);
- break;
-
- case EfiBadgingDisplayAttributeLeftBottom:
- DestX = CoordinateX;
- DestY = (SizeOfY - Height - CoordinateY);
- break;
-
- case EfiBadgingDisplayAttributeCenterLeft:
- DestX = CoordinateX;
- DestY = (SizeOfY - Height) / 2;
- break;
-
- case EfiBadgingDisplayAttributeCenter:
- DestX = (SizeOfX - Width) / 2;
- DestY = (SizeOfY - Height) / 2;
- break;
-
- default:
- DestX = CoordinateX;
- DestY = CoordinateY;
- break;
- }
-
- if ((DestX >= 0) && (DestY >= 0)) {
- if (GraphicsOutput != NULL) {
- Status = GraphicsOutput->Blt (
- GraphicsOutput,
- Blt,
- EfiBltBufferToVideo,
- 0,
- 0,
- (UINTN) DestX,
- (UINTN) DestY,
- Width,
- Height,
- Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
- );
- } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
- Status = UgaDraw->Blt (
- UgaDraw,
- (EFI_UGA_PIXEL *) Blt,
- EfiUgaBltBufferToVideo,
- 0,
- 0,
- (UINTN) DestX,
- (UINTN) DestY,
- Width,
- Height,
- Width * sizeof (EFI_UGA_PIXEL)
- );
- } else {
- Status = EFI_UNSUPPORTED;
- }
- }
-
- FreePool (ImageData);
-
- if (Blt != NULL) {
- FreePool (Blt);
- }
-
- if (Badging == NULL) {
- break;
- }
- }
-
- return Status;
-}
-
-/**
- Use Console Control to turn on UGA based Simple Text Out consoles. The UGA
- Simple Text Out screens will now be synced up with all non UGA output devices
-
- @retval EFI_SUCCESS UGA devices are back in text mode and synced up.
-
-**/
-EFI_STATUS
-EFIAPI
-DisableQuietBoot (
- VOID
- )
-{
- EFI_STATUS Status;
- EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
-
- Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);
- if (EFI_ERROR (Status)) {
- return EFI_UNSUPPORTED;
- }
-
- //
- // Set console control to text mode.
- //
- return ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenText);
-}
-
diff --git a/MdeModulePkg/Library/GenericBdsLib/BdsMisc.c b/MdeModulePkg/Library/GenericBdsLib/BdsMisc.c
deleted file mode 100644
index acf61ebcb6..0000000000
--- a/MdeModulePkg/Library/GenericBdsLib/BdsMisc.c
+++ /dev/null
@@ -1,1272 +0,0 @@
-/** @file
- Misc BDS library function
-
-Copyright (c) 2004 - 2008, Intel Corporation. <BR>
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "InternalBdsLib.h"
-
-
-#define MAX_STRING_LEN 200
-
-BOOLEAN mFeaturerSwitch = TRUE;
-BOOLEAN mResetRequired = FALSE;
-
-extern UINT16 gPlatformBootTimeOutDefault;
-
-
-/**
- Return the default value for system Timeout variable.
-
- @return Timeout value.
-
-**/
-UINT16
-EFIAPI
-BdsLibGetTimeout (
- VOID
- )
-{
- UINT16 Timeout;
- UINTN Size;
- EFI_STATUS Status;
-
- //
- // Return Timeout variable or 0xffff if no valid
- // Timeout variable exists.
- //
- Size = sizeof (UINT16);
- Status = gRT->GetVariable (L"Timeout", &gEfiGlobalVariableGuid, NULL, &Size, &Timeout);
- if (EFI_ERROR (Status)) {
- //
- // According to UEFI 2.0 spec, it should treat the Timeout value as 0xffff
- // (default value PcdPlatformBootTimeOutDefault) when L"Timeout" variable is not present.
- // To make the current EFI Automatic-Test activity possible, platform can choose other value
- // for automatic boot when the variable is not present.
- //
- Timeout = PcdGet16 (PcdPlatformBootTimeOutDefault);
- }
-
- return Timeout;
-}
-
-/**
- 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 link 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 = FALSE;
-
- //
- // Process the driver option
- //
- for (Link = BdsDriverLists->ForwardLink; Link != BdsDriverLists; Link = Link->ForwardLink) {
- Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);
-
- //
- // 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;
- }
-
- //
- // 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_RECONNECT)) {
- ReconnectAll = TRUE;
- }
-
- //
- // Make sure the driver path is connected.
- //
- BdsLibConnectDevicePath (Option->DevicePath);
-
- //
- // Load and start the image that Driver#### describes
- //
- Status = gBS->LoadImage (
- FALSE,
- mBdsImageHandle,
- Option->DevicePath,
- NULL,
- 0,
- &ImageHandle
- );
-
- if (!EFI_ERROR (Status)) {
- gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &ImageInfo);
-
- //
- // Verify whether this image is a driver, if not,
- // exit it and continue to parse next load option
- //
- if (ImageInfo->ImageCodeType != EfiBootServicesCode && ImageInfo->ImageCodeType != EfiRuntimeServicesCode) {
- gBS->Exit (ImageHandle, EFI_INVALID_PARAMETER, 0, NULL);
- continue;
- }
-
- if (Option->LoadOptionsSize != 0) {
- ImageInfo->LoadOptionsSize = Option->LoadOptionsSize;
- ImageInfo->LoadOptions = Option->LoadOptions;
- }
- //
- // Before calling the image, enable the Watchdog Timer for
- // the 5 Minute period
- //
- gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);
-
- Status = gBS->StartImage (ImageHandle, &ExitDataSize, &ExitData);
- DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Driver Return Status = %r\n", Status));
-
- //
- // Clear the Watchdog Timer after the image returns
- //
- gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
- }
- }
-
- //
- // 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#### option
-
- @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 = 0;
- do {
- if (*VariableName == '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 = BdsLibGetVariableAndSize (
- StrTemp,
- &gEfiGlobalVariableGuid,
- &OptionSize
- );
- if (OptionBuffer == NULL) {
- break;
- }
- 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 linked
- 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#### link list
- @param DevicePath The device path which the boot#### or driver####
- option present
- @param String The description of the boot#### or driver####
- @param VariableName Indicate if the boot#### or driver#### option
-
- @retval EFI_SUCCESS The boot#### or driver#### have been success
- 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;
-
-
- OptionPtr = NULL;
- OptionSize = 0;
- TempPtr = NULL;
- OptionDevicePath = NULL;
- Description = NULL;
- OptionOrderPtr = NULL;
- UpdateDescription = FALSE;
- Status = EFI_SUCCESS;
- ZeroMem (OptionName, sizeof (OptionName));
-
- TempOptionSize = 0;
- TempOptionPtr = BdsLibGetVariableAndSize (
- VariableName,
- &gEfiGlobalVariableGuid,
- &TempOptionSize
- );
- //
- // Compare with current option variable if the previous option is set in global variable.
- //
- for (Index = 0; Index < TempOptionSize / sizeof (UINT16); Index++) {
- //
- // TempOptionPtr must not be NULL if we have non-zero TempOptionSize.
- //
- ASSERT (TempOptionPtr != NULL);
-
- if (*VariableName == 'B') {
- UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", TempOptionPtr[Index]);
- } else {
- UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", TempOptionPtr[Index]);
- }
-
- OptionPtr = BdsLibGetVariableAndSize (
- OptionName,
- &gEfiGlobalVariableGuid,
- &OptionSize
- );
- if (OptionPtr == NULL) {
- continue;
- }
- TempPtr = OptionPtr;
- TempPtr += sizeof (UINT32) + sizeof (UINT16);
- Description = (CHAR16 *) TempPtr;
- TempPtr += StrSize ((CHAR16 *) TempPtr);
- OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
-
- //
- // Notes: the description may will change base on the GetStringToken
- //
- if (CompareMem (OptionDevicePath, DevicePath, GetDevicePathSize (OptionDevicePath)) == 0) {
- if (CompareMem (Description, String, StrSize (Description)) == 0) {
- //
- // Got the option, so just return
- //
- FreePool (OptionPtr);
- FreePool (TempOptionPtr);
- return EFI_SUCCESS;
- } else {
- //
- // Option description changed, need update.
- //
- UpdateDescription = TRUE;
- FreePool (OptionPtr);
- break;
- }
- }
-
- FreePool (OptionPtr);
- }
-
- OptionSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (String);
- OptionSize += GetDevicePathSize (DevicePath);
- OptionPtr = AllocateZeroPool (OptionSize);
- ASSERT (OptionPtr != NULL);
-
- TempPtr = OptionPtr;
- *(UINT32 *) TempPtr = LOAD_OPTION_ACTIVE;
- TempPtr += sizeof (UINT32);
- *(UINT16 *) TempPtr = (UINT16) GetDevicePathSize (DevicePath);
- TempPtr += sizeof (UINT16);
- CopyMem (TempPtr, String, StrSize (String));
- TempPtr += StrSize (String);
- CopyMem (TempPtr, DevicePath, GetDevicePathSize (DevicePath));
-
- if (UpdateDescription) {
- //
- // The number in option#### to be updated.
- // In this case, we must have non-NULL TempOptionPtr.
- //
- ASSERT (TempOptionPtr != NULL);
- RegisterOptionNumber = TempOptionPtr[Index];
- } else {
- //
- // The new option#### number
- //
- RegisterOptionNumber = BdsLibGetFreeOptionNumber(VariableName);
- }
-
- if (*VariableName == 'B') {
- UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", RegisterOptionNumber);
- } else {
- UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", RegisterOptionNumber);
- }
-
- Status = gRT->SetVariable (
- OptionName,
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- OptionSize,
- OptionPtr
- );
- //
- // Return if only need to update a changed description or fail to set option.
- //
- if (EFI_ERROR (Status) || UpdateDescription) {
- FreePool (OptionPtr);
- if (TempOptionPtr != NULL) {
- FreePool (TempOptionPtr);
- }
- return Status;
- }
-
- FreePool (OptionPtr);
-
- //
- // Update the option order variable
- //
-
- //
- // If no option order
- //
- if (TempOptionSize == 0) {
- BootOrderEntry = 0;
- Status = gRT->SetVariable (
- VariableName,
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- sizeof (UINT16),
- &BootOrderEntry
- );
- if (TempOptionPtr != NULL) {
- FreePool (TempOptionPtr);
- }
- return Status;
- }
-
- //
- // TempOptionPtr must not be NULL if TempOptionSize is not zero.
- //
- ASSERT (TempOptionPtr != NULL);
- //
- // Append the new option number to the original option order
- //
- OrderItemNum = (TempOptionSize / sizeof (UINT16)) + 1 ;
- OptionOrderPtr = AllocateZeroPool ( OrderItemNum * sizeof (UINT16));
- ASSERT (OptionOrderPtr!= NULL);
- CopyMem (OptionOrderPtr, TempOptionPtr, (OrderItemNum - 1) * sizeof (UINT16));
-
- OptionOrderPtr[Index] = RegisterOptionNumber;
-
- Status = gRT->SetVariable (
- VariableName,
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- OrderItemNum * sizeof (UINT16),
- OptionOrderPtr
- );
- FreePool (TempOptionPtr);
- FreePool (OptionOrderPtr);
-
- return Status;
-}
-
-
-/**
- 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#### option
- 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 = BdsLibGetVariableAndSize (
- VariableName,
- &gEfiGlobalVariableGuid,
- &VariableSize
- );
- if (Variable == NULL) {
- return NULL;
- }
- //
- // Notes: careful defined the variable of Boot#### or
- // Driver####, consider use some macro to abstract the code
- //
- //
- // Get the option attribute
- //
- TempPtr = Variable;
- Attribute = *(UINT32 *) Variable;
- TempPtr += sizeof (UINT32);
-
- //
- // Get the option's device path size
- //
- FilePathSize = *(UINT16 *) TempPtr;
- TempPtr += sizeof (UINT16);
-
- //
- // Get the option's description string
- //
- Description = (CHAR16 *) TempPtr;
-
- //
- // Get the option's description string size
- //
- TempPtr += StrSize ((CHAR16 *) TempPtr);
-
- //
- // Get the option's device path
- //
- DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
- TempPtr += FilePathSize;
-
- LoadOptions = TempPtr;
- LoadOptionsSize = (UINT32) (VariableSize - (UINTN) (TempPtr - Variable));
-
- //
- // The Console variables may have multiple device paths, so make
- // an Entry for each one.
- //
- Option = AllocateZeroPool (sizeof (BDS_COMMON_OPTION));
- if (Option == NULL) {
- return NULL;
- }
-
- Option->Signature = BDS_LOAD_OPTION_SIGNATURE;
- Option->DevicePath = AllocateZeroPool (GetDevicePathSize (DevicePath));
- ASSERT(Option->DevicePath != NULL);
- CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));
-
- Option->Attribute = Attribute;
- Option->Description = AllocateZeroPool (StrSize (Description));
- ASSERT(Option->Description != NULL);
- CopyMem (Option->Description, Description, StrSize (Description));
-
- Option->LoadOptions = AllocateZeroPool (LoadOptionsSize);
- ASSERT(Option->LoadOptions != NULL);
- CopyMem (Option->LoadOptions, LoadOptions, LoadOptionsSize);
- Option->LoadOptionsSize = 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 == 'B') {
- NumOff = sizeof (L"Boot")/sizeof(CHAR16) -1 ;
- Option->BootCurrent = (UINT16) ((VariableName[NumOff] -'0') * 0x1000);
- Option->BootCurrent = (UINT16) (Option->BootCurrent + ((VariableName[NumOff+1]-'0') * 0x100));
- Option->BootCurrent = (UINT16) (Option->BootCurrent + ((VariableName[NumOff+2]-'0') * 0x10));
- Option->BootCurrent = (UINT16) (Option->BootCurrent + ((VariableName[NumOff+3]-'0')));
- }
- //
- // Insert active entry to BdsDeviceList
- //
- if ((Option->Attribute & LOAD_OPTION_ACTIVE) == LOAD_OPTION_ACTIVE) {
- InsertTailList (BdsCommonOptionList, &Option->Link);
- FreePool (Variable);
- return Option;
- }
-
- FreePool (Variable);
- FreePool (Option);
- return NULL;
-
-}
-
-/**
- Process BootOrder, or DriverOrder variables, by calling
- BdsLibVariableToOption () for each UINT16 in the variables.
-
- @param BdsCommonOptionList The header of the option list base on variable
- VariableName
- @param VariableName EFI Variable name indicate the BootOrder or
- DriverOrder
-
- @retval EFI_SUCCESS Success create the boot option or driver option
- list
- @retval EFI_OUT_OF_RESOURCES Failed to get the boot option or driver option 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 = BdsLibGetVariableAndSize (
- VariableName,
- &gEfiGlobalVariableGuid,
- &OptionOrderSize
- );
- if (OptionOrder == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) {
- if (*VariableName == 'B') {
- UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", OptionOrder[Index]);
- } else {
- UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", OptionOrder[Index]);
- }
-
- Option = BdsLibVariableToOption (BdsCommonOptionList, OptionName);
- ASSERT (Option != NULL);
- Option->BootCurrent = 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 = GetBootModeHob ();
-
- return EFI_SUCCESS;
-}
-
-/**
- Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
- 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 = NULL;
-
- //
- // Pass in a zero size buffer to find the required buffer size.
- //
- BufferSize = 0;
- Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);
- if (Status == EFI_BUFFER_TOO_SMALL) {
- //
- // Allocate the buffer to return
- //
- Buffer = AllocateZeroPool (BufferSize);
- if (Buffer == NULL) {
- return NULL;
- }
- //
- // Read variable into the allocated buffer.
- //
- Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);
- if (EFI_ERROR (Status)) {
- BufferSize = 0;
- }
- }
-
- *VariableSize = 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 which partly
- match with the Single, and return the result device path. If there is no
- remaining device path as a result, this function will return NULL.
-
-**/
-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 = NULL;
- TempNewDevicePath = NULL;
-
- if (Multi == NULL || Single == NULL) {
- return Multi;
- }
-
- Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);
- SingleDpSize = GetDevicePathSize (Single) - END_DEVICE_PATH_LENGTH;
- InstanceSize -= END_DEVICE_PATH_LENGTH;
-
- while (Instance != NULL) {
-
- Size = (SingleDpSize < InstanceSize) ? SingleDpSize : InstanceSize;
-
- if ((CompareMem (Instance, Single, Size) != 0)) {
- //
- // Append the device path instance which does not match with Single
- //
- TempNewDevicePath = NewDevicePath;
- NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance);
- if (TempNewDevicePath != NULL) {
- FreePool(TempNewDevicePath);
- }
- }
- FreePool(Instance);
- Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);
- InstanceSize -= 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 within 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 == NULL || Single == NULL) {
- return FALSE;
- }
-
- DevicePath = Multi;
- DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);
-
- //
- // Search for the match of 'Single' in 'Multi'
- //
- while (DevicePathInst != NULL) {
- //
- // If the single device path is found in multiple device paths,
- // return success
- //
- if (CompareMem (Single, DevicePathInst, Size) == 0) {
- FreePool (DevicePathInst);
- return TRUE;
- }
-
- FreePool (DevicePathInst);
- DevicePathInst = 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->OutputString ().
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibOutputStrings (
- IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut,
- ...
- )
-{
- VA_LIST Args;
- EFI_STATUS Status;
- CHAR16 *String;
-
- Status = EFI_SUCCESS;
- VA_START (Args, ConOut);
-
- while (!EFI_ERROR (Status)) {
- //
- // If String is NULL, then it's the end of the list
- //
- String = VA_ARG (Args, CHAR16 *);
- if (String != NULL) {
- break;
- }
-
- Status = ConOut->OutputString (ConOut, String);
-
- if (EFI_ERROR (Status)) {
- break;
- }
- }
-
- 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, and 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 feature, use the routine to enable it.
-
-**/
-VOID
-EFIAPI
-EnableResetReminderFeature (
- VOID
- )
-{
- mFeaturerSwitch = 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 = 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 = 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 = FALSE;
-}
-
-
-/**
- Check whether platform policy enable the reset reminder feature. The default 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 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
- ASSERT (StringBuffer1 != NULL);
- StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
- ASSERT (StringBuffer2 != NULL);
- StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now ? ");
- StrCpy (StringBuffer2, L"Enter (YES) / Esc (NO)");
- //
- // Popup a menu to notice user
- //
- do {
- IfrLibCreatePopUp (2, &Key, StringBuffer1, StringBuffer2);
- } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
-
- FreePool (StringBuffer1);
- FreePool (StringBuffer2);
- //
- // If the user hits the YES Response key, reset
- //
- if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN)) {
- gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
- }
- gST->ConOut->ClearScreen (gST->ConOut);
- }
- }
-}
-
-/**
- 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, PE32+, 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 = NULL;
- ThisFile = NULL;
- //
- // Handle the file system interface to the device
- //
- Status = gBS->HandleProtocol (
- Device,
- &gEfiSimpleFileSystemProtocolGuid,
- (VOID *) &Volume
- );
- if (EFI_ERROR (Status)) {
- goto Done;
- }
-
- Status = Volume->OpenVolume (
- Volume,
- &Root
- );
- if (EFI_ERROR (Status)) {
- Root = NULL;
- goto Done;
- }
-
- Status = Root->Open (Root, &ThisFile, FileName, EFI_FILE_MODE_READ, 0);
- if (EFI_ERROR (Status)) {
- goto Done;
- }
-
- //
- // Get file size
- //
- BufferSize = SIZE_OF_EFI_FILE_INFO + 200;
- do {
- Info = NULL;
- Status = gBS->AllocatePool (EfiBootServicesData, BufferSize, (VOID **) &Info);
- if (EFI_ERROR (Status)) {
- goto Done;
- }
- Status = ThisFile->GetInfo (
- ThisFile,
- &gEfiFileInfoGuid,
- &BufferSize,
- Info
- );
- if (!EFI_ERROR (Status)) {
- break;
- }
- if (Status != EFI_BUFFER_TOO_SMALL) {
- FreePool (Info);
- goto Done;
- }
- FreePool (Info);
- } while (TRUE);
-
- FileSize = Info->FileSize;
- FreePool (Info);
-
- //
- // Read dos header
- //
- BufferSize = sizeof (EFI_IMAGE_DOS_HEADER);
- Status = ThisFile->Read (ThisFile, &BufferSize, DosHeader);
- if (EFI_ERROR (Status) ||
- BufferSize < sizeof (EFI_IMAGE_DOS_HEADER) ||
- FileSize <= DosHeader->e_lfanew ||
- DosHeader->e_magic != EFI_IMAGE_DOS_SIGNATURE) {
- Status = EFI_LOAD_ERROR;
- goto Done;
- }
-
- //
- // Move to PE signature
- //
- Status = ThisFile->SetPosition (ThisFile, DosHeader->e_lfanew);
- if (EFI_ERROR (Status)) {
- Status = EFI_LOAD_ERROR;
- goto Done;
- }
-
- //
- // Read and check PE signature
- //
- BufferSize = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION);
- Status = ThisFile->Read (ThisFile, &BufferSize, Hdr.Pe32);
- if (EFI_ERROR (Status) ||
- BufferSize < sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION) ||
- Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {
- Status = EFI_LOAD_ERROR;
- goto Done;
- }
-
- //
- // Check PE32 or PE32+ magic
- //
- if (Hdr.Pe32->OptionalHeader.Magic != EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC &&
- Hdr.Pe32->OptionalHeader.Magic != EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
- Status = EFI_LOAD_ERROR;
- goto Done;
- }
-
- Done:
- if (ThisFile != NULL) {
- ThisFile->Close (ThisFile);
- }
- if (Root != NULL) {
- Root->Close (Root);
- }
- return Status;
-}
-
-/**
-
- This routine is a notification function for legayc boot or exit boot
- service event. It will adjust the memory information for different
- memory type and save them into the variables for next boot.
-
-
- @param Event The event that triggered this notification function.
- @param Context Pointer to the notification functions context.
-
-**/
-VOID
-EFIAPI
-BdsSetMemoryTypeInformationVariable (
- EFI_EVENT Event,
- VOID *Context
- )
-{
- EFI_STATUS Status;
- EFI_MEMORY_TYPE_INFORMATION *PreviousMemoryTypeInformation;
- EFI_MEMORY_TYPE_INFORMATION *CurrentMemoryTypeInformation;
- UINTN VariableSize;
- BOOLEAN UpdateRequired;
- UINTN Index;
- UINTN Index1;
- UINT32 Previous;
- UINT32 Current;
- UINT32 Next;
- EFI_HOB_GUID_TYPE *GuidHob;
-
- UpdateRequired = FALSE;
-
- //
- // Retrieve the current memory usage statistics. If they are not found, then
- // no adjustments can be made to the Memory Type Information variable.
- //
- Status = EfiGetSystemConfigurationTable (
- &gEfiMemoryTypeInformationGuid,
- (VOID **) &CurrentMemoryTypeInformation
- );
- if (EFI_ERROR (Status) || CurrentMemoryTypeInformation == 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 defaults
- //
- GuidHob = GetFirstGuidHob (&gEfiMemoryTypeInformationGuid);
- if (GuidHob == NULL) {
- //
- // If Platform has not built Memory Type Info into the Hob, just return.
- //
- return;
- }
- PreviousMemoryTypeInformation = GET_GUID_HOB_DATA (GuidHob);
- VariableSize = GET_GUID_HOB_DATA_SIZE (GuidHob);
-
- //
- // Use a heuristic to adjust the Memory Type Information for the next boot
- //
- for (Index = 0; PreviousMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) {
-
- Current = 0;
- for (Index1 = 0; CurrentMemoryTypeInformation[Index1].Type != EfiMaxMemoryType; Index1++) {
- if (PreviousMemoryTypeInformation[Index].Type == CurrentMemoryTypeInformation[Index1].Type) {
- Current = CurrentMemoryTypeInformation[Index1].NumberOfPages;
- break;
- }
- }
-
- if (CurrentMemoryTypeInformation[Index1].Type == EfiMaxMemoryType) {
- continue;
- }
-
- Previous = PreviousMemoryTypeInformation[Index].NumberOfPages;
-
- //
- // Write next varible to 125% * current and Inconsistent Memory Reserved across bootings may lead to S4 fail
- //
- if (Current > Previous) {
- Next = Current + (Current >> 2);
- } else {
- Next = Previous;
- }
- if (Next > 0 && Next < 4) {
- Next = 4;
- }
-
- if (Next != Previous) {
- PreviousMemoryTypeInformation[Index].NumberOfPages = Next;
- UpdateRequired = TRUE;
- }
-
- }
-
- //
- // If any changes were made to the Memory Type Information settings, then set the new variable value
- //
- if (UpdateRequired) {
- Status = gRT->SetVariable (
- EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
- &gEfiMemoryTypeInformationGuid,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- VariableSize,
- PreviousMemoryTypeInformation
- );
- }
-
- return;
-}
-
-/**
- This routine register a function to adjust the different type memory page number
- just before booting and save the updated info into the variable for next boot to use.
-
-**/
-VOID
-EFIAPI
-BdsLibSaveMemoryTypeInformation (
- VOID
- )
-{
- EFI_STATUS Status;
- EFI_EVENT ReadyToBootEvent;
-
- Status = EfiCreateEventReadyToBootEx (
- TPL_CALLBACK,
- BdsSetMemoryTypeInformationVariable,
- NULL,
- &ReadyToBootEvent
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR,"Bds Set Memory Type Informationa Variable Fails\n"));
- }
-
-}
-
-
diff --git a/MdeModulePkg/Library/GenericBdsLib/DevicePath.c b/MdeModulePkg/Library/GenericBdsLib/DevicePath.c
deleted file mode 100644
index 135fa63d1a..0000000000
--- a/MdeModulePkg/Library/GenericBdsLib/DevicePath.c
+++ /dev/null
@@ -1,1485 +0,0 @@
-/** @file
- BDS internal function define the default device path string, it can be
- replaced by platform device path.
-
-Copyright (c) 2004 - 2008, Intel Corporation. <BR>
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "InternalBdsLib.h"
-
-/**
- Concatenates a formatted unicode string to allocated pool.
- The caller must free the resulting buffer.
-
- @param Str Tracks the allocated pool, size in use, and amount of pool allocated.
- @param fmt The format string
- @param ... The data will be printed.
-
- @return Allocated buffer with the formatted string printed in it.
- The caller must free the allocated buffer.
- The buffer allocation is not packed.
-
-**/
-CHAR16 *
-EFIAPI
-CatPrint (
- IN OUT POOL_PRINT *Str,
- IN CHAR16 *fmt,
- ...
- )
-{
- UINT16 *AppendStr;
- VA_LIST Args;
- UINTN StringSize;
-
- AppendStr = AllocateZeroPool (0x1000);
- if (AppendStr == NULL) {
- return Str->str;
- }
-
- VA_START (Args, fmt);
- UnicodeVSPrint (AppendStr, 0x1000, fmt, Args);
- VA_END (Args);
- if (NULL == Str->str) {
- StringSize = StrSize (AppendStr);
- Str->str = AllocateZeroPool (StringSize);
- ASSERT (Str->str != NULL);
- } else {
- StringSize = StrSize (AppendStr);
- StringSize += (StrSize (Str->str) - sizeof (UINT16));
-
- Str->str = ReallocatePool (
- StrSize (Str->str),
- StringSize,
- Str->str
- );
- ASSERT (Str->str != NULL);
- }
-
- Str->maxlen = MAX_CHAR * sizeof (UINT16);
- if (StringSize < Str->maxlen) {
- StrCat (Str->str, AppendStr);
- Str->len = StringSize - sizeof (UINT16);
- }
-
- FreePool (AppendStr);
- return Str->str;
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathPci (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- PCI_DEVICE_PATH *Pci;
-
- Pci = DevPath;
- CatPrint (Str, L"Pci(%x|%x)", (UINTN) Pci->Device, (UINTN) Pci->Function);
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathPccard (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- PCCARD_DEVICE_PATH *Pccard;
-
- Pccard = DevPath;
- CatPrint (Str, L"Pcmcia(Function%x)", (UINTN) Pccard->FunctionNumber);
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathMemMap (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- MEMMAP_DEVICE_PATH *MemMap;
-
- MemMap = DevPath;
- CatPrint (
- Str,
- L"MemMap(%d:%lx-%lx)",
- MemMap->MemoryType,
- MemMap->StartingAddress,
- MemMap->EndingAddress
- );
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathController (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- CONTROLLER_DEVICE_PATH *Controller;
-
- Controller = DevPath;
- CatPrint (Str, L"Ctrl(%d)", (UINTN) Controller->ControllerNumber);
-}
-
-
-/**
- Convert Vendor device path to device name.
-
- @param Str The buffer store device name
- @param DevPath Pointer to vendor device path
-
-**/
-VOID
-EFIAPI
-DevPathVendor (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- VENDOR_DEVICE_PATH *Vendor;
- CHAR16 *Type;
- UINTN DataLength;
- UINTN Index;
- UINT32 FlowControlMap;
-
- UINT16 Info;
-
- Vendor = DevPath;
-
- switch (DevicePathType (&Vendor->Header)) {
- case HARDWARE_DEVICE_PATH:
- Type = L"Hw";
- break;
-
- case MESSAGING_DEVICE_PATH:
- Type = L"Msg";
- if (CompareGuid (&Vendor->Guid, &gEfiPcAnsiGuid)) {
- CatPrint (Str, L"VenPcAnsi()");
- return ;
- } else if (CompareGuid (&Vendor->Guid, &gEfiVT100Guid)) {
- CatPrint (Str, L"VenVt100()");
- return ;
- } else if (CompareGuid (&Vendor->Guid, &gEfiVT100PlusGuid)) {
- CatPrint (Str, L"VenVt100Plus()");
- return ;
- } else if (CompareGuid (&Vendor->Guid, &gEfiVTUTF8Guid)) {
- CatPrint (Str, L"VenUft8()");
- return ;
- } else if (CompareGuid (&Vendor->Guid, &gEfiUartDevicePathGuid )) {
- FlowControlMap = (((UART_FLOW_CONTROL_DEVICE_PATH *) Vendor)->FlowControlMap);
- switch (FlowControlMap & 0x00000003) {
- case 0:
- CatPrint (Str, L"UartFlowCtrl(%s)", L"None");
- break;
-
- case 1:
- CatPrint (Str, L"UartFlowCtrl(%s)", L"Hardware");
- break;
-
- case 2:
- CatPrint (Str, L"UartFlowCtrl(%s)", L"XonXoff");
- break;
-
- default:
- break;
- }
-
- return ;
-
- } else if (CompareGuid (&Vendor->Guid, &gEfiSasDevicePathGuid)) {
- CatPrint (
- Str,
- L"SAS(%lx,%lx,%x,",
- ((SAS_DEVICE_PATH *) Vendor)->SasAddress,
- ((SAS_DEVICE_PATH *) Vendor)->Lun,
- ((SAS_DEVICE_PATH *) Vendor)->RelativeTargetPort
- );
- Info = (((SAS_DEVICE_PATH *) Vendor)->DeviceTopology);
- if ((Info & 0x0f) == 0) {
- CatPrint (Str, L"NoTopology,0,0,0,");
- } else if (((Info & 0x0f) == 1) || ((Info & 0x0f) == 2)) {
- CatPrint (
- Str,
- L"%s,%s,%s,",
- ((Info & (0x1 << 4)) != 0) ? L"SATA" : L"SAS",
- ((Info & (0x1 << 5)) != 0) ? L"External" : L"Internal",
- ((Info & (0x1 << 6)) != 0) ? L"Expanded" : L"Direct"
- );
- if ((Info & 0x0f) == 1) {
- CatPrint (Str, L"0,");
- } else {
- CatPrint (Str, L"%x,", (UINTN) ((Info >> 8) & 0xff));
- }
- } else {
- CatPrint (Str, L"0,0,0,0,");
- }
-
- CatPrint (Str, L"%x)", (UINTN) ((SAS_DEVICE_PATH *) Vendor)->Reserved);
- return ;
-
- } else if (CompareGuid (&Vendor->Guid, &gEfiDebugPortProtocolGuid)) {
- CatPrint (Str, L"DebugPort()");
- return ;
- }
- break;
-
- case MEDIA_DEVICE_PATH:
- Type = L"Media";
- break;
-
- default:
- Type = L"?";
- break;
- }
-
- CatPrint (Str, L"Ven%s(%g", Type, &Vendor->Guid);
- DataLength = DevicePathNodeLength (&Vendor->Header) - sizeof (VENDOR_DEVICE_PATH);
- if (DataLength > 0) {
- CatPrint (Str, L",");
- for (Index = 0; Index < DataLength; Index++) {
- CatPrint (Str, L"%02x", (UINTN) ((VENDOR_DEVICE_PATH_WITH_DATA *) Vendor)->VendorDefinedData[Index]);
- }
- }
- CatPrint (Str, L")");
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathAcpi (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- ACPI_HID_DEVICE_PATH *Acpi;
-
- Acpi = DevPath;
- if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
- CatPrint (Str, L"Acpi(PNP%04x,%x)", (UINTN) EISA_ID_TO_NUM (Acpi->HID), (UINTN) Acpi->UID);
- } else {
- CatPrint (Str, L"Acpi(%08x,%x)", (UINTN) Acpi->HID, (UINTN) Acpi->UID);
- }
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathExtendedAcpi (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- ACPI_EXTENDED_HID_DEVICE_PATH *ExtendedAcpi;
-
- //
- // Index for HID, UID and CID strings, 0 for non-exist
- //
- UINT16 HIDSTRIdx;
- UINT16 UIDSTRIdx;
- UINT16 CIDSTRIdx;
- UINT16 Index;
- UINT16 Length;
- UINT16 Anchor;
- CHAR8 *AsChar8Array;
-
- ASSERT (Str != NULL);
- ASSERT (DevPath != NULL);
-
- HIDSTRIdx = 0;
- UIDSTRIdx = 0;
- CIDSTRIdx = 0;
- ExtendedAcpi = DevPath;
- Length = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) ExtendedAcpi);
-
- ASSERT (Length >= 19);
- AsChar8Array = (CHAR8 *) ExtendedAcpi;
-
- //
- // find HIDSTR
- //
- Anchor = 16;
- for (Index = Anchor; Index < Length && AsChar8Array[Index] != '\0'; Index++) {
- ;
- }
- if (Index > Anchor) {
- HIDSTRIdx = Anchor;
- }
- //
- // find UIDSTR
- //
- Anchor = (UINT16) (Index + 1);
- for (Index = Anchor; Index < Length && AsChar8Array[Index] != '\0'; Index++) {
- ;
- }
- if (Index > Anchor) {
- UIDSTRIdx = Anchor;
- }
- //
- // find CIDSTR
- //
- Anchor = (UINT16) (Index + 1);
- for (Index = Anchor; Index < Length && AsChar8Array[Index] != '\0'; Index++) {
- ;
- }
- if (Index > Anchor) {
- CIDSTRIdx = Anchor;
- }
-
- if (HIDSTRIdx == 0 && CIDSTRIdx == 0 && ExtendedAcpi->UID == 0) {
- CatPrint (Str, L"AcpiExp(");
- if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
- CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->HID));
- } else {
- CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->HID);
- }
- if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
- CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->CID));
- } else {
- CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->CID);
- }
- if (UIDSTRIdx != 0) {
- CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);
- } else {
- CatPrint (Str, L"\"\")");
- }
- } else {
- CatPrint (Str, L"AcpiEx(");
- if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
- CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->HID));
- } else {
- CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->HID);
- }
- if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
- CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->CID));
- } else {
- CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->CID);
- }
- CatPrint (Str, L"%x,", (UINTN) ExtendedAcpi->UID);
-
- if (HIDSTRIdx != 0) {
- CatPrint (Str, L"%a,", AsChar8Array + HIDSTRIdx);
- } else {
- CatPrint (Str, L"\"\",");
- }
- if (CIDSTRIdx != 0) {
- CatPrint (Str, L"%a,", AsChar8Array + CIDSTRIdx);
- } else {
- CatPrint (Str, L"\"\",");
- }
- if (UIDSTRIdx != 0) {
- CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);
- } else {
- CatPrint (Str, L"\"\")");
- }
- }
-
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathAdrAcpi (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- ACPI_ADR_DEVICE_PATH *AcpiAdr;
- UINT16 Index;
- UINT16 Length;
- UINT16 AdditionalAdrCount;
-
- AcpiAdr = DevPath;
- Length = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr);
- AdditionalAdrCount = (UINT16) ((Length - 8) / 4);
-
- CatPrint (Str, L"AcpiAdr(%x", (UINTN) AcpiAdr->ADR);
- for (Index = 0; Index < AdditionalAdrCount; Index++) {
- CatPrint (Str, L",%x", (UINTN) *(UINT32 *) ((UINT8 *) AcpiAdr + 8 + Index * 4));
- }
- CatPrint (Str, L")");
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathAtapi (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- ATAPI_DEVICE_PATH *Atapi;
-
- Atapi = DevPath;
- CatPrint (
- Str,
- L"Ata(%s,%s)",
- Atapi->PrimarySecondary ? L"Secondary" : L"Primary",
- Atapi->SlaveMaster ? L"Slave" : L"Master"
- );
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathScsi (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- SCSI_DEVICE_PATH *Scsi;
-
- Scsi = DevPath;
- CatPrint (Str, L"Scsi(Pun%x,Lun%x)", (UINTN) Scsi->Pun, (UINTN) Scsi->Lun);
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathFibre (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- FIBRECHANNEL_DEVICE_PATH *Fibre;
-
- Fibre = DevPath;
- CatPrint (Str, L"Fibre(Wwn%lx,Lun%x)", Fibre->WWN, Fibre->Lun);
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPath1394 (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- F1394_DEVICE_PATH *F1394Path;
-
- F1394Path = DevPath;
- CatPrint (Str, L"1394(%g)", &F1394Path->Guid);
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathUsb (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- USB_DEVICE_PATH *Usb;
-
- Usb = DevPath;
- CatPrint (Str, L"Usb(%x,%x)", (UINTN) Usb->ParentPortNumber, (UINTN) Usb->InterfaceNumber);
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathUsbWWID (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- USB_WWID_DEVICE_PATH *UsbWWId;
-
- UsbWWId = DevPath;
- CatPrint (
- Str,
- L"UsbWwid(%x,%x,%x,\"WWID\")",
- (UINTN) UsbWWId->VendorId,
- (UINTN) UsbWWId->ProductId,
- (UINTN) UsbWWId->InterfaceNumber
- );
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathLogicalUnit (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
-
- LogicalUnit = DevPath;
- CatPrint (Str, L"Unit(%x)", (UINTN) LogicalUnit->Lun);
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathUsbClass (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- USB_CLASS_DEVICE_PATH *UsbClass;
-
- UsbClass = DevPath;
- CatPrint (
- Str,
- L"Usb Class(%x,%x,%x,%x,%x)",
- (UINTN) UsbClass->VendorId,
- (UINTN) UsbClass->ProductId,
- (UINTN) UsbClass->DeviceClass,
- (UINTN) UsbClass->DeviceSubClass,
- (UINTN) UsbClass->DeviceProtocol
- );
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathSata (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- SATA_DEVICE_PATH *Sata;
-
- Sata = DevPath;
- CatPrint (
- Str,
- L"Sata(%x,%x,%x)",
- (UINTN) Sata->HBAPortNumber,
- (UINTN) Sata->PortMultiplierPortNumber,
- (UINTN) Sata->Lun
- );
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathI2O (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- I2O_DEVICE_PATH *I2OPath;
-
- I2OPath = DevPath;
- CatPrint (Str, L"I2O(%x)", (UINTN) I2OPath->Tid);
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathMacAddr (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- MAC_ADDR_DEVICE_PATH *MACDevPath;
- UINTN HwAddressSize;
- UINTN Index;
-
- MACDevPath = DevPath;
-
- HwAddressSize = sizeof (EFI_MAC_ADDRESS);
- if (MACDevPath->IfType == 0x01 || MACDevPath->IfType == 0x00) {
- HwAddressSize = 6;
- }
-
- CatPrint (Str, L"Mac(");
-
- for (Index = 0; Index < HwAddressSize; Index++) {
- CatPrint (Str, L"%02x", (UINTN) MACDevPath->MacAddress.Addr[Index]);
- }
-
- CatPrint (Str, L")");
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathIPv4 (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- IPv4_DEVICE_PATH *IPDevPath;
-
- IPDevPath = DevPath;
- CatPrint (
- Str,
- L"IPv4(%d.%d.%d.%d:%d)",
- (UINTN) IPDevPath->RemoteIpAddress.Addr[0],
- (UINTN) IPDevPath->RemoteIpAddress.Addr[1],
- (UINTN) IPDevPath->RemoteIpAddress.Addr[2],
- (UINTN) IPDevPath->RemoteIpAddress.Addr[3],
- (UINTN) IPDevPath->RemotePort
- );
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathIPv6 (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- IPv6_DEVICE_PATH *IPv6DevPath;
-
- IPv6DevPath = DevPath;
- CatPrint (
- Str,
- L"IPv6(%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x)",
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[0],
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[1],
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[2],
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[3],
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[4],
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[5],
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[6],
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[7],
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[8],
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[9],
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[10],
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[11],
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[12],
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[13],
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[14],
- (UINTN) IPv6DevPath->RemoteIpAddress.Addr[15]
- );
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathInfiniBand (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- INFINIBAND_DEVICE_PATH *InfiniBand;
-
- InfiniBand = DevPath;
- CatPrint (
- Str,
- L"Infiniband(%x,%g,%lx,%lx,%lx)",
- (UINTN) InfiniBand->ResourceFlags,
- InfiniBand->PortGid,
- InfiniBand->ServiceId,
- InfiniBand->TargetPortId,
- InfiniBand->DeviceId
- );
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathUart (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- UART_DEVICE_PATH *Uart;
- CHAR8 Parity;
-
- Uart = DevPath;
- switch (Uart->Parity) {
- case 0:
- Parity = 'D';
- break;
-
- case 1:
- Parity = 'N';
- break;
-
- case 2:
- Parity = 'E';
- break;
-
- case 3:
- Parity = 'O';
- break;
-
- case 4:
- Parity = 'M';
- break;
-
- case 5:
- Parity = 'S';
- break;
-
- default:
- Parity = 'x';
- break;
- }
-
- if (Uart->BaudRate == 0) {
- CatPrint (Str, L"Uart(DEFAULT,%c,", Parity);
- } else {
- CatPrint (Str, L"Uart(%d,%c,", Uart->BaudRate, Parity);
- }
-
- if (Uart->DataBits == 0) {
- CatPrint (Str, L"D,");
- } else {
- CatPrint (Str, L"%d,", (UINTN) Uart->DataBits);
- }
-
- switch (Uart->StopBits) {
- case 0:
- CatPrint (Str, L"D)");
- break;
-
- case 1:
- CatPrint (Str, L"1)");
- break;
-
- case 2:
- CatPrint (Str, L"1.5)");
- break;
-
- case 3:
- CatPrint (Str, L"2)");
- break;
-
- default:
- CatPrint (Str, L"x)");
- break;
- }
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathiSCSI (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- ISCSI_DEVICE_PATH_WITH_NAME *IScsi;
- UINT16 Options;
-
- ASSERT (Str != NULL);
- ASSERT (DevPath != NULL);
-
- IScsi = DevPath;
- CatPrint (
- Str,
- L"iSCSI(%s,%x,%lx,",
- IScsi->iSCSITargetName,
- IScsi->TargetPortalGroupTag,
- IScsi->Lun
- );
-
- Options = IScsi->LoginOption;
- CatPrint (Str, L"%s,", (((Options >> 1) & 0x0001) != 0) ? L"CRC32C" : L"None");
- CatPrint (Str, L"%s,", (((Options >> 3) & 0x0001) != 0) ? L"CRC32C" : L"None");
- if (((Options >> 11) & 0x0001) != 0) {
- CatPrint (Str, L"%s,", L"None");
- } else if (((Options >> 12) & 0x0001) != 0) {
- CatPrint (Str, L"%s,", L"CHAP_UNI");
- } else {
- CatPrint (Str, L"%s,", L"CHAP_BI");
-
- }
-
- CatPrint (Str, L"%s)", (IScsi->NetworkProtocol == 0) ? L"TCP" : L"reserved");
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathHardDrive (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- HARDDRIVE_DEVICE_PATH *Hd;
-
- Hd = DevPath;
- switch (Hd->SignatureType) {
- case SIGNATURE_TYPE_MBR:
- CatPrint (
- Str,
- L"HD(Part%d,Sig%08x)",
- (UINTN) Hd->PartitionNumber,
- (UINTN) *((UINT32 *) (&(Hd->Signature[0])))
- );
- break;
-
- case SIGNATURE_TYPE_GUID:
- CatPrint (
- Str,
- L"HD(Part%d,Sig%g)",
- (UINTN) Hd->PartitionNumber,
- (EFI_GUID *) &(Hd->Signature[0])
- );
- break;
-
- default:
- CatPrint (
- Str,
- L"HD(Part%d,MBRType=%02x,SigType=%02x)",
- (UINTN) Hd->PartitionNumber,
- (UINTN) Hd->MBRType,
- (UINTN) Hd->SignatureType
- );
- break;
- }
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathCDROM (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- CDROM_DEVICE_PATH *Cd;
-
- Cd = DevPath;
- CatPrint (Str, L"CDROM(Entry%x)", (UINTN) Cd->BootEntry);
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathFilePath (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- FILEPATH_DEVICE_PATH *Fp;
-
- Fp = DevPath;
- CatPrint (Str, L"%s", Fp->PathName);
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathMediaProtocol (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- MEDIA_PROTOCOL_DEVICE_PATH *MediaProt;
-
- MediaProt = DevPath;
- CatPrint (Str, L"Media(%g)", &MediaProt->Protocol);
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathFvFilePath (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;
-
- FvFilePath = DevPath;
- CatPrint (Str, L"%g", &FvFilePath->FvFileName);
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathBssBss (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- BBS_BBS_DEVICE_PATH *Bbs;
- CHAR16 *Type;
-
- Bbs = DevPath;
- switch (Bbs->DeviceType) {
- case BBS_TYPE_FLOPPY:
- Type = L"Floppy";
- break;
-
- case BBS_TYPE_HARDDRIVE:
- Type = L"Harddrive";
- break;
-
- case BBS_TYPE_CDROM:
- Type = L"CDROM";
- break;
-
- case BBS_TYPE_PCMCIA:
- Type = L"PCMCIA";
- break;
-
- case BBS_TYPE_USB:
- Type = L"Usb";
- break;
-
- case BBS_TYPE_EMBEDDED_NETWORK:
- Type = L"Net";
- break;
-
- case BBS_TYPE_BEV:
- Type = L"BEV";
- break;
-
- default:
- Type = L"?";
- break;
- }
- CatPrint (Str, L"Legacy-%s", Type);
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathEndInstance (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- CatPrint (Str, L",");
-}
-
-/**
- Convert Device Path to a Unicode string for printing.
-
- @param Str The buffer holding the output string.
- This buffer contains the length of the
- string and the maixmum length reserved
- for the string buffer.
- @param DevPath The device path.
-
-**/
-VOID
-DevPathNodeUnknown (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- CatPrint (Str, L"?");
-}
-
-DEVICE_PATH_STRING_TABLE DevPathTable[] = {
- {
- HARDWARE_DEVICE_PATH,
- HW_PCI_DP,
- DevPathPci
- },
- {
- HARDWARE_DEVICE_PATH,
- HW_PCCARD_DP,
- DevPathPccard
- },
- {
- HARDWARE_DEVICE_PATH,
- HW_MEMMAP_DP,
- DevPathMemMap
- },
- {
- HARDWARE_DEVICE_PATH,
- HW_VENDOR_DP,
- DevPathVendor
- },
- {
- HARDWARE_DEVICE_PATH,
- HW_CONTROLLER_DP,
- DevPathController
- },
- {
- ACPI_DEVICE_PATH,
- ACPI_DP,
- DevPathAcpi
- },
- {
- ACPI_DEVICE_PATH,
- ACPI_EXTENDED_DP,
- DevPathExtendedAcpi
- },
- {
- ACPI_DEVICE_PATH,
- ACPI_ADR_DP,
- DevPathAdrAcpi
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_ATAPI_DP,
- DevPathAtapi
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_SCSI_DP,
- DevPathScsi
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_FIBRECHANNEL_DP,
- DevPathFibre
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_1394_DP,
- DevPath1394
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_USB_DP,
- DevPathUsb
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_USB_WWID_DP,
- DevPathUsbWWID
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_DEVICE_LOGICAL_UNIT_DP,
- DevPathLogicalUnit
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_USB_CLASS_DP,
- DevPathUsbClass
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_SATA_DP,
- DevPathSata
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_I2O_DP,
- DevPathI2O
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_MAC_ADDR_DP,
- DevPathMacAddr
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_IPv4_DP,
- DevPathIPv4
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_IPv6_DP,
- DevPathIPv6
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_INFINIBAND_DP,
- DevPathInfiniBand
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_UART_DP,
- DevPathUart
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_VENDOR_DP,
- DevPathVendor
- },
- {
- MESSAGING_DEVICE_PATH,
- MSG_ISCSI_DP,
- DevPathiSCSI
- },
- {
- MEDIA_DEVICE_PATH,
- MEDIA_HARDDRIVE_DP,
- DevPathHardDrive
- },
- {
- MEDIA_DEVICE_PATH,
- MEDIA_CDROM_DP,
- DevPathCDROM
- },
- {
- MEDIA_DEVICE_PATH,
- MEDIA_VENDOR_DP,
- DevPathVendor
- },
- {
- MEDIA_DEVICE_PATH,
- MEDIA_FILEPATH_DP,
- DevPathFilePath
- },
- {
- MEDIA_DEVICE_PATH,
- MEDIA_PROTOCOL_DP,
- DevPathMediaProtocol
- },
- {
- MEDIA_DEVICE_PATH,
- MEDIA_PIWG_FW_FILE_DP,
- DevPathFvFilePath
- },
- {
- BBS_DEVICE_PATH,
- BBS_BBS_DP,
- DevPathBssBss
- },
- {
- END_DEVICE_PATH_TYPE,
- END_INSTANCE_DEVICE_PATH_SUBTYPE,
- DevPathEndInstance
- },
- {
- 0,
- 0,
- NULL
- }
-};
-
-
-/**
- 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
- )
-{
- POOL_PRINT Str;
- EFI_DEVICE_PATH_PROTOCOL *DevPathNode;
- VOID (*DumpNode) (POOL_PRINT *, VOID *);
-
- UINTN Index;
- UINTN NewSize;
-
- EFI_STATUS Status;
- CHAR16 *ToText;
- EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;
-
- ZeroMem (&Str, sizeof (Str));
-
- if (DevPath == NULL) {
- goto Done;
- }
-
- Status = gBS->LocateProtocol (
- &gEfiDevicePathToTextProtocolGuid,
- NULL,
- (VOID **) &DevPathToText
- );
- if (!EFI_ERROR (Status)) {
- ToText = DevPathToText->ConvertDevicePathToText (
- DevPath,
- FALSE,
- TRUE
- );
- ASSERT (ToText != NULL);
- return ToText;
- }
-
- //
- // Process each device path node
- //
- DevPathNode = DevPath;
- while (!IsDevicePathEnd (DevPathNode)) {
- //
- // Find the handler to dump this device path node
- //
- DumpNode = NULL;
- for (Index = 0; DevPathTable[Index].Function; Index += 1) {
-
- if (DevicePathType (DevPathNode) == DevPathTable[Index].Type &&
- DevicePathSubType (DevPathNode) == DevPathTable[Index].SubType
- ) {
- DumpNode = DevPathTable[Index].Function;
- break;
- }
- }
- //
- // If not found, use a generic function
- //
- if (!DumpNode) {
- DumpNode = DevPathNodeUnknown;
- }
- //
- // Put a path seperator in if needed
- //
- if (Str.len && DumpNode != DevPathEndInstance) {
- CatPrint (&Str, L"/");
- }
- //
- // Print this node of the device path
- //
- DumpNode (&Str, DevPathNode);
-
- //
- // Next device path node
- //
- DevPathNode = NextDevicePathNode (DevPathNode);
- }
-
-Done:
- NewSize = (Str.len + 1) * sizeof (CHAR16);
- Str.str = ReallocatePool (NewSize, NewSize, Str.str);
- ASSERT (Str.str != NULL);
- Str.str[Str.len] = 0;
- return Str.str;
-}
diff --git a/MdeModulePkg/Library/GenericBdsLib/GenericBdsLib.inf b/MdeModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
deleted file mode 100644
index fdce5f3d85..0000000000
--- a/MdeModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
+++ /dev/null
@@ -1,114 +0,0 @@
-#/** @file
-#
-# General BDS defines and produce general interfaces for platform BDS driver 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 - 2008, Intel Corporation. <BR>
-# All rights reserved. This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution. The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-#
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#**/
-
-[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = GenericBdsLib
- FILE_GUID = e405ec31-ccaa-4dd4-83e8-0aec01703f7e
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
- LIBRARY_CLASS = GenericBdsLib|DXE_DRIVER UEFI_APPLICATION
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-# VALID_ARCHITECTURES = IA32 X64 IPF EBC
-#
-
-[Sources.common]
- DevicePath.c
- Performance.c
- BdsConnect.c
- BdsMisc.c
- BdsConsole.c
- BdsBoot.c
- InternalBdsLib.h
-
-[Sources.IPF]
- Ipf/ShadowRom.c
-
-[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- #
- #This dependency is because of gEfiLegacyBiosProtocolGuid. It may be removed if a Library class is created to
- #abstract away definition in Framework specification or PI spec incorporates the Legacy Booting Protocols.
- #
- IntelFrameworkPkg/IntelFrameworkPkg.dec
-
-
-[LibraryClasses]
- DevicePathLib
- PeCoffGetEntryPointLib
- BaseLib
- HobLib
- UefiRuntimeServicesTableLib
- DxeServicesTableLib
- MemoryAllocationLib
- UefiLib
- UefiBootServicesTableLib
- BaseMemoryLib
- DebugLib
- PrintLib
- PcdLib
- PerformanceLib
- TimerLib
- PcdLib
- DxeServicesLib
-
-[Guids]
- gEfiVT100PlusGuid # ALWAYS_CONSUMED
- gEfiMemoryTypeInformationGuid # ALWAYS_CONSUMED
- gEfiVTUTF8Guid # ALWAYS_CONSUMED
- gEfiShellFileGuid # ALWAYS_CONSUMED
- gEfiGlobalVariableGuid # ALWAYS_CONSUMED
- gEfiVT100Guid # ALWAYS_CONSUMED
- gEfiFileInfoGuid # ALWAYS_CONSUMED
- gEfiPcAnsiGuid # ALWAYS_CONSUMED
- gEfiGenericPlatformVariableGuid # ALWAYS_CONSUMED
- gEfiUartDevicePathGuid # ALWAYS_CONSUMED
- gEfiSasDevicePathGuid # ALWAYS_CONSUMED
-
-[Protocols]
- gEfiSimpleFileSystemProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiSimpleTextOutProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiPciIoProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiLoadedImageProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiDevicePathToTextProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiSimpleNetworkProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiDebugPortProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiSimpleTextInProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiBlockIoProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiFirmwareVolume2ProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiLegacyBiosProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiCpuArchProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiDevicePathProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiFirmwareVolumeDispatchProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiAcpiS3SaveProtocolGuid
- gEfiGraphicsOutputProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiUgaDrawProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiConsoleControlProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiOEMBadgingProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiHiiFontProtocolGuid # PROTOCOL ALWAYS_CONSUMED
-
-[FeaturePcd.common]
- gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport
-
-[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformBootTimeOutDefault
- gEfiMdeModulePkgTokenSpaceGuid.PcdDefaultBootFileName \ No newline at end of file
diff --git a/MdeModulePkg/Library/GenericBdsLib/InternalBdsLib.h b/MdeModulePkg/Library/GenericBdsLib/InternalBdsLib.h
deleted file mode 100644
index cb11b6e02d..0000000000
--- a/MdeModulePkg/Library/GenericBdsLib/InternalBdsLib.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/** @file
- BDS library definition, include the file and data structure
-
-Copyright (c) 2004 - 2008, Intel Corporation. <BR>
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#ifndef _INTERNAL_BDS_LIB_H_
-#define _INTERNAL_BDS_LIB_H_
-
-#include <PiDxe.h>
-
-#include <IndustryStandard/Pci22.h>
-
-#include <Protocol/BlockIo.h>
-#include <Protocol/LoadedImage.h>
-#include <Protocol/Cpu.h>
-#include <Protocol/SimpleFileSystem.h>
-#include <Protocol/DebugPort.h>
-#include <Protocol/DevicePath.h>
-#include <Protocol/SimpleTextIn.h>
-#include <Protocol/LegacyBios.h>
-#include <Protocol/SimpleTextOut.h>
-#include <Protocol/SimpleNetwork.h>
-#include <Protocol/DevicePathToText.h>
-#include <Protocol/FirmwareVolume2.h>
-#include <Protocol/PciIo.h>
-#include <Protocol/AcpiS3Save.h>
-#include <Protocol/Performance.h>
-#include <Protocol/FirmwareVolumeDispatch.h>
-#include <Protocol/OEMBadging.h>
-#include <Protocol/ConsoleControl.h>
-#include <Protocol/GraphicsOutput.h>
-#include <Protocol/UgaDraw.h>
-#include <Protocol/HiiFont.h>
-#include <Protocol/HiiImage.h>
-
-
-#include <Guid/MemoryTypeInformation.h>
-#include <Guid/FileInfo.h>
-#include <Guid/GlobalVariable.h>
-#include <Guid/PcAnsi.h>
-#include <Guid/ShellFile.h>
-#include <Guid/GenericPlatformVariable.h>
-#include <Guid/Bmp.h>
-
-#include <Library/PrintLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/DxeServicesTableLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/HobLib.h>
-#include <Library/BaseLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/PerformanceLib.h>
-#include <Library/PcdLib.h>
-#include <Library/IfrSupportLib.h>
-#include <Library/PeCoffGetEntryPointLib.h>
-#include <Library/GenericBdsLib.h>
-#include <Library/TimerLib.h>
-#include <Library/PcdLib.h>
-#include <Library/DxeServicesLib.h>
-
-#define PERFORMANCE_SIGNATURE SIGNATURE_32 ('P', 'e', 'r', 'f')
-#define PERF_TOKEN_SIZE 28
-#define PERF_TOKEN_LENGTH (PERF_TOKEN_SIZE - 1)
-#define PERF_PEI_ENTRY_MAX_NUM 50
-
-typedef struct {
- CHAR8 Token[PERF_TOKEN_SIZE];
- UINT32 Duration;
-} PERF_DATA;
-
-typedef struct {
- UINT64 BootToOs;
- UINT64 S3Resume;
- UINT32 S3EntryNum;
- PERF_DATA S3Entry[PERF_PEI_ENTRY_MAX_NUM];
- UINT64 CpuFreq;
- UINT64 BDSRaw;
- UINT32 Count;
- UINT32 Signiture;
-} PERF_HEADER;
-
-/**
-
- Allocates a block of memory and writes performance data of booting into it.
- OS can processing these record.
-
-**/
-VOID
-WriteBootToOsPerformanceData (
- VOID
- );
-
-#endif // _BDS_LIB_H_
diff --git a/MdeModulePkg/Library/GenericBdsLib/Ipf/ShadowRom.c b/MdeModulePkg/Library/GenericBdsLib/Ipf/ShadowRom.c
deleted file mode 100644
index 10e8f55c55..0000000000
--- a/MdeModulePkg/Library/GenericBdsLib/Ipf/ShadowRom.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/** @file
- Shadow all option rom
-
-Copyright (c) 2004 - 2008, Intel Corporation. <BR>
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "InternalBdsLib.h"
-
-UINT8 mShadowRomFlag = 0;
-
-/**
- Shadow all opton ROM if the it is not done.
-**/
-VOID
-ShadowAllOptionRom(
- VOID
- )
-{
- EFI_STATUS Status;
- EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
- //
- // Rom shadow only do once.
- //
- if (mShadowRomFlag == 0) {
- Status = gBS->LocateProtocol (
- &gEfiLegacyBiosProtocolGuid,
- NULL,
- (VOID **) &LegacyBios
- );
- if (!EFI_ERROR (Status)) {
- LegacyBios->PrepareToBootEfi (LegacyBios, NULL, NULL);
- }
-
- mShadowRomFlag = 1;
- }
-
- return ;
-}
diff --git a/MdeModulePkg/Library/GenericBdsLib/Performance.c b/MdeModulePkg/Library/GenericBdsLib/Performance.c
deleted file mode 100644
index 0e3f7936cd..0000000000
--- a/MdeModulePkg/Library/GenericBdsLib/Performance.c
+++ /dev/null
@@ -1,316 +0,0 @@
-/** @file
- This file include the file which can help to get the system
- performance, all the function will only include if the performance
- switch is set.
-
-Copyright (c) 2004 - 2008, Intel Corporation. <BR>
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "InternalBdsLib.h"
-
-PERF_HEADER mPerfHeader;
-PERF_DATA mPerfData;
-
-/**
- Get the short verion of PDB file name to be
- used in performance data logging.
-
- @param PdbFileName The long PDB file name.
- @param GaugeString The output string to be logged by performance logger.
-
-**/
-VOID
-GetShortPdbFileName (
- IN CONST CHAR8 *PdbFileName,
- OUT CHAR8 *GaugeString
- )
-{
- UINTN Index;
- UINTN Index1;
- UINTN StartIndex;
- UINTN EndIndex;
-
- if (PdbFileName == NULL) {
- AsciiStrCpy (GaugeString, " ");
- } else {
- StartIndex = 0;
- for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++)
- ;
-
- for (Index = 0; PdbFileName[Index] != 0; Index++) {
- if (PdbFileName[Index] == '\\') {
- StartIndex = Index + 1;
- }
-
- if (PdbFileName[Index] == '.') {
- EndIndex = Index;
- }
- }
-
- Index1 = 0;
- for (Index = StartIndex; Index < EndIndex; Index++) {
- GaugeString[Index1] = PdbFileName[Index];
- Index1++;
- if (Index1 == PERF_TOKEN_LENGTH - 1) {
- break;
- }
- }
-
- GaugeString[Index1] = 0;
- }
-
- return ;
-}
-
-/**
- Get the name from the Driver handle, which can be a handle with
- EFI_LOADED_IMAGE_PROTOCOL or EFI_DRIVER_BINDING_PROTOCOL installed.
- This name can be used in performance data logging.
-
- @param Handle Driver handle.
- @param GaugeString The output string to be logged by performance logger.
-
-**/
-VOID
-GetNameFromHandle (
- IN EFI_HANDLE Handle,
- OUT CHAR8 *GaugeString
- )
-{
- EFI_STATUS Status;
- EFI_LOADED_IMAGE_PROTOCOL *Image;
- CHAR8 *PdbFileName;
- EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;
-
- AsciiStrCpy (GaugeString, " ");
-
- //
- // Get handle name from image protocol
- //
- Status = gBS->HandleProtocol (
- Handle,
- &gEfiLoadedImageProtocolGuid,
- (VOID **) &Image
- );
-
- if (EFI_ERROR (Status)) {
- Status = gBS->OpenProtocol (
- Handle,
- &gEfiDriverBindingProtocolGuid,
- (VOID **) &DriverBinding,
- NULL,
- NULL,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL
- );
- if (EFI_ERROR (Status)) {
- return ;
- }
- //
- // Get handle name from image protocol
- //
- Status = gBS->HandleProtocol (
- DriverBinding->ImageHandle,
- &gEfiLoadedImageProtocolGuid,
- (VOID **) &Image
- );
- }
-
- PdbFileName = PeCoffLoaderGetPdbPointer (Image->ImageBase);
-
- if (PdbFileName != NULL) {
- GetShortPdbFileName (PdbFileName, GaugeString);
- }
-
- return ;
-}
-
-/**
-
- Allocates a block of memory and writes performance data of booting into it.
- OS can processing these record.
-
-**/
-VOID
-WriteBootToOsPerformanceData (
- VOID
- )
-{
- EFI_STATUS Status;
- EFI_PHYSICAL_ADDRESS AcpiLowMemoryBase;
- UINT32 AcpiLowMemoryLength;
- UINT32 LimitCount;
- EFI_HANDLE *Handles;
- UINTN NoHandles;
- CHAR8 GaugeString[PERF_TOKEN_LENGTH];
- UINT8 *Ptr;
- UINT32 Index;
- UINT64 Ticker;
- UINT64 Freq;
- UINT32 Duration;
- UINTN LogEntryKey;
- CONST VOID *Handle;
- CONST CHAR8 *Token;
- CONST CHAR8 *Module;
- UINT64 StartTicker;
- UINT64 EndTicker;
- UINT64 StartValue;
- UINT64 EndValue;
- BOOLEAN CountUp;
-
- //
- // Retrive time stamp count as early as possilbe
- //
- Ticker = GetPerformanceCounter ();
-
- Freq = GetPerformanceCounterProperties (&StartValue, &EndValue);
-
- Freq = DivU64x32 (Freq, 1000);
-
- mPerfHeader.CpuFreq = Freq;
-
- //
- // Record BDS raw performance data
- //
- if (EndValue >= StartValue) {
- mPerfHeader.BDSRaw = Ticker - StartValue;
- CountUp = TRUE;
- } else {
- mPerfHeader.BDSRaw = StartValue - Ticker;
- CountUp = FALSE;
- }
-
- AcpiLowMemoryLength = 0x2000;
-
- //
- // Allocate a block of memory that contain performance data to OS
- //
- Status = gBS->AllocatePages (
- AllocateAnyPages,
- EfiACPIReclaimMemory,
- EFI_SIZE_TO_PAGES (AcpiLowMemoryLength),
- &AcpiLowMemoryBase
- );
- if (EFI_ERROR (Status)) {
- return ;
- }
-
-
- Ptr = (UINT8 *) ((UINT32) AcpiLowMemoryBase + sizeof (PERF_HEADER));
- LimitCount = (AcpiLowMemoryLength - sizeof (PERF_HEADER)) / sizeof (PERF_DATA);
-
- //
- // Put Detailed performance data into memory
- //
- Handles = NULL;
- Status = gBS->LocateHandleBuffer (
- AllHandles,
- NULL,
- NULL,
- &NoHandles,
- &Handles
- );
- if (EFI_ERROR (Status)) {
- gBS->FreePages (AcpiLowMemoryBase, 1);
- return ;
- }
-
- //
- // Get DXE drivers performance
- //
- for (Index = 0; Index < NoHandles; Index++) {
- Ticker = 0;
- LogEntryKey = 0;
- while ((LogEntryKey = GetPerformanceMeasurement (
- LogEntryKey,
- &Handle,
- &Token,
- &Module,
- &StartTicker,
- &EndTicker)) != 0) {
- if ((Handle == Handles[Index]) && (EndTicker != 0)) {
- Ticker += CountUp ? (EndTicker - StartTicker) : (StartTicker - EndTicker);
- }
- }
-
- Duration = (UINT32) DivU64x32 (Ticker, (UINT32) Freq);
-
- if (Duration > 0) {
-
- GetNameFromHandle (Handles[Index], GaugeString);
-
- AsciiStrCpy (mPerfData.Token, GaugeString);
- mPerfData.Duration = Duration;
-
- CopyMem (Ptr, &mPerfData, sizeof (PERF_DATA));
- Ptr += sizeof (PERF_DATA);
-
- mPerfHeader.Count++;
- if (mPerfHeader.Count == LimitCount) {
- goto Done;
- }
- }
- }
-
- FreePool (Handles);
-
- //
- // Get inserted performance data
- //
- LogEntryKey = 0;
- while ((LogEntryKey = GetPerformanceMeasurement (
- LogEntryKey,
- &Handle,
- &Token,
- &Module,
- &StartTicker,
- &EndTicker)) != 0) {
- if (Handle == NULL && EndTicker != 0) {
-
- ZeroMem (&mPerfData, sizeof (PERF_DATA));
-
- AsciiStrnCpy (mPerfData.Token, Token, PERF_TOKEN_LENGTH);
- Ticker = CountUp ? (EndTicker - StartTicker) : (StartTicker - EndTicker);
-
- mPerfData.Duration = (UINT32) DivU64x32 (Ticker, (UINT32) Freq);
-
- CopyMem (Ptr, &mPerfData, sizeof (PERF_DATA));
- Ptr += sizeof (PERF_DATA);
-
- mPerfHeader.Count++;
- if (mPerfHeader.Count == LimitCount) {
- goto Done;
- }
- }
- }
-
-Done:
-
- mPerfHeader.Signiture = PERFORMANCE_SIGNATURE;
-
- //
- // Put performance data to ACPI memory
- //
- CopyMem (
- (UINTN *) (UINTN) AcpiLowMemoryBase,
- &mPerfHeader,
- sizeof (PERF_HEADER)
- );
-
- gRT->SetVariable (
- L"PerfDataMemAddr",
- &gEfiGenericPlatformVariableGuid,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- sizeof (EFI_PHYSICAL_ADDRESS),
- &AcpiLowMemoryBase
- );
-
- return ;
-}
diff --git a/MdeModulePkg/Library/PlatformBdsLibNull/BdsPlatform.h b/MdeModulePkg/Library/PlatformBdsLibNull/BdsPlatform.h
index 1d4990831f..165ad3b1f2 100644
--- a/MdeModulePkg/Library/PlatformBdsLibNull/BdsPlatform.h
+++ b/MdeModulePkg/Library/PlatformBdsLibNull/BdsPlatform.h
@@ -26,4 +26,5 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/GenericBdsLib.h>
#include <Library/PlatformBdsLib.h>
+
#endif // _BDS_PLATFORM_H
diff --git a/MdeModulePkg/Library/PlatformBdsLibNull/PlatformBdsLibNull.inf b/MdeModulePkg/Library/PlatformBdsLibNull/PlatformBdsLibNull.inf
index 13bd32ec64..3ac36d9f8c 100644
--- a/MdeModulePkg/Library/PlatformBdsLibNull/PlatformBdsLibNull.inf
+++ b/MdeModulePkg/Library/PlatformBdsLibNull/PlatformBdsLibNull.inf
@@ -44,4 +44,4 @@
BaseMemoryLib
DebugLib
PcdLib
- GenericBdsLib
+ GenericBdsLib \ No newline at end of file