This patch introduces GetSectionFromFvToBuffer function that allows to read FFS section content to buffer allocated by a caller.
The generic behaviour for this function is same as for GetSectionFromFv function. If there is no room for FFS section in provided buffer a truncated sections contents and EFI_WARN_BUFFER_TOO_SMALL status are returned. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Mike Maslenkin <[email protected]> --- MdePkg/Include/Library/DxeServicesLib.h | 56 +++++++++++++++++++ MdePkg/Library/DxeServicesLib/DxeServicesLib.c | 70 ++++++++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/MdePkg/Include/Library/DxeServicesLib.h b/MdePkg/Include/Library/DxeServicesLib.h index e01dd49..b30a121 100644 --- a/MdePkg/Include/Library/DxeServicesLib.h +++ b/MdePkg/Include/Library/DxeServicesLib.h @@ -174,6 +174,62 @@ GetSectionFromFv ( OUT UINTN *Size ); +/** + Searches the firmware volume that the currently executing module was loaded from and returns the first matching FFS section. + + This function searches the firmware volume that the currently executing module was loaded + from for an FFS file with an FFS filename specified by NameGuid. If the FFS file is found, a search + is made for FFS sections of type SectionType. If the FFS file contains at least SectionInstance + instances of the FFS section specified by SectionType, then the SectionInstance instance is returned in Buffer. + See EFI_FIRMWARE_VOLUME2_PROTOCOL.ReadSection() for details on how sections are retrieved from + an FFS file based on SectionType and SectionInstance. + + If the currently executing module was not loaded from a firmware volume, then EFI_NOT_FOUND is returned. + 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(). + If Buffer is NULL, then ASSERT(). + If Size is NULL, then ASSERT(). + + @param NameGuid A pointer to to the FFS filename GUID to search for + within the firmware volumes that the currently + executing module was loaded from. + @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 Buffer On input must be a valid pointer to + caller allocated buffer. + On output, Buffer contains the data read + from the section in the Firmware File found. + @param Size On input, indicates the size of *Buffer. + On output, indicates the required size of *Buffer. + + @retval EFI_SUCCESS The specified FFS section was returned. + @retval EFI_NOT_FOUND The specified FFS section could not be found. + @retval EFI_OUT_OF_RESOURCES There are not enough resources available to retrieve + the matching FFS section. + @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_WARN_TOO_SMALL The size of the caller allocated input buffer is + insufficient to contain the requested section. + The input buffer is filled and contents are section + contents are truncated. +**/ +EFI_STATUS +EFIAPI +GetSectionFromFvToBuffer ( + IN CONST EFI_GUID *NameGuid, + IN EFI_SECTION_TYPE SectionType, + IN UINTN SectionInstance, + IN VOID **Buffer, + IN OUT UINTN *Size + ); /** Searches the FFS file the the currently executing module was loaded from and returns the first matching FFS section. diff --git a/MdePkg/Library/DxeServicesLib/DxeServicesLib.c b/MdePkg/Library/DxeServicesLib/DxeServicesLib.c index 308b952..0a048a1 100644 --- a/MdePkg/Library/DxeServicesLib/DxeServicesLib.c +++ b/MdePkg/Library/DxeServicesLib/DxeServicesLib.c @@ -528,6 +528,76 @@ GetSectionFromFv ( ); } +/** + Searches the firmware volume that the currently executing module was loaded from and returns the first matching FFS section. + + This function searches the firmware volume that the currently executing module was loaded + from for an FFS file with an FFS filename specified by NameGuid. If the FFS file is found a search + is made for FFS sections of type SectionType. If the FFS file contains at least SectionInstance + instances of the FFS section specified by SectionType, then the SectionInstance instance is returned in Buffer. + Buffer is allocated by caller and the size of the allocated buffer is passed in Size. + If size of the allocated buffer is to small to hold whole FFS section the required size + of *Buffer is returned and truncated FFS section data is returned in *Buffer also. + See EFI_FIRMWARE_VOLUME2_PROTOCOL.ReadSection() for details on how sections are retrieved from + an FFS file based on SectionType and SectionInstance. + + If the currently executing module was not loaded from a firmware volume, then EFI_NOT_FOUND is returned. + 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(). + If Buffer is NULL, then ASSERT(). + If *Buffer is NULL, then ASSERT(). + If Size is NULL, then ASSERT(). + + @param NameGuid A pointer to to the FFS filename GUID to search for + within the firmware volumes that the currently + executing module was loaded from. + @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 Buffer On input *Buffer is a valid pointer to caller allocated buffer. + @param Size On input, indicates the size of *Buffer. + On output, indicates the required size of *Buffer. + + @retval EFI_SUCCESS The specified FFS section was returned. + @retval EFI_NOT_FOUND The specified FFS section could not be found. + @retval EFI_OUT_OF_RESOURCES There are not enough resources available to retrieve + the matching FFS section. + @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_WARN_TOO_SMALL The size of the buffer is insufficient to contain + the requested section. The input buffer is filled + and contents of a sections are truncated. +**/ +EFI_STATUS +EFIAPI +GetSectionFromFvToBuffer ( + IN CONST EFI_GUID *NameGuid, + IN EFI_SECTION_TYPE SectionType, + IN UINTN SectionInstance, + IN VOID **Buffer, + IN OUT UINTN *Size + ) +{ + ASSERT (Buffer != NULL); + ASSERT (*Buffer != NULL); + + return InternalGetSectionFromFv ( + InternalImageHandleToFvHandle(gImageHandle), + NameGuid, + SectionType, + SectionInstance, + FALSE, + Buffer, + Size + ); +} /** Searches the FFS file the the currently executing module was loaded from and returns the first matching FFS section. -- 1.7.10.4 ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_d2d_feb _______________________________________________ edk2-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/edk2-devel
