Move DSO update/check to TccLib (#1444)
IsMarkedBadDso and InvalidateBadDso would be required for all the platforms that support TCC. And the implementation is also common, so just move them to common TccLib. Also updated the implementation to remove SPI flash erase for InvalidateBadDso(). Signed-off-by: Guo Dong <guo.dong@intel.com>
This commit is contained in:
parent
500300c537
commit
bf4a56033f
|
@ -40,7 +40,7 @@
|
|||
#include <Library/ResetSystemLib.h>
|
||||
#include <Library/WatchDogTimerLib.h>
|
||||
#include <Library/SocInitLib.h>
|
||||
|
||||
#include <Library/TccLib.h>
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
BootGuardLib
|
||||
BoardSupportLib
|
||||
WatchDogTimerLib
|
||||
TccLib
|
||||
|
||||
[Guids]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include <Library/BootloaderCommonLib.h>
|
||||
#include <Library/BootloaderCoreLib.h>
|
||||
#include <Library/TccLib.h>
|
||||
#include <Library/SpiFlashLib.h>
|
||||
#include <Library/ContainerLib.h>
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
DebugLib
|
||||
HobLib
|
||||
BootloaderCoreLib
|
||||
SpiFlashLib
|
||||
ContainerLib
|
||||
|
||||
[Guids]
|
||||
gTccRtctHobGuid
|
||||
|
|
Loading…
Reference in New Issue