X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FLibrary%2FGenericBdsLib%2FBdsMisc.c;h=5779aec725c66acc9904598d1fedcb88fa4ce62b;hb=8c80d3942e41325fe0f4dc2f5deea2bd9fda8e53;hp=56b9f8537ee0ed0bb0c22d8de0aec61c3e28b30c;hpb=ec8cd35c80fa0b5d9cf249754780f6f3d3809160;p=mirror_edk2.git diff --git a/MdeModulePkg/Library/GenericBdsLib/BdsMisc.c b/MdeModulePkg/Library/GenericBdsLib/BdsMisc.c index 56b9f8537e..5779aec725 100644 --- a/MdeModulePkg/Library/GenericBdsLib/BdsMisc.c +++ b/MdeModulePkg/Library/GenericBdsLib/BdsMisc.c @@ -45,33 +45,22 @@ BdsLibGetTimeout ( // Size = sizeof (UINT16); Status = gRT->GetVariable (L"Timeout", &gEfiGlobalVariableGuid, NULL, &Size, &Timeout); - if (!EFI_ERROR (Status)) { - return 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); } - // - // To make the current EFI Automatic-Test activity possible, just add - // following code to make AutoBoot enabled when this variable is not - // present. - // This code should be removed later. - // - Timeout = PcdGet16 (PcdPlatformBootTimeOutDefault); - // - // Notes: Platform should set default variable if non exists on all error cases!!! - // - Status = gRT->SetVariable ( - L"Timeout", - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, - sizeof (UINT16), - &Timeout - ); return Timeout; } /** - The function will go through the driver optoin link list, load and start - every driver the driver optoin device path point to. + 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 @@ -177,7 +166,7 @@ BdsLibLoadDrivers ( /** Get the Option Number that does not used. - Try to locate the specific option variable one by one untile find a free number. + Try to locate the specific option variable one by one utile find a free number. @param VariableName Indicate if the boot#### or driver#### option @@ -215,7 +204,7 @@ BdsLibGetFreeOptionNumber ( if (OptionBuffer == NULL) { break; } - Index ++; + Index++; } while (TRUE); return ((UINT16) Index); @@ -281,7 +270,7 @@ BdsLibRegisterNewOption ( &gEfiGlobalVariableGuid, &TempOptionSize ); - + ASSERT (TempOptionPtr != NULL); // // Compare with current option variable // @@ -315,25 +304,27 @@ BdsLibRegisterNewOption ( // // Got the option, so just return // - SafeFreePool (OptionPtr); - SafeFreePool (TempOptionPtr); + FreePool (OptionPtr); + FreePool (TempOptionPtr); return EFI_SUCCESS; } else { // // Option description changed, need update. // UpdateDescription = TRUE; - SafeFreePool (OptionPtr); + FreePool (OptionPtr); break; } } - SafeFreePool (OptionPtr); + 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); @@ -372,12 +363,14 @@ BdsLibRegisterNewOption ( // Return if only need to update a changed description or fail to set option. // if (EFI_ERROR (Status) || UpdateDescription) { - SafeFreePool (OptionPtr); - SafeFreePool (TempOptionPtr); + FreePool (OptionPtr); + if (TempOptionPtr != NULL) { + FreePool (TempOptionPtr); + } return Status; } - SafeFreePool (OptionPtr); + FreePool (OptionPtr); // // Update the option order variable @@ -395,7 +388,9 @@ BdsLibRegisterNewOption ( sizeof (UINT16), &BootOrderEntry ); - SafeFreePool (TempOptionPtr); + if (TempOptionPtr != NULL) { + FreePool (TempOptionPtr); + } return Status; } @@ -404,6 +399,8 @@ BdsLibRegisterNewOption ( // OrderItemNum = (TempOptionSize / sizeof (UINT16)) + 1 ; OptionOrderPtr = AllocateZeroPool ( OrderItemNum * sizeof (UINT16)); + ASSERT (OptionOrderPtr!= NULL); + CopyMem (OptionOrderPtr, TempOptionPtr, (OrderItemNum - 1) * sizeof (UINT16)); OptionOrderPtr[Index] = RegisterOptionNumber; @@ -415,8 +412,8 @@ BdsLibRegisterNewOption ( OrderItemNum * sizeof (UINT16), OptionOrderPtr ); - SafeFreePool (TempOptionPtr); - SafeFreePool (OptionOrderPtr); + FreePool (TempOptionPtr); + FreePool (OptionOrderPtr); return Status; } @@ -511,11 +508,16 @@ BdsLibVariableToOption ( 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; @@ -536,12 +538,12 @@ BdsLibVariableToOption ( // if ((Option->Attribute & LOAD_OPTION_ACTIVE) == LOAD_OPTION_ACTIVE) { InsertTailList (BdsCommonOptionList, &Option->Link); - SafeFreePool (Variable); + FreePool (Variable); return Option; } - SafeFreePool (Variable); - SafeFreePool (Option); + FreePool (Variable); + FreePool (Option); return NULL; } @@ -598,11 +600,12 @@ BdsLibBuildOptionFromVar ( } Option = BdsLibVariableToOption (BdsCommonOptionList, OptionName); + ASSERT (Option != NULL); Option->BootCurrent = OptionOrder[Index]; } - SafeFreePool (OptionOrder); + FreePool (OptionOrder); return EFI_SUCCESS; } @@ -634,8 +637,8 @@ BdsLibGetBootMode ( @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. - @return Caller is responsible freeing the buffer. + @return Dynamically allocated memory that contains a copy of the EFI variable + Caller is responsible freeing the buffer. @retval NULL Variable was not read **/ @@ -727,9 +730,11 @@ BdsLibDelPartMatchInstance ( // TempNewDevicePath = NewDevicePath; NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance); - SafeFreePool(TempNewDevicePath); + if (TempNewDevicePath != NULL) { + FreePool(TempNewDevicePath); + } } - SafeFreePool(Instance); + FreePool(Instance); Instance = GetNextDevicePathInstance (&Multi, &InstanceSize); InstanceSize -= END_DEVICE_PATH_LENGTH; } @@ -746,8 +751,8 @@ BdsLibDelPartMatchInstance ( @param Single A pointer to a single-instance device path data structure. - @retval TRUE If the Single is contained within Multi - @retval FALSE The Single is not match within Multi + @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 @@ -761,7 +766,7 @@ BdsLibMatchDevicePaths ( EFI_DEVICE_PATH_PROTOCOL *DevicePathInst; UINTN Size; - if (Multi != NULL || Single != NULL) { + if (Multi == NULL || Single == NULL) { return FALSE; } @@ -777,11 +782,11 @@ BdsLibMatchDevicePaths ( // return success // if (CompareMem (Single, DevicePathInst, Size) == 0) { - SafeFreePool (DevicePathInst); + FreePool (DevicePathInst); return TRUE; } - SafeFreePool (DevicePathInst); + FreePool (DevicePathInst); DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size); } @@ -828,7 +833,8 @@ BdsLibOutputStrings ( break; } } - + + VA_END(Args); return Status; } @@ -963,8 +969,8 @@ SetupResetReminder ( IfrLibCreatePopUp (2, &Key, StringBuffer1, StringBuffer2); } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN)); - SafeFreePool (StringBuffer1); - SafeFreePool (StringBuffer2); + FreePool (StringBuffer1); + FreePool (StringBuffer2); // // If the user hits the YES Response key, reset // @@ -977,12 +983,12 @@ SetupResetReminder ( } /** - Get the headers (dos, image, optional header) from an image. + 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 Pointer to optional 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. @@ -1025,6 +1031,7 @@ BdsLibGetImageHeader ( &Root ); if (EFI_ERROR (Status)) { + Root = NULL; goto Done; } @@ -1053,13 +1060,14 @@ BdsLibGetImageHeader ( break; } if (Status != EFI_BUFFER_TOO_SMALL) { + FreePool (Info); goto Done; } - SafeFreePool (Info); + FreePool (Info); } while (TRUE); FileSize = Info->FileSize; - SafeFreePool (Info); + FreePool (Info); // // Read dos header @@ -1228,8 +1236,8 @@ BdsSetMemoryTypeInformationVariable ( } /** - 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. + 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