]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c
Remove SafeFreePool from MemoryAllocationLib as this API's name is misleading. Its...
[mirror_edk2.git] / MdeModulePkg / Universal / BdsDxe / BootMaint / BootMaint.c
index 9fca22afbd5a376df5f423177a2729ea6b0db893..ac313989874c0ee5020984eba0bebcdfe43b1d52 100644 (file)
@@ -17,19 +17,25 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "Bds.h"\r
 #include "FrontPage.h"\r
 \r
-EFI_GUID EfiLegacyDevOrderGuid = EFI_LEGACY_DEV_ORDER_VARIABLE_GUID;\r
-EFI_GUID mBootMaintGuid = BOOT_MAINT_FORMSET_GUID;\r
-EFI_GUID mFileExplorerGuid = FILE_EXPLORE_FORMSET_GUID;\r
+EFI_DEVICE_PATH_PROTOCOL  EndDevicePath[] = {\r
+  END_DEVICE_PATH_TYPE,\r
+  END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+  END_DEVICE_PATH_LENGTH,\r
+  0\r
+};\r
 \r
-CHAR16  mBootMaintStorageName[] = L"BmData";\r
-CHAR16  mFileExplorerStorageName[] = L"FeData";\r
+\r
+EFI_GUID EfiLegacyDevOrderGuid  = EFI_LEGACY_DEV_ORDER_VARIABLE_GUID;\r
+EFI_GUID mBootMaintGuid         = BOOT_MAINT_FORMSET_GUID;\r
+EFI_GUID mFileExplorerGuid      = FILE_EXPLORE_FORMSET_GUID;\r
+\r
+CHAR16  mBootMaintStorageName[]     = L"BmData";\r
+CHAR16  mFileExplorerStorageName[]  = L"FeData";\r
 \r
 /**\r
   Init all memu.\r
 \r
-  @param CallbackData    The \r
-\r
-  @return EDES_TODO: Add description for return value\r
+  @param CallbackData    The BMM context data.\r
 \r
 **/\r
 VOID\r
@@ -38,11 +44,7 @@ InitAllMenu (
   );\r
 \r
 /**\r
-  EDES_TODO: Add function description\r
-\r
-  @param VOID            EDES_TODO: Add parameter description\r
-\r
-  @return EDES_TODO: Add description for return value\r
+  Free up all Menu Option list.\r
 \r
 **/\r
 VOID\r
