MdeModulePkg/DxeCapsuleLibFmp: Capsule on Disk file name capsule

Enhance RelocateCapsuleToRam() to skip creation of the Capsule on Disk
file name capsule if PcdSupportUpdateCapsuleReset feature is not enabled.
This avoids an EFI_UNSUPPORTED return status from UpdateCapsule() when the
file name capsule is encountered and PcdSupportUpdateCapsuleReset is FALSE.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Signed-off-by: Bob Morgan <bobm@nvidia.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
This commit is contained in:
Bob Morgan 2021-11-03 04:40:23 +08:00 committed by mergify[bot]
parent c974257821
commit aab6bb3d32
2 changed files with 19 additions and 3 deletions

View File

@ -1739,6 +1739,7 @@ RelocateCapsuleToRam (
UINT8 *StringBuf; UINT8 *StringBuf;
UINTN StringSize; UINTN StringSize;
UINTN TotalStringSize; UINTN TotalStringSize;
UINTN CapsulesToProcess;
CapsuleOnDiskBuf = NULL; CapsuleOnDiskBuf = NULL;
BlockDescriptors = NULL; BlockDescriptors = NULL;
@ -1778,6 +1779,13 @@ RelocateCapsuleToRam (
TotalStringSize += StrSize (CapsuleOnDiskBuf[Index].FileInfo->FileName); TotalStringSize += StrSize (CapsuleOnDiskBuf[Index].FileInfo->FileName);
} }
// If Persist Across Reset isn't supported, skip the file name strings capsule
if (!FeaturePcdGet (PcdSupportUpdateCapsuleReset)) {
CapsulesToProcess = CapsuleOnDiskNum;
goto BuildGather;
}
CapsulesToProcess = CapsuleOnDiskNum + 1;
FileNameCapsule = AllocateZeroPool (sizeof (EFI_CAPSULE_HEADER) + TotalStringSize); FileNameCapsule = AllocateZeroPool (sizeof (EFI_CAPSULE_HEADER) + TotalStringSize);
if (FileNameCapsule == NULL) { if (FileNameCapsule == NULL) {
DEBUG ((DEBUG_ERROR, "Fail to allocate memory for name capsule.\n")); DEBUG ((DEBUG_ERROR, "Fail to allocate memory for name capsule.\n"));
@ -1804,18 +1812,23 @@ RelocateCapsuleToRam (
// //
// 3. Build Gather list for the capsules // 3. Build Gather list for the capsules
// //
Status = BuildGatherList (CapsuleBuffer, CapsuleSize, CapsuleOnDiskNum + 1, &BlockDescriptors); BuildGather:
Status = BuildGatherList (CapsuleBuffer, CapsuleSize, CapsulesToProcess, &BlockDescriptors);
if (EFI_ERROR (Status) || BlockDescriptors == NULL) { if (EFI_ERROR (Status) || BlockDescriptors == NULL) {
FreePool (CapsuleBuffer); FreePool (CapsuleBuffer);
FreePool (CapsuleSize); FreePool (CapsuleSize);
if (FileNameCapsule != NULL) {
FreePool (FileNameCapsule); FreePool (FileNameCapsule);
}
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
// //
// 4. Call UpdateCapsule() service // 4. Call UpdateCapsule() service
// //
Status = gRT->UpdateCapsule((EFI_CAPSULE_HEADER **) CapsuleBuffer, CapsuleOnDiskNum + 1, (UINTN) BlockDescriptors); Status = gRT->UpdateCapsule ((EFI_CAPSULE_HEADER **) CapsuleBuffer,
CapsulesToProcess,
(UINTN) BlockDescriptors);
return Status; return Status;
} }

View File

@ -68,6 +68,9 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdCodRelocationDevPath ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCodRelocationDevPath ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdCoDRelocationFileName ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCoDRelocationFileName ## CONSUMES
[FeaturePcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdSupportUpdateCapsuleReset ## CONSUMES
[Protocols] [Protocols]
gEsrtManagementProtocolGuid ## CONSUMES gEsrtManagementProtocolGuid ## CONSUMES
gEfiFirmwareManagementProtocolGuid ## CONSUMES gEfiFirmwareManagementProtocolGuid ## CONSUMES