From ec8cd35c80fa0b5d9cf249754780f6f3d3809160 Mon Sep 17 00:00:00 2001 From: klu2 Date: Tue, 22 Jul 2008 04:17:51 +0000 Subject: [PATCH] Code scrub for GenericBdsLib git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5545 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Library/GenericBdsLib/BdsBoot.c | 153 +++++++++--------- .../Library/GenericBdsLib/BdsConnect.c | 10 +- .../Library/GenericBdsLib/BdsConsole.c | 5 +- MdeModulePkg/Library/GenericBdsLib/BdsMisc.c | 122 ++++++-------- .../Library/GenericBdsLib/DevicePath.c | 37 +---- .../Library/GenericBdsLib/Ebc/BmMachine.h | 23 --- .../Library/GenericBdsLib/GenericBdsLib.inf | 17 +- .../Library/GenericBdsLib/Ia32/BmMachine.h | 20 --- .../Library/GenericBdsLib/InternalBdsLib.h | 2 - .../Library/GenericBdsLib/Ipf/BmMachine.h | 20 --- .../Library/GenericBdsLib/Performance.c | 3 +- .../Library/GenericBdsLib/x64/BmMachine.h | 20 --- MdeModulePkg/MdeModulePkg.dec | 12 ++ 13 files changed, 162 insertions(+), 282 deletions(-) delete mode 100644 MdeModulePkg/Library/GenericBdsLib/Ebc/BmMachine.h delete mode 100644 MdeModulePkg/Library/GenericBdsLib/Ia32/BmMachine.h delete mode 100644 MdeModulePkg/Library/GenericBdsLib/Ipf/BmMachine.h delete mode 100644 MdeModulePkg/Library/GenericBdsLib/x64/BmMachine.h diff --git a/MdeModulePkg/Library/GenericBdsLib/BdsBoot.c b/MdeModulePkg/Library/GenericBdsLib/BdsBoot.c index 14df23af35..18738be8a8 100644 --- a/MdeModulePkg/Library/GenericBdsLib/BdsBoot.c +++ b/MdeModulePkg/Library/GenericBdsLib/BdsBoot.c @@ -17,10 +17,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 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. -// +/// +/// 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 } }; @@ -182,10 +182,11 @@ BdsLibBootViaBootOption ( // InitializeListHead (&TempBootLists); BdsLibRegisterNewOption (&TempBootLists, DevicePath, L"EFI Internal Shell", L"BootOrder"); + // // free the temporary device path created by BdsLibUpdateFvFileDevicePath() // - gBS->FreePool (DevicePath); + SafeFreePool (DevicePath); DevicePath = Option->DevicePath; } @@ -222,7 +223,7 @@ BdsLibBootViaBootOption ( // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media // machinename is ia32, ia64, x64, ... // - FilePath = FileDevicePath (Handle, DEFAULT_REMOVABLE_FILE_NAME); + FilePath = FileDevicePath (Handle, (CONST CHAR16*)PcdGetPtr(PcdDefaultBootFileName)); if (FilePath != NULL) { Status = gBS->LoadImage ( TRUE, @@ -340,6 +341,7 @@ BdsExpandPartitionPartialDevicePathToFull ( &mHdBootVariablePrivateGuid, &CachedDevicePathSize ); + if (CachedDevicePath != NULL) { TempNewDevicePath = CachedDevicePath; DeviceExist = FALSE; @@ -374,7 +376,7 @@ BdsExpandPartitionPartialDevicePathToFull ( // Find the matched device path. // Append the file path infomration from the boot option and return the fully expanded device path. // - DevicePath = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath); + DevicePath = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath); FullDevicePath = AppendDevicePath (Instance, DevicePath); // @@ -385,13 +387,14 @@ BdsExpandPartitionPartialDevicePathToFull ( // First delete the matched instance. // TempNewDevicePath = CachedDevicePath; - CachedDevicePath = BdsLibDelPartMatchInstance ( CachedDevicePath, Instance ); + CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, Instance ); SafeFreePool (TempNewDevicePath); + // // Second, append the remaining parth after the matched instance // TempNewDevicePath = CachedDevicePath; - CachedDevicePath = AppendDevicePathInstance ( Instance, CachedDevicePath ); + CachedDevicePath = AppendDevicePathInstance (Instance, CachedDevicePath ); SafeFreePool (TempNewDevicePath); // // Save the matching Device Path so we don't need to do a connect all next time @@ -404,8 +407,9 @@ BdsExpandPartitionPartialDevicePathToFull ( CachedDevicePath ); } - SafeFreePool(Instance); - gBS->FreePool (CachedDevicePath); + + SafeFreePool (Instance); + SafeFreePool (CachedDevicePath); return FullDevicePath; } } @@ -501,12 +505,12 @@ BdsExpandPartitionPartialDevicePathToFull ( break; } } - gBS->FreePool (CachedDevicePath); - gBS->FreePool (BlockIoBuffer); + + SafeFreePool (CachedDevicePath); + SafeFreePool (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 @@ -516,7 +520,7 @@ BdsExpandPartitionPartialDevicePathToFull ( device path. @retval TRUE There is a matched device path instance FALSE - -There is no matched device path instance + @retval FALSE There is no matched device path instance **/ BOOLEAN @@ -535,10 +539,11 @@ MatchPartitionDevicePathNode ( if ((BlockIoDevicePath == NULL) || (HardDriveDevicePath == NULL)) { return FALSE; } + // // Make PreviousDevicePath == the device path node before the end node // - DevicePath = BlockIoDevicePath; + DevicePath = BlockIoDevicePath; BlockIoHdDevicePathNode = NULL; // @@ -564,6 +569,7 @@ MatchPartitionDevicePathNode ( TmpHdPath = (HARDDRIVE_DEVICE_PATH *) BlockIoHdDevicePathNode; TempPath = (HARDDRIVE_DEVICE_PATH *) BdsLibUnpackDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath); Match = FALSE; + // // Check for the match // @@ -585,7 +591,6 @@ MatchPartitionDevicePathNode ( return Match; } - /** Delete the boot option associated with the handle passed in. @@ -620,21 +625,30 @@ BdsLibDeleteOptionFromHandle ( BootOrder = NULL; BootOrderSize = 0; + // + // Check "BootOrder" variable, if no, means there is no any boot order. + // BootOrder = BdsLibGetVariableAndSize ( L"BootOrder", &gEfiGlobalVariableGuid, &BootOrderSize ); - if (NULL == BootOrder) { + 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]); @@ -643,8 +657,9 @@ BdsLibDeleteOptionFromHandle ( &gEfiGlobalVariableGuid, &BootOptionSize ); - if (NULL == BootOptionVar) { - gBS->FreePool (BootOrder); + + if (BootOptionVar == NULL) { + SafeFreePool (BootOrder); return EFI_OUT_OF_RESOURCES; } @@ -660,14 +675,17 @@ BdsLibDeleteOptionFromHandle ( if ((OptionDevicePathSize == DevicePathSize) && (CompareMem (DevicePath, OptionDevicePath, DevicePathSize) == 0)) { BdsDeleteBootOption (BootOrder[Index], BootOrder, &BootOrderSize); - gBS->FreePool (BootOptionVar); + SafeFreePool (BootOptionVar); break; } - gBS->FreePool (BootOptionVar); + SafeFreePool (BootOptionVar); Index++; } + // + // Adjust number of boot option for "BootOrder" variable. + // Status = gRT->SetVariable ( L"BootOrder", &gEfiGlobalVariableGuid, @@ -676,7 +694,7 @@ BdsLibDeleteOptionFromHandle ( BootOrder ); - gBS->FreePool (BootOrder); + SafeFreePool (BootOrder); return Status; } @@ -686,8 +704,6 @@ BdsLibDeleteOptionFromHandle ( Delete all invalid EFI boot options. The probable invalid boot option could be Removable media or Network boot device. - VOID - @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 @@ -714,6 +730,9 @@ BdsDeleteAllInvalidEfiBootOption ( BootOrder = NULL; BootOrderSize = 0; + // + // Check "BootOrder" variable firstly, this variable hold the number of boot options + // BootOrder = BdsLibGetVariableAndSize ( L"BootOrder", &gEfiGlobalVariableGuid, @@ -732,7 +751,7 @@ BdsDeleteAllInvalidEfiBootOption ( &BootOptionSize ); if (NULL == BootOptionVar) { - gBS->FreePool (BootOrder); + SafeFreePool (BootOrder); return EFI_OUT_OF_RESOURCES; } @@ -746,7 +765,7 @@ BdsDeleteAllInvalidEfiBootOption ( // if ((DevicePathType (OptionDevicePath) == BBS_DEVICE_PATH) && (DevicePathSubType (OptionDevicePath) == BBS_BBS_DP)) { - gBS->FreePool (BootOptionVar); + SafeFreePool (BootOptionVar); Index++; continue; } @@ -768,7 +787,7 @@ BdsDeleteAllInvalidEfiBootOption ( BootOrder[Index] = 0xffff; } - gBS->FreePool (BootOptionVar); + SafeFreePool (BootOptionVar); Index++; } @@ -790,7 +809,7 @@ BdsDeleteAllInvalidEfiBootOption ( BootOrder ); - gBS->FreePool (BootOrder); + SafeFreePool (BootOrder); return Status; } @@ -842,11 +861,12 @@ BdsLibEnumerateAllBootOption ( EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData; EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; - FloppyNumber = 0; - CdromNumber = 0; - UsbNumber = 0; - MiscNumber = 0; + 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 @@ -855,6 +875,7 @@ BdsLibEnumerateAllBootOption ( 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 @@ -866,6 +887,7 @@ BdsLibEnumerateAllBootOption ( // Delete invalid boot option // BdsDeleteAllInvalidEfiBootOption (); + // // Parse removable media // @@ -876,6 +898,7 @@ BdsLibEnumerateAllBootOption ( &NumberBlockIoHandles, &BlockIoHandles ); + for (Index = 0; Index < NumberBlockIoHandles; Index++) { Status = gBS->HandleProtocol ( BlockIoHandles[Index], @@ -950,7 +973,7 @@ BdsLibEnumerateAllBootOption ( } if (NumberBlockIoHandles != 0) { - gBS->FreePool (BlockIoHandles); + SafeFreePool (BlockIoHandles); } // @@ -985,7 +1008,7 @@ BdsLibEnumerateAllBootOption ( NeedDelete = TRUE; Status = BdsLibGetImageHeader ( FileSystemHandles[Index], - DEFAULT_REMOVABLE_FILE_NAME, + (CHAR16*)PcdGetPtr (PcdDefaultBootFileName), &DosHeader, Hdr ); @@ -1012,7 +1035,7 @@ BdsLibEnumerateAllBootOption ( } if (NumberFileSystemHandles != 0) { - gBS->FreePool (FileSystemHandles); + SafeFreePool (FileSystemHandles); } // @@ -1035,7 +1058,7 @@ BdsLibEnumerateAllBootOption ( } if (NumberSimpleNetworkHandles != 0) { - gBS->FreePool (SimpleNetworkHandles); + SafeFreePool (SimpleNetworkHandles); } // @@ -1089,7 +1112,7 @@ BdsLibEnumerateAllBootOption ( } if (FvHandleCount != 0) { - gBS->FreePool (FvHandleBuffer); + SafeFreePool (FvHandleBuffer); } // // Make sure every boot only have one time @@ -1101,7 +1124,6 @@ BdsLibEnumerateAllBootOption ( return EFI_SUCCESS; } - /** Build the boot option with the handle parsed in. @@ -1156,12 +1178,7 @@ BdsLibBuildOptionFromShell ( // Build the shell device path // EfiInitializeFwVolDevicepathNode (&ShellNode, &gEfiShellFileGuid); - // - //ShellNode.Header.Type = MEDIA_DEVICE_PATH; - //ShellNode.Header.SubType = MEDIA_FV_FILEPATH_DP; - //SetDevicePathNodeLength (&ShellNode.Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH)); - //CopyMem (&ShellNode.NameGuid, &gEfiShellFileGuid, sizeof (EFI_GUID)); - // + DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &ShellNode); // @@ -1171,7 +1188,6 @@ BdsLibBuildOptionFromShell ( } - /** Boot from the EFI1.1 spec defined "BootNext" variable @@ -1225,8 +1241,6 @@ BdsLibBootNext ( } - - /** Return the bootable media handle. First, check the device is connected @@ -1264,6 +1278,7 @@ BdsLibGetBootableHandle ( EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; UpdatedDevicePath = DevicePath; + // // Check whether the device is connected // @@ -1278,7 +1293,7 @@ BdsLibGetBootableHandle ( // 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); + Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &UpdatedDevicePath, &Handle); gBS->ConnectController (Handle, NULL, NULL, TRUE); } } else { @@ -1302,7 +1317,7 @@ BdsLibGetBootableHandle ( BlockIo->Media->BlockSize, Buffer ); - gBS->FreePool (Buffer); + SafeFreePool(Buffer); } } @@ -1361,7 +1376,7 @@ BdsLibGetBootableHandle ( Hdr.Union = &HdrData; Status = BdsLibGetImageHeader ( SimpleFileSystemHandles[Index], - DEFAULT_REMOVABLE_FILE_NAME, + (CHAR16*)PcdGetPtr(PcdDefaultBootFileName), &DosHeader, Hdr ); @@ -1374,19 +1389,13 @@ BdsLibGetBootableHandle ( } } - if (DupDevicePath != NULL) { - SafeFreePool(DupDevicePath); - } - if (SimpleFileSystemHandles !=NULL ) { - gBS->FreePool (SimpleFileSystemHandles); - } + SafeFreePool(DupDevicePath); + + SafeFreePool(SimpleFileSystemHandles); return ReturnHandle; } - - - /** Check to see if the network cable is plugged in. If the DevicePath is not connected it will be connected. @@ -1458,8 +1467,6 @@ BdsLibNetworkBootWithMediaPresent ( return MediaPresent; } - - /** For a bootable Device path, return its boot type. @@ -1554,16 +1561,15 @@ BdsGetBootTypeFromDevicePath ( return BDS_EFI_UNSUPPORT; } - /** Check whether the Device path in a boot option point to a valide 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. + @param DevPath the Device path in a boot option + @param CheckMedia if true, check the device is ready to boot now. - @return TRUE -- the Device path is valide - @return FALSE -- the Device path is invalide . + @retval TRUE the Device path is valide + @retval FALSE the Device path is invalide . **/ BOOLEAN @@ -1581,6 +1587,7 @@ BdsLibIsValidEFIBootOptDevicePath ( 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 @@ -1603,6 +1610,7 @@ BdsLibIsValidEFIBootOptDevicePath ( &Handle ); } + if (!EFI_ERROR (Status)) { if (CheckMedia) { // @@ -1642,7 +1650,7 @@ BdsLibIsValidEFIBootOptDevicePath ( return TRUE; } else { if (Status == EFI_SUCCESS) { - gBS->FreePool (TempDevicePath); + SafeFreePool (TempDevicePath); } return FALSE; } @@ -1666,6 +1674,7 @@ BdsLibIsValidEFIBootOptDevicePath ( Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDevicePath, &Handle); } } + if (!EFI_ERROR (Status)) { Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo); if (!EFI_ERROR (Status)) { @@ -1727,7 +1736,7 @@ EFI_STATUS EFIAPI BdsLibUpdateFvFileDevicePath ( IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePath, - IN EFI_GUID *FileGuid + IN EFI_GUID *FileGuid ) { EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; @@ -1754,6 +1763,7 @@ BdsLibUpdateFvFileDevicePath ( if (FileGuid == NULL) { return EFI_INVALID_PARAMETER; } + // // Check whether the device path point to the default the input Fv file // @@ -1885,9 +1895,8 @@ BdsLibUpdateFvFileDevicePath ( FoundFvHandle = FvHandleBuffer[Index]; break; } - if (FvHandleBuffer !=NULL ) { - FreePool (FvHandleBuffer); - } + + SafeFreePool (FvHandleBuffer); } if (FindFvFile) { diff --git a/MdeModulePkg/Library/GenericBdsLib/BdsConnect.c b/MdeModulePkg/Library/GenericBdsLib/BdsConnect.c index 07d5c38320..5e7d13fb82 100644 --- a/MdeModulePkg/Library/GenericBdsLib/BdsConnect.c +++ b/MdeModulePkg/Library/GenericBdsLib/BdsConnect.c @@ -52,10 +52,6 @@ BdsLibConnectAll ( have. After this we should get all the device work and console avariable if the system have console device. - None - - @return None - **/ VOID BdsLibGenericConnectAll ( @@ -180,7 +176,7 @@ BdsLibConnectDevicePath ( } while (DevicePath != NULL); if (CopyOfDevicePath != NULL) { - gBS->FreePool (CopyOfDevicePath); + SafeFreePool (CopyOfDevicePath); } // // All handle with DevicePath exists in the handle database @@ -224,7 +220,7 @@ BdsLibConnectAllEfi ( Status = gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE); } - gBS->FreePool (HandleBuffer); + SafeFreePool (HandleBuffer); return EFI_SUCCESS; } @@ -267,7 +263,7 @@ BdsLibDisconnectAllEfi ( Status = gBS->DisconnectController (HandleBuffer[Index], NULL, NULL); } - gBS->FreePool (HandleBuffer); + SafeFreePool (HandleBuffer); return EFI_SUCCESS; } diff --git a/MdeModulePkg/Library/GenericBdsLib/BdsConsole.c b/MdeModulePkg/Library/GenericBdsLib/BdsConsole.c index 9f77553ec2..dacc9c22d1 100644 --- a/MdeModulePkg/Library/GenericBdsLib/BdsConsole.c +++ b/MdeModulePkg/Library/GenericBdsLib/BdsConsole.c @@ -40,7 +40,7 @@ IsNvNeed ( Ptr++; } - if ((*(Ptr-3) == 'D') && (*(Ptr-2) == 'e') && (*(Ptr-1) == 'v')) { + if ((*(Ptr - 3) == 'D') && (*(Ptr - 2) == 'e') && (*(Ptr - 1) == 'v')) { return FALSE; } else { return TRUE; @@ -261,7 +261,7 @@ BdsLibConnectConsoleVariable ( SafeFreePool(Instance); } while (CopyOfDevicePath != NULL); - gBS->FreePool (StartDevicePath); + SafeFreePool (StartDevicePath); if (!DeviceExist) { return EFI_NOT_FOUND; @@ -340,7 +340,6 @@ BdsLibConnectAllConsoles ( } - /** This function will connect console device base on the console device variable ConIn, ConOut and ErrOut. diff --git a/MdeModulePkg/Library/GenericBdsLib/BdsMisc.c b/MdeModulePkg/Library/GenericBdsLib/BdsMisc.c index c96aa23cab..56b9f8537e 100644 --- a/MdeModulePkg/Library/GenericBdsLib/BdsMisc.c +++ b/MdeModulePkg/Library/GenericBdsLib/BdsMisc.c @@ -18,7 +18,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #define MAX_STRING_LEN 200 BOOLEAN mFeaturerSwitch = TRUE; -BOOLEAN mResetRequired = FALSE; +BOOLEAN mResetRequired = FALSE; extern UINT16 gPlatformBootTimeOutDefault; @@ -69,7 +69,6 @@ BdsLibGetTimeout ( return Timeout; } - /** The function will go through the driver optoin link list, load and start every driver the driver optoin device path point to. @@ -99,6 +98,7 @@ BdsLibLoadDrivers ( // 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. @@ -106,6 +106,7 @@ BdsLibLoadDrivers ( 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 @@ -114,6 +115,7 @@ BdsLibLoadDrivers ( if (IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_FORCE_RECONNECT)) { ReconnectAll = TRUE; } + // // Make sure the driver path is connected. // @@ -162,6 +164,7 @@ BdsLibLoadDrivers ( gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL); } } + // // Process the LOAD_OPTION_FORCE_RECONNECT driver option // @@ -172,7 +175,6 @@ BdsLibLoadDrivers ( } - /** Get the Option Number that does not used. Try to locate the specific option variable one by one untile find a free number. @@ -187,7 +189,6 @@ BdsLibGetFreeOptionNumber ( IN CHAR16 *VariableName ) { - UINT16 Number; UINTN Index; CHAR16 StrTemp[10]; UINT16 *OptionBuffer; @@ -207,18 +208,17 @@ BdsLibGetFreeOptionNumber ( // try if the option number is used // OptionBuffer = BdsLibGetVariableAndSize ( - StrTemp, - &gEfiGlobalVariableGuid, - &OptionSize - ); + StrTemp, + &gEfiGlobalVariableGuid, + &OptionSize + ); if (OptionBuffer == NULL) { break; } - Index++; - } while (1); + Index ++; + } while (TRUE); - Number = (UINT16) Index; - return Number; + return ((UINT16) Index); } @@ -272,6 +272,7 @@ BdsLibRegisterNewOption ( Description = NULL; OptionOrderPtr = NULL; UpdateDescription = FALSE; + Status = EFI_SUCCESS; ZeroMem (OptionName, sizeof (OptionName)); TempOptionSize = 0; @@ -300,11 +301,11 @@ BdsLibRegisterNewOption ( if (OptionPtr == NULL) { continue; } - TempPtr = OptionPtr; - TempPtr += sizeof (UINT32) + sizeof (UINT16); - Description = (CHAR16 *) TempPtr; - TempPtr += StrSize ((CHAR16 *) TempPtr); - OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr; + 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 @@ -314,32 +315,32 @@ BdsLibRegisterNewOption ( // // Got the option, so just return // - gBS->FreePool (OptionPtr); - gBS->FreePool (TempOptionPtr); + SafeFreePool (OptionPtr); + SafeFreePool (TempOptionPtr); return EFI_SUCCESS; } else { // // Option description changed, need update. // UpdateDescription = TRUE; - gBS->FreePool (OptionPtr); + SafeFreePool (OptionPtr); break; } } - gBS->FreePool (OptionPtr); + SafeFreePool (OptionPtr); } OptionSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (String); - OptionSize += GetDevicePathSize (DevicePath); + OptionSize += GetDevicePathSize (DevicePath); OptionPtr = AllocateZeroPool (OptionSize); TempPtr = OptionPtr; *(UINT32 *) TempPtr = LOAD_OPTION_ACTIVE; - TempPtr += sizeof (UINT32); + TempPtr += sizeof (UINT32); *(UINT16 *) TempPtr = (UINT16) GetDevicePathSize (DevicePath); - TempPtr += sizeof (UINT16); + TempPtr += sizeof (UINT16); CopyMem (TempPtr, String, StrSize (String)); - TempPtr += StrSize (String); + TempPtr += StrSize (String); CopyMem (TempPtr, DevicePath, GetDevicePathSize (DevicePath)); if (UpdateDescription) { @@ -371,12 +372,12 @@ BdsLibRegisterNewOption ( // Return if only need to update a changed description or fail to set option. // if (EFI_ERROR (Status) || UpdateDescription) { - gBS->FreePool (OptionPtr); - gBS->FreePool (TempOptionPtr); + SafeFreePool (OptionPtr); + SafeFreePool (TempOptionPtr); return Status; } - gBS->FreePool (OptionPtr); + SafeFreePool (OptionPtr); // // Update the option order variable @@ -394,11 +395,8 @@ BdsLibRegisterNewOption ( sizeof (UINT16), &BootOrderEntry ); - if (EFI_ERROR (Status)) { - gBS->FreePool (TempOptionPtr); - return Status; - } - return EFI_SUCCESS; + SafeFreePool (TempOptionPtr); + return Status; } // @@ -417,16 +415,10 @@ BdsLibRegisterNewOption ( OrderItemNum * sizeof (UINT16), OptionOrderPtr ); - if (EFI_ERROR (Status)) { - gBS->FreePool (TempOptionPtr); - gBS->FreePool (OptionOrderPtr); - return Status; - } + SafeFreePool (TempOptionPtr); + SafeFreePool (OptionOrderPtr); - gBS->FreePool (TempOptionPtr); - gBS->FreePool (OptionOrderPtr); - - return EFI_SUCCESS; + return Status; } @@ -479,15 +471,15 @@ BdsLibVariableToOption ( // // Get the option attribute // - TempPtr = Variable; - Attribute = *(UINT32 *) Variable; - TempPtr += sizeof (UINT32); + TempPtr = Variable; + Attribute = *(UINT32 *) Variable; + TempPtr += sizeof (UINT32); // // Get the option's device path size // - FilePathSize = *(UINT16 *) TempPtr; - TempPtr += sizeof (UINT16); + FilePathSize = *(UINT16 *) TempPtr; + TempPtr += sizeof (UINT16); // // Get the option's description string @@ -497,13 +489,13 @@ BdsLibVariableToOption ( // // Get the option's description string size // - TempPtr += StrSize ((CHAR16 *) TempPtr); + TempPtr += StrSize ((CHAR16 *) TempPtr); // // Get the option's device path // - DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr; - TempPtr += FilePathSize; + DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr; + TempPtr += FilePathSize; LoadOptions = TempPtr; LoadOptionsSize = (UINT32) (VariableSize - (UINTN) (TempPtr - Variable)); @@ -544,17 +536,16 @@ BdsLibVariableToOption ( // if ((Option->Attribute & LOAD_OPTION_ACTIVE) == LOAD_OPTION_ACTIVE) { InsertTailList (BdsCommonOptionList, &Option->Link); - gBS->FreePool (Variable); + SafeFreePool (Variable); return Option; } - gBS->FreePool (Variable); - gBS->FreePool (Option); + SafeFreePool (Variable); + SafeFreePool (Option); return NULL; } - /** Process BootOrder, or DriverOrder variables, by calling BdsLibVariableToOption () for each UINT16 in the variables. @@ -611,12 +602,11 @@ BdsLibBuildOptionFromVar ( } - gBS->FreePool (OptionOrder); + SafeFreePool (OptionOrder); return EFI_SUCCESS; } - /** Get boot mode by looking up configuration table and parsing HOB list @@ -636,7 +626,6 @@ BdsLibGetBootMode ( 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. @@ -690,7 +679,6 @@ BdsLibGetVariableAndSize ( return Buffer; } - /** Delete the instance in Multi which matches partly with Single instance @@ -749,7 +737,6 @@ BdsLibDelPartMatchInstance ( return NewDevicePath; } - /** Function compares a device path data structure to that of all the nodes of a second device path instance. @@ -790,18 +777,17 @@ BdsLibMatchDevicePaths ( // return success // if (CompareMem (Single, DevicePathInst, Size) == 0) { - gBS->FreePool (DevicePathInst); + SafeFreePool (DevicePathInst); return TRUE; } - gBS->FreePool (DevicePathInst); + SafeFreePool (DevicePathInst); DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size); } return FALSE; } - /** This function prints a series of strings. @@ -977,8 +963,8 @@ SetupResetReminder ( IfrLibCreatePopUp (2, &Key, StringBuffer1, StringBuffer2); } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN)); - gBS->FreePool (StringBuffer1); - gBS->FreePool (StringBuffer2); + SafeFreePool (StringBuffer1); + SafeFreePool (StringBuffer2); // // If the user hits the YES Response key, reset // @@ -990,7 +976,6 @@ SetupResetReminder ( } } - /** Get the headers (dos, image, optional header) from an image. @@ -1070,11 +1055,11 @@ BdsLibGetImageHeader ( if (Status != EFI_BUFFER_TOO_SMALL) { goto Done; } - gBS->FreePool (Info); + SafeFreePool (Info); } while (TRUE); FileSize = Info->FileSize; - gBS->FreePool (Info); + SafeFreePool (Info); // // Read dos header @@ -1139,8 +1124,6 @@ BdsLibGetImageHeader ( @param Event The event that triggered this notification function. @param Context Pointer to the notification functions context. - EDES_TODO: Incomplete Descriptions None. - **/ VOID EFIAPI @@ -1244,7 +1227,6 @@ BdsSetMemoryTypeInformationVariable ( 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. diff --git a/MdeModulePkg/Library/GenericBdsLib/DevicePath.c b/MdeModulePkg/Library/GenericBdsLib/DevicePath.c index fc6d420d5c..7435d544b6 100644 --- a/MdeModulePkg/Library/GenericBdsLib/DevicePath.c +++ b/MdeModulePkg/Library/GenericBdsLib/DevicePath.c @@ -15,17 +15,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "InternalBdsLib.h" - -EFI_GUID mEfiDevicePathMessagingUartFlowControlGuid = DEVICE_PATH_MESSAGING_UART_FLOW_CONTROL; - -EFI_GUID mEfiDevicePathMessagingSASGuid = DEVICE_PATH_MESSAGING_SAS; - - /** Adjusts the size of a previously allocated buffer. - @param OldPool A pointer to the buffer whose size is being adjusted. @param OldSize The size of the current buffer. @param NewSize The size of the new buffer. @@ -52,13 +45,12 @@ ReallocatePool ( CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize); } - gBS->FreePool (OldPool); + SafeFreePool (OldPool); } return NewPool; } - /** Concatenates a formatted unicode string to allocated pool. The caller must free the resulting buffer. @@ -116,7 +108,7 @@ CatPrint ( Str->len = StringSize - sizeof (UINT16); } - gBS->FreePool (AppendStr); + SafeFreePool (AppendStr); return Str->str; } @@ -314,22 +306,6 @@ DevPathVendor ( switch (DevicePathType (&Vendor->Header)) { case HARDWARE_DEVICE_PATH: Type = L"Hw"; -// bugbug: nt 32 specific definition -#if 0 - // - // If the device is a winntbus device, we will give it a readable device name. - // - if (CompareGuid (&Vendor->Guid, &mEfiWinNtThunkProtocolGuid)) { - CatPrint (Str, L"%s", L"WinNtBus"); - return ; - } else if (CompareGuid (&Vendor->Guid, &mEfiWinNtGopGuid)) { - CatPrint (Str, L"%s", L"GOP"); - return ; - } else if (CompareGuid (&Vendor->Guid, &mEfiWinNtSerialPortGuid)) { - CatPrint (Str, L"%s", L"Serial"); - return ; - } -#endif break; case MESSAGING_DEVICE_PATH: @@ -346,7 +322,7 @@ DevPathVendor ( } else if (CompareGuid (&Vendor->Guid, &gEfiVTUTF8Guid)) { CatPrint (Str, L"VenUft8()"); return ; - } else if (CompareGuid (&Vendor->Guid, &mEfiDevicePathMessagingUartFlowControlGuid)) { + } else if (CompareGuid (&Vendor->Guid, &gEfiUartDevicePathGuid )) { FlowControlMap = (((UART_FLOW_CONTROL_DEVICE_PATH *) Vendor)->FlowControlMap); switch (FlowControlMap & 0x00000003) { case 0: @@ -367,7 +343,7 @@ DevPathVendor ( return ; - } else if (CompareGuid (&Vendor->Guid, &mEfiDevicePathMessagingSASGuid)) { + } else if (CompareGuid (&Vendor->Guid, &gEfiSasDevicePathGuid)) { CatPrint ( Str, L"SAS(%lx,%lx,%x,", @@ -424,7 +400,6 @@ DevPathVendor ( CatPrint (Str, L")"); } - /** Convert Device Path to a Unicode string for printing. @@ -468,6 +443,7 @@ DevPathExtendedAcpi ( ) { ACPI_EXTENDED_HID_DEVICE_PATH *ExtendedAcpi; + // // Index for HID, UID and CID strings, 0 for non-exist // @@ -1550,7 +1526,7 @@ DevicePathToStr ( // // Shrink pool used for string allocation // - gBS->FreePool (DevPath); + SafeFreePool (DevPath); Done: NewSize = (Str.len + 1) * sizeof (CHAR16); @@ -1560,7 +1536,6 @@ Done: return Str.str; } - /** Function creates a device path data structure that identically matches the device path passed in. diff --git a/MdeModulePkg/Library/GenericBdsLib/Ebc/BmMachine.h b/MdeModulePkg/Library/GenericBdsLib/Ebc/BmMachine.h deleted file mode 100644 index c0469d098b..0000000000 --- a/MdeModulePkg/Library/GenericBdsLib/Ebc/BmMachine.h +++ /dev/null @@ -1,23 +0,0 @@ -/** @file - Boot Manager Machine type - -Copyright (c) 2007 - 2008, Intel Corporation.
-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 _BM_MACHINE_H_ -#define _BM_MACHINE_H_ - -// -// NOTE: This is not defined in UEFI spec. -// -#define DEFAULT_REMOVABLE_FILE_NAME L"\\EFI\\BOOT\\BOOTEBC.EFI" - -#endif diff --git a/MdeModulePkg/Library/GenericBdsLib/GenericBdsLib.inf b/MdeModulePkg/Library/GenericBdsLib/GenericBdsLib.inf index 92231fef6f..5b7f753ed9 100644 --- a/MdeModulePkg/Library/GenericBdsLib/GenericBdsLib.inf +++ b/MdeModulePkg/Library/GenericBdsLib/GenericBdsLib.inf @@ -39,19 +39,8 @@ BdsBoot.c InternalBdsLib.h -[Sources.Ia32] - Ia32/BmMachine.h - -[Sources.X64] - x64/BmMachine.h - [Sources.IPF] Ipf/ShadowRom.c - Ipf/BmMachine.h - -[Sources.EBC] - Ebc/BmMachine.h - [Packages] MdePkg/MdePkg.dec @@ -92,8 +81,9 @@ gEfiFileInfoGuid # ALWAYS_CONSUMED gEfiPcAnsiGuid # ALWAYS_CONSUMED gEfiGenericPlatformVariableGuid # ALWAYS_CONSUMED - - + gEfiUartDevicePathGuid # ALWAYS_CONSUMED + gEfiSasDevicePathGuid # ALWAYS_CONSUMED + [Protocols] gEfiSimpleFileSystemProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiSimpleTextOutProtocolGuid # PROTOCOL ALWAYS_CONSUMED @@ -113,3 +103,4 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformBootTimeOutDefault + gEfiMdeModulePkgTokenSpaceGuid.PcdDefaultBootFileName \ No newline at end of file diff --git a/MdeModulePkg/Library/GenericBdsLib/Ia32/BmMachine.h b/MdeModulePkg/Library/GenericBdsLib/Ia32/BmMachine.h deleted file mode 100644 index 057717e00e..0000000000 --- a/MdeModulePkg/Library/GenericBdsLib/Ia32/BmMachine.h +++ /dev/null @@ -1,20 +0,0 @@ -/** @file - Boot Manager Machine type - -Copyright (c) 2004 - 2008, Intel Corporation.
-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 _BM_MACHINE_H_ -#define _BM_MACHINE_H_ - -#define DEFAULT_REMOVABLE_FILE_NAME L"\\EFI\\BOOT\\BOOTIA32.EFI" - -#endif diff --git a/MdeModulePkg/Library/GenericBdsLib/InternalBdsLib.h b/MdeModulePkg/Library/GenericBdsLib/InternalBdsLib.h index 0ee38eee97..f8ff4c27be 100644 --- a/MdeModulePkg/Library/GenericBdsLib/InternalBdsLib.h +++ b/MdeModulePkg/Library/GenericBdsLib/InternalBdsLib.h @@ -62,8 +62,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include -#include "BmMachine.h" - #define PERFORMANCE_SIGNATURE EFI_SIGNATURE_32 ('P', 'e', 'r', 'f') #define PERF_TOKEN_SIZE 28 #define PERF_TOKEN_LENGTH (PERF_TOKEN_SIZE - 1) diff --git a/MdeModulePkg/Library/GenericBdsLib/Ipf/BmMachine.h b/MdeModulePkg/Library/GenericBdsLib/Ipf/BmMachine.h deleted file mode 100644 index 06ae3dc5c0..0000000000 --- a/MdeModulePkg/Library/GenericBdsLib/Ipf/BmMachine.h +++ /dev/null @@ -1,20 +0,0 @@ -/** @file - Boot Manager Machine type - -Copyright (c) 2004 - 2008, Intel Corporation.
-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 _BM_MACHINE_H_ -#define _BM_MACHINE_H_ - -#define DEFAULT_REMOVABLE_FILE_NAME L"\\EFI\\BOOT\\BOOTIA64.EFI" - -#endif diff --git a/MdeModulePkg/Library/GenericBdsLib/Performance.c b/MdeModulePkg/Library/GenericBdsLib/Performance.c index 3b58351495..e88b50fa6a 100644 --- a/MdeModulePkg/Library/GenericBdsLib/Performance.c +++ b/MdeModulePkg/Library/GenericBdsLib/Performance.c @@ -221,6 +221,7 @@ WriteBootToOsPerformanceData ( gBS->FreePages (AcpiLowMemoryBase, 1); return ; } + // // Get DXE drivers performance // @@ -295,7 +296,7 @@ Done: mPerfHeader.Signiture = PERFORMANCE_SIGNATURE; // - // Put performance data to memory + // Put performance data to ACPI memory // CopyMem ( (UINTN *) (UINTN) AcpiLowMemoryBase, diff --git a/MdeModulePkg/Library/GenericBdsLib/x64/BmMachine.h b/MdeModulePkg/Library/GenericBdsLib/x64/BmMachine.h deleted file mode 100644 index 5e218df8ac..0000000000 --- a/MdeModulePkg/Library/GenericBdsLib/x64/BmMachine.h +++ /dev/null @@ -1,20 +0,0 @@ -/** @file - Boot Manager Machine type - -Copyright (c) 2005 - 2008, Intel Corporation.
-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 _BM_MACHINE_H_ -#define _BM_MACHINE_H_ - -#define DEFAULT_REMOVABLE_FILE_NAME L"\\EFI\\BOOT\\BOOTX64.EFI" - -#endif diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index b4cf2cf83c..afacf2874c 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -161,6 +161,18 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformBootTimeOutDefault|10|UINT16|0x40000001 gEfiMdeModulePkgTokenSpaceGuid.PcdHardwareErrorRecordLevel|1|UINT16|0x40000002 +[PcdsFixedAtBuild.IA32] + gEfiMdeModulePkgTokenSpaceGuid.PcdDefaultBootFileName|L"\\EFI\\BOOT\\BOOTIA32.EFI"|VOID*|0x40000003 + +[PcdsFixedAtBuild.X64] + gEfiMdeModulePkgTokenSpaceGuid.PcdDefaultBootFileName|L"\\EFI\\BOOT\\BOOTX64.EFI"|VOID*|0x40000003 + +[PcdsFixedAtBuild.IPF] + gEfiMdeModulePkgTokenSpaceGuid.PcdDefaultBootFileName|L"\\EFI\\BOOT\\BOOTIA64.EFI"|VOID*|0x40000003 + +[PcdsFixedAtBuild.EBC] + gEfiMdeModulePkgTokenSpaceGuid.PcdDefaultBootFileName|L"\\EFI\\BOOT\\BOOTEBC.EFI"|VOID*|0x40000003 + [PcdsDynamic.common] gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0|UINT32|0x30000001 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x0|UINT32|0x30000002 -- 2.39.2