X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=IntelFrameworkModulePkg%2FLibrary%2FGenericBdsLib%2FBdsBoot.c;h=de69a04b04be9b1bda379f5c33b5f220e0b93a53;hp=c04c586f50d7ad2bc8e16e832754b3f6642373ba;hb=f3fc9d8dc987f9b78aeefd5800833c4c5bb8acf0;hpb=cb38c322f037a9a5d2751a4c7e351b0ee7302e96 diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c index c04c586f50..de69a04b04 100644 --- a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c +++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c @@ -1,7 +1,7 @@ /** @file BDS Lib functions which relate with create or process the boot option. -Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2014, 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 @@ -40,7 +40,7 @@ GenericBdsLibConstructor ( gBdsLibStringPackHandle = HiiAddPackages ( &gBdsLibStringPackageGuid, - &ImageHandle, + ImageHandle, GenericBdsLibStrings, NULL ); @@ -82,6 +82,10 @@ BdsDeleteBootOption ( 0, NULL ); + // + // Deleting variable with existing variable implementation shouldn't fail. + // + ASSERT_EFI_ERROR (Status); // // adjust boot order array @@ -517,23 +521,23 @@ BdsDeleteAllInvalidLegacyBootOptions ( return Status; } - LegacyBios->GetBbsInfo ( - LegacyBios, - &HddCount, - &LocalHddInfo, - &BbsCount, - &LocalBbsTable - ); - BootOrder = BdsLibGetVariableAndSize ( L"BootOrder", &gEfiGlobalVariableGuid, &BootOrderSize ); if (BootOrder == NULL) { - BootOrderSize = 0; + return EFI_NOT_FOUND; } + LegacyBios->GetBbsInfo ( + LegacyBios, + &HddCount, + &LocalHddInfo, + &BbsCount, + &LocalBbsTable + ); + Index = 0; while (Index < BootOrderSize / sizeof (UINT16)) { UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]); @@ -626,9 +630,11 @@ BdsDeleteAllInvalidLegacyBootOptions ( BootOrderSize, BootOrder ); - if (BootOrder != NULL) { - FreePool (BootOrder); - } + // + // Shrinking variable with existing variable implementation shouldn't fail. + // + ASSERT_EFI_ERROR (Status); + FreePool (BootOrder); return Status; } @@ -857,11 +863,10 @@ BdsAddNonExistingLegacyBootOptions ( &BootOrder, &BootOrderSize ); - if (EFI_ERROR (Status)) { - break; + if (!EFI_ERROR (Status)) { + BbsIndex = Index; + OptionNumber = BootOrder[BootOrderSize / sizeof (UINT16) - 1]; } - BbsIndex = Index; - OptionNumber = BootOrder[BootOrderSize / sizeof (UINT16) - 1]; } ASSERT (BbsIndex == Index); @@ -2229,10 +2234,6 @@ BdsLibBootViaBootOption ( LIST_ENTRY TempBootLists; EFI_BOOT_LOGO_PROTOCOL *BootLogo; - PERF_CODE ( - AllocateMemoryForPerformanceData (); - ); - *ExitDataSize = 0; *ExitData = NULL; @@ -2269,7 +2270,7 @@ BdsLibBootViaBootOption ( // In this case, "BootCurrent" is not created. // Only create the BootCurrent variable when it points to a valid Boot#### variable. // - gRT->SetVariable ( + SetVariableAndReportStatusCodeOnError ( L"BootCurrent", &gEfiGlobalVariableGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, @@ -2467,13 +2468,14 @@ Done: // // Clear Boot Current + // Deleting variable with current implementation shouldn't fail. // gRT->SetVariable ( L"BootCurrent", &gEfiGlobalVariableGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, 0, - &Option->BootCurrent + NULL ); return Status; @@ -2522,11 +2524,28 @@ BdsExpandPartitionPartialDevicePathToFull ( // If exist, search the front path which point to partition node in the variable instants. // If fail to find or HD_BOOT_DEVICE_PATH_VARIABLE_NAME not exist, reconnect all and search in all system // - CachedDevicePath = BdsLibGetVariableAndSize ( - HD_BOOT_DEVICE_PATH_VARIABLE_NAME, - &gHdBootDevicePathVariablGuid, - &CachedDevicePathSize - ); + GetVariable2 ( + HD_BOOT_DEVICE_PATH_VARIABLE_NAME, + &gHdBootDevicePathVariablGuid, + (VOID **) &CachedDevicePath, + &CachedDevicePathSize + ); + + // + // Delete the invalid HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable. + // + if ((CachedDevicePath != NULL) && !IsDevicePathValid (CachedDevicePath, CachedDevicePathSize)) { + FreePool (CachedDevicePath); + CachedDevicePath = NULL; + Status = gRT->SetVariable ( + HD_BOOT_DEVICE_PATH_VARIABLE_NAME, + &gHdBootDevicePathVariablGuid, + 0, + 0, + NULL + ); + ASSERT_EFI_ERROR (Status); + } if (CachedDevicePath != NULL) { TempNewDevicePath = CachedDevicePath; @@ -2584,11 +2603,12 @@ BdsExpandPartitionPartialDevicePathToFull ( FreePool (TempNewDevicePath); // // Save the matching Device Path so we don't need to do a connect all next time + // Failure to set the variable only impacts the performance when next time expanding the short-form device path. // Status = gRT->SetVariable ( HD_BOOT_DEVICE_PATH_VARIABLE_NAME, &gHdBootDevicePathVariablGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, GetDevicePathSize (CachedDevicePath), CachedDevicePath ); @@ -2641,17 +2661,16 @@ BdsExpandPartitionPartialDevicePathToFull ( TempNewDevicePath = CachedDevicePath; CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, BlockIoDevicePath); FreePool(TempNewDevicePath); + } - TempNewDevicePath = CachedDevicePath; - CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath); - if (TempNewDevicePath != NULL) { - FreePool(TempNewDevicePath); - } - } else { + if (CachedDevicePath != NULL) { TempNewDevicePath = CachedDevicePath; CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath); FreePool(TempNewDevicePath); + } else { + CachedDevicePath = DuplicateDevicePath (BlockIoDevicePath); } + // // Here limit the device path instance number to 12, which is max number for a system support 3 IDE controller // If the user try to boot many OS in different HDs or partitions, in theory, @@ -2683,11 +2702,12 @@ BdsExpandPartitionPartialDevicePathToFull ( // // Save the matching Device Path so we don't need to do a connect all next time + // Failure to set the variable only impacts the performance when next time expanding the short-form device path. // Status = gRT->SetVariable ( HD_BOOT_DEVICE_PATH_VARIABLE_NAME, &gHdBootDevicePathVariablGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, GetDevicePathSize (CachedDevicePath), CachedDevicePath ); @@ -2892,6 +2912,10 @@ BdsLibDeleteOptionFromHandle ( BootOrderSize, BootOrder ); + // + // Shrinking variable with existing variable implementation shouldn't fail. + // + ASSERT_EFI_ERROR (Status); FreePool (BootOrder); @@ -2990,6 +3014,10 @@ BdsDeleteAllInvalidEfiBootOption ( NULL ); // + // Deleting variable with current variable implementation shouldn't fail. + // + ASSERT_EFI_ERROR (Status); + // // Mark this boot option in boot order as deleted // BootOrder[Index] = 0xffff; @@ -3017,6 +3045,10 @@ BdsDeleteAllInvalidEfiBootOption ( Index2 * sizeof (UINT16), BootOrder ); + // + // Shrinking variable with current variable implementation shouldn't fail. + // + ASSERT_EFI_ERROR (Status); FreePool (BootOrder); @@ -3140,7 +3172,9 @@ BdsLibEnumerateAllBootOption ( AsciiStrSize (PlatLang), PlatLang ); - ASSERT_EFI_ERROR (Status); + // + // Failure to set the variable only impacts the performance next time enumerating the boot options. + // if (LastLang != NULL) { FreePool (LastLang); @@ -3483,6 +3517,7 @@ BdsLibBootNext ( VOID ) { + EFI_STATUS Status; UINT16 *BootNext; UINTN BootNextSize; CHAR16 Buffer[20]; @@ -3507,13 +3542,17 @@ BdsLibBootNext ( // 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 - ); + Status = gRT->SetVariable ( + L"BootNext", + &gEfiGlobalVariableGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + 0, + NULL + ); + // + // Deleting variable with current variable implementation shouldn't fail. + // + ASSERT_EFI_ERROR (Status); // // Start to build the boot option and try to boot