From nobody Wed May 8 21:27:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1511950504327557.5758880147425; Wed, 29 Nov 2017 02:15:04 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3F0D5203564D5; Wed, 29 Nov 2017 02:10:38 -0800 (PST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 ED39B203564AF for ; Wed, 29 Nov 2017 02:10:36 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2017 02:15:00 -0800 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.46]) by fmsmga001.fm.intel.com with ESMTP; 29 Nov 2017 02:15:00 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,472,1505804400"; d="scan'208";a="8383175" From: Star Zeng To: edk2-devel@lists.01.org Date: Wed, 29 Nov 2017 18:14:54 +0800 Message-Id: <1511950497-9088-2-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1511950497-9088-1-git-send-email-star.zeng@intel.com> References: <1511950497-9088-1-git-send-email-star.zeng@intel.com> Subject: [edk2] [PATCH V2 1/4] MdePkg PiFirmwareVolume.h: Add USED_SIZE FV_EXT_TYPE definitions X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The definitions are introduced by PI 1.6 spec. The EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE can be used to find out how many EFI_FVB2_ERASE_POLARITY bytes are at the end of the FV. When the FV gets shadowed into memory you only need to copy the used bytes into memory and fill the rest of the memory buffer with the erase value. Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Liming Gao --- MdePkg/Include/Pi/PiFirmwareVolume.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/MdePkg/Include/Pi/PiFirmwareVolume.h b/MdePkg/Include/Pi/PiFir= mwareVolume.h index 79fde131902e..2482a7f96add 100644 --- a/MdePkg/Include/Pi/PiFirmwareVolume.h +++ b/MdePkg/Include/Pi/PiFirmwareVolume.h @@ -1,7 +1,7 @@ /** @file The firmware volume related definitions in PI. =20 - Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. =20 @par Revision Reference: - PI Version 1.3 + PI Version 1.6 =20 **/ =20 @@ -231,4 +231,23 @@ typedef struct { /// } EFI_FIRMWARE_VOLUME_EXT_ENTRY_GUID_TYPE; =20 +#define EFI_FV_EXT_TYPE_USED_SIZE_TYPE 0x03 + +/// +/// The EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE can be used to find +/// out how many EFI_FVB2_ERASE_POLARITY bytes are at the end of the FV. +/// +typedef struct { + /// + /// Standard extension entry, with the type EFI_FV_EXT_TYPE_USED_SIZE_TY= PE. + /// + EFI_FIRMWARE_VOLUME_EXT_ENTRY Hdr; + /// + /// The number of bytes of the FV that are in uses. The remaining + /// EFI_FIRMWARE_VOLUME_HEADER FvLength minus UsedSize bytes in + /// the FV must contain the value implied by EFI_FVB2_ERASE_POLARITY. + /// + UINT32 UsedSize; +} EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE; + #endif --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Wed May 8 21:27:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1511950506465628.4057904950233; Wed, 29 Nov 2017 02:15:06 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7F117203564D7; Wed, 29 Nov 2017 02:10:38 -0800 (PST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 C587E203564AF for ; Wed, 29 Nov 2017 02:10:37 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2017 02:15:01 -0800 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.46]) by fmsmga001.fm.intel.com with ESMTP; 29 Nov 2017 02:15:00 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,472,1505804400"; d="scan'208";a="8383187" From: Star Zeng To: edk2-devel@lists.01.org Date: Wed, 29 Nov 2017 18:14:55 +0800 Message-Id: <1511950497-9088-3-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1511950497-9088-1-git-send-email-star.zeng@intel.com> References: <1511950497-9088-1-git-send-email-star.zeng@intel.com> Subject: [edk2] [PATCH V2 2/4] MdeModulePkg PeiCore: Support USED_SIZE FV_EXT_TYPE X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The USED_SIZE FV_EXT_TYPE is introduced by PI 1.6 spec. The EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE can be used to find out how many EFI_FVB2_ERASE_POLARITY bytes are at the end of the FV. When the FV gets shadowed into memory you only need to copy the used bytes into memory and fill the rest of the memory buffer with the erase value. Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Liming Gao --- MdeModulePkg/Core/Pei/FwVol/FwVol.c | 90 +++++++++++++++++++++++++++++++++= ++-- 1 file changed, 87 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Core/Pei/FwVol/FwVol.c b/MdeModulePkg/Core/Pei/Fw= Vol/FwVol.c index 3da90f95312d..7cb295c2c679 100644 --- a/MdeModulePkg/Core/Pei/FwVol/FwVol.c +++ b/MdeModulePkg/Core/Pei/FwVol/FwVol.c @@ -1295,6 +1295,68 @@ PeiFfsGetVolumeInfo ( } =20 /** + Find USED_SIZE FV_EXT_TYPE entry in FV extension header and get the FV u= sed size. + + @param[in] FvHeader Pointer to FV header. + @param[out] FvUsedSize Pointer to FV used size returned, + only valid if USED_SIZE FV_EXT_TYPE entry is f= ound. + @param[out] EraseByte Pointer to erase byte returned, + only valid if USED_SIZE FV_EXT_TYPE entry is f= ound. + + @retval TRUE USED_SIZE FV_EXT_TYPE entry is found, + FV used size and erase byte are returned. + @retval FALSE No USED_SIZE FV_EXT_TYPE entry found. + +**/ +BOOLEAN +GetFvUsedSize ( + IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader, + OUT UINT32 *FvUsedSize, + OUT UINT8 *EraseByte + ) +{ + UINT16 ExtHeaderOffset; + EFI_FIRMWARE_VOLUME_EXT_HEADER *ExtHeader; + EFI_FIRMWARE_VOLUME_EXT_ENTRY *ExtEntryList; + EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE *ExtEntryUsedSize; + + ExtHeaderOffset =3D ReadUnaligned16 (&FvHeader->ExtHeaderOffset); + if (ExtHeaderOffset !=3D 0) { + ExtHeader =3D (EFI_FIRMWARE_VOLUME_EXT_HEADER *) ((UINT8 *) FvHeade= r + ExtHeaderOffset); + ExtEntryList =3D (EFI_FIRMWARE_VOLUME_EXT_ENTRY *) (ExtHeader + 1); + while ((UINTN) ExtEntryList < ((UINTN) ExtHeader + ReadUnaligned32 (&E= xtHeader->ExtHeaderSize))) { + if (ReadUnaligned16 (&ExtEntryList->ExtEntryType) =3D=3D EFI_FV_EXT_= TYPE_USED_SIZE_TYPE) { + // + // USED_SIZE FV_EXT_TYPE entry is found. + // + ExtEntryUsedSize =3D (EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE= *) ExtEntryList; + *FvUsedSize =3D ReadUnaligned32 (&ExtEntryUsedSize->UsedSize); + if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ERASE_POLA= RITY) !=3D 0) { + *EraseByte =3D 0xFF; + } else { + *EraseByte =3D 0; + } + DEBUG (( + DEBUG_INFO, + "FV at 0x%x has 0x%x used size, and erase byte is 0x%02x\n", + FvHeader, + *FvUsedSize, + *EraseByte + )); + return TRUE; + } + ExtEntryList =3D (EFI_FIRMWARE_VOLUME_EXT_ENTRY *) + ((UINT8 *) ExtEntryList + ReadUnaligned16 (&ExtEntryL= ist->ExtEntrySize)); + } + } + + // + // No USED_SIZE FV_EXT_TYPE entry found. + // + return FALSE; +} + +/** Get Fv image from the FV type file, then install FV INFO(2) ppi, Build F= V hob. =20 @param PrivateData PeiCore's private data structure @@ -1326,7 +1388,9 @@ ProcessFvFile ( EFI_FV_FILE_INFO FileInfo; UINT64 FvLength; UINT32 AuthenticationStatus; - =20 + UINT32 FvUsedSize; + UINT8 EraseByte; + // // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already // been extracted. @@ -1391,8 +1455,16 @@ ProcessFvFile ( FvAlignment =3D 8; } =20 + DEBUG (( + DEBUG_INFO, + "%a() FV at 0x%x, FvAlignment required is 0x%x\n", + __FUNCTION__, + FvHeader, + FvAlignment + )); + // - // Check FvImage + // Check FvImage alignment. // if ((UINTN) FvHeader % FvAlignment !=3D 0) { FvLength =3D ReadUnaligned64 (&FvHeader->FvLength); @@ -1400,7 +1472,19 @@ ProcessFvFile ( if (NewFvBuffer =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } - CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength); + if (GetFvUsedSize (FvHeader, &FvUsedSize, &EraseByte)) { + // + // Copy the used bytes and fill the rest with the erase value. + // + CopyMem (NewFvBuffer, FvHeader, (UINTN) FvUsedSize); + SetMem ( + (UINT8 *) NewFvBuffer + FvUsedSize, + (UINTN) (FvLength - FvUsedSize), + EraseByte + ); + } else { + CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength); + } FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer; } } --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Wed May 8 21:27:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1511950510298674.3711472381527; Wed, 29 Nov 2017 02:15:10 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E35A520359E86; Wed, 29 Nov 2017 02:10:42 -0800 (PST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 B2523203564D9 for ; Wed, 29 Nov 2017 02:10:38 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2017 02:15:02 -0800 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.46]) by fmsmga001.fm.intel.com with ESMTP; 29 Nov 2017 02:15:01 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,472,1505804400"; d="scan'208";a="8383207" From: Star Zeng To: edk2-devel@lists.01.org Date: Wed, 29 Nov 2017 18:14:56 +0800 Message-Id: <1511950497-9088-4-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1511950497-9088-1-git-send-email-star.zeng@intel.com> References: <1511950497-9088-1-git-send-email-star.zeng@intel.com> Subject: [edk2] [PATCH V2 3/4] MdeModulePkg DxeCore: Check FvImage alignment X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" No need to allocate aligned buffer if FvImage has been at required alignment. Then the code logic will be aligned with ProcessFvFile() in MdeModulePkg/Core/Pei/FwVol/FwVol.c. Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Liming Gao --- MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c | 32 ++++++++++++++++-------= ---- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c b/MdeModulePkg/C= ore/Dxe/Dispatcher/Dispatcher.c index 5eee71bb2cd3..c7b9224c0e33 100644 --- a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c @@ -1023,32 +1023,38 @@ CoreProcessFvImageFile ( // can be aligned on any power-of-two boundary. A weakly aligned volum= e can not be moved from // its initial linked location and maintain its alignment. // - if ((FvHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT) !=3D EFI_FVB2_WEA= K_ALIGNMENT) { + if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_WEAK_ALIGNMENT= ) !=3D EFI_FVB2_WEAK_ALIGNMENT) { // // Get FvHeader alignment // - FvAlignment =3D 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >>= 16); + FvAlignment =3D 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI= _FVB2_ALIGNMENT) >> 16); // // FvAlignment must be greater than or equal to 8 bytes of the minim= um FFS alignment value. // if (FvAlignment < 8) { FvAlignment =3D 8; } + // - // Allocate the aligned buffer for the FvImage. + // Check FvImage alignment. // - AlignedBuffer =3D AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSiz= e), (UINTN) FvAlignment); - if (AlignedBuffer =3D=3D NULL) { - FreePool (Buffer); - return EFI_OUT_OF_RESOURCES; - } else { + if ((UINTN) FvHeader % FvAlignment !=3D 0) { // - // Move FvImage into the aligned buffer and release the original b= uffer. + // Allocate the aligned buffer for the FvImage. // - CopyMem (AlignedBuffer, Buffer, BufferSize); - FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer; - CoreFreePool (Buffer); - Buffer =3D NULL; + AlignedBuffer =3D AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferS= ize), (UINTN) FvAlignment); + if (AlignedBuffer =3D=3D NULL) { + FreePool (Buffer); + return EFI_OUT_OF_RESOURCES; + } else { + // + // Move FvImage into the aligned buffer and release the original= buffer. + // + CopyMem (AlignedBuffer, Buffer, BufferSize); + FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer; + CoreFreePool (Buffer); + Buffer =3D NULL; + } } } // --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Wed May 8 21:27:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1511950517712536.899228417764; Wed, 29 Nov 2017 02:15:17 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9C9EB20359E97; Wed, 29 Nov 2017 02:10:43 -0800 (PST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 AE555203564D2 for ; Wed, 29 Nov 2017 02:10:39 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2017 02:15:03 -0800 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.46]) by fmsmga001.fm.intel.com with ESMTP; 29 Nov 2017 02:15:02 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,472,1505804400"; d="scan'208";a="8383223" From: Star Zeng To: edk2-devel@lists.01.org Date: Wed, 29 Nov 2017 18:14:57 +0800 Message-Id: <1511950497-9088-5-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1511950497-9088-1-git-send-email-star.zeng@intel.com> References: <1511950497-9088-1-git-send-email-star.zeng@intel.com> Subject: [edk2] [PATCH V2 4/4] MdeModulePkg DxeCore: Support USED_SIZE FV_EXT_TYPE X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The USED_SIZE FV_EXT_TYPE is introduced by PI 1.6 spec. The EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE can be used to find out how many EFI_FVB2_ERASE_POLARITY bytes are at the end of the FV. When the FV gets shadowed into memory you only need to copy the used bytes into memory and fill the rest of the memory buffer with the erase value. Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Liming Gao --- MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c | 84 +++++++++++++++++++++++= +++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c b/MdeModulePkg/C= ore/Dxe/Dispatcher/Dispatcher.c index c7b9224c0e33..088cd8106313 100644 --- a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c @@ -938,7 +938,67 @@ FvFoundInHobFv2 ( return FALSE; } =20 +/** + Find USED_SIZE FV_EXT_TYPE entry in FV extension header and get the FV u= sed size. + + @param[in] FvHeader Pointer to FV header. + @param[out] FvUsedSize Pointer to FV used size returned, + only valid if USED_SIZE FV_EXT_TYPE entry is f= ound. + @param[out] EraseByte Pointer to erase byte returned, + only valid if USED_SIZE FV_EXT_TYPE entry is f= ound. =20 + @retval TRUE USED_SIZE FV_EXT_TYPE entry is found, + FV used size and erase byte are returned. + @retval FALSE No USED_SIZE FV_EXT_TYPE entry found. + +**/ +BOOLEAN +GetFvUsedSize ( + IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader, + OUT UINT32 *FvUsedSize, + OUT UINT8 *EraseByte + ) +{ + UINT16 ExtHeaderOffset; + EFI_FIRMWARE_VOLUME_EXT_HEADER *ExtHeader; + EFI_FIRMWARE_VOLUME_EXT_ENTRY *ExtEntryList; + EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE *ExtEntryUsedSize; + + ExtHeaderOffset =3D ReadUnaligned16 (&FvHeader->ExtHeaderOffset); + if (ExtHeaderOffset !=3D 0) { + ExtHeader =3D (EFI_FIRMWARE_VOLUME_EXT_HEADER *) ((UINT8 *) FvHeade= r + ExtHeaderOffset); + ExtEntryList =3D (EFI_FIRMWARE_VOLUME_EXT_ENTRY *) (ExtHeader + 1); + while ((UINTN) ExtEntryList < ((UINTN) ExtHeader + ReadUnaligned32 (&E= xtHeader->ExtHeaderSize))) { + if (ReadUnaligned16 (&ExtEntryList->ExtEntryType) =3D=3D EFI_FV_EXT_= TYPE_USED_SIZE_TYPE) { + // + // USED_SIZE FV_EXT_TYPE entry is found. + // + ExtEntryUsedSize =3D (EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE= *) ExtEntryList; + *FvUsedSize =3D ReadUnaligned32 (&ExtEntryUsedSize->UsedSize); + if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ERASE_POLA= RITY) !=3D 0) { + *EraseByte =3D 0xFF; + } else { + *EraseByte =3D 0; + } + DEBUG (( + DEBUG_INFO, + "FV at 0x%x has 0x%x used size, and erase byte is 0x%02x\n", + FvHeader, + *FvUsedSize, + *EraseByte + )); + return TRUE; + } + ExtEntryList =3D (EFI_FIRMWARE_VOLUME_EXT_ENTRY *) + ((UINT8 *) ExtEntryList + ReadUnaligned16 (&ExtEntryL= ist->ExtEntrySize)); + } + } + + // + // No USED_SIZE FV_EXT_TYPE entry found. + // + return FALSE; +} =20 /** Get the driver from the FV through driver name, and produce a FVB protoc= ol on FvHandle. @@ -968,6 +1028,8 @@ CoreProcessFvImageFile ( EFI_FIRMWARE_VOLUME_HEADER *FvHeader; UINT32 FvAlignment; EFI_DEVICE_PATH_PROTOCOL *FvFileDevicePath; + UINT32 FvUsedSize; + UINT8 EraseByte; =20 // // Read the first (and only the first) firmware volume section @@ -1035,6 +1097,14 @@ CoreProcessFvImageFile ( FvAlignment =3D 8; } =20 + DEBUG (( + DEBUG_INFO, + "%a() FV at 0x%x, FvAlignment required is 0x%x\n", + __FUNCTION__, + FvHeader, + FvAlignment + )); + // // Check FvImage alignment. // @@ -1050,7 +1120,19 @@ CoreProcessFvImageFile ( // // Move FvImage into the aligned buffer and release the original= buffer. // - CopyMem (AlignedBuffer, Buffer, BufferSize); + if (GetFvUsedSize (FvHeader, &FvUsedSize, &EraseByte)) { + // + // Copy the used bytes and fill the rest with the erase value. + // + CopyMem (AlignedBuffer, FvHeader, (UINTN) FvUsedSize); + SetMem ( + (UINT8 *) AlignedBuffer + FvUsedSize, + (UINTN) (BufferSize - FvUsedSize), + EraseByte + ); + } else { + CopyMem (AlignedBuffer, Buffer, BufferSize); + } FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer; CoreFreePool (Buffer); Buffer =3D NULL; --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel