]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/BdsDxe/BdsEntry.c
MdeModulePkg/BootGraphicsResourceDxe: Add Boot Logo 2 Protocol
[mirror_edk2.git] / MdeModulePkg / Universal / BdsDxe / BdsEntry.c
index 98b393109389d74a1fe824562afe845acc6535a0..3191a986304b2aa2752ecff696b8736c8943fd3b 100644 (file)
@@ -5,7 +5,7 @@
   After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be invoked\r
   to enter BDS phase.\r
 \r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
 This program and the accompanying materials\r
@@ -369,6 +369,11 @@ BootBootOptions (
 {\r
   UINTN                              Index;\r
 \r
+  //\r
+  // Report Status Code to indicate BDS starts attempting booting from the UEFI BootOrder list.\r
+  //\r
+  REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_ATTEMPT_BOOT_ORDER_EVENT));\r
+\r
   //\r
   // Attempt boot each boot option\r
   //\r
@@ -630,54 +635,52 @@ BdsFormalizeEfiGlobalVariable (
 }\r
 \r
 /**\r
+  Enter an infinite loop of calling the Boot Manager Menu.\r
 \r
-  Allocate a block of memory that will contain performance data to OS.\r
+  This is a last resort alternative to BdsEntry() giving up for good. This\r
+  function never returns.\r
 \r
+  @param[in] BootManagerMenu  The EFI_BOOT_MANAGER_LOAD_OPTION located and/or\r
+                              created by the EfiBootManagerGetBootManagerMenu()\r
+                              call in BdsEntry().\r
 **/\r
 VOID\r
