From 50a65824c74ace597145b55fcacc4f0e20fc994a Mon Sep 17 00:00:00 2001 From: Fu Siyuan Date: Wed, 4 May 2016 10:02:41 +0800 Subject: NetworkPkg: Use UefiBootManagerLib API to create load option. This patch updates the HTTP boot driver to use the API in UefiBootManagerLib to create new load option, to avoid duplicate code. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Fu Siyuan Reviewed-by: : Ye Ting Reviewed-by: : Ni Ruiyu --- NetworkPkg/HttpBootDxe/HttpBootConfig.c | 136 ++++++-------------------------- NetworkPkg/HttpBootDxe/HttpBootDxe.inf | 1 + 2 files changed, 25 insertions(+), 112 deletions(-) (limited to 'NetworkPkg/HttpBootDxe') diff --git a/NetworkPkg/HttpBootDxe/HttpBootConfig.c b/NetworkPkg/HttpBootDxe/HttpBootConfig.c index 00e4782f56..2ca38b5333 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootConfig.c +++ b/NetworkPkg/HttpBootDxe/HttpBootConfig.c @@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #include "HttpBootDxe.h" +#include CHAR16 mHttpBootConfigStorageName[] = L"HTTP_BOOT_CONFIG_IFR_NVDATA"; @@ -36,31 +37,18 @@ HttpBootAddBootOption ( IN CHAR16 *Uri ) { - EFI_DEV_PATH *Node; - EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; - EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; - UINTN Length; - CHAR8 AsciiUri[URI_STR_MAX_SIZE]; - CHAR16 *CurrentOrder; - EFI_STATUS Status; - UINTN OrderCount; - UINTN TargetLocation; - BOOLEAN Found; - UINT8 *TempByteBuffer; - UINT8 *TempByteStart; - UINTN DescSize; - UINTN FilePathSize; - CHAR16 OptionStr[10]; - UINT16 *NewOrder; - UINTN Index; - - NewOrder = NULL; - TempByteStart = NULL; + EFI_DEV_PATH *Node; + EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; + EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; + UINTN Length; + CHAR8 AsciiUri[URI_STR_MAX_SIZE]; + EFI_STATUS Status; + UINTN Index; + EFI_BOOT_MANAGER_LOAD_OPTION NewOption; + NewDevicePath = NULL; - NewOrder = NULL; Node = NULL; TmpDevicePath = NULL; - CurrentOrder = NULL; if (StrLen (Description) == 0) { return EFI_INVALID_PARAMETER; @@ -137,105 +125,29 @@ HttpBootAddBootOption ( } // - // Get current "BootOrder" variable and find a free target. - // - Length = 0; - Status = GetVariable2 ( - L"BootOrder", - &gEfiGlobalVariableGuid, - (VOID **)&CurrentOrder, - &Length - ); - if (EFI_ERROR (Status) && Status != EFI_NOT_FOUND) { - goto ON_EXIT; - } - OrderCount = Length / sizeof (UINT16); - Found = FALSE; - for (TargetLocation=0; TargetLocation < 0xFFFF; TargetLocation++) { - Found = TRUE; - for (Index = 0; Index < OrderCount; Index++) { - if (CurrentOrder[Index] == TargetLocation) { - Found = FALSE; - break; - } - } - if (Found) { - break; - } - } - - if (TargetLocation == 0xFFFF) { - DEBUG ((EFI_D_ERROR, "Could not find unused target index.\n")); - Status = EFI_OUT_OF_RESOURCES; - goto ON_EXIT; - } else { - DEBUG ((EFI_D_INFO, "TargetIndex = %04x.\n", TargetLocation)); - } - - // - // Construct and set the "Boot####" variable + // Add a new load option. // - DescSize = StrSize(Description); - FilePathSize = GetDevicePathSize (NewDevicePath); - TempByteBuffer = AllocateZeroPool(sizeof(EFI_LOAD_OPTION) + DescSize + FilePathSize); - if (TempByteBuffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto ON_EXIT; - } - - TempByteStart = TempByteBuffer; - *((UINT32 *) TempByteBuffer) = LOAD_OPTION_ACTIVE; // Attributes - TempByteBuffer += sizeof (UINT32); - - *((UINT16 *) TempByteBuffer) = (UINT16)FilePathSize; // FilePathListLength - TempByteBuffer += sizeof (UINT16); - - CopyMem (TempByteBuffer, Description, DescSize); - TempByteBuffer += DescSize; - CopyMem (TempByteBuffer, NewDevicePath, FilePathSize); - - UnicodeSPrint (OptionStr, sizeof(OptionStr), L"%s%04x", L"Boot", TargetLocation); - Status = gRT->SetVariable ( - OptionStr, - &gEfiGlobalVariableGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - sizeof(UINT32) + sizeof(UINT16) + DescSize + FilePathSize, - TempByteStart - ); + Status = EfiBootManagerInitializeLoadOption ( + &NewOption, + LoadOptionNumberUnassigned, + LoadOptionTypeBoot, + LOAD_OPTION_ACTIVE, + Description, + NewDevicePath, + NULL, + 0 + ); if (EFI_ERROR (Status)) { goto ON_EXIT; } - // - // Insert into the order list and set "BootOrder" variable - // - NewOrder = AllocateZeroPool ((OrderCount + 1) * sizeof (UINT16)); - if (NewOrder == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto ON_EXIT; + Status = EfiBootManagerAddLoadOptionVariable (&NewOption, (UINTN) -1); + if (EFI_ERROR (Status)) { + EfiBootManagerFreeLoadOption (&NewOption); } - CopyMem(NewOrder, CurrentOrder, OrderCount * sizeof(UINT16)); - NewOrder[OrderCount] = (UINT16) TargetLocation; - Status = gRT->SetVariable ( - L"BootOrder", - &gEfiGlobalVariableGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - ((OrderCount + 1) * sizeof (UINT16)), - NewOrder - ); - ON_EXIT: - if (CurrentOrder != NULL) { - FreePool (CurrentOrder); - } - if (NewOrder != NULL) { - FreePool (NewOrder); - } - if (TempByteStart != NULL) { - FreePool (TempByteStart); - } if (NewDevicePath != NULL) { FreePool (NewDevicePath); } diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.inf b/NetworkPkg/HttpBootDxe/HttpBootDxe.inf index d3df5f7d6e..e6ce864264 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootDxe.inf +++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.inf @@ -61,6 +61,7 @@ HiiLib PrintLib UefiHiiServicesLib + UefiBootManagerLib [Protocols] ## TO_START -- cgit v1.2.3