@@ -54,9 +56,9 @@ FreeAllMenu (
   Create string tokens for a menu from its help strings and display strings\r
 \r
 \r
-  @param CallbackData    EDES_TODO: Add parameter description\r
-  @param HiiHandle       Hii Handle of the package to be updated.\r
-  @param MenuOption      The Menu whose string tokens need to be created\r
+  @param CallbackData    The BMM context data.\r
+  @param HiiHandle       Hii Handle of the package to be updated.\r
+  @param MenuOption      The Menu whose string tokens need to be created\r
 \r
   @retval  EFI_SUCCESS      string tokens created successfully\r
   @retval  others           contain some errors\r
@@ -100,14 +102,14 @@ CreateMenuStringToken (
   or more named elements from the target driver.\r
 \r
 \r
-  @param This            Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
-  @param Request         A null-terminated Unicode string in <ConfigRequest> format.\r
-  @param Progress        On return, points to a character in the Request string.\r
+  @param This            Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+  @param Request         A null-terminated Unicode string in <ConfigRequest> format.\r
+  @param Progress        On return, points to a character in the Request string.\r
                          Points to the string's null terminator if request was successful.\r
                          Points to the most recent '&' before the first failing name/value\r
                          pair (or the beginning of the string if the failure is in the\r
                          first name/value pair) if the request was not successful.\r
-  @param Results         A null-terminated Unicode string in <ConfigAltResp> format which\r
+  @param Results         A null-terminated Unicode string in <ConfigAltResp> format which\r
                          has all values filled in for the names in the Request string.\r
                          String to be allocated by the called function.\r
 \r
@@ -538,10 +540,9 @@ BootMaintCallback (
 /**\r
   Function handling request to apply changes for BMM pages.\r
 \r
-\r
-  @param Private         - Pointer to callback data buffer.\r
-  @param CurrentFakeNVMap - Pointer to buffer holding data of various values used by BMM\r
-  @param FormId          - ID of the form which has sent the request to apply change.\r
+  @param Private            Pointer to callback data buffer.\r
+  @param CurrentFakeNVMap   Pointer to buffer holding data of various values used by BMM\r
+  @param FormId             ID of the form which has sent the request to apply change.\r
 \r
   @retval  EFI_SUCCESS       Change successfully applied.\r
   @retval  Other             Error occurs while trying to apply changes.\r
@@ -723,12 +724,11 @@ Error:
 }\r
 \r
 /**\r
-  EDES_TODO: Add function description\r
-\r
-  @param Private         EDES_TODO: Add parameter description\r
-  @param CurrentFakeNVMap EDES_TODO: Add parameter description\r
+  Discard all changes done to the BMM pages such as Boot Order change,\r
+  Driver order change.\r
 \r
-  @return EDES_TODO: Add description for return value\r
+  @param Private            The BMM context data.\r
+  @param CurrentFakeNVMap   The current Fack NV Map.\r
 \r
 **/\r
 VOID\r
@@ -778,10 +778,8 @@ DiscardChangeHandler (
 }\r
 \r
 /**\r
-  Initialize the Boot Maintenance Utitliy\r
-\r
+  Initialize the Boot Maintenance Utitliy.\r
 \r
-  @param VOID            EDES_TODO: Add parameter description\r
 \r
   @retval  EFI_SUCCESS      utility ended successfully\r
   @retval  others           contain some errors\r
@@ -803,7 +801,7 @@ InitializeBM (
   //\r
   // Create CallbackData structures for Driver Callback\r
   //\r
-  BmmCallbackInfo = EfiAllocateZeroPool (sizeof (BMM_CALLBACK_DATA));\r
+  BmmCallbackInfo = AllocateZeroPool (sizeof (BMM_CALLBACK_DATA));\r
   if (BmmCallbackInfo == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -811,9 +809,9 @@ InitializeBM (
   //\r
   // Create LoadOption in BmmCallbackInfo for Driver Callback\r
   //\r
-  Ptr = EfiAllocateZeroPool (sizeof (BM_LOAD_CONTEXT) + sizeof (BM_FILE_CONTEXT) + sizeof (BM_HANDLE_CONTEXT) + sizeof (BM_MENU_ENTRY));\r
-  if (!Ptr) {\r
-    SafeFreePool (BmmCallbackInfo);\r
+  Ptr = AllocateZeroPool (sizeof (BM_LOAD_CONTEXT) + sizeof (BM_FILE_CONTEXT) + sizeof (BM_HANDLE_CONTEXT) + sizeof (BM_MENU_ENTRY));\r
+  if (Ptr == NULL) {\r
+    FreePool (BmmCallbackInfo);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
@@ -917,10 +915,10 @@ InitializeBM (
   // Allocate space for creation of Buffer\r
   //\r
   gUpdateData.BufferSize = UPDATE_DATA_SIZE;\r
-  gUpdateData.Data = EfiAllocateZeroPool (UPDATE_DATA_SIZE);\r
+  gUpdateData.Data = AllocateZeroPool (UPDATE_DATA_SIZE);\r
   if (gUpdateData.Data == NULL) {\r
-    SafeFreePool (BmmCallbackInfo->LoadContext);\r
-    SafeFreePool (BmmCallbackInfo);\r
+    FreePool (BmmCallbackInfo->LoadContext);\r
+    FreePool (BmmCallbackInfo);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
@@ -1022,20 +1020,20 @@ InitializeBM (
 \r
   FreeAllMenu ();\r
 \r
-  SafeFreePool (BmmCallbackInfo->LoadContext);\r
-  SafeFreePool (BmmCallbackInfo);\r
-  SafeFreePool (gUpdateData.Data);\r
+  FreePool (BmmCallbackInfo->LoadContext);\r
+  FreePool (BmmCallbackInfo);\r
+  FreePool (gUpdateData.Data);\r
   gUpdateData.Data = NULL;\r
 \r
   return Status;\r
 }\r
 \r
 /**\r
-  EDES_TODO: Add function description\r
+  Initialized all Menu Option List.\r
 \r
-  @param CallbackData    EDES_TODO: Add parameter description\r
+  @param CallbackData    The BMM context data.\r
 \r
-  @return EDES_TODO: Add description for return value\r
+  \r
 \r
 **/\r
 VOID\r
@@ -1060,11 +1058,11 @@ InitAllMenu (
 }\r
 \r
 /**\r
-  EDES_TODO: Add function description\r
+  Free up all Menu Option list.\r
 \r
-  @param VOID            EDES_TODO: Add parameter description\r
+  \r
 \r
-  @return EDES_TODO: Add description for return value\r
+  \r
 \r
 **/\r
 VOID\r
@@ -1085,9 +1083,9 @@ FreeAllMenu (
   Intialize all the string depositories.\r
 \r
 \r
-  @param VOID            EDES_TODO: Add parameter description\r
+  \r
 \r
-           EDES_TODO: Description incomplete  None.\r
+  \r
 \r
 **/\r
 VOID\r
@@ -1096,7 +1094,7 @@ InitializeStringDepository (
   )\r
 {\r
   STRING_DEPOSITORY *StringDepository;\r
-  StringDepository              = EfiAllocateZeroPool (sizeof (STRING_DEPOSITORY) * STRING_DEPOSITORY_NUMBER);\r
+  StringDepository              = AllocateZeroPool (sizeof (STRING_DEPOSITORY) * STRING_DEPOSITORY_NUMBER);\r
   FileOptionStrDepository       = StringDepository++;\r
   ConsoleOptionStrDepository    = StringDepository++;\r
   BootOptionStrDepository       = StringDepository++;\r
@@ -1110,8 +1108,8 @@ InitializeStringDepository (
   Fetch a usable string node from the string depository and return the string token.\r
 \r
 \r
-  @param CallbackData    EDES_TODO: Add parameter description\r
-  @param StringDepository - Pointer of the string depository.\r
+  @param CallbackData    The BMM context data.\r
+  @param StringDepository  The string repository.\r
 \r
   @retval  EFI_STRING_ID           String token.\r
 \r
@@ -1136,7 +1134,7 @@ GetStringTokenFromDepository (
     //\r
     // If there is no usable node in the list, update the list.\r
     //\r
-    NextListNode = EfiAllocateZeroPool (sizeof (STRING_LIST_NODE));\r
+    NextListNode = AllocateZeroPool (sizeof (STRING_LIST_NODE));\r
 \r
     HiiLibNewString (CallbackData->BmmHiiHandle, &(NextListNode->StringToken), L" ");\r
     ASSERT (NextListNode->StringToken != 0);\r
@@ -1159,9 +1157,9 @@ GetStringTokenFromDepository (
   Reclaim string depositories by moving the current node pointer to list head..\r
 \r
 \r
-  @param VOID            EDES_TODO: Add parameter description\r
+   \r
 \r
-           EDES_TODO: Description incomplete  None.\r
+  \r
 \r
 **/\r
 VOID\r
@@ -1183,9 +1181,9 @@ ReclaimStringDepository (
   Release resource for all the string depositories.\r
 \r
 \r
-  @param VOID            EDES_TODO: Add parameter description\r
+  \r
 \r
-           EDES_TODO: Description incomplete  None.\r
+  \r
 \r
 **/\r
 VOID\r
@@ -1207,7 +1205,7 @@ CleanUpStringDepository (
     CurrentListNode = StringDepository->ListHead;\r
     for (NodeIndex = 0; NodeIndex < StringDepository->TotalNodeNumber; NodeIndex++) {\r
       NextListNode = CurrentListNode->Next;\r
-      SafeFreePool (CurrentListNode);\r
+      FreePool (CurrentListNode);\r
       CurrentListNode = NextListNode;\r
     }\r
 \r
@@ -1216,16 +1214,17 @@ CleanUpStringDepository (
   //\r
   // Release string depository.\r
   //\r
-  SafeFreePool (FileOptionStrDepository);\r
+  FreePool (FileOptionStrDepository);\r
 }\r
 \r
 /**\r
   Start boot maintenance manager\r
 \r
 \r
-  @param VOID            EDES_TODO: Add parameter description\r
+  \r
 \r
-  @return EDES_TODO: Add description for return value\r
+  @retval EFI_SUCCESS If BMM is invoked successfully.\r
+  @return Other value if BMM return unsuccessfully.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1250,21 +1249,11 @@ BdsStartBootMaint (
   //\r
   BdsLibEnumerateAllBootOption (&BdsBootOptionList);\r
 \r
-  //\r
-  // Drop the TPL level from TPL_APPLICATION to TPL_APPLICATION\r
-  //\r
-  gBS->RestoreTPL (TPL_APPLICATION);\r
-\r
   //\r
   // Init the BMM\r
   //\r
   Status = InitializeBM ();\r
 \r
-  //\r
-  // Raise the TPL level back to TPL_APPLICATION\r
-  //\r
-  gBS->RaiseTPL (TPL_APPLICATION);\r
-\r
   return Status;\r
 }\r
 \r
@@ -1272,9 +1261,11 @@ BdsStartBootMaint (
   Dispatch BMM formset and FileExplorer formset.\r
 \r
 \r
-  @param CallbackData    EDES_TODO: Add parameter description\r
+  @param CallbackData    The BMM context data.\r
 \r
-  @return EDES_TODO: Add description for return value\r
+  @retval EFI_SUCCESS If function complete successfully.\r
+  @return Other value if the Setup Browser process BMM's pages and\r
+           return unsuccessfully.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1335,3 +1326,58 @@ FormSetDispatcher (
   return Status;\r
 }\r
 \r
+\r
+/**\r
+  Deletete the Boot Option from EFI Variable. The Boot Order Arrray\r
+  is also updated.\r
+\r
+  @param OptionNumber    EDES_TODO: Add parameter description\r
+  @param BootOrder       The Boot Order array.\r
+  @param BootOrderSize   The size of the Boot Order Array.\r
+\r
+  @return Other value if the Boot Option specified by OptionNumber is not deleteed succesfully.\r
+  @retval EFI_SUCCESS    If function return successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+BdsDeleteBootOption (\r
+  IN UINTN                       OptionNumber,\r
+  IN OUT UINT16                  *BootOrder,\r
+  IN OUT UINTN                   *BootOrderSize\r
+  )\r
+{\r
+  UINT16      BootOption[100];\r
+  UINTN       Index;\r
+  EFI_STATUS  Status;\r
+  UINTN       Index2Del;\r
+\r
+  Status    = EFI_SUCCESS;\r
+  Index2Del = 0;\r
+\r
+  UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", OptionNumber);\r
+  Status = EfiLibDeleteVariable (BootOption, &gEfiGlobalVariableGuid);\r
+  //\r
+  // adjust boot order array\r
+  //\r
+  for (Index = 0; Index < *BootOrderSize / sizeof (UINT16); Index++) {\r
+    if (BootOrder[Index] == OptionNumber) {\r
+      Index2Del = Index;\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (Index != *BootOrderSize / sizeof (UINT16)) {\r
+    for (Index = 0; Index < *BootOrderSize / sizeof (UINT16) - 1; Index++) {\r
+      if (Index >= Index2Del) {\r
+        BootOrder[Index] = BootOrder[Index + 1];\r
+      }\r
+    }\r
+\r
+    *BootOrderSize -= sizeof (UINT16);\r
+  }\r
+\r
+  return Status;\r
+\r
+}\r
+\r
+\r