]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/BMMUiLib: Replace same logic with API in UefiBootManagerLib
authorDandan Bi <dandan.bi@intel.com>
Mon, 27 Feb 2017 05:33:06 +0000 (13:33 +0800)
committerHao Wu <hao.a.wu@intel.com>
Tue, 28 Feb 2017 08:45:11 +0000 (16:45 +0800)
Use the API EfiBootManagerDeleteLoadOptionVariable in UefiBootManagerLib to
replace the same logic in function Var_DelBootOption/Var_DelDriverOption.
This can make code clean and prevent potential bugs.

https://bugzilla.tianocore.org/show_bug.cgi?id=391

Cc: Eric Dong <eric.dong@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManager.h
MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c

index 532b75b202133b8552b44bcc5541aa5cf4b6c9cf..a8d7a0f8d0f966058066da7a18636029b418b447 100644 (file)
@@ -633,8 +633,6 @@ Var_UpdateBootOption (
 \r
 /**\r
   Delete Boot Option that represent a Deleted state in BootOptionMenu.\r
-  After deleting this boot option, call Var_ChangeBootOrder to\r
-  make sure BootOrder is in valid state.\r
 \r
   @retval EFI_SUCCESS   If all boot load option EFI Variables corresponding to  \r
                         BM_LOAD_CONTEXT marked for deletion is deleted\r
@@ -646,21 +644,6 @@ Var_DelBootOption (
   VOID\r
   );\r
 \r
-/**\r
-  After any operation on Boot####, there will be a discrepancy in BootOrder.\r
-  Since some are missing but in BootOrder, while some are present but are\r
-  not reflected by BootOrder. Then a function rebuild BootOrder from\r
-  scratch by content from BootOptionMenu is needed.\r
-\r
-  @retval  EFI_SUCCESS  The boot order is updated successfully.\r
-  @return  other than EFI_SUCCESS if failed to change the "BootOrder" EFI Variable.\r
-\r
-**/\r
-EFI_STATUS\r
-Var_ChangeBootOrder (\r
-  VOID\r
-  );\r
-\r
 /**\r
   This function create a currently loaded Drive Option from \r
   the BMM. It then appends this Driver Option to the end of \r
@@ -687,9 +670,7 @@ Var_UpdateDriverOption (
   );\r
 \r
 /**\r
-  Delete Load Option that represent a Deleted state in BootOptionMenu.\r
-  After deleting this Driver option, call Var_ChangeDriverOrder to\r
-  make sure DriverOrder is in valid state.\r
+  Delete Load Option that represent a Deleted state in DriverOptionMenu.\r
 \r
   @retval EFI_SUCCESS Load Option is successfully updated.\r
   @return Other value than EFI_SUCCESS if failed to update "Driver Order" EFI\r
@@ -701,22 +682,6 @@ Var_DelDriverOption (
   VOID\r
   );\r
 \r
-/**\r
-  After any operation on Driver####, there will be a discrepancy in\r
-  DriverOrder. Since some are missing but in DriverOrder, while some\r
-  are present but are not reflected by DriverOrder. Then a function\r
-  rebuild DriverOrder from scratch by content from DriverOptionMenu is\r
-  needed.\r
-\r
-  @retval  EFI_SUCCESS  The driver order is updated successfully.\r
-  @return  other than EFI_SUCCESS if failed to set the "DriverOrder" EFI Variable.\r
-\r
-**/\r
-EFI_STATUS\r
-Var_ChangeDriverOrder (\r
-  VOID\r
-  );\r
-\r
 /**\r
   This function delete and build multi-instance device path ConIn\r
   console device.\r
index 746b2335edc525f318c6299c578087be29d577ae..c1c55b0fb23c6b6bc492fb8ffe6a23720c67ffae 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Variable operation that will be used by bootmaint\r
 \r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, 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
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 /**\r
   Delete Boot Option that represent a Deleted state in BootOptionMenu.\r
-  After deleting this boot option, call Var_ChangeBootOrder to\r
-  make sure BootOrder is in valid state.\r
 \r
   @retval EFI_SUCCESS   If all boot load option EFI Variables corresponding to  \r
                         BM_LOAD_CONTEXT marked for deletion is deleted.\r
@@ -32,12 +30,10 @@ Var_DelBootOption (
 {\r
   BM_MENU_ENTRY   *NewMenuEntry;\r
   BM_LOAD_CONTEXT *NewLoadContext;\r
-  UINT16          BootString[10];\r
   EFI_STATUS      Status;\r
   UINTN           Index;\r
   UINTN           Index2;\r
 \r
-  Status  = EFI_SUCCESS;\r
   Index2  = 0;\r
   for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) {\r
     NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, (Index - Index2));\r
@@ -50,14 +46,10 @@ Var_DelBootOption (
       continue;\r
     }\r
 \r
-    UnicodeSPrint (\r
-      BootString,\r
-      sizeof (BootString),\r
-      L"Boot%04x",\r
-      NewMenuEntry->OptionNumber\r
-      );\r
-\r
-    EfiLibDeleteVariable (BootString, &gEfiGlobalVariableGuid);\r
+    Status = EfiBootManagerDeleteLoadOptionVariable (NewMenuEntry->OptionNumber,LoadOptionTypeBoot);\r
+    if (EFI_ERROR (Status)) {\r
+     return Status;\r
+    }\r
     Index2++;\r
     //\r
     // If current Load Option is the same as BootNext,\r
@@ -75,102 +67,11 @@ Var_DelBootOption (
 \r
   BootOptionMenu.MenuNumber -= Index2;\r
 \r
-  Status = Var_ChangeBootOrder ();\r
-  return Status;\r
-}\r
-\r
-/**\r
-  After any operation on Boot####, there will be a discrepancy in BootOrder.\r
-  Since some are missing but in BootOrder, while some are present but are\r
-  not reflected by BootOrder. Then a function rebuild BootOrder from\r
-  scratch by content from BootOptionMenu is needed.\r
-\r
-\r
-  \r
-\r
-  @retval  EFI_SUCCESS  The boot order is updated successfully.\r
-  @return               EFI_STATUS other than EFI_SUCCESS if failed to\r
-                        Set the "BootOrder" EFI Variable.\r
-\r
-**/\r
-EFI_STATUS\r
-Var_ChangeBootOrder (\r
-  VOID\r
-  )\r
-{\r
-\r
-  EFI_STATUS    Status;\r
-  BM_MENU_ENTRY *NewMenuEntry;\r
-  UINT16        *BootOrderList;\r
-  UINT16        *BootOrderListPtr;\r
-  UINTN         BootOrderListSize;\r
-  UINTN         Index;\r
-\r
-  BootOrderList     = NULL;\r
-  BootOrderListSize = 0;\r
-  //\r
-  // First check whether BootOrder is present in current configuration\r
-  //\r
-  GetEfiGlobalVariable2 (L"BootOrder", (VOID **) &BootOrderList, &BootOrderListSize);\r
-\r
-  //\r
-  // If exists, delete it to hold new BootOrder\r
-  //\r
-  if (BootOrderList != NULL) {\r
-    EfiLibDeleteVariable (L"BootOrder", &gEfiGlobalVariableGuid);\r
-    FreePool (BootOrderList);\r
-    BootOrderList = NULL;\r
-  }\r
-  //\r
-  // Maybe here should be some check method to ensure that\r
-  // no new added boot options will be added\r
-  // but the setup engine now will give only one callback\r
-  // that is to say, user are granted only one chance to\r
-  // decide whether the boot option will be added or not\r
-  // there should be no indictor to show whether this\r
-  // is a "new" boot option\r
-  //\r
-  BootOrderListSize = BootOptionMenu.MenuNumber;\r
-\r
-  if (BootOrderListSize > 0) {\r
-    BootOrderList = AllocateZeroPool (BootOrderListSize * sizeof (UINT16));\r
-    ASSERT (BootOrderList != NULL);\r
-    BootOrderListPtr = BootOrderList;\r
-\r
-    //\r
-    // Get all current used Boot#### from BootOptionMenu.\r
-    // OptionNumber in each BM_LOAD_OPTION is really its\r
-    // #### value.\r
-    //\r
-    for (Index = 0; Index < BootOrderListSize; Index++) {\r
-      NewMenuEntry    = BOpt_GetMenuEntry (&BootOptionMenu, Index);\r
-      *BootOrderList  = (UINT16) NewMenuEntry->OptionNumber;\r
-      BootOrderList++;\r
-    }\r
-\r
-    BootOrderList = BootOrderListPtr;\r
-\r
-    //\r
-    // After building the BootOrderList, write it back\r
-    //\r
-    Status = gRT->SetVariable (\r
-                    L"BootOrder",\r
-                    &gEfiGlobalVariableGuid,\r
-                    VAR_FLAG,\r
-                    BootOrderListSize * sizeof (UINT16),\r
-                    BootOrderList\r
-                    );\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
-  }\r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Delete Load Option that represent a Deleted state in BootOptionMenu.\r
-  After deleting this Driver option, call Var_ChangeDriverOrder to\r
-  make sure DriverOrder is in valid state.\r
+  Delete Load Option that represent a Deleted state in DriverOptionMenu.\r
 \r
   @retval EFI_SUCCESS       Load Option is successfully updated.\r
   @retval EFI_NOT_FOUND     Fail to find the driver option want to be deleted.\r
@@ -185,12 +86,10 @@ Var_DelDriverOption (
 {\r
   BM_MENU_ENTRY   *NewMenuEntry;\r
   BM_LOAD_CONTEXT *NewLoadContext;\r
-  UINT16          DriverString[12];\r
   EFI_STATUS      Status;\r
   UINTN           Index;\r
   UINTN           Index2;\r
 \r
-  Status  = EFI_SUCCESS;\r
   Index2  = 0;\r
   for (Index = 0; Index < DriverOptionMenu.MenuNumber; Index++) {\r
     NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, (Index - Index2));\r
@@ -202,15 +101,11 @@ Var_DelDriverOption (
     if (!NewLoadContext->Deleted) {\r
       continue;\r
     }\r
+    Status = EfiBootManagerDeleteLoadOptionVariable (NewMenuEntry->OptionNumber,LoadOptionTypeDriver);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
 \r
-    UnicodeSPrint (\r
-      DriverString,\r
-      sizeof (DriverString),\r
-      L"Driver%04x",\r
-      NewMenuEntry->OptionNumber\r
-      );\r
-\r
-    EfiLibDeleteVariable (DriverString, &gEfiGlobalVariableGuid);\r
     Index2++;\r
 \r
     RemoveEntryList (&NewMenuEntry->Link);\r
@@ -220,83 +115,6 @@ Var_DelDriverOption (
 \r
   DriverOptionMenu.MenuNumber -= Index2;\r
 \r
-  Status = Var_ChangeDriverOrder ();\r
-  return Status;\r
-}\r
-\r
-/**\r
-  After any operation on Driver####, there will be a discrepancy in\r
-  DriverOrder. Since some are missing but in DriverOrder, while some\r
-  are present but are not reflected by DriverOrder. Then a function\r
-  rebuild DriverOrder from scratch by content from DriverOptionMenu is\r
-  needed.\r
-\r
-  @retval  EFI_SUCCESS  The driver order is updated successfully.\r
-  @return  Other status than EFI_SUCCESS if failed to set the "DriverOrder" EFI Variable.\r
-\r
-**/\r
-EFI_STATUS\r
-Var_ChangeDriverOrder (\r
-  VOID\r
-  )\r
-{\r
-  EFI_STATUS    Status;\r
-  BM_MENU_ENTRY *NewMenuEntry;\r
-  UINT16        *DriverOrderList;\r
-  UINT16        *DriverOrderListPtr;\r
-  UINTN         DriverOrderListSize;\r
-  UINTN         Index;\r
-\r
-  DriverOrderList     = NULL;\r
-  DriverOrderListSize = 0;\r
-\r
-  //\r
-  // First check whether DriverOrder is present in current configuration\r
-  //\r
-  GetEfiGlobalVariable2 (L"DriverOrder", (VOID **) &DriverOrderList, &DriverOrderListSize);\r
-  //\r
-  // If exists, delete it to hold new DriverOrder\r
-  //\r
-  if (DriverOrderList != NULL) {\r
-    EfiLibDeleteVariable (L"DriverOrder", &gEfiGlobalVariableGuid);\r
-    FreePool (DriverOrderList);\r
-    DriverOrderList = NULL;\r
-  }\r
-\r
-  DriverOrderListSize = DriverOptionMenu.MenuNumber;\r
-\r
-  if (DriverOrderListSize > 0) {\r
-    DriverOrderList = AllocateZeroPool (DriverOrderListSize * sizeof (UINT16));\r
-    ASSERT (DriverOrderList != NULL);\r
-    DriverOrderListPtr = DriverOrderList;\r
-\r
-    //\r
-    // Get all current used Driver#### from DriverOptionMenu.\r
-    // OptionNumber in each BM_LOAD_OPTION is really its\r
-    // #### value.\r
-    //\r
-    for (Index = 0; Index < DriverOrderListSize; Index++) {\r
-      NewMenuEntry      = BOpt_GetMenuEntry (&DriverOptionMenu, Index);\r
-      *DriverOrderList  = (UINT16) NewMenuEntry->OptionNumber;\r
-      DriverOrderList++;\r
-    }\r
-\r
-    DriverOrderList = DriverOrderListPtr;\r
-\r
-    //\r
-    // After building the DriverOrderList, write it back\r
-    //\r
-    Status = gRT->SetVariable (\r
-                    L"DriverOrder",\r
-                    &gEfiGlobalVariableGuid,\r
-                    VAR_FLAG,\r
-                    DriverOrderListSize * sizeof (UINT16),\r
-                    DriverOrderList\r
-                    );\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
-  }\r
   return EFI_SUCCESS;\r
 }\r
 \r