]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/BootGraphicsResourceTableDxe: Use BmpSupportLib
authorMichael D Kinney <michael.d.kinney@intel.com>
Fri, 29 Dec 2017 19:26:42 +0000 (11:26 -0800)
committerMichael D Kinney <michael.d.kinney@intel.com>
Mon, 12 Feb 2018 00:05:23 +0000 (16:05 -0800)
https://bugzilla.tianocore.org/show_bug.cgi?id=800

Based on content from the following branch/commits:
https://github.com/Microsoft/MS_UEFI/tree/share/MsCapsuleSupport
https://github.com/Microsoft/MS_UEFI/commit/33bab4031a417d7d5a7d356c15a14c2e60302b2d
https://github.com/Microsoft/MS_UEFI/commit/ca516b1a61315c2d823f453e12d2135098f53d61
https://github.com/Microsoft/MS_UEFI/commit/2b9f111f2e74a4c2ef4c4e32379e111f016dbd9b

Use BmpSupportLib to convert a GOP BLT Buffer to the BMP graphics
image that is published in an ACPI BGRT table.

* Remove use of IndustryStandard/Bmp.h include file
* Remove mBmpImageHeaderTemplate.  This is handled by BmpSupportLib
* Clean up code style with function prototypes at top
  and all module global variables together
* Update SetBootLogo() to use SafeIntLib to check input parameters
  for overflows.
* Remove internal function BgrtAcpiTableChecksum().  Use
  CalculateCheckSum8() directly from BgrtReadyToBootEventNotify()
* Remove InstallBootGraphicsResourceTable().  Move all the code into
  BgrtReadyToBootEventNotify() that is signaled at ready to boot.
* Remove all logic that converts a GOP BLT buffer to a BMP graphics image
  and use BmpSupportLib function TranslateGopBltToBmp() instead.
* Use AllocatePool() instead of AllocatePages() to allocate copy of
  BMP image that is provided by BGRT.  This is required to be compatible
  with BmpSupportLib function TranslateGopBltToBmp() that uses
  AllocatePool().
* Zero OemId in BGRT header before filling in value from PCD.
* Get size of PcdAcpiDefaultOemId and only copy the the size of the PCD
  if it is smaller than the size of the OemId field in the BGRT header.
* Use WriteUnaligned24() instead of CopyMem() for the OemTableId field
  of the BGRT header.

Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Bret Barkelew <Bret.Barkelew@microsoft.com>
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.c
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf

index 6a7165a954897068e4c4b0da3018445eec953755..118fb4a922d73e1fe65113bb0ac38007dbd2dc0c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   This module install ACPI Boot Graphics Resource Table (BGRT).\r
 \r
-  Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2011 - 2018, 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
@@ -14,7 +14,6 @@
 #include <Uefi.h>\r
 \r
 #include <IndustryStandard/Acpi.h>\r
-#include <IndustryStandard/Bmp.h>\r
 \r
 #include <Protocol/AcpiTable.h>\r
 #include <Protocol/GraphicsOutput.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/PcdLib.h>\r
+#include <Library/SafeIntLib.h>\r
+#include <Library/BmpSupportLib.h>\r
 \r
