]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
Remove the RT attribute for HDDP variable and validate the variable content before...
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GenericBdsLib / BdsBoot.c
index c04c586f50d7ad2bc8e16e832754b3f6642373ba..de69a04b04be9b1bda379f5c33b5f220e0b93a53 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   BDS Lib functions which relate with create or process the boot option.\r
 \r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, 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
@@ -40,7 +40,7 @@ GenericBdsLibConstructor (
 \r
   gBdsLibStringPackHandle = HiiAddPackages (\r
                               &gBdsLibStringPackageGuid,\r
-                              &ImageHandle,\r
+                              ImageHandle,\r
                               GenericBdsLibStrings,\r
                               NULL\r
                               );\r
@@ -82,6 +82,10 @@ BdsDeleteBootOption (
                   0,\r
                   NULL\r
                   );\r
+  //\r
+  // Deleting variable with existing variable implementation shouldn't fail.\r
+  //\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // adjust boot order array\r
@@ -517,23 +521,23 @@ BdsDeleteAllInvalidLegacyBootOptions (
     return Status;\r
   }\r
 \r
-  LegacyBios->GetBbsInfo (\r
-                LegacyBios,\r
-                &HddCount,\r
-                &LocalHddInfo,\r
-                &BbsCount,\r
-                &LocalBbsTable\r
-                );\r
-\r
   BootOrder = BdsLibGetVariableAndSize (\r
                 L"BootOrder",\r
                 &gEfiGlobalVariableGuid,\r
                 &BootOrderSize\r
                 );\r
   if (BootOrder == NULL) {\r
-    BootOrderSize = 0;\r
+    return EFI_NOT_FOUND;\r
   }\r
 \r
+  LegacyBios->GetBbsInfo (\r
+                LegacyBios,\r
+                &HddCount,\r
+                &LocalHddInfo,\r
+                &BbsCount,\r
+                &LocalBbsTable\r
+                );\r
+\r
   Index = 0;\r
   while (Index < BootOrderSize / sizeof (UINT16)) {\r
     UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);\r
@@ -626,9 +630,11 @@ BdsDeleteAllInvalidLegacyBootOptions (
                   BootOrderSize,\r
                   BootOrder\r
                   );\r
-  if (BootOrder != NULL) {\r
-    FreePool (BootOrder);\r
-  }\r
+  //\r
+  // Shrinking variable with existing variable implementation shouldn't fail.\r
+  //\r
+  ASSERT_EFI_ERROR (Status);\r
+  FreePool (BootOrder);\r
 \r
   return Status;\r
 }\r
@@ -857,11 +863,10 @@ BdsAddNonExistingLegacyBootOptions (
                 &BootOrder,\r
                 &BootOrderSize\r
                 );\r
-      if (EFI_ERROR (Status)) {\r
-        break;\r
+      if (!EFI_ERROR (Status)) {\r
+        BbsIndex     = Index;\r
+        OptionNumber = BootOrder[BootOrderSize / sizeof (UINT16) - 1];\r
       }\r
-      BbsIndex     = Index;\r
-      OptionNumber = BootOrder[BootOrderSize / sizeof (UINT16) - 1];\r
     }\r
 \r
     ASSERT (BbsIndex == Index);\r
