mirror of https://github.com/acidanthera/audk.git
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 <siyuan.fu@intel.com> Reviewed-by: : Ye Ting <ting.ye@intel.com> Reviewed-by: : Ni Ruiyu <ruiyu.ni@intel.com>
This commit is contained in:
parent
f14307489f
commit
50a65824c7
|
@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "HttpBootDxe.h"
|
#include "HttpBootDxe.h"
|
||||||
|
#include <Library/UefiBootManagerLib.h>
|
||||||
|
|
||||||
CHAR16 mHttpBootConfigStorageName[] = L"HTTP_BOOT_CONFIG_IFR_NVDATA";
|
CHAR16 mHttpBootConfigStorageName[] = L"HTTP_BOOT_CONFIG_IFR_NVDATA";
|
||||||
|
|
||||||
|
@ -41,26 +42,13 @@ HttpBootAddBootOption (
|
||||||
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
|
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
|
||||||
UINTN Length;
|
UINTN Length;
|
||||||
CHAR8 AsciiUri[URI_STR_MAX_SIZE];
|
CHAR8 AsciiUri[URI_STR_MAX_SIZE];
|
||||||
CHAR16 *CurrentOrder;
|
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINTN OrderCount;
|
|
||||||
UINTN TargetLocation;
|
|
||||||
BOOLEAN Found;
|
|
||||||
UINT8 *TempByteBuffer;
|
|
||||||
UINT8 *TempByteStart;
|
|
||||||
UINTN DescSize;
|
|
||||||
UINTN FilePathSize;
|
|
||||||
CHAR16 OptionStr[10];
|
|
||||||
UINT16 *NewOrder;
|
|
||||||
UINTN Index;
|
UINTN Index;
|
||||||
|
EFI_BOOT_MANAGER_LOAD_OPTION NewOption;
|
||||||
|
|
||||||
NewOrder = NULL;
|
|
||||||
TempByteStart = NULL;
|
|
||||||
NewDevicePath = NULL;
|
NewDevicePath = NULL;
|
||||||
NewOrder = NULL;
|
|
||||||
Node = NULL;
|
Node = NULL;
|
||||||
TmpDevicePath = NULL;
|
TmpDevicePath = NULL;
|
||||||
CurrentOrder = NULL;
|
|
||||||
|
|
||||||
if (StrLen (Description) == 0) {
|
if (StrLen (Description) == 0) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
|
@ -137,105 +125,29 @@ HttpBootAddBootOption (
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Get current "BootOrder" variable and find a free target.
|
// Add a new load option.
|
||||||
//
|
//
|
||||||
Length = 0;
|
Status = EfiBootManagerInitializeLoadOption (
|
||||||
Status = GetVariable2 (
|
&NewOption,
|
||||||
L"BootOrder",
|
LoadOptionNumberUnassigned,
|
||||||
&gEfiGlobalVariableGuid,
|
LoadOptionTypeBoot,
|
||||||
(VOID **)&CurrentOrder,
|
LOAD_OPTION_ACTIVE,
|
||||||
&Length
|
Description,
|
||||||
);
|
NewDevicePath,
|
||||||
if (EFI_ERROR (Status) && Status != EFI_NOT_FOUND) {
|
NULL,
|
||||||
goto ON_EXIT;
|
0
|
||||||
}
|
|
||||||
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
|
|
||||||
//
|
|
||||||
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
|
|
||||||
);
|
);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
goto ON_EXIT;
|
goto ON_EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
Status = EfiBootManagerAddLoadOptionVariable (&NewOption, (UINTN) -1);
|
||||||
// Insert into the order list and set "BootOrder" variable
|
if (EFI_ERROR (Status)) {
|
||||||
//
|
EfiBootManagerFreeLoadOption (&NewOption);
|
||||||
NewOrder = AllocateZeroPool ((OrderCount + 1) * sizeof (UINT16));
|
|
||||||
if (NewOrder == NULL) {
|
|
||||||
Status = EFI_OUT_OF_RESOURCES;
|
|
||||||
goto ON_EXIT;
|
|
||||||
}
|
}
|
||||||
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:
|
ON_EXIT:
|
||||||
|
|
||||||
if (CurrentOrder != NULL) {
|
|
||||||
FreePool (CurrentOrder);
|
|
||||||
}
|
|
||||||
if (NewOrder != NULL) {
|
|
||||||
FreePool (NewOrder);
|
|
||||||
}
|
|
||||||
if (TempByteStart != NULL) {
|
|
||||||
FreePool (TempByteStart);
|
|
||||||
}
|
|
||||||
if (NewDevicePath != NULL) {
|
if (NewDevicePath != NULL) {
|
||||||
FreePool (NewDevicePath);
|
FreePool (NewDevicePath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,7 @@
|
||||||
HiiLib
|
HiiLib
|
||||||
PrintLib
|
PrintLib
|
||||||
UefiHiiServicesLib
|
UefiHiiServicesLib
|
||||||
|
UefiBootManagerLib
|
||||||
|
|
||||||
[Protocols]
|
[Protocols]
|
||||||
## TO_START
|
## TO_START
|
||||||
|
|
|
@ -39,6 +39,12 @@
|
||||||
UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
|
UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
|
||||||
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
|
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
|
||||||
UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
|
UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
|
||||||
|
UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
|
||||||
|
TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
|
||||||
|
PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
|
||||||
|
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
|
||||||
|
DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
|
||||||
|
DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
|
||||||
|
|
||||||
DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf
|
DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf
|
||||||
NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
|
NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
|
||||||
|
@ -54,6 +60,8 @@
|
||||||
SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
|
SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
|
||||||
|
|
||||||
[LibraryClasses.common.UEFI_DRIVER]
|
[LibraryClasses.common.UEFI_DRIVER]
|
||||||
|
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
|
||||||
|
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
|
||||||
DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
|
DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
|
||||||
|
|
||||||
[LibraryClasses.common.UEFI_APPLICATION]
|
[LibraryClasses.common.UEFI_APPLICATION]
|
||||||
|
|
Loading…
Reference in New Issue