]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg: Use UefiBootManagerLib API to create load option.
authorFu Siyuan <siyuan.fu@intel.com>
Wed, 4 May 2016 02:02:41 +0000 (10:02 +0800)
committerFu Siyuan <siyuan.fu@intel.com>
Thu, 5 May 2016 00:45:35 +0000 (08:45 +0800)
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>
NetworkPkg/HttpBootDxe/HttpBootConfig.c
NetworkPkg/HttpBootDxe/HttpBootDxe.inf
NetworkPkg/NetworkPkg.dsc

index 00e4782f567416a5220a1b4d9f452f42984f6eab..2ca38b533329b65057518f4224348c2a5f2bfa7e 100644 (file)
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 #include "HttpBootDxe.h"\r
+#include <Library/UefiBootManagerLib.h>\r
 \r
 CHAR16  mHttpBootConfigStorageName[]     = L"HTTP_BOOT_CONFIG_IFR_NVDATA";\r
 \r
@@ -36,31 +37,18 @@ HttpBootAddBootOption (
   IN   CHAR16                   *Uri\r
   )\r
 {\r
-  EFI_DEV_PATH               *Node;\r
-  EFI_DEVICE_PATH_PROTOCOL   *TmpDevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL   *NewDevicePath;\r
-  UINTN                      Length;\r
-  CHAR8                      AsciiUri[URI_STR_MAX_SIZE];\r
-  CHAR16                     *CurrentOrder;\r
-  EFI_STATUS                 Status;\r
-  UINTN                      OrderCount;\r
-  UINTN                      TargetLocation;\r
-  BOOLEAN                    Found;\r
-  UINT8                      *TempByteBuffer;\r
-  UINT8                      *TempByteStart;\r
-  UINTN                      DescSize;\r
-  UINTN                      FilePathSize;\r
-  CHAR16                     OptionStr[10];\r
-  UINT16                     *NewOrder;\r
-  UINTN                      Index;\r
-\r
-  NewOrder      = NULL;\r
-  TempByteStart = NULL;\r
+  EFI_DEV_PATH                      *Node;\r
+  EFI_DEVICE_PATH_PROTOCOL          *TmpDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL          *NewDevicePath;\r
+  UINTN                             Length;\r
+  CHAR8                             AsciiUri[URI_STR_MAX_SIZE];\r
+  EFI_STATUS                        Status;\r
+  UINTN                             Index;\r
+  EFI_BOOT_MANAGER_LOAD_OPTION      NewOption;\r
+\r
   NewDevicePath = NULL;\r
-  NewOrder      = NULL;\r
   Node          = NULL;\r
   TmpDevicePath = NULL;\r
-  CurrentOrder  = NULL;\r
 \r
   if (StrLen (Description) == 0) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -137,105 +125,29 @@ HttpBootAddBootOption (
   }\r
 \r
   //\r
-  // Get current "BootOrder" variable and find a free target.\r
-  //\r
-  Length = 0;\r
-  Status = GetVariable2 (\r
-             L"BootOrder",\r
-             &gEfiGlobalVariableGuid,\r
-             (VOID **)&CurrentOrder,\r
-             &Length \r
-             );\r
-  if (EFI_ERROR (Status) && Status != EFI_NOT_FOUND) {\r
-    goto ON_EXIT;\r
-  }\r
-  OrderCount = Length / sizeof (UINT16);\r
-  Found = FALSE;\r
-  for (TargetLocation=0; TargetLocation < 0xFFFF; TargetLocation++) {\r
-    Found = TRUE;\r
-    for (Index = 0; Index < OrderCount; Index++) {\r
-      if (CurrentOrder[Index] == TargetLocation) {\r
-        Found = FALSE;\r
-        break;\r
-      }\r
-    }\r
-    if (Found) {\r
-      break;\r
-    }\r
-  }\r
-\r
-  if (TargetLocation == 0xFFFF) {\r
-    DEBUG ((EFI_D_ERROR, "Could not find unused target index.\n"));\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto ON_EXIT;\r
-  } else {\r
-    DEBUG ((EFI_D_INFO, "TargetIndex = %04x.\n", TargetLocation));\r
-  }\r
-  \r
-  //\r
-  // Construct and set the "Boot####" variable\r
+  // Add a new load option.\r
   //\r
-  DescSize = StrSize(Description);\r
-  FilePathSize = GetDevicePathSize (NewDevicePath);\r
-  TempByteBuffer = AllocateZeroPool(sizeof(EFI_LOAD_OPTION) + DescSize + FilePathSize);\r
-  if (TempByteBuffer == NULL) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto ON_EXIT;\r
-  }\r
-\r
-  TempByteStart = TempByteBuffer;\r
-  *((UINT32 *) TempByteBuffer) = LOAD_OPTION_ACTIVE;      // Attributes\r
-  TempByteBuffer += sizeof (UINT32);\r
-\r
-  *((UINT16 *) TempByteBuffer) = (UINT16)FilePathSize;    // FilePathListLength\r
-  TempByteBuffer += sizeof (UINT16);\r
-\r
-  CopyMem (TempByteBuffer, Description, DescSize);\r
-  TempByteBuffer += DescSize;\r
-  CopyMem (TempByteBuffer, NewDevicePath, FilePathSize);\r
-\r
-  UnicodeSPrint (OptionStr, sizeof(OptionStr), L"%s%04x", L"Boot", TargetLocation);\r
-  Status = gRT->SetVariable (\r
-                  OptionStr,\r
-                  &gEfiGlobalVariableGuid,\r
-                  EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-                  sizeof(UINT32) + sizeof(UINT16) + DescSize + FilePathSize,\r
-                  TempByteStart\r
-                  );\r
+  Status = EfiBootManagerInitializeLoadOption (\r
+                 &NewOption,\r
+                 LoadOptionNumberUnassigned,\r
+                 LoadOptionTypeBoot,\r
+                 LOAD_OPTION_ACTIVE,\r
+                 Description,\r
+                 NewDevicePath,\r
+                 NULL,\r
+                 0\r
+                 );\r
   if (EFI_ERROR (Status)) {\r
     goto ON_EXIT;\r
   }\r
 \r
