diff --git a/Platform/TigerlakeBoardPkg/Library/Stage1BBoardInitLib/Stage1BBoardInitLib.c b/Platform/TigerlakeBoardPkg/Library/Stage1BBoardInitLib/Stage1BBoardInitLib.c index 7f22074f..38d57774 100644 --- a/Platform/TigerlakeBoardPkg/Library/Stage1BBoardInitLib/Stage1BBoardInitLib.c +++ b/Platform/TigerlakeBoardPkg/Library/Stage1BBoardInitLib/Stage1BBoardInitLib.c @@ -40,7 +40,7 @@ #include #include #include - +#include CONST PLT_DEVICE mPlatformDevices[]= { {{0x00001700}, OsBootDeviceSata , 0 }, @@ -58,117 +58,6 @@ GetBoardId ( OUT UINT8 *BoardId ); - -/** - Check if the BAD DSO mark exists or not - BAD DSO mark is defined as - LOADER_COMPRESSED_HEADER of the component in flash - Its Signature' and 'Size' fields are 0 (zero). - Other fields are subject to change - - @retval TRUE DSO was marked as BAD DSO - @retval FALSE No BAD DSO mark found - - */ -BOOLEAN -EFIAPI -IsMarkedBadDso ( - VOID -) -{ - EFI_STATUS Status; - UINT32 Length; - LOADER_COMPRESSED_HEADER *Hdr; - LOADER_COMPRESSED_HEADER BadDsoMark = {0}; - - DEBUG ((DEBUG_INFO, "Check BAD DSO mark\n")); - - Status = LocateComponent (SIGNATURE_32 ('I', 'P', 'F', 'W'), - SIGNATURE_32 ('T', 'C', 'C', 'T'), - (VOID *)&Hdr, &Length); - if (EFI_ERROR (Status) || (Length < sizeof(LOADER_COMPRESSED_HEADER))) { - return FALSE; - } - - if ((Hdr->Signature == BadDsoMark.Signature) && (Hdr->Size == BadDsoMark.Size)) { - DEBUG ((DEBUG_INFO, "BAD DSO(TCCT) detected!\n")); - return TRUE; - } else { - return FALSE; - } -} - -/** - Invalidate BAD DSO - - @retval EFI_SUCCESS - @retval EFI_NOT_FOUND Unable to find IPFW/TCCT - @retval EFI_OUT_OF_RESOURCES Bios region is too small - @retval Others Errors during SPI operations - - */ -EFI_STATUS -EFIAPI -InvalidateBadDso ( - VOID -) -{ - EFI_STATUS Status; - UINT32 Address; - UINT32 Length; - UINT32 BaseAddress; - UINT32 RegionSize; - CONTAINER_ENTRY *ContainerEntry; - COMPONENT_ENTRY *CompEntry; - CONTAINER_HDR *ContainerHdr; - // BAD DSO mark: The 'Signature' and 'Size' fields are zero(0) - // Other fields are subject to change - LOADER_COMPRESSED_HEADER BadDsoMark = {0}; - - DEBUG ((DEBUG_INFO, "Invalidate BAD DSO region\n")); - - Status = LocateComponentEntry (SIGNATURE_32 ('I', 'P', 'F', 'W'), - SIGNATURE_32 ('T', 'C', 'C', 'T'), - &ContainerEntry, &CompEntry); - if (EFI_ERROR (Status) || (ContainerEntry == NULL) || (CompEntry == NULL)) { - return EFI_NOT_FOUND; - } - - /* a region should have 4KB as min erase size */ - Length = SIZE_4KB; - if (CompEntry->Size < Length) { - return EFI_OUT_OF_RESOURCES; - } - - ContainerHdr = (CONTAINER_HDR *)(UINTN)ContainerEntry->HeaderCache; - Address = ContainerEntry->Base + ContainerHdr->DataOffset + CompEntry->Offset; - - /* Svn is kept for anti-rollback control */ - BadDsoMark.Svn = ((LOADER_COMPRESSED_HEADER *)(UINTN)Address)->Svn; - - Status = SpiGetRegionAddress (FlashRegionBios, &BaseAddress, &RegionSize); - if (EFI_ERROR (Status)) { - return Status; - } - - BaseAddress = ((UINT32)(~RegionSize) + 1); - - Address -= BaseAddress; - if ((Address + Length) > RegionSize) { - return EFI_OUT_OF_RESOURCES; - } - - Status = SpiFlashErase (FlashRegionBios, Address, Length); - if (!EFI_ERROR(Status)) { - Status = SpiFlashWrite (FlashRegionBios, Address, sizeof(BadDsoMark), (VOID *)&BadDsoMark); - if (!EFI_ERROR(Status)) { - DEBUG ((DEBUG_INFO, "Mark BAD DSO(TCCT) successfully\n")); - } - } - - return Status; -} - /** Update FSP-M UPD config data for TCC mode and tuning diff --git a/Platform/TigerlakeBoardPkg/Library/Stage1BBoardInitLib/Stage1BBoardInitLib.inf b/Platform/TigerlakeBoardPkg/Library/Stage1BBoardInitLib/Stage1BBoardInitLib.inf index 0c03f899..03b09939 100644 --- a/Platform/TigerlakeBoardPkg/Library/Stage1BBoardInitLib/Stage1BBoardInitLib.inf +++ b/Platform/TigerlakeBoardPkg/Library/Stage1BBoardInitLib/Stage1BBoardInitLib.inf @@ -48,6 +48,7 @@ BootGuardLib BoardSupportLib WatchDogTimerLib + TccLib [Guids] diff --git a/Silicon/CommonSocPkg/Include/Library/TccLib.h b/Silicon/CommonSocPkg/Include/Library/TccLib.h index f61dfaf8..298895ab 100644 --- a/Silicon/CommonSocPkg/Include/Library/TccLib.h +++ b/Silicon/CommonSocPkg/Include/Library/TccLib.h @@ -28,4 +28,31 @@ UpdateAcpiRtctTable ( IN EFI_ACPI_DESCRIPTION_HEADER *RtctTable ); +/** + Check if the TCC DSO is a bad binary by checking its signature. + + @retval TRUE TCC DSO was marked as a bad binary + @retval FALSE TCC DSO was not found or not marked as a bad binary + + */ +BOOLEAN +EFIAPI +IsMarkedBadDso ( + VOID + ); + +/** + Mark TCC DSO as a bad binary by changing its signature to 0. + + @retval EFI_SUCCESS + @retval EFI_NOT_FOUND Unable to find IPFW/TCCT + @retval Others Errors during SPI operations + + */ +EFI_STATUS +EFIAPI +InvalidateBadDso ( + VOID + ); + #endif diff --git a/Silicon/CommonSocPkg/Library/TccLib/TccLib.c b/Silicon/CommonSocPkg/Library/TccLib/TccLib.c index 50875023..db2278f5 100644 --- a/Silicon/CommonSocPkg/Library/TccLib/TccLib.c +++ b/Silicon/CommonSocPkg/Library/TccLib/TccLib.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include "TccRtctHob.h" @@ -82,3 +84,79 @@ UpdateAcpiRtctTable ( return EFI_SUCCESS; } +/** + Check if the TCC DSO is a bad binary by checking its signature. + + @retval TRUE TCC DSO was marked as a bad binary + @retval FALSE TCC DSO was not found or not marked as a bad binary + + */ +BOOLEAN +EFIAPI +IsMarkedBadDso ( + VOID + ) +{ + EFI_STATUS Status; + UINT32 Length; + LOADER_COMPRESSED_HEADER *Hdr; + + Status = LocateComponent (SIGNATURE_32 ('I', 'P', 'F', 'W'), SIGNATURE_32 ('T', 'C', 'C', 'T'), (VOID *)&Hdr, &Length); + if (EFI_ERROR (Status) || (Length < sizeof(LOADER_COMPRESSED_HEADER))) { + return FALSE; + } + + if (Hdr->Signature == 0) { + DEBUG ((DEBUG_INFO, "BAD DSO(TCCT) detected!\n")); + return TRUE; + } else { + return FALSE; + } +} + +/** + Mark TCC DSO as a bad binary by changing its signature to 0. + + @retval EFI_SUCCESS + @retval EFI_NOT_FOUND Unable to find IPFW/TCCT + @retval Others Errors during SPI operations + + */ +EFI_STATUS +EFIAPI +InvalidateBadDso ( + VOID + ) +{ + EFI_STATUS Status; + UINT32 Address; + UINT32 BaseAddress; + UINT32 RegionSize; + CONTAINER_ENTRY *ContainerEntry; + COMPONENT_ENTRY *CompEntry; + CONTAINER_HDR *ContainerHdr; + UINT32 Signature; + + Status = LocateComponentEntry (SIGNATURE_32 ('I', 'P', 'F', 'W'), SIGNATURE_32 ('T', 'C', 'C', 'T'), &ContainerEntry, &CompEntry); + if (EFI_ERROR (Status) || (ContainerEntry == NULL) || (CompEntry == NULL)) { + return EFI_NOT_FOUND; + } + + Status = SpiGetRegionAddress (FlashRegionBios, NULL, &RegionSize); + if (EFI_ERROR (Status)) { + return Status; + } + BaseAddress = ((UINT32)(~RegionSize) + 1); + + ContainerHdr = (CONTAINER_HDR *)(UINTN)ContainerEntry->HeaderCache; + Address = ContainerEntry->Base + ContainerHdr->DataOffset + CompEntry->Offset; + Address -= BaseAddress; + + // Update 'Signature' field to 0 to mark bad DSO + Signature = 0; + Status = SpiFlashWrite (FlashRegionBios, Address, sizeof(Signature), (VOID *)&Signature); + if (!EFI_ERROR(Status)) { + DEBUG ((DEBUG_INFO, "Mark BAD DSO(TCCT) successfully\n")); + } + return Status; +} diff --git a/Silicon/CommonSocPkg/Library/TccLib/TccLib.inf b/Silicon/CommonSocPkg/Library/TccLib/TccLib.inf index 21d76196..aec8b94c 100644 --- a/Silicon/CommonSocPkg/Library/TccLib/TccLib.inf +++ b/Silicon/CommonSocPkg/Library/TccLib/TccLib.inf @@ -34,6 +34,8 @@ DebugLib HobLib BootloaderCoreLib + SpiFlashLib + ContainerLib [Guids] gTccRtctHobGuid