2 Perform the platform memory test
4 Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "PlatformBootManager.h"
11 EFI_HII_HANDLE gStringPackHandle
= NULL
;
12 EFI_GUID mPlatformBootManagerStringPackGuid
= {
13 0x154dd51, 0x9079, 0x4a10, { 0x89, 0x5c, 0x9c, 0x7, 0x72, 0x81, 0x57, 0x88 }
15 // extern UINT8 BdsDxeStrings[];
18 // BDS Platform Functions
22 Perform the memory test base on the memory test intensive level,
23 and update the memory resource.
25 @param Level The memory test intensive level.
27 @retval EFI_STATUS Success test all the system memory and update
32 PlatformBootManagerMemoryTest (
33 IN EXTENDMEM_COVERAGE_LEVEL Level
38 EFI_STATUS InitStatus
;
39 EFI_STATUS ReturnStatus
;
40 BOOLEAN RequireSoftECCInit
;
41 EFI_GENERIC_MEMORY_TEST_PROTOCOL
*GenMemoryTest
;
42 UINT64 TestedMemorySize
;
43 UINT64 TotalMemorySize
;
49 CHAR16 StrPercent
[80];
50 CHAR16
*StrTotalMemory
;
53 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
54 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
55 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
57 UINTN StrTotalMemorySize
;
59 ReturnStatus
= EFI_SUCCESS
;
60 ZeroMem (&Key
, sizeof (EFI_INPUT_KEY
));
62 StrTotalMemorySize
= 128;
63 Pos
= AllocateZeroPool (StrTotalMemorySize
);
66 if (gStringPackHandle
== NULL
) {
67 gStringPackHandle
= HiiAddPackages (
68 &mPlatformBootManagerStringPackGuid
,
70 PlatformBootManagerLibStrings
,
73 ASSERT (gStringPackHandle
!= NULL
);
84 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
85 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
86 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
88 RequireSoftECCInit
= FALSE
;
90 Status
= gBS
->LocateProtocol (
91 &gEfiGenericMemTestProtocolGuid
,
93 (VOID
**) &GenMemoryTest
95 if (EFI_ERROR (Status
)) {
100 InitStatus
= GenMemoryTest
->MemoryTestInit (
105 if (InitStatus
== EFI_NO_MEDIA
) {
107 // The PEI codes also have the relevant memory test code to check the memory,
108 // it can select to test some range of the memory or all of them. If PEI code
109 // checks all the memory, this BDS memory test will has no not-test memory to
110 // do the test, and then the status of EFI_NO_MEDIA will be returned by
111 // "MemoryTestInit". So it does not need to test memory again, just return.
117 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
118 TmpStr
= HiiGetString (gStringPackHandle
, STRING_TOKEN (STR_ESC_TO_SKIP_MEM_TEST
), NULL
);
120 if (TmpStr
!= NULL
) {
121 PrintXY (10, 10, NULL
, NULL
, TmpStr
);
125 DEBUG ((EFI_D_INFO
, "Enter memory test.\n"));
128 Status
= GenMemoryTest
->PerformMemoryTest (
135 if (ErrorOut
&& (Status
== EFI_DEVICE_ERROR
)) {
136 TmpStr
= HiiGetString (gStringPackHandle
, STRING_TOKEN (STR_SYSTEM_MEM_ERROR
), NULL
);
137 if (TmpStr
!= NULL
) {
138 PrintXY (10, 10, NULL
, NULL
, TmpStr
);
145 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
146 TempData
= (UINT32
) DivU64x32 (TotalMemorySize
, 16);
147 TestPercent
= (UINTN
) DivU64x32 (
148 DivU64x32 (MultU64x32 (TestedMemorySize
, 100), 16),
151 if (TestPercent
!= PreviousValue
) {
152 UnicodeValueToStringS (StrPercent
, sizeof (StrPercent
), 0, TestPercent
, 0);
153 TmpStr
= HiiGetString (gStringPackHandle
, STRING_TOKEN (STR_MEMORY_TEST_PERCENT
), NULL
);
154 if (TmpStr
!= NULL
) {
156 // TmpStr size is 64, StrPercent is reserved to 16.
160 sizeof (StrPercent
) / sizeof (CHAR16
),
162 sizeof (StrPercent
) / sizeof (CHAR16
) - StrLen (StrPercent
) - 1
164 PrintXY (10, 10, NULL
, NULL
, StrPercent
);
168 TmpStr
= HiiGetString (gStringPackHandle
, STRING_TOKEN (STR_PERFORM_MEM_TEST
), NULL
);
169 if (TmpStr
!= NULL
) {
170 BootLogoUpdateProgress (
176 (UINTN
) PreviousValue
182 PreviousValue
= TestPercent
;
184 DEBUG ((EFI_D_INFO
, "Perform memory test (ESC to skip).\n"));
187 if (!PcdGetBool (PcdConInConnectOnDemand
)) {
188 KeyStatus
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
189 if (!EFI_ERROR (KeyStatus
) && (Key
.ScanCode
== SCAN_ESC
)) {
190 if (!RequireSoftECCInit
) {
191 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
192 TmpStr
= HiiGetString (gStringPackHandle
, STRING_TOKEN (STR_PERFORM_MEM_TEST
), NULL
);
193 if (TmpStr
!= NULL
) {
194 BootLogoUpdateProgress (
200 (UINTN
) PreviousValue
205 PrintXY (10, 10, NULL
, NULL
, L
"100");
207 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
214 } while (Status
!= EFI_NOT_FOUND
);
216 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
219 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
220 UnicodeValueToStringS (StrTotalMemory
, StrTotalMemorySize
, COMMA_TYPE
, TotalMemorySize
, 0);
221 if (StrTotalMemory
[0] == L
',') {
223 StrTotalMemorySize
-= sizeof (CHAR16
);
226 TmpStr
= HiiGetString (gStringPackHandle
, STRING_TOKEN (STR_MEM_TEST_COMPLETED
), NULL
);
227 if (TmpStr
!= NULL
) {
230 StrTotalMemorySize
/ sizeof (CHAR16
),
232 StrTotalMemorySize
/ sizeof (CHAR16
) - StrLen (StrTotalMemory
) - 1
237 PrintXY (10, 10, NULL
, NULL
, StrTotalMemory
);
238 BootLogoUpdateProgress (
244 (UINTN
) PreviousValue
248 DEBUG ((EFI_D_INFO
, "%d bytes of system memory tested OK\r\n", TotalMemorySize
));