From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.151; helo=mga17.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E7A9022361E4F for ; Wed, 7 Feb 2018 21:28:50 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Feb 2018 21:34:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,477,1511856000"; d="scan'208";a="25652964" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga003.jf.intel.com with ESMTP; 07 Feb 2018 21:34:34 -0800 Received: from fmsmsx151.amr.corp.intel.com (10.18.125.4) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 7 Feb 2018 21:34:34 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX151.amr.corp.intel.com (10.18.125.4) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 7 Feb 2018 21:34:33 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.124]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.125]) with mapi id 14.03.0319.002; Thu, 8 Feb 2018 13:34:31 +0800 From: "Zeng, Star" To: "Kinney, Michael D" , "edk2-devel@lists.01.org" CC: Sean Brogan , "Yao, Jiewen" , "Dong, Eric" , "Ni, Ruiyu" , "Zeng, Star" Thread-Topic: [Patch V2 1/3] MdeModulePkg/EsrtFmpDxe: Add EsrtFmpDxe module Thread-Index: AQHToGRMRZNIZc6ACkGKNfcFUOXLWKOZ/BmQ Date: Thu, 8 Feb 2018 05:34:31 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103BA3D82B@shsmsx102.ccr.corp.intel.com> References: <20180207223738.11948-1-michael.d.kinney@intel.com> <20180207223738.11948-2-michael.d.kinney@intel.com> In-Reply-To: <20180207223738.11948-2-michael.d.kinney@intel.com> 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 Subject: Re: [Patch V2 1/3] MdeModulePkg/EsrtFmpDxe: Add EsrtFmpDxe module X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Feb 2018 05:28:51 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Star Zeng Thanks, Star -----Original Message----- From: Kinney, Michael D=20 Sent: Thursday, February 8, 2018 6:38 AM To: edk2-devel@lists.01.org Cc: Kinney, Michael D ; Sean Brogan ; Yao, Jiewen ; Zeng, Star ; Dong, Eric ; Ni, Ruiyu Subject: [Patch V2 1/3] MdeModulePkg/EsrtFmpDxe: Add EsrtFmpDxe module From: Michael D Kinney https://bugzilla.tianocore.org/show_bug.cgi?id=3D802 Based on content from the following branch/commits: https://github.com/Microsoft/MS_UEFI/tree/share/MsCapsuleSupport The EsrtFmpDxe module is a lightweight version of the EsrtDxe module that p= roduces ESRT entries based only on FMP Protocol instances. Cc: Sean Brogan Cc: Jiewen Yao Cc: Star Zeng Cc: Eric Dong Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael D Kinney --- MdeModulePkg/MdeModulePkg.dsc | 1 + MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmp.c | 482 +++++++++++++++++= ++++ .../Universal/EsrtFmpDxe/EsrtFmpDebugPrint.c | 161 +++++++ MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDxe.inf | 74 ++++ MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDxe.uni | 19 + .../Universal/EsrtFmpDxe/EsrtFmpDxeExtra.uni | 18 + 6 files changed, 755 insertions(+) create mode 100644 MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmp.c create mode 100644 MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDebugPrint.c create mode 100644 MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDxe.inf create mode 100644 MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDxe.uni create mode 100644 MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDxeExtra.uni diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc = index 1c0085aee6..50002f8e3f 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -412,6 +412,7 @@ =20 MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemDxe.inf MdeModulePkg/Universal/EsrtDxe/EsrtDxe.inf + MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDxe.inf =20 MdeModulePkg/Universal/PropertiesTableAttributesDxe/PropertiesTableAttri= butesDxe.inf MdeModulePkg/Universal/FileExplorerDxe/FileExplorerDxe.inf { diff --git= a/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmp.c b/MdeModulePkg/Universal/Esr= tFmpDxe/EsrtFmp.c new file mode 100644 index 0000000000..b98430edbf --- /dev/null +++ b/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmp.c @@ -0,0 +1,482 @@ +/** @file + Publishes ESRT table from Firmware Management Protocol instances + + Copyright (c) 2016, Microsoft Corporation Copyright (c) 2018, Intel=20 + Corporation. All rights reserved.
+ + All rights reserved. + Redistribution and use in source and binary forms, with or without =20 + modification, are permitted provided that the following conditions are me= t: + 1. Redistributions of source code must retain the above copyright=20 + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright=20 + notice, this list of conditions and the following disclaimer in the=20 + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=20 + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT=20 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A = PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR=20 + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR=20 + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF=20 + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR=20 + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,=20 + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE =20 + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF= ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include +#include +#include +#include #include=20 + +#include +#include +#include +#include #include =20 +#include + +// +// Print ESRT to debug console +// +VOID +EFIAPI +PrintTable ( + IN EFI_SYSTEM_RESOURCE_TABLE *Table + ); + +// +// Number of ESRT entries to grow by each time we run out of room //=20 +#define GROWTH_STEP 10 + +// +// Module globals. +// +EFI_EVENT mEsrtReadyToBootEvent; +EFI_SYSTEM_RESOURCE_TABLE *mTable =3D NULL; +BOOLEAN mEsrtInstalled =3D FALSE; +EFI_EVENT mFmpInstallEvent; +VOID *mFmpInstallEventRegistration =3D NULL; + +/** + Install EFI System Resource Table into the UEFI Configuration Table + + @return Status code. + +**/ +EFI_STATUS +InstallEfiSystemResourceTableInUefiConfigurationTable ( + VOID + ) +{ + EFI_STATUS Status; + + Status =3D EFI_SUCCESS; + if (!mEsrtInstalled) { + if (mTable =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Can't install ESRT table because i= t is NULL. \n")); + Status =3D EFI_OUT_OF_RESOURCES; + } else if (mTable->FwResourceCount =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Can't install ESRT table because i= t has zero Entries. \n")); + Status =3D EFI_UNSUPPORTED; + } else { + // + // Install the pointer into config table + // + Status =3D gBS->InstallConfigurationTable (&gEfiSystemResourceTableG= uid, mTable); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Can't install ESRT table. Statu= s: %r. \n", Status)); + } else { + DEBUG ((DEBUG_INFO, "EsrtFmpDxe: Installed ESRT table. \n")); + mEsrtInstalled =3D TRUE; + } + } + } + return Status; +} + +/** + Return if this FMP is a system FMP or a device FMP, based upon FmpImageI= nfo. + + @param[in] FmpImageInfo A pointer to EFI_FIRMWARE_IMAGE_DESCRIPTOR + + @return TRUE It is a system FMP. + @return FALSE It is a device FMP. +**/ +BOOLEAN +IsSystemFmp ( + IN EFI_FIRMWARE_IMAGE_DESCRIPTOR *FmpImageInfo + ) +{ + GUID *Guid; + UINTN Count; + UINTN Index; + + Guid =3D PcdGetPtr (PcdSystemFmpCapsuleImageTypeIdGuid); + Count =3D PcdGetSize (PcdSystemFmpCapsuleImageTypeIdGuid) /=20 + sizeof(GUID); + + for (Index =3D 0; Index < Count; Index++, Guid++) { + if (CompareGuid (&FmpImageInfo->ImageTypeId, Guid)) { + return TRUE; + } + } + + return FALSE; +} + +/** + 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. + + @return Status code. + +**/ +EFI_STATUS +EFIAPI +CreateEsrtEntry ( + IN EFI_FIRMWARE_IMAGE_DESCRIPTOR *FmpImageInfoBuf, + IN UINT32 FmpVersion + ) +{ + UINTN Index; + EFI_SYSTEM_RESOURCE_ENTRY *Entry; + UINTN NewSize; + EFI_SYSTEM_RESOURCE_TABLE *NewTable; + + Index =3D 0; + Entry =3D NULL; + + // + // Get our ESRT table. This should never be null at this point // =20 + if (mTable =3D=3D NULL) { + return EFI_DEVICE_ERROR; + } + + Entry =3D (EFI_SYSTEM_RESOURCE_ENTRY *)(mTable + 1); // // Make sure=20 + Guid isn't already in the list // for (Index =3D 0; Index <=20 + mTable->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; + } + Entry++; + } + + // + // Grow table if needed + // + if (mTable->FwResourceCount >=3D mTable->FwResourceCountMax) { + // + // Can't grow table after installed. + // Only because didn't add support for this. + // Would need to re-install ESRT in system table if wanted to support + // + if (mEsrtInstalled) { + DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Failed to install entry because ES= RT table needed to grow after table already installed. \n")); + return EFI_OUT_OF_RESOURCES; + } + + NewSize =3D ((mTable->FwResourceCountMax + GROWTH_STEP) * sizeof (EFI= _SYSTEM_RESOURCE_ENTRY)) + sizeof (EFI_SYSTEM_RESOURCE_TABLE); + NewTable =3D AllocateRuntimeZeroPool (NewSize); + if (NewTable =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Failed to allocate memory larger t= able for ESRT. \n")); + return EFI_OUT_OF_RESOURCES; + } + // + // Copy the whole old table into new table buffer + // + CopyMem ( + NewTable, + mTable, + ((mTable->FwResourceCountMax) * sizeof (EFI_SYSTEM_RESOURCE_ENTRY)) = + sizeof (EFI_SYSTEM_RESOURCE_TABLE) + ); + // + // Update max + // + NewTable->FwResourceCountMax =3D NewTable->FwResourceCountMax + GROWTH= _STEP; + // + // Free old table + // + FreePool (mTable); + // + // Reassign pointer to new table. + // + mTable =3D NewTable; + } + + // + // ESRT table has enough room for the new entry so add new entry // =20 + Entry =3D (EFI_SYSTEM_RESOURCE_ENTRY *)(((UINT8 *)mTable) + sizeof=20 + (EFI_SYSTEM_RESOURCE_TABLE)); // // Move to the location of new=20 + entry // Entry =3D Entry + mTable->FwResourceCount; // // Increment=20 + resource count // mTable->FwResourceCount++; + + CopyGuid (&Entry->FwClass, &FmpImageInfoBuf->ImageTypeId); + + if (IsSystemFmp (FmpImageInfoBuf)) { + DEBUG ((DEBUG_INFO, "EsrtFmpDxe: Found an ESRT entry for a System Devi= ce.\n")); + Entry->FwType =3D (UINT32)(ESRT_FW_TYPE_SYSTEMFIRMWARE); + } else { + Entry->FwType =3D (UINT32)(ESRT_FW_TYPE_DEVICEFIRMWARE); + } + + Entry->FwVersion =3D FmpImageInfoBuf->Version; =20 + Entry->LowestSupportedFwVersion =3D 0; Entry->CapsuleFlags =3D 0; =20 + Entry->LastAttemptVersion =3D 0; Entry->LastAttemptStatus =3D 0; + + // + // VERSION 2 has Lowest Supported + // + if (FmpVersion >=3D 2) { + Entry->LowestSupportedFwVersion =3D=20 + FmpImageInfoBuf->LowestSupportedImageVersion; + } + + // + // VERSION 3 supports last attempt values // if (FmpVersion >=3D 3) { + Entry->LastAttemptVersion =3D FmpImageInfoBuf->LastAttemptVersion; + Entry->LastAttemptStatus =3D FmpImageInfoBuf->LastAttemptStatus; + } + + return EFI_SUCCESS; +} + +/** + Notify function for every Firmware Management Protocol being installed. + Get the descriptors from FMP Instance and create ESRT entries (ESRE) + + @param[in] Event The Event that is being processed. + @param[in] Context The Event Context. + +**/ +VOID +EFIAPI +FmpInstallProtocolNotify ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + UINTN BufferSize; + 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; + + Status =3D EFI_SUCCESS; + Handle =3D 0; + BufferSize =3D 0; + PackageVersionName =3D NULL; + FmpImageInfoBuf =3D NULL; + FmpImageInfoBufOrg =3D NULL; + Fmp =3D NULL; + + DEBUG ((DEBUG_INFO, "FMP Installed Notify\n")); while (TRUE) { + BufferSize =3D sizeof (EFI_HANDLE); + Status =3D gBS->LocateHandle (ByRegisterNotify, NULL, mFmpInstallEvent= Registration, &BufferSize, &Handle); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "EsrtFmpDxe: Failed to Locate handle from notify= value. Status: %r\n", Status)); + return; + } + + Status =3D gBS->HandleProtocol (Handle, &gEfiFirmwareManagementProtoco= lGuid, (VOID **)&Fmp); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Failed to get FMP for a handle 0x%= x\n", Handle)); + continue; + } + ImageInfoSize =3D 0; + + Status =3D Fmp->GetImageInfo ( + Fmp, // FMP Pointer + &ImageInfoSize, // Buffer Size (in this c= ase 0) + NULL, // NULL so we can get siz= e + &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 NULL; + FmpImageInfoBuf =3D AllocateZeroPool (ImageInfoSize); + if (FmpImageInfoBuf =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Failed to get memory for descripto= rs.\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)); + goto CleanUp; + } + + // + // Check each descriptor and read from the one specified + // + while (FmpImageInfoCount > 0) { + // + // If the descriptor has the IN USE bit set, create ESRT entry other= wise ignore. + // + if ((FmpImageInfoBuf->AttributesSetting & FmpImageInfoBuf->Attribute= sSupported & IMAGE_ATTRIBUTE_IN_USE) =3D=3D IMAGE_ATTRIBUTE_IN_USE) { + // + // Create ESRT entry + // + CreateEsrtEntry (FmpImageInfoBuf, FmpImageInfoDescriptorVer); + } + FmpImageInfoCount--; + // + // Increment the buffer pointer ahead by the size of the descriptor + // + FmpImageInfoBuf =3D (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)(((UINT8 *)FmpI= mageInfoBuf) + DescriptorSize); + } + + if (PackageVersionName !=3D NULL) { + FreePool (PackageVersionName); + PackageVersionName =3D NULL; + } + if (FmpImageInfoBufOrg !=3D NULL) { + FreePool (FmpImageInfoBufOrg); + FmpImageInfoBufOrg =3D NULL; + } + } + +CleanUp: + if (FmpImageInfoBufOrg !=3D NULL) { + FreePool (FmpImageInfoBufOrg); + } + return; +} + +/** + Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. This=20 +is used to + install the Efi System Resource Table. + + @param[in] Event The Event that is being processed. + @param[in] Context The Event Context. + +**/ +VOID +EFIAPI +EsrtReadyToBootEventNotify ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + InstallEfiSystemResourceTableInUefiConfigurationTable (); + + // + // Print table on debug builds + // + DEBUG_CODE_BEGIN (); + PrintTable (mTable); + DEBUG_CODE_END (); +} + +/** + The module Entry Point of the Efi System Resource Table DXE driver. + + @param[in] ImageHandle The firmware allocated handle for the EFI image= . + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Other Some error occurs when executing this entry point. + +**/ +EFI_STATUS +EFIAPI +EsrtFmpEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + // + // Allocate Memory for table + // + mTable =3D AllocateRuntimeZeroPool ( + (GROWTH_STEP * sizeof (EFI_SYSTEM_RESOURCE_ENTRY)) + sizeof (= EFI_SYSTEM_RESOURCE_TABLE) + ); + ASSERT (mTable !=3D NULL); + if (mTable =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Failed to allocate memory for ESRT.\= n")); + return EFI_OUT_OF_RESOURCES; + } + + mTable->FwResourceCount =3D 0; + mTable->FwResourceCountMax =3D GROWTH_STEP; mTable->FwResourceVersion = =20 + =3D EFI_SYSTEM_RESOURCE_TABLE_FIRMWARE_RESOURCE_VERSION; + + // + // Register notify function for all FMP installed // =20 + mFmpInstallEvent =3D EfiCreateProtocolNotifyEvent ( + &gEfiFirmwareManagementProtocolGuid, + TPL_CALLBACK, + FmpInstallProtocolNotify, + NULL, + &mFmpInstallEventRegistration + ); + + ASSERT (mFmpInstallEvent !=3D NULL); + + if (mFmpInstallEvent =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Failed to Create Protocol Notify=20 + Event for FMP.\n")); } + + // + // Register notify function to install ESRT on ReadyToBoot Event. + // + Status =3D EfiCreateEventReadyToBootEx ( + TPL_CALLBACK, + EsrtReadyToBootEventNotify, + NULL, + &mEsrtReadyToBootEvent + ); + + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Failed to register for ready to=20 + boot\n")); } + + return Status; +} diff --git a/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDebugPrint.c b/MdeMod= ulePkg/Universal/EsrtFmpDxe/EsrtFmpDebugPrint.c new file mode 100644 index 0000000000..b4e5135e05 --- /dev/null +++ b/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDebugPrint.c @@ -0,0 +1,161 @@ +/** @file + Publishes ESRT table from Firmware Management Protocol instances + + Copyright (c) 2016, Microsoft Corporation Copyright (c) 2018, Intel=20 + Corporation. All rights reserved.
+ + All rights reserved. + Redistribution and use in source and binary forms, with or without =20 + modification, are permitted provided that the following conditions are me= t: + 1. Redistributions of source code must retain the above copyright=20 + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright=20 + notice, this list of conditions and the following disclaimer in the=20 + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=20 + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT=20 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A = PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR=20 + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR=20 + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF=20 + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR=20 + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,=20 + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE =20 + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF= ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include +#include +#include +#include +#include #include=20 + + +/** + Function to print a single ESRT Entry (ESRE) to the debug console + + Print Format: + | 00000000-0000-0000-0000-000000000000 | SSSSSSSSSSSS | 0x00000000 |=20 + 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | + + @param[in] Entry - Pointer to an ESRE entry + @retval EFI_SUCCESS + EFI_INVALID_PARAMETER **/ EFI_STATUS EFIAPI=20 +PrintOutEsrtEntry ( + IN EFI_SYSTEM_RESOURCE_ENTRY *Entry + ) +{ + if (Entry =3D=3D NULL) { + DEBUG ((DEBUG_INFO, "| ERROR: Invalid resource entry pointer = ")); + DEBUG ((DEBUG_INFO, " = |\n")); + return EFI_INVALID_PARAMETER; + } + + // + // GUID FW Class (36 chars plus table formatting) // DEBUG=20 + ((DEBUG_INFO, "| %g |", &Entry->FwClass)); + + // + // Entry Type (12 chars plus table formatting) // switch=20 + (Entry->FwType) { case (ESRT_FW_TYPE_SYSTEMFIRMWARE) : + DEBUG ((DEBUG_INFO, " System FW |")); + break; + case (ESRT_FW_TYPE_DEVICEFIRMWARE) : + DEBUG ((DEBUG_INFO, " Device FW |")); + break; + case (ESRT_FW_TYPE_UEFIDRIVER) : + DEBUG ((DEBUG_INFO, " Uefi Driver |")); + break; + case (ESRT_FW_TYPE_UNKNOWN) : + DEBUG ((DEBUG_INFO, " Unknown Type |")); + break; + default: + DEBUG ((DEBUG_INFO, " ? 0x%8X |", Entry->FwType)); + break; + } + + // + // FW Version (10 char UINT32 string plus table formatting) //=20 + Lowest Supported Version (10 char UINT32 string plus table formatting) =20 + // Capsule Flags (10 char UINT32 string plus table formatting) //=20 + Last Attempt Version (10 char UINT32 string plus table formatting) //=20 + Last Attempt Status (10 char UINT32 string plus table formatting) // =20 + DEBUG ((DEBUG_INFO, + " 0x%8X | 0x%8X | 0x%8X | 0x%8X | 0x%8X |\n", + Entry->FwVersion, + Entry->LowestSupportedFwVersion, + Entry->CapsuleFlags, + Entry->LastAttemptVersion, + Entry->LastAttemptStatus + )); + + return EFI_SUCCESS; +} + +/** + Function to print the ESRT table to the debug console + + @param[in] Table - Pointer to the ESRT table **/ VOID EFIAPI=20 +PrintTable ( + IN EFI_SYSTEM_RESOURCE_TABLE *Table + ) +{ + EFI_SYSTEM_RESOURCE_ENTRY *Entry; + UINTN Index; + + Entry =3D (EFI_SYSTEM_RESOURCE_ENTRY *)(((UINT8 *)Table) + sizeof=20 + (EFI_SYSTEM_RESOURCE_TABLE)); + + // + // Print ESRT table information + // + DEBUG ((DEBUG_INFO, "ESRT Table Information:\n")); if (Table =3D=3D=20 + NULL) { + DEBUG ((DEBUG_INFO, "ERROR: Invalid table pointer\n")); + return; + } + + DEBUG ((DEBUG_INFO, "+--------------------------------------------------= ------+\n")); + DEBUG ((DEBUG_INFO, "| Firmware Resource Count : 0x%08x = |\n", Table->FwResourceCount)); + DEBUG ((DEBUG_INFO, "| Firmware Resource Count Max : 0x%08x = |\n", Table->FwResourceCountMax)); + DEBUG ((DEBUG_INFO, "| Firmware Resource Entry Version : 0x%016x |\n",= Table->FwResourceVersion)); + DEBUG ((DEBUG_INFO,=20 + "+--------------------------------------------------------+\n")); + + // + // Print table entry information + // + DEBUG ((DEBUG_INFO, "ESRT Table Entries:\n")); if=20 + (Table->FwResourceVersion !=3D EFI_SYSTEM_RESOURCE_TABLE_FIRMWARE_RESOURC= E_VERSION) { + DEBUG ((DEBUG_INFO, "ERROR: Unsupported Resource Entry Version\n")); + return; + } + + DEBUG ((DEBUG_INFO,=20 + "+--------------------------------------+--------------+------------") + ); DEBUG ((DEBUG_INFO,=20 + "+------------+------------+------------+------------+\n")); + DEBUG ((DEBUG_INFO, "| | = | ")); + DEBUG ((DEBUG_INFO, "| Lowest | | Last | Last = |\n")); + DEBUG ((DEBUG_INFO, "| | Firmware = | ")); + DEBUG ((DEBUG_INFO, "| Supported | Capsule | Attempted | Attempted = |\n")); + DEBUG ((DEBUG_INFO, "| CLASS GUID | Type = | Version ")); + DEBUG ((DEBUG_INFO, "| Version | Flags | Version | Status = |\n")); + DEBUG ((DEBUG_INFO,=20 + "+--------------------------------------+--------------+------------") + ); DEBUG ((DEBUG_INFO,=20 + "+------------+------------+------------+------------+\n")); + + for (Index =3D 0; Index < Table->FwResourceCount; Index++) { + PrintOutEsrtEntry (&(Entry[Index])); } + + DEBUG ((DEBUG_INFO,=20 +"+--------------------------------------+--------------+------------")) +; + DEBUG ((DEBUG_INFO,=20 +"+------------+------------+------------+------------+\n")); +} + diff --git a/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDxe.inf b/MdeModulePk= g/Universal/EsrtFmpDxe/EsrtFmpDxe.inf new file mode 100644 index 0000000000..6da5ce5b04 --- /dev/null +++ b/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDxe.inf @@ -0,0 +1,74 @@ +## @file +# Publishes ESRT table from Firmware Management Protocol instances # #=20 +Copyright (c) 2016, Microsoft Corporation # Copyright (c) 2018, Intel=20 +Corporation. All rights reserved.
# # All rights reserved. +# Redistribution and use in source and binary forms, with or without #=20 +modification, are permitted provided that the following conditions are met= : +# 1. Redistributions of source code must retain the above copyright=20 +notice, # this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright=20 +notice, # this list of conditions and the following disclaimer in the=20 +documentation # and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=20 +"AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT=20 +LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A = PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR=20 +ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR=20 +CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF=20 +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR=20 +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY,=20 +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE #=20 +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF = # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D EsrtFmpDxe + MODULE_UNI_FILE =3D EsrtFmpDxe.uni + FILE_GUID =3D FF626DA9-17EE-4949-A8B8-B10FA0044E9F + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D EsrtFmpEntryPoint + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + EsrtFmp.c + EsrtFmpDebugPrint.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + UefiDriverEntryPoint + BaseLib + BaseMemoryLib + MemoryAllocationLib + UefiLib + UefiBootServicesTableLib + DebugLib + PcdLib + +[Protocols] + gEfiFirmwareManagementProtocolGuid ## CONSUMES + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdSystemFmpCapsuleImageTypeIdGuid ##=20 +CONSUMES + +[Guids] + gEfiSystemResourceTableGuid ## PRODUCES + +[Depex] + TRUE + +[UserExtensions.TianoCore."ExtraFiles"] + EsrtFmpDxeExtra.uni diff --git a/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDxe.uni b/MdeModulePk= g/Universal/EsrtFmpDxe/EsrtFmpDxe.uni new file mode 100644 index 0000000000..fdad5b5bd9 --- /dev/null +++ b/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDxe.uni @@ -0,0 +1,19 @@ +// /** @file +// Publishes ESRT table from Firmware Management Protocol instances //=20 +// Copyright (c) 2018, Intel Corporation. All rights reserved.
//=20 +// This program and the accompanying materials // are licensed and made=20 +available under the terms and conditions of the BSD License // which=20 +accompanies this distribution. The full text of the license may be=20 +found at // http://opensource.org/licenses/bsd-license.php +// +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"=20 +BASIS, // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRES= S OR IMPLIED. +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "Publishes ESRT ta= ble from Firmware Management Protocol instances" + +#string STR_MODULE_DESCRIPTION #language en-US "This driver publi= shes the ESRT table from Firmware Management Protocol instances.

\n" + "The ESRT table is= published when the Ready To Boot event is signaled.
" diff --git a/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDxeExtra.uni b/MdeMod= ulePkg/Universal/EsrtFmpDxe/EsrtFmpDxeExtra.uni new file mode 100644 index 0000000000..2c6f6dab9c --- /dev/null +++ b/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDxeExtra.uni @@ -0,0 +1,18 @@ +// /** @file +// EsrtFmpDxe Localized Strings and Content // // Copyright (c) 2018,=20 +Intel Corporation. All rights reserved.
// // This program and the=20 +accompanying materials // are licensed and made available under the=20 +terms and conditions of the BSD License // which accompanies this=20 +distribution. The full text of the license may be found at //=20 +http://opensource.org/licenses/bsd-license.php +// +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"=20 +BASIS, // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRES= S OR IMPLIED. +// +// **/ + +#string STR_PROPERTIES_MODULE_NAME +#language en-US +"ESRT FMP DXE Driver" -- 2.14.2.windows.3