]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
Report the setting variable failure to platform through the status code when core...
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GenericBdsLib / BdsConsole.c
index f9860a24777101c86681c1ac1d5a24a7ef1b0da6..271093eec95c4e884bbdb99d1a2d38335e101038 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   BDS Lib functions which contain all the code to connect console device\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\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
 http://opensource.org/licenses/bsd-license.php\r
@@ -13,12 +13,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 #include "InternalBdsLib.h"\r
-#include "Bmp.h"\r
+#include <IndustryStandard/Bmp.h>\r
+\r
 \r
 /**\r
   Check if we need to save the EFI variable with "ConVarName" as name\r
   as NV type\r
-\r
+  If ConVarName is NULL, then ASSERT().\r
+  \r
   @param ConVarName The name of the EFI variable.\r
 \r
   @retval TRUE    Set the EFI variable as NV type.\r
@@ -31,6 +33,8 @@ IsNvNeed (
 {\r
   CHAR16 *Ptr;\r
 \r
+  ASSERT (ConVarName != NULL);\r
+  \r
   Ptr = ConVarName;\r
 \r
   //\r
@@ -41,6 +45,10 @@ IsNvNeed (
     Ptr++;\r
   }\r
 \r
+  if (((INTN)((UINTN)Ptr - (UINTN)ConVarName) / sizeof (CHAR16)) <= 3) {\r
+    return TRUE;\r
+  }\r
+  \r
   if ((*(Ptr - 3) == 'D') && (*(Ptr - 2) == 'e') && (*(Ptr - 1) == 'v')) {\r
     return FALSE;\r
   } else {\r
@@ -48,6 +56,131 @@ IsNvNeed (
   }\r
 }\r
 \r
+/**\r
+  Fill console handle in System Table if there are no valid console handle in.\r
+\r
+  Firstly, check the validation of console handle in System Table. If it is invalid,\r
+  update it by the first console device handle from EFI console variable. \r
+\r
+  @param  VarName            The name of the EFI console variable.\r
+  @param  ConsoleGuid        Specified Console protocol GUID.\r
+  @param  ConsoleHandle      On IN,  console handle in System Table to be checked. \r
+                             On OUT, new console hanlde in system table.\r
+  @param  ProtocolInterface  On IN,  console protocol on console handle in System Table to be checked. \r
+                             On OUT, new console protocol on new console hanlde in system table.\r
+\r
+  @retval TRUE               System Table has been updated.\r
+  @retval FALSE              System Table hasn't been updated.\r
+\r
+**/\r
+BOOLEAN \r
+UpdateSystemTableConsole (\r
+  IN     CHAR16                          *VarName,\r
+  IN     EFI_GUID                        *ConsoleGuid,\r
+  IN OUT EFI_HANDLE                      *ConsoleHandle,\r
+  IN OUT VOID                            **ProtocolInterface\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  UINTN                     DevicePathSize;\r
+  EFI_DEVICE_PATH_PROTOCOL  *FullDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *VarConsole;\r
+  EFI_DEVICE_PATH_PROTOCOL  *Instance;\r
+  VOID                      *Interface;\r
+  EFI_HANDLE                NewHandle;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;\r
+\r
+  ASSERT (VarName != NULL);\r
+  ASSERT (ConsoleHandle != NULL);\r
+  ASSERT (ConsoleGuid != NULL);\r
+  ASSERT (ProtocolInterface != NULL);\r
+\r
+  if (*ConsoleHandle != NULL) {\r
+    Status = gBS->HandleProtocol (\r
+                   *ConsoleHandle,\r
+                   ConsoleGuid,\r
+                   &Interface\r
+                   );\r
+    if (Status == EFI_SUCCESS && Interface == *ProtocolInterface) {\r
+      //\r
+      // If ConsoleHandle is valid and console protocol on this handle also\r
+      // also matched, just return.\r
+      //\r
+      return FALSE;\r
+    }\r
+  }\r
+  \r
+  //\r
+  // Get all possible consoles device path from EFI variable\r
+  //\r
+  VarConsole = BdsLibGetVariableAndSize (\r
+                VarName,\r
+                &gEfiGlobalVariableGuid,\r
+                &DevicePathSize\r
+                );\r
+  if (VarConsole == NULL) {\r
+    //\r
+    // If there is no any console device, just return.\r
+    //\r
+    return FALSE;\r
+  }\r
+\r
+  FullDevicePath = VarConsole;\r
+\r
+  do {\r
+    //\r
+    // Check every instance of the console variable\r
+    //\r
+    Instance  = GetNextDevicePathInstance (&VarConsole, &DevicePathSize);\r
+    if (Instance == NULL) {\r
+      FreePool (FullDevicePath);\r
+      ASSERT (FALSE);\r
+    }\r
+    \r
+    //\r
+    // Find console device handle by device path instance\r
+    //\r
+    Status = gBS->LocateDevicePath (\r
+                   ConsoleGuid,\r
+                   &Instance,\r
+                   &NewHandle\r
+                   );\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Get the console protocol on this console device handle\r
+      //\r
+      Status = gBS->HandleProtocol (\r
+                     NewHandle,\r
+                     ConsoleGuid,\r
+                     &Interface\r
+                     );\r
+      if (!EFI_ERROR (Status)) {\r
+        //\r
+        // Update new console handle in System Table.\r
+        //\r
+        *ConsoleHandle     = NewHandle;\r
+        *ProtocolInterface = Interface;\r
+        if (CompareGuid (ConsoleGuid, &gEfiSimpleTextOutProtocolGuid)) {\r
+          //\r
+          // If it is console out device, set console mode 80x25 if current mode is invalid.\r
+          //\r
+          TextOut = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *) Interface;\r
+          if (TextOut->Mode->Mode == -1) {\r
+            TextOut->SetMode (TextOut, 0);\r
+          }\r
+        }\r
+        return TRUE;\r
+      }\r
+    }\r
+\r
+  } while (Instance != NULL);\r
+\r
+  //\r
+  // No any available console devcie found.\r
+  //\r
+  return FALSE;\r
+}\r
+\r
 /**\r
   This function update console variable based on ConVarName, it can\r
   add or remove one specific console device path from the variable\r
@@ -74,6 +207,7 @@ BdsLibUpdateConsoleVariable (
   IN  EFI_DEVICE_PATH_PROTOCOL  *ExclusiveDevicePath\r
   )\r
 {\r
+  EFI_STATUS                Status;\r
   EFI_DEVICE_PATH_PROTOCOL  *VarConsole;\r
   UINTN                     DevicePathSize;\r
   EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;\r
@@ -150,13 +284,17 @@ BdsLibUpdateConsoleVariable (
   //\r
   // Finally, Update the variable of the default console by NewDevicePath\r
   //\r
-  gRT->SetVariable (\r
-        ConVarName,\r
-        &gEfiGlobalVariableGuid,\r
-        Attributes,\r
-        GetDevicePathSize (NewDevicePath),\r
-        NewDevicePath\r
-        );\r
+  DevicePathSize = GetDevicePathSize (NewDevicePath);\r
+  Status = SetVariableAndReportStatusCodeOnError (\r
+             ConVarName,\r
+             &gEfiGlobalVariableGuid,\r
+             Attributes,\r
+             DevicePathSize,\r
+             NewDevicePath\r
+             );\r
+  if ((DevicePathSize == 0) && (Status == EFI_NOT_FOUND)) {\r
+    Status = EFI_SUCCESS;\r
+  }\r
 \r
   if (VarConsole == NewDevicePath) {\r
     if (VarConsole != NULL) {\r
@@ -171,16 +309,19 @@ BdsLibUpdateConsoleVariable (
     }\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 \r
 }\r
 \r
 \r
 /**\r
   Connect the console device base on the variable ConVarName, if\r
-  device path of the ConVarName is multi-instance device path, if\r
+  device path of the ConVarName is multi-instance device path and\r
   anyone of the instances is connected success, then this function\r
   will return success.\r
+  If the handle associate with one device path node can not\r
+  be created successfully, then still give chance to do the dispatch,\r
+  which load the missing drivers if possible..\r
 \r
   @param  ConVarName               Console related variable name, ConIn, ConOut,\r
                                    ErrOut.\r
@@ -239,21 +380,16 @@ BdsLibConnectConsoleVariable (
 \r
     SetDevicePathEndNode (Next);\r
     //\r
-    // Check USB1.1 console\r
+    // Connect the USB console\r
+    // USB console device path is a short-form device path that \r
+    //  starts with the first element being a USB WWID\r
+    //  or a USB Class device path\r
     //\r
     if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) &&\r
        ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP)\r
        || (DevicePathSubType (Instance) == MSG_USB_WWID_DP)\r
        )) {\r
-      //\r
-      // Check the Usb console in Usb2.0 bus firstly, then Usb1.1 bus\r
-      //\r
-      Status = BdsLibConnectUsbDevByShortFormDP (PCI_CLASSC_PI_EHCI, Instance);\r
-      if (!EFI_ERROR (Status)) {\r
-        DeviceExist = TRUE;\r
-      }\r
-\r
-      Status = BdsLibConnectUsbDevByShortFormDP (PCI_CLASSC_PI_UHCI, Instance);\r
+      Status = BdsLibConnectUsbDevByShortFormDP (0xFF, Instance);\r
       if (!EFI_ERROR (Status)) {\r
         DeviceExist = TRUE;\r
       }\r
@@ -262,6 +398,7 @@ BdsLibConnectConsoleVariable (
       // Connect the instance device path\r
       //\r
       Status = BdsLibConnectDevicePath (Instance);\r
+\r
       if (EFI_ERROR (Status)) {\r
         //\r
         // Delete the instance from the console varialbe\r
@@ -283,7 +420,6 @@ BdsLibConnectConsoleVariable (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   This function will search every simpletext device in current system,\r
   and make every simpletext device as pertantial console device.\r
@@ -374,6 +510,7 @@ BdsLibConnectAllDefaultConsoles (
   )\r
 {\r
   EFI_STATUS                Status;\r
+  BOOLEAN                   SystemTableUpdated;\r
 \r
   //\r
   // Connect all default console variables\r
@@ -406,6 +543,101 @@ BdsLibConnectAllDefaultConsoles (
   //\r
   BdsLibConnectConsoleVariable (L"ErrOut");\r
 \r
+  SystemTableUpdated = FALSE;\r
+  //\r
+  // Fill console handles in System Table if no console device assignd.\r
+  //\r
+  if (UpdateSystemTableConsole (L"ConIn", &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **) &gST->ConIn)) {\r
+    SystemTableUpdated = TRUE;\r
+  }\r
+  if (UpdateSystemTableConsole (L"ConOut", &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **) &gST->ConOut)) {\r
+    SystemTableUpdated = TRUE;\r
+  }\r
+  if (UpdateSystemTableConsole (L"ErrOut", &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **) &gST->StdErr)) {\r
+    SystemTableUpdated = TRUE;\r
+  }\r
+\r
+  if (SystemTableUpdated) {\r
+    //\r
+    // Update the CRC32 in the EFI System Table header\r
+    //\r
+    gST->Hdr.CRC32 = 0;\r
+    gBS->CalculateCrc32 (\r
+          (UINT8 *) &gST->Hdr,\r
+          gST->Hdr.HeaderSize,\r
+          &gST->Hdr.CRC32\r
+          );\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+\r
+}\r
+\r
+/**\r
+  This function will connect console device except ConIn base on the console\r
+  device variable  ConOut and ErrOut.\r
+\r
+  @retval EFI_SUCCESS              At least one of the ConOut device have\r
+                                   been connected success.\r
+  @retval EFI_STATUS               Return the status of BdsLibConnectConsoleVariable ().\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BdsLibConnectAllDefaultConsolesWithOutConIn (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  BOOLEAN                   SystemTableUpdated;\r
+\r
+  //\r
+  // Connect all default console variables except ConIn\r
+  //\r
+\r
+  //\r
+  // It seems impossible not to have any ConOut device on platform,\r
+  // so we check the status here.\r
+  //\r
+  Status = BdsLibConnectConsoleVariable (L"ConOut");\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Insert the performance probe for Console Out\r
+  //\r
+  PERF_START (NULL, "ConOut", "BDS", 1);\r
+  PERF_END (NULL, "ConOut", "BDS", 0);\r
+\r
+  //\r
+  // The _ModuleEntryPoint err out var is legal.\r
+  //\r
+  BdsLibConnectConsoleVariable (L"ErrOut");\r
+\r
+  SystemTableUpdated = FALSE;\r
+  //\r
+  // Fill console handles in System Table if no console device assignd.\r
+  //\r
+  if (UpdateSystemTableConsole (L"ConOut", &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **) &gST->ConOut)) {\r
+    SystemTableUpdated = TRUE;\r
+  }\r
+  if (UpdateSystemTableConsole (L"ErrOut", &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **) &gST->StdErr)) {\r
+    SystemTableUpdated = TRUE;\r
+  }\r
+\r
+  if (SystemTableUpdated) {\r
+    //\r
+    // Update the CRC32 in the EFI System Table header\r
+    //\r
+    gST->Hdr.CRC32 = 0;\r
+    gBS->CalculateCrc32 (\r
+          (UINT8 *) &gST->Hdr,\r
+          gST->Hdr.HeaderSize,\r
+          &gST->Hdr.CRC32\r
+          );\r
+  }\r
+\r
   return EFI_SUCCESS;\r
 \r
 }\r
@@ -445,12 +677,18 @@ ConvertBmpToGopBlt (
   BMP_COLOR_MAP                 *BmpColorMap;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;\r
-  UINT                        BltBufferSize;\r
+  UINT64                        BltBufferSize;\r
   UINTN                         Index;\r
   UINTN                         Height;\r
   UINTN                         Width;\r
   UINTN                         ImageIndex;\r
+  UINT32                        DataSizePerLine;\r
   BOOLEAN                       IsAllocated;\r
+  UINT32                        ColorMapNum;\r
+\r
+  if (sizeof (BMP_IMAGE_HEADER) > BmpImageSize) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
 \r
   BmpHeader = (BMP_IMAGE_HEADER *) BmpImage;\r
 \r
@@ -465,11 +703,60 @@ ConvertBmpToGopBlt (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  //\r
+  // Only support BITMAPINFOHEADER format.\r
+  // BITMAPFILEHEADER + BITMAPINFOHEADER = BMP_IMAGE_HEADER\r
+  //\r
+  if (BmpHeader->HeaderSize != sizeof (BMP_IMAGE_HEADER) - OFFSET_OF(BMP_IMAGE_HEADER, HeaderSize)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // The data size in each line must be 4 byte alignment.\r
+  //\r
+  DataSizePerLine = ((BmpHeader->PixelWidth * BmpHeader->BitPerPixel + 31) >> 3) & (~0x3);\r
+  BltBufferSize = MultU64x32 (DataSizePerLine, BmpHeader->PixelHeight);\r
+  if (BltBufferSize > (UINT32) ~0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if ((BmpHeader->Size != BmpImageSize) || \r
+      (BmpHeader->Size < BmpHeader->ImageOffset) ||\r
+      (BmpHeader->Size - BmpHeader->ImageOffset !=  BmpHeader->PixelHeight * DataSizePerLine)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   //\r
   // Calculate Color Map offset in the image.\r
   //\r
   Image       = BmpImage;\r
   BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER));\r
+  if (BmpHeader->ImageOffset < sizeof (BMP_IMAGE_HEADER)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (BmpHeader->ImageOffset > sizeof (BMP_IMAGE_HEADER)) {\r
+    switch (BmpHeader->BitPerPixel) {\r
+      case 1:\r
+        ColorMapNum = 2;\r
+        break;\r
+      case 4:\r
+        ColorMapNum = 16;\r
+        break;\r
+      case 8:\r
+        ColorMapNum = 256;\r
+        break;\r
+      default:\r
+        ColorMapNum = 0;\r
+        break;\r
+      }\r
+    //\r
+    // BMP file may has padding data between the bmp header section and the bmp data section.\r
+    //\r
+    if (BmpHeader->ImageOffset - sizeof (BMP_IMAGE_HEADER) < sizeof (BMP_COLOR_MAP) * ColorMapNum) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
 \r
   //\r
   // Calculate graphics image data address in the image\r
@@ -480,13 +767,21 @@ ConvertBmpToGopBlt (
   //\r
   // Calculate the BltBuffer needed size.\r
   //\r
-  BltBufferSize = BmpHeader->PixelWidth * BmpHeader->PixelHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
+  BltBufferSize = MultU64x32 ((UINT64) BmpHeader->PixelWidth, BmpHeader->PixelHeight);\r
+  //\r
+  // Ensure the BltBufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow\r
+  //\r
+  if (BltBufferSize > DivU64x32 ((UINTN) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  BltBufferSize = MultU64x32 (BltBufferSize, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
+\r
   IsAllocated   = FALSE;\r
   if (*GopBlt == NULL) {\r
     //\r
     // GopBlt is not allocated by caller.\r
     //\r
-    *GopBltSize = BltBufferSize;\r
+    *GopBltSize = (UINTN) BltBufferSize;\r
     *GopBlt     = AllocatePool (*GopBltSize);\r
     IsAllocated = TRUE;\r
     if (*GopBlt == NULL) {\r
@@ -496,8 +791,8 @@ ConvertBmpToGopBlt (
     //\r
     // GopBlt has been allocated by caller.\r
     //\r
-    if (*GopBltSize < BltBufferSize) {\r
-      *GopBltSize = BltBufferSize;\r
+    if (*GopBltSize < (UINTN) BltBufferSize) {\r
+      *GopBltSize = (UINTN) BltBufferSize;\r
       return EFI_BUFFER_TOO_SMALL;\r
     }\r
   }\r
@@ -591,41 +886,9 @@ ConvertBmpToGopBlt (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
-  Use Console Control Protocol to lock the Console In Spliter virtual handle.\r
-  This is the ConInHandle and ConIn handle in the EFI system table. All key\r
-  presses will be ignored until the Password is typed in. The only way to\r
-  disable the password is to type it in to a ConIn device.\r
-\r
-  @param  Password        Password used to lock ConIn device.\r
-\r
-  @retval EFI_SUCCESS     lock the Console In Spliter virtual handle successfully.\r
-  @retval EFI_UNSUPPORTED Password not found\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-LockKeyboards (\r
-  IN  CHAR16    *Password\r
-  )\r
-{\r
-  EFI_STATUS                    Status;\r
-  EFI_CONSOLE_CONTROL_PROTOCOL  *ConsoleControl;\r
-\r
-  Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  Status = ConsoleControl->LockStdIn (ConsoleControl, Password);\r
-  return Status;\r
-}\r
-\r
-\r
-/**\r
-  Use Console Control to turn off UGA based Simple Text Out consoles from going\r
-  to the UGA device. Put up LogoFile on every UGA device that is a console\r
+  Use SystemTable Conout to stop video based Simple Text Out consoles from going\r
+  to the video device. Put up LogoFile on every video device that is a console.\r
 \r
   @param[in]  LogoFile   File name of logo to display on the center of the screen.\r
 \r
@@ -640,7 +903,6 @@ EnableQuietBoot (
   )\r
 {\r
   EFI_STATUS                    Status;\r
-  EFI_CONSOLE_CONTROL_PROTOCOL  *ConsoleControl;\r
   EFI_OEM_BADGING_PROTOCOL      *Badging;\r
   UINT32                        SizeOfX;\r
   UINT32                        SizeOfY;\r
@@ -661,11 +923,18 @@ EnableQuietBoot (
   UINT32                        ColorDepth;\r
   UINT32                        RefreshRate;\r
   EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;\r
-\r
-  Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
+  EFI_BOOT_LOGO_PROTOCOL        *BootLogo;\r
+  UINTN                         NumberOfLogos;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LogoBlt;\r
+  UINTN                         LogoDestX;\r
+  UINTN                         LogoDestY;\r
+  UINTN                         LogoHeight;\r
+  UINTN                         LogoWidth;\r
+  UINTN                         NewDestX;\r
+  UINTN                         NewDestY;\r
+  UINTN                         NewHeight;\r
+  UINTN                         NewWidth;\r
+  UINT64                        BufferSize;\r
 \r
   UgaDraw = NULL;\r
   //\r
@@ -683,16 +952,19 @@ EnableQuietBoot (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  Badging = NULL;\r
-  Status  = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging);\r
+  //\r
+  // Try to open Boot Logo Protocol.\r
+  //\r
+  BootLogo = NULL;\r
+  gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);\r
 \r
   //\r
-  // Set console control to graphics mode.\r
+  // Erase Cursor from screen\r
   //\r
-  Status = ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics);\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
+  gST->ConOut->EnableCursor (gST->ConOut, FALSE);\r
+\r
+  Badging = NULL;\r
+  Status  = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging);\r
 \r
   if (GraphicsOutput != NULL) {\r
     SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;\r
@@ -707,6 +979,16 @@ EnableQuietBoot (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  Blt = NULL;\r
+  NumberOfLogos = 0;\r
+  LogoDestX = 0;\r
+  LogoDestY = 0;\r
+  LogoHeight = 0;\r
+  LogoWidth = 0;\r
+  NewDestX = 0;\r
+  NewDestY = 0;\r
+  NewHeight = 0;\r
+  NewWidth = 0;\r
   Instance = 0;\r
   while (1) {\r
     ImageData = NULL;\r
@@ -727,7 +1009,7 @@ EnableQuietBoot (
                           &CoordinateY\r
                           );\r
       if (EFI_ERROR (Status)) {\r
-        return Status;\r
+        goto Done;\r
       }\r
 \r
       //\r
@@ -750,9 +1032,16 @@ EnableQuietBoot (
 \r
       CoordinateX = 0;\r
       CoordinateY = 0;\r
-      Attribute   = EfiBadgingDisplayAttributeCenter;\r
+      if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {\r
+        Attribute   = EfiBadgingDisplayAttributeCenter;\r
+      } else {\r
+        Attribute   = EfiBadgingDisplayAttributeCustomized;\r
+      } \r
     }\r
 \r
+    if (Blt != NULL) {\r
+      FreePool (Blt);\r
+    }\r
     Blt = NULL;\r
     Status = ConvertBmpToGopBlt (\r
               ImageData,\r
@@ -821,6 +1110,11 @@ EnableQuietBoot (
       DestY = (SizeOfY - Height) / 2;\r
       break;\r
 \r
+    case EfiBadgingDisplayAttributeCustomized:\r
+      DestX = (SizeOfX - Width) / 2;\r
+      DestY = ((SizeOfY * 382) / 1000) - Height / 2;\r
+      break;\r
+\r
     default:\r
       DestX = CoordinateX;\r
       DestY = CoordinateY;\r
@@ -855,27 +1149,138 @@ EnableQuietBoot (
                             Width * sizeof (EFI_UGA_PIXEL)\r
                             );\r
       } else {\r
-      Status = EFI_UNSUPPORTED;\r
+        Status = EFI_UNSUPPORTED;\r
+      }\r
+\r
+      //\r
+      // Report displayed Logo information.\r
+      //\r
+      if (!EFI_ERROR (Status)) {\r
+        NumberOfLogos++;\r
+\r
+        if (LogoWidth == 0) {\r
+          //\r
+          // The first Logo.\r
+          //\r
+          LogoDestX = (UINTN) DestX;\r
+          LogoDestY = (UINTN) DestY;\r
+          LogoWidth = Width;\r
+          LogoHeight = Height;\r
+        } else {\r
+          //\r
+          // Merge new logo with old one.\r
+          //\r
+          NewDestX = MIN ((UINTN) DestX, LogoDestX);\r
+          NewDestY = MIN ((UINTN) DestY, LogoDestY);\r
+          NewWidth = MAX ((UINTN) DestX + Width, LogoDestX + LogoWidth) - NewDestX;\r
+          NewHeight = MAX ((UINTN) DestY + Height, LogoDestY + LogoHeight) - NewDestY;\r
+\r
+          LogoDestX = NewDestX;\r
+          LogoDestY = NewDestY;\r
+          LogoWidth = NewWidth;\r
+          LogoHeight = NewHeight;\r
+        }\r
       }\r
     }\r
 \r
     FreePool (ImageData);\r
 \r
+    if (Badging == NULL) {\r
+      break;\r
+    }\r
+  }\r
+\r
+Done:\r
+  if (BootLogo == NULL || NumberOfLogos == 0) {\r
+    //\r
+    // No logo displayed.\r
+    //\r
     if (Blt != NULL) {\r
       FreePool (Blt);\r
     }\r
 \r
-    if (Badging == NULL) {\r
-      break;\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Advertise displayed Logo information.\r
+  //\r
+  if (NumberOfLogos == 1) {\r
+    //\r
+    // Only one logo displayed, use its Blt buffer directly for BootLogo protocol.\r
+    //\r
+    LogoBlt = Blt;\r
+    Status = EFI_SUCCESS;\r
+  } else {\r
+    //\r
+    // More than one Logo displayed, get merged BltBuffer using VideoToBuffer operation. \r
+    //\r
+    if (Blt != NULL) {\r
+      FreePool (Blt);\r
+    }\r
+\r
+    //\r
+    // Ensure the LogoHeight * LogoWidth doesn't overflow\r
+    //\r
+    if (LogoHeight > DivU64x64Remainder ((UINTN) ~0, LogoWidth, NULL)) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+    BufferSize = MultU64x64 (LogoWidth, LogoHeight);\r
+\r
+    //\r
+    // Ensure the BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow\r
+    //\r
+    if (BufferSize > DivU64x32 ((UINTN) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+\r
+    LogoBlt = AllocateZeroPool ((UINTN)BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
+    if (LogoBlt == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    if (GraphicsOutput != NULL) {\r
+      Status = GraphicsOutput->Blt (\r
+                          GraphicsOutput,\r
+                          LogoBlt,\r
+                          EfiBltVideoToBltBuffer,\r
+                          LogoDestX,\r
+                          LogoDestY,\r
+                          0,\r
+                          0,\r
+                          LogoWidth,\r
+                          LogoHeight,\r
+                          LogoWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+                          );\r
+    } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+      Status = UgaDraw->Blt (\r
+                          UgaDraw,\r
+                          (EFI_UGA_PIXEL *) LogoBlt,\r
+                          EfiUgaVideoToBltBuffer,\r
+                          LogoDestX,\r
+                          LogoDestY,\r
+                          0,\r
+                          0,\r
+                          LogoWidth,\r
+                          LogoHeight,\r
+                          LogoWidth * sizeof (EFI_UGA_PIXEL)\r
+                          );\r
+    } else {\r
+      Status = EFI_UNSUPPORTED;\r
     }\r
   }\r
 \r
+  if (!EFI_ERROR (Status)) {\r
+    BootLogo->SetBootLogo (BootLogo, LogoBlt, LogoDestX, LogoDestY, LogoWidth, LogoHeight);\r
+  }\r
+  FreePool (LogoBlt);\r
+\r
   return Status;\r
 }\r
 \r
 /**\r
-  Use Console Control to turn on UGA based Simple Text Out consoles. The UGA\r
-  Simple Text Out screens will now be synced up with all non UGA output devices\r
+  Use SystemTable Conout to turn on video based Simple Text Out consoles. The \r
+  Simple Text Out screens will now be synced up with all non video output devices\r
 \r
   @retval EFI_SUCCESS     UGA devices are back in text mode and synced up.\r
 \r
@@ -886,17 +1291,11 @@ DisableQuietBoot (
   VOID\r
   )\r
 {\r
-  EFI_STATUS                    Status;\r
-  EFI_CONSOLE_CONTROL_PROTOCOL  *ConsoleControl;\r
-\r
-  Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
 \r
   //\r
-  // Set console control to text mode.\r
+  // Enable Cursor on Screen\r
   //\r
-  return ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenText);\r
+  gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
+  return EFI_SUCCESS;\r
 }\r
 \r