Nt32Pkg: Keep boot behavior using new BDS almost same as that using old BDS
authorRuiyu Ni <ruiyu.ni@intel.com>
Tue, 25 Aug 2015 09:51:07 +0000 (09:51 +0000)
committerniruiyu <niruiyu@Edk2>
Tue, 25 Aug 2015 09:51:07 +0000 (09:51 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18306 6f19259b-4bc3-4df7-8a09-765794883524

Nt32Pkg/Library/PlatformBootManagerLib/MemoryTest.c [new file with mode: 0644]
Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.c
Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.h
Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
Nt32Pkg/Library/PlatformBootManagerLib/Strings.uni [new file with mode: 0644]

diff --git a/Nt32Pkg/Library/PlatformBootManagerLib/MemoryTest.c b/Nt32Pkg/Library/PlatformBootManagerLib/MemoryTest.c
new file mode 100644 (file)
index 0000000..9f57466
--- /dev/null
@@ -0,0 +1,1086 @@
+/** @file\r
+  Perform the platform memory test\r
+\r
+Copyright (c) 2004 - 2015, 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
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "PlatformBootManager.h"\r
+\r
+EFI_HII_HANDLE gStringPackHandle                  = NULL;\r
+EFI_GUID       mPlatformBootManagerStringPackGuid = {\r
+  0x154dd51, 0x9079, 0x4a10, { 0x89, 0x5c, 0x9c, 0x7, 0x72, 0x81, 0x57, 0x88 }\r
+  };\r
+// extern UINT8  BdsDxeStrings[];\r
+\r
+//\r
+// BDS Platform Functions\r
+//\r
+/**\r
+\r
+  Show progress bar with title above it. It only works in Graphics mode.\r
+\r
+\r
+  @param TitleForeground Foreground color for Title.\r
+  @param TitleBackground Background color for Title.\r
+  @param Title           Title above progress bar.\r
+  @param ProgressColor   Progress bar color.\r
+  @param Progress        Progress (0-100)\r
+  @param PreviousValue   The previous value of the progress.\r
+\r
+  @retval  EFI_STATUS       Success update the progress bar\r
+\r
+**/\r
+EFI_STATUS\r
+PlatformBootManagerShowProgress (\r
+  IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground,\r
+  IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground,\r
+  IN CHAR16                        *Title,\r
+  IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor,\r
+  IN UINTN                         Progress,\r
+  IN UINTN                         PreviousValue\r
+  )\r
+{\r
+  EFI_STATUS                     Status;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL   *GraphicsOutput;\r
+  EFI_UGA_DRAW_PROTOCOL          *UgaDraw;\r
+  UINT32                         SizeOfX;\r
+  UINT32                         SizeOfY;\r
+  UINT32                         ColorDepth;\r
+  UINT32                         RefreshRate;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL  Color;\r
+  UINTN                          BlockHeight;\r
+  UINTN                          BlockWidth;\r
+  UINTN                          BlockNum;\r
+  UINTN                          PosX;\r
+  UINTN                          PosY;\r
+  UINTN                          Index;\r
+\r
+  if (Progress > 100) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  UgaDraw = NULL;\r
+  Status = gBS->HandleProtocol (\r
+                  gST->ConsoleOutHandle,\r
+                  &gEfiGraphicsOutputProtocolGuid,\r
+                  (VOID **) &GraphicsOutput\r
+                  );\r
+  if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+    GraphicsOutput = NULL;\r
+\r
+    Status = gBS->HandleProtocol (\r
+                    gST->ConsoleOutHandle,\r
+                    &gEfiUgaDrawProtocolGuid,\r
+                    (VOID **) &UgaDraw\r
+                    );\r
+  }\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  SizeOfX = 0;\r
+  SizeOfY = 0;\r
+  if (GraphicsOutput != NULL) {\r
+    SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;\r
+    SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;\r
+  } else if (UgaDraw != NULL) {\r
+    Status = UgaDraw->GetMode (\r
+                        UgaDraw,\r
+                        &SizeOfX,\r
+                        &SizeOfY,\r
+                        &ColorDepth,\r
+                        &RefreshRate\r
+                        );\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+  } else {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  BlockWidth  = SizeOfX / 100;\r
+  BlockHeight = SizeOfY / 50;\r
+\r
+  BlockNum    = Progress;\r
+\r
+  PosX        = 0;\r
+  PosY        = SizeOfY * 48 / 50;\r
+\r
+  if (BlockNum == 0) {\r
+    //\r
+    // Clear progress area\r
+    //\r
+    SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);\r
+\r
+    if (GraphicsOutput != NULL) {\r
+      Status = GraphicsOutput->Blt (\r
+                          GraphicsOutput,\r
+                          &Color,\r
+                          EfiBltVideoFill,\r
+                          0,\r
+                          0,\r
+                          0,\r
+                          PosY - EFI_GLYPH_HEIGHT - 1,\r
+                          SizeOfX,\r
+                          SizeOfY - (PosY - EFI_GLYPH_HEIGHT - 1),\r
+                          SizeOfX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+                          );\r
+    } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+      Status = UgaDraw->Blt (\r
+                          UgaDraw,\r
+                          (EFI_UGA_PIXEL *) &Color,\r
+                          EfiUgaVideoFill,\r
+                          0,\r
+                          0,\r
+                          0,\r
+                          PosY - EFI_GLYPH_HEIGHT - 1,\r
+                          SizeOfX,\r
+                          SizeOfY - (PosY - EFI_GLYPH_HEIGHT - 1),\r
+                          SizeOfX * sizeof (EFI_UGA_PIXEL)\r
+                          );\r
+    } else {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+  }\r
+  //\r
+  // Show progress by drawing blocks\r
+  //\r
+  for (Index = PreviousValue; Index < BlockNum; Index++) {\r
+    PosX = Index * BlockWidth;\r
+    if (GraphicsOutput != NULL) {\r
+      Status = GraphicsOutput->Blt (\r
+                          GraphicsOutput,\r
+                          &ProgressColor,\r
+                          EfiBltVideoFill,\r
+                          0,\r
+                          0,\r
+                          PosX,\r
+                          PosY,\r
+                          BlockWidth - 1,\r
+                          BlockHeight,\r
+                          (BlockWidth) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+                          );\r
+    } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+      Status = UgaDraw->Blt (\r
+                          UgaDraw,\r
+                          (EFI_UGA_PIXEL *) &ProgressColor,\r
+                          EfiUgaVideoFill,\r
+                          0,\r
+                          0,\r
+                          PosX,\r
+                          PosY,\r
+                          BlockWidth - 1,\r
+                          BlockHeight,\r
+                          (BlockWidth) * sizeof (EFI_UGA_PIXEL)\r
+                          );\r
+    } else {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+  }\r
+\r
+  PrintXY (\r
+    (SizeOfX - StrLen (Title) * EFI_GLYPH_WIDTH) / 2,\r
+    PosY - EFI_GLYPH_HEIGHT - 1,\r
+    &TitleForeground,\r
+    &TitleBackground,\r
+    Title\r
+    );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Perform the memory test base on the memory test intensive level,\r
+  and update the memory resource.\r
+\r
+  @param  Level         The memory test intensive level.\r
+\r
+  @retval EFI_STATUS    Success test all the system memory and update\r
+                        the memory resource\r
+\r
+**/\r
+EFI_STATUS\r
+PlatformBootManagerMemoryTest (\r
+  IN EXTENDMEM_COVERAGE_LEVEL Level\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_STATUS                        KeyStatus;\r
+  EFI_STATUS                        InitStatus;\r
+  EFI_STATUS                        ReturnStatus;\r
+  BOOLEAN                           RequireSoftECCInit;\r
+  EFI_GENERIC_MEMORY_TEST_PROTOCOL  *GenMemoryTest;\r
+  UINT64                            TestedMemorySize;\r
+  UINT64                            TotalMemorySize;\r
+  UINTN                             TestPercent;\r
+  UINT64                            PreviousValue;\r
+  BOOLEAN                           ErrorOut;\r
+  BOOLEAN                           TestAbort;\r
+  EFI_INPUT_KEY                     Key;\r
+  CHAR16                            StrPercent[80];\r
+  CHAR16                            *StrTotalMemory;\r
+  CHAR16                            *Pos;\r
+  CHAR16                            *TmpStr;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL     Foreground;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL     Background;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL     Color;\r
+  UINT32                            TempData;\r
+  UINTN                             StrTotalMemorySize;\r
+\r
+  ReturnStatus = EFI_SUCCESS;\r
+  ZeroMem (&Key, sizeof (EFI_INPUT_KEY));\r
+\r
+  StrTotalMemorySize = 128;\r
+  Pos = AllocateZeroPool (StrTotalMemorySize);\r
+  ASSERT (Pos != NULL);\r
+\r
+  if (gStringPackHandle == NULL) {  \r
+    gStringPackHandle = HiiAddPackages (\r
+                           &mPlatformBootManagerStringPackGuid,\r
+                           gImageHandle,\r
+                           PlatformBootManagerLibStrings,\r
+                           NULL\r
+                           );\r
+    ASSERT (gStringPackHandle != NULL);\r
+  }\r
+\r
+  StrTotalMemory    = Pos;\r
+\r
+  TestedMemorySize  = 0;\r
+  TotalMemorySize   = 0;\r
+  PreviousValue     = 0;\r
+  ErrorOut          = FALSE;\r
+  TestAbort         = FALSE;\r
+\r
+  SetMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);\r
+  SetMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);\r
+  SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);\r
+\r
+  RequireSoftECCInit = FALSE;\r
+\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiGenericMemTestProtocolGuid,\r
+                  NULL,\r
+                  (VOID **) &GenMemoryTest\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (Pos);\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  InitStatus = GenMemoryTest->MemoryTestInit (\r
+                                GenMemoryTest,\r
+                                Level,\r
+                                &RequireSoftECCInit\r
+                                );\r
+  if (InitStatus == EFI_NO_MEDIA) {\r
+    //\r
+    // The PEI codes also have the relevant memory test code to check the memory,\r
+    // it can select to test some range of the memory or all of them. If PEI code\r
+    // checks all the memory, this BDS memory test will has no not-test memory to\r
+    // do the test, and then the status of EFI_NO_MEDIA will be returned by\r
+    // "MemoryTestInit". So it does not need to test memory again, just return.\r
+    //\r
+    FreePool (Pos);\r
+    return EFI_SUCCESS;\r
+  }\r
+  \r
+  if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {\r
+    TmpStr = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_ESC_TO_SKIP_MEM_TEST), NULL);\r
+\r
+    if (TmpStr != NULL) {\r
+      PrintXY (10, 10, NULL, NULL, TmpStr);\r
+      FreePool (TmpStr);\r
+    }\r
+  } else {\r
+    DEBUG ((EFI_D_INFO, "Enter memory test.\n"));\r
+  }\r
+  do {\r
+    Status = GenMemoryTest->PerformMemoryTest (\r
+                              GenMemoryTest,\r
+                              &TestedMemorySize,\r
+                              &TotalMemorySize,\r
+                              &ErrorOut,\r
+                              TestAbort\r
+                              );\r
+    if (ErrorOut && (Status == EFI_DEVICE_ERROR)) {\r
+      TmpStr = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_SYSTEM_MEM_ERROR), NULL);\r
+      if (TmpStr != NULL) {\r
+        PrintXY (10, 10, NULL, NULL, TmpStr);\r
+        FreePool (TmpStr);\r
+      }\r
+\r
+      ASSERT (0);\r
+    }\r
+    \r
+    if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {\r
+      TempData = (UINT32) DivU64x32 (TotalMemorySize, 16);\r
+      TestPercent = (UINTN) DivU64x32 (\r
+                              DivU64x32 (MultU64x32 (TestedMemorySize, 100), 16),\r
+                              TempData\r
+                              );\r
+      if (TestPercent != PreviousValue) {\r
+        UnicodeValueToString (StrPercent, 0, TestPercent, 0);\r
+        TmpStr = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_MEMORY_TEST_PERCENT), NULL);\r
+        if (TmpStr != NULL) {\r
+          //\r
+          // TmpStr size is 64, StrPercent is reserved to 16.\r
+          //\r
+          StrnCatS (\r
+            StrPercent,\r
+            sizeof (StrPercent) / sizeof (CHAR16), \r
+            TmpStr,\r
+            sizeof (StrPercent) / sizeof (CHAR16) - StrLen (StrPercent) - 1\r
+            );\r
+          PrintXY (10, 10, NULL, NULL, StrPercent);\r
+          FreePool (TmpStr);\r
+        }\r
+\r
+        TmpStr = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_PERFORM_MEM_TEST), NULL);\r
+        if (TmpStr != NULL) {\r
+          PlatformBootManagerShowProgress (\r
+            Foreground,\r
+            Background,\r
+            TmpStr,\r
+            Color,\r
+            TestPercent,\r
+            (UINTN) PreviousValue\r
+            );\r
+          FreePool (TmpStr);\r
+        }\r
+      }\r
+\r
+      PreviousValue = TestPercent;\r
+    } else {\r
+      DEBUG ((EFI_D_INFO, "Perform memory test (ESC to skip).\n"));\r
+    }\r
+\r
+    if (!PcdGetBool (PcdConInConnectOnDemand)) {\r
+      KeyStatus     = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+      if (!EFI_ERROR (KeyStatus) && (Key.ScanCode == SCAN_ESC)) {\r
+        if (!RequireSoftECCInit) {\r
+          if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {\r
+            TmpStr = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_PERFORM_MEM_TEST), NULL);\r
+            if (TmpStr != NULL) {\r
+              PlatformBootManagerShowProgress (\r
+                Foreground,\r
+                Background,\r
+                TmpStr,\r
+                Color,\r
+                100,\r
+                (UINTN) PreviousValue\r
+                );\r
+              FreePool (TmpStr);\r
+            }\r
+\r
+            PrintXY (10, 10, NULL, NULL, L"100");\r
+          }\r
+          Status = GenMemoryTest->Finished (GenMemoryTest);\r
+          goto Done;\r
+        }\r
+\r
+        TestAbort = TRUE;\r
+      }\r
+    }\r
+  } while (Status != EFI_NOT_FOUND);\r
+\r
+  Status = GenMemoryTest->Finished (GenMemoryTest);\r
+\r
+Done:\r
+  if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {\r
+    UnicodeValueToString (StrTotalMemory, COMMA_TYPE, TotalMemorySize, 0);\r
+    if (StrTotalMemory[0] == L',') {\r
+      StrTotalMemory++;\r
+      StrTotalMemorySize -= sizeof (CHAR16);\r
+    }\r
+\r
+    TmpStr = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_MEM_TEST_COMPLETED), NULL);\r
+    if (TmpStr != NULL) {\r
+      StrnCatS (\r
+        StrTotalMemory,\r
+        StrTotalMemorySize / sizeof (CHAR16),\r
+        TmpStr,\r
+        StrTotalMemorySize / sizeof (CHAR16) - StrLen (StrTotalMemory) - 1\r
+        );\r
+      FreePool (TmpStr);\r
+    }\r
+\r
+    PrintXY (10, 10, NULL, NULL, StrTotalMemory);\r
+    PlatformBootManagerShowProgress (\r
+      Foreground,\r
+      Background,\r
+      StrTotalMemory,\r
+      Color,\r
+      100,\r
+      (UINTN) PreviousValue\r
+      );\r
+    \r
+  } else {\r
+    DEBUG ((EFI_D_INFO, "%d bytes of system memory tested OK\r\n", TotalMemorySize));\r
+  }\r
+  \r
+  FreePool (Pos);\r
+  return ReturnStatus;\r
+}\r
+\r
+/**\r
+  Convert a *.BMP graphics image to a GOP blt buffer. If a NULL Blt buffer\r
+  is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt\r
+  buffer is passed in it will be used if it is big enough.\r
+\r
+  @param  BmpImage      Pointer to BMP file\r
+  @param  BmpImageSize  Number of bytes in BmpImage\r
+  @param  GopBlt        Buffer containing GOP version of BmpImage.\r
+  @param  GopBltSize    Size of GopBlt in bytes.\r
+  @param  PixelHeight   Height of GopBlt/BmpImage in pixels\r
+  @param  PixelWidth    Width of GopBlt/BmpImage in pixels\r
+\r
+  @retval EFI_SUCCESS           GopBlt and GopBltSize are returned.\r
+  @retval EFI_UNSUPPORTED       BmpImage is not a valid *.BMP image\r
+  @retval EFI_BUFFER_TOO_SMALL  The passed in GopBlt buffer is not big enough.\r
+                                GopBltSize will contain the required size.\r
+  @retval EFI_OUT_OF_RESOURCES  No enough buffer to allocate.\r
+\r
+**/\r
+EFI_STATUS\r
+PlatformBootManagerConvertBmpToGopBlt (\r
+  IN     VOID      *BmpImage,\r
+  IN     UINTN     BmpImageSize,\r
+  IN OUT VOID      **GopBlt,\r
+  IN OUT UINTN     *GopBltSize,\r
+     OUT UINTN     *PixelHeight,\r
+     OUT UINTN     *PixelWidth\r
+  )\r
+{\r
+  UINT8                         *Image;\r
+  UINT8                         *ImageHeader;\r
+  BMP_IMAGE_HEADER              *BmpHeader;\r
+  BMP_COLOR_MAP                 *BmpColorMap;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;\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
+  if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Doesn't support compress.\r
+  //\r
+  if (BmpHeader->CompressionType != 0) {\r
+    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
+  //\r
+  Image         = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset;\r
+  ImageHeader   = Image;\r
+\r
+  //\r
+  // Calculate the BltBuffer needed size.\r
+  //\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 = (UINTN) BltBufferSize;\r
+    *GopBlt     = AllocatePool (*GopBltSize);\r
+    IsAllocated = TRUE;\r
+    if (*GopBlt == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  } else {\r
+    //\r
+    // GopBlt has been allocated by caller.\r
+    //\r
+    if (*GopBltSize < (UINTN) BltBufferSize) {\r
+      *GopBltSize = (UINTN) BltBufferSize;\r
+      return EFI_BUFFER_TOO_SMALL;\r
+    }\r
+  }\r
+\r
+  *PixelWidth   = BmpHeader->PixelWidth;\r
+  *PixelHeight  = BmpHeader->PixelHeight;\r
+\r
+  //\r
+  // Convert image from BMP to Blt buffer format\r
+  //\r
+  BltBuffer = *GopBlt;\r
+  for (Height = 0; Height < BmpHeader->PixelHeight; Height++) {\r
+    Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth];\r
+    for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) {\r
+      switch (BmpHeader->BitPerPixel) {\r
+      case 1:\r
+        //\r
+        // Convert 1-bit (2 colors) BMP to 24-bit color\r
+        //\r
+        for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) {\r
+          Blt->Red    = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red;\r
+          Blt->Green  = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green;\r
+          Blt->Blue   = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue;\r
+          Blt++;\r
+          Width++;\r
+        }\r
+\r
+        Blt--;\r
+        Width--;\r
+        break;\r
+\r
+      case 4:\r
+        //\r
+        // Convert 4-bit (16 colors) BMP Palette to 24-bit color\r
+        //\r
+        Index       = (*Image) >> 4;\r
+        Blt->Red    = BmpColorMap[Index].Red;\r
+        Blt->Green  = BmpColorMap[Index].Green;\r
+        Blt->Blue   = BmpColorMap[Index].Blue;\r
+        if (Width < (BmpHeader->PixelWidth - 1)) {\r
+          Blt++;\r
+          Width++;\r
+          Index       = (*Image) & 0x0f;\r
+          Blt->Red    = BmpColorMap[Index].Red;\r
+          Blt->Green  = BmpColorMap[Index].Green;\r
+          Blt->Blue   = BmpColorMap[Index].Blue;\r
+        }\r
+        break;\r
+\r
+      case 8:\r
+        //\r
+        // Convert 8-bit (256 colors) BMP Palette to 24-bit color\r
+        //\r
+        Blt->Red    = BmpColorMap[*Image].Red;\r
+        Blt->Green  = BmpColorMap[*Image].Green;\r
+        Blt->Blue   = BmpColorMap[*Image].Blue;\r
+        break;\r
+\r
+      case 24:\r
+        //\r
+        // It is 24-bit BMP.\r
+        //\r
+        Blt->Blue   = *Image++;\r
+        Blt->Green  = *Image++;\r
+        Blt->Red    = *Image;\r
+        break;\r
+\r
+      default:\r
+        //\r
+        // Other bit format BMP is not supported.\r
+        //\r
+        if (IsAllocated) {\r
+          FreePool (*GopBlt);\r
+          *GopBlt = NULL;\r
+        }\r
+        return EFI_UNSUPPORTED;\r
+        break;\r
+      };\r
+\r
+    }\r
+\r
+    ImageIndex = (UINTN) (Image - ImageHeader);\r
+    if ((ImageIndex % 4) != 0) {\r
+      //\r
+      // Bmp Image starts each row on a 32-bit boundary!\r
+      //\r
+      Image = Image + (4 - (ImageIndex % 4));\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\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
+  @retval EFI_SUCCESS     ConsoleControl has been flipped to graphics and logo displayed.\r
+  @retval EFI_UNSUPPORTED Logo not found\r
+\r
+**/\r
+EFI_STATUS\r
+PlatformBootManagerEnableQuietBoot (\r
+  IN  EFI_GUID  *LogoFile\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_OEM_BADGING_PROTOCOL      *Badging;\r
+  UINT32                        SizeOfX;\r
+  UINT32                        SizeOfY;\r
+  INTN                          DestX;\r
+  INTN                          DestY;\r
+  UINT8                         *ImageData;\r
+  UINTN                         ImageSize;\r
+  UINTN                         BltSize;\r
+  UINT32                        Instance;\r
+  EFI_BADGING_FORMAT            Format;\r
+  EFI_BADGING_DISPLAY_ATTRIBUTE Attribute;\r
+  UINTN                         CoordinateX;\r
+  UINTN                         CoordinateY;\r
+  UINTN                         Height;\r
+  UINTN                         Width;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;\r
+  EFI_UGA_DRAW_PROTOCOL         *UgaDraw;\r
+  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
+  // Try to open GOP first\r
+  //\r
+  Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput);\r
+  if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+    GraphicsOutput = NULL;\r
+    //\r
+    // Open GOP failed, try to open UGA\r
+    //\r
+    Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw);\r
+  }\r
+  if (EFI_ERROR (Status)) {\r
+    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
+  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
+    SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;\r
+\r
+  } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+    Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+  } else {\r
+    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
+    ImageSize = 0;\r
+\r
+    if (Badging != NULL) {\r
+      //\r
+      // Get image from OEMBadging protocol.\r
+      //\r
+      Status = Badging->GetImage (\r
+                          Badging,\r
+                          &Instance,\r
+                          &Format,\r
+                          &ImageData,\r
+                          &ImageSize,\r
+                          &Attribute,\r
+                          &CoordinateX,\r
+                          &CoordinateY\r
+                          );\r
+      if (EFI_ERROR (Status)) {\r
+        goto Done;\r
+      }\r
+\r
+      //\r
+      // Currently only support BMP format.\r
+      //\r
+      if (Format != EfiBadgingFormatBMP) {\r
+        if (ImageData != NULL) {\r
+          FreePool (ImageData);\r
+        }\r
+        continue;\r
+      }\r
+    } else {\r
+      //\r
+      // Get the specified image from FV.\r
+      //\r
+      Status = GetSectionFromAnyFv (LogoFile, EFI_SECTION_RAW, 0, (VOID **) &ImageData, &ImageSize);\r
+      if (EFI_ERROR (Status)) {\r
+        return EFI_UNSUPPORTED;\r
+      }\r
+\r
+      CoordinateX = 0;\r
+      CoordinateY = 0;\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 = PlatformBootManagerConvertBmpToGopBlt (\r
+              ImageData,\r
+              ImageSize,\r
+              (VOID **) &Blt,\r
+              &BltSize,\r
+              &Height,\r
+              &Width\r
+              );\r
+    if (EFI_ERROR (Status)) {\r
+      FreePool (ImageData);\r
+\r
+      if (Badging == NULL) {\r
+        return Status;\r
+      } else {\r
+        continue;\r
+      }\r
+    }\r
+\r
+    //\r
+    // Calculate the display position according to Attribute.\r
+    //\r
+    switch (Attribute) {\r
+    case EfiBadgingDisplayAttributeLeftTop:\r
+      DestX = CoordinateX;\r
+      DestY = CoordinateY;\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeCenterTop:\r
+      DestX = (SizeOfX - Width) / 2;\r
+      DestY = CoordinateY;\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeRightTop:\r
+      DestX = (SizeOfX - Width - CoordinateX);\r
+      DestY = CoordinateY;;\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeCenterRight:\r
+      DestX = (SizeOfX - Width - CoordinateX);\r
+      DestY = (SizeOfY - Height) / 2;\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeRightBottom:\r
+      DestX = (SizeOfX - Width - CoordinateX);\r
+      DestY = (SizeOfY - Height - CoordinateY);\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeCenterBottom:\r
+      DestX = (SizeOfX - Width) / 2;\r
+      DestY = (SizeOfY - Height - CoordinateY);\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeLeftBottom:\r
+      DestX = CoordinateX;\r
+      DestY = (SizeOfY - Height - CoordinateY);\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeCenterLeft:\r
+      DestX = CoordinateX;\r
+      DestY = (SizeOfY - Height) / 2;\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeCenter:\r
+      DestX = (SizeOfX - Width) / 2;\r
+      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
+      break;\r
+    }\r
+\r
+    if ((DestX >= 0) && (DestY >= 0)) {\r
+      if (GraphicsOutput != NULL) {\r
+        Status = GraphicsOutput->Blt (\r
+                            GraphicsOutput,\r
+                            Blt,\r
+                            EfiBltBufferToVideo,\r
+                            0,\r
+                            0,\r
+                            (UINTN) DestX,\r
+                            (UINTN) DestY,\r
+                            Width,\r
+                            Height,\r
+                            Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+                            );\r
+      } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+        Status = UgaDraw->Blt (\r
+                            UgaDraw,\r
+                            (EFI_UGA_PIXEL *) Blt,\r
+                            EfiUgaBltBufferToVideo,\r
+                            0,\r
+                            0,\r
+                            (UINTN) DestX,\r
+                            (UINTN) DestY,\r
+                            Width,\r
+                            Height,\r
+                            Width * sizeof (EFI_UGA_PIXEL)\r
+                            );\r
+      } else {\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
+    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 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
+**/\r
+EFI_STATUS\r
+PlatformBootManagerDisableQuietBoot (\r
+  VOID\r
+  )\r
+{\r
+  //\r
+  // Enable Cursor on Screen\r
+  //\r
+  gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
+  return EFI_SUCCESS;\r
+}\r
index 7964b2b..3f634fc 100644 (file)
@@ -19,92 +19,47 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 EFI_GUID mUefiShellFileGuid = { 0x7C04A583, 0x9E3E, 0x4f1c, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 };\r
 \r
 /**\r
-  Perform the memory test base on the memory test intensive level,\r
-  and update the memory resource.\r
+  Perform the platform diagnostic, such like test memory. OEM/IBV also\r
+  can customize this function to support specific platform diagnostic.\r
 \r
-  @param  Level         The memory test intensive level.\r
-\r
-  @retval EFI_STATUS    Success test all the system memory and update\r
-                        the memory resource\r
+  @param MemoryTestLevel  The memory test intensive level\r
+  @param QuietBoot        Indicate if need to enable the quiet boot\r
 \r
 **/\r
-EFI_STATUS\r
-PlatformBootManagerMemoryTest (\r
-  IN EXTENDMEM_COVERAGE_LEVEL Level\r
+VOID\r
+PlatformBootManagerDiagnostics (\r
+  IN EXTENDMEM_COVERAGE_LEVEL    MemoryTestLevel,\r
+  IN BOOLEAN                     QuietBoot\r
   )\r
 {\r
-  EFI_STATUS                        Status;\r
-  BOOLEAN                           RequireSoftECCInit;\r
-  EFI_GENERIC_MEMORY_TEST_PROTOCOL  *GenMemoryTest;\r
-  UINT64                            TestedMemorySize;\r
-  UINT64                            TotalMemorySize;\r
-  UINTN                             TestPercent;\r
-  UINT64                            PreviousValue;\r
-  BOOLEAN                           ErrorOut;\r
-  UINT32                            TempData;\r
-\r
-  TestedMemorySize  = 0;\r
-  TotalMemorySize   = 0;\r
-  PreviousValue     = 0;\r
-\r
-  RequireSoftECCInit = FALSE;\r
-\r
-  Status = gBS->LocateProtocol (\r
-                  &gEfiGenericMemTestProtocolGuid,\r
-                  NULL,\r
-                  (VOID **) &GenMemoryTest\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_SUCCESS;\r
-  }\r
+  EFI_STATUS                     Status;\r
+\r
+  //\r
+  // Here we can decide if we need to show\r
+  // the diagnostics screen\r
+  // Notes: this quiet boot code should be remove\r
+  // from the graphic lib\r
+  //\r
+  if (QuietBoot) {\r
+    PlatformBootManagerEnableQuietBoot (PcdGetPtr(PcdLogoFile));\r
 \r
-  Status = GenMemoryTest->MemoryTestInit (\r
-                            GenMemoryTest,\r
-                            Level,\r
-                            &RequireSoftECCInit\r
-                            );\r
-  if (Status == EFI_NO_MEDIA) {\r
     //\r
-    // The PEI codes also have the relevant memory test code to check the memory,\r
-    // it can select to test some range of the memory or all of them. If PEI code\r
-    // checks all the memory, this BDS memory test will has no not-test memory to\r
-    // do the test, and then the status of EFI_NO_MEDIA will be returned by\r
-    // "MemoryTestInit". So it does not need to test memory again, just return.\r
+    // Perform system diagnostic\r
     //\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  do {\r
-    Status = GenMemoryTest->PerformMemoryTest (\r
-                              GenMemoryTest,\r
-                              &TestedMemorySize,\r
-                              &TotalMemorySize,\r
-                              &ErrorOut,\r
-                              FALSE\r
-                              );\r
-    if (ErrorOut && (Status == EFI_DEVICE_ERROR)) {\r
-      Print (L"System encounters memory errors!");\r
-      CpuDeadLoop ();\r
-    }\r
-    \r
-    TempData = (UINT32) DivU64x32 (TotalMemorySize, 16);\r
-    TestPercent = (UINTN) DivU64x32 (\r
-                            DivU64x32 (MultU64x32 (TestedMemorySize, 100), 16),\r
-                            TempData\r
-                            );\r
-    if (TestPercent != PreviousValue) {\r
-      Print (L"Perform memory test: %d/100", TestPercent);\r
-      PreviousValue = TestPercent;\r
+    Status = PlatformBootManagerMemoryTest (MemoryTestLevel);\r
+    if (EFI_ERROR (Status)) {\r
+      PlatformBootManagerDisableQuietBoot ();\r
     }\r
-  } while (Status != EFI_NOT_FOUND);\r
 \r
-  Status = GenMemoryTest->Finished (GenMemoryTest);\r
+    return;\r
+  }\r
 \r
-  Print (L"\r%dM bytes of system memory tested OK\n", (UINT32) DivU64x32 (TotalMemorySize, 1024 * 1024));\r
-  return EFI_SUCCESS;\r
+  //\r
+  // Perform system diagnostic\r
+  //\r
+  Status = PlatformBootManagerMemoryTest (MemoryTestLevel);\r
 }\r
 \r
-\r
 /**\r
   Return the index of the load option in the load option array.\r
 \r
@@ -284,15 +239,19 @@ PlatformBootManagerAfterConsole (
   VOID\r
   )\r
 {\r
-  PlatformBootManagerMemoryTest (QUICK);\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL  Black;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL  White;\r
+\r
+  Black.Blue = Black.Green = Black.Red = Black.Reserved = 0;\r
+  White.Blue = White.Green = White.Red = White.Reserved = 0xFF;\r
+\r
   EfiBootManagerConnectAll ();\r
   EfiBootManagerRefreshAllBootOption ();\r
-  Print (\r
-    L"\n"\r
-    L"F2    to enter Boot Manager Menu.\n"\r
-    L"Enter to boot directly.\n"\r
-    L"\n"\r
-    );\r
+\r
+  PlatformBootManagerDiagnostics (QUICK, TRUE);\r
+  \r
+  PrintXY (10, 10, &White, &Black, L"F2    to enter Boot Manager Menu.                                            ");\r
+  PrintXY (10, 30, &White, &Black, L"Enter to boot directly.");\r
 }\r
 \r
 /**\r
@@ -306,5 +265,21 @@ PlatformBootManagerWaitCallback (
   UINT16          TimeoutRemain\r
   )\r
 {\r
-  Print (L"\r%-2d seconds remained...", TimeoutRemain);\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL White;\r
+  UINT16                        Timeout;\r
+\r
+  Timeout = PcdGet16 (PcdPlatformBootTimeOut);\r
+\r
+  Black.Blue = Black.Green = Black.Red = Black.Reserved = 0;\r
+  White.Blue = White.Green = White.Red = White.Reserved = 0xFF;\r
+\r
+  PlatformBootManagerShowProgress (\r
+    White,\r
+    Black,\r
+    L"Start boot option",\r
+    White,\r
+    (Timeout - TimeoutRemain) * 100 / Timeout,\r
+    0\r
+    );\r
 }\r
index eb1ffe1..7e0fae8 100644 (file)
@@ -15,12 +15,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define _PLATFORM_BOOT_MANAGER_H\r
 \r
 #include <PiDxe.h>\r
-\r
+#include <IndustryStandard/Bmp.h>\r
 #include <Guid/WinNtSystemConfig.h>\r
 #include <Protocol/GenericMemoryTest.h>\r
 #include <Protocol/WinNtThunk.h>\r
 #include <Protocol/WinNtIo.h>\r
 #include <Protocol/LoadedImage.h>\r
+#include <Protocol/UgaDraw.h>\r
+#include <Protocol/GraphicsOutput.h>\r
+#include <Protocol/OEMBadging.h>\r
+#include <Protocol/BootLogo.h>\r
 \r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
@@ -33,6 +37,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/UefiBootManagerLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/DevicePathLib.h>\r
+#include <Library/HiiLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/DxeServicesLib.h>\r
 \r
 \r
 typedef struct {\r
@@ -76,4 +83,71 @@ typedef struct {
   EFI_DEVICE_PATH_PROTOCOL        End;\r
 } NT_PLATFORM_GOP_DEVICE_PATH;\r
 \r
+/**\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
+  @retval EFI_SUCCESS     ConsoleControl has been flipped to graphics and logo displayed.\r
+  @retval EFI_UNSUPPORTED Logo not found\r
+\r
+**/\r
+EFI_STATUS\r
+PlatformBootManagerEnableQuietBoot (\r
+  IN  EFI_GUID  *LogoFile\r
+  );\r
+\r
+/**\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
+**/\r
+EFI_STATUS\r
+PlatformBootManagerDisableQuietBoot (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Perform the memory test base on the memory test intensive level,\r
+  and update the memory resource.\r
+\r
+  @param  Level         The memory test intensive level.\r
+\r
+  @retval EFI_STATUS    Success test all the system memory and update\r
+                        the memory resource\r
+\r
+**/\r
+EFI_STATUS\r
+PlatformBootManagerMemoryTest (\r
+  IN EXTENDMEM_COVERAGE_LEVEL Level\r
+  );\r
+\r
+/**\r
+\r
+  Show progress bar with title above it. It only works in Graphics mode.\r
+\r
+\r
+  @param TitleForeground Foreground color for Title.\r
+  @param TitleBackground Background color for Title.\r
+  @param Title           Title above progress bar.\r
+  @param ProgressColor   Progress bar color.\r
+  @param Progress        Progress (0-100)\r
+  @param PreviousValue   The previous value of the progress.\r
+\r
+  @retval  EFI_STATUS       Success update the progress bar\r
+\r
+**/\r
+EFI_STATUS\r
+PlatformBootManagerShowProgress (\r
+  IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground,\r
+  IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground,\r
+  IN CHAR16                        *Title,\r
+  IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor,\r
+  IN UINTN                         Progress,\r
+  IN UINTN                         PreviousValue\r
+  );\r
+\r
 #endif // _PLATFORM_BOOT_MANAGER_H\r
index 7fac55b..d617538 100644 (file)
   PlatformData.c\r
   PlatformBootManager.c\r
   PlatformBootManager.h\r
+  MemoryTest.c\r
+  Strings.uni\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
   MdeModulePkg/MdeModulePkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
   Nt32Pkg/Nt32Pkg.dec\r
 \r
 [LibraryClasses]\r
   BaseLib\r
+  UefiBootServicesTableLib\r
   UefiRuntimeServicesTableLib\r
   UefiLib\r
   UefiBootManagerLib\r
   PcdLib\r
+  DxeServicesLib\r
+  MemoryAllocationLib\r
+  DevicePathLib\r
+  HiiLib\r
+  PrintLib\r
 \r
 [Guids]\r
   gEfiWinNtSystemConfigGuid\r
 \r
 [Protocols]\r
   gEfiGenericMemTestProtocolGuid  ## CONSUMES\r
+  gEfiGraphicsOutputProtocolGuid  ## CONSUMES\r
+  gEfiUgaDrawProtocolGuid         ## CONSUMES\r
+  gEfiOEMBadgingProtocolGuid      ## CONSUMES\r
+  gEfiBootLogoProtocolGuid        ## CONSUMES\r
 \r
 [Pcd]\r
+  gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn\r
+  gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdBootlogoOnlyEnable\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand\r
diff --git a/Nt32Pkg/Library/PlatformBootManagerLib/Strings.uni b/Nt32Pkg/Library/PlatformBootManagerLib/Strings.uni
new file mode 100644 (file)
index 0000000..f8823fe
Binary files /dev/null and b/Nt32Pkg/Library/PlatformBootManagerLib/Strings.uni differ