]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Refine the code in BootMaintenanceManagerUiLib
authorDandan Bi <dandan.bi@intel.com>
Tue, 26 Jan 2016 08:07:18 +0000 (16:07 +0800)
committerStar Zeng <star.zeng@intel.com>
Tue, 23 Feb 2016 09:03:21 +0000 (17:03 +0800)
Refine the code in function Var_UpdateDriverOption and Var_UpdateBootOption,
use the existed API(EfiBootManagerInitializeLoadOption and
EfiBootManagerAddLoadOptionVariable) supplied by UefiBootManagerLib
to replace the same logic in the two functions. And remove the useless
code.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManager.h
MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c
MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c

index 24526e1096757ffbc945086856a2376c97a76be2..b482bf28923a546d603efb1ae92a9f9f8f1471d4 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Header file for boot maintenance module.\r
 \r
 /** @file\r
 Header file for boot maintenance module.\r
 \r
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -268,24 +268,15 @@ typedef struct {
 \r
 typedef struct {\r
   BOOLEAN                   IsBootNext;\r
 \r
 typedef struct {\r
   BOOLEAN                   IsBootNext;\r
-  BOOLEAN                   LoadOptionModified;\r
   BOOLEAN                   Deleted;\r
 \r
   BOOLEAN                   IsLegacy;\r
   BOOLEAN                   Deleted;\r
 \r
   BOOLEAN                   IsLegacy;\r
-  BOOLEAN                   IsActive;\r
-  BOOLEAN                   ForceReconnect;\r
-  UINTN                     OptionalDataSize;\r
-\r
-  UINTN                     LoadOptionSize;\r
-  UINT8                     *LoadOption;\r
 \r
   UINT32                    Attributes;\r
   UINT16                    FilePathListLength;\r
   UINT16                    *Description;\r
   EFI_DEVICE_PATH_PROTOCOL  *FilePathList;\r
   UINT8                     *OptionalData;\r
 \r
   UINT32                    Attributes;\r
   UINT16                    FilePathListLength;\r
   UINT16                    *Description;\r
   EFI_DEVICE_PATH_PROTOCOL  *FilePathList;\r
   UINT8                     *OptionalData;\r
-\r
-  UINT16                    BbsIndex;\r
 } BM_LOAD_CONTEXT;\r
 \r
 typedef struct {\r
 } BM_LOAD_CONTEXT;\r
 \r
 typedef struct {\r
index a375d61dd3963bfeba0745d6132e530568a7a2a9..5665d040889ba406d293577fd96573b55087c7d5 100644 (file)
@@ -5,7 +5,7 @@
 \r
   Boot option manipulation\r
 \r
 \r
   Boot option manipulation\r
 \r
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -116,7 +116,6 @@ BOpt_DestroyMenuEntry (
   case BM_LOAD_CONTEXT_SELECT:\r
     LoadContext = (BM_LOAD_CONTEXT *) MenuEntry->VariableContext;\r
     FreePool (LoadContext->FilePathList);\r
   case BM_LOAD_CONTEXT_SELECT:\r
     LoadContext = (BM_LOAD_CONTEXT *) MenuEntry->VariableContext;\r
     FreePool (LoadContext->FilePathList);\r
-    FreePool (LoadContext->LoadOption);\r
     if (LoadContext->OptionalData != NULL) {\r
       FreePool (LoadContext->OptionalData);\r
     }\r
     if (LoadContext->OptionalData != NULL) {\r
       FreePool (LoadContext->OptionalData);\r
     }\r
@@ -336,7 +335,6 @@ BOpt_GetBootOptions (
     LoadOptionEnd                       = LoadOption + BootOptionSize;\r
 \r
     NewMenuEntry->OptionNumber          = BootOrderList[Index];\r
     LoadOptionEnd                       = LoadOption + BootOptionSize;\r
 \r
     NewMenuEntry->OptionNumber          = BootOrderList[Index];\r
-    NewLoadContext->LoadOptionModified  = FALSE;\r
     NewLoadContext->Deleted             = FALSE;\r
     NewLoadContext->IsBootNext          = BootNextFlag;\r
 \r
     NewLoadContext->Deleted             = FALSE;\r
     NewLoadContext->IsBootNext          = BootNextFlag;\r
 \r
@@ -374,13 +372,8 @@ BOpt_GetBootOptions (
     // for easy use with following LOAD_OPTION\r
     // embedded in this struct\r
     //\r
     // for easy use with following LOAD_OPTION\r
     // embedded in this struct\r
     //\r
-    NewLoadContext->LoadOption      = LoadOption;\r
-    NewLoadContext->LoadOptionSize  = BootOptionSize;\r
 \r
     NewLoadContext->Attributes      = *(UINT32 *) LoadOptionPtr;\r
 \r
     NewLoadContext->Attributes      = *(UINT32 *) LoadOptionPtr;\r
-    NewLoadContext->IsActive        = (BOOLEAN) (NewLoadContext->Attributes & LOAD_OPTION_ACTIVE);\r
-\r
-    NewLoadContext->ForceReconnect  = (BOOLEAN) (NewLoadContext->Attributes & LOAD_OPTION_FORCE_RECONNECT);\r
 \r
     LoadOptionPtr += sizeof (UINT32);\r
 \r
 \r
     LoadOptionPtr += sizeof (UINT32);\r
 \r
@@ -426,8 +419,6 @@ BOpt_GetBootOptions (
         LoadOptionPtr,\r
         OptionalDataSize\r
         );\r
         LoadOptionPtr,\r
         OptionalDataSize\r
         );\r
-\r
-      NewLoadContext->OptionalDataSize = OptionalDataSize;\r
     }\r
 \r
     InsertTailList (&BootOptionMenu.Head, &NewMenuEntry->Link);\r
     }\r
 \r
     InsertTailList (&BootOptionMenu.Head, &NewMenuEntry->Link);\r
@@ -441,6 +432,8 @@ BOpt_GetBootOptions (
   if (BootOrderList != NULL) {\r
     FreePool (BootOrderList);\r
   }\r
   if (BootOrderList != NULL) {\r
     FreePool (BootOrderList);\r
   }\r
+\r
+  FreePool(LoadOption);\r
   BootOptionMenu.MenuNumber = MenuCount;\r
   return EFI_SUCCESS;\r
 }\r
   BootOptionMenu.MenuNumber = MenuCount;\r
   return EFI_SUCCESS;\r
 }\r
@@ -708,7 +701,6 @@ BOpt_GetDriverOptions (
     LoadOptionPtr                       = LoadOption;\r
     LoadOptionEnd                       = LoadOption + DriverOptionSize;\r
     NewMenuEntry->OptionNumber          = DriverOrderList[Index];\r
     LoadOptionPtr                       = LoadOption;\r
     LoadOptionEnd                       = LoadOption + DriverOptionSize;\r
     NewMenuEntry->OptionNumber          = DriverOrderList[Index];\r
-    NewLoadContext->LoadOptionModified  = FALSE;\r
     NewLoadContext->Deleted             = FALSE;\r
     NewLoadContext->IsLegacy            = FALSE;\r
 \r
     NewLoadContext->Deleted             = FALSE;\r
     NewLoadContext->IsLegacy            = FALSE;\r
 \r
@@ -717,13 +709,8 @@ BOpt_GetDriverOptions (
     // for easy use with following LOAD_OPTION\r
     // embedded in this struct\r
     //\r
     // for easy use with following LOAD_OPTION\r
     // embedded in this struct\r
     //\r
-    NewLoadContext->LoadOption      = LoadOption;\r
-    NewLoadContext->LoadOptionSize  = DriverOptionSize;\r
 \r
     NewLoadContext->Attributes      = *(UINT32 *) LoadOptionPtr;\r
 \r
     NewLoadContext->Attributes      = *(UINT32 *) LoadOptionPtr;\r
-    NewLoadContext->IsActive        = (BOOLEAN) (NewLoadContext->Attributes & LOAD_OPTION_ACTIVE);\r
-\r
-    NewLoadContext->ForceReconnect  = (BOOLEAN) (NewLoadContext->Attributes & LOAD_OPTION_FORCE_RECONNECT);\r
 \r
     LoadOptionPtr += sizeof (UINT32);\r
 \r
 \r
     LoadOptionPtr += sizeof (UINT32);\r
 \r
@@ -771,7 +758,6 @@ BOpt_GetDriverOptions (
         OptionalDataSize\r
         );\r
 \r
         OptionalDataSize\r
         );\r
 \r
-      NewLoadContext->OptionalDataSize = OptionalDataSize;\r
     }\r
 \r
     InsertTailList (&DriverOptionMenu.Head, &NewMenuEntry->Link);\r
     }\r
 \r
     InsertTailList (&DriverOptionMenu.Head, &NewMenuEntry->Link);\r
@@ -781,6 +767,7 @@ BOpt_GetDriverOptions (
   if (DriverOrderList != NULL) {\r
     FreePool (DriverOrderList);\r
   }\r
   if (DriverOrderList != NULL) {\r
     FreePool (DriverOrderList);\r
   }\r
+  FreePool(LoadOption);\r
   DriverOptionMenu.MenuNumber = Index;\r
   return EFI_SUCCESS;\r
 \r
   DriverOptionMenu.MenuNumber = Index;\r
   return EFI_SUCCESS;\r
 \r
index a276caed05c4f3a76a87e0d29356ed3349ca5f77..929f38343bd65f591846cf5a11584ec4d579072e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Variable operation that will be used by bootmaint\r
 \r
 /** @file\r
 Variable operation that will be used by bootmaint\r
 \r
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -535,19 +535,18 @@ Var_UpdateDriverOption (
   )\r
 {\r
   UINT16          Index;\r
   )\r
 {\r
   UINT16          Index;\r
-  UINT16          *DriverOrderList;\r
-  UINT16          *NewDriverOrderList;\r
   UINT16          DriverString[12];\r
   UINT16          DriverString[12];\r
-  UINTN           DriverOrderListSize;\r
-  VOID            *Buffer;\r
-  UINTN           BufferSize;\r
-  UINT8           *Ptr;\r
   BM_MENU_ENTRY   *NewMenuEntry;\r
   BM_LOAD_CONTEXT *NewLoadContext;\r
   BOOLEAN         OptionalDataExist;\r
   EFI_STATUS      Status;\r
   BM_MENU_ENTRY   *NewMenuEntry;\r
   BM_LOAD_CONTEXT *NewLoadContext;\r
   BOOLEAN         OptionalDataExist;\r
   EFI_STATUS      Status;\r
+  EFI_BOOT_MANAGER_LOAD_OPTION  LoadOption;\r
+  UINT8                         *OptionalDesData;\r
+  UINT32                        OptionalDataSize;\r
 \r
   OptionalDataExist = FALSE;\r
 \r
   OptionalDataExist = FALSE;\r
+  OptionalDesData = NULL;\r
+  OptionalDataSize = 0;\r
 \r
   Index             = BOpt_GetDriverOptionNumber ();\r
   UnicodeSPrint (\r
 \r
   Index             = BOpt_GetDriverOptionNumber ();\r
   UnicodeSPrint (\r
@@ -561,68 +560,50 @@ Var_UpdateDriverOption (
     StrCpyS (DescriptionData, MAX_MENU_NUMBER, DriverString);\r
   }\r
 \r
     StrCpyS (DescriptionData, MAX_MENU_NUMBER, DriverString);\r
   }\r
 \r
-  BufferSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (DescriptionData);\r
-  BufferSize += GetDevicePathSize (CallbackData->LoadContext->FilePathList);\r
-\r
   if (*OptionalData != 0x0000) {\r
     OptionalDataExist = TRUE;\r
   if (*OptionalData != 0x0000) {\r
     OptionalDataExist = TRUE;\r
-    BufferSize += StrSize (OptionalData);\r
-  }\r
-\r
-  Buffer = AllocateZeroPool (BufferSize);\r
-  if (NULL == Buffer) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+    OptionalDesData = (UINT8 *)OptionalData;\r
+    OptionalDataSize = (UINT32)StrSize (OptionalData);\r
   }\r
 \r
   NewMenuEntry = BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT);\r
   if (NULL == NewMenuEntry) {\r
   }\r
 \r
   NewMenuEntry = BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT);\r
   if (NULL == NewMenuEntry) {\r
-    FreePool (Buffer);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
+  Status = EfiBootManagerInitializeLoadOption (\r
+             &LoadOption,\r
+             Index,\r
+             LoadOptionTypeDriver,\r
+             LOAD_OPTION_ACTIVE | (ForceReconnect << 1),\r
+             DescriptionData,\r
+             CallbackData->LoadContext->FilePathList,\r
+             OptionalDesData,\r
+             OptionalDataSize\r
+           );\r
+  if (!EFI_ERROR (Status)){\r
+    Status = EfiBootManagerAddLoadOptionVariable (&LoadOption,(UINTN) -1 );\r
+  }\r
+\r
   NewLoadContext                  = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;\r
   NewLoadContext->Deleted         = FALSE;\r
   NewLoadContext                  = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;\r
   NewLoadContext->Deleted         = FALSE;\r
-  NewLoadContext->LoadOptionSize  = BufferSize;\r
-  Ptr = (UINT8 *) Buffer;\r
-  NewLoadContext->LoadOption = Ptr;\r
-  *((UINT32 *) Ptr) = LOAD_OPTION_ACTIVE | (ForceReconnect << 1);\r
-  NewLoadContext->Attributes = *((UINT32 *) Ptr);\r
-  NewLoadContext->IsActive = TRUE;\r
-  NewLoadContext->ForceReconnect = (BOOLEAN) (NewLoadContext->Attributes & LOAD_OPTION_FORCE_RECONNECT);\r
-\r
-  Ptr += sizeof (UINT32);\r
-  *((UINT16 *) Ptr) = (UINT16) GetDevicePathSize (CallbackData->LoadContext->FilePathList);\r
-  NewLoadContext->FilePathListLength = *((UINT16 *) Ptr);\r
-\r
-  Ptr += sizeof (UINT16);\r
-  CopyMem (\r
-    Ptr,\r
-    DescriptionData,\r
-    StrSize (DescriptionData)\r
-    );\r
+  NewLoadContext->Attributes = LoadOption.Attributes;\r
+  NewLoadContext->FilePathListLength = (UINT16)GetDevicePathSize (LoadOption.FilePath);\r
 \r
   NewLoadContext->Description = AllocateZeroPool (StrSize (DescriptionData));\r
   ASSERT (NewLoadContext->Description != NULL);\r
   NewMenuEntry->DisplayString = NewLoadContext->Description;\r
   CopyMem (\r
     NewLoadContext->Description,\r
 \r
   NewLoadContext->Description = AllocateZeroPool (StrSize (DescriptionData));\r
   ASSERT (NewLoadContext->Description != NULL);\r
   NewMenuEntry->DisplayString = NewLoadContext->Description;\r
   CopyMem (\r
     NewLoadContext->Description,\r
-    (VOID *) Ptr,\r
+    LoadOption.Description,\r
     StrSize (DescriptionData)\r
     );\r
 \r
     StrSize (DescriptionData)\r
     );\r
 \r
-  Ptr += StrSize (DescriptionData);\r
-  CopyMem (\r
-    Ptr,\r
-    CallbackData->LoadContext->FilePathList,\r
-    GetDevicePathSize (CallbackData->LoadContext->FilePathList)\r
-    );\r
-\r
   NewLoadContext->FilePathList = AllocateZeroPool (GetDevicePathSize (CallbackData->LoadContext->FilePathList));\r
   ASSERT (NewLoadContext->FilePathList != NULL);\r
   NewLoadContext->FilePathList = AllocateZeroPool (GetDevicePathSize (CallbackData->LoadContext->FilePathList));\r
   ASSERT (NewLoadContext->FilePathList != NULL);\r
-\r
   CopyMem (\r
     NewLoadContext->FilePathList,\r
   CopyMem (\r
     NewLoadContext->FilePathList,\r
-    (VOID *) Ptr,\r
+    LoadOption.FilePath,\r
     GetDevicePathSize (CallbackData->LoadContext->FilePathList)\r
     );\r
 \r
     GetDevicePathSize (CallbackData->LoadContext->FilePathList)\r
     );\r
 \r
@@ -632,50 +613,19 @@ Var_UpdateDriverOption (
   NewMenuEntry->HelpStringToken = HiiSetString (HiiHandle, 0, NewMenuEntry->HelpString, NULL);\r
 \r
   if (OptionalDataExist) {\r
   NewMenuEntry->HelpStringToken = HiiSetString (HiiHandle, 0, NewMenuEntry->HelpString, NULL);\r
 \r
   if (OptionalDataExist) {\r
-    Ptr += (UINT8) GetDevicePathSize (CallbackData->LoadContext->FilePathList);\r
-\r
+    NewLoadContext->OptionalData = AllocateZeroPool (LoadOption.OptionalDataSize);\r
     CopyMem (\r
     CopyMem (\r
-      Ptr,\r
-      OptionalData,\r
-      StrSize (OptionalData)\r
+      NewLoadContext->OptionalData,\r
+      LoadOption.OptionalData,\r
+      LoadOption.OptionalDataSize\r
       );\r
   }\r
 \r
       );\r
   }\r
 \r
-  Status = gRT->SetVariable (\r
-                  DriverString,\r
-                  &gEfiGlobalVariableGuid,\r
-                  VAR_FLAG,\r
-                  BufferSize,\r
-                  Buffer\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-  GetEfiGlobalVariable2 (L"DriverOrder", (VOID **) &DriverOrderList, &DriverOrderListSize);\r
-  NewDriverOrderList = AllocateZeroPool (DriverOrderListSize + sizeof (UINT16));\r
-  ASSERT (NewDriverOrderList != NULL);\r
-  if (DriverOrderList != NULL){\r
-    CopyMem (NewDriverOrderList, DriverOrderList, DriverOrderListSize);\r
-  }\r
-  NewDriverOrderList[DriverOrderListSize / sizeof (UINT16)] = Index;\r
-  if (DriverOrderList != NULL) {\r
-    EfiLibDeleteVariable (L"DriverOrder", &gEfiGlobalVariableGuid);\r
-  }\r
-\r
-  Status = gRT->SetVariable (\r
-                  L"DriverOrder",\r
-                  &gEfiGlobalVariableGuid,\r
-                  VAR_FLAG,\r
-                  DriverOrderListSize + sizeof (UINT16),\r
-                  NewDriverOrderList\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-  if (DriverOrderList != NULL) {\r
-    FreePool (DriverOrderList);\r
-  }\r
-  DriverOrderList = NULL;\r
-  FreePool (NewDriverOrderList);\r
   InsertTailList (&DriverOptionMenu.Head, &NewMenuEntry->Link);\r
   DriverOptionMenu.MenuNumber++;\r
 \r
   InsertTailList (&DriverOptionMenu.Head, &NewMenuEntry->Link);\r
   DriverOptionMenu.MenuNumber++;\r
 \r
+  EfiBootManagerFreeLoadOption(&LoadOption);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -696,22 +646,21 @@ Var_UpdateBootOption (
   IN  BMM_CALLBACK_DATA              *CallbackData\r
   )\r
 {\r
   IN  BMM_CALLBACK_DATA              *CallbackData\r
   )\r
 {\r
-  UINT16          *BootOrderList;\r
-  UINT16          *NewBootOrderList;\r
-  UINTN           BootOrderListSize;\r
   UINT16          BootString[10];\r
   UINT16          BootString[10];\r
-  VOID            *Buffer;\r
-  UINTN           BufferSize;\r
-  UINT8           *Ptr;\r
   UINT16          Index;\r
   BM_MENU_ENTRY   *NewMenuEntry;\r
   BM_LOAD_CONTEXT *NewLoadContext;\r
   BOOLEAN         OptionalDataExist;\r
   EFI_STATUS      Status;\r
   BMM_FAKE_NV_DATA  *NvRamMap;\r
   UINT16          Index;\r
   BM_MENU_ENTRY   *NewMenuEntry;\r
   BM_LOAD_CONTEXT *NewLoadContext;\r
   BOOLEAN         OptionalDataExist;\r
   EFI_STATUS      Status;\r
   BMM_FAKE_NV_DATA  *NvRamMap;\r
+  EFI_BOOT_MANAGER_LOAD_OPTION  LoadOption;\r
+  UINT8                         *OptionalData;\r
+  UINT32                        OptionalDataSize;\r
 \r
   OptionalDataExist = FALSE;\r
   NvRamMap = &CallbackData->BmmFakeNvData;\r
 \r
   OptionalDataExist = FALSE;\r
   NvRamMap = &CallbackData->BmmFakeNvData;\r
+  OptionalData = NULL;\r
+  OptionalDataSize = 0;\r
 \r
   Index = BOpt_GetBootOptionNumber () ;\r
   UnicodeSPrint (BootString, sizeof (BootString), L"Boot%04x", Index);\r
 \r
   Index = BOpt_GetBootOptionNumber () ;\r
   UnicodeSPrint (BootString, sizeof (BootString), L"Boot%04x", Index);\r
@@ -720,17 +669,10 @@ Var_UpdateBootOption (
     StrCpyS (NvRamMap->BootDescriptionData, sizeof (NvRamMap->BootDescriptionData) / sizeof (NvRamMap->BootDescriptionData[0]), BootString);\r
   }\r
 \r
     StrCpyS (NvRamMap->BootDescriptionData, sizeof (NvRamMap->BootDescriptionData) / sizeof (NvRamMap->BootDescriptionData[0]), BootString);\r
   }\r
 \r
-  BufferSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (NvRamMap->BootDescriptionData);\r
-  BufferSize += GetDevicePathSize (CallbackData->LoadContext->FilePathList);\r
-\r
   if (NvRamMap->BootOptionalData[0] != 0x0000) {\r
     OptionalDataExist = TRUE;\r
   if (NvRamMap->BootOptionalData[0] != 0x0000) {\r
     OptionalDataExist = TRUE;\r
-    BufferSize += StrSize (NvRamMap->BootOptionalData);\r
-  }\r
-\r
-  Buffer = AllocateZeroPool (BufferSize);\r
-  if (NULL == Buffer) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+    OptionalData = (UINT8 *)NvRamMap->BootOptionalData;\r
+    OptionalDataSize = (UINT32)StrSize (NvRamMap->BootOptionalData);\r
   }\r
 \r
   NewMenuEntry = BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT);\r
   }\r
 \r
   NewMenuEntry = BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT);\r
@@ -738,50 +680,41 @@ Var_UpdateBootOption (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
+  Status = EfiBootManagerInitializeLoadOption (\r
+             &LoadOption,\r
+             Index,\r
+             LoadOptionTypeBoot,\r
+             LOAD_OPTION_ACTIVE,\r
+             NvRamMap->BootDescriptionData,\r
+             CallbackData->LoadContext->FilePathList,\r
+             OptionalData,\r
+             OptionalDataSize\r
+           );\r
+  if (!EFI_ERROR (Status)){\r
+    Status = EfiBootManagerAddLoadOptionVariable (&LoadOption,(UINTN) -1 );\r
+  }\r
+\r
   NewLoadContext                  = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;\r
   NewLoadContext->Deleted         = FALSE;\r
   NewLoadContext                  = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;\r
   NewLoadContext->Deleted         = FALSE;\r
-  NewLoadContext->LoadOptionSize  = BufferSize;\r
-  Ptr = (UINT8 *) Buffer;\r
-  NewLoadContext->LoadOption = Ptr;\r
-  *((UINT32 *) Ptr) = LOAD_OPTION_ACTIVE;\r
-  NewLoadContext->Attributes = *((UINT32 *) Ptr);\r
-  NewLoadContext->IsActive = TRUE;\r
-  NewLoadContext->ForceReconnect = (BOOLEAN) (NewLoadContext->Attributes & LOAD_OPTION_FORCE_RECONNECT);\r
-\r
-  Ptr += sizeof (UINT32);\r
-  *((UINT16 *) Ptr) = (UINT16) GetDevicePathSize (CallbackData->LoadContext->FilePathList);\r
-  NewLoadContext->FilePathListLength = *((UINT16 *) Ptr);\r
-  Ptr += sizeof (UINT16);\r
-\r
-  CopyMem (\r
-    Ptr,\r
-    NvRamMap->BootDescriptionData,\r
-    StrSize (NvRamMap->BootDescriptionData)\r
-    );\r
+  NewLoadContext->Attributes = LoadOption.Attributes;\r
+  NewLoadContext->FilePathListLength = (UINT16) GetDevicePathSize (LoadOption.FilePath);\r
 \r
   NewLoadContext->Description = AllocateZeroPool (StrSize (NvRamMap->BootDescriptionData));\r
   ASSERT (NewLoadContext->Description != NULL);\r
 \r
   NewMenuEntry->DisplayString = NewLoadContext->Description;\r
 \r
   NewLoadContext->Description = AllocateZeroPool (StrSize (NvRamMap->BootDescriptionData));\r
   ASSERT (NewLoadContext->Description != NULL);\r
 \r
   NewMenuEntry->DisplayString = NewLoadContext->Description;\r
+\r
   CopyMem (\r
     NewLoadContext->Description,\r
   CopyMem (\r
     NewLoadContext->Description,\r
-    (VOID *) Ptr,\r
+    LoadOption.Description,\r
     StrSize (NvRamMap->BootDescriptionData)\r
     );\r
 \r
     StrSize (NvRamMap->BootDescriptionData)\r
     );\r
 \r
-  Ptr += StrSize (NvRamMap->BootDescriptionData);\r
-  CopyMem (\r
-    Ptr,\r
-    CallbackData->LoadContext->FilePathList,\r
-    GetDevicePathSize (CallbackData->LoadContext->FilePathList)\r
-    );\r
-\r
   NewLoadContext->FilePathList = AllocateZeroPool (GetDevicePathSize (CallbackData->LoadContext->FilePathList));\r
   ASSERT (NewLoadContext->FilePathList != NULL);\r
   NewLoadContext->FilePathList = AllocateZeroPool (GetDevicePathSize (CallbackData->LoadContext->FilePathList));\r
   ASSERT (NewLoadContext->FilePathList != NULL);\r
-\r
   CopyMem (\r
     NewLoadContext->FilePathList,\r
   CopyMem (\r
     NewLoadContext->FilePathList,\r
-    (VOID *) Ptr,\r
+    LoadOption.FilePath,\r
     GetDevicePathSize (CallbackData->LoadContext->FilePathList)\r
     );\r
 \r
     GetDevicePathSize (CallbackData->LoadContext->FilePathList)\r
     );\r
 \r
@@ -791,46 +724,19 @@ Var_UpdateBootOption (
   NewMenuEntry->HelpStringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, NewMenuEntry->HelpString, NULL);\r
 \r
   if (OptionalDataExist) {\r
   NewMenuEntry->HelpStringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, NewMenuEntry->HelpString, NULL);\r
 \r
   if (OptionalDataExist) {\r
-    Ptr += (UINT8) GetDevicePathSize (CallbackData->LoadContext->FilePathList);\r
-\r
-    CopyMem (Ptr, NvRamMap->BootOptionalData, StrSize (NvRamMap->BootOptionalData));\r
-  }\r
-\r
-  Status = gRT->SetVariable (\r
-                  BootString,\r
-                  &gEfiGlobalVariableGuid,\r
-                  VAR_FLAG,\r
-                  BufferSize,\r
-                  Buffer\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  GetEfiGlobalVariable2 (L"BootOrder", (VOID **) &BootOrderList, &BootOrderListSize);\r
-  NewBootOrderList = AllocateZeroPool (BootOrderListSize + sizeof (UINT16));\r
-  ASSERT (NewBootOrderList != NULL);\r
-  if (BootOrderList != NULL){\r
-    CopyMem (NewBootOrderList, BootOrderList, BootOrderListSize);\r
-  }\r
-  NewBootOrderList[BootOrderListSize / sizeof (UINT16)] = Index;\r
-\r
-  if (BootOrderList != NULL) {\r
-    FreePool (BootOrderList);\r
+    NewLoadContext->OptionalData = AllocateZeroPool (LoadOption.OptionalDataSize);\r
+    CopyMem (\r
+      NewLoadContext->OptionalData,\r
+      LoadOption.OptionalData,\r
+      LoadOption.OptionalDataSize\r
+      );\r
   }\r
 \r
   }\r
 \r
-  Status = gRT->SetVariable (\r
-                  L"BootOrder",\r
-                  &gEfiGlobalVariableGuid,\r
-                  VAR_FLAG,\r
-                  BootOrderListSize + sizeof (UINT16),\r
-                  NewBootOrderList\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  FreePool (NewBootOrderList);\r
-  NewBootOrderList = NULL;\r
   InsertTailList (&BootOptionMenu.Head, &NewMenuEntry->Link);\r
   BootOptionMenu.MenuNumber++;\r
 \r
   InsertTailList (&BootOptionMenu.Head, &NewMenuEntry->Link);\r
   BootOptionMenu.MenuNumber++;\r
 \r
+  EfiBootManagerFreeLoadOption(&LoadOption);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r