X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=FmpDevicePkg%2FFmpDxe%2FFmpDxe.c;h=3794ac5008f95ecc51cb881540e745e62fa3782e;hp=69b6cb7d4c0d957bb4343a8932cf5cd094a29385;hb=27e42bf61bb27a61b5b4dd053c6bc219c73c4cc8;hpb=4e61b8d06b470cc7e4c60c975ec3b984f93642a1 diff --git a/FmpDevicePkg/FmpDxe/FmpDxe.c b/FmpDevicePkg/FmpDxe/FmpDxe.c index 69b6cb7d4c..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; /** @@ -222,6 +229,7 @@ GetLowestSupportedVersion ( // // Check the FmpDeviceLib // + DeviceLibLowestSupportedVersion = DEFAULT_LOWESTSUPPORTEDVERSION; Status = FmpDeviceGetLowestSupportedVersion (&DeviceLibLowestSupportedVersion); if (EFI_ERROR (Status)) { DeviceLibLowestSupportedVersion = DEFAULT_LOWESTSUPPORTEDVERSION; @@ -466,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. @@ -480,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 @@ -497,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; @@ -523,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: @@ -629,7 +636,7 @@ GetAllHeaderSize ( @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 @@ -639,7 +646,7 @@ CheckTheImage ( IN UINT8 ImageIndex, IN CONST VOID *Image, IN UINTN ImageSize, - OUT UINT32 *ImageUpdateable + OUT UINT32 *ImageUpdatable ) { EFI_STATUS Status; @@ -670,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; } @@ -679,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; } @@ -760,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; } @@ -778,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; } @@ -792,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; } @@ -803,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; } @@ -823,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)); } @@ -875,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 @@ -899,6 +906,8 @@ SetTheImage ( UINT32 AllHeaderSize; UINT32 IncommingFwVersion; UINT32 LastAttemptStatus; + UINT32 Version; + UINT32 LowestSupportedVersion; Status = EFI_SUCCESS; Updateable = 0; @@ -919,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; } @@ -1093,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); } @@ -1102,21 +1111,13 @@ 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; @@ -1129,6 +1130,12 @@ cleanup: Progress (100); } + // + // Need repopulate after SetImage is called to + // update LastAttemptVersion and LastAttemptStatus. + // + mDescriptorPopulated = FALSE; + return Status; } @@ -1206,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