+/**\r
+  Update information of logo image drawn on screen.\r
+\r
+  @param  This           The pointer to the Boot Logo protocol instance.\r
+  @param  BltBuffer      The BLT buffer for logo drawn on screen. If BltBuffer\r
+                         is set to NULL, it indicates that logo image is no\r
+                         longer on the screen.\r
+  @param  DestinationX   X coordinate of destination for the BltBuffer.\r
+  @param  DestinationY   Y coordinate of destination for the BltBuffer.\r
+  @param  Width          Width of rectangle in BltBuffer in pixels.\r
+  @param  Height         Hight of rectangle in BltBuffer in pixels.\r
+\r
+  @retval EFI_SUCCESS             The boot logo information was updated.\r
+  @retval EFI_INVALID_PARAMETER   One of the parameters has an invalid value.\r
+  @retval EFI_OUT_OF_RESOURCES    The logo information was not updated due to\r
+                                  insufficient memory resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SetBootLogo (\r
+  IN EFI_BOOT_LOGO_PROTOCOL         *This,\r
+  IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL  *BltBuffer       OPTIONAL,\r
+  IN UINTN                          DestinationX,\r
+  IN UINTN                          DestinationY,\r
+  IN UINTN                          Width,\r
+  IN UINTN                          Height\r
+  );\r
+\r
+//\r
+// Boot Logo Protocol Handle\r
 //\r
-// Module globals.\r
+EFI_HANDLE  mBootLogoHandle = NULL;\r
+\r
+//\r
+// Boot Logo Protocol Instance\r
 //\r
-EFI_EVENT  mBootGraphicsReadyToBootEvent;\r
-UINTN      mBootGraphicsResourceTableKey = 0;\r
+EFI_BOOT_LOGO_PROTOCOL  mBootLogoProtocolTemplate = {\r
+  SetBootLogo\r
+};\r
 \r
-EFI_HANDLE                     mBootLogoHandle = NULL;\r
+EFI_EVENT                      mBootGraphicsReadyToBootEvent;\r
+UINTN                          mBootGraphicsResourceTableKey = 0;\r
 BOOLEAN                        mIsLogoValid = FALSE;\r
 EFI_GRAPHICS_OUTPUT_BLT_PIXEL  *mLogoBltBuffer = NULL;\r
-UINTN                          mLogoDestX = 0;\r
-UINTN                          mLogoDestY = 0;\r
-UINTN                          mLogoWidth = 0;\r
+UINTN                          mLogoDestX  = 0;\r
+UINTN                          mLogoDestY  = 0;\r
+UINTN                          mLogoWidth  = 0;\r
 UINTN                          mLogoHeight = 0;\r
+BOOLEAN                        mAcpiBgrtInstalled     = FALSE;\r
+BOOLEAN                        mAcpiBgrtStatusChanged = FALSE;\r
+BOOLEAN                        mAcpiBgrtBufferChanged = FALSE;\r
 \r
-BMP_IMAGE_HEADER  mBmpImageHeaderTemplate = {\r
-  'B',    // CharB\r
-  'M',    // CharM\r
-  0,      // Size will be updated at runtime\r
-  {0, 0}, // Reserved\r
-  sizeof (BMP_IMAGE_HEADER), // ImageOffset\r
-  sizeof (BMP_IMAGE_HEADER) - OFFSET_OF (BMP_IMAGE_HEADER, HeaderSize), // HeaderSize\r
-  0,      // PixelWidth will be updated at runtime\r
-  0,      // PixelHeight will be updated at runtime\r
-  1,      // Planes\r
-  24,     // BitPerPixel\r
-  0,      // CompressionType\r
-  0,      // ImageSize will be updated at runtime\r
-  0,      // XPixelsPerMeter\r
-  0,      // YPixelsPerMeter\r
-  0,      // NumberOfColors\r
-  0       // ImportantColors\r
-};\r
-\r
-BOOLEAN  mAcpiBgrtInstalled = FALSE;\r
-BOOLEAN  mAcpiBgrtStatusChanged = FALSE;\r
-BOOLEAN  mAcpiBgrtBufferChanged = FALSE;\r
-\r
+//\r
+// ACPI Boot Graphics Resource Table template\r
+//\r
 EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE mBootGraphicsResourceTableTemplate = {\r
   {\r
     EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE,\r
@@ -89,37 +109,6 @@ EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE mBootGraphicsResourceTableTemplate = {
   0                                  // Image Offset Y\r
 };\r
 \r
-/**\r
-  Update information of logo image drawn on screen.\r
-\r
-  @param  This           The pointer to the Boot Logo protocol instance.\r
-  @param  BltBuffer      The BLT buffer for logo drawn on screen. If BltBuffer\r
-                         is set to NULL, it indicates that logo image is no\r
-                         longer on the screen.\r
-  @param  DestinationX   X coordinate of destination for the BltBuffer.\r
-  @param  DestinationY   Y coordinate of destination for the BltBuffer.\r
-  @param  Width          Width of rectangle in BltBuffer in pixels.\r
-  @param  Height         Hight of rectangle in BltBuffer in pixels.\r
-\r
-  @retval EFI_SUCCESS             The boot logo information was updated.\r
-  @retval EFI_INVALID_PARAMETER   One of the parameters has an invalid value.\r
-  @retval EFI_OUT_OF_RESOURCES    The logo information was not updated due to\r
-                                  insufficient memory resources.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SetBootLogo (\r
-  IN EFI_BOOT_LOGO_PROTOCOL            *This,\r
-  IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL     *BltBuffer       OPTIONAL,\r
-  IN UINTN                             DestinationX,\r
-  IN UINTN                             DestinationY,\r
-  IN UINTN                             Width,\r
-  IN UINTN                             Height\r
-  );\r
-\r
-EFI_BOOT_LOGO_PROTOCOL  mBootLogoProtocolTemplate = { SetBootLogo };\r
-\r
 /**\r
   Update information of logo image drawn on screen.\r
 \r
@@ -149,7 +138,9 @@ SetBootLogo (
   IN UINTN                             Height\r
   )\r
 {\r
-  UINT64                        BufferSize;\r
+  EFI_STATUS  Status;\r
+  UINTN       BufferSize;\r
+  UINT32      Result32;\r
 \r
   if (BltBuffer == NULL) {\r
     mIsLogoValid = FALSE;\r
@@ -157,103 +148,115 @@ SetBootLogo (
     return EFI_SUCCESS;\r
   }\r
 \r
+  //\r
+  // Width and height are not allowed to be zero.\r
+  //\r
   if (Width == 0 || Height == 0) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
-  mAcpiBgrtBufferChanged = TRUE;\r
-  if (mLogoBltBuffer != NULL) {\r
-    FreePool (mLogoBltBuffer);\r
-    mLogoBltBuffer = NULL;\r
+\r
+  //\r
+  // Verify destination, width, and height do not overflow 32-bit values.\r
+  // The Boot Graphics Resource Table only has 32-bit fields for these values.\r
+  //\r
+  Status = SafeUintnToUint32 (DestinationX, &Result32);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+  Status = SafeUintnToUint32 (DestinationY, &Result32);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  Status = SafeUintnToUint32 (Width, &Result32);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  Status = SafeUintnToUint32 (Height, &Result32);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   //\r
-  // Ensure the Height * Width doesn't overflow\r
+  // Ensure the Height * Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) does\r
+  // not overflow UINTN\r
   //\r
-  if (Height > DivU64x64Remainder ((UINTN) ~0, Width, NULL)) {\r
+  Status = SafeUintnMult (\r
+             Width,\r
+             Height,\r
+             &BufferSize\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  Status = SafeUintnMult (\r
+             BufferSize,\r
+             sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL),\r
+             &BufferSize\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
-  BufferSize = MultU64x64 (Width, Height);\r
-  \r
+\r
   //\r
-  // Ensure the BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow\r
+  // Update state\r
   //\r
-  if (BufferSize > DivU64x32 ((UINTN) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {\r
-    return EFI_UNSUPPORTED;\r
+  mAcpiBgrtBufferChanged = TRUE;\r
+\r
+  //\r
+  // Free old logo buffer\r
+  //\r
+  if (mLogoBltBuffer != NULL) {\r
+    FreePool (mLogoBltBuffer);\r
+    mLogoBltBuffer = NULL;\r
   }\r
 \r
-  mLogoBltBuffer = AllocateCopyPool (\r
-                     (UINTN)BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL),\r
-                     BltBuffer\r
-                     );\r
+  //\r
+  // Allocate new logo buffer\r
+  //\r
+  mLogoBltBuffer = AllocateCopyPool (BufferSize, BltBuffer);\r
   if (mLogoBltBuffer == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  mLogoDestX = DestinationX;\r
-  mLogoDestY = DestinationY;\r
-  mLogoWidth = Width;\r
-  mLogoHeight = Height;\r
+\r
+  mLogoDestX   = DestinationX;\r
+  mLogoDestY   = DestinationY;\r
+  mLogoWidth   = Width;\r
+  mLogoHeight  = Height;\r
   mIsLogoValid = TRUE;\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  This function calculates and updates an UINT8 checksum.\r
+  Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. This is used to\r
+  install the Boot Graphics Resource Table.\r
 \r
-  @param[in]  Buffer          Pointer to buffer to checksum.\r
-  @param[in]  Size            Number of bytes to checksum.\r
+  @param[in]  Event   The Event that is being processed.\r
+  @param[in]  Context The Event Context.\r
 \r
 **/\r
 VOID\r
