summaryrefslogtreecommitdiff
path: root/MdePkg/Library/DxePiLib/DxePiLib.c
diff options
context:
space:
mode:
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>2007-09-24 11:38:43 +0000
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>2007-09-24 11:38:43 +0000
commitb0d803fe3e5c55a9a0c75bc90ccf40ebbbc9ffa3 (patch)
tree071d183f0cf4e1be4345e64f10a6228639187135 /MdePkg/Library/DxePiLib/DxePiLib.c
parentf6203b71926848e7b197ee99a3a86a487d7b334a (diff)
downloadedk2-platforms-b0d803fe3e5c55a9a0c75bc90ccf40ebbbc9ffa3.tar.xz
Merge branch of PI tree to main trunk
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3918 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg/Library/DxePiLib/DxePiLib.c')
-rw-r--r--MdePkg/Library/DxePiLib/DxePiLib.c220
1 files changed, 217 insertions, 3 deletions
diff --git a/MdePkg/Library/DxePiLib/DxePiLib.c b/MdePkg/Library/DxePiLib/DxePiLib.c
index 3261e08ade..32e0337c19 100644
--- a/MdePkg/Library/DxePiLib/DxePiLib.c
+++ b/MdePkg/Library/DxePiLib/DxePiLib.c
@@ -16,6 +16,7 @@
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
+#include <Library/PiLib.h>
#include <Protocol/FirmwareVolume2.h>
#include <Protocol/LoadedImage.h>
@@ -40,7 +41,7 @@
**/
STATIC
EFI_STATUS
-GetImageFromFv (
+InternalGetImageFromFv (
IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,
IN CONST EFI_GUID *NameGuid,
IN EFI_SECTION_TYPE SectionType,
@@ -193,7 +194,7 @@ GetSectionFromFvFile (
(VOID **) &ImageFv
);
if (!EFI_ERROR (Status)) {
- Status = GetImageFromFv (ImageFv, NameGuid, SectionType, Buffer, Size);
+ Status = InternalGetImageFromFv (ImageFv, NameGuid, SectionType, Buffer, Size);
}
}
@@ -231,7 +232,7 @@ GetSectionFromFvFile (
continue;
}
- Status = GetImageFromFv (Fv, NameGuid, SectionType, Buffer, Size);
+ Status = InternalGetImageFromFv (Fv, NameGuid, SectionType, Buffer, Size);
if (!EFI_ERROR (Status)) {
goto Done;
@@ -254,3 +255,216 @@ Done:
return Status;
}
+EFI_HANDLE
+EFIAPI
+ImageHandleToFvHandle (
+ EFI_HANDLE ImageHandle
+ )
+{
+ EFI_STATUS Status;
+ EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
+
+ ASSERT (ImageHandle != NULL);
+
+ Status = gBS->HandleProtocol (
+ (EFI_HANDLE *) ImageHandle,
+ &gEfiLoadedImageProtocolGuid,
+ (VOID **) &LoadedImage
+ );
+
+ ASSERT_EFI_ERROR (Status);
+
+ return LoadedImage->DeviceHandle;
+
+}
+
+EFI_STATUS
+EFIAPI
+GetSectionFromAnyFv (
+ IN CONST EFI_GUID *NameGuid,
+ IN EFI_SECTION_TYPE SectionType,
+ IN UINTN Instance,
+ OUT VOID **Buffer,
+ OUT UINTN *Size
+ )
+{
+ EFI_STATUS Status;
+ EFI_HANDLE *HandleBuffer;
+ UINTN HandleCount;
+ UINTN Index;
+ EFI_HANDLE FvHandle;
+ EFI_TPL OldTpl;
+
+ //
+ // Search the FV that contain the caller's FFS first.
+ // FV builder can choose to build FFS into the this FV
+ // so that this implementation of GetSectionFromAnyFv
+ // will locate the FFS faster.
+ //
+ FvHandle = ImageHandleToFvHandle (gImageHandle);
+ Status = GetSectionFromFv (
+ FvHandle,
+ NameGuid,
+ SectionType,
+ Instance,
+ Buffer,
+ Size
+ );
+ if (!EFI_ERROR (Status)) {
+ return EFI_SUCCESS;
+ }
+
+ OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
+
+ HandleBuffer = NULL;
+ Status = gBS->LocateHandleBuffer (
+ ByProtocol,
+ &gEfiFirmwareVolume2ProtocolGuid,
+ NULL,
+ &HandleCount,
+ &HandleBuffer
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ for (Index = 0; Index < HandleCount; ++Index) {
+ //
+ // Skip the FV that contain the caller's FFS
+ //
+ if (HandleBuffer[Index] == FvHandle) {
+ continue;
+ }
+
+ Status = GetSectionFromFv (
+ HandleBuffer[Index],
+ NameGuid,
+ SectionType,
+ Instance,
+ Buffer,
+ Size
+ );
+
+ if (!EFI_ERROR (Status)) {
+ goto Done;
+ }
+ }
+
+ if (Index == HandleCount) {
+ Status = EFI_NOT_FOUND;
+ }
+
+Done:
+
+ gBS->RestoreTPL (OldTpl);
+
+ if (HandleBuffer != NULL) {
+ FreePool(HandleBuffer);
+ }
+ return Status;
+
+}
+
+EFI_STATUS
+EFIAPI
+GetSectionFromFv (
+ IN EFI_HANDLE FvHandle,
+ IN CONST EFI_GUID *NameGuid,
+ IN EFI_SECTION_TYPE SectionType,
+ IN UINTN Instance,
+ OUT VOID **Buffer,
+ OUT UINTN *Size
+ )
+{
+ EFI_STATUS Status;
+ EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
+ UINT32 AuthenticationStatus;
+
+ ASSERT (FvHandle != NULL);
+
+ Status = gBS->HandleProtocol (
+ FvHandle,
+ &gEfiFirmwareVolume2ProtocolGuid,
+ (VOID **) &Fv
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Read desired section content in NameGuid file
+ //
+ *Buffer = NULL;
+ *Size = 0;
+ Status = Fv->ReadSection (
+ Fv,
+ NameGuid,
+ SectionType,
+ 0,
+ Buffer,
+ Size,
+ &AuthenticationStatus
+ );
+
+ if (EFI_ERROR (Status) && (SectionType == EFI_SECTION_TE)) {
+ //
+ // Try reading PE32 section, if the required section is TE type
+ //
+ *Buffer = NULL;
+ *Size = 0;
+ Status = Fv->ReadSection (
+ Fv,
+ NameGuid,
+ EFI_SECTION_PE32,
+ 0,
+ Buffer,
+ Size,
+ &AuthenticationStatus
+ );
+ }
+
+ return Status;
+}
+
+
+EFI_STATUS
+EFIAPI
+GetSectionFromCurrentFv (
+ IN CONST EFI_GUID *NameGuid,
+ IN EFI_SECTION_TYPE SectionType,
+ IN UINTN Instance,
+ OUT VOID **Buffer,
+ OUT UINTN *Size
+ )
+{
+ return GetSectionFromFv(
+ ImageHandleToFvHandle(gImageHandle),
+ NameGuid,
+ SectionType,
+ Instance,
+ Buffer,
+ Size
+ );
+}
+
+
+
+EFI_STATUS
+EFIAPI
+GetSectionFromCurrentFfs (
+ IN EFI_SECTION_TYPE SectionType,
+ IN UINTN Instance,
+ OUT VOID **Buffer,
+ OUT UINTN *Size
+ )
+{
+ return GetSectionFromFv(
+ ImageHandleToFvHandle(gImageHandle),
+ &gEfiCallerIdGuid,
+ SectionType,
+ Instance,
+ Buffer,
+ Size
+ );
+}
+