From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: hao.a.wu@intel.com) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by groups.io with SMTP; Tue, 06 Aug 2019 22:20:31 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Aug 2019 22:20:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,356,1559545200"; d="scan'208";a="258248097" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga001.jf.intel.com with ESMTP; 06 Aug 2019 22:20:29 -0700 Received: from fmsmsx111.amr.corp.intel.com (10.18.116.5) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 6 Aug 2019 22:20:29 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by fmsmsx111.amr.corp.intel.com (10.18.116.5) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 6 Aug 2019 22:20:28 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.112]) by shsmsx102.ccr.corp.intel.com ([169.254.2.19]) with mapi id 14.03.0439.000; Wed, 7 Aug 2019 13:20:27 +0800 From: "Wu, Hao A" To: "Kinney, Michael D" , "Jin, Eric" , "devel@edk2.groups.io" CC: Sean Brogan , Bret Barkelew , "Wang, Jian J" , "Gao, Liming" , "afish@apple.com" , "lersek@redhat.com" , "leif.lindholm@linaro.org" Subject: Re: [PATCH v2] MdeModulePkg/EsrtFmpDxe: Enhance ESRT to support multiple controllers Thread-Topic: [PATCH v2] MdeModulePkg/EsrtFmpDxe: Enhance ESRT to support multiple controllers Thread-Index: AQHVS2Q5c9OlstErlkaxwlCmtgWqvabta3Mw//+bTgCAAh/2kA== Date: Wed, 7 Aug 2019 05:20:26 +0000 Message-ID: References: <20190805080248.10360-1-eric.jin@intel.com> In-Reply-To: Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: hao.a.wu@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Kinney, Michael D > Sent: Tuesday, August 06, 2019 12:46 PM > To: Wu, Hao A; Jin, Eric; devel@edk2.groups.io; Kinney, Michael D > Cc: Sean Brogan; Bret Barkelew; Wang, Jian J; Gao, Liming; afish@apple.co= m; > lersek@redhat.com; leif.lindholm@linaro.org > Subject: RE: [PATCH v2] MdeModulePkg/EsrtFmpDxe: Enhance ESRT to > support multiple controllers >=20 > Hao Wu, >=20 > I agree that patches should be cleaned up for > submission to edk2 repo. The work in edk2-staging > may contain bug fixes and design changes in the > patch history that can be consolidated to a smaller > patch set. Also, all feedback to a patch set from > edk2-staging must be addressed just like any other > submission which may include splitting or merging > patches. Hello Mike, Thanks for the confirmation. Since there is no other feedback received, the patch has been pushed via commit e314132fea. Best Regards, Hao Wu >=20 > Mike >=20 > > -----Original Message----- > > From: Wu, Hao A > > Sent: Monday, August 5, 2019 7:49 PM > > To: Jin, Eric ; > > devel@edk2.groups.io > > Cc: Sean Brogan ; Bret > > Barkelew ; Wang, Jian J > > ; Kinney, Michael D > > ; Gao, Liming > > ; afish@apple.com; > > lersek@redhat.com; leif.lindholm@linaro.org > > Subject: RE: [PATCH v2] MdeModulePkg/EsrtFmpDxe: > > Enhance ESRT to support multiple controllers > > > > > -----Original Message----- > > > From: Jin, Eric > > > Sent: Monday, August 05, 2019 4:03 PM > > > To: devel@edk2.groups.io > > > Cc: Sean Brogan; Bret Barkelew; Wang, Jian J; Wu, Hao > > A; Kinney, > > > Michael D > > > Subject: [PATCH v2] MdeModulePkg/EsrtFmpDxe: Enhance > > ESRT to support > > > multiple controllers > > > > > > REF: > > https://bugzilla.tianocore.org/show_bug.cgi?id=3D1525 > > > > > > The patch is to merge multiple FMP instances into > > single ESRT entry > > > when they have the same GUID. > > > > > > The policy to LastAttemptStatus/LastAttemptVersion of > > ESRT entry is: > > > If all the LastAttemptStatus are > > LAST_ATTEMPT_STATUS_SUCCESS, then > > > LastAttemptVersion should be the smallest of > > LastAttemptVersion. If > > > any of the LastAttemptStatus is not > > LAST_ATTEMPT_STATUS_SUCCESS, then > > > the LastAttemptVersion/LastAttemptStatus should be > > the values of the > > > first FMP instance whose LastAttemptStatus is not > > > LAST_ATTEMPT_STATUS_SUCCESS. > > > > > > To detect possible duplicated GUID/HardwareInstance, > > a table of > > > GUID/HardwareInstance pairs from all the > > > EFI_FIRMWARE_IMAGE_DESCRIPTORs from all FMP instances > > is built. If a > > > duplicate is found, then generate a DEBUG_ERROR > > message, generate an > > > ASSERT(), and ignore the duplicate > > EFI_FIRMWARE_IMAGE_DESCRIPTOR. > > > > > > Add an internal worker function called > > FmpGetFirmwareImageDescriptor() > > > that retrieves the list of > > EFI_FIRMWARE_IMAGE_DESCRIPTORs from a > > > single FMP instance and returns the descriptors in an > > allocated > > > buffer. This function is used to get the descriptors > > used to build the > > > table of unique GUID/HardwareInstance pairs. It is > > then used again to > > > generate the ESRT Table from all the > > EFI_FIRMWARE_IMAGE_DESCRIPTORs > > > from all the FMP instances. 2 passes are performed so > > the total number > > > of descriptors is known. This allows the correct > > sized buffers to > > > always be allocated. > > > > > > The patch looks good to me. > > Reviewed-by: Hao A Wu > > > > I will wait a little longer to push the patch to see if > > there is additional feedbacks from stewards with regard > > to the approach when merging changes from the edk2- > > staging repo. > > > > Best Regards, > > Hao Wu > > > > > > > > > > Cc: Sean Brogan > > > Cc: Bret Barkelew > > > Cc: Jian J Wang > > > Cc: Hao A Wu > > > Signed-off-by: Michael D Kinney > > > > > Signed-off-by: Eric Jin > > > --- > > > MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmp.c | 394 > > +++++++++++++--- > > > ---- > > > 1 file changed, 257 insertions(+), 137 deletions(-) > > > > > > diff --git > > a/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmp.c > > > b/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmp.c > > > index 2356da662e..4670349f89 100644 > > > --- a/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmp.c > > > +++ b/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmp.c > > > @@ -2,7 +2,7 @@ > > > Publishes ESRT table from Firmware Management > > Protocol instances > > > > > > Copyright (c) 2016, Microsoft Corporation > > > - Copyright (c) 2018, Intel Corporation. All rights > > reserved.
> > > + Copyright (c) 2018 - 2019, Intel Corporation. All > > rights > > > + reserved.
> > > > > > All rights reserved. > > > SPDX-License-Identifier: BSD-2-Clause-Patent @@ - > > 21,6 +21,22 @@ > > > #include #include > > > > > > > > +/// > > > +/// Structure for array of unique > > GUID/HardwareInstance pairs from > > > +the /// current set of > > EFI_FIRMWARE_IMAGE_DESCRIPTORs from all FMP > > > Protocols. > > > +/// > > > +typedef struct { > > > + /// > > > + /// A unique GUID identifying the firmware image > > type. > > > + /// > > > + EFI_GUID ImageTypeGuid; > > > + /// > > > + /// An optional number to identify the unique > > hardware instance > > > +within > > > the > > > + /// system for devices that may have multiple > > instances whenever > > > possible. > > > + /// > > > + UINT64 HardwareInstance; > > > +} GUID_HARDWAREINSTANCE_PAIR; > > > + > > > /** > > > Print ESRT to debug console. > > > > > > @@ -33,11 +49,6 @@ PrintTable ( > > > IN EFI_SYSTEM_RESOURCE_TABLE *Table > > > ); > > > > > > -// > > > -// Number of ESRT entries to grow by each time we > > run out of room -// > > > -#define GROWTH_STEP 10 > > > - > > > /** > > > Install EFI System Resource Table into the UEFI > > Configuration Table > > > > > > @@ -101,90 +112,129 @@ IsSystemFmp ( > > > } > > > > > > /** > > > - Function to create a single ESRT Entry and add it > > to the ESRT > > > - given a FMP descriptor. If the guid is already in > > the ESRT it > > > - will be ignored. The ESRT will grow if it does > > not have enough room. > > > - > > > - @param[in, out] Table On input, > > pointer to the pointer to the ESRT. > > > - On output, same > > as input or pointer to the pointer > > > - to new enlarged > > ESRT. > > > - @param[in] FmpImageInfoBuf Pointer to the > > > EFI_FIRMWARE_IMAGE_DESCRIPTOR. > > > - @param[in] FmpVersion FMP Version. > > > - > > > - @return Status code. > > > + Function to create a single ESRT Entry and add it > > to the ESRT with > > > + a given FMP descriptor. If the GUID is already in > > the ESRT, then > > > + the ESRT entry is updated. > > > + > > > + @param[in,out] Table Pointer to the > > ESRT Table. > > > + @param[in,out] HardwareInstances Pointer to the > > > GUID_HARDWAREINSTANCE_PAIR. > > > + @param[in,out] NumberOfDescriptors The number of > > > EFI_FIRMWARE_IMAGE_DESCRIPTORs. > > > + @param[in] FmpImageInfoBuf Pointer to the > > > EFI_FIRMWARE_IMAGE_DESCRIPTOR. > > > + @param[in] FmpVersion FMP Version. > > > + > > > + @retval EFI_SUCCESS FmpImageInfoBuf was use > > to fill in a new ESRT > > > entry > > > + in Table. > > > + @retval EFI_SUCCESS The ImageTypeId GUID in > > FmpImageInfoBuf > > > matches an > > > + existing ESRT entry in > > Table, and the information > > > + from FmpImageInfoBuf was > > merged into the the existing > > > + ESRT entry. > > > + @retval EFI_UNSPOORTED The GUID/HardareInstance > > in > > > FmpImageInfoBuf has is a > > > + duplicate. > > > > > > **/ > > > EFI_STATUS > > > CreateEsrtEntry ( > > > - IN OUT EFI_SYSTEM_RESOURCE_TABLE **Table, > > > - IN EFI_FIRMWARE_IMAGE_DESCRIPTOR > > *FmpImageInfoBuf, > > > - IN UINT32 FmpVersion > > > + IN OUT EFI_SYSTEM_RESOURCE_TABLE *Table, > > > + IN OUT GUID_HARDWAREINSTANCE_PAIR > > *HardwareInstances, > > > + IN OUT UINT32 > > *NumberOfDescriptors, > > > + IN EFI_FIRMWARE_IMAGE_DESCRIPTOR > > *FmpImageInfoBuf, > > > + IN UINT32 FmpVersion > > > ) > > > { > > > UINTN Index; > > > EFI_SYSTEM_RESOURCE_ENTRY *Entry; > > > - UINTN NewSize; > > > - EFI_SYSTEM_RESOURCE_TABLE *NewTable; > > > + UINT64 FmpHardwareInstance; > > > > > > - Index =3D 0; > > > - Entry =3D NULL; > > > + FmpHardwareInstance =3D 0; > > > + if (FmpVersion >=3D 3) { > > > + FmpHardwareInstance =3D FmpImageInfoBuf- > > >HardwareInstance; > > > + } > > > > > > - Entry =3D (EFI_SYSTEM_RESOURCE_ENTRY *)((*Table) + > > 1); > > > // > > > - // Make sure Guid isn't already in the list > > > + // Check to see of FmpImageInfoBuf > > GUID/HardwareInstance is unique > > > // > > > - for (Index =3D 0; Index < (*Table)->FwResourceCount; > > Index++) { > > > - if (CompareGuid (&Entry->FwClass, > > &FmpImageInfoBuf->ImageTypeId)) { > > > - DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: ESRT Entry > > already exists for FMP > > > Instance with GUID %g\n", &Entry->FwClass)); > > > - return EFI_INVALID_PARAMETER; > > > + for (Index =3D 0; Index < *NumberOfDescriptors; > > Index++) { > > > + if (CompareGuid > > (&HardwareInstances[Index].ImageTypeGuid, > > > &FmpImageInfoBuf->ImageTypeId)) { > > > + if (HardwareInstances[Index].HardwareInstance > > =3D=3D > > > FmpHardwareInstance) { > > > + DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Duplicate > > firmware image > > > descriptor with GUID %g HardwareInstance:0x%x\n", > > &FmpImageInfoBuf- > > > >ImageTypeId, FmpHardwareInstance)); > > > + ASSERT ( > > > + !CompareGuid > > (&HardwareInstances[Index].ImageTypeGuid, > > > &FmpImageInfoBuf->ImageTypeId) || > > > + HardwareInstances[Index].HardwareInstance > > !=3D > > > FmpHardwareInstance > > > + ); > > > + return EFI_UNSUPPORTED; > > > + } > > > } > > > - Entry++; > > > } > > > > > > // > > > - // Grow table if needed > > > + // Record new GUID/HardwareInstance pair > > > // > > > - if ((*Table)->FwResourceCount >=3D (*Table)- > > >FwResourceCountMax) { > > > - NewSize =3D (((*Table)->FwResourceCountMax + > > GROWTH_STEP) * sizeof > > > (EFI_SYSTEM_RESOURCE_ENTRY)) + sizeof > > (EFI_SYSTEM_RESOURCE_TABLE); > > > - NewTable =3D AllocateZeroPool (NewSize); > > > - if (NewTable =3D=3D NULL) { > > > - DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Failed to > > allocate memory larger > > > table for ESRT. \n")); > > > - return EFI_OUT_OF_RESOURCES; > > > + CopyGuid > > (&HardwareInstances[*NumberOfDescriptors].ImageTypeGuid > > , > > > &FmpImageInfoBuf->ImageTypeId); > > > + > > HardwareInstances[*NumberOfDescriptors].HardwareInstanc > > e =3D > > > FmpHardwareInstance; > > > + *NumberOfDescriptors =3D *NumberOfDescriptors + 1; > > > + > > > + DEBUG ((DEBUG_INFO, "EsrtFmpDxe: Add new image > > descriptor with > > > GUID %g HardwareInstance:0x%x\n", &FmpImageInfoBuf- > > >ImageTypeId, > > > FmpHardwareInstance)); > > > + > > > + // > > > + // Check to see if GUID is already in the ESRT > > table // Entry =3D > > > + (EFI_SYSTEM_RESOURCE_ENTRY *)(Table + 1); for > > (Index =3D 0; Index < > > > + Table->FwResourceCount; Index++, Entry++) { > > > + if (!CompareGuid (&Entry->FwClass, > > > + &FmpImageInfoBuf->ImageTypeId)) > > > { > > > + continue; > > > } > > > + DEBUG ((DEBUG_INFO, "EsrtFmpDxe: ESRT Entry > > already exists for > > > + FMP > > > Instance with GUID %g\n", &Entry->FwClass)); > > > + > > > // > > > - // Copy the whole old table into new table > > buffer > > > - // > > > - CopyMem ( > > > - NewTable, > > > - (*Table), > > > - (((*Table)->FwResourceCountMax) * sizeof > > > (EFI_SYSTEM_RESOURCE_ENTRY)) + sizeof > > (EFI_SYSTEM_RESOURCE_TABLE) > > > - ); > > > - // > > > - // Update max > > > + // Set ESRT FwVersion to the smaller of the two > > values > > > // > > > - NewTable->FwResourceCountMax =3D NewTable- > > >FwResourceCountMax + > > > GROWTH_STEP; > > > + Entry->FwVersion =3D MIN (FmpImageInfoBuf- > > >Version, Entry- > > > >FwVersion); > > > + > > > // > > > - // Free old table > > > + // VERSION 2 has Lowest Supported > > > // > > > - FreePool ((*Table)); > > > + if (FmpVersion >=3D 2) { > > > + // > > > + // Set ESRT LowestSupportedFwVersion to the > > smaller of the two values > > > + // > > > + Entry->LowestSupportedFwVersion =3D > > > + MIN ( > > > + FmpImageInfoBuf- > > >LowestSupportedImageVersion, > > > + Entry->LowestSupportedFwVersion > > > + ); > > > + } > > > + > > > // > > > - // Reassign pointer to new table. > > > + // VERSION 3 supports last attempt values > > > // > > > - (*Table) =3D NewTable; > > > + if (FmpVersion >=3D 3) { > > > + // > > > + // Update the ESRT entry with the last attempt > > status and last attempt > > > + // version from the first FMP instance whose > > last attempt status is not > > > + // SUCCESS. If all FMP instances are SUCCESS, > > then set version to the > > > + // smallest value from all FMP instances. > > > + // > > > + if (Entry->LastAttemptStatus =3D=3D > > LAST_ATTEMPT_STATUS_SUCCESS) { > > > + if (FmpImageInfoBuf->LastAttemptStatus !=3D > > > LAST_ATTEMPT_STATUS_SUCCESS) { > > > + Entry->LastAttemptStatus =3D > > FmpImageInfoBuf->LastAttemptStatus; > > > + Entry->LastAttemptVersion =3D > > FmpImageInfoBuf->LastAttemptVersion; > > > + } else { > > > + Entry->LastAttemptVersion =3D > > > + MIN ( > > > + FmpImageInfoBuf->LastAttemptVersion, > > > + Entry->LastAttemptVersion > > > + ); > > > + } > > > + } > > > + } > > > + > > > + return EFI_SUCCESS; > > > } > > > > > > // > > > - // ESRT table has enough room for the new entry so > > add new entry > > > - // > > > - Entry =3D (EFI_SYSTEM_RESOURCE_ENTRY *)(((UINT8 > > *)(*Table)) + sizeof > > > (EFI_SYSTEM_RESOURCE_TABLE)); > > > - // > > > - // Move to the location of new entry > > > - // > > > - Entry =3D Entry + (*Table)->FwResourceCount; > > > + // Add a new ESRT Table Entry > > > // > > > - // Increment resource count > > > - // > > > - (*Table)->FwResourceCount++; > > > + Entry =3D (EFI_SYSTEM_RESOURCE_ENTRY *)(Table + 1) + > > Table- > > > >FwResourceCount; > > > > > > CopyGuid (&Entry->FwClass, &FmpImageInfoBuf- > > >ImageTypeId); > > > > > > @@ -195,11 +245,11 @@ CreateEsrtEntry ( > > > Entry->FwType =3D > > (UINT32)(ESRT_FW_TYPE_DEVICEFIRMWARE); > > > } > > > > > > - Entry->FwVersion =3D FmpImageInfoBuf->Version; > > > + Entry->FwVersion =3D FmpImageInfoBuf- > > >Version; > > > Entry->LowestSupportedFwVersion =3D 0; > > > - Entry->CapsuleFlags =3D 0; > > > - Entry->LastAttemptVersion =3D 0; > > > - Entry->LastAttemptStatus =3D 0; > > > + Entry->CapsuleFlags =3D 0; > > > + Entry->LastAttemptVersion =3D 0; > > > + Entry->LastAttemptStatus =3D 0; > > > > > > // > > > // VERSION 2 has Lowest Supported > > > @@ -213,12 +263,93 @@ CreateEsrtEntry ( > > > // > > > if (FmpVersion >=3D 3) { > > > Entry->LastAttemptVersion =3D FmpImageInfoBuf- > > >LastAttemptVersion; > > > - Entry->LastAttemptStatus =3D FmpImageInfoBuf- > > >LastAttemptStatus; > > > + Entry->LastAttemptStatus =3D FmpImageInfoBuf- > > >LastAttemptStatus; > > > } > > > > > > + // > > > + // Increment the number of active ESRT Table > > Entries // > > > + Table->FwResourceCount++; > > > + > > > return EFI_SUCCESS; > > > } > > > > > > +/** > > > + Function to retrieve the > > EFI_FIRMWARE_IMAGE_DESCRIPTOR from an > > > FMP Instance. > > > + The returned buffer is allocated using > > AllocatePool() and must be > > > + freed by > > > the > > > + caller using FreePool(). > > > + > > > + @param[in] Fmp Pointer to > > an > > > EFI_FIRMWARE_MANAGEMENT_PROTOCOL. > > > + @param[out] FmpImageInfoDescriptorVer Pointer to > > the version > > > + number > > > associated > > > + with the > > returned > > > EFI_FIRMWARE_IMAGE_DESCRIPTOR. > > > + @param[out] FmpImageInfoCount Pointer to > > the number of the > > > returned > > > + > > EFI_FIRMWARE_IMAGE_DESCRIPTORs. > > > + @param[out] DescriptorSize Pointer to > > the size, in bytes, of each > > > + returned > > EFI_FIRMWARE_IMAGE_DESCRIPTOR. > > > + > > > + @return Pointer to the retrieved > > EFI_FIRMWARE_IMAGE_DESCRIPTOR. > > > + If > > > the > > > + descriptor can not be retrieved, then > > NULL is returned. > > > + > > > +**/ > > > +EFI_FIRMWARE_IMAGE_DESCRIPTOR * > > > +FmpGetFirmwareImageDescriptor ( > > > + IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *Fmp, > > > + OUT UINT32 > > *FmpImageInfoDescriptorVer, > > > + OUT UINT8 > > *FmpImageInfoCount, > > > + OUT UINTN > > *DescriptorSize > > > + ) > > > +{ > > > + EFI_STATUS Status; > > > + UINTN ImageInfoSize; > > > + UINT32 PackageVersion; > > > + CHAR16 > > *PackageVersionName; > > > + EFI_FIRMWARE_IMAGE_DESCRIPTOR *FmpImageInfoBuf; > > > + > > > + ImageInfoSize =3D 0; > > > + Status =3D Fmp->GetImageInfo ( > > > + Fmp, // FMP > > Pointer > > > + &ImageInfoSize, // > > Buffer Size (in this case 0) > > > + NULL, // > > NULL so we can get size > > > + FmpImageInfoDescriptorVer, // > > DescriptorVersion > > > + FmpImageInfoCount, // > > DescriptorCount > > > + DescriptorSize, // > > DescriptorSize > > > + &PackageVersion, // > > PackageVersion > > > + &PackageVersionName // > > PackageVersionName > > > + ); > > > + if (Status !=3D EFI_BUFFER_TOO_SMALL) { > > > + DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Unexpected > > Failure in > > > GetImageInfo. Status =3D %r\n", Status)); > > > + return NULL; > > > + } > > > + > > > + FmpImageInfoBuf =3D AllocateZeroPool > > (ImageInfoSize); if > > > + (FmpImageInfoBuf =3D=3D NULL) { > > > + DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Failed to get > > memory for FMP > > > descriptor.\n")); > > > + return NULL; > > > + } > > > + > > > + PackageVersionName =3D NULL; > > > + Status =3D Fmp->GetImageInfo ( > > > + Fmp, // FMP > > Pointer > > > + &ImageInfoSize, // > > ImageInfoSize > > > + FmpImageInfoBuf, // > > ImageInfo > > > + FmpImageInfoDescriptorVer, // > > DescriptorVersion > > > + FmpImageInfoCount, // > > DescriptorCount > > > + DescriptorSize, // > > DescriptorSize > > > + &PackageVersion, // > > PackageVersion > > > + &PackageVersionName // > > PackageVersionName > > > + ); > > > + if (PackageVersionName !=3D NULL) { > > > + FreePool (PackageVersionName); > > > + } > > > + if (EFI_ERROR (Status)) { > > > + DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Failure in > > GetImageInfo. > > > + Status > > > =3D %r\n", Status)); > > > + FreePool (FmpImageInfoBuf); > > > + return NULL; > > > + } > > > + > > > + return FmpImageInfoBuf; > > > +} > > > + > > > /** > > > Function to create ESRT based on FMP Instances. > > > Create ESRT table, get the descriptors from FMP > > Instance and @@ > > > -232,29 +363,26 @@ CreateFmpBasedEsrt ( > > > VOID > > > ) > > > { > > > - EFI_STATUS Status; > > > - EFI_SYSTEM_RESOURCE_TABLE *Table; > > > - UINTN NoProtocols; > > > - VOID **Buffer; > > > - UINTN Index; > > > - EFI_FIRMWARE_MANAGEMENT_PROTOCOL *Fmp; > > > - UINTN DescriptorSize; > > > - EFI_FIRMWARE_IMAGE_DESCRIPTOR > > *FmpImageInfoBuf; > > > - EFI_FIRMWARE_IMAGE_DESCRIPTOR > > *FmpImageInfoBufOrg; > > > - UINT8 > > FmpImageInfoCount; > > > - UINT32 > > FmpImageInfoDescriptorVer; > > > - UINTN ImageInfoSize; > > > - UINT32 PackageVersion; > > > - CHAR16 > > *PackageVersionName; > > > + EFI_STATUS Status; > > > + UINTN NoProtocols; > > > + VOID **Buffer; > > > + UINTN Index; > > > + UINT32 > > FmpImageInfoDescriptorVer; > > > + UINT8 FmpImageInfoCount; > > > + UINTN DescriptorSize; > > > + UINT32 > > NumberOfDescriptors; > > > + EFI_FIRMWARE_IMAGE_DESCRIPTOR *FmpImageInfoBuf; > > > + EFI_FIRMWARE_IMAGE_DESCRIPTOR *OrgFmpImageInfoBuf; > > > + EFI_SYSTEM_RESOURCE_TABLE *Table; > > > + GUID_HARDWAREINSTANCE_PAIR *HardwareInstances; > > > > > > Status =3D EFI_SUCCESS; > > > - Table =3D NULL; > > > NoProtocols =3D 0; > > > Buffer =3D NULL; > > > - PackageVersionName =3D NULL; > > > FmpImageInfoBuf =3D NULL; > > > - FmpImageInfoBufOrg =3D NULL; > > > - Fmp =3D NULL; > > > + OrgFmpImageInfoBuf =3D NULL; > > > + Table =3D NULL; > > > + HardwareInstances =3D NULL; > > > > > > Status =3D EfiLocateProtocolBuffer ( > > > &gEfiFirmwareManagementProtocolGuid, > > > @@ -266,69 +394,64 @@ CreateFmpBasedEsrt ( > > > } > > > > > > // > > > - // Allocate Memory for table > > > + // Count the total number of > > EFI_FIRMWARE_IMAGE_DESCRIPTORs // > > > + for (Index =3D 0, NumberOfDescriptors =3D 0; Index < > > NoProtocols; Index++) { > > > + FmpImageInfoBuf =3D FmpGetFirmwareImageDescriptor > > ( > > > + > > (EFI_FIRMWARE_MANAGEMENT_PROTOCOL *) Buffer[Index], > > > + &FmpImageInfoDescriptorVer, > > > + &FmpImageInfoCount, > > > + &DescriptorSize > > > + ); > > > + if (FmpImageInfoBuf !=3D NULL) { > > > + NumberOfDescriptors +=3D FmpImageInfoCount; > > > + FreePool (FmpImageInfoBuf); > > > + } > > > + } > > > + > > > + // > > > + // Allocate ESRT Table and GUID/HardwareInstance > > table > > > // > > > Table =3D AllocateZeroPool ( > > > - (GROWTH_STEP * sizeof > > (EFI_SYSTEM_RESOURCE_ENTRY)) + sizeof > > > (EFI_SYSTEM_RESOURCE_TABLE) > > > + (NumberOfDescriptors * sizeof > > > + (EFI_SYSTEM_RESOURCE_ENTRY)) + > > > sizeof (EFI_SYSTEM_RESOURCE_TABLE) > > > ); > > > if (Table =3D=3D NULL) { > > > DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Failed to > > allocate memory for > > > ESRT.\n")); > > > - gBS->FreePool (Buffer); > > > + FreePool (Buffer); > > > return NULL; > > > } > > > > > > + HardwareInstances =3D AllocateZeroPool > > (NumberOfDescriptors * sizeof > > > (GUID_HARDWAREINSTANCE_PAIR)); > > > + if (HardwareInstances =3D=3D NULL) { > > > + DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Failed to > > allocate memory for > > > + HW > > > Instance Table.\n")); > > > + FreePool (Table); > > > + FreePool (Buffer); > > > + return NULL; > > > + } > > > + > > > + // > > > + // Initialize ESRT Table > > > + // > > > Table->FwResourceCount =3D 0; > > > - Table->FwResourceCountMax =3D GROWTH_STEP; > > > + Table->FwResourceCountMax =3D NumberOfDescriptors; > > > Table->FwResourceVersion =3D > > > EFI_SYSTEM_RESOURCE_TABLE_FIRMWARE_RESOURCE_VERSION; > > > > > > + NumberOfDescriptors =3D 0; > > > for (Index =3D 0; Index < NoProtocols; Index++) { > > > - Fmp =3D (EFI_FIRMWARE_MANAGEMENT_PROTOCOL *) > > Buffer[Index]; > > > - > > > - ImageInfoSize =3D 0; > > > - Status =3D Fmp->GetImageInfo ( > > > - Fmp, // > > FMP Pointer > > > - &ImageInfoSize, // > > Buffer Size (in this case 0) > > > - NULL, // > > NULL so we can get size > > > - &FmpImageInfoDescriptorVer, // > > DescriptorVersion > > > - &FmpImageInfoCount, // > > DescriptorCount > > > - &DescriptorSize, // > > DescriptorSize > > > - &PackageVersion, // > > PackageVersion > > > - &PackageVersionName // > > PackageVersionName > > > - ); > > > - > > > - if (Status !=3D EFI_BUFFER_TOO_SMALL) { > > > - DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Unexpected > > Failure in > > > GetImageInfo. Status =3D %r\n", Status)); > > > - continue; > > > - } > > > - > > > - FmpImageInfoBuf =3D AllocateZeroPool > > (ImageInfoSize); > > > + FmpImageInfoBuf =3D FmpGetFirmwareImageDescriptor > > ( > > > + > > (EFI_FIRMWARE_MANAGEMENT_PROTOCOL *) Buffer[Index], > > > + &FmpImageInfoDescriptorVer, > > > + &FmpImageInfoCount, > > > + &DescriptorSize > > > + ); > > > if (FmpImageInfoBuf =3D=3D NULL) { > > > - DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Failed to > > get memory for > > > descriptors.\n")); > > > - continue; > > > - } > > > - > > > - FmpImageInfoBufOrg =3D FmpImageInfoBuf; > > > - PackageVersionName =3D NULL; > > > - Status =3D Fmp->GetImageInfo ( > > > - Fmp, > > > - &ImageInfoSize, // > > ImageInfoSize > > > - FmpImageInfoBuf, // > > ImageInfo > > > - &FmpImageInfoDescriptorVer, // > > DescriptorVersion > > > - &FmpImageInfoCount, // > > DescriptorCount > > > - &DescriptorSize, // > > DescriptorSize > > > - &PackageVersion, // > > PackageVersion > > > - &PackageVersionName // > > PackageVersionName > > > - ); > > > - if (EFI_ERROR (Status)) { > > > - DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Failure in > > GetImageInfo. Status > > > =3D %r\n", Status)); > > > - FreePool (FmpImageInfoBufOrg); > > > - FmpImageInfoBufOrg =3D NULL; > > > continue; > > > } > > > > > > // > > > // Check each descriptor and read from the one > > specified > > > // > > > + OrgFmpImageInfoBuf =3D FmpImageInfoBuf; > > > while (FmpImageInfoCount > 0) { > > > // > > > // If the descriptor has the IN USE bit set, > > create ESRT entry > > > otherwise ignore. > > > @@ -337,7 +460,7 @@ CreateFmpBasedEsrt ( > > > // > > > // Create ESRT entry > > > // > > > - CreateEsrtEntry (&Table, FmpImageInfoBuf, > > > FmpImageInfoDescriptorVer); > > > + CreateEsrtEntry (Table, HardwareInstances, > > > + &NumberOfDescriptors, > > > FmpImageInfoBuf, FmpImageInfoDescriptorVer); > > > } > > > FmpImageInfoCount--; > > > // > > > @@ -346,15 +469,12 @@ CreateFmpBasedEsrt ( > > > FmpImageInfoBuf =3D > > (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)(((UINT8 > > > *)FmpImageInfoBuf) + DescriptorSize); > > > } > > > > > > - if (PackageVersionName !=3D NULL) { > > > - FreePool (PackageVersionName); > > > - PackageVersionName =3D NULL; > > > - } > > > - FreePool (FmpImageInfoBufOrg); > > > - FmpImageInfoBufOrg =3D NULL; > > > + FreePool (OrgFmpImageInfoBuf); > > > + OrgFmpImageInfoBuf =3D NULL; > > > } > > > > > > - gBS->FreePool (Buffer); > > > + FreePool (Buffer); > > > + FreePool (HardwareInstances); > > > return Table; > > > } > > > > > > -- > > > 2.20.1.windows.1