]> 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 30a6c3e6ed6a6a9e2b9db7f826493504bc11ef01..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 - 2009, 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
@@ -60,8 +68,12 @@ IsNvNeed (
                              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
-VOID \r
+BOOLEAN \r
 UpdateSystemTableConsole (\r
   IN     CHAR16                          *VarName,\r
   IN     EFI_GUID                        *ConsoleGuid,\r
@@ -76,6 +88,7 @@ UpdateSystemTableConsole (
   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
@@ -93,7 +106,7 @@ UpdateSystemTableConsole (
       // If ConsoleHandle is valid and console protocol on this handle also\r
       // also matched, just return.\r
       //\r
-      return;\r
+      return FALSE;\r
     }\r
   }\r
   \r
@@ -109,7 +122,7 @@ UpdateSystemTableConsole (
     //\r
     // If there is no any console device, just return.\r
     //\r
-    return ;\r
+    return FALSE;\r
   }\r
 \r
   FullDevicePath = VarConsole;\r
@@ -147,7 +160,16 @@ UpdateSystemTableConsole (
         //\r
         *ConsoleHandle     = NewHandle;\r
         *ProtocolInterface = Interface;\r
-        return ;\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
@@ -156,7 +178,7 @@ UpdateSystemTableConsole (
   //\r
   // No any available console devcie found.\r
   //\r
-  ASSERT (FALSE);  \r
+  return FALSE;\r
 }\r
 \r
 /**\r
@@ -185,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
@@ -261,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
@@ -282,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
@@ -350,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
@@ -373,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
@@ -394,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
@@ -485,6 +510,7 @@ BdsLibConnectAllDefaultConsoles (
   )\r
 {\r
   EFI_STATUS                Status;\r
+  BOOLEAN                   SystemTableUpdated;\r
 \r
   //\r
   // Connect all default console variables\r
@@ -517,12 +543,100 @@ BdsLibConnectAllDefaultConsoles (
   //\r
   BdsLibConnectConsoleVariable (L"ErrOut");\r
 \r
+  SystemTableUpdated = FALSE;\r
   //\r
   // Fill console handles in System Table if no console device assignd.\r
   //\r
-  UpdateSystemTableConsole (L"ConIn", &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **) &gST->ConIn);\r
-  UpdateSystemTableConsole (L"ConOut", &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **) &gST->ConOut);\r
-  UpdateSystemTableConsole (L"ErrOut", &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **) &gST->StdErr);\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
@@ -563,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
@@ -583,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
@@ -598,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
@@ -614,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
@@ -709,32 +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
-    return EFI_UNSUPPORTED;\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
@@ -769,6 +923,18 @@ EnableQuietBoot (
   UINT32                        ColorDepth;\r
   UINT32                        RefreshRate;\r
   EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;\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
@@ -786,6 +952,12 @@ EnableQuietBoot (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  //\r
+  // Try to open Boot Logo Protocol.\r
+  //\r
+  BootLogo = NULL;\r
+  gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);\r
+\r
   //\r
   // Erase Cursor from screen\r
   //\r
@@ -807,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
@@ -827,7 +1009,7 @@ EnableQuietBoot (
                           &CoordinateY\r
                           );\r
       if (EFI_ERROR (Status)) {\r
-        return Status;\r
+        goto Done;\r
       }\r
 \r
       //\r
@@ -850,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
@@ -921,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
@@ -955,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