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

@ -7,7 +7,6 @@
**/ **/
#ifndef __EDKII_SYSTEM_FMP_CAPSULE_GUID_H__ #ifndef __EDKII_SYSTEM_FMP_CAPSULE_GUID_H__
#define __EDKII_SYSTEM_FMP_CAPSULE_GUID_H__ #define __EDKII_SYSTEM_FMP_CAPSULE_GUID_H__
@ -115,9 +114,9 @@ typedef struct {
UINT8 Reserved3[4]; UINT8 Reserved3[4];
UINT64 HardwareInstance; UINT64 HardwareInstance;
// real string data // real string data
//CHAR16 ImageIdNameStr[]; // CHAR16 string including NULL terminate char // CHAR16 ImageIdNameStr[]; // CHAR16 string including NULL terminate char
//CHAR16 VersionNameStr[]; // CHAR16 string including NULL terminate char // CHAR16 VersionNameStr[]; // CHAR16 string including NULL terminate char
//CHAR16 PackageVersionNameStr[]; // CHAR16 string including NULL terminate char // CHAR16 PackageVersionNameStr[]; // CHAR16 string including NULL terminate char
} EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR; } EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR;
#pragma pack() #pragma pack()

View File

@ -6,7 +6,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef __EDKII_SYSTEM_CAPSULE_LIB_H__ #ifndef __EDKII_SYSTEM_CAPSULE_LIB_H__
#define __EDKII_SYSTEM_CAPSULE_LIB_H__ #define __EDKII_SYSTEM_CAPSULE_LIB_H__
@ -145,4 +144,3 @@ CapsuleAuthenticateSystemFirmware (
); );
#endif #endif

View File

@ -24,7 +24,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef __INI_PARSING_LIB_H__ #ifndef __INI_PARSING_LIB_H__
#define __INI_PARSING_LIB_H__ #define __INI_PARSING_LIB_H__
@ -157,4 +156,3 @@ CloseIniFile (
); );
#endif #endif

View File

@ -6,7 +6,6 @@
**/ **/
#ifndef __PLATFORM_FLASH_ACCESS_LIB_H__ #ifndef __PLATFORM_FLASH_ACCESS_LIB_H__
#define __PLATFORM_FLASH_ACCESS_LIB_H__ #define __PLATFORM_FLASH_ACCESS_LIB_H__

View File

