From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web12.8104.1580913151403143252 for ; Wed, 05 Feb 2020 06:32:31 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: liming.gao@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Feb 2020 06:32:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,405,1574150400"; d="scan'208";a="224669147" Received: from lgao4-mobl.ccr.corp.intel.com ([10.249.170.116]) by orsmga008.jf.intel.com with ESMTP; 05 Feb 2020 06:32:29 -0800 From: "Liming Gao" To: devel@edk2.groups.io Cc: Bob Feng Subject: [edk2-platform] FitGen: Support FV with the extension header Date: Wed, 5 Feb 2020 22:32:24 +0800 Message-Id: <20200205143224.2038-1-liming.gao@intel.com> X-Mailer: git-send-email 2.24.1.windows.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2086 To find Microcode FILE in FV image, need to skip FV header and FV extension header, then find the first RAW FFS file. Cc: Bob Feng Signed-off-by: Liming Gao --- Silicon/Intel/Tools/FitGen/FitGen.c | 40 +++++++++++++++++++++++++++++++------ Silicon/Intel/Tools/FitGen/FitGen.h | 2 +- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Silicon/Intel/Tools/FitGen/FitGen.c b/Silicon/Intel/Tools/FitGen/FitGen.c index 9f1db32a15..5f5638dc8b 100644 --- a/Silicon/Intel/Tools/FitGen/FitGen.c +++ b/Silicon/Intel/Tools/FitGen/FitGen.c @@ -747,6 +747,37 @@ CheckOverlap ( } } +UINT8 * +GetMicrocodeBufferFromFv ( + EFI_FIRMWARE_VOLUME_HEADER *FvHeader + ) +{ + UINT8 *MicrocodeBuffer; + EFI_FFS_FILE_HEADER *FfsHeader; + + MicrocodeBuffer = NULL; + // + // Skip FV header + FV extension header + FFS header + // + FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *) FvHeader + FvHeader->HeaderLength); + while ((UINT8 *) FfsHeader < (UINT8 *) FvHeader + FvHeader->FvLength) { + if (FfsHeader->Type == EFI_FV_FILETYPE_RAW) { + // + // Find the first RAW ffs file as Microcode Buffer + // + MicrocodeBuffer = (UINT8 *)(FfsHeader + 1); + break; + } + if (GetFfsFileLength (FfsHeader) == 0xFFFFFF) { + // spare space is found, and exit + break; + } + FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + ((GetFfsFileLength (FfsHeader)+7)&~7)); + } + + return MicrocodeBuffer; +} + UINT32 GetFitEntryNumber ( IN INTN argc, @@ -1047,8 +1078,7 @@ Returns: FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)MicrocodeFileBuffer; if (FvHeader->Signature == EFI_FVH_SIGNATURE) { - // Skip FV header + FFS header - MicrocodeBuffer = MicrocodeFileBuffer + sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(EFI_FFS_FILE_HEADER); + MicrocodeBuffer = GetMicrocodeBufferFromFv (FvHeader); } else { MicrocodeBuffer = MicrocodeFileBuffer; } @@ -1388,8 +1418,7 @@ Returns: FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)MicrocodeFileBuffer; if (FvHeader->Signature == EFI_FVH_SIGNATURE) { - // Skip FV header + FFS header - MicrocodeBuffer = MicrocodeFileBuffer + sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(EFI_FFS_FILE_HEADER); + MicrocodeBuffer = GetMicrocodeBufferFromFv (FvHeader); } else { MicrocodeBuffer = MicrocodeFileBuffer; } @@ -1401,8 +1430,7 @@ Returns: FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)MicrocodeFileBuffer; if (FvHeader->Signature == EFI_FVH_SIGNATURE) { - // Skip FV header + FFS header - MicrocodeBuffer = MicrocodeFileBuffer + sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(EFI_FFS_FILE_HEADER); + MicrocodeBuffer = GetMicrocodeBufferFromFv (FvHeader); } else { MicrocodeBuffer = MicrocodeFileBuffer; } diff --git a/Silicon/Intel/Tools/FitGen/FitGen.h b/Silicon/Intel/Tools/FitGen/FitGen.h index ecb5822d32..4d0a2dc6f8 100644 --- a/Silicon/Intel/Tools/FitGen/FitGen.h +++ b/Silicon/Intel/Tools/FitGen/FitGen.h @@ -31,7 +31,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // Utility version information // #define UTILITY_MAJOR_VERSION 0 -#define UTILITY_MINOR_VERSION 57 +#define UTILITY_MINOR_VERSION 58 #define UTILITY_DATE __DATE__ // -- 2.13.0.windows.1