Skip to content

Commit

Permalink
Updates to make recover SPI work again
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn L Diviney <[email protected]>
Signed-off-by: Juston Li <[email protected]>
  • Loading branch information
gldiviney authored and Juston Li committed Sep 12, 2018
1 parent c53b1f1 commit 49a16cc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 19 deletions.
21 changes: 12 additions & 9 deletions DcpmPkg/cli/LoadRecoverCommand.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,25 +240,24 @@ LoadRecover(
**/
}

if (Examine) {
pFwImageInfo = AllocateZeroPool(sizeof(*pFwImageInfo));
if (pFwImageInfo == NULL) {
Print(FORMAT_STR_NL, CLI_ERR_OUT_OF_MEMORY);
ReturnCode = EFI_OUT_OF_RESOURCES;
goto Finish;
}
pFwImageInfo = AllocateZeroPool(sizeof(FW_IMAGE_INFO));
if (pFwImageInfo == NULL) {
Print(FORMAT_STR_NL, CLI_ERR_OUT_OF_MEMORY);
ReturnCode = EFI_OUT_OF_RESOURCES;
goto Finish;
}

// Create callback that will print progress
if (!Examine) {
gBS->CreateEvent((EVT_TIMER|EVT_NOTIFY_SIGNAL), PRINT_PRIORITY, PrintProgress, pCommandStatus, &ProgressEvent);
// Create callback that will print progress
gBS->CreateEvent((EVT_TIMER | EVT_NOTIFY_SIGNAL), PRINT_PRIORITY, PrintProgress, pCommandStatus, &ProgressEvent);
gBS->SetTimer(ProgressEvent, TimerPeriodic, PROGRESS_EVENT_TIMEOUT);
}

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

if (Examine && pCommandStatus->GeneralStatus != NVM_ERR_OPERATION_NOT_SUPPORTED_BY_MIXED_SKU) {

if (pFwImageInfo != NULL && pCommandStatus->GeneralStatus == NVM_SUCCESS) {

Print(FORMAT_STR L": %02d.%02d.%02d.%04d\n",
Expand All @@ -270,13 +269,17 @@ LoadRecover(
} else {
Print(FORMAT_STR FORMAT_STR_NL, pFileName, CLI_ERR_VERSION_RETRIEVE);
}

DisplayCommandStatus(L"", L"", pCommandStatus);
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
goto Finish;
} else {
if (!EFI_ERROR(ReturnCode)) {
Print(L"\n");
}
}

if (!Examine) {
gBS->CloseEvent(ProgressEvent);
}

Expand Down
55 changes: 45 additions & 10 deletions DcpmPkg/driver/Protocol/Driver/NvmDimmConfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -4739,7 +4739,6 @@ DebugWriteSpiImageToFile(
EFI_FILE_HANDLE FileHandle = NULL;
CHAR16 *FileNameFconfig = NULL;


FileHandle = NULL;
FileNameFconfig = CatSPrint(NULL, L"new_spi_w_merged_fconfig_0x%04x.bin", DimmHandle);

Expand Down Expand Up @@ -4844,6 +4843,7 @@ RecoverDimmFw(
*pNvmStatus = NVM_ERR_SPD_NOT_ACCESSIBLE;
goto Finish;
}

if (DeviceId != SPD_DEVICE_ID_DCPM_GEN1) {
NVDIMM_ERR("Incompatible hardware revision 0x%x", DeviceId);
*pNvmStatus = NVM_ERR_INCOMPATIBLE_HARDWARE_REVISION;
Expand Down Expand Up @@ -4889,8 +4889,7 @@ RecoverDimmFw(
// dimm back to a good state after testing.
// TODO: Needed for validation only! We do not need this after product PRQ and will
// probably confuse people
CHECK_RESULT(DebugWriteSpiImageToFile(pWorkingDirectory, pCurrentDimm->DeviceHandle.AsUint32,
pNewSpiImageBuffer, ImageBufferSize), Finish);
DebugWriteSpiImageToFile(pWorkingDirectory, pCurrentDimm->DeviceHandle.AsUint32, pNewSpiImageBuffer, ImageBufferSize);
///////////////////////////////////////////////////

CHECK_RESULT(SpiEraseChip(pCurrentDimm, pCommandStatus), Finish);
Expand Down Expand Up @@ -4957,6 +4956,8 @@ UpdateFw(
UINTN TempBuffSize = 0;
NVM_STATUS NvmStatus = NVM_ERR_OPERATION_NOT_STARTED;
BOOLEAN ValidImage = TRUE;
BOOLEAN* pDimmsCanBeRecovered = NULL;
UINT32 DimmsToRecover = 0;

ZeroMem(pDimms, sizeof(pDimms));

Expand Down Expand Up @@ -5008,6 +5009,14 @@ UpdateFw(
goto Finish;
}

if (pFwImageInfo != NULL) {
pFwImageInfo->Date = pFileHeader->Date;
pFwImageInfo->ImageVersion = pFileHeader->ImageVersion;
pFwImageInfo->FirmwareType = pFileHeader->ImageType;
pFwImageInfo->ModuleVendor = pFileHeader->ModuleVendor;
pFwImageInfo->Size = pFileHeader->Size;
}

TempReturnCode = OpenFile(pFileName, &FileHandle, pWorkingDirectory, FALSE);
TempReturnCode = GetFileSize(FileHandle, &BuffSize);

Expand All @@ -5030,10 +5039,14 @@ UpdateFw(
}

// don't update, just get image information
if (pFwImageInfo == NULL) {
if (TRUE == Examine) {
goto Finish;
}

pDimmsCanBeRecovered = AllocatePool(sizeof(BOOLEAN) * DimmsNum);

for (Index = 0; Index < DimmsNum; Index++) {
pDimmsCanBeRecovered[Index] = FALSE;
if (Recovery && FlashSPI) {
// We will only be able to flash spi if we can access the
// spi interface over smbus
Expand All @@ -5046,6 +5059,8 @@ UpdateFw(
if (EFI_ERROR(TempReturnCode)) {
SetObjStatusForDimm(pCommandStatus, pDimms[Index], NVM_ERR_RECOVERY_ACCESS_NOT_ENABLED);
} else {
pDimmsCanBeRecovered[Index] = TRUE;
DimmsToRecover++;
SetObjStatusForDimm(pCommandStatus, pDimms[Index], NVM_SUCCESS_IMAGE_EXAMINE_OK);
}
} else {
Expand All @@ -5065,21 +5080,27 @@ UpdateFw(
}
}
} else {
pDimmsCanBeRecovered[Index] = TRUE;
DimmsToRecover++;
SetObjStatusForDimm(pCommandStatus, pDimms[Index], NVM_SUCCESS_IMAGE_EXAMINE_OK);
}
}
}

pFwImageInfo->Date = pFileHeader->Date;
pFwImageInfo->ImageVersion = pFileHeader->ImageVersion;
pFwImageInfo->FirmwareType = pFileHeader->ImageType;
pFwImageInfo->ModuleVendor = pFileHeader->ModuleVendor;
pFwImageInfo->Size = pFileHeader->Size;
if (DimmsToRecover == 0) {
Print(L"There are no DIMMs which can be updated\n");
ResetCmdStatus(pCommandStatus, NVM_ERR_GENERAL_DEV_FAILURE);
goto Finish;
}

ReturnCode = EFI_SUCCESS;
if (!Examine && ValidImage) {
// upload FW image to all specified DIMMs
for (Index = 0; Index < DimmsNum; Index++) {
if (pDimmsCanBeRecovered[Index] == FALSE) {
continue;
}

if (Recovery && FlashSPI) {
ReturnCode = RecoverDimmFw(pDimms[Index]->DeviceHandle.AsUint32,
pImageBuffer, BuffSize, pWorkingDirectory, &NvmStatus, pCommandStatus);
Expand All @@ -5089,8 +5110,21 @@ UpdateFw(
ReturnCode = UpdateDimmFw(pDimms[Index]->DimmID, pImageBuffer, BuffSize, Force, &NvmStatus);
}

SetObjStatusForDimm(pCommandStatus, pDimms[Index], NvmStatus);
if (EFI_ERROR(ReturnCode)) {
if (NvmStatus == NVM_SUCCESS) {
SetObjStatusForDimm(pCommandStatus, pDimms[Index], NVM_ERR_OPERATION_FAILED);
}
else
{
SetObjStatusForDimm(pCommandStatus, pDimms[Index], NvmStatus);
}
}
else
{
SetObjStatusForDimm(pCommandStatus, pDimms[Index], NvmStatus);
}
}

SetCmdStatus(pCommandStatus, NVM_SUCCESS);
}

Expand All @@ -5101,6 +5135,7 @@ UpdateFw(
FREE_POOL_SAFE(pFileHeader);
FREE_POOL_SAFE(pImageBuffer);
FREE_POOL_SAFE(pErrorMessage);
FREE_POOL_SAFE(pDimmsCanBeRecovered);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
Expand Down

0 comments on commit 49a16cc

Please sign in to comment.