SignedCapsulePkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the SignedCapsulePkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:14 -08:00
committed by mergify[bot]
parent 47d20b54f9
commit b878648967
15 changed files with 1336 additions and 1215 deletions

View File

@@ -30,9 +30,9 @@
#include <Protocol/FirmwareManagement.h>
EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR *mImageFmpInfo;
UINTN mImageFmpInfoSize;
EFI_GUID mEdkiiSystemFirmwareFileGuid;
EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR *mImageFmpInfo;
UINTN mImageFmpInfoSize;
EFI_GUID mEdkiiSystemFirmwareFileGuid;
/**
Check if a block of buffer is erased.
@@ -46,16 +46,16 @@ EFI_GUID mEdkiiSystemFirmwareFileGuid;
**/
BOOLEAN
IsBufferErased (
IN UINT8 ErasePolarity,
IN VOID *InBuffer,
IN UINTN BufferSize
IN UINT8 ErasePolarity,
IN VOID *InBuffer,
IN UINTN BufferSize
)
{
UINTN Count;
UINT8 EraseByte;
UINT8 *Buffer;
UINTN Count;
UINT8 EraseByte;
UINT8 *Buffer;
if(ErasePolarity == 1) {
if (ErasePolarity == 1) {
EraseByte = 0xFF;
} else {
EraseByte = 0;
@@ -86,17 +86,17 @@ IsBufferErased (
**/
BOOLEAN
GetSectionByType (
IN VOID *SectionBuffer,
IN UINT32 SectionBufferSize,
IN EFI_SECTION_TYPE SectionType,
IN UINTN SectionInstance,
OUT VOID **OutSectionBuffer,
OUT UINTN *OutSectionSize
IN VOID *SectionBuffer,
IN UINT32 SectionBufferSize,
IN EFI_SECTION_TYPE SectionType,
IN UINTN SectionInstance,
OUT VOID **OutSectionBuffer,
OUT UINTN *OutSectionSize
)
{
EFI_COMMON_SECTION_HEADER *SectionHeader;
UINTN SectionSize;
UINTN Instance;
EFI_COMMON_SECTION_HEADER *SectionHeader;
UINTN SectionSize;
UINTN Instance;
DEBUG ((DEBUG_INFO, "GetSectionByType - Buffer: 0x%08x - 0x%08x\n", SectionBuffer, SectionBufferSize));
@@ -108,20 +108,20 @@ GetSectionByType (
Instance = 0;
while ((UINTN)SectionHeader < (UINTN)SectionBuffer + SectionBufferSize) {
DEBUG ((DEBUG_INFO, "GetSectionByType - Section: 0x%08x\n", SectionHeader));
if (IS_SECTION2(SectionHeader)) {
SectionSize = SECTION2_SIZE(SectionHeader);
if (IS_SECTION2 (SectionHeader)) {
SectionSize = SECTION2_SIZE (SectionHeader);
} else {
SectionSize = SECTION_SIZE(SectionHeader);
SectionSize = SECTION_SIZE (SectionHeader);
}
if (SectionHeader->Type == SectionType) {
if (Instance == SectionInstance) {
*OutSectionBuffer = (UINT8 *)SectionHeader;
*OutSectionSize = SectionSize;
DEBUG((DEBUG_INFO, "GetSectionByType - 0x%x - 0x%x\n", *OutSectionBuffer, *OutSectionSize));
*OutSectionSize = SectionSize;
DEBUG ((DEBUG_INFO, "GetSectionByType - 0x%x - 0x%x\n", *OutSectionBuffer, *OutSectionSize));
return TRUE;
} else {
DEBUG((DEBUG_INFO, "GetSectionByType - find section instance %x\n", Instance));
DEBUG ((DEBUG_INFO, "GetSectionByType - find section instance %x\n", Instance));
Instance++;
}
} else {
@@ -134,7 +134,7 @@ GetSectionByType (
//
// Next Section
//
SectionHeader = (EFI_COMMON_SECTION_HEADER *)((UINTN)SectionHeader + ALIGN_VALUE(SectionSize, 4));
SectionHeader = (EFI_COMMON_SECTION_HEADER *)((UINTN)SectionHeader + ALIGN_VALUE (SectionSize, 4));
}
return FALSE;
@@ -155,25 +155,25 @@ GetSectionByType (
**/
BOOLEAN
GetFfsByName (
IN VOID *FdStart,
IN UINTN FdSize,
IN EFI_GUID *FileName,
IN EFI_FV_FILETYPE Type,
OUT VOID **OutFfsBuffer,
OUT UINTN *OutFfsBufferSize
IN VOID *FdStart,
IN UINTN FdSize,
IN EFI_GUID *FileName,
IN EFI_FV_FILETYPE Type,
OUT VOID **OutFfsBuffer,
OUT UINTN *OutFfsBufferSize
)
{
UINTN FvSize;
EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
EFI_FIRMWARE_VOLUME_EXT_HEADER *FvExtHeader;
EFI_FFS_FILE_HEADER *FfsHeader;
UINT32 FfsSize;
UINTN TestLength;
BOOLEAN FvFound;
UINTN FvSize;
EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
EFI_FIRMWARE_VOLUME_EXT_HEADER *FvExtHeader;
EFI_FFS_FILE_HEADER *FfsHeader;
UINT32 FfsSize;
UINTN TestLength;
BOOLEAN FvFound;
DEBUG ((DEBUG_INFO, "GetFfsByName - FV: 0x%08x - 0x%08x\n", (UINTN)FdStart, (UINTN)FdSize));
FvFound = FALSE;
FvFound = FALSE;
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)FdStart;
while ((UINTN)FvHeader < (UINTN)FdStart + FdSize - 1) {
FvSize = (UINTN)FdStart + FdSize - (UINTN)FvHeader;
@@ -182,12 +182,14 @@ GetFfsByName (
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN)FvHeader + SIZE_4KB);
continue;
}
DEBUG((DEBUG_INFO, "checking FV....0x%08x - 0x%x\n", FvHeader, FvHeader->FvLength));
DEBUG ((DEBUG_INFO, "checking FV....0x%08x - 0x%x\n", FvHeader, FvHeader->FvLength));
FvFound = TRUE;
if (FvHeader->FvLength > FvSize) {
DEBUG((DEBUG_ERROR, "GetFfsByName - FvSize: 0x%08x, MaxSize - 0x%08x\n", (UINTN)FvHeader->FvLength, (UINTN)FvSize));
DEBUG ((DEBUG_ERROR, "GetFfsByName - FvSize: 0x%08x, MaxSize - 0x%08x\n", (UINTN)FvHeader->FvLength, (UINTN)FvSize));
return FALSE;
}
FvSize = (UINTN)FvHeader->FvLength;
//
@@ -195,44 +197,47 @@ GetFfsByName (
//
if (FvHeader->ExtHeaderOffset != 0) {
FvExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)((UINT8 *)FvHeader + FvHeader->ExtHeaderOffset);
FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FvExtHeader + FvExtHeader->ExtHeaderSize);
FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FvExtHeader + FvExtHeader->ExtHeaderSize);
} else {
FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FvHeader + FvHeader->HeaderLength);
}
FfsHeader = (EFI_FFS_FILE_HEADER *)((UINTN)FvHeader + ALIGN_VALUE((UINTN)FfsHeader - (UINTN)FvHeader, 8));
FfsHeader = (EFI_FFS_FILE_HEADER *)((UINTN)FvHeader + ALIGN_VALUE ((UINTN)FfsHeader - (UINTN)FvHeader, 8));
while ((UINTN)FfsHeader < (UINTN)FvHeader + FvSize - 1) {
DEBUG((DEBUG_INFO, "GetFfsByName - FFS: 0x%08x\n", FfsHeader));
DEBUG ((DEBUG_INFO, "GetFfsByName - FFS: 0x%08x\n", FfsHeader));
TestLength = (UINTN)((UINTN)FvHeader + FvSize - (UINTN)FfsHeader);
if (TestLength > sizeof(EFI_FFS_FILE_HEADER)) {
TestLength = sizeof(EFI_FFS_FILE_HEADER);
if (TestLength > sizeof (EFI_FFS_FILE_HEADER)) {
TestLength = sizeof (EFI_FFS_FILE_HEADER);
}
if (IsBufferErased(1, FfsHeader, TestLength)) {
if (IsBufferErased (1, FfsHeader, TestLength)) {
break;
}
if (IS_FFS_FILE2(FfsHeader)) {
FfsSize = FFS_FILE2_SIZE(FfsHeader);
if (IS_FFS_FILE2 (FfsHeader)) {
FfsSize = FFS_FILE2_SIZE (FfsHeader);
} else {
FfsSize = FFS_FILE_SIZE(FfsHeader);
FfsSize = FFS_FILE_SIZE (FfsHeader);
}
if (CompareGuid(FileName, &FfsHeader->Name) &&
((Type == EFI_FV_FILETYPE_ALL) || (FfsHeader->Type == Type))) {
*OutFfsBuffer = FfsHeader;
if (CompareGuid (FileName, &FfsHeader->Name) &&
((Type == EFI_FV_FILETYPE_ALL) || (FfsHeader->Type == Type)))
{
*OutFfsBuffer = FfsHeader;
*OutFfsBufferSize = FfsSize;
return TRUE;
} else {
//
// Any other type is not allowed
//
DEBUG((DEBUG_INFO, "GetFfsByName - other FFS type 0x%x, name %g\n", FfsHeader->Type, &FfsHeader->Name));
DEBUG ((DEBUG_INFO, "GetFfsByName - other FFS type 0x%x, name %g\n", FfsHeader->Type, &FfsHeader->Name));
}
//
// Next File
//
FfsHeader = (EFI_FFS_FILE_HEADER *)((UINTN)FfsHeader + ALIGN_VALUE(FfsSize, 8));
FfsHeader = (EFI_FFS_FILE_HEADER *)((UINTN)FfsHeader + ALIGN_VALUE (FfsSize, 8));
}
//
@@ -242,8 +247,9 @@ GetFfsByName (
}
if (!FvFound) {
DEBUG((DEBUG_ERROR, "GetFfsByName - NO FV Found\n"));
DEBUG ((DEBUG_ERROR, "GetFfsByName - NO FV Found\n"));
}
return FALSE;
}
@@ -261,29 +267,30 @@ GetFfsByName (
BOOLEAN
EFIAPI
ExtractDriverFvImage (
IN VOID *AuthenticatedImage,
IN UINTN AuthenticatedImageSize,
OUT VOID **DriverFvImage,
OUT UINTN *DriverFvImageSize
IN VOID *AuthenticatedImage,
IN UINTN AuthenticatedImageSize,
OUT VOID **DriverFvImage,
OUT UINTN *DriverFvImageSize
)
{
BOOLEAN Result;
UINT32 FileHeaderSize;
BOOLEAN Result;
UINT32 FileHeaderSize;
*DriverFvImage = NULL;
*DriverFvImage = NULL;
*DriverFvImageSize = 0;
Result = GetFfsByName(AuthenticatedImage, AuthenticatedImageSize, &gEdkiiSystemFmpCapsuleDriverFvFileGuid, EFI_FV_FILETYPE_RAW, DriverFvImage, DriverFvImageSize);
Result = GetFfsByName (AuthenticatedImage, AuthenticatedImageSize, &gEdkiiSystemFmpCapsuleDriverFvFileGuid, EFI_FV_FILETYPE_RAW, DriverFvImage, DriverFvImageSize);
if (!Result) {
return FALSE;
}
if (IS_FFS_FILE2(*DriverFvImage)) {
FileHeaderSize = sizeof(EFI_FFS_FILE_HEADER2);
if (IS_FFS_FILE2 (*DriverFvImage)) {
FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER2);
} else {
FileHeaderSize = sizeof(EFI_FFS_FILE_HEADER);
FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER);
}
*DriverFvImage = (UINT8 *)*DriverFvImage + FileHeaderSize;
*DriverFvImage = (UINT8 *)*DriverFvImage + FileHeaderSize;
*DriverFvImageSize = *DriverFvImageSize - FileHeaderSize;
return Result;
@@ -303,29 +310,30 @@ ExtractDriverFvImage (
BOOLEAN
EFIAPI
ExtractConfigImage (
IN VOID *AuthenticatedImage,
IN UINTN AuthenticatedImageSize,
OUT VOID **ConfigImage,
OUT UINTN *ConfigImageSize
IN VOID *AuthenticatedImage,
IN UINTN AuthenticatedImageSize,
OUT VOID **ConfigImage,
OUT UINTN *ConfigImageSize
)
{
BOOLEAN Result;
UINT32 FileHeaderSize;
BOOLEAN Result;
UINT32 FileHeaderSize;
*ConfigImage = NULL;
*ConfigImage = NULL;
*ConfigImageSize = 0;
Result = GetFfsByName(AuthenticatedImage, AuthenticatedImageSize, &gEdkiiSystemFmpCapsuleConfigFileGuid, EFI_FV_FILETYPE_RAW, ConfigImage, ConfigImageSize);
Result = GetFfsByName (AuthenticatedImage, AuthenticatedImageSize, &gEdkiiSystemFmpCapsuleConfigFileGuid, EFI_FV_FILETYPE_RAW, ConfigImage, ConfigImageSize);
if (!Result) {
return FALSE;
}
if (IS_FFS_FILE2(*ConfigImage)) {
FileHeaderSize = sizeof(EFI_FFS_FILE_HEADER2);
if (IS_FFS_FILE2 (*ConfigImage)) {
FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER2);
} else {
FileHeaderSize = sizeof(EFI_FFS_FILE_HEADER);
FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER);
}
*ConfigImage = (UINT8 *)*ConfigImage + FileHeaderSize;
*ConfigImage = (UINT8 *)*ConfigImage + FileHeaderSize;
*ConfigImageSize = *ConfigImageSize - FileHeaderSize;
return Result;
@@ -348,20 +356,20 @@ ExtractConfigImage (
BOOLEAN
EFIAPI
ExtractAuthenticatedImage (
IN VOID *Image,
IN UINTN ImageSize,
OUT UINT32 *LastAttemptStatus,
OUT VOID **AuthenticatedImage,
OUT UINTN *AuthenticatedImageSize
IN VOID *Image,
IN UINTN ImageSize,
OUT UINT32 *LastAttemptStatus,
OUT VOID **AuthenticatedImage,
OUT UINTN *AuthenticatedImageSize
)
{
EFI_FIRMWARE_IMAGE_AUTHENTICATION *ImageAuth;
EFI_STATUS Status;
GUID *CertType;
VOID *PublicKeyData;
UINTN PublicKeyDataLength;
EFI_FIRMWARE_IMAGE_AUTHENTICATION *ImageAuth;
EFI_STATUS Status;
GUID *CertType;
VOID *PublicKeyData;
UINTN PublicKeyDataLength;
DEBUG((DEBUG_INFO, "ExtractAuthenticatedImage - Image: 0x%08x - 0x%08x\n", (UINTN)Image, (UINTN)ImageSize));
DEBUG ((DEBUG_INFO, "ExtractAuthenticatedImage - Image: 0x%08x - 0x%08x\n", (UINTN)Image, (UINTN)ImageSize));
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
if ((Image == NULL) || (ImageSize == 0)) {
@@ -369,82 +377,91 @@ ExtractAuthenticatedImage (
}
ImageAuth = (EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image;
if (ImageSize < sizeof(EFI_FIRMWARE_IMAGE_AUTHENTICATION)) {
DEBUG((DEBUG_ERROR, "ExtractAuthenticatedImage - ImageSize too small\n"));
if (ImageSize < sizeof (EFI_FIRMWARE_IMAGE_AUTHENTICATION)) {
DEBUG ((DEBUG_ERROR, "ExtractAuthenticatedImage - ImageSize too small\n"));
return FALSE;
}
if (ImageAuth->AuthInfo.Hdr.dwLength <= OFFSET_OF(WIN_CERTIFICATE_UEFI_GUID, CertData)) {
DEBUG((DEBUG_ERROR, "ExtractAuthenticatedImage - dwLength too small\n"));
if (ImageAuth->AuthInfo.Hdr.dwLength <= OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData)) {
DEBUG ((DEBUG_ERROR, "ExtractAuthenticatedImage - dwLength too small\n"));
return FALSE;
}
if ((UINTN) ImageAuth->AuthInfo.Hdr.dwLength > MAX_UINTN - sizeof(UINT64)) {
DEBUG((DEBUG_ERROR, "ExtractAuthenticatedImage - dwLength too big\n"));
if ((UINTN)ImageAuth->AuthInfo.Hdr.dwLength > MAX_UINTN - sizeof (UINT64)) {
DEBUG ((DEBUG_ERROR, "ExtractAuthenticatedImage - dwLength too big\n"));
return FALSE;
}
if (ImageSize <= sizeof(ImageAuth->MonotonicCount) + ImageAuth->AuthInfo.Hdr.dwLength) {
DEBUG((DEBUG_ERROR, "ExtractAuthenticatedImage - ImageSize too small\n"));
if (ImageSize <= sizeof (ImageAuth->MonotonicCount) + ImageAuth->AuthInfo.Hdr.dwLength) {
DEBUG ((DEBUG_ERROR, "ExtractAuthenticatedImage - ImageSize too small\n"));
return FALSE;
}
if (ImageAuth->AuthInfo.Hdr.wRevision != 0x0200) {
DEBUG((DEBUG_ERROR, "ExtractAuthenticatedImage - wRevision: 0x%02x, expect - 0x%02x\n", (UINTN)ImageAuth->AuthInfo.Hdr.wRevision, (UINTN)0x0200));
DEBUG ((DEBUG_ERROR, "ExtractAuthenticatedImage - wRevision: 0x%02x, expect - 0x%02x\n", (UINTN)ImageAuth->AuthInfo.Hdr.wRevision, (UINTN)0x0200));
return FALSE;
}
if (ImageAuth->AuthInfo.Hdr.wCertificateType != WIN_CERT_TYPE_EFI_GUID) {
DEBUG((DEBUG_ERROR, "ExtractAuthenticatedImage - wCertificateType: 0x%02x, expect - 0x%02x\n", (UINTN)ImageAuth->AuthInfo.Hdr.wCertificateType, (UINTN)WIN_CERT_TYPE_EFI_GUID));
DEBUG ((DEBUG_ERROR, "ExtractAuthenticatedImage - wCertificateType: 0x%02x, expect - 0x%02x\n", (UINTN)ImageAuth->AuthInfo.Hdr.wCertificateType, (UINTN)WIN_CERT_TYPE_EFI_GUID));
return FALSE;
}
CertType = &ImageAuth->AuthInfo.CertType;
DEBUG((DEBUG_INFO, "ExtractAuthenticatedImage - CertType: %g\n", CertType));
DEBUG ((DEBUG_INFO, "ExtractAuthenticatedImage - CertType: %g\n", CertType));
if (CompareGuid(&gEfiCertPkcs7Guid, CertType)) {
PublicKeyData = PcdGetPtr(PcdPkcs7CertBuffer);
PublicKeyDataLength = PcdGetSize(PcdPkcs7CertBuffer);
} else if (CompareGuid(&gEfiCertTypeRsa2048Sha256Guid, CertType)) {
PublicKeyData = PcdGetPtr(PcdRsa2048Sha256PublicKeyBuffer);
PublicKeyDataLength = PcdGetSize(PcdRsa2048Sha256PublicKeyBuffer);
if (CompareGuid (&gEfiCertPkcs7Guid, CertType)) {
PublicKeyData = PcdGetPtr (PcdPkcs7CertBuffer);
PublicKeyDataLength = PcdGetSize (PcdPkcs7CertBuffer);
} else if (CompareGuid (&gEfiCertTypeRsa2048Sha256Guid, CertType)) {
PublicKeyData = PcdGetPtr (PcdRsa2048Sha256PublicKeyBuffer);
PublicKeyDataLength = PcdGetSize (PcdRsa2048Sha256PublicKeyBuffer);
} else {
return FALSE;
}
ASSERT (PublicKeyData != NULL);
ASSERT (PublicKeyDataLength != 0);
Status = AuthenticateFmpImage(
Status = AuthenticateFmpImage (
ImageAuth,
ImageSize,
PublicKeyData,
PublicKeyDataLength
);
switch (Status) {
case RETURN_SUCCESS:
*LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;
break;
case RETURN_SECURITY_VIOLATION:
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR;
break;
case RETURN_INVALID_PARAMETER:
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
break;
case RETURN_UNSUPPORTED:
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
break;
case RETURN_OUT_OF_RESOURCES:
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES;
break;
default:
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
break;
case RETURN_SUCCESS:
*LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;
break;
case RETURN_SECURITY_VIOLATION:
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR;
break;
case RETURN_INVALID_PARAMETER:
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
break;
case RETURN_UNSUPPORTED:
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
break;
case RETURN_OUT_OF_RESOURCES:
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES;
break;
default:
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
break;
}
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
return FALSE;
}
if (AuthenticatedImage != NULL) {
*AuthenticatedImage = (UINT8 *)ImageAuth + ImageAuth->AuthInfo.Hdr.dwLength + sizeof(ImageAuth->MonotonicCount);
*AuthenticatedImage = (UINT8 *)ImageAuth + ImageAuth->AuthInfo.Hdr.dwLength + sizeof (ImageAuth->MonotonicCount);
}
if (AuthenticatedImageSize != NULL) {
*AuthenticatedImageSize = ImageSize - ImageAuth->AuthInfo.Hdr.dwLength - sizeof(ImageAuth->MonotonicCount);
*AuthenticatedImageSize = ImageSize - ImageAuth->AuthInfo.Hdr.dwLength - sizeof (ImageAuth->MonotonicCount);
}
return TRUE;
}
@@ -462,41 +479,45 @@ ExtractAuthenticatedImage (
BOOLEAN
EFIAPI
ExtractSystemFirmwareImageFmpInfo (
IN VOID *SystemFirmwareImage,
IN UINTN SystemFirmwareImageSize,
OUT EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR **ImageFmpInfo,
OUT UINTN *ImageFmpInfoSize
IN VOID *SystemFirmwareImage,
IN UINTN SystemFirmwareImageSize,
OUT EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR **ImageFmpInfo,
OUT UINTN *ImageFmpInfoSize
)
{
BOOLEAN Result;
UINT32 SectionHeaderSize;
UINT32 FileHeaderSize;
BOOLEAN Result;
UINT32 SectionHeaderSize;
UINT32 FileHeaderSize;
*ImageFmpInfo = NULL;
*ImageFmpInfo = NULL;
*ImageFmpInfoSize = 0;
Result = GetFfsByName(SystemFirmwareImage, SystemFirmwareImageSize, &gEdkiiSystemFirmwareImageDescriptorFileGuid, EFI_FV_FILETYPE_ALL, (VOID **)ImageFmpInfo, ImageFmpInfoSize);
Result = GetFfsByName (SystemFirmwareImage, SystemFirmwareImageSize, &gEdkiiSystemFirmwareImageDescriptorFileGuid, EFI_FV_FILETYPE_ALL, (VOID **)ImageFmpInfo, ImageFmpInfoSize);
if (!Result) {
return FALSE;
}
if (IS_FFS_FILE2 (*ImageFmpInfo)) {
FileHeaderSize = sizeof(EFI_FFS_FILE_HEADER2);
FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER2);
} else {
FileHeaderSize = sizeof(EFI_FFS_FILE_HEADER);
FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER);
}
*ImageFmpInfo = (VOID *)((UINT8 *)*ImageFmpInfo + FileHeaderSize);
*ImageFmpInfo = (VOID *)((UINT8 *)*ImageFmpInfo + FileHeaderSize);
*ImageFmpInfoSize = *ImageFmpInfoSize - FileHeaderSize;
Result = GetSectionByType(*ImageFmpInfo, (UINT32)*ImageFmpInfoSize, EFI_SECTION_RAW, 0, (VOID **)ImageFmpInfo, ImageFmpInfoSize);
Result = GetSectionByType (*ImageFmpInfo, (UINT32)*ImageFmpInfoSize, EFI_SECTION_RAW, 0, (VOID **)ImageFmpInfo, ImageFmpInfoSize);
if (!Result) {
return FALSE;
}
if (IS_SECTION2(*ImageFmpInfo)) {
SectionHeaderSize = sizeof(EFI_RAW_SECTION2);
if (IS_SECTION2 (*ImageFmpInfo)) {
SectionHeaderSize = sizeof (EFI_RAW_SECTION2);
} else {
SectionHeaderSize = sizeof(EFI_RAW_SECTION);
SectionHeaderSize = sizeof (EFI_RAW_SECTION);
}
*ImageFmpInfo = (VOID *)((UINT8 *)*ImageFmpInfo + SectionHeaderSize);
*ImageFmpInfo = (VOID *)((UINT8 *)*ImageFmpInfo + SectionHeaderSize);
*ImageFmpInfoSize = *ImageFmpInfoSize - SectionHeaderSize;
return TRUE;
@@ -516,32 +537,34 @@ ExtractSystemFirmwareImageFmpInfo (
BOOLEAN
EFIAPI
ExtractSystemFirmwareImage (
IN VOID *AuthenticatedImage,
IN UINTN AuthenticatedImageSize,
OUT VOID **SystemFirmwareImage,
OUT UINTN *SystemFirmwareImageSize
IN VOID *AuthenticatedImage,
IN UINTN AuthenticatedImageSize,
OUT VOID **SystemFirmwareImage,
OUT UINTN *SystemFirmwareImageSize
)
{
BOOLEAN Result;
UINT32 FileHeaderSize;
BOOLEAN Result;
UINT32 FileHeaderSize;
*SystemFirmwareImage = NULL;
*SystemFirmwareImage = NULL;
*SystemFirmwareImageSize = 0;
Result = GetFfsByName(AuthenticatedImage, AuthenticatedImageSize, &mEdkiiSystemFirmwareFileGuid, EFI_FV_FILETYPE_RAW, SystemFirmwareImage, SystemFirmwareImageSize);
Result = GetFfsByName (AuthenticatedImage, AuthenticatedImageSize, &mEdkiiSystemFirmwareFileGuid, EFI_FV_FILETYPE_RAW, SystemFirmwareImage, SystemFirmwareImageSize);
if (!Result) {
// no nested FV, just return all data.
*SystemFirmwareImage = AuthenticatedImage;
*SystemFirmwareImage = AuthenticatedImage;
*SystemFirmwareImageSize = AuthenticatedImageSize;
return TRUE;
}
if (IS_FFS_FILE2 (*SystemFirmwareImage)) {
FileHeaderSize = sizeof(EFI_FFS_FILE_HEADER2);
FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER2);
} else {
FileHeaderSize = sizeof(EFI_FFS_FILE_HEADER);
FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER);
}
*SystemFirmwareImage = (UINT8 *)*SystemFirmwareImage + FileHeaderSize;
*SystemFirmwareImage = (UINT8 *)*SystemFirmwareImage + FileHeaderSize;
*SystemFirmwareImageSize = *SystemFirmwareImageSize - FileHeaderSize;
return Result;
@@ -568,22 +591,22 @@ ExtractSystemFirmwareImage (
EFI_STATUS
EFIAPI
CapsuleAuthenticateSystemFirmware (
IN VOID *Image,
IN UINTN ImageSize,
IN BOOLEAN ForceVersionMatch,
OUT UINT32 *LastAttemptVersion,
OUT UINT32 *LastAttemptStatus,
OUT VOID **AuthenticatedImage,
OUT UINTN *AuthenticatedImageSize
IN VOID *Image,
IN UINTN ImageSize,
IN BOOLEAN ForceVersionMatch,
OUT UINT32 *LastAttemptVersion,
OUT UINT32 *LastAttemptStatus,
OUT VOID **AuthenticatedImage,
OUT UINTN *AuthenticatedImageSize
)
{
BOOLEAN Result;
EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR *ImageFmpInfo;
UINTN ImageFmpInfoSize;
EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR *CurrentImageFmpInfo;
UINTN CurrentImageFmpInfoSize;
VOID *SystemFirmwareImage;
UINTN SystemFirmwareImageSize;
BOOLEAN Result;
EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR *ImageFmpInfo;
UINTN ImageFmpInfoSize;
EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR *CurrentImageFmpInfo;
UINTN CurrentImageFmpInfoSize;
VOID *SystemFirmwareImage;
UINTN SystemFirmwareImageSize;
*LastAttemptVersion = 0;
@@ -592,55 +615,56 @@ CapsuleAuthenticateSystemFirmware (
// Do not touch FMP protocol and its private structure.
//
if (mImageFmpInfo == NULL) {
DEBUG((DEBUG_INFO, "ImageFmpInfo is not set\n"));
DEBUG ((DEBUG_INFO, "ImageFmpInfo is not set\n"));
return EFI_SECURITY_VIOLATION;
}
Result = ExtractAuthenticatedImage((VOID *)Image, ImageSize, LastAttemptStatus, AuthenticatedImage, AuthenticatedImageSize);
Result = ExtractAuthenticatedImage ((VOID *)Image, ImageSize, LastAttemptStatus, AuthenticatedImage, AuthenticatedImageSize);
if (!Result) {
DEBUG((DEBUG_INFO, "ExtractAuthenticatedImage - fail\n"));
DEBUG ((DEBUG_INFO, "ExtractAuthenticatedImage - fail\n"));
return EFI_SECURITY_VIOLATION;
}
DEBUG((DEBUG_INFO, "AuthenticatedImage - 0x%x - 0x%x\n", *AuthenticatedImage, *AuthenticatedImageSize));
DEBUG ((DEBUG_INFO, "AuthenticatedImage - 0x%x - 0x%x\n", *AuthenticatedImage, *AuthenticatedImageSize));
Result = ExtractSystemFirmwareImage(*AuthenticatedImage, *AuthenticatedImageSize, &SystemFirmwareImage, &SystemFirmwareImageSize);
Result = ExtractSystemFirmwareImage (*AuthenticatedImage, *AuthenticatedImageSize, &SystemFirmwareImage, &SystemFirmwareImageSize);
if (!Result) {
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
DEBUG((DEBUG_INFO, "ExtractSystemFirmwareImage - fail\n"));
DEBUG ((DEBUG_INFO, "ExtractSystemFirmwareImage - fail\n"));
return EFI_SECURITY_VIOLATION;
}
DEBUG((DEBUG_INFO, "SystemFirmwareImage - 0x%x - 0x%x\n", SystemFirmwareImage, SystemFirmwareImageSize));
Result = ExtractSystemFirmwareImageFmpInfo(SystemFirmwareImage, SystemFirmwareImageSize, &ImageFmpInfo, &ImageFmpInfoSize);
DEBUG ((DEBUG_INFO, "SystemFirmwareImage - 0x%x - 0x%x\n", SystemFirmwareImage, SystemFirmwareImageSize));
Result = ExtractSystemFirmwareImageFmpInfo (SystemFirmwareImage, SystemFirmwareImageSize, &ImageFmpInfo, &ImageFmpInfoSize);
if (!Result) {
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
DEBUG((DEBUG_INFO, "ExtractSystemFirmwareImageFmpInfo - fail\n"));
DEBUG ((DEBUG_INFO, "ExtractSystemFirmwareImageFmpInfo - fail\n"));
return EFI_SECURITY_VIOLATION;
}
*LastAttemptVersion = ImageFmpInfo->Version;
DEBUG((DEBUG_INFO, "ImageFmpInfo - 0x%x - 0x%x\n", ImageFmpInfo, ImageFmpInfoSize));
DEBUG((DEBUG_INFO, "NewImage Version - 0x%x\n", ImageFmpInfo->Version));
DEBUG((DEBUG_INFO, "NewImage LowestSupportedImageVersion - 0x%x\n", ImageFmpInfo->LowestSupportedImageVersion));
DEBUG ((DEBUG_INFO, "ImageFmpInfo - 0x%x - 0x%x\n", ImageFmpInfo, ImageFmpInfoSize));
DEBUG ((DEBUG_INFO, "NewImage Version - 0x%x\n", ImageFmpInfo->Version));
DEBUG ((DEBUG_INFO, "NewImage LowestSupportedImageVersion - 0x%x\n", ImageFmpInfo->LowestSupportedImageVersion));
CurrentImageFmpInfo = mImageFmpInfo;
CurrentImageFmpInfo = mImageFmpInfo;
CurrentImageFmpInfoSize = mImageFmpInfoSize;
DEBUG((DEBUG_INFO, "ImageFmpInfo - 0x%x - 0x%x\n", CurrentImageFmpInfo, CurrentImageFmpInfoSize));
DEBUG((DEBUG_INFO, "Current Version - 0x%x\n", CurrentImageFmpInfo->Version));
DEBUG((DEBUG_INFO, "Current LowestSupportedImageVersion - 0x%x\n", CurrentImageFmpInfo->LowestSupportedImageVersion));
DEBUG ((DEBUG_INFO, "ImageFmpInfo - 0x%x - 0x%x\n", CurrentImageFmpInfo, CurrentImageFmpInfoSize));
DEBUG ((DEBUG_INFO, "Current Version - 0x%x\n", CurrentImageFmpInfo->Version));
DEBUG ((DEBUG_INFO, "Current LowestSupportedImageVersion - 0x%x\n", CurrentImageFmpInfo->LowestSupportedImageVersion));
if (ForceVersionMatch) {
if (CurrentImageFmpInfo->Version != ImageFmpInfo->Version) {
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION;
DEBUG((DEBUG_INFO, "ForceVersionMatch check - fail\n"));
DEBUG ((DEBUG_INFO, "ForceVersionMatch check - fail\n"));
return EFI_SECURITY_VIOLATION;
}
} else {
if (ImageFmpInfo->Version < CurrentImageFmpInfo->LowestSupportedImageVersion) {
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION;
DEBUG((DEBUG_INFO, "LowestSupportedImageVersion check - fail\n"));
DEBUG ((DEBUG_INFO, "LowestSupportedImageVersion check - fail\n"));
return EFI_SECURITY_VIOLATION;
}
}
@@ -661,17 +685,18 @@ CapsuleAuthenticateSystemFirmware (
VOID
EFIAPI
EdkiiSystemCapsuleLibPcdCallBack (
IN CONST GUID *CallBackGuid OPTIONAL,
IN UINTN CallBackToken,
IN OUT VOID *TokenData,
IN UINTN TokenDataSize
IN CONST GUID *CallBackGuid OPTIONAL,
IN UINTN CallBackToken,
IN OUT VOID *TokenData,
IN UINTN TokenDataSize
)
{
if (CompareGuid (CallBackGuid, &gEfiSignedCapsulePkgTokenSpaceGuid) &&
CallBackToken == PcdToken (PcdEdkiiSystemFirmwareImageDescriptor)) {
(CallBackToken == PcdToken (PcdEdkiiSystemFirmwareImageDescriptor)))
{
mImageFmpInfoSize = TokenDataSize;
mImageFmpInfo = AllocateCopyPool (mImageFmpInfoSize, TokenData);
ASSERT(mImageFmpInfo != NULL);
mImageFmpInfo = AllocateCopyPool (mImageFmpInfoSize, TokenData);
ASSERT (mImageFmpInfo != NULL);
//
// Cancel Callback after get the real set value
//
@@ -683,8 +708,9 @@ EdkiiSystemCapsuleLibPcdCallBack (
}
if (CompareGuid (CallBackGuid, &gEfiSignedCapsulePkgTokenSpaceGuid) &&
CallBackToken == PcdToken (PcdEdkiiSystemFirmwareFileGuid)) {
CopyGuid(&mEdkiiSystemFirmwareFileGuid, TokenData);
(CallBackToken == PcdToken (PcdEdkiiSystemFirmwareFileGuid)))
{
CopyGuid (&mEdkiiSystemFirmwareFileGuid, TokenData);
//
// Cancel Callback after get the real set value
//
@@ -707,13 +733,14 @@ EdkiiSystemCapsuleLibConstructor (
VOID
)
{
mImageFmpInfoSize = PcdGetSize(PcdEdkiiSystemFirmwareImageDescriptor);
mImageFmpInfo = PcdGetPtr(PcdEdkiiSystemFirmwareImageDescriptor);
mImageFmpInfoSize = PcdGetSize (PcdEdkiiSystemFirmwareImageDescriptor);
mImageFmpInfo = PcdGetPtr (PcdEdkiiSystemFirmwareImageDescriptor);
//
// Verify Firmware Image Descriptor first
//
if (mImageFmpInfoSize < sizeof (EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR) ||
mImageFmpInfo->Signature != EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR_SIGNATURE) {
if ((mImageFmpInfoSize < sizeof (EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR)) ||
(mImageFmpInfo->Signature != EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR_SIGNATURE))
{
//
// SystemFirmwareImageDescriptor is not set.
// Register PCD set callback to hook PCD value set.
@@ -727,10 +754,10 @@ EdkiiSystemCapsuleLibConstructor (
);
} else {
mImageFmpInfo = AllocateCopyPool (mImageFmpInfoSize, mImageFmpInfo);
ASSERT(mImageFmpInfo != NULL);
ASSERT (mImageFmpInfo != NULL);
}
CopyGuid(&mEdkiiSystemFirmwareFileGuid, PcdGetPtr(PcdEdkiiSystemFirmwareFileGuid));
CopyGuid (&mEdkiiSystemFirmwareFileGuid, PcdGetPtr (PcdEdkiiSystemFirmwareFileGuid));
//
// Verify GUID value first
//
@@ -741,5 +768,6 @@ EdkiiSystemCapsuleLibConstructor (
EdkiiSystemCapsuleLibPcdCallBack
);
}
return EFI_SUCCESS;
}