From 8c533a4e567dc29eb31cf1d991f31700aad12d45 Mon Sep 17 00:00:00 2001 From: Raghava Gudla Date: Fri, 9 Aug 2019 14:25:33 -0700 Subject: [PATCH] [CFL] MRC data save is ignored after first boot Current code will check if the first 4 bytes of the existing MRC training data, if it is 0xFFFFFFFF then MRC training data will be saved otherwise even though there is change in the training data, it will not be saved. Modified the code to compare the incoming training data to the saved data, if they do not match, save the incoming training data. Signed-off-by: Raghava Gudla --- .../Stage2BoardInitLib/Stage2BoardInitLib.c | 69 +++++++++---------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/Platform/CoffeelakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.c b/Platform/CoffeelakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.c index a47b9ea3..8df19cbb 100644 --- a/Platform/CoffeelakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.c +++ b/Platform/CoffeelakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.c @@ -1596,54 +1596,53 @@ SaveNvsData ( UINT32 Address; UINT32 BaseAddress; UINT32 RegionSize; - UINT32 TotalSize; + UINT32 MrcDataRegSize; - Status = GetComponentInfo (FLASH_MAP_SIG_MRCDATA, &Address, NULL); + Status = GetComponentInfo (FLASH_MAP_SIG_MRCDATA, &Address, &MrcDataRegSize); if (EFI_ERROR(Status)) { return EFI_NOT_FOUND; } - if (*(UINT32 *)Address == 0xFFFFFFFF) { - Status = SpiConstructor (); - if (EFI_ERROR (Status)) { - return Status; - } - Status = SpiGetRegionAddress (FlashRegionAll, NULL, &TotalSize); - if (EFI_ERROR (Status)) { - return Status; - } + if (Length > MrcDataRegSize) { + return EFI_INVALID_PARAMETER; + } - Status = SpiGetRegionAddress (FlashRegionBios, &BaseAddress, &RegionSize); - if (EFI_ERROR (Status)) { - return Status; - } + // + // Compare input data against the stored MRC training data + // if they match, no need to update again. + // + if (CompareMem ((VOID *)Address, Buffer, Length) == 0){ + return EFI_ALREADY_STARTED; + } - BaseAddress += ((UINT32)(~TotalSize) + 1); - if (Address < BaseAddress) { - return EFI_ACCESS_DENIED; - } + Status = SpiGetRegionAddress (FlashRegionBios, &BaseAddress, &RegionSize); + if (EFI_ERROR (Status)) { + return Status; + } - Address -= BaseAddress; - if ((Address + ROUNDED_UP(Length, KB_(4))) > RegionSize) { - return EFI_OUT_OF_RESOURCES; - } + BaseAddress = ((UINT32)(~RegionSize) + 1); + if (Address < BaseAddress) { + return EFI_ACCESS_DENIED; + } + Address -= BaseAddress; + if ((Address + ROUNDED_UP(Length, KB_(4))) > RegionSize) { + return EFI_OUT_OF_RESOURCES; + } + + if (!EFI_ERROR(Status)) { + Status = SpiFlashErase (FlashRegionBios, Address, ROUNDED_UP(Length, KB_(4))); if (!EFI_ERROR(Status)) { - Status = SpiFlashErase (FlashRegionBios, Address, ROUNDED_UP(Length, KB_(4))); + Status = SpiFlashWrite (FlashRegionBios, Address, Length, Buffer); if (!EFI_ERROR(Status)) { - Status = SpiFlashWrite (FlashRegionBios, Address, Length, Buffer); - if (!EFI_ERROR(Status)) { - DEBUG ((DEBUG_INFO, "MRC data successfully cached to 0x%X\n", Address)); - MmioAndThenOr8 ( - PCH_PWRM_BASE_ADDRESS + R_PMC_PWRM_GEN_PMCON_A + 2, - (UINT8) ~((B_PMC_PWRM_GEN_PMCON_A_MS4V | B_PMC_PWRM_GEN_PMCON_A_SUS_PWR_FLR) >> 16), - B_PMC_PWRM_GEN_PMCON_A_DISB >> 16 - ); - } + DEBUG ((DEBUG_INFO, "MRC data successfully cached to 0x%X\n", Address)); + MmioAndThenOr8 ( + PCH_PWRM_BASE_ADDRESS + R_PMC_PWRM_GEN_PMCON_A + 2, + (UINT8) ~((B_PMC_PWRM_GEN_PMCON_A_MS4V | B_PMC_PWRM_GEN_PMCON_A_SUS_PWR_FLR) >> 16), + B_PMC_PWRM_GEN_PMCON_A_DISB >> 16 + ); } } - } else { - Status = EFI_ALREADY_STARTED; } return Status;