Skip to content

Commit

Permalink
AmpereAltraPkg: Fix failed to update firmware via Capsule
Browse files Browse the repository at this point in the history
Capsule update is relying on the gEfiMmCommunication2Protocol, meanwhile
some old firmwares might just expose gEfiMmCommunicationProtocol. This
change is to address this issue by trying to locate both protocols and
doing the update via the first found protocol.

Signed-off-by: Vu Nguyen <Vu@amperecomputing.com>
  • Loading branch information
vu-ampere committed Apr 22, 2022
1 parent 69a9a68 commit 2afd172
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#include <Library/UefiBootServicesTableLib.h>
#include <Protocol/MmCommunication2.h>

EFI_MM_COMMUNICATION2_PROTOCOL *mMmCommunication = NULL;
EFI_MM_COMMUNICATION2_PROTOCOL *mMmCommunication2 = NULL;
EFI_MM_COMMUNICATION_PROTOCOL *mMmCommunication = NULL;

#define EFI_MM_MAX_PAYLOAD_U64_E 10
#define EFI_MM_MAX_PAYLOAD_SIZE (EFI_MM_MAX_PAYLOAD_U64_E * sizeof (UINT64))
Expand Down Expand Up @@ -127,16 +128,23 @@ MmFlashUpdate (
ImageSize
));

if (mMmCommunication == NULL) {
if (mMmCommunication2 == NULL && mMmCommunication == NULL) {
Status = gBS->LocateProtocol (
&gEfiMmCommunication2ProtocolGuid,
NULL,
(VOID **)&mMmCommunication
(VOID **)&mMmCommunication2
);

if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Can't locate gEfiMmCommunication2ProtocolGuid.\n", __FUNCTION__));
return Status;
Status = gBS->LocateProtocol (
&gEfiMmCommunicationProtocolGuid,
NULL,
(VOID **)&mMmCommunication
);

if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Can't locate MM Communication protocol.\n", __FUNCTION__));
return Status;
}
}
}

Expand All @@ -149,12 +157,23 @@ MmFlashUpdate (
UefiMmCreateSysFwuReq ((VOID *)&MmData, sizeof (MmData));

Size = sizeof (EFI_MM_COMM_HEADER_NOPAYLOAD) + sizeof (MmData);
Status = mMmCommunication->Communicate (
mMmCommunication,
(VOID *)&mEfiMmSysFwuReq,
(VOID *)&mEfiMmSysFwuReq,
&Size
);
if (mMmCommunication2 != NULL) {
Status = mMmCommunication2->Communicate (
mMmCommunication2,
(VOID *)&mEfiMmSysFwuReq,
(VOID *)&mEfiMmSysFwuReq,
&Size
);
} else if (mMmCommunication != NULL) {
Status = mMmCommunication->Communicate (
mMmCommunication,
(VOID *)&mEfiMmSysFwuReq,
&Size
);
} else {
return EFI_UNSUPPORTED;
}

if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

[Protocols]
gEfiMmCommunication2ProtocolGuid
gEfiMmCommunicationProtocolGuid

[Depex]
TRUE
gEfiMmCommunication2ProtocolGuid OR
gEfiMmCommunicationProtocolGuid

0 comments on commit 2afd172

Please sign in to comment.