From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a01:111:f400:fe0a::601; helo=eur03-db5-obe.outbound.protection.outlook.com; envelope-from=achin.gupta@arm.com; receiver=edk2-devel@lists.01.org Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-db5eur03on0601.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0a::601]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 76E2722742ABD for ; Mon, 16 Apr 2018 07:42:51 -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=E7d2QK4TNqJB4Q/kgey1TBruTRWwW1PRLICYUBvadaw=; b=gkYoXh3ZvhTR0QqfmZ+Es9EGgbLH+yf5F+Q6BU/tBeXfl1O800GbDcU18mRUK+OXRgZJPlZYmExne9TchTJam3ihB/+tyB1ZohP4CIngxzeW3dB8gZlTp0HBLaDWx72vZCu6bRKzFcYjmAULHSt7pSoqnHgWXT7r9E2MirPiIF8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Achin.Gupta@arm.com; Received: from e104320-lin (217.140.96.140) by AM0PR08MB2979.eurprd08.prod.outlook.com (2603:10a6:208:5b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.675.10; Mon, 16 Apr 2018 14:42:47 +0000 Date: Mon, 16 Apr 2018 15:44:13 +0100 From: Achin Gupta To: Supreeth Venkatesh Cc: edk2-devel@lists.01.org, michael.d.kinney@intel.com, liming.gao@intel.com, jiewen.yao@intel.com, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, nd@arm.com Message-ID: <20180416144413.GO663@e104320-lin> References: <20180406144223.10931-1-supreeth.venkatesh@arm.com> <20180406144223.10931-8-supreeth.venkatesh@arm.com> MIME-Version: 1.0 In-Reply-To: <20180406144223.10931-8-supreeth.venkatesh@arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [217.140.96.140] X-ClientProxiedBy: DB6P189CA0020.EURP189.PROD.OUTLOOK.COM (2603:10a6:6:2e::33) To AM0PR08MB2979.eurprd08.prod.outlook.com (2603:10a6:208:5b::24) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(48565401081)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB2979; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB2979; 3:QgKiqJtYIVDHGCUxrhDG4sSlZ8a0AdhtQyNPgU/jdz6c2uxmFxpK8shw0WmZNkYFbh+86eCAt4cGM4Gb0TeB4dWoz/u5yoHrfLREosqDks9pmvfgNgEOGGHJso4L5psBgb7OnbDGCo6lnecKZn93ssJePQ77U+EsqjRl9YVmlN3yh1m8CnaVYnGGul+M/7OyIQpuH/VWuiSbRJvfsbVPqz9HDZbW9Jl0v3cJvg4mr+Mnr5QbP7MEoaBYRRR/EZfz; 25:JgO6DVV/JpVnNBAIVQoLMXBhS+yVilhgAm2eECQTZFoCrQjbT/mEHUbzy/XDd59oHTzQ+e4fkIE1NLDDRtZiKj94cWwHviLagRASBzuSBYaiVK8bH9c0mdMTMxslqekf4mX6gqNV1vnVv5XQ6MyliDIz5rauXxFKVJSG2lX7XHDopNya2IvdtxubvHEOx2taUe7u13AkyJoyTwm9fzuyz7AnMnpxwDc7ub5S4GY2Hp3k6AmERBoExwtChzvxBT+TDWlDIee0p5BDLSS/xqNyF9zFKjMS08+ncsSD5v/8F7hHP7rTaK0PQsSit9gRBxOW3mI6D4Y6P6XZHfKPC1DtPQ==; 31:UKtwZjAUZNt8RJVW05MEJqUl11i3glztpj7rUpzoAlndn7orb+I6bWVuY7mWYHGDNpz5M3j1StT8vzJO8rkU6KgzR6rfJAwH3SM7Am+22G+Kr2tvn28aCY/sFfEpqn9WlLEoh+Xx34pNbuipLyCRedcqWZ3YC6a7KDeAG3HNB8lovns5mSfTxCLorwifKwpqzmbdt4GHC4bP+61gYbCdgrd2rznsBD1Ezgg5do6p41s= X-MS-TrafficTypeDiagnostic: AM0PR08MB2979: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB2979; 20:jThcyfMO4ZC1lxEpyy9HZeVtWh8Xa4PdifNKhdS4qk8qqQsxwg1w4FvTCJio9lKM7ItrGqylcxnjUatwkMeNFnQcIvlwPkyep7iP12pgQSbZ718L96d3FGn2103GPqR23ICTt5b1LRIIIW0h8fvHZXzw2ViKffQE7RnlMlqUu6A=; 4:IQsxiOIg+572Ru7k/zR2lB78J3+Q5gSEBiYQivQ+DRNjrkJuv8+BJML1LAy1mFbMTs/Z7Mg6I4AEIWr8WrC4aJTizccG7yTQRGDp9cshvLdOpGJLb7cmdMH/qptLoDbi+kz57aYScfzjTDbCFYbltGP8FSPAbjRdE2dxzRdI1Fn4CcP0m0fCW8BfkXdJ2P0MInLFq/gi6hcHxVgFbYfcB2zlRGCw9jItwPGb5sHXY30ydOwjSXI/djP+zGzU4j76Jd+8vkVHyKRsgFEzfxtcd2Y6vgMZriq+JcCWy89DORR/y7m0zNZHBjyrA6NVAptzXnUAw9Qd+x0gFOyHQZKMC/c9cfY2yIYXVN5RGhuAJ3g= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231232)(944501327)(52105095)(3002001)(6055026)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123562045)(6072148)(201708071742011); SRVR:AM0PR08MB2979; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB2979; X-Forefront-PRVS: 0644578634 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6029001)(396003)(346002)(39380400002)(39860400002)(366004)(376002)(199004)(189003)(16526019)(97736004)(11346002)(956004)(446003)(476003)(26005)(6862004)(386003)(106356001)(53376002)(16586007)(33896004)(15188155005)(316002)(6496006)(6246003)(52116002)(59450400001)(486006)(76176011)(58126008)(9686003)(305945005)(55016002)(44832011)(53936002)(7736002)(66066001)(16799955002)(2906002)(50466002)(68736007)(6306002)(4326008)(23726003)(81156014)(3846002)(86362001)(47776003)(81166006)(6116002)(8676002)(8936002)(72206003)(105586002)(1076002)(478600001)(33716001)(5660300001)(25786009)(229853002)(6636002)(33656002)(6666003)(966005)(18370500001)(107986001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR08MB2979; H:e104320-lin; 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-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR08MB2979; 23:UT/idgf09BiE3+pB44nA3Odi4kpWGCkL78hTn5cMd?= =?us-ascii?Q?QAFqMZmJ0qevd4iu+nB00hDwpU7Zt34TzCCj9X70Glw6aLxTnwXGYc2BdAag?= =?us-ascii?Q?7szswP4H0PBS5lIVGJ556oqtNCTk1ZN0M9LhAN1+SkxI7c3igXkXcsTJyzEM?= =?us-ascii?Q?i/G5Kefz49ewtxZX/sMkbbm8JqQS3nPYia5NtWiCWuRe68AqEKlQwHHo4/Or?= =?us-ascii?Q?8uyGohhDAbLjRPNgHnt3I53sNydjHbfbC23VAsB7XCUieNl/caHm5oVoGrL3?= =?us-ascii?Q?eRmTPt7Uv/5GhJ5FFkWoPGz/87yNph1wlfHZoldRHygA0e/4p5rw4bh8z6xX?= =?us-ascii?Q?+LfG82YrAy5hnsoWpWBa24X06P6PnVo5PArvg0ri1Yl1vxvgmNVU6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QxXsjugdCaEqhWX9Fvv4VQdCTZassiZOPC7cRC+kU+YQf5/nZLMc66fVaJVZbf3vWhsiDWfSjD6+WT1hrISx8+Z9MxvkZGBl0hzmWpSM709fHFk=; 24:q6/hPaODxcr/YmhqVH1UysPOpfqfEkrptT2I5gucBN0K9RP8wJCaRXoSvYbzEQRgPF5Ku49WVjigvIF1Y0QlUGMiAo2OLO1CBDFd1f/zpag= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB2979; 7:ZIfif5qHv/OQLpGx6TXVLyI7W9dcK2ssqWVAl4jp8RLWK4AM1DqtVqqYs8CYFrgLJJVeSB+E5C5WXIS+XylDqG+dDBQ3+dmLGOKi4mraEHsf3E2iP8y8UynWK6Dd2ESta2SsHYb8vyN677CcvsGsz4d2LfjvJtg2gjKurrrbsyHCh18y7DA/9qaoa7OG/uSTeaqhBQy7yaWpZ35Va3AJGhRGERCjSo0DDlkHdfM7vrzwAaE3v2tJTBJP/d/5VqV5 X-MS-Office365-Filtering-Correlation-Id: d0580262-2303-41e7-60f9-08d5a3a852e2 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2018 14:42:47.8819 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d0580262-2303-41e7-60f9-08d5a3a852e2 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB2979 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: Mon, 16 Apr 2018 14:42:52 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. 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 IMPLIED. > + > +**/ > + > +#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 searching. > + This pointer will be updated upon return to reflect 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 FfsFileHeader. > + 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 IMPLIED. > + > +**/ > + > +#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_POLARITY > + 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 = FfsHeader->State; > + > + if (ErasePolarity != 0) { > + FileState = (EFI_FFS_FILE_STATE)~FileState; > + } > + > + HighestBit = 0x80; > + while (HighestBit != 0 && (HighestBit & FileState) == 0) { > + HighestBit >>= 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 = 0; > + ptr = (UINT8 *) FileHeader; > + > + for (Index = 0; Index < sizeof (EFI_FFS_FILE_HEADER) - 3; Index += 4) { > + Sum = (UINT8) (Sum + ptr[Index]); > + Sum = (UINT8) (Sum + ptr[Index + 1]); > + Sum = (UINT8) (Sum + ptr[Index + 2]); > + Sum = (UINT8) (Sum + ptr[Index + 3]); > + } > + > + for (; Index < sizeof (EFI_FFS_FILE_HEADER); Index++) { > + Sum = (UINT8) (Sum + ptr[Index]); > + } > + // > + // State field (since this indicates the different state of file). > + // > + Sum = (UINT8) (Sum - FileHeader->State); > + // > + // Checksum field of the file is not part of the header checksum. > + // > + Sum = (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 searching. > + This pointer will be updated upon return to reflect 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 = FwVolHeader->FvLength; > + if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) { > + ErasePolarity = 1; > + } else { > + ErasePolarity = 0; > + } > + // > + // If FileHeader is not specified (NULL) start with the first file in the > + // firmware volume. Otherwise, start from the FileHeader. > + // > + if (*FileHeader == NULL) { > + FfsFileHeader = (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 aligned. > + // > + FileLength = FFS_FILE_SIZE(*FileHeader); > + FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8); > + FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) *FileHeader + FileOccupiedSize); > + } > + > + FileOffset = (UINT32) ((UINT8 *) FfsFileHeader - (UINT8 *) FwVolHeader); > + > + while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) { > + // > + // Get FileState which is the highest bit of the State > + // > + FileState = GetFileState (ErasePolarity, FfsFileHeader); > + > + switch (FileState) { > + > + case EFI_FILE_HEADER_INVALID: > + FileOffset += sizeof (EFI_FFS_FILE_HEADER); > + FfsFileHeader = (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) == 0) { > + FileLength = FFS_FILE_SIZE(FfsFileHeader); > + FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8); > + > + if ((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) { > + > + *FileHeader = FfsFileHeader; > + > + return EFI_SUCCESS; > + } > + > + FileOffset += FileOccupiedSize; > + FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize); > + } else { > + return EFI_NOT_FOUND; > + } > + break; > + > + case EFI_FILE_DELETED: > + FileLength = FFS_FILE_SIZE(FfsFileHeader); > + FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8); > + FileOffset += FileOccupiedSize; > + FfsFileHeader = (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 = (EFI_PHYSICAL_ADDRESS)(UINTN) Sections; > + EndOfSections = EndOfSection + SizeOfSections; > + for (;;) { > + if (EndOfSection == EndOfSections) { > + break; > + } > + CurrentAddress = EndOfSection; > + > + Section = (EFI_COMMON_SECTION_HEADER*)(UINTN) CurrentAddress; > +// printf ("Section->Type: 0x%08x\n", Section->Type); > + > + Size = SECTION_SIZE (Section); > + if (Size < sizeof (*Section)) { > + return EFI_VOLUME_CORRUPTED; > + } > + > + EndOfSection = CurrentAddress + Size; > + if (EndOfSection > EndOfSections) { > + return EFI_VOLUME_CORRUPTED; > + } > + Size = GET_OCCUPIED_SIZE (Size, 4); > + > + // > + // Look for the requested section type > + // > + if (Section->Type == SectionType) { > + *FoundSection = 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 FfsFileHeader. > + NULL if section not found > + > + @retval EFI_NOT_FOUND No files matching the search criteria were found > + @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 = (EFI_COMMON_SECTION_HEADER *) (FfsFileHeader + 1); > + FileSize = FFS_FILE_SIZE(FfsFileHeader); > + FileSize -= sizeof (EFI_FFS_FILE_HEADER); > + > + Status = 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 found > + @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 = (EFI_COMMON_SECTION_HEADER *) (FfsFileHeader + 1); > + FileSize = FFS_FILE_SIZE(FfsFileHeader); > + FileSize -= sizeof (EFI_FFS_FILE_HEADER); > + > + *SectionData = NULL; > + ParsedLength = 0; > + while (ParsedLength < FileSize) { > + if (Section->Type == SectionType) { > + *SectionData = (VOID *) (Section + 1); > + *SectionDataSize = 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 = SECTION_SIZE(Section); > + SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4); > + > + ParsedLength += SectionLength; > + Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) Section + SectionLength); > + } > + > + return EFI_NOT_FOUND; > +} > diff --git a/StandaloneMmPkg/Library/FvLib/FvLib.inf b/StandaloneMmPkg/Library/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 Makefile. > +# > +################################################################################ > +[Defines] > + INF_VERSION = 0x0001001A > + BASE_NAME = FvLib > + FILE_GUID = C20085E9-E3AB-4938-A727-C10935FEEE2B > + MODULE_TYPE = BASE > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = FvLib > + > +# > +# The following information is for reference only and not required by the build tools. > +# > +# VALID_ARCHITECTURES = IA32 > +# > + > +################################################################################ > +# > +# Sources Section - list of files that are required for the build to succeed. > +# > +################################################################################ > + > +[Sources] > + FvLib.c > + > +################################################################################ > +# > +# Package Dependency Section - list of Package files that are required for > +# this module. > +# > +################################################################################ > + > +[Packages] > + MdePkg/MdePkg.dec > + StandaloneMmPkg/StandaloneMmPkg.dec > + > +[LibraryClasses] > + BaseLib > + BaseMemoryLib > + DebugLib > -- > 2.16.2 >