[edk2] [Patch 03/10] MdeModulePkg/BootGraphicsResourceTableDxe: Use BmpSupportLib

Kinney, Michael D posted 10 patches 6 years, 10 months ago
[edk2] [Patch 03/10] MdeModulePkg/BootGraphicsResourceTableDxe: Use BmpSupportLib
Posted by Kinney, Michael D 6 years, 10 months ago
From: Michael D Kinney <michael.d.kinney@intel.com>

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>
---
 .../BootGraphicsResourceTableDxe.c                 | 425 ++++++++++-----------
 .../BootGraphicsResourceTableDxe.inf               |   4 +-
 2 files changed, 197 insertions(+), 232 deletions(-)

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

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel