]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
Report the setting variable failure to platform through the status code when core...
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GenericBdsLib / BdsBoot.c
index 4b4333bd88bd14574cc97d9c99700da26fcefeef..134833286fcc8933d252e129ca8aaa7d9660d8ed 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
@@ -626,6 +630,10 @@ BdsDeleteAllInvalidLegacyBootOptions (
                   BootOrderSize,\r
                   BootOrder\r
                   );\r
+  //\r
+  // Shrinking variable with existing variable implementation shouldn't fail.\r
+  //\r
+  ASSERT_EFI_ERROR (Status);\r
   if (BootOrder != NULL) {\r
     FreePool (BootOrder);\r
   }\r
@@ -857,11 +865,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 +2236,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 +2272,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
@@ -2278,6 +2281,11 @@ BdsLibBootViaBootOption (
           );\r
   }\r
 \r
+  //\r
+  // Report Status Code to indicate ReadyToBoot event will be signalled\r
+  //\r
+  REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT));\r
+\r
   //\r
   // Signal the EVT_SIGNAL_READY_TO_BOOT event\r
   //\r
@@ -2368,47 +2376,40 @@ BdsLibBootViaBootOption (
       // and get the bootable media handle\r
       //\r
       Handle = BdsLibGetBootableHandle(DevicePath);\r
-      if (Handle == NULL) {\r
-        goto Done;\r
-      }\r
-      //\r
-      // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media\r
-      //  machinename is ia32, ia64, x64, ...\r
-      //\r
-      FilePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME);\r
-      if (FilePath != NULL) {\r
-        REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));\r
-        Status = gBS->LoadImage (\r
-                        TRUE,\r
-                        gImageHandle,\r
-                        FilePath,\r
-                        NULL,\r
-                        0,\r
-                        &ImageHandle\r
-                        );\r
-       if (EFI_ERROR (Status)) {\r
-          //\r
-          // The DevicePath failed, and it's not a valid\r
-          // removable media device.\r
-          //\r
-          goto Done;\r
+      if (Handle != NULL) {\r
+        //\r
+        // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media\r
+        //  machinename is ia32, ia64, x64, ...\r
+        //\r
+        FilePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME);\r
+        if (FilePath != NULL) {\r
+          REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));\r
+          Status = gBS->LoadImage (\r
+                          TRUE,\r
+                          gImageHandle,\r
+                          FilePath,\r
+                          NULL,\r
+                          0,\r
+                          &ImageHandle\r
+                          );\r
         }\r
       }\r
     }\r
-\r
-    if (EFI_ERROR (Status)) {\r
-      //\r
-      // It there is any error from the Boot attempt exit now.\r
-      //\r
-      goto Done;\r
-    }\r
   }\r
   //\r
   // Provide the image with it's load options\r
   //\r
-  if (ImageHandle == NULL) {\r
+  if ((ImageHandle == NULL) || (EFI_ERROR(Status))) {\r
+    //\r
+    // Report Status Code to indicate that the failure to load boot option\r
+    //\r
+    REPORT_STATUS_CODE (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_BOOT_OPTION_LOAD_ERROR)\r
+      );    \r
     goto Done;\r
   }\r
+\r
   Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &ImageInfo);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
@@ -2442,6 +2443,15 @@ BdsLibBootViaBootOption (
 \r
   Status = gBS->StartImage (ImageHandle, ExitDataSize, ExitData);\r
   DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Image Return Status = %r\n", Status));\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Report Status Code to indicate that boot failure\r
+    //\r
+    REPORT_STATUS_CODE (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_BOOT_OPTION_FAILED)\r
+      );\r
+  }\r
 \r
   //\r
   // Clear the Watchdog Timer after the image returns\r
@@ -2460,13 +2470,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
@@ -2577,6 +2588,7 @@ 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
@@ -2634,17 +2646,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
@@ -2676,6 +2687,7 @@ 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
@@ -2885,6 +2897,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
@@ -2983,6 +2999,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
@@ -3010,6 +3030,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
@@ -3133,7 +3157,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
@@ -3476,6 +3502,7 @@ BdsLibBootNext (
   VOID\r
   )\r
 {\r
+  EFI_STATUS        Status;\r
   UINT16            *BootNext;\r
   UINTN             BootNextSize;\r
   CHAR16            Buffer[20];\r
@@ -3500,13 +3527,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