From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web08.1693.1641328729179404542 for ; Tue, 04 Jan 2022 12:38:49 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=UROY/aKb; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from localhost.localdomain (c-73-27-179-174.hsd1.fl.comcast.net [73.27.179.174]) by linux.microsoft.com (Postfix) with ESMTPSA id DB67F20B7179; Tue, 4 Jan 2022 12:38:47 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DB67F20B7179 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1641328728; bh=jpNmJL3WA39fZWfAe2WKCuMPHiYZkzo81x2PzO2VQ3o=; h=From:To:Cc:Subject:Date:From; b=UROY/aKbXjtUSWFP/AAkklA57W6mLIZuSShHXHipdwuteH+7XEV5Yog55aN+1ThjJ Ptex9fn1+g5tsvXdW1VZdafWRsG3DjUs2i2VGRGl9JvrfzKD652/0gTaMykV53I0r2 9fRmrIB+dyt2KKchNHsEpyKu9nlidRsCZ7+ix2E4= From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Liming Gao , Michael D Kinney , Guomin Jiang , Wei6 Xu Subject: [PATCH v1 1/1] FmpDevicePkg/FmpDxe: Update FmpDeviceCheckImageWithStatus() handling Date: Tue, 4 Jan 2022 15:38:24 -0500 Message-Id: <20220104203824.2047-1-mikuback@linux.microsoft.com> X-Mailer: git-send-email 2.28.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Kubacki Update the logic handling last attempt status codes from FmpDeviceCheckImageWithStatus() implementations to account for cases when the function return status code is EFI_SUCCESS (since the image was checked successfully) but the ImageUpdatable value is not valid. In addition the following sentence is removed from the LastAttemptStatus parameter definition for FmpDeviceCheckImageWithStatus() since it can lead to confusion. The expected status code value range is sufficient to implement the library API. "This value will only be checked when this function returns an error." Cc: Liming Gao Cc: Michael D Kinney Cc: Guomin Jiang Cc: Wei6 Xu Signed-off-by: Michael Kubacki --- FmpDevicePkg/FmpDxe/FmpDxe.c | 23 ++++++++++++++= +----- FmpDevicePkg/Library/FmpDeviceLibNull/FmpDeviceLib.c | 3 +-- FmpDevicePkg/Include/Library/FmpDeviceLib.h | 3 +-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/FmpDevicePkg/FmpDxe/FmpDxe.c b/FmpDevicePkg/FmpDxe/FmpDxe.c index 197df28c8dd6..1e7ec4a09e16 100644 --- a/FmpDevicePkg/FmpDxe/FmpDxe.c +++ b/FmpDevicePkg/FmpDxe/FmpDxe.c @@ -1040,8 +1040,19 @@ CheckTheImageInternal ( // Status =3D FmpDeviceCheckImageWithStatus ((((UINT8 *)Image) + AllHeade= rSize), RawSize, ImageUpdatable, LastAttemptStatus); if (EFI_ERROR (Status)) { + // The image cannot be valid if an error occurred checking the image + if (*ImageUpdatable =3D=3D IMAGE_UPDATABLE_VALID) { + *ImageUpdatable =3D IMAGE_UPDATABLE_INVALID; + } + DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - FmpDeviceLib Che= ckImage failed. Status =3D %r\n", mImageIdName, Status)); + } =20 + // + // Only validate the library last attempt status code if the image is = not updatable. + // This specifically avoids converting LAST_ATTEMPT_STATUS_SUCCESS if = it set for an updatable image. + // + if (*ImageUpdatable !=3D IMAGE_UPDATABLE_VALID) { // // LastAttemptStatus returned from the device library should fall wi= thin the designated error range // [LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE, LAST_AT= TEMPT_STATUS_DEVICE_LIBRARY_MAX_ERROR_CODE_VALUE] @@ -1049,12 +1060,12 @@ CheckTheImageInternal ( if ((*LastAttemptStatus < LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERR= OR_CODE_VALUE) || (*LastAttemptStatus > LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MAX_ERR= OR_CODE_VALUE)) { - DEBUG ( - (DEBUG_ERROR, - "FmpDxe(%s): CheckTheImage() - LastAttemptStatus %d from FmpDev= iceCheckImageWithStatus() is invalid.\n", - mImageIdName, - *LastAttemptStatus) - ); + DEBUG (( + DEBUG_ERROR, + "FmpDxe(%s): CheckTheImage() - LastAttemptStatus %d from FmpDevi= ceCheckImageWithStatus() is invalid.\n", + mImageIdName, + *LastAttemptStatus + )); *LastAttemptStatus =3D LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL; } } diff --git a/FmpDevicePkg/Library/FmpDeviceLibNull/FmpDeviceLib.c b/FmpDe= vicePkg/Library/FmpDeviceLibNull/FmpDeviceLib.c index 2e5c17b2b0f9..82219e87a430 100644 --- a/FmpDevicePkg/Library/FmpDeviceLibNull/FmpDeviceLib.c +++ b/FmpDevicePkg/Library/FmpDeviceLibNull/FmpDeviceLib.c @@ -434,8 +434,7 @@ FmpDeviceCheckImage ( IMAGE_UPDATABLE_VALID_WITH_VENDOR_CO= DE @param[out] LastAttemptStatus A pointer to a UINT32 that holds the l= ast attempt status to report back to the ESRT tabl= e in case - of error. This value will only be chec= ked when this - function returns an error. + of error. =20 The return status code must fall in th= e range of LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN= _ERROR_CODE_VALUE to diff --git a/FmpDevicePkg/Include/Library/FmpDeviceLib.h b/FmpDevicePkg/I= nclude/Library/FmpDeviceLib.h index a14406abe8b5..f82ef64503fa 100644 --- a/FmpDevicePkg/Include/Library/FmpDeviceLib.h +++ b/FmpDevicePkg/Include/Library/FmpDeviceLib.h @@ -421,8 +421,7 @@ FmpDeviceCheckImage ( IMAGE_UPDATABLE_VALID_WITH_VENDOR_CO= DE @param[out] LastAttemptStatus A pointer to a UINT32 that holds the l= ast attempt status to report back to the ESRT tabl= e in case - of error. This value will only be chec= ked when this - function returns an error. + of error. =20 The return status code must fall in th= e range of LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN= _ERROR_CODE_VALUE to --=20 2.28.0.windows.1