-BgrtAcpiTableChecksum (\r
-  IN UINT8      *Buffer,\r
-  IN UINTN      Size\r
-  )\r
-{\r
-  UINTN ChecksumOffset;\r
-\r
-  ChecksumOffset = OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum);\r
-\r
-  //\r
-  // Set checksum to 0 first.\r
-  //\r
-  Buffer[ChecksumOffset] = 0;\r
-\r
-  //\r
-  // Update checksum value.\r
-  //\r
-  Buffer[ChecksumOffset] = CalculateCheckSum8 (Buffer, Size);\r
-}\r
-\r
-/**\r
-  Install Boot Graphics Resource Table to ACPI table.\r
-\r
-  @return Status code.\r
-\r
-**/\r
-EFI_STATUS\r
-InstallBootGraphicsResourceTable (\r
-  VOID\r
+EFIAPI\r
+BgrtReadyToBootEventNotify (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
   )\r
 {\r
-  EFI_STATUS                    Status;\r
-  EFI_ACPI_TABLE_PROTOCOL       *AcpiTableProtocol;\r
-  UINT8                         *ImageBuffer;\r
-  UINTN                         PaddingSize;\r
-  UINTN                         BmpSize;\r
-  UINTN                         OrigBmpSize;\r
-  UINT8                         *Image;\r
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltPixel;\r
-  UINTN                         Col;\r
-  UINTN                         Row;\r
+  EFI_STATUS               Status;\r
+  EFI_ACPI_TABLE_PROTOCOL  *AcpiTableProtocol;\r
+  VOID                     *ImageBuffer;\r
+  UINT32                   BmpSize;\r
 \r
   //\r
   // Get ACPI Table protocol.\r
   //\r
-  Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **) &AcpiTableProtocol);\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiAcpiTableProtocolGuid,\r
+                  NULL,\r
+                  (VOID **) &AcpiTableProtocol\r
+                  );\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    return;\r
   }\r
 \r
   //\r
