]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c
IntelSiliconPkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Library / BootMaintenanceManagerUiLib / Variable.c
index b65d6a5c9ed035258bd1278d90e6fac96e989c75..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
@@ -371,7 +189,7 @@ Var_UpdateConsoleOption (
       Vendor.Header.Type    = MESSAGING_DEVICE_PATH;\r
       Vendor.Header.SubType = MSG_VENDOR_DP;\r
       \r
-      ASSERT (NewTerminalContext->TerminalType < (sizeof (TerminalTypeGuid) / sizeof (TerminalTypeGuid[0])));\r
+      ASSERT (NewTerminalContext->TerminalType < (ARRAY_SIZE (TerminalTypeGuid)));\r
       CopyMem (\r
         &Vendor.Guid,\r
         &TerminalTypeGuid[NewTerminalContext->TerminalType],\r
@@ -465,7 +283,9 @@ Var_UpdateErrorOutOption (
   @param OptionalData    The optional load option.\r
   @param ForceReconnect  If to force reconnect.\r
 \r
-  @retval EFI_OUT_OF_RESOURCES If not enought memory to complete the operation.\r
+  @retval other                Contain some errors when excuting this function.See function\r
+                               EfiBootManagerInitializeLoadOption/EfiBootManagerAddLoadOptionVariabl\r
+                               for detail return information.\r
   @retval EFI_SUCCESS          If function completes successfully.\r
 \r
 **/\r
@@ -525,8 +345,14 @@ Var_UpdateDriverOption (
              OptionalDesData,\r
              OptionalDataSize\r
            );\r
-  if (!EFI_ERROR (Status)){\r
-    Status = EfiBootManagerAddLoadOptionVariable (&LoadOption,(UINTN) -1 );\r
+  if (EFI_ERROR (Status)){\r
+    return Status;\r
+  }\r
+\r
+  Status = EfiBootManagerAddLoadOptionVariable (&LoadOption,(UINTN) -1 );\r
+  if (EFI_ERROR (Status)) {\r
+    EfiBootManagerFreeLoadOption(&LoadOption);\r
+    return Status;\r
   }\r
 \r
   NewLoadContext                  = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;\r
@@ -582,7 +408,9 @@ Var_UpdateDriverOption (
 \r
   @param CallbackData    The BMM context data.\r
 \r
-  @retval EFI_OUT_OF_RESOURCES If not enought memory to complete the operation.\r
+  @retval other                Contain some errors when excuting this function. See function\r
+                               EfiBootManagerInitializeLoadOption/EfiBootManagerAddLoadOptionVariabl\r
+                               for detail return information.\r
   @retval EFI_SUCCESS          If function completes successfully.\r
 \r
 **/\r
@@ -635,8 +463,14 @@ Var_UpdateBootOption (
              OptionalData,\r
              OptionalDataSize\r
            );\r
-  if (!EFI_ERROR (Status)){\r
-    Status = EfiBootManagerAddLoadOptionVariable (&LoadOption,(UINTN) -1 );\r
+  if (EFI_ERROR (Status)){\r
+    return Status;\r
+  }\r
+\r
+  Status = EfiBootManagerAddLoadOptionVariable (&LoadOption,(UINTN) -1 );\r
+  if (EFI_ERROR (Status)) {\r
+    EfiBootManagerFreeLoadOption(&LoadOption);\r
+    return Status;\r
   }\r
 \r
   NewLoadContext                  = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;\r