mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-26 23:24:03 +02:00
MdePkg: Add a new DxeServicesLib GetFileDevicePathFromAnyFv () function
Contributed-under: TianoCore Contribution Agreement 1.0 From: Shia Cinnamon <cinnamon.shia@hpe.com> Signed-off-by: Wang Nickle <nickle.wang@hpe.com> Reviewed-by: Feng Tian <feng.tian@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18655 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
9b18845a4b
commit
711ef3f624
@ -3,6 +3,7 @@
|
|||||||
These functions help access data from sections of FFS files or from file path.
|
These functions help access data from sections of FFS files or from file path.
|
||||||
|
|
||||||
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
|
||||||
|
(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
|
||||||
This program and the accompanying materials are licensed and made available under
|
This program and the accompanying materials are licensed and made available under
|
||||||
the terms and conditions of the BSD License that accompanies this distribution.
|
the terms and conditions of the BSD License that accompanies this distribution.
|
||||||
The full text of the license may be found at
|
The full text of the license may be found at
|
||||||
@ -262,5 +263,47 @@ GetFileBufferByFilePath (
|
|||||||
OUT UINT32 *AuthenticationStatus
|
OUT UINT32 *AuthenticationStatus
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Searches all the available firmware volumes and returns the file device path of first matching
|
||||||
|
FFS section.
|
||||||
|
|
||||||
|
This function searches all the firmware volumes for FFS files with an FFS filename specified by NameGuid.
|
||||||
|
The order that the firmware volumes is searched is not deterministic. For each FFS file found a search
|
||||||
|
is made for FFS sections of type SectionType.
|
||||||
|
|
||||||
|
If SectionType is EFI_SECTION_TE, and the search with an FFS file fails,
|
||||||
|
the search will be retried with a section type of EFI_SECTION_PE32.
|
||||||
|
This function must be called with a TPL <= TPL_NOTIFY.
|
||||||
|
|
||||||
|
If NameGuid is NULL, then ASSERT().
|
||||||
|
|
||||||
|
@param NameGuid A pointer to to the FFS filename GUID to search for
|
||||||
|
within any of the firmware volumes in the platform.
|
||||||
|
@param SectionType Indicates the FFS section type to search for within
|
||||||
|
the FFS file specified by NameGuid.
|
||||||
|
@param SectionInstance Indicates which section instance within the FFS file
|
||||||
|
specified by NameGuid to retrieve.
|
||||||
|
@param FvFileDevicePath Device path for the target FFS
|
||||||
|
file.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The specified file device path of FFS section was returned.
|
||||||
|
@retval EFI_NOT_FOUND The specified file device path of FFS section could not be found.
|
||||||
|
@retval EFI_DEVICE_ERROR The FFS section could not be retrieves due to a
|
||||||
|
device error.
|
||||||
|
@retval EFI_ACCESS_DENIED The FFS section could not be retrieves because the
|
||||||
|
firmware volume that contains the matching FFS section does not
|
||||||
|
allow reads.
|
||||||
|
@retval EFI_INVALID_PARAMETER FvFileDevicePath is NULL.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
GetFileDevicePathFromAnyFv (
|
||||||
|
IN CONST EFI_GUID *NameGuid,
|
||||||
|
IN EFI_SECTION_TYPE SectionType,
|
||||||
|
IN UINTN SectionInstance,
|
||||||
|
OUT EFI_DEVICE_PATH_PROTOCOL **FvFileDevicePath
|
||||||
|
);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
These functions help access data from sections of FFS files or from file path.
|
These functions help access data from sections of FFS files or from file path.
|
||||||
|
|
||||||
Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||||
|
(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
@ -927,3 +928,158 @@ Finish:
|
|||||||
|
|
||||||
return ImageBuffer;
|
return ImageBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Searches all the available firmware volumes and returns the file device path of first matching
|
||||||
|
FFS section.
|
||||||
|
|
||||||
|
This function searches all the firmware volumes for FFS files with an FFS filename specified by NameGuid.
|
||||||
|
The order that the firmware volumes is searched is not deterministic. For each FFS file found a search
|
||||||
|
is made for FFS sections of type SectionType.
|
||||||
|
|
||||||
|
If SectionType is EFI_SECTION_TE, and the search with an FFS file fails,
|
||||||
|
the search will be retried with a section type of EFI_SECTION_PE32.
|
||||||
|
This function must be called with a TPL <= TPL_NOTIFY.
|
||||||
|
|
||||||
|
If NameGuid is NULL, then ASSERT().
|
||||||
|
|
||||||
|
@param NameGuid A pointer to to the FFS filename GUID to search for
|
||||||
|
within any of the firmware volumes in the platform.
|
||||||
|
@param SectionType Indicates the FFS section type to search for within
|
||||||
|
the FFS file specified by NameGuid.
|
||||||
|
@param SectionInstance Indicates which section instance within the FFS file
|
||||||
|
specified by NameGuid to retrieve.
|
||||||
|
@param FvFileDevicePath Device path for the target FFS
|
||||||
|
file.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The specified file device path of FFS section was returned.
|
||||||
|
@retval EFI_NOT_FOUND The specified file device path of FFS section could not be found.
|
||||||
|
@retval EFI_DEVICE_ERROR The FFS section could not be retrieves due to a
|
||||||
|
device error.
|
||||||
|
@retval EFI_ACCESS_DENIED The FFS section could not be retrieves because the
|
||||||
|
firmware volume that contains the matching FFS section does not
|
||||||
|
allow reads.
|
||||||
|
@retval EFI_INVALID_PARAMETER FvFileDevicePath is NULL.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
GetFileDevicePathFromAnyFv (
|
||||||
|
IN CONST EFI_GUID *NameGuid,
|
||||||
|
IN EFI_SECTION_TYPE SectionType,
|
||||||
|
IN UINTN SectionInstance,
|
||||||
|
OUT EFI_DEVICE_PATH_PROTOCOL **FvFileDevicePath
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
EFI_HANDLE *HandleBuffer;
|
||||||
|
UINTN HandleCount;
|
||||||
|
UINTN Index;
|
||||||
|
EFI_HANDLE FvHandle;
|
||||||
|
EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;
|
||||||
|
MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *TempFvFileDevicePath;
|
||||||
|
VOID *Buffer;
|
||||||
|
UINTN Size;
|
||||||
|
|
||||||
|
if (FvFileDevicePath == NULL) {
|
||||||
|
return EFI_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
HandleBuffer = NULL;
|
||||||
|
FvDevicePath = NULL;
|
||||||
|
TempFvFileDevicePath = NULL;
|
||||||
|
Buffer = NULL;
|
||||||
|
Size = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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 = InternalImageHandleToFvHandle (gImageHandle);
|
||||||
|
Status = InternalGetSectionFromFv (
|
||||||
|
FvHandle,
|
||||||
|
NameGuid,
|
||||||
|
SectionType,
|
||||||
|
SectionInstance,
|
||||||
|
&Buffer,
|
||||||
|
&Size
|
||||||
|
);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
goto Done;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
Status = InternalGetSectionFromFv (
|
||||||
|
HandleBuffer[Index],
|
||||||
|
NameGuid,
|
||||||
|
SectionType,
|
||||||
|
SectionInstance,
|
||||||
|
&Buffer,
|
||||||
|
&Size
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
//
|
||||||
|
// Update FvHandle to the current handle.
|
||||||
|
//
|
||||||
|
FvHandle = HandleBuffer[Index];
|
||||||
|
goto Done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Index == HandleCount) {
|
||||||
|
Status = EFI_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
Done:
|
||||||
|
if (Status == EFI_SUCCESS) {
|
||||||
|
//
|
||||||
|
// Build a device path to the file in the FV to pass into gBS->LoadImage
|
||||||
|
//
|
||||||
|
Status = gBS->HandleProtocol (FvHandle, &gEfiDevicePathProtocolGuid, (VOID **)&FvDevicePath);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
*FvFileDevicePath = NULL;
|
||||||
|
} else {
|
||||||
|
TempFvFileDevicePath = AllocateZeroPool (sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + END_DEVICE_PATH_LENGTH);
|
||||||
|
if (TempFvFileDevicePath == NULL) {
|
||||||
|
*FvFileDevicePath = NULL;
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
EfiInitializeFwVolDevicepathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH*)TempFvFileDevicePath, NameGuid);
|
||||||
|
SetDevicePathEndNode (NextDevicePathNode (TempFvFileDevicePath));
|
||||||
|
*FvFileDevicePath = AppendDevicePath (
|
||||||
|
FvDevicePath,
|
||||||
|
(EFI_DEVICE_PATH_PROTOCOL *)TempFvFileDevicePath
|
||||||
|
);
|
||||||
|
FreePool (TempFvFileDevicePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Buffer != NULL) {
|
||||||
|
FreePool (Buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (HandleBuffer != NULL) {
|
||||||
|
FreePool (HandleBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user