@@ -264,109 +267,85 @@ InstallBootGraphicsResourceTable (
       //\r
       // Nothing has changed\r
       //\r
-      return EFI_SUCCESS;\r
+      return;\r
     } else {\r
       //\r
-      // If BGRT data change happens. Uninstall Orignal AcpiTable first\r
+      // If BGRT data change happens, then uninstall orignal AcpiTable first\r
       //\r
       Status = AcpiTableProtocol->UninstallAcpiTable (\r
                                     AcpiTableProtocol,\r
                                     mBootGraphicsResourceTableKey\r
                                     );\r
       if (EFI_ERROR (Status)) {\r
-        return Status;\r
-      } \r
+        return;\r
+      }\r
     }\r
   } else {\r
     //\r
-    // Check whether Logo exist.\r
+    // Check whether Logo exists\r
     //\r
-    if ( mLogoBltBuffer == NULL) {\r
-      return EFI_NOT_FOUND;\r
+    if (mLogoBltBuffer == NULL) {\r
+      return;\r
     }\r
   }\r
 \r
   if (mAcpiBgrtBufferChanged) {\r
     //\r
-    // reserve original BGRT buffer size\r
+    // Free the old BMP image buffer\r
     //\r
-    OrigBmpSize = mBmpImageHeaderTemplate.ImageSize + sizeof (BMP_IMAGE_HEADER);\r
-    //\r
-    // Free orignal BMP memory \r
-    // \r
-    if (mBootGraphicsResourceTableTemplate.ImageAddress) {\r
-      gBS->FreePages(mBootGraphicsResourceTableTemplate.ImageAddress, EFI_SIZE_TO_PAGES(OrigBmpSize));\r
+    ImageBuffer = (UINT8 *)(UINTN)mBootGraphicsResourceTableTemplate.ImageAddress;\r
+    if (ImageBuffer != NULL) {\r
+      FreePool (ImageBuffer);\r
     }\r
 \r
     //\r
-    // Allocate memory for BMP file.\r
+    // Convert GOP Blt buffer to BMP image.  Pass in ImageBuffer set to NULL\r
+    // so the BMP image is allocated by TranslateGopBltToBmp().\r
     //\r
-    PaddingSize = mLogoWidth & 0x3;\r
-\r
-    //\r
-    // First check mLogoWidth * 3 + PaddingSize doesn't overflow\r
-    //\r
-    if (mLogoWidth > (((UINT32) ~0) - PaddingSize) / 3 ) {\r
-      return EFI_UNSUPPORTED;\r
-    }\r
-\r
-    //\r
-    // Second check (mLogoWidth * 3 + PaddingSize) * mLogoHeight + sizeof (BMP_IMAGE_HEADER) doesn't overflow\r
-    //\r
-    if (mLogoHeight > (((UINT32) ~0) - sizeof (BMP_IMAGE_HEADER)) / (mLogoWidth * 3 + PaddingSize)) {\r
-      return EFI_UNSUPPORTED;\r
+    ImageBuffer = NULL;\r
+    Status = TranslateGopBltToBmp (\r
+               mLogoBltBuffer,\r
+               (UINT32)mLogoHeight,\r
+               (UINT32)mLogoWidth,\r
+               &ImageBuffer,\r
+               &BmpSize\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      return;\r
     }\r
 \r
     //\r
-    // The image should be stored in EfiBootServicesData, allowing the system to reclaim the memory\r
-    //\r
-    BmpSize = (mLogoWidth * 3 + PaddingSize) * mLogoHeight + sizeof (BMP_IMAGE_HEADER);\r
-    ImageBuffer = AllocatePages (EFI_SIZE_TO_PAGES (BmpSize));\r
-    if (ImageBuffer == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-\r
-    ZeroMem (ImageBuffer, BmpSize);\r
-\r
-    mBmpImageHeaderTemplate.Size = (UINT32) BmpSize;\r
-    mBmpImageHeaderTemplate.ImageSize = (UINT32) BmpSize - sizeof (BMP_IMAGE_HEADER);\r
-    mBmpImageHeaderTemplate.PixelWidth = (UINT32) mLogoWidth;\r
-    mBmpImageHeaderTemplate.PixelHeight = (UINT32) mLogoHeight;\r
-    CopyMem (ImageBuffer, &mBmpImageHeaderTemplate, sizeof (BMP_IMAGE_HEADER));\r
-    \r
-    //\r
-    // Convert BLT buffer to BMP file.\r
+    // Free the logo buffer\r
     //\r
-    Image = ImageBuffer + sizeof (BMP_IMAGE_HEADER);\r
-    for (Row = 0; Row < mLogoHeight; Row++) {\r
-    BltPixel = &mLogoBltBuffer[(mLogoHeight - Row - 1) * mLogoWidth];\r
-\r
-    for (Col = 0; Col < mLogoWidth; Col++) {\r
-      *Image++ = BltPixel->Blue;\r
-      *Image++ = BltPixel->Green;\r
-      *Image++ = BltPixel->Red;\r
-      BltPixel++;\r
-    }\r
-\r
-      //\r
-      // Padding for 4 byte alignment.\r
-      //\r
-      Image += PaddingSize;\r
-    }\r
     FreePool (mLogoBltBuffer);\r
     mLogoBltBuffer = NULL;\r
 \r
-    mBootGraphicsResourceTableTemplate.ImageAddress = (UINT64) (UINTN) ImageBuffer;\r
-    mBootGraphicsResourceTableTemplate.ImageOffsetX = (UINT32) mLogoDestX;\r
-    mBootGraphicsResourceTableTemplate.ImageOffsetY = (UINT32) mLogoDestY;\r
+    //\r
+    // Update BMP image fields of the Boot Graphics Resource Table\r
+    //\r
+    mBootGraphicsResourceTableTemplate.ImageAddress = (UINT64)(UINTN)ImageBuffer;\r
+    mBootGraphicsResourceTableTemplate.ImageOffsetX = (UINT32)mLogoDestX;\r
+    mBootGraphicsResourceTableTemplate.ImageOffsetY = (UINT32)mLogoDestY;\r
   }\r
 \r
-  mBootGraphicsResourceTableTemplate.Status = (UINT8) (mIsLogoValid ? EFI_ACPI_5_0_BGRT_STATUS_VALID : EFI_ACPI_5_0_BGRT_STATUS_INVALID);\r
+  //\r
+  // Update Status field of Boot Graphics Resource Table\r
+  //\r
+  if (mIsLogoValid) {\r
+    mBootGraphicsResourceTableTemplate.Status = EFI_ACPI_5_0_BGRT_STATUS_VALID;\r
+  } else {\r
+    mBootGraphicsResourceTableTemplate.Status = EFI_ACPI_5_0_BGRT_STATUS_INVALID;\r
+  }\r
 \r
   //\r
-  // Update Checksum.\r
+  // Update Checksum of Boot Graphics Resource Table\r
   //\r
-  BgrtAcpiTableChecksum ((UINT8 *) &mBootGraphicsResourceTableTemplate, sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE));\r
+  mBootGraphicsResourceTableTemplate.Header.Checksum = 0;\r
+  mBootGraphicsResourceTableTemplate.Header.Checksum =\r
+    CalculateCheckSum8 (\r
+      (UINT8 *)&mBootGraphicsResourceTableTemplate,\r
+      sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE)\r
+      );\r
 \r
   //\r
   // Publish Boot Graphics Resource Table.\r
@@ -378,32 +357,12 @@ InstallBootGraphicsResourceTable (
                                 &mBootGraphicsResourceTableKey\r
                                 );\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    return;\r
   }\r
 \r
-  mAcpiBgrtInstalled = TRUE;\r
+  mAcpiBgrtInstalled     = TRUE;\r
   mAcpiBgrtStatusChanged = FALSE;\r
   mAcpiBgrtBufferChanged = FALSE;\r
-  \r
-  return Status;\r
-}\r
-\r
-/**\r
-  Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. This is used to\r
-  install the Boot Graphics Resource Table.\r
-\r
-  @param[in]  Event   The Event that is being processed.\r
-  @param[in]  Context The Event Context.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-BgrtReadyToBootEventNotify (\r
-  IN EFI_EVENT        Event,\r
-  IN VOID             *Context\r
-  )\r
-{\r
-  InstallBootGraphicsResourceTable ();\r
 }\r
 \r
 /**\r
@@ -419,23 +378,27 @@ BgrtReadyToBootEventNotify (
 EFI_STATUS\r
 EFIAPI\r
 BootGraphicsDxeEntryPoint (\r
-  IN EFI_HANDLE          ImageHandle,\r
-  IN EFI_SYSTEM_TABLE    *SystemTable\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  UINT64      OemTableId;\r
+  EFI_STATUS                   Status;\r
+  EFI_ACPI_DESCRIPTION_HEADER  *Header;\r
 \r
+  //\r
+  // Update Header fields of Boot Graphics Resource Table from PCDs\r
+  //\r
+  Header = &mBootGraphicsResourceTableTemplate.Header;\r
+  ZeroMem (Header->OemId, sizeof (Header->OemId));\r
   CopyMem (\r
-    mBootGraphicsResourceTableTemplate.Header.OemId,\r
+    Header->OemId,\r
     PcdGetPtr (PcdAcpiDefaultOemId),\r
-    sizeof (mBootGraphicsResourceTableTemplate.Header.OemId)\r
+    MIN (PcdGetSize (PcdAcpiDefaultOemId), sizeof (Header->OemId))\r
     );\r
-  OemTableId = PcdGet64 (PcdAcpiDefaultOemTableId);\r
-  CopyMem (&mBootGraphicsResourceTableTemplate.Header.OemTableId, &OemTableId, sizeof (UINT64));\r
-  mBootGraphicsResourceTableTemplate.Header.OemRevision      = PcdGet32 (PcdAcpiDefaultOemRevision);\r
-  mBootGraphicsResourceTableTemplate.Header.CreatorId        = PcdGet32 (PcdAcpiDefaultCreatorId);\r
-  mBootGraphicsResourceTableTemplate.Header.CreatorRevision  = PcdGet32 (PcdAcpiDefaultCreatorRevision);\r
+  WriteUnaligned64 (&Header->OemTableId, PcdGet64 (PcdAcpiDefaultOemTableId));\r
+  Header->OemRevision     = PcdGet32 (PcdAcpiDefaultOemRevision);\r
+  Header->CreatorId       = PcdGet32 (PcdAcpiDefaultCreatorId);\r
+  Header->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);\r
 \r
   //\r
   // Install Boot Logo protocol.\r
index 9fd1da448c54871e0ceae8859ffbdd00f22db0b0..ff33405acddc41ef8a9d7cce72b0ebb16a6633b5 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  This module install ACPI Boot Graphics Resource Table (BGRT).\r
 #\r
-#  Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2011 - 2018, 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
@@ -43,6 +43,8 @@
   UefiBootServicesTableLib\r
   DebugLib\r
   PcdLib\r
+  SafeIntLib\r
+  BmpSupportLib\r
 \r
 [Protocols]\r
   gEfiAcpiTableProtocolGuid                     ## CONSUMES\r