-  //\r
-  // Insert into the order list and set "BootOrder" variable\r
-  //\r
-  NewOrder = AllocateZeroPool ((OrderCount + 1) * sizeof (UINT16));\r
-  if (NewOrder == NULL) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto ON_EXIT;\r
+  Status = EfiBootManagerAddLoadOptionVariable (&NewOption, (UINTN) -1);\r
+  if (EFI_ERROR (Status)) {\r
+    EfiBootManagerFreeLoadOption (&NewOption);\r
   }\r
-  CopyMem(NewOrder, CurrentOrder, OrderCount * sizeof(UINT16));\r
-  NewOrder[OrderCount] = (UINT16) TargetLocation;\r
-  Status = gRT->SetVariable (\r
-                  L"BootOrder",\r
-                  &gEfiGlobalVariableGuid,\r
-                  EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-                  ((OrderCount + 1) * sizeof (UINT16)),\r
-                  NewOrder\r
-                  );\r
-  \r
 \r
 ON_EXIT:\r
 \r
-  if (CurrentOrder != NULL) {\r
-    FreePool (CurrentOrder);\r
-  }\r
-  if (NewOrder != NULL) {\r
-    FreePool (NewOrder);\r
-  }\r
-  if (TempByteStart != NULL) {\r
-    FreePool (TempByteStart);\r
-  }\r
   if (NewDevicePath != NULL) {\r
     FreePool (NewDevicePath);\r
   }\r
index d3df5f7d6e51402a8998286d2399c2a384e5e718..e6ce864264c9207f4ba884ba71fd7bf1ddfd0a8f 100644 (file)
@@ -61,6 +61,7 @@
   HiiLib\r
   PrintLib\r
   UefiHiiServicesLib\r
+  UefiBootManagerLib\r
 \r
 [Protocols]\r
   ## TO_START\r
index 0695dc1096c8e3fa588a846586c0880171868c5b..3c809d5009eda11b7a0da3dd2b373474eaa0648b 100644 (file)
   UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
   UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
   UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf\r
+  UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf\r
+  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf\r
+  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf\r
+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf\r
+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf\r
+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
 \r
   DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf\r
   NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf\r
@@ -54,6 +60,8 @@
   SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf\r
 \r
 [LibraryClasses.common.UEFI_DRIVER]\r
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
+  ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf\r
   DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf\r
 \r
 [LibraryClasses.common.UEFI_APPLICATION]\r