@ -55,7 +55,7 @@ IsBufferErased (
UINT8 EraseByte; UINT8 EraseByte;
UINT8 *Buffer; UINT8 *Buffer;
if(ErasePolarity == 1) { if (ErasePolarity == 1) {
EraseByte = 0xFF; EraseByte = 0xFF;
} else { } else {
EraseByte = 0; EraseByte = 0;
@ -108,20 +108,20 @@ GetSectionByType (
Instance = 0; Instance = 0;
while ((UINTN)SectionHeader < (UINTN)SectionBuffer + SectionBufferSize) { while ((UINTN)SectionHeader < (UINTN)SectionBuffer + SectionBufferSize) {
DEBUG ((DEBUG_INFO, "GetSectionByType - Section: 0x%08x\n", SectionHeader)); DEBUG ((DEBUG_INFO, "GetSectionByType - Section: 0x%08x\n", SectionHeader));
if (IS_SECTION2(SectionHeader)) { if (IS_SECTION2 (SectionHeader)) {
SectionSize = SECTION2_SIZE(SectionHeader); SectionSize = SECTION2_SIZE (SectionHeader);
} else { } else {
SectionSize = SECTION_SIZE(SectionHeader); SectionSize = SECTION_SIZE (SectionHeader);
} }
if (SectionHeader->Type == SectionType) { if (SectionHeader->Type == SectionType) {
if (Instance == SectionInstance) { if (Instance == SectionInstance) {
*OutSectionBuffer = (UINT8 *)SectionHeader; *OutSectionBuffer = (UINT8 *)SectionHeader;
*OutSectionSize = SectionSize; *OutSectionSize = SectionSize;
DEBUG((DEBUG_INFO, "GetSectionByType - 0x%x - 0x%x\n", *OutSectionBuffer, *OutSectionSize)); DEBUG ((DEBUG_INFO, "GetSectionByType - 0x%x - 0x%x\n", *OutSectionBuffer, *OutSectionSize));
return TRUE; return TRUE;
} else { } else {
DEBUG((DEBUG_INFO, "GetSectionByType - find section instance %x\n", Instance)); DEBUG ((DEBUG_INFO, "GetSectionByType - find section instance %x\n", Instance));
Instance++; Instance++;
} }
} else { } else {
@ -134,7 +134,7 @@ GetSectionByType (
// //
// Next Section // 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; return FALSE;
@ -182,12 +182,14 @@ GetFfsByName (
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN)FvHeader + SIZE_4KB); FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN)FvHeader + SIZE_4KB);
continue; 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; FvFound = TRUE;
if (FvHeader->FvLength > FvSize) { 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; return FALSE;
} }
FvSize = (UINTN)FvHeader->FvLength; FvSize = (UINTN)FvHeader->FvLength;
// //
@ -199,26 +201,29 @@ GetFfsByName (
} else { } else {
FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FvHeader + FvHeader->HeaderLength); 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) { 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); TestLength = (UINTN)((UINTN)FvHeader + FvSize - (UINTN)FfsHeader);
if (TestLength > sizeof(EFI_FFS_FILE_HEADER)) { if (TestLength > sizeof (EFI_FFS_FILE_HEADER)) {
TestLength = sizeof(EFI_FFS_FILE_HEADER); TestLength = sizeof (EFI_FFS_FILE_HEADER);
} }
if (IsBufferErased(1, FfsHeader, TestLength)) {
if (IsBufferErased (1, FfsHeader, TestLength)) {
break; break;
} }
if (IS_FFS_FILE2(FfsHeader)) { if (IS_FFS_FILE2 (FfsHeader)) {
FfsSize = FFS_FILE2_SIZE(FfsHeader); FfsSize = FFS_FILE2_SIZE (FfsHeader);
} else { } else {
FfsSize = FFS_FILE_SIZE(FfsHeader); FfsSize = FFS_FILE_SIZE (FfsHeader);
} }
if (CompareGuid(FileName, &FfsHeader->Name) && if (CompareGuid (FileName, &FfsHeader->Name) &&
((Type == EFI_FV_FILETYPE_ALL) || (FfsHeader->Type == Type))) { ((Type == EFI_FV_FILETYPE_ALL) || (FfsHeader->Type == Type)))
{
*OutFfsBuffer = FfsHeader; *OutFfsBuffer = FfsHeader;
*OutFfsBufferSize = FfsSize; *OutFfsBufferSize = FfsSize;
return TRUE; return TRUE;
@ -226,13 +231,13 @@ GetFfsByName (
// //
// Any other type is not allowed // 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 // 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) { if (!FvFound) {
DEBUG((DEBUG_ERROR, "GetFfsByName - NO FV Found\n")); DEBUG ((DEBUG_ERROR, "GetFfsByName - NO FV Found\n"));
} }
return FALSE; return FALSE;
} }
@ -273,16 +279,17 @@ ExtractDriverFvImage (
*DriverFvImage = NULL; *DriverFvImage = NULL;
*DriverFvImageSize = 0; *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) { if (!Result) {
return FALSE; return FALSE;
} }
if (IS_FFS_FILE2(*DriverFvImage)) { if (IS_FFS_FILE2 (*DriverFvImage)) {
FileHeaderSize = sizeof(EFI_FFS_FILE_HEADER2); FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER2);
} else { } else {
FileHeaderSize = sizeof(EFI_FFS_FILE_HEADER); FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER);
} }
*DriverFvImage = (UINT8 *)*DriverFvImage + FileHeaderSize; *DriverFvImage = (UINT8 *)*DriverFvImage + FileHeaderSize;
*DriverFvImageSize = *DriverFvImageSize - FileHeaderSize; *DriverFvImageSize = *DriverFvImageSize - FileHeaderSize;
@ -315,16 +322,17 @@ ExtractConfigImage (
*ConfigImage = NULL; *ConfigImage = NULL;
*ConfigImageSize = 0; *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) { if (!Result) {
return FALSE; return FALSE;
} }
if (IS_FFS_FILE2(*ConfigImage)) { if (IS_FFS_FILE2 (*ConfigImage)) {
FileHeaderSize = sizeof(EFI_FFS_FILE_HEADER2); FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER2);
} else { } else {
FileHeaderSize = sizeof(EFI_FFS_FILE_HEADER); FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER);
} }
*ConfigImage = (UINT8 *)*ConfigImage + FileHeaderSize; *ConfigImage = (UINT8 *)*ConfigImage + FileHeaderSize;
*ConfigImageSize = *ConfigImageSize - FileHeaderSize; *ConfigImageSize = *ConfigImageSize - FileHeaderSize;
@ -361,7 +369,7 @@ ExtractAuthenticatedImage (
VOID *PublicKeyData; VOID *PublicKeyData;
UINTN PublicKeyDataLength; 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; *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
if ((Image == NULL) || (ImageSize == 0)) { if ((Image == NULL) || (ImageSize == 0)) {
@ -369,47 +377,53 @@ ExtractAuthenticatedImage (
} }
ImageAuth = (EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image; ImageAuth = (EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image;
if (ImageSize < sizeof(EFI_FIRMWARE_IMAGE_AUTHENTICATION)) { if (ImageSize < sizeof (EFI_FIRMWARE_IMAGE_AUTHENTICATION)) {
DEBUG((DEBUG_ERROR, "ExtractAuthenticatedImage - ImageSize too small\n")); DEBUG ((DEBUG_ERROR, "ExtractAuthenticatedImage - ImageSize too small\n"));
return FALSE; 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; 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; 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; return FALSE;
} }
if (ImageAuth->AuthInfo.Hdr.wRevision != 0x0200) { 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; return FALSE;
} }
if (ImageAuth->AuthInfo.Hdr.wCertificateType != WIN_CERT_TYPE_EFI_GUID) { 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; return FALSE;
} }
CertType = &ImageAuth->AuthInfo.CertType; CertType = &ImageAuth->AuthInfo.CertType;
DEBUG((DEBUG_INFO, "ExtractAuthenticatedImage - CertType: %g\n", CertType)); DEBUG ((DEBUG_INFO, "ExtractAuthenticatedImage - CertType: %g\n", CertType));
if (CompareGuid(&gEfiCertPkcs7Guid, CertType)) { if (CompareGuid (&gEfiCertPkcs7Guid, CertType)) {
PublicKeyData = PcdGetPtr(PcdPkcs7CertBuffer); PublicKeyData = PcdGetPtr (PcdPkcs7CertBuffer);
PublicKeyDataLength = PcdGetSize(PcdPkcs7CertBuffer); PublicKeyDataLength = PcdGetSize (PcdPkcs7CertBuffer);
} else if (CompareGuid(&gEfiCertTypeRsa2048Sha256Guid, CertType)) { } else if (CompareGuid (&gEfiCertTypeRsa2048Sha256Guid, CertType)) {
PublicKeyData = PcdGetPtr(PcdRsa2048Sha256PublicKeyBuffer); PublicKeyData = PcdGetPtr (PcdRsa2048Sha256PublicKeyBuffer);
PublicKeyDataLength = PcdGetSize(PcdRsa2048Sha256PublicKeyBuffer); PublicKeyDataLength = PcdGetSize (PcdRsa2048Sha256PublicKeyBuffer);
} else { } else {
return FALSE; return FALSE;
} }
ASSERT (PublicKeyData != NULL); ASSERT (PublicKeyData != NULL);
ASSERT (PublicKeyDataLength != 0); ASSERT (PublicKeyDataLength != 0);
Status = AuthenticateFmpImage( Status = AuthenticateFmpImage (
ImageAuth, ImageAuth,
ImageSize, ImageSize,
PublicKeyData, PublicKeyData,
@ -435,16 +449,19 @@ ExtractAuthenticatedImage (
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL; *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
break; break;
} }
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
return FALSE; return FALSE;
} }
if (AuthenticatedImage != NULL) { 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) { if (AuthenticatedImageSize != NULL) {
*AuthenticatedImageSize = ImageSize - ImageAuth->AuthInfo.Hdr.dwLength - sizeof(ImageAuth->MonotonicCount); *AuthenticatedImageSize = ImageSize - ImageAuth->AuthInfo.Hdr.dwLength - sizeof (ImageAuth->MonotonicCount);
} }
return TRUE; return TRUE;
} }
@ -475,27 +492,31 @@ ExtractSystemFirmwareImageFmpInfo (
*ImageFmpInfo = NULL; *ImageFmpInfo = NULL;
*ImageFmpInfoSize = 0; *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) { if (!Result) {
return FALSE; return FALSE;
} }
if (IS_FFS_FILE2 (*ImageFmpInfo)) { if (IS_FFS_FILE2 (*ImageFmpInfo)) {
FileHeaderSize = sizeof(EFI_FFS_FILE_HEADER2); FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER2);
} else { } 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; *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) { if (!Result) {
return FALSE; return FALSE;
} }
if (IS_SECTION2(*ImageFmpInfo)) {
SectionHeaderSize = sizeof(EFI_RAW_SECTION2); if (IS_SECTION2 (*ImageFmpInfo)) {
SectionHeaderSize = sizeof (EFI_RAW_SECTION2);
} else { } else {
SectionHeaderSize = sizeof(EFI_RAW_SECTION); SectionHeaderSize = sizeof (EFI_RAW_SECTION);
} }
*ImageFmpInfo = (VOID *)((UINT8 *)*ImageFmpInfo + SectionHeaderSize); *ImageFmpInfo = (VOID *)((UINT8 *)*ImageFmpInfo + SectionHeaderSize);
*ImageFmpInfoSize = *ImageFmpInfoSize - SectionHeaderSize; *ImageFmpInfoSize = *ImageFmpInfoSize - SectionHeaderSize;
@ -528,7 +549,7 @@ ExtractSystemFirmwareImage (
*SystemFirmwareImage = NULL; *SystemFirmwareImage = NULL;
*SystemFirmwareImageSize = 0; *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) { if (!Result) {
// no nested FV, just return all data. // no nested FV, just return all data.
*SystemFirmwareImage = AuthenticatedImage; *SystemFirmwareImage = AuthenticatedImage;
@ -536,11 +557,13 @@ ExtractSystemFirmwareImage (
return TRUE; return TRUE;
} }
if (IS_FFS_FILE2 (*SystemFirmwareImage)) { if (IS_FFS_FILE2 (*SystemFirmwareImage)) {
FileHeaderSize = sizeof(EFI_FFS_FILE_HEADER2); FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER2);
} else { } else {
FileHeaderSize = sizeof(EFI_FFS_FILE_HEADER); FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER);
} }
*SystemFirmwareImage = (UINT8 *)*SystemFirmwareImage + FileHeaderSize; *SystemFirmwareImage = (UINT8 *)*SystemFirmwareImage + FileHeaderSize;
*SystemFirmwareImageSize = *SystemFirmwareImageSize - FileHeaderSize; *SystemFirmwareImageSize = *SystemFirmwareImageSize - FileHeaderSize;
@ -592,55 +615,56 @@ CapsuleAuthenticateSystemFirmware (
// Do not touch FMP protocol and its private structure. // Do not touch FMP protocol and its private structure.
// //
if (mImageFmpInfo == NULL) { if (mImageFmpInfo == NULL) {
DEBUG((DEBUG_INFO, "ImageFmpInfo is not set\n")); DEBUG ((DEBUG_INFO, "ImageFmpInfo is not set\n"));
return EFI_SECURITY_VIOLATION; return EFI_SECURITY_VIOLATION;
} }
Result = ExtractAuthenticatedImage((VOID *)Image, ImageSize, LastAttemptStatus, AuthenticatedImage, AuthenticatedImageSize); Result = ExtractAuthenticatedImage ((VOID *)Image, ImageSize, LastAttemptStatus, AuthenticatedImage, AuthenticatedImageSize);
if (!Result) { if (!Result) {
DEBUG((DEBUG_INFO, "ExtractAuthenticatedImage - fail\n")); DEBUG ((DEBUG_INFO, "ExtractAuthenticatedImage - fail\n"));
return EFI_SECURITY_VIOLATION; 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) { if (!Result) {
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT; *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
DEBUG((DEBUG_INFO, "ExtractSystemFirmwareImage - fail\n")); DEBUG ((DEBUG_INFO, "ExtractSystemFirmwareImage - fail\n"));
return EFI_SECURITY_VIOLATION; 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) { if (!Result) {
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT; *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
DEBUG((DEBUG_INFO, "ExtractSystemFirmwareImageFmpInfo - fail\n")); DEBUG ((DEBUG_INFO, "ExtractSystemFirmwareImageFmpInfo - fail\n"));
return EFI_SECURITY_VIOLATION; return EFI_SECURITY_VIOLATION;
} }
*LastAttemptVersion = ImageFmpInfo->Version; *LastAttemptVersion = ImageFmpInfo->Version;
DEBUG((DEBUG_INFO, "ImageFmpInfo - 0x%x - 0x%x\n", ImageFmpInfo, ImageFmpInfoSize)); 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 Version - 0x%x\n", ImageFmpInfo->Version));
DEBUG((DEBUG_INFO, "NewImage LowestSupportedImageVersion - 0x%x\n", ImageFmpInfo->LowestSupportedImageVersion)); DEBUG ((DEBUG_INFO, "NewImage LowestSupportedImageVersion - 0x%x\n", ImageFmpInfo->LowestSupportedImageVersion));
CurrentImageFmpInfo = mImageFmpInfo; CurrentImageFmpInfo = mImageFmpInfo;
CurrentImageFmpInfoSize = mImageFmpInfoSize; CurrentImageFmpInfoSize = mImageFmpInfoSize;
DEBUG((DEBUG_INFO, "ImageFmpInfo - 0x%x - 0x%x\n", CurrentImageFmpInfo, CurrentImageFmpInfoSize)); 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 Version - 0x%x\n", CurrentImageFmpInfo->Version));
DEBUG((DEBUG_INFO, "Current LowestSupportedImageVersion - 0x%x\n", CurrentImageFmpInfo->LowestSupportedImageVersion)); DEBUG ((DEBUG_INFO, "Current LowestSupportedImageVersion - 0x%x\n", CurrentImageFmpInfo->LowestSupportedImageVersion));
if (ForceVersionMatch) { if (ForceVersionMatch) {
if (CurrentImageFmpInfo->Version != ImageFmpInfo->Version) { if (CurrentImageFmpInfo->Version != ImageFmpInfo->Version) {
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INCORRECT_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; return EFI_SECURITY_VIOLATION;
} }
} else { } else {
if (ImageFmpInfo->Version < CurrentImageFmpInfo->LowestSupportedImageVersion) { if (ImageFmpInfo->Version < CurrentImageFmpInfo->LowestSupportedImageVersion) {
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION; *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; return EFI_SECURITY_VIOLATION;
} }
} }
@ -668,10 +692,11 @@ EdkiiSystemCapsuleLibPcdCallBack (
) )
{ {
if (CompareGuid (CallBackGuid, &gEfiSignedCapsulePkgTokenSpaceGuid) && if (CompareGuid (CallBackGuid, &gEfiSignedCapsulePkgTokenSpaceGuid) &&
CallBackToken == PcdToken (PcdEdkiiSystemFirmwareImageDescriptor)) { (CallBackToken == PcdToken (PcdEdkiiSystemFirmwareImageDescriptor)))
{
mImageFmpInfoSize = TokenDataSize; mImageFmpInfoSize = TokenDataSize;
mImageFmpInfo = AllocateCopyPool (mImageFmpInfoSize, TokenData); mImageFmpInfo = AllocateCopyPool (mImageFmpInfoSize, TokenData);
ASSERT(mImageFmpInfo != NULL); ASSERT (mImageFmpInfo != NULL);
// //
// Cancel Callback after get the real set value // Cancel Callback after get the real set value
// //
@ -683,8 +708,9 @@ EdkiiSystemCapsuleLibPcdCallBack (
} }
if (CompareGuid (CallBackGuid, &gEfiSignedCapsulePkgTokenSpaceGuid) && if (CompareGuid (CallBackGuid, &gEfiSignedCapsulePkgTokenSpaceGuid) &&
CallBackToken == PcdToken (PcdEdkiiSystemFirmwareFileGuid)) { (CallBackToken == PcdToken (PcdEdkiiSystemFirmwareFileGuid)))
CopyGuid(&mEdkiiSystemFirmwareFileGuid, TokenData); {
CopyGuid (&mEdkiiSystemFirmwareFileGuid, TokenData);
// //
// Cancel Callback after get the real set value // Cancel Callback after get the real set value
// //
@ -707,13 +733,14 @@ EdkiiSystemCapsuleLibConstructor (
VOID VOID
) )
{ {
mImageFmpInfoSize = PcdGetSize(PcdEdkiiSystemFirmwareImageDescriptor); mImageFmpInfoSize = PcdGetSize (PcdEdkiiSystemFirmwareImageDescriptor);
mImageFmpInfo = PcdGetPtr(PcdEdkiiSystemFirmwareImageDescriptor); mImageFmpInfo = PcdGetPtr (PcdEdkiiSystemFirmwareImageDescriptor);
// //
// Verify Firmware Image Descriptor first // Verify Firmware Image Descriptor first
// //
if (mImageFmpInfoSize < sizeof (EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR) || if ((mImageFmpInfoSize < sizeof (EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR)) ||
mImageFmpInfo->Signature != EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR_SIGNATURE) { (mImageFmpInfo->Signature != EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR_SIGNATURE))
{
// //
// SystemFirmwareImageDescriptor is not set. // SystemFirmwareImageDescriptor is not set.
// Register PCD set callback to hook PCD value set. // Register PCD set callback to hook PCD value set.
@ -727,10 +754,10 @@ EdkiiSystemCapsuleLibConstructor (
); );
} else { } else {
mImageFmpInfo = AllocateCopyPool (mImageFmpInfoSize, mImageFmpInfo); mImageFmpInfo = AllocateCopyPool (mImageFmpInfoSize, mImageFmpInfo);
ASSERT(mImageFmpInfo != NULL); ASSERT (mImageFmpInfo != NULL);
} }
CopyGuid(&mEdkiiSystemFirmwareFileGuid, PcdGetPtr(PcdEdkiiSystemFirmwareFileGuid)); CopyGuid (&mEdkiiSystemFirmwareFileGuid, PcdGetPtr (PcdEdkiiSystemFirmwareFileGuid));
// //
// Verify GUID value first // Verify GUID value first
// //
@ -741,5 +768,6 @@ EdkiiSystemCapsuleLibConstructor (
EdkiiSystemCapsuleLibPcdCallBack EdkiiSystemCapsuleLibPcdCallBack
); );
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -78,17 +78,20 @@ IsValidDigitalChar (
IN BOOLEAN IncludeHex IN BOOLEAN IncludeHex
) )
{ {
if (DigitalChar >= '0' && DigitalChar <= '9') { if ((DigitalChar >= '0') && (DigitalChar <= '9')) {
return TRUE; return TRUE;
} }
if (IncludeHex) { if (IncludeHex) {
if (DigitalChar >= 'a' && DigitalChar <= 'f') { if ((DigitalChar >= 'a') && (DigitalChar <= 'f')) {
return TRUE; return TRUE;
} }
if (DigitalChar >= 'A' && DigitalChar <= 'F') {
if ((DigitalChar >= 'A') && (DigitalChar <= 'F')) {
return TRUE; return TRUE;
} }
} }
return FALSE; return FALSE;
} }
@ -105,18 +108,22 @@ IsValidNameChar (
IN CHAR8 NameChar IN CHAR8 NameChar
) )
{ {
if (NameChar >= 'a' && NameChar <= 'z') { if ((NameChar >= 'a') && (NameChar <= 'z')) {
return TRUE; return TRUE;
} }
if (NameChar >= 'A' && NameChar <= 'Z') {
if ((NameChar >= 'A') && (NameChar <= 'Z')) {
return TRUE; return TRUE;
} }
if (NameChar >= '0' && NameChar <= '9') {
if ((NameChar >= '0') && (NameChar <= '9')) {
return TRUE; return TRUE;
} }
if (NameChar == '_') { if (NameChar == '_') {
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
@ -138,11 +145,13 @@ IsValidDigital (
) )
{ {
UINTN Index; UINTN Index;
for (Index = 0; Index < Length; Index++) { for (Index = 0; Index < Length; Index++) {
if (!IsValidDigitalChar(Digital[Index], IncludeHex)) { if (!IsValidDigitalChar (Digital[Index], IncludeHex)) {
return FALSE; return FALSE;
} }
} }
return TRUE; return TRUE;
} }
@ -161,7 +170,7 @@ IsValidDecimalString (
IN UINTN Length IN UINTN Length
) )
{ {
return IsValidDigital(Decimal, Length, FALSE); return IsValidDigital (Decimal, Length, FALSE);
} }
/** /**
@ -182,13 +191,16 @@ IsValidHexString (
if (Length <= 2) { if (Length <= 2) {
return FALSE; return FALSE;
} }
if (Hex[0] != '0') { if (Hex[0] != '0') {
return FALSE; return FALSE;
} }
if (Hex[1] != 'x' && Hex[1] != 'X') {
if ((Hex[1] != 'x') && (Hex[1] != 'X')) {
return FALSE; return FALSE;
} }
return IsValidDigital(&Hex[2], Length - 2, TRUE);
return IsValidDigital (&Hex[2], Length - 2, TRUE);
} }
/** /**
@ -207,11 +219,13 @@ IsValidName (
) )
{ {
UINTN Index; UINTN Index;
for (Index = 0; Index < Length; Index++) { for (Index = 0; Index < Length; Index++) {
if (!IsValidNameChar(Name[Index])) { if (!IsValidNameChar (Name[Index])) {
return FALSE; return FALSE;
} }
} }
return TRUE; return TRUE;
} }
@ -230,36 +244,46 @@ IsValidGuid (
IN UINTN Length IN UINTN Length
) )
{ {
if (Length != sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") - 1) { if (Length != sizeof ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") - 1) {
return FALSE; return FALSE;
} }
if (!IS_HYPHEN(Value[8])) {
if (!IS_HYPHEN (Value[8])) {
return FALSE; return FALSE;
} }
if (!IS_HYPHEN(Value[13])) {
if (!IS_HYPHEN (Value[13])) {
return FALSE; return FALSE;
} }
if (!IS_HYPHEN(Value[18])) {
if (!IS_HYPHEN (Value[18])) {
return FALSE; return FALSE;
} }
if (!IS_HYPHEN(Value[23])) {
if (!IS_HYPHEN (Value[23])) {
return FALSE; return FALSE;
} }
if (!IsValidDigital(&Value[0], 8, TRUE)) {
if (!IsValidDigital (&Value[0], 8, TRUE)) {
return FALSE; return FALSE;
} }
if (!IsValidDigital(&Value[9], 4, TRUE)) {
if (!IsValidDigital (&Value[9], 4, TRUE)) {
return FALSE; return FALSE;
} }
if (!IsValidDigital(&Value[14], 4, TRUE)) {
if (!IsValidDigital (&Value[14], 4, TRUE)) {
return FALSE; return FALSE;
} }
if (!IsValidDigital(&Value[19], 4, TRUE)) {
if (!IsValidDigital (&Value[19], 4, TRUE)) {
return FALSE; return FALSE;
} }
if (!IsValidDigital(&Value[24], 12, TRUE)) {
if (!IsValidDigital (&Value[24], 12, TRUE)) {
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
@ -278,9 +302,10 @@ IsValidValue (
IN UINTN Length IN UINTN Length
) )
{ {
if (IsValidName(Value, Length) || IsValidGuid(Value, Length)) { if (IsValidName (Value, Length) || IsValidGuid (Value, Length)) {
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
@ -309,13 +334,15 @@ DumpIniSection (
PtrSection = Section; PtrSection = Section;
Section = Section->PtrNext; Section = Section->PtrNext;
if (PtrSection->PtrSection != NULL) { if (PtrSection->PtrSection != NULL) {
DEBUG((DEBUG_VERBOSE, "Section - %a\n", PtrSection->PtrSection)); DEBUG ((DEBUG_VERBOSE, "Section - %a\n", PtrSection->PtrSection));
} }
if (PtrSection->PtrEntry != NULL) { if (PtrSection->PtrEntry != NULL) {
DEBUG ((DEBUG_VERBOSE, " Entry - %a\n", PtrSection->PtrEntry)); DEBUG ((DEBUG_VERBOSE, " Entry - %a\n", PtrSection->PtrEntry));
} }
if (PtrSection->PtrValue != NULL) { if (PtrSection->PtrValue != NULL) {
DEBUG((DEBUG_VERBOSE, " Value - %a\n", PtrSection->PtrValue)); DEBUG ((DEBUG_VERBOSE, " Value - %a\n", PtrSection->PtrValue));
} }
} }
} }
@ -352,9 +379,10 @@ ProfileGetLine (
// 0x0D indicates a line break. Otherwise there is no line break // 0x0D indicates a line break. Otherwise there is no line break
// //
while ((UINTN)PtrBuf < PtrEnd) { while ((UINTN)PtrBuf < PtrEnd) {
if (*PtrBuf == 0x0D || *PtrBuf == 0x0A) { if ((*PtrBuf == 0x0D) || (*PtrBuf == 0x0A)) {
break; break;
} }
PtrBuf++; PtrBuf++;
} }
@ -368,9 +396,9 @@ ProfileGetLine (
// //
// Further check if a 0x0A follows. If yes, count 0xA // Further check if a 0x0A follows. If yes, count 0xA
// //
Length = (UINTN) PtrBuf - (UINTN) Buffer + 2; Length = (UINTN)PtrBuf - (UINTN)Buffer + 2;
} else { } else {
Length = (UINTN) PtrBuf - (UINTN) Buffer + 1; Length = (UINTN)PtrBuf - (UINTN)Buffer + 1;
} }
if (Length > (*LineSize)) { if (Length > (*LineSize)) {
@ -412,13 +440,15 @@ ProfileTrim (
// Trim the tail first, include CR, LF, TAB, and SPACE. // Trim the tail first, include CR, LF, TAB, and SPACE.
// //
Length = *BufferSize; Length = *BufferSize;
PtrBuf = (UINT8 *) ((UINTN) Buffer + Length - 1); PtrBuf = (UINT8 *)((UINTN)Buffer + Length - 1);
while (PtrBuf >= Buffer) { while (PtrBuf >= Buffer) {
if ((*PtrBuf != 0x0D) && (*PtrBuf != 0x0A ) if ( (*PtrBuf != 0x0D) && (*PtrBuf != 0x0A)
&& (*PtrBuf != 0x20) && (*PtrBuf != 0x09)) { && (*PtrBuf != 0x20) && (*PtrBuf != 0x09))
{
break; break;
} }
PtrBuf --;
PtrBuf--;
} }
// //
@ -437,10 +467,12 @@ ProfileTrim (
// Now skip the heading CR, LF, TAB and SPACE // Now skip the heading CR, LF, TAB and SPACE
// //
while (PtrBuf <= PtrEnd) { while (PtrBuf <= PtrEnd) {
if ((*PtrBuf != 0x0D) && (*PtrBuf != 0x0A ) if ( (*PtrBuf != 0x0D) && (*PtrBuf != 0x0A)
&& (*PtrBuf != 0x20) && (*PtrBuf != 0x09)) { && (*PtrBuf != 0x20) && (*PtrBuf != 0x09))
{
break; break;
} }
PtrBuf++; PtrBuf++;
} }
@ -504,6 +536,7 @@ ProfileGetComments (
FreePool (CommentItem); FreePool (CommentItem);
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
CopyMem (CommentItem->PtrComment, Buffer, BufferSize); CopyMem (CommentItem->PtrComment, Buffer, BufferSize);
*(CommentItem->PtrComment + BufferSize) = '\0'; *(CommentItem->PtrComment + BufferSize) = '\0';
@ -533,7 +566,7 @@ ProfileGetSection (
UINT8 *PtrBuf; UINT8 *PtrBuf;
UINT8 *PtrEnd; UINT8 *PtrEnd;
ASSERT(BufferSize >= 1); ASSERT (BufferSize >= 1);
// //
// The first character of Buffer is '[', now we want for ']' // The first character of Buffer is '[', now we want for ']'
// //
@ -543,14 +576,17 @@ ProfileGetSection (
if (*PtrBuf == ']') { if (*PtrBuf == ']') {
break; break;
} }
PtrBuf ++;
PtrBuf++;
} }
if (PtrBuf > PtrEnd) { if (PtrBuf > PtrEnd) {
// //
// Not found. Invalid line // Not found. Invalid line
// //
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
if (PtrBuf <= Buffer + 1) { if (PtrBuf <= Buffer + 1) {
// Empty name // Empty name
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
@ -572,7 +608,7 @@ ProfileGetSection (
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
if (!IsValidName((CHAR8 *)Buffer + 1, Length)) { if (!IsValidName ((CHAR8 *)Buffer + 1, Length)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -634,7 +670,7 @@ ProfileGetEntry (
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
PtrBuf = Buffer; PtrBuf = Buffer;
PtrEnd = (UINT8 *) ((UINTN)Buffer + BufferSize - 1); PtrEnd = (UINT8 *)((UINTN)Buffer + BufferSize - 1);
// //
// First search for '=' // First search for '='
@ -643,14 +679,17 @@ ProfileGetEntry (
if (*PtrBuf == '=') { if (*PtrBuf == '=') {
break; break;
} }
PtrBuf++; PtrBuf++;
} }
if (PtrBuf > PtrEnd) { if (PtrBuf > PtrEnd) {
// //
// Not found. Invalid line // Not found. Invalid line
// //
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
if (PtrBuf <= Buffer) { if (PtrBuf <= Buffer) {
// Empty name // Empty name
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
@ -672,7 +711,7 @@ ProfileGetEntry (
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
if (!IsValidName((CHAR8 *)Buffer, Length)) { if (!IsValidName ((CHAR8 *)Buffer, Length)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -682,6 +721,7 @@ ProfileGetEntry (
if (*SectionHead == NULL) { if (*SectionHead == NULL) {
return Status; return Status;
} }
PtrSection = *SectionHead; PtrSection = *SectionHead;
SectionItem = AllocatePool (sizeof (SECTION_ITEM)); SectionItem = AllocatePool (sizeof (SECTION_ITEM));
@ -703,6 +743,7 @@ ProfileGetEntry (
if (SectionItem->PtrSection == NULL) { if (SectionItem->PtrSection == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
CopyMem (SectionItem->PtrSection, PtrSection->PtrSection, PtrSection->SecNameLen + 1); CopyMem (SectionItem->PtrSection, PtrSection->PtrSection, PtrSection->SecNameLen + 1);
// //
@ -710,9 +751,10 @@ ProfileGetEntry (
// //
SectionItem->PtrEntry = AllocatePool (Length + 1); SectionItem->PtrEntry = AllocatePool (Length + 1);
if (SectionItem->PtrEntry == NULL) { if (SectionItem->PtrEntry == NULL) {
FreePool(SectionItem->PtrSection); FreePool (SectionItem->PtrSection);
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
CopyMem (SectionItem->PtrEntry, Buffer, Length); CopyMem (SectionItem->PtrEntry, Buffer, Length);
*(SectionItem->PtrEntry + Length) = '\0'; *(SectionItem->PtrEntry + Length) = '\0';
@ -722,17 +764,20 @@ ProfileGetEntry (
PtrBuf = PtrBuf + 1; PtrBuf = PtrBuf + 1;
Buffer = PtrBuf; Buffer = PtrBuf;
while (PtrBuf <= PtrEnd) { while (PtrBuf <= PtrEnd) {
if (*PtrBuf == '#' || *PtrBuf == ';') { if ((*PtrBuf == '#') || (*PtrBuf == ';')) {
break; break;
} }
PtrBuf++; PtrBuf++;
} }
if (PtrBuf <= Buffer) { if (PtrBuf <= Buffer) {
// Empty name // Empty name
FreePool(SectionItem->PtrEntry); FreePool (SectionItem->PtrEntry);
FreePool(SectionItem->PtrSection); FreePool (SectionItem->PtrSection);
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
Length = PtrBuf - Buffer; Length = PtrBuf - Buffer;
ProfileTrim ( ProfileTrim (
Buffer, Buffer,
@ -743,14 +788,14 @@ ProfileGetEntry (
// Invalid line if the entry value is null // Invalid line if the entry value is null
// //
if (Length == 0) { if (Length == 0) {
FreePool(SectionItem->PtrEntry); FreePool (SectionItem->PtrEntry);
FreePool(SectionItem->PtrSection); FreePool (SectionItem->PtrSection);
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
if (!IsValidValue((CHAR8 *)Buffer, Length)) { if (!IsValidValue ((CHAR8 *)Buffer, Length)) {
FreePool(SectionItem->PtrEntry); FreePool (SectionItem->PtrEntry);
FreePool(SectionItem->PtrSection); FreePool (SectionItem->PtrSection);
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -759,10 +804,11 @@ ProfileGetEntry (
// //
SectionItem->PtrValue = AllocatePool (Length + 1); SectionItem->PtrValue = AllocatePool (Length + 1);
if (SectionItem->PtrValue == NULL) { if (SectionItem->PtrValue == NULL) {
FreePool(SectionItem->PtrEntry); FreePool (SectionItem->PtrEntry);
FreePool(SectionItem->PtrSection); FreePool (SectionItem->PtrSection);
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
CopyMem (SectionItem->PtrValue, Buffer, Length); CopyMem (SectionItem->PtrValue, Buffer, Length);
*(SectionItem->PtrValue + Length) = '\0'; *(SectionItem->PtrValue + Length) = '\0';
@ -791,12 +837,15 @@ FreeAllList (
if (PtrSection->PtrEntry != NULL) { if (PtrSection->PtrEntry != NULL) {
FreePool (PtrSection->PtrEntry); FreePool (PtrSection->PtrEntry);
} }
if (PtrSection->PtrSection != NULL) { if (PtrSection->PtrSection != NULL) {
FreePool (PtrSection->PtrSection); FreePool (PtrSection->PtrSection);
} }
if (PtrSection->PtrValue != NULL) { if (PtrSection->PtrValue != NULL) {
FreePool (PtrSection->PtrValue); FreePool (PtrSection->PtrValue);
} }
FreePool (PtrSection); FreePool (PtrSection);
} }
@ -806,6 +855,7 @@ FreeAllList (
if (PtrComment->PtrComment != NULL) { if (PtrComment->PtrComment != NULL) {
FreePool (PtrComment->PtrComment); FreePool (PtrComment->PtrComment);
} }
FreePool (PtrComment); FreePool (PtrComment);
} }
@ -835,13 +885,14 @@ UpdateGetProfileString (
*EntryValue = NULL; *EntryValue = NULL;
while (Section != NULL) { while (Section != NULL) {
if (AsciiStrCmp ((CONST CHAR8 *) Section->PtrSection, (CONST CHAR8 *) SectionName) == 0) { if (AsciiStrCmp ((CONST CHAR8 *)Section->PtrSection, (CONST CHAR8 *)SectionName) == 0) {
if (Section->PtrEntry != NULL) { if (Section->PtrEntry != NULL) {
if (AsciiStrCmp ((CONST CHAR8 *) Section->PtrEntry, (CONST CHAR8 *) EntryName) == 0) { if (AsciiStrCmp ((CONST CHAR8 *)Section->PtrEntry, (CONST CHAR8 *)EntryName) == 0) {
break; break;
} }
} }
} }
Section = Section->PtrNext; Section = Section->PtrNext;
} }
@ -887,8 +938,8 @@ PreProcessDataFile (
*SectionHead = NULL; *SectionHead = NULL;
*CommentHead = NULL; *CommentHead = NULL;
BufferEnd = (CHAR8 *) ( (UINTN) DataBuffer + BufferSize); BufferEnd = (CHAR8 *)((UINTN)DataBuffer + BufferSize);
CurrentPtr = (CHAR8 *) DataBuffer; CurrentPtr = (CHAR8 *)DataBuffer;
MaxLineLength = MAX_LINE_LENGTH; MaxLineLength = MAX_LINE_LENGTH;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
@ -906,9 +957,9 @@ PreProcessDataFile (
// characters. Otherwise BUFFER_TOO_SMALL will be returned. // characters. Otherwise BUFFER_TOO_SMALL will be returned.
// //
Status = ProfileGetLine ( Status = ProfileGetLine (
(UINT8 *) Source, (UINT8 *)Source,
SourceLength, SourceLength,
(UINT8 *) PtrLine, (UINT8 *)PtrLine,
&LineLength &LineLength
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -924,28 +975,31 @@ PreProcessDataFile (
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
break; break;
} }
SourceLength = LineLength; SourceLength = LineLength;
Status = ProfileGetLine ( Status = ProfileGetLine (
(UINT8 *) Source, (UINT8 *)Source,
SourceLength, SourceLength,
(UINT8 *) PtrLine, (UINT8 *)PtrLine,
&LineLength &LineLength
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
break; break;
} }
MaxLineLength = LineLength; MaxLineLength = LineLength;
} else { } else {
break; break;
} }
} }
CurrentPtr = (CHAR8 *) ( (UINTN) CurrentPtr + LineLength);
CurrentPtr = (CHAR8 *)((UINTN)CurrentPtr + LineLength);
// //
// Line got. Trim the line before processing it. // Line got. Trim the line before processing it.
// //
ProfileTrim ( ProfileTrim (
(UINT8 *) PtrLine, (UINT8 *)PtrLine,
&LineLength &LineLength
); );
@ -956,21 +1010,21 @@ PreProcessDataFile (
continue; continue;
} }
if (PtrLine[0] == '#' || PtrLine[0] == ';') { if ((PtrLine[0] == '#') || (PtrLine[0] == ';')) {
Status = ProfileGetComments ( Status = ProfileGetComments (
(UINT8 *) PtrLine, (UINT8 *)PtrLine,
LineLength, LineLength,
CommentHead CommentHead
); );
} else if (PtrLine[0] == '[') { } else if (PtrLine[0] == '[') {
Status = ProfileGetSection ( Status = ProfileGetSection (
(UINT8 *) PtrLine, (UINT8 *)PtrLine,
LineLength, LineLength,
SectionHead SectionHead
); );
} else { } else {
Status = ProfileGetEntry ( Status = ProfileGetEntry (
(UINT8 *) PtrLine, (UINT8 *)PtrLine,
LineLength, LineLength,
SectionHead SectionHead
); );
@ -1009,11 +1063,11 @@ OpenIniFile (
EFI_STATUS Status; EFI_STATUS Status;
INI_PARSING_LIB_CONTEXT *IniContext; INI_PARSING_LIB_CONTEXT *IniContext;
if (DataBuffer == NULL || BufferSize == 0) { if ((DataBuffer == NULL) || (BufferSize == 0)) {
return NULL; return NULL;
} }
IniContext = AllocateZeroPool(sizeof(INI_PARSING_LIB_CONTEXT)); IniContext = AllocateZeroPool (sizeof (INI_PARSING_LIB_CONTEXT));
if (IniContext == NULL) { if (IniContext == NULL) {
return NULL; return NULL;
} }
@ -1027,12 +1081,13 @@ OpenIniFile (
&IniContext->SectionHead, &IniContext->SectionHead,
&IniContext->CommentHead &IniContext->CommentHead
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
FreePool(IniContext); FreePool (IniContext);
return NULL; return NULL;
} }
DEBUG_CODE_BEGIN (); DEBUG_CODE_BEGIN ();
DumpIniSection(IniContext); DumpIniSection (IniContext);
DEBUG_CODE_END (); DEBUG_CODE_END ();
return IniContext; return IniContext;
} }
@ -1050,7 +1105,7 @@ OpenIniFile (
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
GetStringFromDataFile( GetStringFromDataFile (
IN VOID *Context, IN VOID *Context,
IN CHAR8 *SectionName, IN CHAR8 *SectionName,
IN CHAR8 *EntryName, IN CHAR8 *EntryName,
@ -1060,7 +1115,7 @@ GetStringFromDataFile(
INI_PARSING_LIB_CONTEXT *IniContext; INI_PARSING_LIB_CONTEXT *IniContext;
EFI_STATUS Status; EFI_STATUS Status;
if (Context == NULL || SectionName == NULL || EntryName == NULL || EntryValue == NULL) { if ((Context == NULL) || (SectionName == NULL) || (EntryName == NULL) || (EntryValue == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1100,24 +1155,26 @@ GetGuidFromDataFile (
EFI_STATUS Status; EFI_STATUS Status;
RETURN_STATUS RStatus; RETURN_STATUS RStatus;
if (Context == NULL || SectionName == NULL || EntryName == NULL || Guid == NULL) { if ((Context == NULL) || (SectionName == NULL) || (EntryName == NULL) || (Guid == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
Status = GetStringFromDataFile( Status = GetStringFromDataFile (
Context, Context,
SectionName, SectionName,
EntryName, EntryName,
&Value &Value
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
ASSERT (Value != NULL); ASSERT (Value != NULL);
RStatus = AsciiStrToGuid (Value, Guid); RStatus = AsciiStrToGuid (Value, Guid);
if (RETURN_ERROR (RStatus) || (Value[GUID_STRING_LENGTH] != '\0')) { if (RETURN_ERROR (RStatus) || (Value[GUID_STRING_LENGTH] != '\0')) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -1144,24 +1201,26 @@ GetDecimalUintnFromDataFile (
CHAR8 *Value; CHAR8 *Value;
EFI_STATUS Status; EFI_STATUS Status;
if (Context == NULL || SectionName == NULL || EntryName == NULL || Data == NULL) { if ((Context == NULL) || (SectionName == NULL) || (EntryName == NULL) || (Data == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
Status = GetStringFromDataFile( Status = GetStringFromDataFile (
Context, Context,
SectionName, SectionName,
EntryName, EntryName,
&Value &Value
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
ASSERT (Value != NULL); ASSERT (Value != NULL);
if (!IsValidDecimalString(Value, AsciiStrLen(Value))) { if (!IsValidDecimalString (Value, AsciiStrLen (Value))) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
*Data = AsciiStrDecimalToUintn(Value);
*Data = AsciiStrDecimalToUintn (Value);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -1188,24 +1247,26 @@ GetHexUintnFromDataFile (
CHAR8 *Value; CHAR8 *Value;
EFI_STATUS Status; EFI_STATUS Status;
if (Context == NULL || SectionName == NULL || EntryName == NULL || Data == NULL) { if ((Context == NULL) || (SectionName == NULL) || (EntryName == NULL) || (Data == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
Status = GetStringFromDataFile( Status = GetStringFromDataFile (
Context, Context,
SectionName, SectionName,
EntryName, EntryName,
&Value &Value
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
ASSERT (Value != NULL); ASSERT (Value != NULL);
if (!IsValidHexString(Value, AsciiStrLen(Value))) { if (!IsValidHexString (Value, AsciiStrLen (Value))) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
*Data = AsciiStrHexToUintn(Value);
*Data = AsciiStrHexToUintn (Value);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -1232,24 +1293,26 @@ GetHexUint64FromDataFile (
CHAR8 *Value; CHAR8 *Value;
EFI_STATUS Status; EFI_STATUS Status;
if (Context == NULL || SectionName == NULL || EntryName == NULL || Data == NULL) { if ((Context == NULL) || (SectionName == NULL) || (EntryName == NULL) || (Data == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
Status = GetStringFromDataFile( Status = GetStringFromDataFile (
Context, Context,
SectionName, SectionName,
EntryName, EntryName,
&Value &Value
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
ASSERT (Value != NULL); ASSERT (Value != NULL);
if (!IsValidHexString(Value, AsciiStrLen(Value))) { if (!IsValidHexString (Value, AsciiStrLen (Value))) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
*Data = AsciiStrHexToUint64(Value);
*Data = AsciiStrHexToUint64 (Value);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -1267,11 +1330,11 @@ CloseIniFile (
INI_PARSING_LIB_CONTEXT *IniContext; INI_PARSING_LIB_CONTEXT *IniContext;
if (Context == NULL) { if (Context == NULL) {
return ; return;
} }
IniContext = Context; IniContext = Context;
FreeAllList(IniContext->SectionHead, IniContext->CommentHead); FreeAllList (IniContext->SectionHead, IniContext->CommentHead);
return; return;
} }

View File

@ -59,7 +59,8 @@ PerformFlashWriteWithProgress (
if (FlashAddressType == FlashAddressTypeRelativeAddress) { if (FlashAddressType == FlashAddressTypeRelativeAddress) {
FlashAddress = FlashAddress + mInternalFdAddress; FlashAddress = FlashAddress + mInternalFdAddress;
} }
CopyMem((VOID *)(UINTN)(FlashAddress), Buffer, Length);
CopyMem ((VOID *)(UINTN)(FlashAddress), Buffer, Length);
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -46,7 +46,7 @@ ParseRecoveryDataFile (
// //
// First process the data buffer and get all sections and entries // First process the data buffer and get all sections and entries
// //
Context = OpenIniFile(DataBuffer, BufferSize); Context = OpenIniFile (DataBuffer, BufferSize);
if (Context == NULL) { if (Context == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -54,26 +54,26 @@ ParseRecoveryDataFile (
// //
// Now get NumOfUpdate // Now get NumOfUpdate
// //
Status = GetDecimalUintnFromDataFile( Status = GetDecimalUintnFromDataFile (
Context, Context,
"Head", "Head",
"NumOfRecovery", "NumOfRecovery",
&Num &Num
); );
if (EFI_ERROR(Status) || (Num == 0)) { if (EFI_ERROR (Status) || (Num == 0)) {
DEBUG((DEBUG_ERROR, "NumOfRecovery not found\n")); DEBUG ((DEBUG_ERROR, "NumOfRecovery not found\n"));
CloseIniFile(Context); CloseIniFile (Context);
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
ConfigHeader->NumOfRecovery = Num; ConfigHeader->NumOfRecovery = Num;
*RecoveryArray = AllocateZeroPool ((sizeof (RECOVERY_CONFIG_DATA) * Num)); *RecoveryArray = AllocateZeroPool ((sizeof (RECOVERY_CONFIG_DATA) * Num));
if (*RecoveryArray == NULL) { if (*RecoveryArray == NULL) {
CloseIniFile(Context); CloseIniFile (Context);
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
for (Index = 0 ; Index < ConfigHeader->NumOfRecovery; Index++) { for (Index = 0; Index < ConfigHeader->NumOfRecovery; Index++) {
// //
// Get the section name of each update // Get the section name of each update
// //
@ -85,15 +85,15 @@ ParseRecoveryDataFile (
Index, Index,
0 0
); );
Status = GetStringFromDataFile( Status = GetStringFromDataFile (
Context, Context,
"Head", "Head",
Entry, Entry,
&SectionName &SectionName
); );
if (EFI_ERROR(Status) || (SectionName == NULL)) { if (EFI_ERROR (Status) || (SectionName == NULL)) {
DEBUG((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry)); DEBUG ((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry));
CloseIniFile(Context); CloseIniFile (Context);
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -105,58 +105,59 @@ ParseRecoveryDataFile (
// //
// FileGuid // FileGuid
// //
Status = GetGuidFromDataFile( Status = GetGuidFromDataFile (
Context, Context,
SectionName, SectionName,
"FileGuid", "FileGuid",
&FileGuid &FileGuid
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
CloseIniFile(Context); CloseIniFile (Context);
DEBUG((DEBUG_ERROR, "[%d] FileGuid not found\n", Index)); DEBUG ((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
CopyGuid(&((*RecoveryArray)[Index].FileGuid), &FileGuid); CopyGuid (&((*RecoveryArray)[Index].FileGuid), &FileGuid);
// //
// Length // Length
// //
Status = GetHexUintnFromDataFile( Status = GetHexUintnFromDataFile (
Context, Context,
SectionName, SectionName,
"Length", "Length",
&Num &Num
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
CloseIniFile(Context); CloseIniFile (Context);
DEBUG((DEBUG_ERROR, "[%d] Length not found\n", Index)); DEBUG ((DEBUG_ERROR, "[%d] Length not found\n", Index));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
(*RecoveryArray)[Index].Length = Num; (*RecoveryArray)[Index].Length = Num;
// //
// ImageOffset // ImageOffset
// //
Status = GetHexUintnFromDataFile( Status = GetHexUintnFromDataFile (
Context, Context,
SectionName, SectionName,
"ImageOffset", "ImageOffset",
&Num &Num
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
CloseIniFile(Context); CloseIniFile (Context);
DEBUG((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index)); DEBUG ((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
(*RecoveryArray)[Index].ImageOffset = Num; (*RecoveryArray)[Index].ImageOffset = Num;
} }
// //
// Now all configuration data got. Free those temporary buffers // Now all configuration data got. Free those temporary buffers
// //
CloseIniFile(Context); CloseIniFile (Context);
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -111,11 +111,11 @@ IsSystemFmpImage (
UINTN Count; UINTN Count;
UINTN Index; UINTN Index;
Guid = PcdGetPtr(PcdSystemFmpCapsuleImageTypeIdGuid); Guid = PcdGetPtr (PcdSystemFmpCapsuleImageTypeIdGuid);
Count = PcdGetSize(PcdSystemFmpCapsuleImageTypeIdGuid) / sizeof(GUID); Count = PcdGetSize (PcdSystemFmpCapsuleImageTypeIdGuid) / sizeof (GUID);
for (Index = 0; Index < Count; Index++, Guid++) { for (Index = 0; Index < Count; Index++, Guid++) {
if (CompareGuid(&FmpImageHeader->UpdateImageTypeId, Guid)) { if (CompareGuid (&FmpImageHeader->UpdateImageTypeId, Guid)) {
return TRUE; return TRUE;
} }
} }
@ -136,7 +136,7 @@ IsFmpCapsuleGuid (
IN EFI_GUID *CapsuleGuid IN EFI_GUID *CapsuleGuid
) )
{ {
if (CompareGuid(&gEfiFmpCapsuleGuid, CapsuleGuid)) { if (CompareGuid (&gEfiFmpCapsuleGuid, CapsuleGuid)) {
return TRUE; return TRUE;
} }
@ -168,7 +168,7 @@ IsSystemFmpCapsuleImage (
UINT32 ItemNum; UINT32 ItemNum;
UINTN Index; UINTN Index;
FmpCapsuleHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER *) ((UINT8 *) CapsuleHeader + CapsuleHeader->HeaderSize); FmpCapsuleHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER *)((UINT8 *)CapsuleHeader + CapsuleHeader->HeaderSize);
if (FmpCapsuleHeader->EmbeddedDriverCount != 0) { if (FmpCapsuleHeader->EmbeddedDriverCount != 0) {
return FALSE; return FALSE;
@ -184,7 +184,7 @@ IsSystemFmpCapsuleImage (
for (Index = 0; Index < ItemNum; Index++) { for (Index = 0; Index < ItemNum; Index++) {
ImageHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *)((UINT8 *)FmpCapsuleHeader + ItemOffsetList[Index]); ImageHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *)((UINT8 *)FmpCapsuleHeader + ItemOffsetList[Index]);
if (!IsSystemFmpImage(ImageHeader)) { if (!IsSystemFmpImage (ImageHeader)) {
return FALSE; return FALSE;
} }
} }
@ -213,9 +213,11 @@ IsValidCapsuleHeader (
if (CapsuleHeader->CapsuleImageSize != CapsuleSize) { if (CapsuleHeader->CapsuleImageSize != CapsuleSize) {
return FALSE; return FALSE;
} }
if (CapsuleHeader->HeaderSize >= CapsuleHeader->CapsuleImageSize) { if (CapsuleHeader->HeaderSize >= CapsuleHeader->CapsuleImageSize) {
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
@ -258,51 +260,55 @@ ValidateFmpCapsule (
UINTN FmpImageHeaderSize; UINTN FmpImageHeaderSize;
if (CapsuleHeader->HeaderSize >= CapsuleHeader->CapsuleImageSize) { if (CapsuleHeader->HeaderSize >= CapsuleHeader->CapsuleImageSize) {
DEBUG((DEBUG_ERROR, "HeaderSize(0x%x) >= CapsuleImageSize(0x%x)\n", CapsuleHeader->HeaderSize, CapsuleHeader->CapsuleImageSize)); DEBUG ((DEBUG_ERROR, "HeaderSize(0x%x) >= CapsuleImageSize(0x%x)\n", CapsuleHeader->HeaderSize, CapsuleHeader->CapsuleImageSize));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
FmpCapsuleHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER *) ((UINT8 *) CapsuleHeader + CapsuleHeader->HeaderSize); FmpCapsuleHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER *)((UINT8 *)CapsuleHeader + CapsuleHeader->HeaderSize);
EndOfCapsule = (UINT8 *) CapsuleHeader + CapsuleHeader->CapsuleImageSize; EndOfCapsule = (UINT8 *)CapsuleHeader + CapsuleHeader->CapsuleImageSize;
FmpCapsuleSize = (UINTN)EndOfCapsule - (UINTN)FmpCapsuleHeader; FmpCapsuleSize = (UINTN)EndOfCapsule - (UINTN)FmpCapsuleHeader;
if (FmpCapsuleSize < sizeof(EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER)) { if (FmpCapsuleSize < sizeof (EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER)) {
DEBUG((DEBUG_ERROR, "FmpCapsuleSize(0x%x) < EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER\n", FmpCapsuleSize)); DEBUG ((DEBUG_ERROR, "FmpCapsuleSize(0x%x) < EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER\n", FmpCapsuleSize));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// Check EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER // Check EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER
if (FmpCapsuleHeader->Version != EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER_INIT_VERSION) { if (FmpCapsuleHeader->Version != EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER_INIT_VERSION) {
DEBUG((DEBUG_ERROR, "FmpCapsuleHeader->Version(0x%x) != EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER_INIT_VERSION\n", FmpCapsuleHeader->Version)); DEBUG ((DEBUG_ERROR, "FmpCapsuleHeader->Version(0x%x) != EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER_INIT_VERSION\n", FmpCapsuleHeader->Version));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
ItemOffsetList = (UINT64 *)(FmpCapsuleHeader + 1); ItemOffsetList = (UINT64 *)(FmpCapsuleHeader + 1);
// No overflow // No overflow
ItemNum = FmpCapsuleHeader->EmbeddedDriverCount + FmpCapsuleHeader->PayloadItemCount; ItemNum = FmpCapsuleHeader->EmbeddedDriverCount + FmpCapsuleHeader->PayloadItemCount;
if ((FmpCapsuleSize - sizeof(EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER))/sizeof(UINT64) < ItemNum) { if ((FmpCapsuleSize - sizeof (EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER))/sizeof (UINT64) < ItemNum) {
DEBUG((DEBUG_ERROR, "ItemNum(0x%x) too big\n", ItemNum)); DEBUG ((DEBUG_ERROR, "ItemNum(0x%x) too big\n", ItemNum));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
FmpCapsuleHeaderSize = sizeof(EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER) + sizeof(UINT64)*ItemNum;
FmpCapsuleHeaderSize = sizeof (EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER) + sizeof (UINT64)*ItemNum;
// Check ItemOffsetList // Check ItemOffsetList
for (Index = 0; Index < ItemNum; Index++) { for (Index = 0; Index < ItemNum; Index++) {
if (ItemOffsetList[Index] >= FmpCapsuleSize) { if (ItemOffsetList[Index] >= FmpCapsuleSize) {
DEBUG((DEBUG_ERROR, "ItemOffsetList[%d](0x%lx) >= FmpCapsuleSize(0x%x)\n", Index, ItemOffsetList[Index], FmpCapsuleSize)); DEBUG ((DEBUG_ERROR, "ItemOffsetList[%d](0x%lx) >= FmpCapsuleSize(0x%x)\n", Index, ItemOffsetList[Index], FmpCapsuleSize));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (ItemOffsetList[Index] < FmpCapsuleHeaderSize) { if (ItemOffsetList[Index] < FmpCapsuleHeaderSize) {
DEBUG((DEBUG_ERROR, "ItemOffsetList[%d](0x%lx) < FmpCapsuleHeaderSize(0x%x)\n", Index, ItemOffsetList[Index], FmpCapsuleHeaderSize)); DEBUG ((DEBUG_ERROR, "ItemOffsetList[%d](0x%lx) < FmpCapsuleHeaderSize(0x%x)\n", Index, ItemOffsetList[Index], FmpCapsuleHeaderSize));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// //
// All the address in ItemOffsetList must be stored in ascending order // All the address in ItemOffsetList must be stored in ascending order
// //
if (Index > 0) { if (Index > 0) {
if (ItemOffsetList[Index] <= ItemOffsetList[Index - 1]) { if (ItemOffsetList[Index] <= ItemOffsetList[Index - 1]) {
DEBUG((DEBUG_ERROR, "ItemOffsetList[%d](0x%lx) < ItemOffsetList[%d](0x%x)\n", Index, ItemOffsetList[Index], Index, ItemOffsetList[Index - 1])); DEBUG ((DEBUG_ERROR, "ItemOffsetList[%d](0x%lx) < ItemOffsetList[%d](0x%x)\n", Index, ItemOffsetList[Index], Index, ItemOffsetList[Index - 1]));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
} }
@ -316,31 +322,35 @@ ValidateFmpCapsule (
} else { } else {
EndOfPayload = (UINT8 *)(UINTN)ItemOffsetList[Index+1]; EndOfPayload = (UINT8 *)(UINTN)ItemOffsetList[Index+1];
} }
FmpImageSize = (UINTN)EndOfPayload - ItemOffsetList[Index]; FmpImageSize = (UINTN)EndOfPayload - ItemOffsetList[Index];
if (FmpImageSize < OFFSET_OF(EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER, UpdateHardwareInstance)) { if (FmpImageSize < OFFSET_OF (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER, UpdateHardwareInstance)) {
DEBUG((DEBUG_ERROR, "FmpImageSize(0x%lx) < EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER\n", FmpImageSize)); DEBUG ((DEBUG_ERROR, "FmpImageSize(0x%lx) < EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER\n", FmpImageSize));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
FmpImageHeaderSize = sizeof(EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER);
FmpImageHeaderSize = sizeof (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER);
if ((ImageHeader->Version > EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION) || if ((ImageHeader->Version > EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION) ||
(ImageHeader->Version < 1)) { (ImageHeader->Version < 1))
DEBUG((DEBUG_ERROR, "ImageHeader->Version(0x%x) Unknown\n", ImageHeader->Version)); {
DEBUG ((DEBUG_ERROR, "ImageHeader->Version(0x%x) Unknown\n", ImageHeader->Version));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
/// ///
/// Current Init ImageHeader version is 3. UpdateHardwareInstance field was added in version 2 /// Current Init ImageHeader version is 3. UpdateHardwareInstance field was added in version 2
/// and ImageCapsuleSupport field was added in version 3 /// and ImageCapsuleSupport field was added in version 3
/// ///
if (ImageHeader->Version == 1) { if (ImageHeader->Version == 1) {
FmpImageHeaderSize = OFFSET_OF(EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER, UpdateHardwareInstance); FmpImageHeaderSize = OFFSET_OF (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER, UpdateHardwareInstance);
} else if (ImageHeader->Version == 2){ } else if (ImageHeader->Version == 2) {
FmpImageHeaderSize = OFFSET_OF(EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER, ImageCapsuleSupport); FmpImageHeaderSize = OFFSET_OF (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER, ImageCapsuleSupport);
} }
// No overflow // No overflow
if (FmpImageSize != (UINT64)FmpImageHeaderSize + (UINT64)ImageHeader->UpdateImageSize + (UINT64)ImageHeader->UpdateVendorCodeSize) { if (FmpImageSize != (UINT64)FmpImageHeaderSize + (UINT64)ImageHeader->UpdateImageSize + (UINT64)ImageHeader->UpdateVendorCodeSize) {
DEBUG((DEBUG_ERROR, "FmpImageSize(0x%lx) mismatch, UpdateImageSize(0x%x) UpdateVendorCodeSize(0x%x)\n", FmpImageSize, ImageHeader->UpdateImageSize, ImageHeader->UpdateVendorCodeSize)); DEBUG ((DEBUG_ERROR, "FmpImageSize(0x%lx) mismatch, UpdateImageSize(0x%x) UpdateVendorCodeSize(0x%x)\n", FmpImageSize, ImageHeader->UpdateImageSize, ImageHeader->UpdateVendorCodeSize));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
} }
@ -351,9 +361,10 @@ ValidateFmpCapsule (
// //
EndOfPayload = (UINT8 *)(FmpCapsuleHeader + 1); EndOfPayload = (UINT8 *)(FmpCapsuleHeader + 1);
if (EndOfPayload != EndOfCapsule) { if (EndOfPayload != EndOfCapsule) {
DEBUG((DEBUG_ERROR, "EndOfPayload(0x%x) mismatch, EndOfCapsule(0x%x)\n", EndOfPayload, EndOfCapsule)); DEBUG ((DEBUG_ERROR, "EndOfPayload(0x%x) mismatch, EndOfCapsule(0x%x)\n", EndOfPayload, EndOfCapsule));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -361,7 +372,7 @@ ValidateFmpCapsule (
// Check in system FMP capsule // Check in system FMP capsule
// //
if (IsSystemFmp != NULL) { if (IsSystemFmp != NULL) {
*IsSystemFmp = IsSystemFmpCapsuleImage(CapsuleHeader); *IsSystemFmp = IsSystemFmpCapsuleImage (CapsuleHeader);
} }
if (EmbeddedDriverCount != NULL) { if (EmbeddedDriverCount != NULL) {
@ -389,8 +400,8 @@ InitializeRecoveryModule (
EFI_STATUS Status; EFI_STATUS Status;
UINTN BootMode; UINTN BootMode;
BootMode = GetBootModeHob(); BootMode = GetBootModeHob ();
ASSERT(BootMode == BOOT_IN_RECOVERY_MODE); ASSERT (BootMode == BOOT_IN_RECOVERY_MODE);
Status = (**PeiServices).InstallPpi (PeiServices, &mRecoveryPpiList); Status = (**PeiServices).InstallPpi (PeiServices, &mRecoveryPpiList);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
@ -423,14 +434,15 @@ CreateHobForRecoveryCapsule (
// //
// FvImage should be at its required alignment. // FvImage should be at its required alignment.
// //
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) FvImage; FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)FvImage;
// //
// Validate FV Header, if not as expected, return // Validate FV Header, if not as expected, return
// //
if (ReadUnaligned32 (&FvHeader->Signature) != EFI_FVH_SIGNATURE) { if (ReadUnaligned32 (&FvHeader->Signature) != EFI_FVH_SIGNATURE) {
DEBUG((DEBUG_ERROR, "CreateHobForRecoveryCapsule (Fv Signature Error)\n")); DEBUG ((DEBUG_ERROR, "CreateHobForRecoveryCapsule (Fv Signature Error)\n"));
return EFI_VOLUME_CORRUPTED; return EFI_VOLUME_CORRUPTED;
} }
// //
// If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume
// can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from
@ -447,26 +459,28 @@ CreateHobForRecoveryCapsule (
if (FvAlignment < 8) { if (FvAlignment < 8) {
FvAlignment = 8; FvAlignment = 8;
} }
// //
// Allocate the aligned buffer for the FvImage. // Allocate the aligned buffer for the FvImage.
// //
if ((UINTN) FvHeader % FvAlignment != 0) { if ((UINTN)FvHeader % FvAlignment != 0) {
DEBUG((DEBUG_INFO, "CreateHobForRecoveryCapsule (FvHeader 0x%lx is not aligned)\n", (UINT64)(UINTN)FvHeader)); DEBUG ((DEBUG_INFO, "CreateHobForRecoveryCapsule (FvHeader 0x%lx is not aligned)\n", (UINT64)(UINTN)FvHeader));
FvLength = ReadUnaligned64 (&FvHeader->FvLength); FvLength = ReadUnaligned64 (&FvHeader->FvLength);
NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINTN) FvLength), FvAlignment); NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINTN)FvLength), FvAlignment);
if (NewFvBuffer == NULL) { if (NewFvBuffer == NULL) {
DEBUG((DEBUG_ERROR, "CreateHobForRecoveryCapsule (Not enough resource to allocate 0x%lx bytes)\n", FvLength)); DEBUG ((DEBUG_ERROR, "CreateHobForRecoveryCapsule (Not enough resource to allocate 0x%lx bytes)\n", FvLength));
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength);
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer; CopyMem (NewFvBuffer, FvHeader, (UINTN)FvLength);
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)NewFvBuffer;
} }
} }
BuildFvHob((UINT64)(UINTN)FvHeader, FvHeader->FvLength); BuildFvHob ((UINT64)(UINTN)FvHeader, FvHeader->FvLength);
DEBUG((DEBUG_INFO, "BuildFvHob (FV in recovery) - 0x%lx - 0x%lx\n", (UINT64)(UINTN)FvHeader, FvHeader->FvLength)); DEBUG ((DEBUG_INFO, "BuildFvHob (FV in recovery) - 0x%lx - 0x%lx\n", (UINT64)(UINTN)FvHeader, FvHeader->FvLength));
PeiServicesInstallFvInfoPpi( PeiServicesInstallFvInfoPpi (
&FvHeader->FileSystemGuid, &FvHeader->FileSystemGuid,
(VOID *)FvHeader, (VOID *)FvHeader,
(UINT32)FvHeader->FvLength, (UINT32)FvHeader->FvLength,
@ -502,8 +516,8 @@ RecoverImage (
UINTN Index; UINTN Index;
if (ConfigImage == NULL) { if (ConfigImage == NULL) {
DEBUG((DEBUG_INFO, "RecoverImage (NoConfig)\n")); DEBUG ((DEBUG_INFO, "RecoverImage (NoConfig)\n"));
Status = CreateHobForRecoveryCapsule( Status = CreateHobForRecoveryCapsule (
SystemFirmwareImage, SystemFirmwareImage,
SystemFirmwareImageSize SystemFirmwareImageSize
); );
@ -511,25 +525,26 @@ RecoverImage (
} }
ConfigData = NULL; ConfigData = NULL;
ZeroMem (&ConfigHeader, sizeof(ConfigHeader)); ZeroMem (&ConfigHeader, sizeof (ConfigHeader));
Status = ParseRecoveryDataFile ( Status = ParseRecoveryDataFile (
ConfigImage, ConfigImage,
ConfigImageSize, ConfigImageSize,
&ConfigHeader, &ConfigHeader,
&ConfigData &ConfigData
); );
DEBUG((DEBUG_INFO, "ParseRecoveryDataFile - %r\n", Status)); DEBUG ((DEBUG_INFO, "ParseRecoveryDataFile - %r\n", Status));
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
DEBUG((DEBUG_INFO, "ConfigHeader.NumOfRecovery - 0x%x\n", ConfigHeader.NumOfRecovery));
DEBUG((DEBUG_INFO, "PcdEdkiiSystemFirmwareFileGuid - %g\n", PcdGetPtr(PcdEdkiiSystemFirmwareFileGuid))); DEBUG ((DEBUG_INFO, "ConfigHeader.NumOfRecovery - 0x%x\n", ConfigHeader.NumOfRecovery));
DEBUG ((DEBUG_INFO, "PcdEdkiiSystemFirmwareFileGuid - %g\n", PcdGetPtr (PcdEdkiiSystemFirmwareFileGuid)));
Index = 0; Index = 0;
RecoveryConfigData = ConfigData; RecoveryConfigData = ConfigData;
while (Index < ConfigHeader.NumOfRecovery) { while (Index < ConfigHeader.NumOfRecovery) {
if (CompareGuid(&RecoveryConfigData->FileGuid, PcdGetPtr(PcdEdkiiSystemFirmwareFileGuid))) { if (CompareGuid (&RecoveryConfigData->FileGuid, PcdGetPtr (PcdEdkiiSystemFirmwareFileGuid))) {
DEBUG((DEBUG_INFO, "FileGuid - %g (processing)\n", &RecoveryConfigData->FileGuid)); DEBUG ((DEBUG_INFO, "FileGuid - %g (processing)\n", &RecoveryConfigData->FileGuid));
Status = CreateHobForRecoveryCapsule ( Status = CreateHobForRecoveryCapsule (
(UINT8 *)SystemFirmwareImage + RecoveryConfigData->ImageOffset, (UINT8 *)SystemFirmwareImage + RecoveryConfigData->ImageOffset,
RecoveryConfigData->Length RecoveryConfigData->Length
@ -542,7 +557,7 @@ RecoverImage (
break; break;
} }
} else { } else {
DEBUG((DEBUG_INFO, "FileGuid - %g (ignored)\n", &RecoveryConfigData->FileGuid)); DEBUG ((DEBUG_INFO, "FileGuid - %g (ignored)\n", &RecoveryConfigData->FileGuid));
} }
Index++; Index++;
@ -582,18 +597,18 @@ ProcessRecoveryImage (
AuthenticatedImage = NULL; AuthenticatedImage = NULL;
AuthenticatedImageSize = 0; AuthenticatedImageSize = 0;
Status = CapsuleAuthenticateSystemFirmware(Image, Length, TRUE, &LastAttemptVersion, &LastAttemptStatus, &AuthenticatedImage, &AuthenticatedImageSize); Status = CapsuleAuthenticateSystemFirmware (Image, Length, TRUE, &LastAttemptVersion, &LastAttemptStatus, &AuthenticatedImage, &AuthenticatedImageSize);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_INFO, "CapsuleAuthenticateSystemFirmware - %r\n", Status)); DEBUG ((DEBUG_INFO, "CapsuleAuthenticateSystemFirmware - %r\n", Status));
return Status; return Status;
} }
ExtractSystemFirmwareImage(AuthenticatedImage, AuthenticatedImageSize, &SystemFirmwareImage, &SystemFirmwareImageSize); ExtractSystemFirmwareImage (AuthenticatedImage, AuthenticatedImageSize, &SystemFirmwareImage, &SystemFirmwareImageSize);
ExtractConfigImage(AuthenticatedImage, AuthenticatedImageSize, &ConfigImage, &ConfigImageSize); ExtractConfigImage (AuthenticatedImage, AuthenticatedImageSize, &ConfigImage, &ConfigImageSize);
Status = RecoverImage(SystemFirmwareImage, SystemFirmwareImageSize, ConfigImage, ConfigImageSize); Status = RecoverImage (SystemFirmwareImage, SystemFirmwareImageSize, ConfigImage, ConfigImageSize);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_INFO, "RecoverImage - %r\n", Status)); DEBUG ((DEBUG_INFO, "RecoverImage - %r\n", Status));
return Status; return Status;
} }
@ -649,14 +664,14 @@ ProcessFmpCapsuleImage (
// If version is 2 Header should exclude ImageCapsuleSupport field. // If version is 2 Header should exclude ImageCapsuleSupport field.
// //
if (ImageHeader->Version == 1) { if (ImageHeader->Version == 1) {
Image = (UINT8 *)ImageHeader + OFFSET_OF(EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER, UpdateHardwareInstance); Image = (UINT8 *)ImageHeader + OFFSET_OF (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER, UpdateHardwareInstance);
} else { } else {
Image = (UINT8 *)ImageHeader + OFFSET_OF(EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER, ImageCapsuleSupport); Image = (UINT8 *)ImageHeader + OFFSET_OF (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER, ImageCapsuleSupport);
} }
} }
Status = ProcessRecoveryImage (Image, ImageHeader->UpdateImageSize); Status = ProcessRecoveryImage (Image, ImageHeader->UpdateImageSize);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
} }
@ -689,32 +704,32 @@ ProcessRecoveryCapsule (
CapsuleHeader = CapsuleBuffer; CapsuleHeader = CapsuleBuffer;
if (!IsValidCapsuleHeader (CapsuleHeader, CapsuleSize)) { if (!IsValidCapsuleHeader (CapsuleHeader, CapsuleSize)) {
DEBUG((DEBUG_ERROR, "CapsuleImageSize incorrect\n")); DEBUG ((DEBUG_ERROR, "CapsuleImageSize incorrect\n"));
return EFI_SECURITY_VIOLATION; return EFI_SECURITY_VIOLATION;
} }
// //
// Check FMP capsule layout // Check FMP capsule layout
// //
if (IsFmpCapsuleGuid(&CapsuleHeader->CapsuleGuid)) { if (IsFmpCapsuleGuid (&CapsuleHeader->CapsuleGuid)) {
DEBUG((DEBUG_INFO, "CreateHobForRecoveryCapsule\n")); DEBUG ((DEBUG_INFO, "CreateHobForRecoveryCapsule\n"));
DEBUG((DEBUG_INFO, "ProcessCapsuleImage for FmpCapsule ...\n")); DEBUG ((DEBUG_INFO, "ProcessCapsuleImage for FmpCapsule ...\n"));
DEBUG((DEBUG_INFO, "ValidateFmpCapsule ...\n")); DEBUG ((DEBUG_INFO, "ValidateFmpCapsule ...\n"));
Status = ValidateFmpCapsule(CapsuleHeader, &IsSystemFmp, NULL); Status = ValidateFmpCapsule (CapsuleHeader, &IsSystemFmp, NULL);
DEBUG((DEBUG_INFO, "ValidateFmpCapsule - %r\n", Status)); DEBUG ((DEBUG_INFO, "ValidateFmpCapsule - %r\n", Status));
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Process EFI FMP Capsule // Process EFI FMP Capsule
// //
DEBUG((DEBUG_INFO, "ProcessFmpCapsuleImage ...\n")); DEBUG ((DEBUG_INFO, "ProcessFmpCapsuleImage ...\n"));
Status = ProcessFmpCapsuleImage(CapsuleHeader, IsSystemFmp); Status = ProcessFmpCapsuleImage (CapsuleHeader, IsSystemFmp);
DEBUG((DEBUG_INFO, "ProcessFmpCapsuleImage - %r\n", Status)); DEBUG ((DEBUG_INFO, "ProcessFmpCapsuleImage - %r\n", Status));
DEBUG((DEBUG_INFO, "CreateHobForRecoveryCapsule Done\n")); DEBUG ((DEBUG_INFO, "CreateHobForRecoveryCapsule Done\n"));
return Status; return Status;
} }
@ -749,7 +764,7 @@ LoadRecoveryCapsule (
EFI_GUID CapsuleType; EFI_GUID CapsuleType;
VOID *CapsuleBuffer; VOID *CapsuleBuffer;
DEBUG((DEBUG_INFO | DEBUG_LOAD, "Recovery Entry\n")); DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Recovery Entry\n"));
for (Instance = 0; ; Instance++) { for (Instance = 0; ; Instance++) {
Status = PeiServicesLocatePpi ( Status = PeiServicesLocatePpi (
@ -762,6 +777,7 @@ LoadRecoveryCapsule (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
break; break;
} }
NumberRecoveryCapsules = 0; NumberRecoveryCapsules = 0;
Status = DeviceRecoveryPpi->GetNumberRecoveryCapsules ( Status = DeviceRecoveryPpi->GetNumberRecoveryCapsules (
(EFI_PEI_SERVICES **)PeiServices, (EFI_PEI_SERVICES **)PeiServices,
@ -772,6 +788,7 @@ LoadRecoveryCapsule (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
} }
for (CapsuleInstance = 1; CapsuleInstance <= NumberRecoveryCapsules; CapsuleInstance++) { for (CapsuleInstance = 1; CapsuleInstance <= NumberRecoveryCapsules; CapsuleInstance++) {
CapsuleSize = 0; CapsuleSize = 0;
Status = DeviceRecoveryPpi->GetRecoveryCapsuleInfo ( Status = DeviceRecoveryPpi->GetRecoveryCapsuleInfo (
@ -786,11 +803,12 @@ LoadRecoveryCapsule (
break; break;
} }
CapsuleBuffer = AllocatePages (EFI_SIZE_TO_PAGES(CapsuleSize)); CapsuleBuffer = AllocatePages (EFI_SIZE_TO_PAGES (CapsuleSize));
if (CapsuleBuffer == NULL) { if (CapsuleBuffer == NULL) {
DEBUG ((DEBUG_ERROR, "LoadRecoveryCapsule - AllocatePool fail\n")); DEBUG ((DEBUG_ERROR, "LoadRecoveryCapsule - AllocatePool fail\n"));
continue; continue;
} }
Status = DeviceRecoveryPpi->LoadRecoveryCapsule ( Status = DeviceRecoveryPpi->LoadRecoveryCapsule (
(EFI_PEI_SERVICES **)PeiServices, (EFI_PEI_SERVICES **)PeiServices,
DeviceRecoveryPpi, DeviceRecoveryPpi,
@ -799,9 +817,10 @@ LoadRecoveryCapsule (
); );
DEBUG ((DEBUG_ERROR, "LoadRecoveryCapsule - LoadRecoveryCapsule (%d) - %r\n", CapsuleInstance, Status)); DEBUG ((DEBUG_ERROR, "LoadRecoveryCapsule - LoadRecoveryCapsule (%d) - %r\n", CapsuleInstance, Status));
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
FreePages (CapsuleBuffer, EFI_SIZE_TO_PAGES(CapsuleSize)); FreePages (CapsuleBuffer, EFI_SIZE_TO_PAGES (CapsuleSize));
break; break;
} }
// //
// good, load capsule buffer // good, load capsule buffer
// //

View File

@ -35,4 +35,3 @@ typedef struct {
} RECOVERY_CONFIG_DATA; } RECOVERY_CONFIG_DATA;
#endif #endif

View File

@ -47,7 +47,7 @@ ParseUpdateDataFile (
// //
// First process the data buffer and get all sections and entries // First process the data buffer and get all sections and entries
// //
Context = OpenIniFile(DataBuffer, BufferSize); Context = OpenIniFile (DataBuffer, BufferSize);
if (Context == NULL) { if (Context == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -55,26 +55,26 @@ ParseUpdateDataFile (
// //
// Now get NumOfUpdate // Now get NumOfUpdate
// //
Status = GetDecimalUintnFromDataFile( Status = GetDecimalUintnFromDataFile (
Context, Context,
"Head", "Head",
"NumOfUpdate", "NumOfUpdate",
&Num &Num
); );
if (EFI_ERROR(Status) || (Num == 0)) { if (EFI_ERROR (Status) || (Num == 0)) {
DEBUG((DEBUG_ERROR, "NumOfUpdate not found\n")); DEBUG ((DEBUG_ERROR, "NumOfUpdate not found\n"));
CloseIniFile(Context); CloseIniFile (Context);
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
ConfigHeader->NumOfUpdates = Num; ConfigHeader->NumOfUpdates = Num;
*UpdateArray = AllocateZeroPool ((sizeof (UPDATE_CONFIG_DATA) * Num)); *UpdateArray = AllocateZeroPool ((sizeof (UPDATE_CONFIG_DATA) * Num));
if (*UpdateArray == NULL) { if (*UpdateArray == NULL) {
CloseIniFile(Context); CloseIniFile (Context);
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
for (Index = 0 ; Index < ConfigHeader->NumOfUpdates ; Index++) { for (Index = 0; Index < ConfigHeader->NumOfUpdates; Index++) {
// //
// Get the section name of each update // Get the section name of each update
// //
@ -86,15 +86,15 @@ ParseUpdateDataFile (
Index, Index,
0 0
); );
Status = GetStringFromDataFile( Status = GetStringFromDataFile (
Context, Context,
"Head", "Head",
Entry, Entry,
&SectionName &SectionName
); );
if (EFI_ERROR(Status) || (SectionName == NULL)) { if (EFI_ERROR (Status) || (SectionName == NULL)) {
DEBUG((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry)); DEBUG ((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry));
CloseIniFile(Context); CloseIniFile (Context);
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -107,106 +107,110 @@ ParseUpdateDataFile (
// //
// FirmwareType // FirmwareType
// //
Status = GetDecimalUintnFromDataFile( Status = GetDecimalUintnFromDataFile (
Context, Context,
SectionName, SectionName,
"FirmwareType", "FirmwareType",
&Num &Num
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
CloseIniFile(Context); CloseIniFile (Context);
DEBUG((DEBUG_ERROR, "[%d] FirmwareType not found\n", Index)); DEBUG ((DEBUG_ERROR, "[%d] FirmwareType not found\n", Index));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
(*UpdateArray)[Index].FirmwareType = (PLATFORM_FIRMWARE_TYPE) Num;
(*UpdateArray)[Index].FirmwareType = (PLATFORM_FIRMWARE_TYPE)Num;
// //
// AddressType // AddressType
// //
Status = GetDecimalUintnFromDataFile( Status = GetDecimalUintnFromDataFile (
Context, Context,
SectionName, SectionName,
"AddressType", "AddressType",
&Num &Num
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
CloseIniFile(Context); CloseIniFile (Context);
DEBUG((DEBUG_ERROR, "[%d] AddressType not found\n", Index)); DEBUG ((DEBUG_ERROR, "[%d] AddressType not found\n", Index));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
(*UpdateArray)[Index].AddressType = (FLASH_ADDRESS_TYPE) Num;
(*UpdateArray)[Index].AddressType = (FLASH_ADDRESS_TYPE)Num;
// //
// BaseAddress // BaseAddress
// //
Status = GetHexUint64FromDataFile( Status = GetHexUint64FromDataFile (
Context, Context,
SectionName, SectionName,
"BaseAddress", "BaseAddress",
&Num64 &Num64
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
CloseIniFile(Context); CloseIniFile (Context);
DEBUG((DEBUG_ERROR, "[%d] BaseAddress not found\n", Index)); DEBUG ((DEBUG_ERROR, "[%d] BaseAddress not found\n", Index));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
(*UpdateArray)[Index].BaseAddress = (EFI_PHYSICAL_ADDRESS) Num64;
(*UpdateArray)[Index].BaseAddress = (EFI_PHYSICAL_ADDRESS)Num64;
// //
// FileGuid // FileGuid
// //
Status = GetGuidFromDataFile( Status = GetGuidFromDataFile (
Context, Context,
SectionName, SectionName,
"FileGuid", "FileGuid",
&FileGuid &FileGuid
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
CloseIniFile(Context); CloseIniFile (Context);
DEBUG((DEBUG_ERROR, "[%d] FileGuid not found\n", Index)); DEBUG ((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
CopyGuid(&((*UpdateArray)[Index].FileGuid), &FileGuid); CopyGuid (&((*UpdateArray)[Index].FileGuid), &FileGuid);
// //
// Length // Length
// //
Status = GetHexUintnFromDataFile( Status = GetHexUintnFromDataFile (
Context, Context,
SectionName, SectionName,
"Length", "Length",
&Num &Num
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
CloseIniFile(Context); CloseIniFile (Context);
DEBUG((DEBUG_ERROR, "[%d] Length not found\n", Index)); DEBUG ((DEBUG_ERROR, "[%d] Length not found\n", Index));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
(*UpdateArray)[Index].Length = (UINTN) Num;
(*UpdateArray)[Index].Length = (UINTN)Num;
// //
// ImageOffset // ImageOffset
// //
Status = GetHexUintnFromDataFile( Status = GetHexUintnFromDataFile (
Context, Context,
SectionName, SectionName,
"ImageOffset", "ImageOffset",
&Num &Num
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
CloseIniFile(Context); CloseIniFile (Context);
DEBUG((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index)); DEBUG ((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
(*UpdateArray)[Index].ImageOffset = (UINTN) Num;
(*UpdateArray)[Index].ImageOffset = (UINTN)Num;
} }
// //
// Now all configuration data got. Free those temporary buffers // Now all configuration data got. Free those temporary buffers
// //
CloseIniFile(Context); CloseIniFile (Context);
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -74,28 +74,29 @@ FmpGetImageInfo (
SYSTEM_FMP_PRIVATE_DATA *SystemFmpPrivate; SYSTEM_FMP_PRIVATE_DATA *SystemFmpPrivate;
EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR *ImageDescriptor; EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR *ImageDescriptor;
SystemFmpPrivate = SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(This); SystemFmpPrivate = SYSTEM_FMP_PRIVATE_DATA_FROM_FMP (This);
if(ImageInfoSize == NULL) { if (ImageInfoSize == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (*ImageInfoSize < sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * SystemFmpPrivate->DescriptorCount) { if (*ImageInfoSize < sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR) * SystemFmpPrivate->DescriptorCount) {
*ImageInfoSize = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * SystemFmpPrivate->DescriptorCount; *ImageInfoSize = sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR) * SystemFmpPrivate->DescriptorCount;
return EFI_BUFFER_TOO_SMALL; return EFI_BUFFER_TOO_SMALL;
} }
if (ImageInfo == NULL || if ((ImageInfo == NULL) ||
DescriptorVersion == NULL || (DescriptorVersion == NULL) ||
DescriptorCount == NULL || (DescriptorCount == NULL) ||
DescriptorSize == NULL || (DescriptorSize == NULL) ||
PackageVersion == NULL || (PackageVersion == NULL) ||
PackageVersionName == NULL) { (PackageVersionName == NULL))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
*ImageInfoSize = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * SystemFmpPrivate->DescriptorCount; *ImageInfoSize = sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR) * SystemFmpPrivate->DescriptorCount;
*DescriptorSize = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR); *DescriptorSize = sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR);
*DescriptorCount = SystemFmpPrivate->DescriptorCount; *DescriptorCount = SystemFmpPrivate->DescriptorCount;
*DescriptorVersion = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION; *DescriptorVersion = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;
@ -111,12 +112,14 @@ FmpGetImageInfo (
} else { } else {
ImageInfo->ImageIdName = NULL; ImageInfo->ImageIdName = NULL;
} }
ImageInfo->Version = ImageDescriptor->Version; ImageInfo->Version = ImageDescriptor->Version;
if (ImageDescriptor->VersionNameStringOffset != 0) { if (ImageDescriptor->VersionNameStringOffset != 0) {
ImageInfo->VersionName = (CHAR16 *)((UINTN)ImageDescriptor + ImageDescriptor->VersionNameStringOffset); ImageInfo->VersionName = (CHAR16 *)((UINTN)ImageDescriptor + ImageDescriptor->VersionNameStringOffset);
} else { } else {
ImageInfo->VersionName = NULL; ImageInfo->VersionName = NULL;
} }
ImageInfo->Size = (UINTN)ImageDescriptor->Size; ImageInfo->Size = (UINTN)ImageDescriptor->Size;
ImageInfo->AttributesSupported = ImageDescriptor->AttributesSupported; ImageInfo->AttributesSupported = ImageDescriptor->AttributesSupported;
ImageInfo->AttributesSetting = ImageDescriptor->AttributesSetting; ImageInfo->AttributesSetting = ImageDescriptor->AttributesSetting;
@ -132,7 +135,7 @@ FmpGetImageInfo (
*PackageVersion = ImageDescriptor->PackageVersion; *PackageVersion = ImageDescriptor->PackageVersion;
if (ImageDescriptor->PackageVersionNameStringOffset != 0) { if (ImageDescriptor->PackageVersionNameStringOffset != 0) {
*PackageVersionName = (VOID *)((UINTN)ImageDescriptor + ImageDescriptor->PackageVersionNameStringOffset); *PackageVersionName = (VOID *)((UINTN)ImageDescriptor + ImageDescriptor->PackageVersionNameStringOffset);
*PackageVersionName = AllocateCopyPool(StrSize(*PackageVersionName), *PackageVersionName); *PackageVersionName = AllocateCopyPool (StrSize (*PackageVersionName), *PackageVersionName);
} else { } else {
*PackageVersionName = NULL; *PackageVersionName = NULL;
} }
@ -317,24 +320,22 @@ InitializePrivateData (
SystemFmpPrivate->Signature = SYSTEM_FMP_PRIVATE_DATA_SIGNATURE; SystemFmpPrivate->Signature = SYSTEM_FMP_PRIVATE_DATA_SIGNATURE;
SystemFmpPrivate->Handle = NULL; SystemFmpPrivate->Handle = NULL;
SystemFmpPrivate->DescriptorCount = 1; SystemFmpPrivate->DescriptorCount = 1;
CopyMem(&SystemFmpPrivate->Fmp, &mFirmwareManagementProtocol, sizeof(EFI_FIRMWARE_MANAGEMENT_PROTOCOL)); CopyMem (&SystemFmpPrivate->Fmp, &mFirmwareManagementProtocol, sizeof (EFI_FIRMWARE_MANAGEMENT_PROTOCOL));
SystemFmpPrivate->ImageDescriptor = PcdGetPtr(PcdEdkiiSystemFirmwareImageDescriptor); SystemFmpPrivate->ImageDescriptor = PcdGetPtr (PcdEdkiiSystemFirmwareImageDescriptor);
SystemFmpPrivate->LastAttempt.LastAttemptVersion = 0x0; SystemFmpPrivate->LastAttempt.LastAttemptVersion = 0x0;
SystemFmpPrivate->LastAttempt.LastAttemptStatus = 0x0; SystemFmpPrivate->LastAttempt.LastAttemptStatus = 0x0;
VarSize = sizeof(SystemFmpPrivate->LastAttempt); VarSize = sizeof (SystemFmpPrivate->LastAttempt);
VarStatus = gRT->GetVariable( VarStatus = gRT->GetVariable (
SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME, SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME,
&gSystemFmpLastAttemptVariableGuid, &gSystemFmpLastAttemptVariableGuid,
NULL, NULL,
&VarSize, &VarSize,
&SystemFmpPrivate->LastAttempt &SystemFmpPrivate->LastAttempt
); );
DEBUG((DEBUG_INFO, "GetLastAttempt - %r\n", VarStatus)); DEBUG ((DEBUG_INFO, "GetLastAttempt - %r\n", VarStatus));
DEBUG((DEBUG_INFO, "GetLastAttempt Version - 0x%x, State - 0x%x\n", SystemFmpPrivate->LastAttempt.LastAttemptVersion, SystemFmpPrivate->LastAttempt.LastAttemptStatus)); DEBUG ((DEBUG_INFO, "GetLastAttempt Version - 0x%x, State - 0x%x\n", SystemFmpPrivate->LastAttempt.LastAttemptVersion, SystemFmpPrivate->LastAttempt.LastAttemptStatus));
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -80,7 +80,6 @@ typedef struct _SYSTEM_FMP_PRIVATE_DATA SYSTEM_FMP_PRIVATE_DATA;
SYSTEM_FMP_PRIVATE_DATA_SIGNATURE \ SYSTEM_FMP_PRIVATE_DATA_SIGNATURE \
) )
// //
// Update data // Update data
// //
@ -108,7 +107,7 @@ typedef struct {
typedef struct { typedef struct {
UINTN Function; UINTN Function;
EFI_STATUS ReturnStatus; EFI_STATUS ReturnStatus;
//UINT8 Data[]; // UINT8 Data[];
} SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_HEAD; } SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_HEAD;
#define ABORT_REASON_MAX_SIZE 0x40 // UnicodeStringSize including final L'\0' #define ABORT_REASON_MAX_SIZE 0x40 // UnicodeStringSize including final L'\0'
@ -121,10 +120,9 @@ typedef struct {
UINTN AbortReasonSize; UINTN AbortReasonSize;
UINT32 LastAttemptVersion; UINT32 LastAttemptVersion;
UINT32 LastAttemptStatus; UINT32 LastAttemptStatus;
//UINT8 Data[AbortReasonMaxSize + ImageSize]; // UINT8 Data[AbortReasonMaxSize + ImageSize];
} SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_SET_IMAGE; } SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_SET_IMAGE;
/** /**
Returns information about the current firmware image(s) of the device. Returns information about the current firmware image(s) of the device.
@ -398,4 +396,3 @@ extern EFI_GUID mCurrentImageTypeId;
extern EFI_GUID gSystemFmpProtocolGuid; extern EFI_GUID gSystemFmpProtocolGuid;
#endif #endif

View File

@ -55,39 +55,39 @@ DispatchSystemFmpImages (
AuthenticatedImage = NULL; AuthenticatedImage = NULL;
AuthenticatedImageSize = 0; AuthenticatedImageSize = 0;
DEBUG((DEBUG_INFO, "DispatchSystemFmpImages\n")); DEBUG ((DEBUG_INFO, "DispatchSystemFmpImages\n"));
// //
// Verify // Verify
// //
Status = CapsuleAuthenticateSystemFirmware(Image, ImageSize, FALSE, LastAttemptVersion, LastAttemptStatus, &AuthenticatedImage, &AuthenticatedImageSize); Status = CapsuleAuthenticateSystemFirmware (Image, ImageSize, FALSE, LastAttemptVersion, LastAttemptStatus, &AuthenticatedImage, &AuthenticatedImageSize);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_INFO, "SystemFirmwareAuthenticateImage - %r\n", Status)); DEBUG ((DEBUG_INFO, "SystemFirmwareAuthenticateImage - %r\n", Status));
return Status; return Status;
} }
// //
// Get FV // Get FV
// //
Result = ExtractDriverFvImage(AuthenticatedImage, AuthenticatedImageSize, &DispatchFvImage, &DispatchFvImageSize); Result = ExtractDriverFvImage (AuthenticatedImage, AuthenticatedImageSize, &DispatchFvImage, &DispatchFvImageSize);
if (Result) { if (Result) {
DEBUG((DEBUG_INFO, "ExtractDriverFvImage\n")); DEBUG ((DEBUG_INFO, "ExtractDriverFvImage\n"));
// //
// Dispatch // Dispatch
// //
if (((EFI_FIRMWARE_VOLUME_HEADER *)DispatchFvImage)->FvLength == DispatchFvImageSize) { if (((EFI_FIRMWARE_VOLUME_HEADER *)DispatchFvImage)->FvLength == DispatchFvImageSize) {
FvImage = AllocatePages(EFI_SIZE_TO_PAGES(DispatchFvImageSize)); FvImage = AllocatePages (EFI_SIZE_TO_PAGES (DispatchFvImageSize));
if (FvImage != NULL) { if (FvImage != NULL) {
CopyMem(FvImage, DispatchFvImage, DispatchFvImageSize); CopyMem (FvImage, DispatchFvImage, DispatchFvImageSize);
Status = gDS->ProcessFirmwareVolume( Status = gDS->ProcessFirmwareVolume (
(VOID *)FvImage, (VOID *)FvImage,
(UINTN)FvImage->FvLength, (UINTN)FvImage->FvLength,
&FvProtocolHandle &FvProtocolHandle
); );
DEBUG((DEBUG_INFO, "ProcessFirmwareVolume - %r\n", Status)); DEBUG ((DEBUG_INFO, "ProcessFirmwareVolume - %r\n", Status));
if (!EFI_ERROR(Status)) { if (!EFI_ERROR (Status)) {
gDS->Dispatch(); gDS->Dispatch ();
DEBUG((DEBUG_INFO, "Dispatch Done\n")); DEBUG ((DEBUG_INFO, "Dispatch Done\n"));
} }
} }
} }
@ -159,64 +159,64 @@ FmpSetImage (
EFI_STATUS Status; EFI_STATUS Status;
EFI_STATUS VarStatus; EFI_STATUS VarStatus;
if (Image == NULL || ImageSize == 0 || AbortReason == NULL) { if ((Image == NULL) || (ImageSize == 0) || (AbortReason == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
SystemFmpPrivate = SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(This); SystemFmpPrivate = SYSTEM_FMP_PRIVATE_DATA_FROM_FMP (This);
*AbortReason = NULL; *AbortReason = NULL;
if (ImageIndex == 0 || ImageIndex > SystemFmpPrivate->DescriptorCount) { if ((ImageIndex == 0) || (ImageIndex > SystemFmpPrivate->DescriptorCount)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// //
// Process FV // Process FV
// //
Status = DispatchSystemFmpImages((VOID *)Image, ImageSize, &SystemFmpPrivate->LastAttempt.LastAttemptVersion, &SystemFmpPrivate->LastAttempt.LastAttemptStatus); Status = DispatchSystemFmpImages ((VOID *)Image, ImageSize, &SystemFmpPrivate->LastAttempt.LastAttemptVersion, &SystemFmpPrivate->LastAttempt.LastAttemptStatus);
DEBUG((DEBUG_INFO, "(Agent)SetImage - LastAttempt Version - 0x%x, State - 0x%x\n", SystemFmpPrivate->LastAttempt.LastAttemptVersion, SystemFmpPrivate->LastAttempt.LastAttemptStatus)); DEBUG ((DEBUG_INFO, "(Agent)SetImage - LastAttempt Version - 0x%x, State - 0x%x\n", SystemFmpPrivate->LastAttempt.LastAttemptVersion, SystemFmpPrivate->LastAttempt.LastAttemptStatus));
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
VarStatus = gRT->SetVariable( VarStatus = gRT->SetVariable (
SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME, SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME,
&gSystemFmpLastAttemptVariableGuid, &gSystemFmpLastAttemptVariableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof(SystemFmpPrivate->LastAttempt), sizeof (SystemFmpPrivate->LastAttempt),
&SystemFmpPrivate->LastAttempt &SystemFmpPrivate->LastAttempt
); );
DEBUG((DEBUG_INFO, "(Agent)SetLastAttempt - %r\n", VarStatus)); DEBUG ((DEBUG_INFO, "(Agent)SetLastAttempt - %r\n", VarStatus));
return Status; return Status;
} }
// //
// Pass Thru to System FMP Protocol on same handle as FMP Protocol // Pass Thru to System FMP Protocol on same handle as FMP Protocol
// //
Status = gBS->HandleProtocol( Status = gBS->HandleProtocol (
SystemFmpPrivate->Handle, SystemFmpPrivate->Handle,
&gSystemFmpProtocolGuid, &gSystemFmpProtocolGuid,
(VOID **)&SystemFmp (VOID **)&SystemFmp
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
Status = gBS->LocateProtocol ( Status = gBS->LocateProtocol (
&gSystemFmpProtocolGuid, &gSystemFmpProtocolGuid,
NULL, NULL,
(VOID **)&SystemFmp (VOID **)&SystemFmp
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_INFO, "(Agent)SetImage - SystemFmpProtocol - %r\n", Status)); DEBUG ((DEBUG_INFO, "(Agent)SetImage - SystemFmpProtocol - %r\n", Status));
SystemFmpPrivate->LastAttempt.LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT; SystemFmpPrivate->LastAttempt.LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
VarStatus = gRT->SetVariable( VarStatus = gRT->SetVariable (
SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME, SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME,
&gSystemFmpLastAttemptVariableGuid, &gSystemFmpLastAttemptVariableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof(SystemFmpPrivate->LastAttempt), sizeof (SystemFmpPrivate->LastAttempt),
&SystemFmpPrivate->LastAttempt &SystemFmpPrivate->LastAttempt
); );
DEBUG((DEBUG_INFO, "(Agent)SetLastAttempt - %r\n", VarStatus)); DEBUG ((DEBUG_INFO, "(Agent)SetLastAttempt - %r\n", VarStatus));
return Status; return Status;
} }
} }
return SystemFmp->SetImage(SystemFmp, ImageIndex, Image, ImageSize, VendorCode, Progress, AbortReason); return SystemFmp->SetImage (SystemFmp, ImageIndex, Image, ImageSize, VendorCode, Progress, AbortReason);
} }
/** /**
@ -239,14 +239,14 @@ SystemFirmwareReportMainDxe (
// //
// Initialize SystemFmpPrivateData // Initialize SystemFmpPrivateData
// //
mSystemFmpPrivate = AllocateZeroPool (sizeof(SYSTEM_FMP_PRIVATE_DATA)); mSystemFmpPrivate = AllocateZeroPool (sizeof (SYSTEM_FMP_PRIVATE_DATA));
if (mSystemFmpPrivate == NULL) { if (mSystemFmpPrivate == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
Status = InitializePrivateData(mSystemFmpPrivate); Status = InitializePrivateData (mSystemFmpPrivate);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
FreePool(mSystemFmpPrivate); FreePool (mSystemFmpPrivate);
mSystemFmpPrivate = NULL; mSystemFmpPrivate = NULL;
return Status; return Status;
} }
@ -261,7 +261,7 @@ SystemFirmwareReportMainDxe (
&mSystemFmpPrivate->Fmp &mSystemFmpPrivate->Fmp
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
FreePool(mSystemFmpPrivate); FreePool (mSystemFmpPrivate);
mSystemFmpPrivate = NULL; mSystemFmpPrivate = NULL;
return Status; return Status;
} }

View File

@ -74,13 +74,14 @@ PerformUpdate (
{ {
EFI_STATUS Status; EFI_STATUS Status;
DEBUG((DEBUG_INFO, "PlatformUpdate:")); DEBUG ((DEBUG_INFO, "PlatformUpdate:"));
DEBUG((DEBUG_INFO, " BaseAddress - 0x%lx,", ConfigData->BaseAddress)); DEBUG ((DEBUG_INFO, " BaseAddress - 0x%lx,", ConfigData->BaseAddress));
DEBUG((DEBUG_INFO, " ImageOffset - 0x%x,", ConfigData->ImageOffset)); DEBUG ((DEBUG_INFO, " ImageOffset - 0x%x,", ConfigData->ImageOffset));
DEBUG((DEBUG_INFO, " Legnth - 0x%x\n", ConfigData->Length)); DEBUG ((DEBUG_INFO, " Legnth - 0x%x\n", ConfigData->Length));
if (Progress != NULL) { if (Progress != NULL) {
Progress (StartPercentage); Progress (StartPercentage);
} }
Status = PerformFlashWriteWithProgress ( Status = PerformFlashWriteWithProgress (
ConfigData->FirmwareType, ConfigData->FirmwareType,
ConfigData->BaseAddress, ConfigData->BaseAddress,
@ -94,7 +95,8 @@ PerformUpdate (
if (Progress != NULL) { if (Progress != NULL) {
Progress (EndPercentage); Progress (EndPercentage);
} }
if (!EFI_ERROR(Status)) {
if (!EFI_ERROR (Status)) {
*LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS; *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;
if (ConfigData->FirmwareType == PlatformFirmwareTypeNvRam) { if (ConfigData->FirmwareType == PlatformFirmwareTypeNvRam) {
mNvRamUpdated = TRUE; mNvRamUpdated = TRUE;
@ -102,6 +104,7 @@ PerformUpdate (
} else { } else {
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL; *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
} }
return Status; return Status;
} }
@ -141,15 +144,16 @@ UpdateImage (
UINTN EndPercentage; UINTN EndPercentage;
if (ConfigImage == NULL) { if (ConfigImage == NULL) {
DEBUG((DEBUG_INFO, "PlatformUpdate (NoConfig):")); DEBUG ((DEBUG_INFO, "PlatformUpdate (NoConfig):"));
DEBUG((DEBUG_INFO, " BaseAddress - 0x%x,", 0)); DEBUG ((DEBUG_INFO, " BaseAddress - 0x%x,", 0));
DEBUG((DEBUG_INFO, " Length - 0x%x\n", SystemFirmwareImageSize)); DEBUG ((DEBUG_INFO, " Length - 0x%x\n", SystemFirmwareImageSize));
// ASSUME the whole System Firmware include NVRAM region. // ASSUME the whole System Firmware include NVRAM region.
StartPercentage = 0; StartPercentage = 0;
EndPercentage = 100; EndPercentage = 100;
if (Progress != NULL) { if (Progress != NULL) {
Progress (StartPercentage); Progress (StartPercentage);
} }
Status = PerformFlashWriteWithProgress ( Status = PerformFlashWriteWithProgress (
PlatformFirmwareTypeNvRam, PlatformFirmwareTypeNvRam,
0, 0,
@ -163,35 +167,38 @@ UpdateImage (
if (Progress != NULL) { if (Progress != NULL) {
Progress (EndPercentage); Progress (EndPercentage);
} }
if (!EFI_ERROR(Status)) {
if (!EFI_ERROR (Status)) {
*LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS; *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;
mNvRamUpdated = TRUE; mNvRamUpdated = TRUE;
} else { } else {
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL; *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
} }
return Status; return Status;
} }
DEBUG((DEBUG_INFO, "PlatformUpdate (With Config):\n")); DEBUG ((DEBUG_INFO, "PlatformUpdate (With Config):\n"));
ConfigData = NULL; ConfigData = NULL;
ZeroMem (&ConfigHeader, sizeof(ConfigHeader)); ZeroMem (&ConfigHeader, sizeof (ConfigHeader));
Status = ParseUpdateDataFile ( Status = ParseUpdateDataFile (
ConfigImage, ConfigImage,
ConfigImageSize, ConfigImageSize,
&ConfigHeader, &ConfigHeader,
&ConfigData &ConfigData
); );
DEBUG((DEBUG_INFO, "ParseUpdateDataFile - %r\n", Status)); DEBUG ((DEBUG_INFO, "ParseUpdateDataFile - %r\n", Status));
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL; *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
DEBUG((DEBUG_INFO, "ConfigHeader.NumOfUpdates - 0x%x\n", ConfigHeader.NumOfUpdates));
DEBUG((DEBUG_INFO, "PcdEdkiiSystemFirmwareFileGuid - %g\n", PcdGetPtr(PcdEdkiiSystemFirmwareFileGuid))); DEBUG ((DEBUG_INFO, "ConfigHeader.NumOfUpdates - 0x%x\n", ConfigHeader.NumOfUpdates));
DEBUG ((DEBUG_INFO, "PcdEdkiiSystemFirmwareFileGuid - %g\n", PcdGetPtr (PcdEdkiiSystemFirmwareFileGuid)));
TotalSize = 0; TotalSize = 0;
for (Index = 0; Index < ConfigHeader.NumOfUpdates; Index++) { for (Index = 0; Index < ConfigHeader.NumOfUpdates; Index++) {
if (CompareGuid(&ConfigData[Index].FileGuid, PcdGetPtr(PcdEdkiiSystemFirmwareFileGuid))) { if (CompareGuid (&ConfigData[Index].FileGuid, PcdGetPtr (PcdEdkiiSystemFirmwareFileGuid))) {
TotalSize = TotalSize + ConfigData[Index].Length; TotalSize = TotalSize + ConfigData[Index].Length;
} }
} }
@ -200,8 +207,8 @@ UpdateImage (
Index = 0; Index = 0;
UpdateConfigData = ConfigData; UpdateConfigData = ConfigData;
while (Index < ConfigHeader.NumOfUpdates) { while (Index < ConfigHeader.NumOfUpdates) {
if (CompareGuid(&UpdateConfigData->FileGuid, PcdGetPtr(PcdEdkiiSystemFirmwareFileGuid))) { if (CompareGuid (&UpdateConfigData->FileGuid, PcdGetPtr (PcdEdkiiSystemFirmwareFileGuid))) {
DEBUG((DEBUG_INFO, "FileGuid - %g (processing)\n", &UpdateConfigData->FileGuid)); DEBUG ((DEBUG_INFO, "FileGuid - %g (processing)\n", &UpdateConfigData->FileGuid));
StartPercentage = (BytesWritten * 100) / TotalSize; StartPercentage = (BytesWritten * 100) / TotalSize;
EndPercentage = ((BytesWritten + UpdateConfigData->Length) * 100) / TotalSize; EndPercentage = ((BytesWritten + UpdateConfigData->Length) * 100) / TotalSize;
Status = PerformUpdate ( Status = PerformUpdate (
@ -222,7 +229,7 @@ UpdateImage (
break; break;
} }
} else { } else {
DEBUG((DEBUG_INFO, "FileGuid - %g (ignored)\n", &UpdateConfigData->FileGuid)); DEBUG ((DEBUG_INFO, "FileGuid - %g (ignored)\n", &UpdateConfigData->FileGuid));
} }
BytesWritten += UpdateConfigData->Length; BytesWritten += UpdateConfigData->Length;
@ -269,27 +276,27 @@ SystemFirmwareAuthenticatedUpdate (
AuthenticatedImage = NULL; AuthenticatedImage = NULL;
AuthenticatedImageSize = 0; AuthenticatedImageSize = 0;
DEBUG((DEBUG_INFO, "SystemFirmwareAuthenticatedUpdate...\n")); DEBUG ((DEBUG_INFO, "SystemFirmwareAuthenticatedUpdate...\n"));
Status = CapsuleAuthenticateSystemFirmware(Image, ImageSize, FALSE, LastAttemptVersion, LastAttemptStatus, &AuthenticatedImage, &AuthenticatedImageSize); Status = CapsuleAuthenticateSystemFirmware (Image, ImageSize, FALSE, LastAttemptVersion, LastAttemptStatus, &AuthenticatedImage, &AuthenticatedImageSize);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_INFO, "SystemFirmwareAuthenticateImage - %r\n", Status)); DEBUG ((DEBUG_INFO, "SystemFirmwareAuthenticateImage - %r\n", Status));
return Status; return Status;
} }
DEBUG((DEBUG_INFO, "ExtractSystemFirmwareImage ...\n")); DEBUG ((DEBUG_INFO, "ExtractSystemFirmwareImage ...\n"));
ExtractSystemFirmwareImage(AuthenticatedImage, AuthenticatedImageSize, &SystemFirmwareImage, &SystemFirmwareImageSize); ExtractSystemFirmwareImage (AuthenticatedImage, AuthenticatedImageSize, &SystemFirmwareImage, &SystemFirmwareImageSize);
DEBUG((DEBUG_INFO, "ExtractConfigImage ...\n")); DEBUG ((DEBUG_INFO, "ExtractConfigImage ...\n"));
ExtractConfigImage(AuthenticatedImage, AuthenticatedImageSize, &ConfigImage, &ConfigImageSize); ExtractConfigImage (AuthenticatedImage, AuthenticatedImageSize, &ConfigImage, &ConfigImageSize);
DEBUG((DEBUG_INFO, "UpdateImage ...\n")); DEBUG ((DEBUG_INFO, "UpdateImage ...\n"));
Status = UpdateImage(SystemFirmwareImage, SystemFirmwareImageSize, ConfigImage, ConfigImageSize, LastAttemptVersion, LastAttemptStatus, Progress); Status = UpdateImage (SystemFirmwareImage, SystemFirmwareImageSize, ConfigImage, ConfigImageSize, LastAttemptVersion, LastAttemptStatus, Progress);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_INFO, "UpdateImage - %r\n", Status)); DEBUG ((DEBUG_INFO, "UpdateImage - %r\n", Status));
return Status; return Status;
} }
DEBUG((DEBUG_INFO, "SystemFirmwareAuthenticatedUpdate Done\n")); DEBUG ((DEBUG_INFO, "SystemFirmwareAuthenticatedUpdate Done\n"));
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -321,7 +328,7 @@ GetVariableHook (
OUT VOID *Data OUT VOID *Data
) )
{ {
DEBUG((DEBUG_INFO, "GetVariableHook - %S, %g\n", VariableName, VendorGuid)); DEBUG ((DEBUG_INFO, "GetVariableHook - %S, %g\n", VariableName, VendorGuid));
return EFI_NOT_AVAILABLE_YET; return EFI_NOT_AVAILABLE_YET;
} }
@ -347,7 +354,7 @@ GetNextVariableNameHook (
IN OUT EFI_GUID *VendorGuid IN OUT EFI_GUID *VendorGuid
) )
{ {
DEBUG((DEBUG_INFO, "GetNextVariableNameHook - %S, %g\n", VariableName, VendorGuid)); DEBUG ((DEBUG_INFO, "GetNextVariableNameHook - %S, %g\n", VariableName, VendorGuid));
return EFI_NOT_AVAILABLE_YET; return EFI_NOT_AVAILABLE_YET;
} }
@ -379,7 +386,7 @@ SetVariableHook (
IN VOID *Data IN VOID *Data
) )
{ {
DEBUG((DEBUG_INFO, "SetVariableHook - %S, %g, 0x%x (0x%x)\n", VariableName, VendorGuid, Attributes, DataSize)); DEBUG ((DEBUG_INFO, "SetVariableHook - %S, %g, 0x%x (0x%x)\n", VariableName, VendorGuid, Attributes, DataSize));
return EFI_NOT_AVAILABLE_YET; return EFI_NOT_AVAILABLE_YET;
} }
@ -408,7 +415,7 @@ QueryVariableInfoHook (
OUT UINT64 *MaximumVariableSize OUT UINT64 *MaximumVariableSize
) )
{ {
DEBUG((DEBUG_INFO, "QueryVariableInfoHook - 0x%x\n", Attributes)); DEBUG ((DEBUG_INFO, "QueryVariableInfoHook - 0x%x\n", Attributes));
return EFI_NOT_AVAILABLE_YET; return EFI_NOT_AVAILABLE_YET;
} }
@ -474,19 +481,19 @@ FmpSetImage (
EFI_STATUS VarStatus; EFI_STATUS VarStatus;
SYSTEM_FMP_PRIVATE_DATA *SystemFmpPrivate; SYSTEM_FMP_PRIVATE_DATA *SystemFmpPrivate;
if (Image == NULL || ImageSize == 0 || AbortReason == NULL) { if ((Image == NULL) || (ImageSize == 0) || (AbortReason == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
SystemFmpPrivate = SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(This); SystemFmpPrivate = SYSTEM_FMP_PRIVATE_DATA_FROM_FMP (This);
*AbortReason = NULL; *AbortReason = NULL;
if (ImageIndex == 0 || ImageIndex > SystemFmpPrivate->DescriptorCount) { if ((ImageIndex == 0) || (ImageIndex > SystemFmpPrivate->DescriptorCount)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
Status = SystemFirmwareAuthenticatedUpdate((VOID *)Image, ImageSize, &SystemFmpPrivate->LastAttempt.LastAttemptVersion, &SystemFmpPrivate->LastAttempt.LastAttemptStatus, Progress); Status = SystemFirmwareAuthenticatedUpdate ((VOID *)Image, ImageSize, &SystemFmpPrivate->LastAttempt.LastAttemptVersion, &SystemFmpPrivate->LastAttempt.LastAttemptStatus, Progress);
DEBUG((DEBUG_INFO, "SetImage - LastAttempt Version - 0x%x, State - 0x%x\n", SystemFmpPrivate->LastAttempt.LastAttemptVersion, SystemFmpPrivate->LastAttempt.LastAttemptStatus)); DEBUG ((DEBUG_INFO, "SetImage - LastAttempt Version - 0x%x, State - 0x%x\n", SystemFmpPrivate->LastAttempt.LastAttemptVersion, SystemFmpPrivate->LastAttempt.LastAttemptStatus));
// //
// If NVRAM is updated, we should no longer touch variable services, because // If NVRAM is updated, we should no longer touch variable services, because
@ -501,20 +508,20 @@ FmpSetImage (
gRT->Hdr.CRC32 = 0; gRT->Hdr.CRC32 = 0;
gBS->CalculateCrc32 ( gBS->CalculateCrc32 (
(UINT8 *) &gRT->Hdr, (UINT8 *)&gRT->Hdr,
gRT->Hdr.HeaderSize, gRT->Hdr.HeaderSize,
&gRT->Hdr.CRC32 &gRT->Hdr.CRC32
); );
} }
VarStatus = gRT->SetVariable( VarStatus = gRT->SetVariable (
SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME, SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME,
&gSystemFmpLastAttemptVariableGuid, &gSystemFmpLastAttemptVariableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof(SystemFmpPrivate->LastAttempt), sizeof (SystemFmpPrivate->LastAttempt),
&SystemFmpPrivate->LastAttempt &SystemFmpPrivate->LastAttempt
); );
DEBUG((DEBUG_INFO, "SetLastAttempt - %r\n", VarStatus)); DEBUG ((DEBUG_INFO, "SetLastAttempt - %r\n", VarStatus));
return Status; return Status;
} }
@ -621,6 +628,7 @@ GetFmpImageDescriptors (
if (FmpImageInfoBuf != NULL) { if (FmpImageInfoBuf != NULL) {
FreePool (FmpImageInfoBuf); FreePool (FmpImageInfoBuf);
} }
return NULL; return NULL;
} }
@ -695,14 +703,17 @@ FindMatchingFmpHandles (
break; break;
} }
} }
if (MatchFound) { if (MatchFound) {
break; break;
} }
// //
// Increment the buffer pointer ahead by the size of the descriptor // Increment the buffer pointer ahead by the size of the descriptor
// //
FmpImageInfoBuf = (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)(((UINT8 *)FmpImageInfoBuf) + DescriptorSize); FmpImageInfoBuf = (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)(((UINT8 *)FmpImageInfoBuf) + DescriptorSize);
} }
if (MatchFound) { if (MatchFound) {
HandleBuffer[*HandleCount] = HandleBuffer[Index]; HandleBuffer[*HandleCount] = HandleBuffer[Index];
(*HandleCount)++; (*HandleCount)++;
@ -719,6 +730,7 @@ FindMatchingFmpHandles (
FreePool (HandleBuffer); FreePool (HandleBuffer);
return NULL; return NULL;
} }
return HandleBuffer; return HandleBuffer;
} }
@ -752,7 +764,7 @@ UninstallMatchingSystemFmpProtocols (
DEBUG ((DEBUG_INFO, "SystemFirmwareUpdateDxe: Found %d matching System FMP instances\n", HandleCount)); DEBUG ((DEBUG_INFO, "SystemFirmwareUpdateDxe: Found %d matching System FMP instances\n", HandleCount));
for (Index = 0; Index < HandleCount; Index++) { for (Index = 0; Index < HandleCount; Index++) {
Status = gBS->HandleProtocol( Status = gBS->HandleProtocol (
HandleBuffer[Index], HandleBuffer[Index],
&gSystemFmpProtocolGuid, &gSystemFmpProtocolGuid,
(VOID **)&SystemFmp (VOID **)&SystemFmp
@ -760,6 +772,7 @@ UninstallMatchingSystemFmpProtocols (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
} }
DEBUG ((DEBUG_INFO, "SystemFirmwareUpdateDxe: Uninstall SystemFmp produced by another capsule\n")); DEBUG ((DEBUG_INFO, "SystemFirmwareUpdateDxe: Uninstall SystemFmp produced by another capsule\n"));
Status = gBS->UninstallProtocolInterface ( Status = gBS->UninstallProtocolInterface (
HandleBuffer[Index], HandleBuffer[Index],
@ -772,6 +785,7 @@ UninstallMatchingSystemFmpProtocols (
return Status; return Status;
} }
} }
if (HandleBuffer != NULL) { if (HandleBuffer != NULL) {
FreePool (HandleBuffer); FreePool (HandleBuffer);
} }