From 4b4b783dbe49102e5acaa9852e737820a645a559 Mon Sep 17 00:00:00 2001 From: Jordan Justen Date: Tue, 21 Jan 2014 19:39:04 +0000 Subject: OvmfPkg/Sec: Add FindFfsSectionInstance This allow you to search for an 'instance' of a section within a series of FFS sections. For example, we will split the MAINFV into a PEI and DXE FV, and then compress those two FV's together within a FFS FV file. The DXE FV will appear as the second section of the file, and therefore we will search for it using an Instance=1 value. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jordan Justen Reviewed-by: Laszlo Ersek git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15150 6f19259b-4bc3-4df7-8a09-765794883524 --- OvmfPkg/Sec/SecMain.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'OvmfPkg') diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index e25825e51a..6e238fe337 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -128,9 +128,13 @@ FindMainFv ( Locates a section within a series of sections with the specified section type. + The Instance parameter indicates which instance of the section + type to return. (0 is first instance, 1 is second...) + @param[in] Sections The sections to search @param[in] SizeOfSections Total size of all sections @param[in] SectionType The section type to locate + @param[in] Instance The section instance number @param[out] FoundSection The FFS section if found @retval EFI_SUCCESS The file and section was found @@ -139,10 +143,11 @@ FindMainFv ( **/ EFI_STATUS -FindFfsSectionInSections ( +FindFfsSectionInstance ( IN VOID *Sections, IN UINTN SizeOfSections, IN EFI_SECTION_TYPE SectionType, + IN UINTN Instance, OUT EFI_COMMON_SECTION_HEADER **FoundSection ) { @@ -182,14 +187,49 @@ FindFfsSectionInSections ( // Look for the requested section type // if (Section->Type == SectionType) { - *FoundSection = Section; - return EFI_SUCCESS; + if (Instance == 0) { + *FoundSection = Section; + return EFI_SUCCESS; + } else { + Instance--; + } } } return EFI_NOT_FOUND; } +/** + Locates a section within a series of sections + with the specified section type. + + @param[in] Sections The sections to search + @param[in] SizeOfSections Total size of all sections + @param[in] SectionType The section type to locate + @param[out] FoundSection The FFS section if found + + @retval EFI_SUCCESS The file and section was found + @retval EFI_NOT_FOUND The file and section was not found + @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted + +**/ +EFI_STATUS +FindFfsSectionInSections ( + IN VOID *Sections, + IN UINTN SizeOfSections, + IN EFI_SECTION_TYPE SectionType, + OUT EFI_COMMON_SECTION_HEADER **FoundSection + ) +{ + return FindFfsSectionInstance ( + Sections, + SizeOfSections, + SectionType, + 0, + FoundSection + ); +} + /** Locates a FFS file with the specified file type and a section within that file with the specified section type. -- cgit v1.2.3