Skip to content

Commit

Permalink
StandaloneMmPkg: Introduce a PCD to disable shadow boot FV
Browse files Browse the repository at this point in the history
On some Arm platforms the boot firmware volume passed in the HOB
by the secure world firmware (TF-A) is never freed and is always
mapped as read-only.

On such platforms the heap memory can be saved by disabling the
shadow copy of the boot firmware volume. This is useful as on
some platforms the amount of memory available is limited.

Therefore, introduce a PCD PcdDisableShadowBfv that platforms
can configure to disable the shadow boot FV. This PCD is set to
FALSE by default.

Signed-off-by: Levi Yun <[email protected]>
  • Loading branch information
LeviYeoReum committed Jan 17, 2025
1 parent f0c87b9 commit c445148
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
42 changes: 32 additions & 10 deletions StandaloneMmPkg/Core/FwVol.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,36 @@ MmDispatchFvs (

DEBUG ((DEBUG_INFO, "%a: FV[%d] address - 0x%x\n", __func__, Index, FvHob.FirmwareVolume->BaseAddress));
DEBUG ((DEBUG_INFO, "%a: FV[%d] size - 0x%x\n", __func__, Index, FvHob.FirmwareVolume->Length));
Fv = AllocatePool (FvHob.FirmwareVolume->Length);
if (Fv == NULL) {
DEBUG ((DEBUG_ERROR, "Fail to allocate memory for Fv\n"));
CpuDeadLoop ();
return;

if (FvHob.FirmwareVolume->Length == 0x00) {
DEBUG ((
DEBUG_INFO,
"%a: Skip invalid FV[%d]- 0x%x/0x%x\n",
__func__,
Index,
FvHob.FirmwareVolume->BaseAddress,
FvHob.FirmwareVolume->Length
));
continue;
}

if (FixedPcdGetBool (PcdDisableShadowBfv)) {
Fv = (EFI_FIRMWARE_VOLUME_HEADER *)FvHob.FirmwareVolume->BaseAddress;
} else {
Fv = AllocatePool (FvHob.FirmwareVolume->Length);
if (Fv == NULL) {
DEBUG ((DEBUG_ERROR, "Fail to allocate memory for Fv\n"));
CpuDeadLoop ();
return;
}

CopyMem (
(VOID *)Fv,
(VOID *)(UINTN)FvHob.FirmwareVolume->BaseAddress,
FvHob.FirmwareVolume->Length
);
}

CopyMem (
(VOID *)Fv,
(VOID *)(UINTN)FvHob.FirmwareVolume->BaseAddress,
FvHob.FirmwareVolume->Length
);
MmCoreFfsFindMmDriver (Fv, 0);
mMmFv[Index++] = Fv;

Expand All @@ -307,6 +325,10 @@ MmFreeShadowedFvs (
{
UINTN Index;

if (FixedPcdGetBool (PcdDisableShadowBfv)) {
return;
}

for (Index = 0; Index < ARRAY_SIZE (mMmFv); Index++) {
if (mMmFv[Index] != NULL) {
FreePool (mMmFv[Index]);
Expand Down
1 change: 1 addition & 0 deletions StandaloneMmPkg/Core/StandaloneMmCore.inf
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
[Pcd]
gStandaloneMmPkgTokenSpaceGuid.PcdFwVolMmMaxEncapsulationDepth ##CONSUMES
gStandaloneMmPkgTokenSpaceGuid.PcdRestartMmDispatcherOnceMmEntryRegistered ##CONSUMES
gStandaloneMmPkgTokenSpaceGuid.PcdDisableShadowBfv ##CONSUMES

#
# This configuration fails for CLANGPDB, which does not support PIE in the GCC
Expand Down
7 changes: 7 additions & 0 deletions StandaloneMmPkg/StandaloneMmPkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
# @Prompt Maximum permitted FwVol section nesting depth (exclusive) in MM.
gStandaloneMmPkgTokenSpaceGuid.PcdFwVolMmMaxEncapsulationDepth|0x10|UINT32|0x00000001

## Option to disable shadow copy of boot firmware volume while loading drivers.
# This options is useful when the BFV is not located in the Flash area
# but is in the RAM instead and therefore no shadow copy is needed.
# TRUE - Disable shadow copy of the boot firmware volume.
# FALSE - Default. Make a shadow copy of the boot firmware volume.
gStandaloneMmPkgTokenSpaceGuid.PcdDisableShadowBfv|FALSE|BOOLEAN|0x00000003

[PcdsFeatureFlag]
## Indicates if restart MM Dispatcher once MM Entry Point is registered.<BR><BR>
# TRUE - Restart MM Dispatcher once MM Entry Point is registered.<BR>
Expand Down

0 comments on commit c445148

Please sign in to comment.