-BdsAllocateMemoryForPerformanceData (\r
-  VOID\r
+BdsBootManagerMenuLoop (\r
+  IN EFI_BOOT_MANAGER_LOAD_OPTION *BootManagerMenu\r
   )\r
 {\r
-  EFI_STATUS                    Status;\r
-  EFI_PHYSICAL_ADDRESS          AcpiLowMemoryBase;\r
-  EDKII_VARIABLE_LOCK_PROTOCOL  *VariableLock;\r
-\r
-  AcpiLowMemoryBase = 0x0FFFFFFFFULL;\r
+  EFI_INPUT_KEY Key;\r
 \r
   //\r
-  // Allocate a block of memory that will contain performance data to OS.\r
+  // Normally BdsDxe does not print anything to the system console, but this is\r
+  // a last resort -- the end-user will likely not see any DEBUG messages\r
+  // logged in this situation.\r
   //\r
-  Status = gBS->AllocatePages (\r
-                  AllocateMaxAddress,\r
-                  EfiReservedMemoryType,\r
-                  EFI_SIZE_TO_PAGES (PERF_DATA_MAX_LENGTH),\r
-                  &AcpiLowMemoryBase\r
-                  );\r
-  if (!EFI_ERROR (Status)) {\r
-    //\r
-    // Save the pointer to variable for use in S3 resume.\r
-    //\r
-    Status = BdsDxeSetVariableAndReportStatusCodeOnError (\r
-               L"PerfDataMemAddr",\r
-               &gPerformanceProtocolGuid,\r
-               EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-               sizeof (EFI_PHYSICAL_ADDRESS),\r
-               &AcpiLowMemoryBase\r
-               );\r
-    if (EFI_ERROR (Status)) {\r
-      DEBUG ((EFI_D_ERROR, "[Bds] PerfDataMemAddr (%08x) cannot be saved to NV storage.\n", AcpiLowMemoryBase));\r
-    }\r
+  // AsciiPrint() will NULL-check gST->ConOut internally. We check gST->ConIn\r
+  // here to see if it makes sense to request and wait for a keypress.\r
+  //\r
+  if (gST->ConIn != NULL) {\r
+    AsciiPrint (\r
+      "%a: No bootable option or device was found.\n"\r
+      "%a: Press any key to enter the Boot Manager Menu.\n",\r
+      gEfiCallerBaseName,\r
+      gEfiCallerBaseName\r
+      );\r
+    BdsWaitForSingleEvent (gST->ConIn->WaitForKey, 0);\r
+\r
     //\r
-    // Mark L"PerfDataMemAddr" variable to read-only if the Variable Lock protocol exists\r
-    // Still lock it even the variable cannot be saved to prevent it's set by 3rd party code.\r
+    // Drain any queued keys.\r
     //\r
-    Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **) &VariableLock);\r
-    if (!EFI_ERROR (Status)) {\r
-      Status = VariableLock->RequestToLock (VariableLock, L"PerfDataMemAddr", &gPerformanceProtocolGuid);\r
-      ASSERT_EFI_ERROR (Status);\r
+    while (!EFI_ERROR (gST->ConIn->ReadKeyStroke (gST->ConIn, &Key))) {\r
+      //\r
+      // just throw away Key\r
+      //\r
     }\r
   }\r
+\r
+  for (;;) {\r
+    EfiBootManagerBoot (BootManagerMenu);\r
+  }\r
 }\r
 \r
 /**\r
@@ -726,10 +729,6 @@ BdsEntry (
   PERF_START (NULL, "BDS", NULL, 0);\r
   DEBUG ((EFI_D_INFO, "[Bds] Entry...\n"));\r
 \r
-  PERF_CODE (\r
-    BdsAllocateMemoryForPerformanceData ();\r
-  );\r
-\r
   //\r
   // Fill in FirmwareVendor and FirmwareRevision from PCDs\r
   //\r
@@ -803,7 +802,8 @@ BdsEntry (
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Cache and remove the "BootNext" NV variable.\r
+  // Cache the "BootNext" NV variable before calling any PlatformBootManagerLib APIs\r
+  // This could avoid the "BootNext" set by PlatformBootManagerLib be consumed in this boot.\r
   //\r
   GetEfiGlobalVariable2 (EFI_BOOT_NEXT_VARIABLE_NAME, (VOID **) &BootNext, &DataSize);\r
   if (DataSize != sizeof (UINT16)) {\r
@@ -812,17 +812,6 @@ BdsEntry (
     }\r
     BootNext = NULL;\r
   }\r
-  Status = gRT->SetVariable (\r
-                  EFI_BOOT_NEXT_VARIABLE_NAME,\r
-                  &gEfiGlobalVariableGuid,\r
-                  0,\r
-                  0,\r
-                  NULL\r
-                  );\r
-  //\r
-  // Deleting NV variable shouldn't fail unless it doesn't exist.\r
-  //\r
-  ASSERT (Status == EFI_SUCCESS || Status == EFI_NOT_FOUND);\r
 \r
   //\r
   // Initialize the platform language variables\r
@@ -873,6 +862,23 @@ BdsEntry (
     (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_BEGIN_CONNECTING_DRIVERS)\r
     );\r
 \r
+  //\r
+  // Initialize ConnectConIn event before calling platform code.\r
+  //\r
+  if (PcdGetBool (PcdConInConnectOnDemand)) {\r
+    Status = gBS->CreateEventEx (\r
+                    EVT_NOTIFY_SIGNAL,\r
+                    TPL_CALLBACK,\r
+                    BdsDxeOnConnectConInCallBack,\r
+                    NULL,\r
+                    &gConnectConInEventGuid,\r
+                    &gConnectConInEvent\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      gConnectConInEvent = NULL;\r
+    }\r
+  }\r
+\r
   //\r
   // Do the platform init, can be customized by OEM/IBV\r
   // Possible things that can be done in PlatformBootManagerBeforeConsole:\r
@@ -905,21 +911,9 @@ BdsEntry (
   if (PcdGetBool (PcdConInConnectOnDemand)) {\r
     EfiBootManagerConnectConsoleVariable (ConOut);\r
     EfiBootManagerConnectConsoleVariable (ErrOut);\r
-\r
     //\r
-    // Initialize ConnectConIn event\r
+    // Do not connect ConIn devices when lazy ConIn feature is ON.\r
     //\r
-    Status = gBS->CreateEventEx (\r
-                    EVT_NOTIFY_SIGNAL,\r
-                    TPL_CALLBACK,\r
-                    BdsDxeOnConnectConInCallBack,\r
-                    NULL,\r
-                    &gConnectConInEventGuid,\r
-                    &gConnectConInEvent\r
-                    );\r
-    if (EFI_ERROR (Status)) {\r
-      gConnectConInEvent = NULL;\r
-    }\r
   } else {\r
     EfiBootManagerConnectAllDefaultConsoles ();\r
   }\r
@@ -1042,10 +1036,25 @@ BdsEntry (
 \r
     EfiBootManagerHotkeyBoot ();\r
 \r
-    //\r
-    // Boot to "BootNext"\r
-    //\r
     if (BootNext != NULL) {\r
+      //\r
+      // Delete "BootNext" NV variable before transferring control to it to prevent loops.\r
+      //\r
+      Status = gRT->SetVariable (\r
+                      EFI_BOOT_NEXT_VARIABLE_NAME,\r
+                      &gEfiGlobalVariableGuid,\r
+                      0,\r
+                      0,\r
+                      NULL\r
+                      );\r
+      //\r
+      // Deleting NV variable shouldn't fail unless it doesn't exist.\r
+      //\r
+      ASSERT (Status == EFI_SUCCESS || Status == EFI_NOT_FOUND);\r
+\r
+      //\r
+      // Boot to "BootNext"\r
+      //\r
       UnicodeSPrint (BootNextVariableName, sizeof (BootNextVariableName), L"Boot%04x", *BootNext);\r
       Status = EfiBootManagerVariableToLoadOption (BootNextVariableName, &LoadOption);\r
       if (!EFI_ERROR (Status)) {\r
@@ -1073,16 +1082,19 @@ BdsEntry (
     } while (BootSuccess);\r
   }\r
 \r
-  if (BootManagerMenuStatus != EFI_NOT_FOUND) {\r
-    EfiBootManagerFreeLoadOption (&BootManagerMenu);\r
-  }\r
-\r
   if (!BootSuccess) {\r
     LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);\r
     ProcessLoadOptions (LoadOptions, LoadOptionCount);\r
     EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r
   }\r
 \r
+  //\r
+  // If BootManagerMenu is available, fall back to it indefinitely.\r
+  //\r
+  if (BootManagerMenuStatus != EFI_NOT_FOUND) {\r
+    BdsBootManagerMenuLoop (&BootManagerMenu);\r
+  }\r
+\r
   DEBUG ((EFI_D_ERROR, "[Bds] Unable to boot!\n"));\r
   CpuDeadLoop ();\r
 }\r
@@ -1097,8 +1109,7 @@ BdsEntry (
   @param  VendorGuid             A unique identifier for the vendor.\r
   @param  Attributes             Attributes bitmask to set for the variable.\r
   @param  DataSize               The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, \r
-                                 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or \r
-                                 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero \r
+                                 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero\r
                                  causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is \r
                                  set, then a SetVariable() call with a DataSize of zero will not cause any change to \r
                                  the variable value (the timestamp associated with the variable may be updated however \r
@@ -1116,9 +1127,8 @@ BdsEntry (
   @retval EFI_DEVICE_ERROR       The variable could not be retrieved due to a hardware error.\r
   @retval EFI_WRITE_PROTECTED    The variable in question is read-only.\r
   @retval EFI_WRITE_PROTECTED    The variable in question cannot be deleted.\r
-  @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS \r
-                                 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo \r
-                                 does NOT pass the validation check carried out by the firmware.\r
+  @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS\r
+                                 being set, but the AuthInfo does NOT pass the validation check carried out by the firmware.\r
 \r
   @retval EFI_NOT_FOUND          The variable trying to be updated or deleted was not found.\r
 **/\r