]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
Create boot option for all block IO devices no matter what the device path looks...
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GenericBdsLib / BdsBoot.c
index 29afe45f351c0d4435c84a74c8336f8fb77fa220..b41ce79d50bba5268746be21958e266212c1d822 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 - 2013, 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
@@ -2265,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
@@ -2463,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
@@ -2518,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
@@ -2580,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
@@ -2678,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
@@ -2887,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
@@ -2985,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
@@ -3012,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
@@ -3135,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
@@ -3244,6 +3283,7 @@ BdsLibEnumerateAllBootOption (
         break;\r
 \r
       case BDS_EFI_MESSAGE_MISC_BOOT:\r
+      default:\r
         if (MiscNumber != 0) {\r
           UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)), MiscNumber);\r
         } else {\r
@@ -3252,9 +3292,6 @@ BdsLibEnumerateAllBootOption (
         BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
         MiscNumber++;\r
         break;\r
-\r
-      default:\r
-        break;\r
       }\r
     }\r
   }\r
@@ -3478,6 +3515,7 @@ BdsLibBootNext (
   VOID\r
   )\r
 {\r
+  EFI_STATUS        Status;\r
   UINT16            *BootNext;\r
   UINTN             BootNextSize;\r
   CHAR16            Buffer[20];\r
@@ -3502,13 +3540,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