@@ -2229,10 +2234,6 @@ BdsLibBootViaBootOption (
   LIST_ENTRY                TempBootLists;\r
   EFI_BOOT_LOGO_PROTOCOL    *BootLogo;\r
 \r
-  PERF_CODE (\r
-    AllocateMemoryForPerformanceData ();\r
-  );\r
-\r
   *ExitDataSize = 0;\r
   *ExitData     = NULL;\r
 \r
@@ -2269,7 +2270,7 @@ BdsLibBootViaBootOption (
     // In this case, "BootCurrent" is not created.\r
     // Only create the BootCurrent variable when it points to a valid Boot#### variable.\r
     //\r
-    gRT->SetVariable (\r
+    SetVariableAndReportStatusCodeOnError (\r
           L"BootCurrent",\r
           &gEfiGlobalVariableGuid,\r
           EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
@@ -2467,13 +2468,14 @@ Done:
 \r
   //\r
   // Clear Boot Current\r
+  // Deleting variable with current implementation shouldn't fail.\r
   //\r
   gRT->SetVariable (\r
         L"BootCurrent",\r
         &gEfiGlobalVariableGuid,\r
         EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
         0,\r
-        &Option->BootCurrent\r
+        NULL\r
         );\r
 \r
   return Status;\r
@@ -2522,11 +2524,28 @@ BdsExpandPartitionPartialDevicePathToFull (
   // If exist, search the front path which point to partition node in the variable instants.\r
   // If fail to find or HD_BOOT_DEVICE_PATH_VARIABLE_NAME not exist, reconnect all and search in all system\r
   //\r
-  CachedDevicePath = BdsLibGetVariableAndSize (\r
-                      HD_BOOT_DEVICE_PATH_VARIABLE_NAME,\r
-                      &gHdBootDevicePathVariablGuid,\r
-                      &CachedDevicePathSize\r
-                      );\r
+  GetVariable2 (\r
+    HD_BOOT_DEVICE_PATH_VARIABLE_NAME,\r
+    &gHdBootDevicePathVariablGuid,\r
+    (VOID **) &CachedDevicePath,\r
+    &CachedDevicePathSize\r
+    );\r
+\r
+  //\r
+  // Delete the invalid HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable.\r
+  //\r
+  if ((CachedDevicePath != NULL) && !IsDevicePathValid (CachedDevicePath, CachedDevicePathSize)) {\r
+    FreePool (CachedDevicePath);\r
+    CachedDevicePath = NULL;\r
+    Status = gRT->SetVariable (\r
+                    HD_BOOT_DEVICE_PATH_VARIABLE_NAME,\r
+                    &gHdBootDevicePathVariablGuid,\r
+                    0,\r
+                    0,\r
+                    NULL\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
 \r
   if (CachedDevicePath != NULL) {\r
     TempNewDevicePath = CachedDevicePath;\r
@@ -2584,11 +2603,12 @@ BdsExpandPartitionPartialDevicePathToFull (
         FreePool (TempNewDevicePath);\r
         //\r
         // Save the matching Device Path so we don't need to do a connect all next time\r
+        // Failure to set the variable only impacts the performance when next time expanding the short-form device path.\r
         //\r
         Status = gRT->SetVariable (\r
                         HD_BOOT_DEVICE_PATH_VARIABLE_NAME,\r
                         &gHdBootDevicePathVariablGuid,\r
-                        EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+                        EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
                         GetDevicePathSize (CachedDevicePath),\r
                         CachedDevicePath\r
                         );\r
@@ -2641,17 +2661,16 @@ BdsExpandPartitionPartialDevicePathToFull (
           TempNewDevicePath = CachedDevicePath;\r
           CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, BlockIoDevicePath);\r
           FreePool(TempNewDevicePath);\r
+        }\r
 \r
-          TempNewDevicePath = CachedDevicePath;\r
-          CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath);\r
-          if (TempNewDevicePath != NULL) {\r
-            FreePool(TempNewDevicePath);\r
-          }\r
-        } else {\r
+        if (CachedDevicePath != NULL) {\r
           TempNewDevicePath = CachedDevicePath;\r
           CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath);\r
           FreePool(TempNewDevicePath);\r
+        } else {\r
+          CachedDevicePath = DuplicateDevicePath (BlockIoDevicePath);\r
         }\r
+\r
         //\r
         // Here limit the device path instance number to 12, which is max number for a system support 3 IDE controller\r
         // If the user try to boot many OS in different HDs or partitions, in theory, \r
@@ -2683,11 +2702,12 @@ BdsExpandPartitionPartialDevicePathToFull (
 \r
       //\r
       // Save the matching Device Path so we don't need to do a connect all next time\r
+      // Failure to set the variable only impacts the performance when next time expanding the short-form device path.\r
       //\r
       Status = gRT->SetVariable (\r
                       HD_BOOT_DEVICE_PATH_VARIABLE_NAME,\r
                       &gHdBootDevicePathVariablGuid,\r
-                      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+                      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
                       GetDevicePathSize (CachedDevicePath),\r
                       CachedDevicePath\r
                       );\r
@@ -2892,6 +2912,10 @@ BdsLibDeleteOptionFromHandle (
                   BootOrderSize,\r
                   BootOrder\r
                   );\r
+  //\r
+  // Shrinking variable with existing variable implementation shouldn't fail.\r
+  //\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   FreePool (BootOrder);\r
 \r
@@ -2990,6 +3014,10 @@ BdsDeleteAllInvalidEfiBootOption (
                       NULL\r
                       );\r
       //\r
+      // Deleting variable with current variable implementation shouldn't fail.\r
+      //\r
+      ASSERT_EFI_ERROR (Status);\r
+      //\r
       // Mark this boot option in boot order as deleted\r
       //\r
       BootOrder[Index] = 0xffff;\r
@@ -3017,6 +3045,10 @@ BdsDeleteAllInvalidEfiBootOption (
                   Index2 * sizeof (UINT16),\r
                   BootOrder\r
                   );\r
+  //\r
+  // Shrinking variable with current variable implementation shouldn't fail.\r
+  //\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   FreePool (BootOrder);\r
 \r
@@ -3140,7 +3172,9 @@ BdsLibEnumerateAllBootOption (
         AsciiStrSize (PlatLang),\r
         PlatLang\r
         );\r
-      ASSERT_EFI_ERROR (Status);\r
+      //\r
+      // Failure to set the variable only impacts the performance next time enumerating the boot options.\r
+      //\r
 \r
       if (LastLang != NULL) {\r
         FreePool (LastLang);\r
@@ -3483,6 +3517,7 @@ BdsLibBootNext (
   VOID\r
   )\r
 {\r
+  EFI_STATUS        Status;\r
   UINT16            *BootNext;\r
   UINTN             BootNextSize;\r
   CHAR16            Buffer[20];\r
@@ -3507,13 +3542,17 @@ BdsLibBootNext (
   // Clear the boot next variable first\r
   //\r
   if (BootNext != NULL) {\r
-    gRT->SetVariable (\r
-          L"BootNext",\r
-          &gEfiGlobalVariableGuid,\r
-          EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
-          0,\r
-          BootNext\r
-          );\r
+    Status = gRT->SetVariable (\r
+                    L"BootNext",\r
+                    &gEfiGlobalVariableGuid,\r
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+                    0,\r
+                    NULL\r
+                    );\r
+    //\r
+    // Deleting variable with current variable implementation shouldn't fail.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
 \r
     //\r
     // Start to build the boot option and try to boot\r