Skip to content

Commit 49a16cc

Browse files
gldivineyJuston Li
authored andcommitted
Updates to make recover SPI work again
Signed-off-by: Glenn L Diviney <glenn.l.diviney@intel.com> Signed-off-by: Juston Li <juston.li@intel.com>
1 parent c53b1f1 commit 49a16cc

File tree

2 files changed

+57
-19
lines changed

2 files changed

+57
-19
lines changed

DcpmPkg/cli/LoadRecoverCommand.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,25 +240,24 @@ LoadRecover(
240240
**/
241241
}
242242

243-
if (Examine) {
244-
pFwImageInfo = AllocateZeroPool(sizeof(*pFwImageInfo));
245-
if (pFwImageInfo == NULL) {
246-
Print(FORMAT_STR_NL, CLI_ERR_OUT_OF_MEMORY);
247-
ReturnCode = EFI_OUT_OF_RESOURCES;
248-
goto Finish;
249-
}
243+
pFwImageInfo = AllocateZeroPool(sizeof(FW_IMAGE_INFO));
244+
if (pFwImageInfo == NULL) {
245+
Print(FORMAT_STR_NL, CLI_ERR_OUT_OF_MEMORY);
246+
ReturnCode = EFI_OUT_OF_RESOURCES;
247+
goto Finish;
250248
}
251249

252-
// Create callback that will print progress
253250
if (!Examine) {
254-
gBS->CreateEvent((EVT_TIMER|EVT_NOTIFY_SIGNAL), PRINT_PRIORITY, PrintProgress, pCommandStatus, &ProgressEvent);
251+
// Create callback that will print progress
252+
gBS->CreateEvent((EVT_TIMER | EVT_NOTIFY_SIGNAL), PRINT_PRIORITY, PrintProgress, pCommandStatus, &ProgressEvent);
255253
gBS->SetTimer(ProgressEvent, TimerPeriodic, PROGRESS_EVENT_TIMEOUT);
256254
}
257255

258256
ReturnCode = pNvmDimmConfigProtocol->UpdateFw(pNvmDimmConfigProtocol, pDimmIds, DimmIdsCount, pRelativeFileName,
259257
(CHAR16 *) pWorkingDirectory, Examine, FALSE, TRUE, FlashSpi, pFwImageInfo, pCommandStatus);
260258

261259
if (Examine && pCommandStatus->GeneralStatus != NVM_ERR_OPERATION_NOT_SUPPORTED_BY_MIXED_SKU) {
260+
262261
if (pFwImageInfo != NULL && pCommandStatus->GeneralStatus == NVM_SUCCESS) {
263262

264263
Print(FORMAT_STR L": %02d.%02d.%02d.%04d\n",
@@ -270,13 +269,17 @@ LoadRecover(
270269
} else {
271270
Print(FORMAT_STR FORMAT_STR_NL, pFileName, CLI_ERR_VERSION_RETRIEVE);
272271
}
272+
273273
DisplayCommandStatus(L"", L"", pCommandStatus);
274274
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
275275
goto Finish;
276276
} else {
277277
if (!EFI_ERROR(ReturnCode)) {
278278
Print(L"\n");
279279
}
280+
}
281+
282+
if (!Examine) {
280283
gBS->CloseEvent(ProgressEvent);
281284
}
282285

DcpmPkg/driver/Protocol/Driver/NvmDimmConfig.c

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4739,7 +4739,6 @@ DebugWriteSpiImageToFile(
47394739
EFI_FILE_HANDLE FileHandle = NULL;
47404740
CHAR16 *FileNameFconfig = NULL;
47414741

4742-
47434742
FileHandle = NULL;
47444743
FileNameFconfig = CatSPrint(NULL, L"new_spi_w_merged_fconfig_0x%04x.bin", DimmHandle);
47454744

@@ -4844,6 +4843,7 @@ RecoverDimmFw(
48444843
*pNvmStatus = NVM_ERR_SPD_NOT_ACCESSIBLE;
48454844
goto Finish;
48464845
}
4846+
48474847
if (DeviceId != SPD_DEVICE_ID_DCPM_GEN1) {
48484848
NVDIMM_ERR("Incompatible hardware revision 0x%x", DeviceId);
48494849
*pNvmStatus = NVM_ERR_INCOMPATIBLE_HARDWARE_REVISION;
@@ -4889,8 +4889,7 @@ RecoverDimmFw(
48894889
// dimm back to a good state after testing.
48904890
// TODO: Needed for validation only! We do not need this after product PRQ and will
48914891
// probably confuse people
4892-
CHECK_RESULT(DebugWriteSpiImageToFile(pWorkingDirectory, pCurrentDimm->DeviceHandle.AsUint32,
4893-
pNewSpiImageBuffer, ImageBufferSize), Finish);
4892+
DebugWriteSpiImageToFile(pWorkingDirectory, pCurrentDimm->DeviceHandle.AsUint32, pNewSpiImageBuffer, ImageBufferSize);
48944893
///////////////////////////////////////////////////
48954894

48964895
CHECK_RESULT(SpiEraseChip(pCurrentDimm, pCommandStatus), Finish);
@@ -4957,6 +4956,8 @@ UpdateFw(
49574956
UINTN TempBuffSize = 0;
49584957
NVM_STATUS NvmStatus = NVM_ERR_OPERATION_NOT_STARTED;
49594958
BOOLEAN ValidImage = TRUE;
4959+
BOOLEAN* pDimmsCanBeRecovered = NULL;
4960+
UINT32 DimmsToRecover = 0;
49604961

49614962
ZeroMem(pDimms, sizeof(pDimms));
49624963

@@ -5008,6 +5009,14 @@ UpdateFw(
50085009
goto Finish;
50095010
}
50105011

5012+
if (pFwImageInfo != NULL) {
5013+
pFwImageInfo->Date = pFileHeader->Date;
5014+
pFwImageInfo->ImageVersion = pFileHeader->ImageVersion;
5015+
pFwImageInfo->FirmwareType = pFileHeader->ImageType;
5016+
pFwImageInfo->ModuleVendor = pFileHeader->ModuleVendor;
5017+
pFwImageInfo->Size = pFileHeader->Size;
5018+
}
5019+
50115020
TempReturnCode = OpenFile(pFileName, &FileHandle, pWorkingDirectory, FALSE);
50125021
TempReturnCode = GetFileSize(FileHandle, &BuffSize);
50135022

@@ -5030,10 +5039,14 @@ UpdateFw(
50305039
}
50315040

50325041
// don't update, just get image information
5033-
if (pFwImageInfo == NULL) {
5042+
if (TRUE == Examine) {
50345043
goto Finish;
50355044
}
5045+
5046+
pDimmsCanBeRecovered = AllocatePool(sizeof(BOOLEAN) * DimmsNum);
5047+
50365048
for (Index = 0; Index < DimmsNum; Index++) {
5049+
pDimmsCanBeRecovered[Index] = FALSE;
50375050
if (Recovery && FlashSPI) {
50385051
// We will only be able to flash spi if we can access the
50395052
// spi interface over smbus
@@ -5046,6 +5059,8 @@ UpdateFw(
50465059
if (EFI_ERROR(TempReturnCode)) {
50475060
SetObjStatusForDimm(pCommandStatus, pDimms[Index], NVM_ERR_RECOVERY_ACCESS_NOT_ENABLED);
50485061
} else {
5062+
pDimmsCanBeRecovered[Index] = TRUE;
5063+
DimmsToRecover++;
50495064
SetObjStatusForDimm(pCommandStatus, pDimms[Index], NVM_SUCCESS_IMAGE_EXAMINE_OK);
50505065
}
50515066
} else {
@@ -5065,21 +5080,27 @@ UpdateFw(
50655080
}
50665081
}
50675082
} else {
5083+
pDimmsCanBeRecovered[Index] = TRUE;
5084+
DimmsToRecover++;
50685085
SetObjStatusForDimm(pCommandStatus, pDimms[Index], NVM_SUCCESS_IMAGE_EXAMINE_OK);
50695086
}
50705087
}
50715088
}
50725089

5073-
pFwImageInfo->Date = pFileHeader->Date;
5074-
pFwImageInfo->ImageVersion = pFileHeader->ImageVersion;
5075-
pFwImageInfo->FirmwareType = pFileHeader->ImageType;
5076-
pFwImageInfo->ModuleVendor = pFileHeader->ModuleVendor;
5077-
pFwImageInfo->Size = pFileHeader->Size;
5090+
if (DimmsToRecover == 0) {
5091+
Print(L"There are no DIMMs which can be updated\n");
5092+
ResetCmdStatus(pCommandStatus, NVM_ERR_GENERAL_DEV_FAILURE);
5093+
goto Finish;
5094+
}
50785095

50795096
ReturnCode = EFI_SUCCESS;
50805097
if (!Examine && ValidImage) {
50815098
// upload FW image to all specified DIMMs
50825099
for (Index = 0; Index < DimmsNum; Index++) {
5100+
if (pDimmsCanBeRecovered[Index] == FALSE) {
5101+
continue;
5102+
}
5103+
50835104
if (Recovery && FlashSPI) {
50845105
ReturnCode = RecoverDimmFw(pDimms[Index]->DeviceHandle.AsUint32,
50855106
pImageBuffer, BuffSize, pWorkingDirectory, &NvmStatus, pCommandStatus);
@@ -5089,8 +5110,21 @@ UpdateFw(
50895110
ReturnCode = UpdateDimmFw(pDimms[Index]->DimmID, pImageBuffer, BuffSize, Force, &NvmStatus);
50905111
}
50915112

5092-
SetObjStatusForDimm(pCommandStatus, pDimms[Index], NvmStatus);
5113+
if (EFI_ERROR(ReturnCode)) {
5114+
if (NvmStatus == NVM_SUCCESS) {
5115+
SetObjStatusForDimm(pCommandStatus, pDimms[Index], NVM_ERR_OPERATION_FAILED);
5116+
}
5117+
else
5118+
{
5119+
SetObjStatusForDimm(pCommandStatus, pDimms[Index], NvmStatus);
5120+
}
5121+
}
5122+
else
5123+
{
5124+
SetObjStatusForDimm(pCommandStatus, pDimms[Index], NvmStatus);
5125+
}
50935126
}
5127+
50945128
SetCmdStatus(pCommandStatus, NVM_SUCCESS);
50955129
}
50965130

@@ -5101,6 +5135,7 @@ UpdateFw(
51015135
FREE_POOL_SAFE(pFileHeader);
51025136
FREE_POOL_SAFE(pImageBuffer);
51035137
FREE_POOL_SAFE(pErrorMessage);
5138+
FREE_POOL_SAFE(pDimmsCanBeRecovered);
51045139
NVDIMM_EXIT_I64(ReturnCode);
51055140
return ReturnCode;
51065141
}

0 commit comments

Comments
 (0)