X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=FmpDevicePkg%2FFmpDxe%2FFmpDxe.c;h=3794ac5008f95ecc51cb881540e745e62fa3782e;hp=c0c1383723fb4a53d68d9d9832290927c5f59c6f;hb=27e42bf61bb27a61b5b4dd053c6bc219c73c4cc8;hpb=e8619f82ce9522e573f5dd49bb2f2d516ae9ab1b diff --git a/FmpDevicePkg/FmpDxe/FmpDxe.c b/FmpDevicePkg/FmpDxe/FmpDxe.c index c0c1383723..3794ac5008 100644 --- a/FmpDevicePkg/FmpDxe/FmpDxe.c +++ b/FmpDevicePkg/FmpDxe/FmpDxe.c @@ -1,4 +1,4 @@ -/** @file +/** @file Produces a Firmware Management Protocol that supports updates to a firmware image stored in a firmware device with platform and firmware device specific information provided through PCDs and libraries. @@ -89,6 +89,13 @@ UINT64 mImageId = 0x1; CHAR16 *mVersionName = NULL; EFI_EVENT mFmpDeviceLockEvent; +// +// Indicates if an attempt has been made to lock a +// FLASH storage device by calling FmpDeviceLock(). +// A FLASH storage device may not support being locked, +// so this variable is set to TRUE even if FmpDeviceLock() +// returns an error. +// BOOLEAN mFmpDeviceLocked = FALSE; /** @@ -210,15 +217,19 @@ GetLowestSupportedVersion ( // Get the LowestSupportedVersion. // - DeviceLibLowestSupportedVersion = DEFAULT_LOWESTSUPPORTEDVERSION; - ReturnLsv = PcdGet32 (PcdFmpDeviceBuildTimeLowestSupportedVersion); if (!IsLowestSupportedVersionCheckRequired ()) { - return 1; + // + // Any Version can pass the 0 LowestSupportedVersion check. + // + return 0; } + ReturnLsv = PcdGet32 (PcdFmpDeviceBuildTimeLowestSupportedVersion); + // // Check the FmpDeviceLib // + DeviceLibLowestSupportedVersion = DEFAULT_LOWESTSUPPORTEDVERSION; Status = FmpDeviceGetLowestSupportedVersion (&DeviceLibLowestSupportedVersion); if (EFI_ERROR (Status)) { DeviceLibLowestSupportedVersion = DEFAULT_LOWESTSUPPORTEDVERSION; @@ -463,11 +474,11 @@ cleanup: This function allows a copy of the current firmware image to be created and saved. The saved copy could later been used, for example, in firmware image recovery or rollback. - @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance. - @param[in] ImageIndex A unique number identifying the firmware image(s) within the device. + @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance. + @param[in] ImageIndex A unique number identifying the firmware image(s) within the device. The number is between 1 and DescriptorCount. - @param[out] Image Points to the buffer where the current image is copied to. - @param[out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes. + @param[in, out] Image Points to the buffer where the current image is copied to. + @param[in, out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes. On return, points to the length of the image, in bytes. @retval EFI_SUCCESS The device was successfully updated with the new image. @@ -477,7 +488,7 @@ cleanup: @retval EFI_INVALID_PARAMETER The Image was NULL. @retval EFI_NOT_FOUND The current image is not copied to the buffer. @retval EFI_UNSUPPORTED The operation is not supported. - @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure. + @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure. **/ EFI_STATUS @@ -494,7 +505,16 @@ GetTheImage ( Status = EFI_SUCCESS; - if ((ImageSize == NULL)) { + // + // Check to make sure index is 1 (only 1 image for this device) + // + if (ImageIndex != 1) { + DEBUG ((DEBUG_ERROR, "FmpDxe: GetImage() - Image Index Invalid.\n")); + Status = EFI_INVALID_PARAMETER; + goto cleanup; + } + + if (ImageSize == NULL) { DEBUG ((DEBUG_ERROR, "FmpDxe: GetImage() - ImageSize Pointer Parameter is NULL.\n")); Status = EFI_INVALID_PARAMETER; goto cleanup; @@ -520,16 +540,6 @@ GetTheImage ( goto cleanup; } - // - // Check to make sure index is 1 (only 1 image for this device) - // - if (ImageIndex != 1) { - DEBUG ((DEBUG_ERROR, "FmpDxe: GetImage() - Image Index Invalid.\n")); - Status = EFI_INVALID_PARAMETER; - goto cleanup; - } - - Status = FmpDeviceGetImage (Image, ImageSize); cleanup: @@ -623,9 +633,10 @@ GetAllHeaderSize ( if available, additional information if the image is invalid. @retval EFI_SUCCESS The image was successfully checked. + @retval EFI_ABORTED The operation is aborted. @retval EFI_INVALID_PARAMETER The Image was NULL. @retval EFI_UNSUPPORTED The operation is not supported. - @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure. + @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure. **/ EFI_STATUS @@ -635,7 +646,7 @@ CheckTheImage ( IN UINT8 ImageIndex, IN CONST VOID *Image, IN UINTN ImageSize, - OUT UINT32 *ImageUpdateable + OUT UINT32 *ImageUpdatable ) { EFI_STATUS Status; @@ -666,8 +677,8 @@ CheckTheImage ( PopulateDescriptor(); } - if (ImageUpdateable == NULL) { - DEBUG ((DEBUG_ERROR, "FmpDxe: CheckImage() - ImageUpdateable Pointer Parameter is NULL.\n")); + if (ImageUpdatable == NULL) { + DEBUG ((DEBUG_ERROR, "FmpDxe: CheckImage() - ImageUpdatable Pointer Parameter is NULL.\n")); Status = EFI_INVALID_PARAMETER; goto cleanup; } @@ -675,14 +686,14 @@ CheckTheImage ( // //Set to valid and then if any tests fail it will update this flag. // - *ImageUpdateable = IMAGE_UPDATABLE_VALID; + *ImageUpdatable = IMAGE_UPDATABLE_VALID; if (Image == NULL) { DEBUG ((DEBUG_ERROR, "FmpDxe: CheckImage() - Image Pointer Parameter is NULL.\n")); // // not sure if this is needed // - *ImageUpdateable = IMAGE_UPDATABLE_INVALID; + *ImageUpdatable = IMAGE_UPDATABLE_INVALID; return EFI_INVALID_PARAMETER; } @@ -756,7 +767,7 @@ CheckTheImage ( // if (ImageIndex != 1) { DEBUG ((DEBUG_ERROR, "FmpDxe: CheckImage() - Image Index Invalid.\n")); - *ImageUpdateable = IMAGE_UPDATABLE_INVALID_TYPE; + *ImageUpdatable = IMAGE_UPDATABLE_INVALID_TYPE; Status = EFI_SUCCESS; goto cleanup; } @@ -774,7 +785,7 @@ CheckTheImage ( Status = GetFmpPayloadHeaderVersion (FmpPayloadHeader, FmpPayloadSize, &Version); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "FmpDxe: CheckTheImage() - GetFmpPayloadHeaderVersion failed %r.\n", Status)); - *ImageUpdateable = IMAGE_UPDATABLE_INVALID; + *ImageUpdatable = IMAGE_UPDATABLE_INVALID; Status = EFI_SUCCESS; goto cleanup; } @@ -788,7 +799,7 @@ CheckTheImage ( "FmpDxe: CheckTheImage() - Version Lower than lowest supported version. 0x%08X < 0x%08X\n", Version, mDesc.LowestSupportedImageVersion) ); - *ImageUpdateable = IMAGE_UPDATABLE_INVALID_OLD; + *ImageUpdatable = IMAGE_UPDATABLE_INVALID_OLD; Status = EFI_SUCCESS; goto cleanup; } @@ -799,7 +810,7 @@ CheckTheImage ( Status = GetFmpPayloadHeaderSize (FmpPayloadHeader, FmpPayloadSize, &FmpHeaderSize); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "FmpDxe: CheckTheImage() - GetFmpPayloadHeaderSize failed %r.\n", Status)); - *ImageUpdateable = IMAGE_UPDATABLE_INVALID; + *ImageUpdatable = IMAGE_UPDATABLE_INVALID; Status = EFI_SUCCESS; goto cleanup; } @@ -819,7 +830,7 @@ CheckTheImage ( // // FmpDeviceLib CheckImage function to do any specific checks // - Status = FmpDeviceCheckImage ((((UINT8 *)Image) + AllHeaderSize), RawSize, ImageUpdateable); + Status = FmpDeviceCheckImage ((((UINT8 *)Image) + AllHeaderSize), RawSize, ImageUpdatable); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "FmpDxe: CheckTheImage() - FmpDeviceLib CheckImage failed. Status = %r\n", Status)); } @@ -871,7 +882,7 @@ cleanup: @retval EFI_ABORTED The operation is aborted. @retval EFI_INVALID_PARAMETER The Image was NULL. @retval EFI_UNSUPPORTED The operation is not supported. - @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure. + @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure. **/ EFI_STATUS @@ -895,6 +906,8 @@ SetTheImage ( UINT32 AllHeaderSize; UINT32 IncommingFwVersion; UINT32 LastAttemptStatus; + UINT32 Version; + UINT32 LowestSupportedVersion; Status = EFI_SUCCESS; Updateable = 0; @@ -915,7 +928,7 @@ SetTheImage ( // if (mFmpDeviceLocked) { DEBUG ((DEBUG_ERROR, "FmpDxe: SetTheImage() - Device is already locked. Can't update.\n")); - Status = EFI_ACCESS_DENIED; + Status = EFI_UNSUPPORTED; goto cleanup; } @@ -1089,7 +1102,7 @@ SetTheImage ( // Update the version stored in variable // if (!mRuntimeVersionSupported) { - UINT32 Version = DEFAULT_VERSION; + Version = DEFAULT_VERSION; GetFmpPayloadHeaderVersion (FmpHeader, FmpPayloadSize, &Version); SetVersionInVariable (Version); } @@ -1098,30 +1111,30 @@ SetTheImage ( // Update lowest supported variable // { - UINT32 Version = DEFAULT_LOWESTSUPPORTEDVERSION; - GetFmpPayloadHeaderLowestSupportedVersion (FmpHeader, FmpPayloadSize, &Version); - SetLowestSupportedVersionInVariable (Version); + LowestSupportedVersion = DEFAULT_LOWESTSUPPORTEDVERSION; + GetFmpPayloadHeaderLowestSupportedVersion (FmpHeader, FmpPayloadSize, &LowestSupportedVersion); + SetLowestSupportedVersionInVariable (LowestSupportedVersion); } LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS; - // - // Set flag so the descriptor is repopulated - // This only applied to devices that do not require system reboot - // - if (!PcdGetBool (PcdFmpDeviceSystemResetRequired)) { - mDescriptorPopulated = FALSE; - } - cleanup: mProgressFunc = NULL; mProgressSupported = FALSE; SetLastAttemptStatusInVariable (LastAttemptStatus); + if (Progress != NULL) { + // + // Set progress to 100 after everything is done including recording Status. + // + Progress (100); + } + // - // Set progress to 100 after everything is done including recording Status. + // Need repopulate after SetImage is called to + // update LastAttemptVersion and LastAttemptStatus. // - Progress (100); + mDescriptorPopulated = FALSE; return Status; } @@ -1200,7 +1213,7 @@ GetPackageInfo ( @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value returned in PackageVersionNameMaxLen. @retval EFI_UNSUPPORTED The operation is not supported. - @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure. + @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure. **/ EFI_STATUS