]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c
Follow UEFI spec, set TimeOut and HwErrRecSupport variable by EFI variable service...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / BdsEntry.c
index dcaa488894af9b94f8b0ca3aef6c0ea2949ee285..6eaec886f2317d484021538260a6ba5b0dfc8897 100644 (file)
@@ -5,8 +5,8 @@
   After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be invoked\r
   to enter BDS phase.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2004 - 2013, 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -38,11 +38,6 @@ EFI_BDS_ARCH_PROTOCOL  gBds = {
 \r
 UINT16                          *mBootNext = NULL;\r
 \r
-EFI_HANDLE                      mBdsImageHandle;\r
-\r
-extern EFI_STATUS BdsMemoryTest (EXTENDMEM_COVERAGE_LEVEL Level);\r
-extern EFI_STATUS ProcessCapsules (EFI_BOOT_MODE BootMode);\r
-\r
 /**\r
 \r
   Install Boot Device Selection Protocol\r
@@ -64,8 +59,6 @@ BdsInitialize (
 {\r
   EFI_STATUS  Status;\r
 \r
-  mBdsImageHandle = ImageHandle;\r
-\r
   //\r
   // Install protocol interface\r
   //\r
@@ -79,6 +72,24 @@ BdsInitialize (
   return Status;\r
 }\r
 \r
+\r
+/**\r
+  An empty function to pass error checking of CreateEventEx ().\r
+\r
+  @param  Event                 Event whose notification function is being invoked.\r
+  @param  Context               Pointer to the notification function's context,\r
+                                which is implementation-dependent.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BdsEmptyCallbackFunction (\r
+  IN EFI_EVENT                Event,\r
+  IN VOID                     *Context\r
+  )\r
+{\r
+}\r
+\r
 /**\r
 \r
   This function attempts to boot for the boot order specified\r
@@ -100,12 +111,14 @@ BdsBootDeviceSelect (
   CHAR16            Buffer[20];\r
   BOOLEAN           BootNextExist;\r
   LIST_ENTRY        *LinkBootNext;\r
+  EFI_EVENT         ConnectConInEvent;\r
 \r
   //\r
   // Got the latest boot option\r
   //\r
   BootNextExist = FALSE;\r
   LinkBootNext  = NULL;\r
+  ConnectConInEvent = NULL;\r
   InitializeListHead (&BootLists);\r
 \r
   //\r
@@ -113,6 +126,23 @@ BdsBootDeviceSelect (
   //\r
   ZeroMem (Buffer, sizeof (Buffer));\r
 \r
+  //\r
+  // Create Event to signal ConIn connection request\r
+  //\r
+  if (PcdGetBool (PcdConInConnectOnDemand)) {\r
+    Status = gBS->CreateEventEx (\r
+                    EVT_NOTIFY_SIGNAL,\r
+                    TPL_CALLBACK,\r
+                    BdsEmptyCallbackFunction,\r
+                    NULL,\r
+                    &gConnectConInEventGuid,\r
+                    &ConnectConInEvent\r
+                    );\r
+    if (EFI_ERROR(Status)) {\r
+      ConnectConInEvent = NULL;\r
+    }\r
+  }\r
+\r
   if (mBootNext != NULL) {\r
     //\r
     // Indicate we have the boot next variable, so this time\r
@@ -150,6 +180,17 @@ BdsBootDeviceSelect (
   // Parse the boot order to get boot option\r
   //\r
   BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");\r
+\r
+  //\r
+  // When we didn't have chance to build boot option variables in the first \r
+  // full configuration boot (e.g.: Reset in the first page or in Device Manager),\r
+  // we have no boot options in the following mini configuration boot.\r
+  // Give the last chance to enumerate the boot options.\r
+  //\r
+  if (IsListEmpty (&BootLists)) {\r
+    BdsLibEnumerateAllBootOption (&BootLists);\r
+  }\r
+\r
   Link = BootLists.ForwardLink;\r
 \r
   //\r
@@ -167,6 +208,13 @@ BdsBootDeviceSelect (
     // Check the boot option list first\r
     //\r
     if (Link == &BootLists) {\r
+      //\r
+      // When LazyConIn enabled, signal connect ConIn event before enter UI\r
+      //\r
+      if (PcdGetBool (PcdConInConnectOnDemand) && ConnectConInEvent != NULL) {\r
+        gBS->SignalEvent (ConnectConInEvent);\r
+      }\r
+\r
       //\r
       // There are two ways to enter here:\r
       // 1. There is no active boot option, give user chance to\r
@@ -194,7 +242,7 @@ BdsBootDeviceSelect (
     //\r
     if (!IS_LOAD_OPTION_TYPE (BootOption->Attribute, LOAD_OPTION_ACTIVE)) {\r
       //\r
-      // skip the header of the link list, becuase it has no boot option\r
+      // skip the header of the link list, because it has no boot option\r
       //\r
       Link = Link->ForwardLink;\r
       continue;\r
@@ -210,12 +258,18 @@ BdsBootDeviceSelect (
       //\r
       BdsLibConnectDevicePath (BootOption->DevicePath);\r
     }\r
+\r
+    //\r
+    // Restore to original mode before launching boot option.\r
+    //\r
+    BdsSetConsoleMode (FALSE);\r
+    \r
     //\r
     // All the driver options should have been processed since\r
     // now boot will be performed.\r
     //\r
     Status = BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);\r
-    if (EFI_ERROR (Status)) {\r
+    if (Status != EFI_SUCCESS) {\r
       //\r
       // Call platform action to indicate the boot fail\r
       //\r
@@ -238,11 +292,19 @@ BdsBootDeviceSelect (
       // Boot success, then stop process the boot order, and\r
       // present the boot manager menu, front page\r
       //\r
+\r
+      //\r
+      // When LazyConIn enabled, signal connect ConIn Event before enter UI\r
+      //\r
+      if (PcdGetBool (PcdConInConnectOnDemand) && ConnectConInEvent != NULL) {\r
+        gBS->SignalEvent (ConnectConInEvent);\r
+      }\r
+\r
       Timeout = 0xffff;\r
       PlatformBdsEnterFrontPage (Timeout, FALSE);\r
 \r
       //\r
-      // Rescan the boot option list, avoid pertential risk of the boot\r
+      // Rescan the boot option list, avoid potential risk of the boot\r
       // option change in front page\r
       //\r
       if (BootNextExist) {\r
@@ -264,6 +326,119 @@ BdsBootDeviceSelect (
 \r
 }\r
 \r
+/**\r
+\r
+  Validate input console variable data. \r
+\r
+  If found the device path is not a valid device path, remove the variable.\r
+  \r
+  @param VariableName             Input console variable name.\r
+\r
+**/\r
+VOID\r
+BdsFormalizeConsoleVariable (\r
+  IN  CHAR16          *VariableName\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  UINTN                     VariableSize;\r
+  EFI_STATUS                Status;\r
+\r
+  DevicePath = BdsLibGetVariableAndSize (\r
+                      VariableName,\r
+                      &gEfiGlobalVariableGuid,\r
+                      &VariableSize\r
+                      );\r
+  if ((DevicePath != NULL) && !IsDevicePathValid (DevicePath, VariableSize)) { \r
+    Status = gRT->SetVariable (\r
+                    VariableName,\r
+                    &gEfiGlobalVariableGuid,\r
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+                    0,\r
+                    NULL\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+}\r
+\r
+/**\r
+\r
+  Formalize Bds global variables. \r
+\r
+ 1. For ConIn/ConOut/ConErr, if found the device path is not a valid device path, remove the variable.\r
+ 2. For OsIndicationsSupported, Create a BS/RT/UINT64 variable to report caps \r
+ 3. Delete OsIndications variable if it is not NV/BS/RT UINT64\r
+ Item 3 is used to solve case when OS corrupts OsIndications. Here simply delete this NV variable.\r
\r
+**/\r
+VOID \r
+BdsFormalizeEfiGlobalVariable (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  UINT64     OsIndicationSupport;\r
+  UINT64     OsIndication;\r
+  UINTN      DataSize;\r
+  UINT32     Attributes;\r
+  \r
+  //\r
+  // Validate Console variable.\r
+  //\r
+  BdsFormalizeConsoleVariable (L"ConIn");\r
+  BdsFormalizeConsoleVariable (L"ConOut");\r
+  BdsFormalizeConsoleVariable (L"ErrOut");\r
+\r
+  //\r
+  // OS indicater support variable\r
+  //\r
+  OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;\r
+  Status = gRT->SetVariable (\r
+                  L"OsIndicationsSupported",\r
+                  &gEfiGlobalVariableGuid,\r
+                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                  sizeof(UINT64),\r
+                  &OsIndicationSupport\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // If OsIndications is invalid, remove it.\r
+  // Invalid case\r
+  //   1. Data size != UINT64\r
+  //   2. OsIndication value inconsistence\r
+  //   3. OsIndication attribute inconsistence\r
+  //\r
+  OsIndication = 0;\r
+  Attributes = 0;\r
+  DataSize = sizeof(UINT64);\r
+  Status = gRT->GetVariable (\r
+                  L"OsIndications",\r
+                  &gEfiGlobalVariableGuid,\r
+                  &Attributes,\r
+                  &DataSize,\r
+                  &OsIndication\r
+                  );\r
+\r
+  if (!EFI_ERROR(Status)) {\r
+    if (DataSize != sizeof(UINT64) ||\r
+        (OsIndication & ~OsIndicationSupport) != 0 ||\r
+        Attributes != (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE)){\r
+\r
+      DEBUG ((EFI_D_ERROR, "Unformalized OsIndications variable exists. Delete it\n"));\r
+      Status = gRT->SetVariable (\r
+                      L"OsIndications",\r
+                      &gEfiGlobalVariableGuid,\r
+                      Attributes,\r
+                      0,\r
+                      &OsIndication\r
+                      );\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+  }\r
+\r
+}\r
+\r
 /**\r
 \r
   Service routine for BdsInstance->Entry(). Devices are connected, the\r
@@ -282,6 +457,8 @@ BdsEntry (
   LIST_ENTRY                      BootOptionList;\r
   UINTN                           BootNextSize;\r
   CHAR16                          *FirmwareVendor;\r
+  EFI_STATUS                      Status;\r
+  UINT16                          BootTimeOut;\r
 \r
   //\r
   // Insert the performance probe\r
@@ -311,8 +488,22 @@ BdsEntry (
   //\r
   // Fixup Tasble CRC after we updated Firmware Vendor and Revision\r
   //\r
+  gST->Hdr.CRC32 = 0;\r
   gBS->CalculateCrc32 ((VOID *)gST, sizeof(EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);\r
 \r
+  //\r
+  // Validate Variable.\r
+  //\r
+  BdsFormalizeEfiGlobalVariable();\r
+\r
+  //\r
+  // Report Status Code to indicate connecting drivers will happen\r
+  //\r
+  REPORT_STATUS_CODE (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_BEGIN_CONNECTING_DRIVERS)\r
+    );\r
+\r
   //\r
   // Do the platform init, can be customized by OEM/IBV\r
   //\r
@@ -321,6 +512,25 @@ BdsEntry (
 \r
   InitializeHwErrRecSupport();\r
 \r
+  //\r
+  // Initialize L"Timeout" EFI global variable.\r
+  //\r
+  BootTimeOut = PcdGet16 (PcdPlatformBootTimeOut);\r
+  if (BootTimeOut != 0xFFFF) {\r
+    //\r
+    // If time out value equal 0xFFFF, no need set to 0xFFFF to variable area because UEFI specification\r
+    // define same behavior between no value or 0xFFFF value for L"Timeout".\r
+    //\r
+    Status = gRT->SetVariable (\r
+                    L"Timeout",\r
+                    &gEfiGlobalVariableGuid,\r
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+                    sizeof (UINT16),\r
+                    &BootTimeOut\r
+                    );\r
+    ASSERT_EFI_ERROR(Status);\r
+  }\r
+\r
   //\r
   // bugbug: platform specific code\r
   // Initialize the platform specific string and language\r
@@ -350,7 +560,7 @@ BdsEntry (
   //\r
   // Setup some platform policy here\r
   //\r
-  PlatformBdsPolicyBehavior (&DriverOptionList, &BootOptionList, ProcessCapsules, BdsMemoryTest);\r
+  PlatformBdsPolicyBehavior (&DriverOptionList, &BootOptionList, BdsProcessCapsules, BdsMemoryTest);\r
   PERF_END (NULL, "PlatformBds", "BDS", 0);\r
 \r
   //\r