]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/BdsDxe/MemoryTest.c
IntelFrameworkModulePkg: Replace [Ascii|Unicode]ValueToString
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / MemoryTest.c
index 19a505e2b7d8e21fe8d5f955a91b803ac9e16029..118808201d1f02db454ff6d34f346bcfe9de303e 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Perform the platform memory test\r
 \r
-Copyright (c) 2004 - 2009, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2004 - 2017, 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
@@ -203,6 +203,7 @@ PlatformBdsShowProgress (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 BdsMemoryTest (\r
   IN EXTENDMEM_COVERAGE_LEVEL Level\r
   )\r
@@ -229,11 +230,13 @@ BdsMemoryTest (
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL     Color;\r
   BOOLEAN                           IsFirstBoot;\r
   UINT32                            TempData;\r
+  UINTN                             StrTotalMemorySize;\r
 \r
   ReturnStatus = EFI_SUCCESS;\r
   ZeroMem (&Key, sizeof (EFI_INPUT_KEY));\r
 \r
-  Pos = AllocatePool (128);\r
+  StrTotalMemorySize = 128;\r
+  Pos = AllocateZeroPool (StrTotalMemorySize);\r
 \r
   if (Pos == NULL) {\r
     return ReturnStatus;\r
@@ -279,14 +282,17 @@ BdsMemoryTest (
     FreePool (Pos);\r
     return EFI_SUCCESS;\r
   }\r
+  \r
+  if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {\r
+    TmpStr = GetStringById (STRING_TOKEN (STR_ESC_TO_SKIP_MEM_TEST));\r
 \r
-  TmpStr = GetStringById (STRING_TOKEN (STR_ESC_TO_SKIP_MEM_TEST));\r
-\r
-  if (TmpStr != NULL) {\r
-    PrintXY (10, 10, NULL, NULL, TmpStr);\r
-    FreePool (TmpStr);\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
-\r
   do {\r
     Status = GenMemoryTest->PerformMemoryTest (\r
                               GenMemoryTest,\r
@@ -304,43 +310,30 @@ BdsMemoryTest (
 \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
+        UnicodeValueToStringS (StrPercent, sizeof (StrPercent), 0, TestPercent, 0);\r
+        TmpStr = GetStringById (STRING_TOKEN (STR_MEMORY_TEST_PERCENT));\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
-    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 = GetStringById (STRING_TOKEN (STR_MEMORY_TEST_PERCENT));\r
-      if (TmpStr != NULL) {\r
-        //\r
-        // TmpStr size is 64, StrPercent is reserved to 16.\r
-        //\r
-        StrCat (StrPercent, TmpStr);\r
-        PrintXY (10, 10, NULL, NULL, StrPercent);\r
-        FreePool (TmpStr);\r
-      }\r
-\r
-      TmpStr = GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST));\r
-      if (TmpStr != NULL) {\r
-        PlatformBdsShowProgress (\r
-          Foreground,\r
-          Background,\r
-          TmpStr,\r
-          Color,\r
-          TestPercent,\r
-          (UINTN) PreviousValue\r
-          );\r
-        FreePool (TmpStr);\r
-      }\r
-    }\r
-\r
-    PreviousValue = TestPercent;\r
-\r
-    KeyStatus     = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-    if (!EFI_ERROR (KeyStatus) && (Key.ScanCode == SCAN_ESC)) {\r
-      if (!RequireSoftECCInit) {\r
         TmpStr = GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST));\r
         if (TmpStr != NULL) {\r
           PlatformBdsShowProgress (\r
@@ -348,54 +341,95 @@ BdsMemoryTest (
             Background,\r
             TmpStr,\r
             Color,\r
-            100,\r
+            TestPercent,\r
             (UINTN) PreviousValue\r
             );\r
           FreePool (TmpStr);\r
         }\r
-\r
-        PrintXY (10, 10, NULL, NULL, L"100");\r
-        Status = GenMemoryTest->Finished (GenMemoryTest);\r
-        goto Done;\r
       }\r
 \r
-      TestAbort = TRUE;\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 = GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST));\r
+            if (TmpStr != NULL) {\r
+              PlatformBdsShowProgress (\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
-  UnicodeValueToString (StrTotalMemory, COMMA_TYPE, TotalMemorySize, 0);\r
-  if (StrTotalMemory[0] == L',') {\r
-    StrTotalMemory++;\r
-  }\r
-\r
-  TmpStr = GetStringById (STRING_TOKEN (STR_MEM_TEST_COMPLETED));\r
-  if (TmpStr != NULL) {\r
-    StrCat (StrTotalMemory, TmpStr);\r
-    FreePool (TmpStr);\r
-  }\r
+  if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {\r
+    UnicodeValueToStringS (StrTotalMemory, StrTotalMemorySize, COMMA_TYPE, TotalMemorySize, 0);\r
+    if (StrTotalMemory[0] == L',') {\r
+      StrTotalMemory++;\r
+      StrTotalMemorySize -= sizeof (CHAR16);\r
+    }\r
 \r
-  PrintXY (10, 10, NULL, NULL, StrTotalMemory);\r
-  PlatformBdsShowProgress (\r
-    Foreground,\r
-    Background,\r
-    StrTotalMemory,\r
-    Color,\r
-    100,\r
-    (UINTN) PreviousValue\r
-    );\r
+    TmpStr = GetStringById (STRING_TOKEN (STR_MEM_TEST_COMPLETED));\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
+    PlatformBdsShowProgress (\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
 \r
+\r
   //\r
   // Use a DynamicHii type pcd to save the boot status, which is used to\r
   // control configuration mode, such as FULL/MINIMAL/NO_CHANGES configuration.\r
   //\r
   IsFirstBoot = PcdGetBool(PcdBootState);\r
   if (IsFirstBoot) {\r
-    PcdSetBool(PcdBootState, FALSE);\r
+    Status = PcdSetBoolS(PcdBootState, FALSE);\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "Set PcdBootState to FALSE failed.\n"));\r
+    }\r
   }\r
 \r
   return ReturnStatus;\r