summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Library
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2019-04-20 12:34:54 +0200
committerArd Biesheuvel <ard.biesheuvel@linaro.org>2019-04-23 18:15:00 +0200
commit2c0d39ac4704b76b7efb67b0aee23c2e78045cbc (patch)
treeadad51bf3ed89cb0e0440041ac12ad41dd99ae3c /MdeModulePkg/Library
parent40ffb6dc635d0848e6a1ed48b0819d2e5d177069 (diff)
MdeModulePkg/DxeCapsuleLibFmp: clone ESRT for runtime access
The DxeCapsuleLibFmp code accesses the ESRT table to decide whether a certain capsule is an FMP capsule. Since the UEFI spec mandates that the ESRT resides in EfiBootServicesData memory, this results in problems at OS runtime, since the firmware implementation itself cannot access memory that has not been virtually remapped. So let's take a private copy of the ESRT at ReadyToBoot, and store it in EfiRuntimeServicesData memory. The ESRT's size is order 10s of bytes so the memory footprint is going to be negligigble. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Acked-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Diffstat (limited to 'MdeModulePkg/Library')
-rw-r--r--MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c59
-rw-r--r--MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf1
2 files changed, 52 insertions, 8 deletions
diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
index 602921d13c..f94044a409 100644
--- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
+++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
@@ -23,6 +23,7 @@
extern EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable;
extern BOOLEAN mIsVirtualAddrConverted;
EFI_EVENT mDxeRuntimeCapsuleLibVirtualAddressChangeEvent = NULL;
+EFI_EVENT mDxeRuntimeCapsuleLibReadyToBootEvent = NULL;
/**
Convert EsrtTable physical address to virtual address.
@@ -38,8 +39,28 @@ DxeCapsuleLibVirtualAddressChangeEvent (
IN VOID *Context
)
{
- UINTN Index;
- EFI_CONFIGURATION_TABLE *ConfigEntry;
+ gRT->ConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mEsrtTable);
+ mIsVirtualAddrConverted = TRUE;
+}
+
+/**
+ Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT.
+
+ @param[in] Event The Event that is being processed.
+ @param[in] Context The Event Context.
+
+**/
+STATIC
+VOID
+EFIAPI
+DxeCapsuleLibReadyToBootEventNotify (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ UINTN Index;
+ EFI_CONFIGURATION_TABLE *ConfigEntry;
+ EFI_SYSTEM_RESOURCE_TABLE *EsrtTable;
//
// Get Esrt table first
@@ -59,16 +80,19 @@ DxeCapsuleLibVirtualAddressChangeEvent (
//
// Search Esrt to check given capsule is qualified
//
- mEsrtTable = (EFI_SYSTEM_RESOURCE_TABLE *) ConfigEntry->VendorTable;
+ EsrtTable = (EFI_SYSTEM_RESOURCE_TABLE *) ConfigEntry->VendorTable;
+
+ mEsrtTable = AllocateRuntimeCopyPool (
+ sizeof (EFI_SYSTEM_RESOURCE_TABLE) +
+ EsrtTable->FwResourceCount * sizeof (EFI_SYSTEM_RESOURCE_ENTRY),
+ EsrtTable);
+ ASSERT (mEsrtTable != NULL);
//
- // Update protocol pointer to Esrt Table.
+ // Set FwResourceCountMax to a sane value.
//
- gRT->ConvertPointer (0x00, (VOID**) &(mEsrtTable));
+ mEsrtTable->FwResourceCountMax = mEsrtTable->FwResourceCount;
}
-
- mIsVirtualAddrConverted = TRUE;
-
}
/**
@@ -101,6 +125,19 @@ DxeRuntimeCapsuleLibConstructor (
);
ASSERT_EFI_ERROR (Status);
+ //
+ // Register notify function to cache the FMP capsule GUIDs at ReadyToBoot.
+ //
+ Status = gBS->CreateEventEx (
+ EVT_NOTIFY_SIGNAL,
+ TPL_CALLBACK,
+ DxeCapsuleLibReadyToBootEventNotify,
+ NULL,
+ &gEfiEventReadyToBootGuid,
+ &mDxeRuntimeCapsuleLibReadyToBootEvent
+ );
+ ASSERT_EFI_ERROR (Status);
+
return EFI_SUCCESS;
}
@@ -127,5 +164,11 @@ DxeRuntimeCapsuleLibDestructor (
Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibVirtualAddressChangeEvent);
ASSERT_EFI_ERROR (Status);
+ //
+ // Close the ReadyToBoot event.
+ //
+ Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibReadyToBootEvent);
+ ASSERT_EFI_ERROR (Status);
+
return EFI_SUCCESS;
}
diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf
index 700d0d5dcd..2c93e68700 100644
--- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf
+++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf
@@ -66,6 +66,7 @@
gEfiCapsuleReportGuid
gEfiCapsuleVendorGuid ## SOMETIMES_CONSUMES ## Variable:L"CapsuleUpdateData"
gEfiEndOfDxeEventGroupGuid ## CONSUMES ## Event
+ gEfiEventReadyToBootGuid ## CONSUMES ## Event
gEfiEventVirtualAddressChangeGuid ## CONSUMES ## Event
[Depex]