From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=104.47.2.43; helo=eur01-db5-obe.outbound.protection.outlook.com; envelope-from=supreeth.venkatesh@arm.com; receiver=edk2-devel@lists.01.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0043.outbound.protection.outlook.com [104.47.2.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E9EBE203BEA3A for ; Fri, 4 May 2018 16:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=U0BSKsyz/Al5CyVt8Tm/jChrfGfSIWT35XPvEzry/+c=; b=gQqxOZquMSUUKGVCgGbPyVVTKdQzxFegOkhVIC3iuym8g/UOhkjDwrID/IPbBNgwpeZJN7E2MsgPOexOcvmCVCqKbjMZizl+1xWWzA/pgogyuVj3948qeKC+oHgeeIg5z1xk5FKAD1MDSoUJaSNvTfnfxzAYgldEEy7Duzhs4zg= Received: from AM4PR0802MB2306.eurprd08.prod.outlook.com (10.172.218.15) by AM4PR0802MB2196.eurprd08.prod.outlook.com (10.172.217.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.735.16; Fri, 4 May 2018 23:21:04 +0000 Received: from AM4PR0802MB2306.eurprd08.prod.outlook.com ([fe80::e117:6f62:6a9b:6be4]) by AM4PR0802MB2306.eurprd08.prod.outlook.com ([fe80::e117:6f62:6a9b:6be4%8]) with mapi id 15.20.0735.016; Fri, 4 May 2018 23:21:04 +0000 From: Supreeth Venkatesh To: Achin Gupta CC: "edk2-devel@lists.01.org" Thread-Topic: [PATCH v1 07/18] StandaloneMmPkg/FvLib: Add a common FV Library for management mode. Thread-Index: AQHTzbWYjt/FZO3AVEuN6XBWJjqO5qQDh1qAgByJ9TA= Date: Fri, 4 May 2018 23:21:04 +0000 Message-ID: References: <20180406144223.10931-1-supreeth.venkatesh@arm.com> <20180406144223.10931-8-supreeth.venkatesh@arm.com> <20180416144413.GO663@e104320-lin> In-Reply-To: <20180416144413.GO663@e104320-lin> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Supreeth.Venkatesh@arm.com; x-originating-ip: [217.140.111.135] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM4PR0802MB2196; 7:NI04VALKLoKrMyV+QRIvXD+CEbnR2eIHjbWec7yh46o45Q80wLrcf3WjEzyFCXAEAJ6sVfRruqcsGv93Z9myHiypJMOU0koC4RQ1nsQp3MrJA5w1M7HUFhcnA7j1V5dWh7Iy2318IcwWz351VFbuQKNZ4tGe03+0n3h5o5HEcckYcmL0dGBRifSl4WgFYlchV+2BeeWG8Cx5wy/N0Q/aVz66ctzmXn3H8aMNTsR+pSuj+OIwZq+eSPGPIHwhxTgI x-ms-exchange-antispam-srfa-diagnostics: SOS;SOR; x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(2017052603328)(7153060)(7193020); SRVR:AM4PR0802MB2196; x-ms-traffictypediagnostic: AM4PR0802MB2196: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917)(162533806227266)(228905959029699)(17755550239193); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231254)(944501410)(52105095)(10201501046)(93006095)(93001095)(3002001)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(6072148)(201708071742011); SRVR:AM4PR0802MB2196; BCL:0; PCL:0; RULEID:; SRVR:AM4PR0802MB2196; x-forefront-prvs: 06628F7CA4 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6029001)(39860400002)(346002)(39380400002)(396003)(376002)(366004)(13464003)(199004)(189003)(40434004)(105586002)(446003)(8936002)(106356001)(4326008)(11346002)(476003)(486006)(966005)(72206003)(5660300001)(6116002)(478600001)(305945005)(7736002)(3846002)(25786009)(81156014)(81166006)(8676002)(66066001)(14454004)(97736004)(316002)(5250100002)(3280700002)(99286004)(6246003)(86362001)(3660700001)(53946003)(74316002)(6306002)(9686003)(55016002)(6436002)(229853002)(102836004)(6862004)(2906002)(6636002)(6506007)(68736007)(59450400001)(53546011)(15188155005)(16799955002)(53376002)(33656002)(26005)(2900100001)(76176011)(7696005)(53936002)(5890100001)(579004); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR0802MB2196; H:AM4PR0802MB2306.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: Jg+ipGmAwnZXiMhm9mFoeZ4H9T1hvRKsAbtHTAnthk4NqqNhTcxqI9E/LyQIxH2wlltG0erBfAeDirmilWgwi5tIdBWW5N9MG796F6UckR894tt3iLJERJtLLq7iv0Qj694Vcm8ixblZm+fwpiAyZGNpPeQmfxlRZLBAm6uS7pU25cKC0huOA3CH3OtebjL8 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: a51933f9-b5fa-4802-e8c8-08d5b215b502 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: a51933f9-b5fa-4802-e8c8-08d5b215b502 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 May 2018 23:21:04.2154 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0802MB2196 Subject: Re: [PATCH v1 07/18] StandaloneMmPkg/FvLib: Add a common FV Library for management mode. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 May 2018 23:21:07 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable My response inline. -----Original Message----- From: Achin Gupta Sent: Monday, April 16, 2018 9:44 AM To: Supreeth Venkatesh Cc: edk2-devel@lists.01.org; michael.d.kinney@intel.com; liming.gao@intel.c= om; jiewen.yao@intel.com; leif.lindholm@linaro.org; ard.biesheuvel@linaro.o= rg; nd Subject: Re: [PATCH v1 07/18] StandaloneMmPkg/FvLib: Add a common FV Librar= y for management mode. Hi Supreeth, On Fri, Apr 06, 2018 at 03:42:12PM +0100, Supreeth Venkatesh wrote: > This patch implements a firmware volume library that can be used by > the Standalone management mode core module to parse the firmware volume. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Achin Gupta I have not contributed to this patch at all. Could you please remove me? Not being an expert, I will wait for Jiewen's feedback cycle to complete. [Supreeth] Ok. Jiewen has given his feedback already. cheers, Achin > Signed-off-by: Supreeth Venkatesh > --- > StandaloneMmPkg/Include/Library/FvLib.h | 109 ++++++++++ > StandaloneMmPkg/Library/FvLib/FvLib.c | 366 ++++++++++++++++++++++++++= ++++++ > StandaloneMmPkg/Library/FvLib/FvLib.inf | 57 +++++ > 3 files changed, 532 insertions(+) > create mode 100644 StandaloneMmPkg/Include/Library/FvLib.h > create mode 100644 StandaloneMmPkg/Library/FvLib/FvLib.c > create mode 100644 StandaloneMmPkg/Library/FvLib/FvLib.inf > > diff --git a/StandaloneMmPkg/Include/Library/FvLib.h > b/StandaloneMmPkg/Include/Library/FvLib.h > new file mode 100644 > index 0000000000..13e1ae2b01 > --- /dev/null > +++ b/StandaloneMmPkg/Include/Library/FvLib.h > @@ -0,0 +1,109 @@ > +/** @file > + > +Copyright (c) 2015, Intel Corporation. All rights reserved.
> +Copyright (c) 2016 - 2017, ARM Limited. All rights reserved.
> + > +This program and the accompanying materials 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 http://opensource.org/licenses/bsd-license.php > + > +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. > + > +**/ > + > +#ifndef _FV_LIB_H_ > +#define _FV_LIB_H_ > + > +#include > +#include > +#include > + > +/** > + Given the input file pointer, search for the next matching file in > +the > + FFS volume as defined by SearchType. The search starts from > +FileHeader inside > + the Firmware Volume defined by FwVolHeader. > + > + @param SearchType Filter to find only files of this type. > + Type EFI_FV_FILETYPE_ALL causes no filtering to be= done. > + @param FwVolHeader Pointer to the FV header of the volume to search. > + This parameter must point to a valid FFS volume. > + @param FileHeader Pointer to the current file from which to begin se= arching. > + This pointer will be updated upon return to reflec= t the file found. > + > + @retval EFI_NOT_FOUND No files matching the search criteria were > +found > + @retval EFI_SUCCESS > +**/ > +EFI_STATUS > +EFIAPI > +FfsFindNextFile ( > + IN EFI_FV_FILETYPE SearchType, > + IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader, > + IN OUT EFI_FFS_FILE_HEADER **FileHeader > + ); > + > +/** > + Given the input file pointer, search for the next matching section > +in the > + FFS volume. > + > + @param SearchType Filter to find only sections of this type. > + @param FfsFileHeader Pointer to the current file to search. > + @param SectionHeader Pointer to the Section matching SectionType in F= fsFileHeader. > + NULL if section not found > + > + @retval EFI_NOT_FOUND No files matching the search criteria were > +found > + @retval EFI_SUCCESS > +**/ > +EFI_STATUS > +FfsFindSection ( > + IN EFI_SECTION_TYPE SectionType, > + IN EFI_FFS_FILE_HEADER *FfsFileHeader, > + IN OUT EFI_COMMON_SECTION_HEADER **SectionHeader > + ); > + > +/** > + 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 EFIAPI FindFfsSectionInSections ( > + IN VOID *Sections, > + IN UINTN SizeOfSections, > + IN EFI_SECTION_TYPE SectionType, > + OUT EFI_COMMON_SECTION_HEADER **FoundSection > + ); > + > +/** > + Given the input file pointer, search for the next matching section > +in the > + FFS volume. > + > + @param SearchType Filter to find only sections of this type. > + @param FfsFileHeader Pointer to the current file to search. > + @param SectionData Pointer to the Section matching SectionType in= FfsFileHeader. > + NULL if section not found @param > + SectionDataSize The size of SectionData > + > + @retval EFI_NOT_FOUND No files matching the search criteria were > +found > + @retval EFI_SUCCESS > +**/ > +EFI_STATUS > +EFIAPI > +FfsFindSectionData ( > + IN EFI_SECTION_TYPE SectionType, > + IN EFI_FFS_FILE_HEADER *FfsFileHeader, > + OUT VOID **SectionData, > + OUT UINTN *SectionDataSize > + ); > + > +#endif > diff --git a/StandaloneMmPkg/Library/FvLib/FvLib.c > b/StandaloneMmPkg/Library/FvLib/FvLib.c > new file mode 100644 > index 0000000000..cacfc81338 > --- /dev/null > +++ b/StandaloneMmPkg/Library/FvLib/FvLib.c > @@ -0,0 +1,366 @@ > +/** @file > + > +Copyright (c) 2015, Intel Corporation. All rights reserved.
> +Copyright (c) 2016 - 2017, ARM Limited. All rights reserved.
> + > +This program and the accompanying materials 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 http://opensource.org/licenses/bsd-license.php > + > +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. > + > +**/ > + > +#include > + > +#include > +#include > +#include > + > +#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \ > + (ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) > +& ((Alignment) - 1)) > + > +/** > + Returns the highest bit set of the State field > + > + @param ErasePolarity Erase Polarity as defined by EFI_FVB_ERASE_POL= ARITY > + in the Attributes field. > + @param FfsHeader Pointer to FFS File Header. > + > + @return the highest bit in the State field **/ EFI_FFS_FILE_STATE > +GetFileState ( > + IN UINT8 ErasePolarity, > + IN EFI_FFS_FILE_HEADER *FfsHeader > + ) > +{ > + EFI_FFS_FILE_STATE FileState; > + EFI_FFS_FILE_STATE HighestBit; > + > + FileState =3D FfsHeader->State; > + > + if (ErasePolarity !=3D 0) { > + FileState =3D (EFI_FFS_FILE_STATE)~FileState; } > + > + HighestBit =3D 0x80; > + while (HighestBit !=3D 0 && (HighestBit & FileState) =3D=3D 0) { > + HighestBit >>=3D 1; > + } > + > + return HighestBit; > +} > + > +/** > + Calculates the checksum of the header of a file. > + > + @param FileHeader Pointer to FFS File Header. > + > + @return Checksum of the header. > +**/ > +UINT8 > +CalculateHeaderChecksum ( > + IN EFI_FFS_FILE_HEADER *FileHeader > + ) > +{ > + UINT8 *ptr; > + UINTN Index; > + UINT8 Sum; > + > + Sum =3D 0; > + ptr =3D (UINT8 *) FileHeader; > + > + for (Index =3D 0; Index < sizeof (EFI_FFS_FILE_HEADER) - 3; Index +=3D= 4) { > + Sum =3D (UINT8) (Sum + ptr[Index]); > + Sum =3D (UINT8) (Sum + ptr[Index + 1]); > + Sum =3D (UINT8) (Sum + ptr[Index + 2]); > + Sum =3D (UINT8) (Sum + ptr[Index + 3]); } > + > + for (; Index < sizeof (EFI_FFS_FILE_HEADER); Index++) { > + Sum =3D (UINT8) (Sum + ptr[Index]); } // // State field (since > + this indicates the different state of file). > + // > + Sum =3D (UINT8) (Sum - FileHeader->State); // // Checksum field of > + the file is not part of the header checksum. > + // > + Sum =3D (UINT8) (Sum - FileHeader->IntegrityCheck.Checksum.File); > + > + return Sum; > +} > + > +/** > + Given the input file pointer, search for the next matching file in > +the > + FFS volume as defined by SearchType. The search starts from > +FileHeader inside > + the Firmware Volume defined by FwVolHeader. > + > + @param SearchType Filter to find only files of this type. > + Type EFI_FV_FILETYPE_ALL causes no filtering to be= done. > + @param FwVolHeader Pointer to the FV header of the volume to search. > + This parameter must point to a valid FFS volume. > + @param FileHeader Pointer to the current file from which to begin se= arching. > + This pointer will be updated upon return to reflec= t the file found. > + > + @retval EFI_NOT_FOUND No files matching the search criteria were > +found > + @retval EFI_SUCCESS > +**/ > +EFI_STATUS > +EFIAPI > +FfsFindNextFile ( > + IN EFI_FV_FILETYPE SearchType, > + IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader, > + IN OUT EFI_FFS_FILE_HEADER **FileHeader > + ) > +{ > + EFI_FFS_FILE_HEADER *FfsFileHeader; > + UINT32 FileLength; > + UINT32 FileOccupiedSize; > + UINT32 FileOffset; > + UINT64 FvLength; > + UINT8 ErasePolarity; > + UINT8 FileState; > + > + FvLength =3D FwVolHeader->FvLength; > + if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) { > + ErasePolarity =3D 1; > + } else { > + ErasePolarity =3D 0; > + } > + // > + // If FileHeader is not specified (NULL) start with the first file > + in the // firmware volume. Otherwise, start from the FileHeader. > + // > + if (*FileHeader =3D=3D NULL) { > + FfsFileHeader =3D (EFI_FFS_FILE_HEADER *) ((UINT8 *) FwVolHeader + > + FwVolHeader->HeaderLength); } else { > + // > + // Length is 24 bits wide so mask upper 8 bits > + // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligne= d. > + // > + FileLength =3D FFS_FILE_SIZE(*FileHeader); > + FileOccupiedSize =3D GET_OCCUPIED_SIZE (FileLength, 8); > + FfsFileHeader =3D (EFI_FFS_FILE_HEADER *) ((UINT8 *) *FileHeader= + FileOccupiedSize); > + } > + > + FileOffset =3D (UINT32) ((UINT8 *) FfsFileHeader - (UINT8 *) > + FwVolHeader); > + > + while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) { > + // > + // Get FileState which is the highest bit of the State > + // > + FileState =3D GetFileState (ErasePolarity, FfsFileHeader); > + > + switch (FileState) { > + > + case EFI_FILE_HEADER_INVALID: > + FileOffset +=3D sizeof (EFI_FFS_FILE_HEADER); > + FfsFileHeader =3D (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader= + sizeof (EFI_FFS_FILE_HEADER)); > + break; > + > + case EFI_FILE_DATA_VALID: > + case EFI_FILE_MARKED_FOR_UPDATE: > + if (CalculateHeaderChecksum (FfsFileHeader) =3D=3D 0) { > + FileLength =3D FFS_FILE_SIZE(FfsFileHeader); > + FileOccupiedSize =3D GET_OCCUPIED_SIZE (FileLength, 8); > + > + if ((SearchType =3D=3D FfsFileHeader->Type) || (SearchType =3D= =3D > + EFI_FV_FILETYPE_ALL)) { > + > + *FileHeader =3D FfsFileHeader; > + > + return EFI_SUCCESS; > + } > + > + FileOffset +=3D FileOccupiedSize; > + FfsFileHeader =3D (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHead= er + FileOccupiedSize); > + } else { > + return EFI_NOT_FOUND; > + } > + break; > + > + case EFI_FILE_DELETED: > + FileLength =3D FFS_FILE_SIZE(FfsFileHeader); > + FileOccupiedSize =3D GET_OCCUPIED_SIZE (FileLength, 8); > + FileOffset +=3D FileOccupiedSize; > + FfsFileHeader =3D (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader= + FileOccupiedSize); > + break; > + > + default: > + return EFI_NOT_FOUND; > + > + } > + } > + > + 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 EFIAPI FindFfsSectionInSections ( > + IN VOID *Sections, > + IN UINTN SizeOfSections, > + IN EFI_SECTION_TYPE SectionType, > + OUT EFI_COMMON_SECTION_HEADER **FoundSection > + ) > +{ > + EFI_PHYSICAL_ADDRESS CurrentAddress; > + UINT32 Size; > + EFI_PHYSICAL_ADDRESS EndOfSections; > + EFI_COMMON_SECTION_HEADER *Section; > + EFI_PHYSICAL_ADDRESS EndOfSection; > + > + // > + // Loop through the FFS file sections > + // > + EndOfSection =3D (EFI_PHYSICAL_ADDRESS)(UINTN) Sections; > + EndOfSections =3D EndOfSection + SizeOfSections; > + for (;;) { > + if (EndOfSection =3D=3D EndOfSections) { > + break; > + } > + CurrentAddress =3D EndOfSection; > + > + Section =3D (EFI_COMMON_SECTION_HEADER*)(UINTN) CurrentAddress; > +// printf ("Section->Type: 0x%08x\n", Section->Type); > + > + Size =3D SECTION_SIZE (Section); > + if (Size < sizeof (*Section)) { > + return EFI_VOLUME_CORRUPTED; > + } > + > + EndOfSection =3D CurrentAddress + Size; > + if (EndOfSection > EndOfSections) { > + return EFI_VOLUME_CORRUPTED; > + } > + Size =3D GET_OCCUPIED_SIZE (Size, 4); > + > + // > + // Look for the requested section type > + // > + if (Section->Type =3D=3D SectionType) { > + *FoundSection =3D Section; > + return EFI_SUCCESS; > + } > + } > + > + return EFI_NOT_FOUND; > +} > + > +/** > + Given the input file pointer, search for the next matching section in = the > + FFS volume. > + > + @param SearchType Filter to find only sections of this type. > + @param FfsFileHeader Pointer to the current file to search. > + @param SectionHeader Pointer to the Section matching SectionType in F= fsFileHeader. > + NULL if section not found > + > + @retval EFI_NOT_FOUND No files matching the search criteria were fou= nd > + @retval EFI_SUCCESS > +**/ > +EFI_STATUS > +EFIAPI > +FfsFindSection ( > + IN EFI_SECTION_TYPE SectionType, > + IN EFI_FFS_FILE_HEADER *FfsFileHeader, > + IN OUT EFI_COMMON_SECTION_HEADER **SectionHeader > + ) > +{ > + UINT32 FileSize; > + EFI_COMMON_SECTION_HEADER *Section; > + EFI_STATUS Status; > + > + // > + // Size is 24 bits wide so mask upper 8 bits. > + // Does not include FfsFileHeader header size > + // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned. > + // > + Section =3D (EFI_COMMON_SECTION_HEADER *) (FfsFileHeader + 1); > + FileSize =3D FFS_FILE_SIZE(FfsFileHeader); > + FileSize -=3D sizeof (EFI_FFS_FILE_HEADER); > + > + Status =3D FindFfsSectionInSections ( > + Section, > + FileSize, > + SectionType, > + SectionHeader > + ); > + return Status; > +} > + > +/** > + Given the input file pointer, search for the next matching section in = the > + FFS volume. > + > + @param SearchType Filter to find only sections of this type. > + @param FfsFileHeader Pointer to the current file to search. > + @param SectionData Pointer to the Section matching SectionType in= FfsFileHeader. > + NULL if section not found > + @param SectionDataSize The size of SectionData > + > + @retval EFI_NOT_FOUND No files matching the search criteria were fou= nd > + @retval EFI_SUCCESS > +**/ > +EFI_STATUS > +EFIAPI > +FfsFindSectionData ( > + IN EFI_SECTION_TYPE SectionType, > + IN EFI_FFS_FILE_HEADER *FfsFileHeader, > + IN OUT VOID **SectionData, > + IN OUT UINTN *SectionDataSize > + ) > +{ > + UINT32 FileSize; > + EFI_COMMON_SECTION_HEADER *Section; > + UINT32 SectionLength; > + UINT32 ParsedLength; > + > + // > + // Size is 24 bits wide so mask upper 8 bits. > + // Does not include FfsFileHeader header size > + // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned. > + // > + Section =3D (EFI_COMMON_SECTION_HEADER *) (FfsFileHeader + 1); > + FileSize =3D FFS_FILE_SIZE(FfsFileHeader); > + FileSize -=3D sizeof (EFI_FFS_FILE_HEADER); > + > + *SectionData =3D NULL; > + ParsedLength =3D 0; > + while (ParsedLength < FileSize) { > + if (Section->Type =3D=3D SectionType) { > + *SectionData =3D (VOID *) (Section + 1); > + *SectionDataSize =3D SECTION_SIZE(Section); > + return EFI_SUCCESS; > + } > + // > + // Size is 24 bits wide so mask upper 8 bits. > + // SectionLength is adjusted it is 4 byte aligned. > + // Go to the next section > + // > + SectionLength =3D SECTION_SIZE(Section); > + SectionLength =3D GET_OCCUPIED_SIZE (SectionLength, 4); > + > + ParsedLength +=3D SectionLength; > + Section =3D (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) Section + Secti= onLength); > + } > + > + return EFI_NOT_FOUND; > +} > diff --git a/StandaloneMmPkg/Library/FvLib/FvLib.inf b/StandaloneMmPkg/Li= brary/FvLib/FvLib.inf > new file mode 100644 > index 0000000000..6df50ab364 > --- /dev/null > +++ b/StandaloneMmPkg/Library/FvLib/FvLib.inf > @@ -0,0 +1,57 @@ > +## @file > +# > +# Copyright (c) 2015, Intel Corporation. All rights reserved.
> +# Copyright (c) 2016 - 2017, ARM Limited. All rights reserved.
> +# > +# This program and the accompanying materials > +# 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 > +# http://opensource.org/licenses/bsd-license.php > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. > +# > +## > + > +########################################################################= ######## > +# > +# Defines Section - statements that will be processed to create a Makefi= le. > +# > +########################################################################= ######## > +[Defines] > + INF_VERSION =3D 0x0001001A > + BASE_NAME =3D FvLib > + FILE_GUID =3D C20085E9-E3AB-4938-A727-C10935FEEE2= B > + MODULE_TYPE =3D BASE > + VERSION_STRING =3D 1.0 > + LIBRARY_CLASS =3D FvLib > + > +# > +# The following information is for reference only and not required by th= e build tools. > +# > +# VALID_ARCHITECTURES =3D IA32 > +# > + > +########################################################################= ######## > +# > +# Sources Section - list of files that are required for the build to suc= ceed. > +# > +########################################################################= ######## > + > +[Sources] > + FvLib.c > + > +########################################################################= ######## > +# > +# Package Dependency Section - list of Package files that are required f= or > +# this module. > +# > +########################################################################= ######## > + > +[Packages] > + MdePkg/MdePkg.dec > + StandaloneMmPkg/StandaloneMmPkg.dec > + > +[LibraryClasses] > + BaseLib > + BaseMemoryLib > + DebugLib > -- > 2.16.2 > IMPORTANT NOTICE: The contents of this email and any attachments are confid= ential and may also be privileged. If you are not the intended recipient, p= lease notify the sender immediately and do not disclose the contents to any= other person, use it for any purpose, or store or copy the information in = any medium. Thank you.