From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.1976.1668563907493027159 for ; Tue, 15 Nov 2022 17:58:28 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=FB1n0qTP; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: rahul.r.kumar@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668563907; x=1700099907; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=pNkKvY54ulYe7SvzF7/qsiQRCyEbKGd4MVPIU/s5mcI=; b=FB1n0qTPZ6QqgDBycN/Z5SRLUPIpJabrkzkkVFeuEzQlE7KXUptwRGC0 TKZaeaQRWZzzsIrZagG5GKgTe2mYAUfB7Q2zHS22CJzf9b7WnHxKhtJq0 EJ5b1o7OMTtVDMdh07Tl2nc/U9OwLsT7t9hymLh8VXx8mImG9LmfIQtsF Qqm7ExvIUWstIH74JZGpGysP0GoowEi3N0C/tLPCv/QkPVoVPKLCHhTjF TzKs2IVAeg+BYWVVDpCB0q+s3GhB/CyDfIFtuOEG9FnhGiOPwnf5N90VI 6us4nrwEPm3snJtRAjis8YrAz9EMkrVjNAScoZv+h/Bq69caBDNEbkW5u g==; X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="374554084" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="374554084" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2022 17:58:26 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="728181339" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="728181339" Received: from rahul-workstn.amr.corp.intel.com ([10.24.80.184]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2022 17:58:25 -0800 From: Rahul R Kumar To: devel@edk2.groups.io, bob.c.feng@intel.com, gaoliming@byosoft.com.cn, yuwei.chen@intel.com, isaac.w.oram@intel.com, rangasai.v.chaganty@intel.com, catharine.west@intel.com Cc: Rahul R Kumar Subject: [PATCH] Silicon/Intel/FitGen:FitGen Supporting MultiFIT 2 rc Date: Tue, 15 Nov 2022 17:58:10 -0800 Message-Id: <20221116015810.2049-1-rahul.r.kumar@intel.com> X-Mailer: git-send-email 2.30.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4155 With new implementation, FITGEN will populate info needed for the PROT assisted BootGuard solution and TXT on servers using FIT 4 Entry. FitGen based on the CPU FMS FITGEN will decide to call one of the two Type 2 FIT entry. Signed-off-by: Rahul R Kumar --- Silicon/Intel/Tools/FitGen/FitGen.c | 1186 ++++++++++++++++----------- Silicon/Intel/Tools/FitGen/FitGen.h | 7 +- 2 files changed, 722 insertions(+), 471 deletions(-) diff --git a/Silicon/Intel/Tools/FitGen/FitGen.c b/Silicon/Intel/Tools/FitG= en/FitGen.c index 87123f9922..4ba07945a6 100644 --- a/Silicon/Intel/Tools/FitGen/FitGen.c +++ b/Silicon/Intel/Tools/FitGen/FitGen.c @@ -44,11 +44,18 @@ typedef struct { #define BIOS_MODULE_ALIGNMENT 0x3F // 64 bytes for AnC=0D #define MICROCODE_ALIGNMENT 0x7FF=0D =0D +#define MICROCODE_EXTERNAL_HEADER_SIZE 0x30=0D +=0D #define ACM_PKCS_1_5_RSA_SIGNATURE_SHA256_SIZE 256=0D #define ACM_PKCS_1_5_RSA_SIGNATURE_SHA384_SIZE 384=0D =0D -#define ACM_HEADER_VERSION_3 (3 << 16)=0D -#define ACM_HEADER_VERSION_0 (0)=0D +#define ACM_XMSS_PUBLIC_KEY_SIZE 64=0D +#define ACM_XMSS_SIGNATURE_SIZE 2692=0D +=0D +#define ACM_HEADER_VERSION_5 0x50004=0D +#define ACM_HEADER_VERSION_4 (4 << 16)=0D +#define ACM_HEADER_VERSION_3 (3 << 16)=0D +#define ACM_HEADER_VERSION_0 (0)=0D #define ACM_MODULE_TYPE_CHIPSET_ACM 2=0D #define ACM_MODULE_SUBTYPE_CAPABLE_OF_EXECUTE_AT_RESET 0x1=0D #define ACM_MODULE_SUBTYPE_ANC_MODULE 0x2=0D @@ -56,6 +63,37 @@ typedef struct { #define ACM_MODULE_FLAG_DEBUG_SIGN 0x8000=0D =0D #define NIBBLES_TO_BYTE(A, B) (UINT8)(((A & (0x0F)) << 4) | (B & 0x0F))=0D +//=0D +//Flash Map 0 Register (Flash Descriptor Records)=0D +//=0D +typedef struct {=0D + UINT32 Fcba : 8; //Bits[7:0]: Flash Component Base Address=0D + UINT32 Nc : 2; //Bits[9:8]: Number of Components=0D + UINT32 Rsvd0: 1; //Bit10: Reserved=0D + UINT32 Rsvd1: 1; //Bit11: Reserved=0D + UINT32 Rsvd2: 1; //Bit12: Reserved=0D + UINT32 Rsvd3: 3; //Bits[15:13]: Reserved=0D + UINT32 Frba : 8; //Bits[23:16]: Flash Region Base Address=0D + UINT32 Rsvd4: 3; //Bits[26:24]: Reserved=0D + UINT32 Rsvd5: 5; //Bits[31:27]: Reserved=0D +} FLASH_MAP_0_REGISTER;=0D +=0D +//=0D +//Flash Region 1 (BIOS) Register (Flash Descriptor Records)=0D +//=0D +typedef struct {=0D + UINT32 RegionBase : 15; //Bits[14:0]: Region base=0D + UINT32 Rsvd : 1; //Bit15: Reserved=0D + UINT32 RegionLimit: 15; //Bits[30:16]: Region limit=0D + UINT32 Rsvd1 : 1; //Bit31: Reserved=0D +} FLASH_REGION_1_BIOS_REGISTER;=0D +=0D +#define FLASH_VALID_SIGNATURE 0x0FF0A55A //Fla= sh Valid Signature (Flash Descriptor Records)=0D +#define FLVALSIG_BASE_OFFSET 0x10 //Fla= sh Valid Signature Base Offset=0D +#define FLMAP0_BASE_OFFSET 0x14 //Fla= sh Map 0 Register Base Offset=0D +=0D +#define ACMFV_GUID \=0D + { 0x8a4b197f, 0x1113, 0x43d0, { 0xa2, 0x3f, 0x26, 0xf3, 0x69, 0xb2, 0xb8= , 0x41 }}=0D =0D typedef struct {=0D UINT16 ModuleType;=0D @@ -98,6 +136,8 @@ typedef struct { #define CHIPSET_ACM_TYPE_BIOS 0=0D #define CHIPSET_ACM_TYPE_SINIT 1=0D =0D +#define DEFAULT_ACM_EXTENDED_MASK 0x00FFFFFF=0D +=0D typedef struct {=0D UINT32 Guid0;=0D UINT32 Guid1;=0D @@ -238,6 +278,7 @@ typedef struct { #define FIT_TABLE_TYPE_MICROCODE 1=0D #define FIT_TABLE_TYPE_STARTUP_ACM 2=0D #define FIT_TABLE_TYPE_DIAGNST_ACM 3=0D +#define FIT_TABLE_TYPE_PROT_BOOT_POLICY 4=0D #define FIT_TABLE_TYPE_BIOS_MODULE 7=0D #define FIT_TABLE_TYPE_TPM_POLICY 8=0D #define FIT_TABLE_TYPE_BIOS_POLICY 9=0D @@ -252,7 +293,6 @@ typedef struct { #define FIT_TABLE_TYPE_VAB_BOOT_IMAGE_MANIFEST 27=0D #define FIT_TABLE_TYPE_VAB_BOOT_KEY_MANIFEST 28=0D =0D -=0D //=0D // With OptionalModule Address isn't known until free space has been=0D // identified and the optional module has been copied into the FLASH=0D @@ -284,9 +324,10 @@ typedef struct { UINT32 GlobalVersion;=0D UINT32 FitHeaderVersion;=0D FIT_TABLE_CONTEXT_ENTRY StartupAcm[MAX_STARTUP_ACM_ENTRY];=0D - UINT32 StartupAcmVersion[MAX_STARTUP_ACM_ENTRY];=0D + UINT32 StartupAcmFvSize;=0D FIT_TABLE_CONTEXT_ENTRY DiagnstAcm;=0D UINT32 DiagnstAcmVersion;=0D + FIT_TABLE_CONTEXT_ENTRY ProtBootPolicy;=0D FIT_TABLE_CONTEXT_ENTRY BiosModule[MAX_BIOS_MODULE_ENTRY];=0D UINT32 BiosModuleVersion;=0D FIT_TABLE_CONTEXT_ENTRY Microcode[MAX_MICROCODE_ENTRY];=0D @@ -305,25 +346,87 @@ xtoi ( char *str=0D );=0D =0D -VOID=0D -PrintUtilityInfo (=0D - VOID=0D - )=0D -/*++=0D +/**=0D + Pass in supported CPU extended family/extended model/type=0D + /family/model without stepping or CPU FMS >> 4.=0D +=0D + @param FitEntry Pointer to Fit Entry table.=0D + @param AcmFamilyModel Acm Family Model stepping.=0D + @param AcmMask ACM mask.=0D +=0D + @return STATUS_SUCCESS The file found and data read.=0D +**/=0D +STATUS=0D +SetFirmwareInterfaceTableEntryAcmFms(=0D + FIRMWARE_INTERFACE_TABLE_ENTRY *FitEntry,=0D + UINT32 AcmFamilyModel,=0D + UINT32 AcmMask=0D +)=0D +{=0D + if (FitEntry =3D=3D NULL) {=0D + return STATUS_ERROR;=0D + }=0D +=0D + FitEntry->Checksum =3D (UINT8)(((AcmFamilyModel & 0x000F0000) >> 16) | (= ((AcmMask & 0x000F0000) >> 16) << 4));=0D + FitEntry->Rsvd =3D (UINT8)((AcmMask & 0x0000FF00) >> 8);=0D + FitEntry->Size[2] =3D (UINT8)(AcmMask & 0x000000FF);=0D + FitEntry->Size[1] =3D (UINT8)((AcmFamilyModel & 0x0000FF00) >> 8);=0D + FitEntry->Size[0] =3D (UINT8)(AcmFamilyModel & 0x000000FF);=0D + return STATUS_SUCCESS;=0D +}=0D +=0D +/**=0D + Set the FIT Entry Size.=0D +=0D + @param FitEntry Pointer to Fit Entry table.=0D + @param SizeEntry Size of FIT entry.=0D =0D -Routine Description:=0D + @return STATUS_SUCCESS The file found and data read.=0D +**/=0D +STATUS=0D +SetFirmwareInterfaceTableEntrySize (=0D + FIRMWARE_INTERFACE_TABLE_ENTRY *FitEntry,=0D + UINT32 SizeEntry=0D +)=0D +{=0D + if (FitEntry =3D=3D NULL) {=0D + return STATUS_ERROR;=0D + }=0D + FitEntry->Size[2] =3D (UINT8)((SizeEntry & 0x00FF0000) >> 16);=0D + FitEntry->Size[1] =3D (UINT8)((SizeEntry & 0x0000FF00) >> 8);=0D + FitEntry->Size[0] =3D (UINT8)(SizeEntry & 0x000000FF);=0D + return STATUS_SUCCESS;=0D +}=0D =0D - Displays the standard utility information to STDOUT=0D +/**=0D + Get the FIT Entry Size.=0D =0D -Arguments:=0D + @param FitEntry Pointer to Fit Entry table.=0D =0D - None=0D + @return FitEntry pointer=0D +**/=0D +UINT32=0D +GetFirmwareInterfaceTableEntrySize (=0D + FIRMWARE_INTERFACE_TABLE_ENTRY *FitEntry=0D +)=0D +{=0D + if (FitEntry =3D=3D NULL) {=0D + return 0;=0D + }=0D + return (((UINT32)FitEntry->Size[2] << 16) | ((UINT32)FitEntry->Size[1] <= < 8) | (UINT32)FitEntry->Size[0]);=0D +}=0D =0D -Returns:=0D +/**=0D + Displays the FIT utility info=0D =0D - None=0D + @param None=0D =0D ---*/=0D + @return None=0D +**/=0D +VOID=0D +PrintUtilityInfo (=0D + VOID=0D + )=0D {=0D printf (=0D "%s - Tiano IA32/X64 FIT table generation Utility for FIT spec revisio= n %i.%i."" Version %i.%i\n\n",=0D @@ -335,25 +438,17 @@ Returns: );=0D }=0D =0D +/**=0D + Displays the utility usage syntax to STDOUT.=0D +=0D + @param None=0D +=0D + @return None=0D +**/=0D VOID=0D PrintUsage (=0D VOID=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Displays the utility usage syntax to STDOUT=0D -=0D -Arguments:=0D -=0D - None=0D -=0D -Returns:=0D -=0D - None=0D -=0D ---*/=0D {=0D printf ("Usage (generate): %s [-D] InputFvRecoveryFile OutputFvRecoveryF= ile\n"=0D "\t[-V ]\n"=0D @@ -371,6 +466,7 @@ Returns: "\t[-M ] [-M ...]|[-U ||] [-V ]\n"=0D "\t[-O RecordType |||| [-V ]] [-O ... [-V ...]]\n"=0D "\t[-P RecordType [-V ]] [-P ... [-V ...]]\n"=0D + "\t[-BP [-V ]\n"=0D "\t[-T ]\n"=0D , UTILITY_NAME);=0D printf (" Where:\n");=0D @@ -407,12 +503,14 @@ Returns: printf ("\tRecordDataGuid - FIT entry record data GUID.\n");=0D printf ("\tRecordBinFile - FIT entry record data binary file.\n= ");=0D printf ("\tCseRecordSubType - FIT entry record subtype. Use to fur= ther distinguish CSE entries (see FIT spec revision 1.2 chapter 4.12).\n");= =0D + printf ("\tBootPolicySize - FIT entry size for type 04 boot poli= cy.\n");=0D printf ("\tFitEntryDefaultVersion - The default version for all FIT tabl= e entries. 0x%04x is used if this is not specified.\n", DEFAULT_FIT_ENTRY_V= ERSION);=0D printf ("\tFitHeaderVersion - The version for FIT header. (Overrid= e default version)\n");=0D printf ("\tStartupAcmVersion - The version for StartupAcm. (Overrid= e default version)\n");=0D printf ("\tBiosModuleVersion - The version for BiosModule. (Overrid= e default version)\n");=0D printf ("\tMicrocodeVersion - The version for Microcode. (Override= default version)\n");=0D printf ("\tRecordVersion - The version for Record. (Override de= fault version)\n");=0D + printf ("\tBootPolicyVersion - The version for BootPolicy. (Ove= rride default version)\n");=0D printf ("\tIndexPort - The Index Port Number.\n");=0D printf ("\tDataPort - The Data Port Number.\n");=0D printf ("\tWidth - The Width of the port.\n");=0D @@ -427,11 +525,20 @@ Returns: printf ("\tSTATUS_SUCCESS=3D%d, STATUS_WARNING=3D%d, STATUS_ERROR=3D%d\n= ", STATUS_SUCCESS, STATUS_WARNING, STATUS_ERROR);=0D }=0D =0D +/**=0D + Set Value of memory.=0D +=0D + @param Buffer The pointer where we need to set the me= mory.=0D + @param Length Size of memory to be set.=0D + @param Value Value of memory to be set.=0D +=0D + @return Buffer The pointer address.=0D +**/=0D VOID *=0D SetMem (=0D - OUT VOID *Buffer,=0D - IN UINTN Length,=0D - IN UINT8 Value=0D + OUT VOID *Buffer,=0D + IN UINTN Length,=0D + IN UINT8 Value=0D )=0D {=0D //=0D @@ -448,6 +555,14 @@ SetMem ( return Buffer;=0D }=0D =0D +/**=0D + check the input Path.=0D +=0D + @param String Passed input path.=0D +=0D + @return TRUE If the input path is correct.=0D + @return FLASE if the input path is not correct.=0D +**/=0D BOOLEAN=0D CheckPath (=0D IN CHAR8 * String=0D @@ -476,28 +591,20 @@ CheckPath ( return TRUE;=0D }=0D =0D +/**=0D + Get fixed FIT location from argument.=0D +=0D + @param argc Number of command line parameters.=0D + @param argv Array of pointers to parameter strings.=0D +=0D + @return FitLocation The FIT location specified by Argument.=0D + @return 0 Argument parse fail.=0D +**/=0D UINT32=0D GetFixedFitLocation (=0D IN INTN argc,=0D IN CHAR8 **argv=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Get fixed FIT location from argument=0D -=0D -Arguments:=0D -=0D - argc - Number of command line parameters.=0D - argv - Array of pointers to parameter strings.=0D -=0D -Returns:=0D -=0D - FitLocation - The FIT location specified by Argument=0D - 0 - Argument parse fail=0D -=0D -*/=0D {=0D UINT32 FitLocation;=0D INTN Index;=0D @@ -516,6 +623,18 @@ Returns: return FitLocation;=0D }=0D =0D +/**=0D + Read input file.=0D +=0D + @param FileName The input file name.=0D + @param FileData The input file data, the memory is al= igned.=0D + @param FileSize The input file size.=0D + @param FileBufferRaw The memory to hold input file data. T= he caller must free the memory.=0D +=0D + @return STATUS_SUCCESS The file found and data read.=0D + @return STATUS_ERROR The file data is not read.=0D + @return STATUS_WARNING The file is not found.=0D +**/=0D STATUS=0D ReadInputFile (=0D IN CHAR8 *FileName,=0D @@ -523,26 +642,6 @@ ReadInputFile ( OUT UINT32 *FileSize,=0D OUT UINT8 **FileBufferRaw OPTIONAL=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Read input file=0D -=0D -Arguments:=0D -=0D - FileName - The input file name=0D - FileData - The input file data, the memory is aligned.=0D - FileSize - The input file size=0D - FileBufferRaw - The memory to hold input file data. The caller must free= the memory.=0D -=0D -Returns:=0D -=0D - STATUS_SUCCESS - The file found and data read=0D - STATUS_ERROR - The file data is not read=0D - STATUS_WARNING - The file is not found=0D -=0D ---*/=0D {=0D FILE *FpIn;=0D UINT32 TempResult;=0D @@ -612,24 +711,20 @@ Returns: return STATUS_SUCCESS;=0D }=0D =0D +/**=0D + Find next FvHeader in the FileBuffer.=0D +=0D + @param FileBuffer The start FileBuffer which needs to be se= arched.=0D + @param FileLength The whole File Length.=0D +=0D + @return FvHeader The FvHeader is found successfully.=0D + @return NULL The FvHeader is not found.=0D +**/=0D UINT8 *=0D FindNextFvHeader (=0D IN UINT8 *FileBuffer,=0D IN UINTN FileLength=0D )=0D -/*++=0D -=0D - Routine Description:=0D - Find next FvHeader in the FileBuffer=0D -=0D - Parameters:=0D - FileBuffer - The start FileBuffer which needs to be searched= =0D - FileLength - The whole File Length.=0D - Return:=0D - FvHeader - The FvHeader is found successfully.=0D - NULL - The FvHeader is not found.=0D -=0D ---*/=0D {=0D UINT8 *FileHeader;=0D EFI_FIRMWARE_VOLUME_HEADER *FvHeader;=0D @@ -679,6 +774,17 @@ FindNextFvHeader ( return NULL;=0D }=0D =0D +/**=0D + Find File with GUID in an FV.=0D +=0D + @param FvBuffer FV binary buffer.=0D + @param FvSize FV size.=0D + @param Guid File GUID value to be searched.=0D + @param FileSize Guid File size.=0D +=0D + @return FileLocation Guid File location.=0D + @return NULL Guid File is not found.=0D +**/=0D UINT8 *=0D FindFileFromFvByGuid (=0D IN UINT8 *FvBuffer,=0D @@ -686,25 +792,6 @@ FindFileFromFvByGuid ( IN EFI_GUID *Guid,=0D OUT UINT32 *FileSize=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Find File with GUID in an FV=0D -=0D -Arguments:=0D -=0D - FvBuffer - FV binary buffer=0D - FvSize - FV size=0D - Guid - File GUID value to be searched=0D - FileSize - Guid File size=0D -=0D -Returns:=0D -=0D - FileLocation - Guid File location.=0D - NULL - Guid File is not found.=0D -=0D ---*/=0D {=0D EFI_FIRMWARE_VOLUME_HEADER *FvHeader;=0D EFI_FFS_FILE_HEADER *FileHeader;=0D @@ -783,28 +870,20 @@ Returns: return NULL;=0D }=0D =0D +/**=0D + Check whether a string is a GUID.=0D +=0D + @param StringData The String.=0D + @param Guid Guid to hold the value=0D +=0D + @return TRUE StringData is a GUID, and Guid field is filled.=0D + @return FALSE StringData is not a GUID.=0D +**/=0D BOOLEAN=0D IsGuidData (=0D IN CHAR8 *StringData,=0D OUT EFI_GUID *Guid=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Check whether a string is a GUID=0D -=0D -Arguments:=0D -=0D - StringData - the String=0D - Guid - Guid to hold the value=0D -=0D -Returns:=0D -=0D - TRUE - StringData is a GUID, and Guid field is filled.=0D - FALSE - StringData is not a GUID=0D -=0D ---*/=0D {=0D if (strlen (StringData) !=3D strlen ("00000000-0000-0000-0000-0000000000= 00")) {=0D return FALSE;=0D @@ -821,6 +900,17 @@ Returns: return TRUE;=0D }=0D =0D +/**=0D + Get FIT entry number and fill global FIT table context, from argument.=0D +=0D + @param argc Number of command line parameters.=0D + @param argv Array of pointers to parameter strings.=0D + @param FdBuffer FD binary buffer.=0D + @param FdSize FD size.=0D +=0D + @return FitEntryNumber The FIT entry number.=0D + @return 0 Argument parse fail.=0D +**/=0D VOID=0D CheckOverlap (=0D IN UINT32 Address,=0D @@ -875,6 +965,17 @@ CheckOverlap ( }=0D }=0D =0D +/**=0D + Get FIT entry number and fill global FIT table context, from argument.=0D +=0D + @param argc Number of command line parameters.=0D + @param argv Array of pointers to parameter strings.=0D + @param FdBuffer FD binary buffer.=0D + @param FdSize FD size.=0D +=0D + @return FitEntryNumber The FIT entry number.=0D + @return 0 Argument parse fail.=0D +**/=0D UINT8 *=0D GetMicrocodeBufferFromFv (=0D EFI_FIRMWARE_VOLUME_HEADER *FvHeader=0D @@ -906,6 +1007,17 @@ GetMicrocodeBufferFromFv ( return MicrocodeBuffer;=0D }=0D =0D +/**=0D + Get FIT entry number and fill global FIT table context, from argument.=0D +=0D + @param argc Number of command line parameters.=0D + @param argv Array of pointers to parameter strings.=0D + @param FdBuffer FD binary buffer.=0D + @param FdSize FD size.=0D +=0D + @return FitEntryNumber The FIT entry number.=0D + @return 0 Argument parse fail.=0D +**/=0D UINT32=0D GetFitEntryNumber (=0D IN INTN argc,=0D @@ -913,25 +1025,6 @@ GetFitEntryNumber ( IN UINT8 *FdBuffer,=0D IN UINT32 FdSize=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Get FIT entry number and fill global FIT table context, from argument=0D -=0D -Arguments:=0D -=0D - argc - Number of command line parameters.=0D - argv - Array of pointers to parameter strings.=0D - FdBuffer - FD binary buffer=0D - FdSize - FD size=0D -=0D -Returns:=0D -=0D - FitEntryNumber - The FIT entry number=0D - 0 - Argument parse fail=0D -=0D -*/=0D {=0D EFI_GUID Guid;=0D EFI_GUID MicrocodeFfsGuid;=0D @@ -1188,7 +1281,7 @@ Returns: gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].T= ype =3D FIT_TABLE_TYPE_STARTUP_ACM;=0D gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].A= ddress =3D (UINT32)BiosInfoStruct[BiosInfoIndex].Address;=0D gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].S= ize =3D (UINT32)BiosInfoStruct[BiosInfoIndex].Size;=0D - gFitTableContext.StartupAcmVersion[gFitTableContext.StartupAcmNu= mber] =3D BiosInfoStruct[BiosInfoIndex].Version;=0D + gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].V= ersion =3D BiosInfoStruct[BiosInfoIndex].Version;=0D gFitTableContext.StartupAcmNumber ++;=0D gFitTableContext.FitEntryNumber ++;=0D break;=0D @@ -1203,6 +1296,13 @@ Returns: gFitTableContext.DiagnstAcmVersion =3D DEFAULT_FIT_ENTRY_VERSIO= N;=0D gFitTableContext.FitEntryNumber ++;=0D break;=0D + case FIT_TABLE_TYPE_PROT_BOOT_POLICY:=0D + gFitTableContext.ProtBootPolicy.Type =3D FIT_TABLE_TYPE_PROT= _BOOT_POLICY;=0D + gFitTableContext.ProtBootPolicy.Address =3D (UINT32)BiosInfoStr= uct[BiosInfoIndex].Address;=0D + gFitTableContext.ProtBootPolicy.Size =3D (UINT32)BiosInfoStr= uct[BiosInfoIndex].Size;=0D + gFitTableContext.ProtBootPolicy.Version =3D DEFAULT_FIT_ENTRY_V= ERSION;=0D + gFitTableContext.FitEntryNumber ++;=0D + break;=0D case FIT_TABLE_TYPE_BIOS_MODULE:=0D if ((BiosInfoStruct[BiosInfoIndex].Attributes & BIOS_INFO_STRUCT= _ATTRIBUTE_BIOS_POST_IBB) !=3D 0) {=0D continue;=0D @@ -1402,7 +1502,8 @@ Returns: // not found=0D return 0;=0D }=0D - FileBuffer =3D (UINT8 *)MEMORY_TO_FLASH (FileBuffer, FdBuffer, FdSiz= e);=0D + gFitTableContext.StartupAcmFvSize =3D FdSize;=0D + FileBuffer =3D (UINT8 *)MEMORY_TO_FLASH(FileBuffer, FdBuffer, FdSize= );=0D Index +=3D 2;=0D } else {=0D if (Index + 2 >=3D argc) {=0D @@ -1431,7 +1532,7 @@ Returns: //=0D // Bypass=0D //=0D - gFitTableContext.StartupAcmVersion[gFitTableContext.StartupAcmNumber= ] =3D gFitTableContext.GlobalVersion;=0D + gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Versi= on =3D gFitTableContext.GlobalVersion;=0D } else {=0D if (Index + 2 >=3D argc) {=0D //=0D @@ -1443,7 +1544,7 @@ Returns: //=0D // With the -I parameter should assign the type 2 entry version as= 0x200 format=0D //=0D - gFitTableContext.StartupAcmVersion[gFitTableContext.StartupAcmNumb= er] =3D STARTUP_ACM_FIT_ENTRY_200_VERSION;=0D + gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Ver= sion =3D STARTUP_ACM_FIT_ENTRY_200_VERSION;=0D gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].FMS= =3D (UINT32)xtoi (argv[Index + 1]);=0D gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].FMS= Mask =3D (UINT32)xtoi (argv[Index + 2]);=0D =0D @@ -1464,7 +1565,8 @@ Returns: //=0D // Get offset from parameter=0D //=0D - gFitTableContext.StartupAcmVersion[gFitTableContext.StartupAcmNumber= ] =3D xtoi (argv[Index + 1]);=0D + gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Versi= on =3D gFitTableContext.GlobalVersion;=0D + gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Versi= on =3D xtoi (argv[Index + 1]);=0D Index +=3D 2;=0D }=0D =0D @@ -1942,7 +2044,7 @@ Returns: //=0D // Get offset from parameter=0D //=0D - gFitTableContext.PortModule[gFitTableContext.PortModuleNumber].Versi= on =3D xtoi (argv[Index + 1]);=0D + gFitTableContext.PortModule[gFitTableContext.PortModuleNumber].Versi= on =3D xtoi(argv[Index + 1]);=0D Index +=3D 2;=0D }=0D =0D @@ -1950,6 +2052,69 @@ Returns: gFitTableContext.FitEntryNumber++;=0D }=0D =0D + //=0D + // 6th, try FIT boot policy data=0D + //=0D + if ((Index < argc) &&=0D + ((strcmp(argv[Index], "-BP") =3D=3D 0) ||=0D + (strcmp(argv[Index], "-bp") =3D=3D 0))) {=0D +=0D + if (Index + 1 >=3D argc) {=0D + Error(NULL, 0, 0, "-BP: Invalid Parameters.", NULL);=0D + FitEntryNumber =3D 0;=0D + }=0D +=0D + gFitTableContext.StartupAcmFvSize =3D GetFvAcmSizeFromFd(FdBuffer, FdS= ize);=0D + if (gFitTableContext.StartupAcmFvSize =3D=3D 0) {=0D + Error(NULL, 0, 0, "FV_ACM not found in Fd file!", NULL);=0D + }=0D +=0D + //=0D + // FIT type 04 record shares FV allocated space with FV_ACM.=0D + //=0D + FileSize =3D xtoi(argv[Index + 1]);=0D +=0D + if (gFitTableContext.StartupAcm[0].Size + FileSize > gFitTableContext.= StartupAcmFvSize) {=0D + Error(NULL, 0, 0, "Error: not enough FV_ACM room for FIT type 04 rec= ord!", NULL);=0D + FitEntryNumber =3D 0;=0D + }=0D +=0D + FileBuffer =3D malloc(FileSize);=0D + if (FileBuffer =3D=3D NULL) {=0D + Error(NULL, 0, 0, "No sufficient memory to allocate!", NULL);=0D + FitEntryNumber =3D 0;=0D + }=0D +=0D + SetMem(FileBuffer, FileSize, 0xFF);=0D +=0D + gFitTableContext.ProtBootPolicy.Type =3D FIT_TABLE_TYPE_PROT_BOOT_POLI= CY;=0D + gFitTableContext.ProtBootPolicy.Address =3D gFitTableContext.StartupAc= m[0].Address + gFitTableContext.StartupAcm[0].Size;=0D + gFitTableContext.ProtBootPolicy.Size =3D FileSize;=0D + gFitTableContext.ProtBootPolicy.Version =3D 0;=0D +=0D + Index +=3D 2;=0D +=0D + //=0D + // 6.1 PROT Module version=0D + //=0D + if ((Index + 1 >=3D argc) ||=0D + ((strcmp (argv[Index], "-V") !=3D 0) &&=0D + (strcmp (argv[Index], "-v") !=3D 0)) ) {=0D + //=0D + // Bypass=0D + //=0D + gFitTableContext.ProtBootPolicy.Version =3D gFitTableContext.GlobalV= ersion;=0D + } else {=0D + //=0D + // Get offset from parameter=0D + //=0D + gFitTableContext.ProtBootPolicy.Version =3D xtoi(argv[Index + 1]);=0D + Index +=3D 2;=0D + }=0D +=0D + gFitTableContext.FitEntryNumber++;=0D + }=0D +=0D //=0D // Final: Check StartupAcm in BiosModule.=0D //=0D @@ -1974,31 +2139,23 @@ Returns: return FitEntryNumber;=0D }=0D =0D +/**=0D + No enough space - it might happen that it is occupied by AP wake vector.= =0D + Last chance - skip this and search again.=0D +=0D + @param FvBuffer FvRecovery binary buffer.=0D + @param Address Address to be searched from.=0D + @param Size Size need to be filled.=0D +=0D + @return FitTableOffset The FIT table offset.=0D + @return NULL No enough space for FIT table.=0D +**/=0D VOID *=0D FindSpaceSkipApVector (=0D IN UINT8 *FvBuffer,=0D IN UINT8 *Address,=0D IN UINTN Size=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - No enough space - it might happen that it is occupied by AP wake vector.= =0D - Last chance - skip this and search again.=0D -=0D -Arguments:=0D -=0D - FvBuffer - FvRecovery binary buffer=0D - Address - Address to be searched from=0D - Size - Size need to be filled=0D -=0D -Returns:=0D -=0D - FitTableOffset - The FIT table offset=0D - NULL - No enough space for FIT table=0D -=0D -*/=0D {=0D UINT8 *ApVector;=0D UINT8 *NewAddress;=0D @@ -2018,6 +2175,17 @@ Returns: return NewAddress;=0D }=0D =0D +/**=0D + Get free space for FIT table from FvRecovery.=0D +=0D + @param FvBuffer FvRecovery binary buffer.=0D + @param FvSize FvRecovery size.=0D + @param FitTableSize The FIT table size.=0D + @param FixedFitLocation Fixed FIT location provided by argument.=0D +=0D + @return FitTableOffset The offset of FIT table in FvRecovery file.=0D + @return NULL Free space not found.=0D +**/=0D VOID *=0D GetFreeSpaceForFit (=0D IN UINT8 *FvBuffer,=0D @@ -2025,25 +2193,6 @@ GetFreeSpaceForFit ( IN UINT32 FitTableSize,=0D IN UINT32 FixedFitLocation=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Get free space for FIT table from FvRecovery=0D -=0D -Arguments:=0D -=0D - FvBuffer - FvRecovery binary buffer=0D - FvSize - FvRecovery size=0D - FitTableSize - The FIT table size=0D - FixedFitLocation - Fixed FIT location provided by argument=0D -=0D -Returns:=0D -=0D - FitTableOffset - The offset of FIT table in FvRecovery file=0D - NULL - Free space not found=0D -=0D ---*/=0D {=0D UINT8 *FitTableOffset;=0D INTN Index;=0D @@ -2167,7 +2316,7 @@ Returns: (gFitTableContext.OptionalModule[Index].Type =3D=3D FIT_TABLE_TY= PE_VAB_PROVISION_TABLE) ||=0D (gFitTableContext.OptionalModule[Index].Type =3D=3D FIT_TABLE_TY= PE_VAB_BOOT_IMAGE_MANIFEST) ||=0D (gFitTableContext.OptionalModule[Index].Type =3D=3D FIT_TABLE_TY= PE_VAB_BOOT_KEY_MANIFEST)) {=0D - // Let it 64 byte align=0D + // Let it 64 byte align=0D AlignedSize +=3D BIOS_MODULE_ALIGNMENT;=0D AlignedSize &=3D ~BIOS_MODULE_ALIGNMENT;=0D }=0D @@ -2228,25 +2377,17 @@ Returns: return FitTableOffset;=0D }=0D =0D +/**=0D + Output FIT table information.=0D +=0D + @param None=0D +=0D + @return None=0D +**/=0D VOID=0D PrintFitData (=0D VOID=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Output FIT table information=0D -=0D -Arguments:=0D -=0D - None=0D -=0D -Returns:=0D -=0D - None=0D -=0D ---*/=0D {=0D UINT32 Index;=0D =0D @@ -2257,11 +2398,15 @@ Returns: printf ("Total FIT Entry number: 0x%x\n", gFitTableContext.FitEntryNumbe= r);=0D printf ("FitHeader version: 0x%04x\n", gFitTableContext.FitHeaderVersion= );=0D for (Index =3D 0; Index < gFitTableContext.StartupAcmNumber; Index++) {= =0D - printf ("StartupAcm[%d] - (0x%08x, 0x%08x, 0x%04x)\n", Index, gFitTabl= eContext.StartupAcm[Index].Address, gFitTableContext.StartupAcm[Index].Size= , gFitTableContext.StartupAcmVersion[Index]);=0D + printf("StartupAcm[%d] - (0x%08x, 0x%08x, 0x%04x)\n", Index, gFitTable= Context.StartupAcm[Index].Address, gFitTableContext.StartupAcm[Index].Size,= gFitTableContext.StartupAcm[Index].Version);=0D }=0D if (gFitTableContext.DiagnstAcm.Address !=3D 0) {=0D printf ("DiagnosticAcm - (0x%08x, 0x%08x, 0x%04x)\n", gFitTableContext= .DiagnstAcm.Address, gFitTableContext.DiagnstAcm.Size, gFitTableContext.Dia= gnstAcmVersion);=0D }=0D +=0D + if (gFitTableContext.ProtBootPolicy.Address !=3D 0) {=0D + printf ("ProtBootPolicy - (0x%08x, 0x%08x, 0x%04x)\n", gFitTableContex= t.ProtBootPolicy.Address, gFitTableContext.ProtBootPolicy.Size, gFitTableCo= ntext.ProtBootPolicy.Version);=0D + }=0D for (Index =3D 0; Index < gFitTableContext.BiosModuleNumber; Index++) {= =0D printf ("BiosModule[%d] - (0x%08x, 0x%08x, 0x%04x)\n", Index, gFitTabl= eContext.BiosModule[Index].Address, gFitTableContext.BiosModule[Index].Size= , gFitTableContext.BiosModuleVersion);=0D }=0D @@ -2304,8 +2449,7 @@ CHAR8 *mFitTypeStr[] =3D { "MICROCODE ",=0D "STARTUP_ACM",=0D "DIAGNST_ACM",=0D - " ",=0D - " ",=0D + "BOOT_POLICY",=0D " ",=0D " ",=0D "BIOS_MODULE",=0D @@ -2320,27 +2464,19 @@ CHAR8 *mFitTypeStr[] =3D { "CSE_SECUREB"=0D };=0D =0D +/**=0D + Convert FitEntry type to a string.=0D +=0D + @param FitEntry Fit entry=0D +=0D + @return String=0D +**/=0D CHAR8 mFitSignature[] =3D "'_FIT_ ' ";=0D CHAR8 mFitSignatureInHeader[] =3D "' ' ";=0D CHAR8 *=0D FitTypeToStr (=0D IN FIRMWARE_INTERFACE_TABLE_ENTRY *FitEntry=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Convert FitEntry type to a string=0D -=0D -Arguments:=0D -=0D - FitEntry - Fit entry=0D -=0D -Returns:=0D -=0D - String=0D -=0D ---*/=0D {=0D if (FitEntry->Type =3D=3D FIT_TABLE_TYPE_HEADER) {=0D CopyMem (&mFitSignatureInHeader[1], &FitEntry->Address, sizeof(FitEntr= y->Address));=0D @@ -2361,27 +2497,19 @@ Returns: }=0D }=0D =0D +/**=0D + Print Fit table in flash image.=0D +=0D + @param FvBuffer FvRecovery binary buffer.=0D + @param FvSize FvRecovery size.=0D +=0D + @return None=0D +**/=0D VOID=0D PrintFitTable (=0D IN UINT8 *FvBuffer,=0D IN UINT32 FvSize=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Print Fit table in flash image=0D -=0D -Arguments:=0D -=0D - FvBuffer - FvRecovery binary buffer=0D - FvSize - FvRecovery size=0D -=0D -Returns:=0D -=0D - None=0D -=0D ---*/=0D {=0D FIRMWARE_INTERFACE_TABLE_ENTRY *FitEntry;=0D UINT32 EntryNum;=0D @@ -2460,11 +2588,12 @@ Returns: }=0D =0D /**=0D -=0D This function dump raw data.=0D =0D - @param Data raw data=0D - @param Size raw data size=0D + @param Data Raw data.=0D + @param Size Raw data size.=0D +=0D + @return none=0D =0D **/=0D VOID=0D @@ -2480,12 +2609,12 @@ DumpData ( }=0D =0D /**=0D -=0D This function dump raw data with colume format.=0D =0D - @param Data raw data=0D - @param Size raw data size=0D + @param Data Raw data=0D + @param Size Raw data size=0D =0D + @return none=0D **/=0D VOID=0D DumpHex (=0D @@ -2532,25 +2661,17 @@ CHAR8 *mCapabilityStr[] =3D { "STM support ",=0D };=0D =0D +/**=0D + DumpAcm information=0D +=0D + @param Acm - ACM buffer=0D +=0D + @retval None=0D +**/=0D VOID=0D DumpAcm (=0D IN ACM_FORMAT *Acm=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - DumpAcm information=0D -=0D -Arguments:=0D -=0D - Acm - ACM buffer=0D -=0D -Returns:=0D -=0D - None=0D -=0D ---*/=0D {=0D CHIPSET_ACM_INFORMATION_TABLE *ChipsetAcmInformationTable;=0D CHIPSET_ID_LIST *ChipsetIdList;=0D @@ -2600,23 +2721,21 @@ Returns: printf (" RSAPubKey - \n");=0D DumpHex (Buffer, Acm->KeySize * 4);=0D printf ("\n");=0D - Buffer +=3D Acm->KeySize * 4;=0D - //=0D - // To simplify the tool and making it independent of ACM header change,= =0D - // the rest of ACM parsing will be skipped starting ACM_HEADER_VERSION4= =0D - //=0D - if((Acm->HeaderVersion !=3D ACM_HEADER_VERSION_3) && (Acm->HeaderVersion= !=3D ACM_HEADER_VERSION_0)){=0D - printf (=0D - "*****************************************************************= ************\n\n"=0D - );=0D - return;=0D - }=0D + Buffer +=3D Acm->KeySize * 4; //add public key size (taken from header = variable * 4) to buffer.=0D +=0D + //add signature size to pointer.=0D if (Acm->HeaderVersion =3D=3D ACM_HEADER_VERSION_3) {=0D printf (" RSASig - \n");=0D DumpHex (Buffer, ACM_PKCS_1_5_RSA_SIGNATURE_SHA384_SIZE); // PKCS #1.5= RSA Signature=0D printf ("\n");=0D Buffer +=3D ACM_PKCS_1_5_RSA_SIGNATURE_SHA384_SIZE;=0D - } else {=0D + }=0D + else if ((Acm->HeaderVersion =3D=3D ACM_HEADER_VERSION_4) || (Acm->Heade= rVersion =3D=3D ACM_HEADER_VERSION_5)) {=0D + Buffer +=3D ACM_PKCS_1_5_RSA_SIGNATURE_SHA384_SIZE;=0D + Buffer +=3D ACM_XMSS_PUBLIC_KEY_SIZE;=0D + Buffer +=3D ACM_XMSS_SIGNATURE_SIZE;=0D + }=0D + else {=0D printf (" RSAPubExp - %08x\n", *(UINT32 *)Buffer);=0D Buffer +=3D 4;=0D =0D @@ -2627,6 +2746,10 @@ Returns: }=0D Buffer +=3D Acm->ScratchSize * 4;=0D =0D + if ((Acm->HeaderVersion =3D=3D ACM_HEADER_VERSION_4) || (Acm->HeaderVers= ion =3D=3D ACM_HEADER_VERSION_5)) {=0D + Buffer +=3D 60; //add reserved bytes.=0D + }=0D +=0D if ((Acm->ModuleSubType & ACM_MODULE_SUBTYPE_ANC_MODULE) =3D=3D 0) {=0D ChipsetAcmInformationTable =3D (CHIPSET_ACM_INFORMATION_TABLE *)Buffer= ;=0D printf ("Chipset ACM info:\n");=0D @@ -2697,28 +2820,77 @@ End: );=0D }=0D =0D -BOOLEAN=0D -CheckAcm (=0D - IN ACM_FORMAT *Acm,=0D - IN UINTN AcmMaxSize=0D - )=0D -/*++=0D +/**=0D + Get ACM FMS information.=0D +=0D + @param Acm ACM buffer.=0D + @param AcmFms Get ACM FMS.=0D + @param AcmMask Get ACM Mask.=0D +=0D + @retval NULL=0D +**/=0D +VOID=0D +GetAcmFms(=0D + IN ACM_FORMAT *Acm,=0D + OUT UINT32 *AcmFms,=0D + OUT UINT32 *AcmMask=0D +)=0D +{=0D + UINT32 FmsOffset =3D 0;=0D + UINT32 TmpFms =3D 0;=0D + UINT32 TmpMask =3D 0;=0D + UINT32 Index =3D 0;=0D + PROCESSOR_ID_LIST *ProcessorIdList =3D NULL;=0D +=0D + if ((Acm =3D=3D NULL) || (AcmFms =3D=3D NULL) || (AcmMask =3D=3D NULL))= =0D + return;=0D +=0D + *AcmFms =3D 0;=0D + *AcmMask =3D 0;=0D +=0D + switch (Acm->HeaderVersion) {=0D + case ACM_HEADER_VERSION_3:=0D + FmsOffset =3D *(UINT32*)((UINT8*)Acm + 0x6E8); //AcmInfoTable at 0x6C0= , +0x28 for ProcessorIdList=0D + break;=0D + case ACM_HEADER_VERSION_4:=0D + case ACM_HEADER_VERSION_5:=0D + FmsOffset =3D *(UINT32*)((UINT8*)Acm + 0x1CA8); //AcmInfoTable at 0x1C= 80, +0x28 for ProcessorIdList=0D + break;=0D + default:=0D + return;=0D + }=0D =0D -Routine Description:=0D + ProcessorIdList =3D (PROCESSOR_ID_LIST *)((UINT8*)Acm + FmsOffset);=0D =0D - Check Acm information=0D + if (ProcessorIdList->Count > 0) {=0D + TmpFms =3D ProcessorIdList->ProcessorID[0].FMS;=0D + *AcmFms =3D TmpFms;=0D + *AcmMask =3D DEFAULT_ACM_EXTENDED_MASK;=0D + }=0D =0D -Arguments:=0D + for (Index =3D 1; Index < ProcessorIdList->Count; Index++) {=0D + TmpMask =3D (TmpFms ^ ProcessorIdList->ProcessorID[Index].FMS);=0D + TmpFms &=3D ProcessorIdList->ProcessorID[Index].FMS;=0D + }=0D =0D - Acm - ACM buffer=0D - AcmMaxSize - ACM max size=0D + *AcmMask =3D ~TmpMask;=0D + return;=0D +}=0D =0D -Returns:=0D +/**=0D + Check Acm information.=0D =0D - TRUE - ACM is valid=0D - FALSE - ACM is invalid=0D + @param Acm ACM buffer.=0D + @param AcmMaxSize ACM max size.=0D =0D ---*/=0D + @retval TRUE ACM is valid.=0D + @retval FALSE ACM is invalid.=0D +**/=0D +BOOLEAN=0D +CheckAcm (=0D + IN ACM_FORMAT *Acm,=0D + IN UINTN AcmMaxSize=0D + )=0D {=0D CHIPSET_ACM_INFORMATION_TABLE *ChipsetAcmInformationTable;=0D CHIPSET_ID_LIST *ChipsetIdList;=0D @@ -2734,24 +2906,27 @@ Returns: return FALSE;=0D }=0D =0D - //=0D - // To simplify the tool and making it independent of ACM header change,= =0D - // the following check will be skipped starting ACM_HEADER_VERSION3=0D - //=0D - if((Acm->HeaderVersion !=3D ACM_HEADER_VERSION_3) && (Acm->HeaderVersion= !=3D ACM_HEADER_VERSION_0)){=0D - printf ("ACM header Version 4 or higher, bypassing other checks!\n");= =0D - return TRUE;=0D - }=0D + //move buffer pointer to address past generic ACM header (post scratchsi= ze)=0D Buffer =3D (UINT8 *)(Acm + 1);=0D Buffer +=3D Acm->KeySize * 4;=0D if (Acm->HeaderVersion =3D=3D ACM_HEADER_VERSION_3) {=0D Buffer +=3D ACM_PKCS_1_5_RSA_SIGNATURE_SHA384_SIZE;=0D - } else {=0D + }=0D + else if ((Acm->HeaderVersion =3D=3D ACM_HEADER_VERSION_4) || (Acm->Heade= rVersion =3D=3D ACM_HEADER_VERSION_5)) {=0D + Buffer +=3D ACM_PKCS_1_5_RSA_SIGNATURE_SHA384_SIZE;=0D + Buffer +=3D ACM_XMSS_PUBLIC_KEY_SIZE;=0D + Buffer +=3D ACM_XMSS_SIGNATURE_SIZE;=0D + }=0D + else {=0D Buffer +=3D 4;=0D Buffer +=3D ACM_PKCS_1_5_RSA_SIGNATURE_SHA256_SIZE;=0D }=0D Buffer +=3D Acm->ScratchSize * 4;=0D =0D + if ((Acm->HeaderVersion =3D=3D ACM_HEADER_VERSION_4) || (Acm->HeaderVers= ion =3D=3D ACM_HEADER_VERSION_5)) {=0D + Buffer +=3D 60; //add reserved bytes.=0D + }=0D +=0D if ((Acm->ModuleSubType & ACM_MODULE_SUBTYPE_ANC_MODULE) =3D=3D 0) {=0D ChipsetAcmInformationTable =3D (CHIPSET_ACM_INFORMATION_TABLE *)Buffer= ;=0D if ((UINTN)ChipsetAcmInformationTable >=3D (UINTN)Acm + AcmMaxSize) {= =0D @@ -2814,29 +2989,21 @@ End: return TRUE;=0D }=0D =0D +/**=0D + Fill the FIT table information to FvRecovery.=0D +=0D + @param FvBuffer FvRecovery binary buffer.=0D + @param FvSize FvRecovery size.=0D + @param FitTableOffset The offset of FIT table in FvRecovery file.=0D +=0D + @retval None=0D +**/=0D VOID=0D FillFitTable (=0D IN UINT8 *FvBuffer,=0D IN UINT32 FvSize,=0D IN UINT8 *FitTableOffset=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Fill the FIT table information to FvRecovery=0D -=0D -Arguments:=0D -=0D - FvBuffer - FvRecovery binary buffer=0D - FvSize - FvRecovery size=0D - FitTableOffset - The offset of FIT table in FvRecovery file=0D -=0D -Returns:=0D -=0D - None=0D -=0D ---*/=0D {=0D FIRMWARE_INTERFACE_TABLE_ENTRY *FitEntry;=0D UINT32 FitIndex;=0D @@ -2899,15 +3066,18 @@ Returns: // 4. StartupAcm=0D //=0D for (Index =3D 0; Index < gFitTableContext.StartupAcmNumber; Index++) {= =0D - if (gFitTableContext.StartupAcmVersion[Index] =3D=3D STARTUP_ACM_FIT_E= NTRY_200_VERSION) {=0D + if (gFitTableContext.StartupAcm[Index].Version =3D=3D STARTUP_ACM_FIT_= ENTRY_200_VERSION) {=0D + printf("ACM version 0x200\n");=0D FMS.Uint32 =3D gFitTableContext.StartupAcm[Index].FMS;=0D FMSMask.Uint32 =3D gFitTableContext.StartupAcm[Index].FMSMask;=0D + printf("ACM FMS:%08x\n", FMS.Uint32);=0D + printf("ACM FMSMask:%08x\n", FMSMask.Uint32);=0D FitEntry[FitIndex].Address =3D gFitTableContext.StartupAcm[Index].A= ddress;=0D FitEntry[FitIndex].Size[0] =3D NIBBLES_TO_BYTE (FMS.Bits.Family, FM= S.Bits.Model);=0D FitEntry[FitIndex].Size[1] =3D NIBBLES_TO_BYTE (FMS.Bits.ExtendedMo= del, FMS.Bits.Type);=0D FitEntry[FitIndex].Size[2] =3D NIBBLES_TO_BYTE (FMSMask.Bits.Family= , FMSMask.Bits.Model);=0D FitEntry[FitIndex].Rsvd =3D NIBBLES_TO_BYTE (FMSMask.Bits.Extend= edModel, FMSMask.Bits.Type);=0D - FitEntry[FitIndex].Version =3D (UINT16)gFitTableContext.StartupAcmV= ersion[Index];=0D + FitEntry[FitIndex].Version =3D (UINT16)gFitTableContext.StartupAcm[I= ndex].Version;=0D FitEntry[FitIndex].Type =3D FIT_TABLE_TYPE_STARTUP_ACM;=0D FitEntry[FitIndex].C_V =3D 0;=0D FitEntry[FitIndex].Checksum =3D NIBBLES_TO_BYTE (FMSMask.Bits.Extend= edFamily, FMS.Bits.ExtendedFamily);=0D @@ -2918,7 +3088,7 @@ Returns: FitEntry[FitIndex].Size[1] =3D (UINT8)(FitEntrySizeValue >> 8);=0D FitEntry[FitIndex].Size[2] =3D (UINT8)(FitEntrySizeValue >> 16);=0D FitEntry[FitIndex].Rsvd =3D 0;=0D - FitEntry[FitIndex].Version =3D (UINT16)gFitTableContext.StartupAcmV= ersion[Index];=0D + FitEntry[FitIndex].Version =3D (UINT16)gFitTableContext.StartupAcm[I= ndex].Version;=0D FitEntry[FitIndex].Type =3D FIT_TABLE_TYPE_STARTUP_ACM;=0D FitEntry[FitIndex].C_V =3D 0;=0D FitEntry[FitIndex].Checksum =3D 0;=0D @@ -2943,7 +3113,23 @@ Returns: FitIndex++;=0D }=0D //=0D - // 5. BiosModule=0D + // 5. (4) Bootable BootPolicy Data=0D + //=0D + if (gFitTableContext.ProtBootPolicy.Address !=3D 0) {=0D + FitEntry[FitIndex].Address =3D gFitTableContext.ProtBo= otPolicy.Address;=0D + FitEntry[FitIndex].Size[0] =3D (UINT8) (gFitTableConte= xt.ProtBootPolicy.Size);=0D + FitEntry[FitIndex].Size[1] =3D (UINT8) (gFitTableConte= xt.ProtBootPolicy.Size >> 8);=0D + FitEntry[FitIndex].Size[2] =3D (UINT8) (gFitTableConte= xt.ProtBootPolicy.Size >> 16);=0D + FitEntry[FitIndex].Rsvd =3D 0;=0D + FitEntry[FitIndex].Version =3D (UINT16)gFitTableContex= t.ProtBootPolicy.Version;=0D + FitEntry[FitIndex].Type =3D FIT_TABLE_TYPE_PROT_BOO= T_POLICY;=0D + FitEntry[FitIndex].C_V =3D 0;=0D + FitEntry[FitIndex].Checksum =3D 0;=0D + FitIndex++;=0D + }=0D +=0D + //=0D + // 6. BiosModule=0D //=0D //=0D // BiosModule segments order needs to be put from low address to high fo= r Btg requirement=0D @@ -2974,7 +3160,7 @@ Returns: }=0D =0D //=0D - // 6. Optional module=0D + // 7. Optional module=0D //=0D for (Index =3D 0; Index < gFitTableContext.OptionalModuleNumber; Index++= ) {=0D FitEntrySizeValue =3D gFitTableContext.OptionalModule[Index]= .Size;=0D @@ -2993,7 +3179,7 @@ Returns: }=0D =0D //=0D - // 7. Port module=0D + // 8. Port module=0D //=0D for (Index =3D 0; Index < gFitTableContext.PortModuleNumber; Index++) {= =0D FitEntrySizeValue =3D 0;=0D @@ -3029,27 +3215,19 @@ Returns: FitEntry[0].Checksum =3D Checksum;=0D }=0D =0D +/**=0D + Clear the FIT table information to Fvrecovery.=0D +=0D + @param FvBuffer - Fvrecovery binary buffer.=0D + @param FvSize - Fvrecovery size.=0D +=0D + @retval None=0D +**/=0D VOID=0D ClearFitTable (=0D IN UINT8 *FvBuffer,=0D IN UINT32 FvSize=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Clear the FIT table information to Fvrecovery=0D -=0D -Arguments:=0D -=0D - FvBuffer - Fvrecovery binary buffer=0D - FvSize - Fvrecovery size=0D -=0D -Returns:=0D -=0D - None=0D -=0D ---*/=0D {=0D FIRMWARE_INTERFACE_TABLE_ENTRY *FitEntry;=0D UINT32 EntryNum;=0D @@ -3097,30 +3275,22 @@ Returns: }=0D }=0D =0D +/**=0D + Read input file.=0D +=0D + @param FileName The input file name.=0D + @param FileData The input file data.=0D + @paramFileSize The input file size.=0D +=0D + @retval STATUS_SUCCESS Write file data successfully.=0D + @retval STATUS_ERROR The file data is not written.=0D +**/=0D STATUS=0D WriteOutputFile (=0D IN CHAR8 *FileName,=0D IN UINT8 *FileData,=0D IN UINT32 FileSize=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Read input file=0D -=0D -Arguments:=0D -=0D - FileName - The input file name=0D - FileData - The input file data=0D - FileSize - The input file size=0D -=0D -Returns:=0D -=0D - STATUS_SUCCESS - Write file data successfully=0D - STATUS_ERROR - The file data is not written=0D -=0D ---*/=0D {=0D FILE *FpOut;=0D =0D @@ -3157,28 +3327,78 @@ Returns: return STATUS_SUCCESS;=0D }=0D =0D +=0D UINT32=0D -GetFvRecoveryInfoFromFd (=0D +GetFvAcmSizeFromFd(=0D IN UINT8 *FdBuffer,=0D - IN UINT32 FdFileSize,=0D - OUT UINT8 **FvRecovery=0D - )=0D -/*++=0D + IN UINT32 FdFileSize=0D +)=0D +/**=0D + Get FV_ACM Size information from Fd file.=0D =0D -Routine Description:=0D + @param FdBuffer Fd file buffer.=0D + @param FdFileSize Fd file size.=0D =0D - Get FvRecovery information from Fd file.=0D + @retval FvACM size=0D +=0D +**/=0D +{=0D + UINT8 *FileBuffer =3D NULL;=0D + UINT32 FvAcmSize =3D 0;=0D + EFI_GUID ACMGuid =3D ACMFV_GUID;=0D + UINT32 FvLength;=0D + UINT32 FileLength;=0D +=0D + //*FvRecovery =3D NULL;=0D + FileBuffer =3D FindNextFvHeader(FdBuffer, FdFileSize);=0D + if (FileBuffer =3D=3D NULL) {=0D + return 0;=0D + }=0D =0D -Arguments:=0D + while ((UINTN)FileBuffer < (UINTN)FdBuffer + FdFileSize) {=0D + FvLength =3D (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)FileBuffer)->FvLen= gth;=0D =0D - FdBuffer - Fd file buffer.=0D - FdFileSize - Fd file size.=0D - FvRecovery - FvRecovery pointer in Fd file buffer=0D + if (FindFileFromFvByGuid(FileBuffer, FvLength, &ACMGuid, &FileLength) = !=3D NULL) {=0D + //=0D + // Found the ACM=0D + //=0D + FvAcmSize =3D FvLength;=0D + }=0D =0D -Returns:=0D - FvRecovery file size=0D + //=0D + // Next fv=0D + //=0D + FileBuffer =3D (UINT8 *)FileBuffer + FvLength;=0D + if ((UINTN)FileBuffer >=3D (UINTN)FdBuffer + FdFileSize) {=0D + break;=0D + }=0D + FileBuffer =3D FindNextFvHeader(FileBuffer, (UINTN)FdBuffer + FdFileSi= ze - (UINTN)FileBuffer);=0D + if (FileBuffer =3D=3D NULL) {=0D + break;=0D + }=0D =0D ---*/=0D + }=0D +=0D + return FvAcmSize;=0D +}=0D +=0D +/**=0D +=0D + Get FvRecovery information from Fd file.=0D +=0D + @param FdBuffer Fd file buffer.=0D + @param FdFileSize Fd file size.=0D + @param FvRecovery FvRecovery pointer in Fd file buffer=0D +=0D + @retval FvRecovery file size=0D +=0D +**/=0D +UINT32=0D +GetFvRecoveryInfoFromFd (=0D + IN UINT8 *FdBuffer,=0D + IN UINT32 FdFileSize,=0D + OUT UINT8 **FvRecovery=0D + )=0D {=0D UINT8 *FileBuffer =3D NULL;=0D UINT32 FvRecoveryFileSize =3D0;=0D @@ -3223,16 +3443,7 @@ Returns: return FvRecoveryFileSize;=0D }=0D =0D -void=0D -GetFMSFromFitEntry (=0D - IN FIRMWARE_INTERFACE_TABLE_ENTRY FitEntry,=0D - IN OUT PROCESSOR_ID *FMS,=0D - IN OUT PROCESSOR_ID *FMSMask=0D - )=0D -/*++=0D -=0D -Routine Description:=0D -=0D +/**=0D Get FMS information from FIT Entry.=0D =0D Note: Since FIT entry not record all the processor ID information.=0D @@ -3260,17 +3471,18 @@ Routine Description: | | Family | Model | ExtModel | Type | Family |= Model | |=0D +----------+-----------------------+-----------------------+------------= -----------+-----------------------+=0D =0D + @param FitEntry FIT entry information.=0D + @param FMS Processor ID information.=0D + @param FMSMask Processor ID mask information.=0D =0D -Arguments:=0D -=0D - FitEntry - FIT entry information.=0D - FMS - Processor ID information.=0D - FMSMask - Processor ID mask information.=0D -=0D -Returns:=0D - None=0D -=0D ---*/=0D + @retval None=0D +**/=0D +void=0D +GetFMSFromFitEntry (=0D + IN FIRMWARE_INTERFACE_TABLE_ENTRY FitEntry,=0D + IN OUT PROCESSOR_ID *FMS,=0D + IN OUT PROCESSOR_ID *FMSMask=0D + )=0D {=0D =0D FMS->Bits.Family =3D (FitEntry.Size[0] & 0xF0) >> 4;=0D @@ -3286,27 +3498,19 @@ Returns: FMSMask->Bits.ExtendedFamily =3D (FitEntry.Checksum & 0xF0) >> 4;=0D }=0D =0D +/**=0D + Get the FIT table information from Fvrecovery.=0D +=0D + @param FvBuffer Fvrecovery binary buffer.=0D + @param FvSize Fvrecovery size.=0D +=0D + @retval 0 - Fit Table not found=0D +**/=0D UINT32=0D GetFitEntryInfo (=0D IN UINT8 *FvBuffer,=0D IN UINT32 FvSize=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Get the FIT table information from Fvrecovery=0D -=0D -Arguments:=0D -=0D - FvBuffer - Fvrecovery binary buffer=0D - FvSize - Fvrecovery size=0D -=0D -Returns:=0D -=0D - 0 - Fit Table not found=0D -=0D ---*/=0D {=0D FIRMWARE_INTERFACE_TABLE_ENTRY *FitEntry;=0D UINT32 FitEntrySizeValue;=0D @@ -3360,14 +3564,20 @@ Returns: gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Addre= ss =3D (UINT32)FitEntry[FitIndex].Address;=0D gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Size = =3D FitEntrySizeValue;=0D gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Type = =3D FitEntry[FitIndex].Type;=0D - gFitTableContext.StartupAcmVersion[gFitTableContext.StartupAcmNumber= ] =3D FitEntry[FitIndex].Version;=0D - if (gFitTableContext.StartupAcmVersion[gFitTableContext.StartupAcmNu= mber] =3D=3D STARTUP_ACM_FIT_ENTRY_200_VERSION) {=0D + gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Versi= on =3D FitEntry[FitIndex].Version;=0D +=0D + if (gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].V= ersion =3D=3D STARTUP_ACM_FIT_ENTRY_200_VERSION) {=0D GetFMSFromFitEntry (FitEntry[FitIndex], &FMS, &FMSMask);=0D gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].FMS= =3D FMS.Uint32;=0D gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].FMS= Mask =3D FMSMask.Uint32;=0D }=0D gFitTableContext.StartupAcmNumber++;=0D break;=0D + case FIT_TABLE_TYPE_PROT_BOOT_POLICY:=0D + gFitTableContext.ProtBootPolicy.Address =3D (UINT32)FitEntry[FitInde= x].Address;=0D + gFitTableContext.ProtBootPolicy.Version =3D FitEntry[FitIndex].Versi= on;=0D + gFitTableContext.ProtBootPolicy.Size =3D GetFirmwareInterfaceTableEn= trySize (&FitEntry[FitIndex]);=0D + break;=0D case FIT_TABLE_TYPE_BIOS_MODULE:=0D gFitTableContext.BiosModule[gFitTableContext.BiosModuleNumber].Addre= ss =3D (UINT32)FitEntry[FitIndex].Address;=0D gFitTableContext.BiosModule[gFitTableContext.BiosModuleNumber].Size = =3D FitEntrySizeValue * 16;=0D @@ -3398,27 +3608,20 @@ Returns: return gFitTableContext.FitEntryNumber;=0D }=0D =0D +/**=0D + Main function for FitGen.=0D +=0D + @param argc Number of command line parameters.=0D + @param argv Array of pointers to parameter strings.=0D +=0D + @retval STATUS_SUCCESS Utility exits successfully.=0D + @retval STATUS_ERROR Some error occurred during execution.=0D +**/=0D STATUS=0D FitGen (=0D IN INTN argc,=0D IN CHAR8 **argv=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Main function for FitGen.=0D -=0D -Arguments:=0D -=0D - argc - Number of command line parameters.=0D - argv - Array of pointers to parameter strings.=0D -=0D -Returns:=0D - STATUS_SUCCESS - Utility exits successfully.=0D - STATUS_ERROR - Some error occurred during execution.=0D -=0D ---*/=0D {=0D UINT32 FvRecoveryFileSize;=0D UINT8 *FileBuffer;=0D @@ -3433,7 +3636,7 @@ Returns: UINT32 FdFileSize;=0D =0D UINT8 *AcmBuffer;=0D - INTN Index;=0D + INTN Index =3D 0;=0D UINT32 FixedFitLocation;=0D =0D FileBufferRaw =3D NULL;=0D @@ -3514,6 +3717,7 @@ Returns: =0D FitTableOffset =3D GetFreeSpaceForFit (FileBuffer, FvRecoveryFileSize,= FitTableSize, FixedFitLocation);=0D if (FitTableOffset =3D=3D NULL) {=0D + printf ("Error - FitTableOffset is NULL\n");=0D return STATUS_ERROR;=0D }=0D =0D @@ -3526,7 +3730,10 @@ Returns: // Get ACM buffer=0D //=0D for (Index =3D 0; Index < (INTN)gFitTableContext.StartupAcmNumber; Ind= ex ++) {=0D + printf("ACM address:%08x\n", gFitTableContext.StartupAcm[Index].Addr= ess);=0D + printf("ACM size:%08x\n", gFitTableContext.StartupAcm[Index].Size);= =0D if (gFitTableContext.StartupAcm[Index].Address !=3D 0) {=0D + printf("get AcmBuffer\n");=0D AcmBuffer =3D FLASH_TO_MEMORY(gFitTableContext.StartupAcm[Index].A= ddress, FdFileBuffer, FdFileSize);=0D if ((AcmBuffer < FdFileBuffer) || (AcmBuffer + gFitTableContext.St= artupAcm[Index].Size > FdFileBuffer + FdFileSize)) {=0D printf ("ACM out of range - can not validate it\n");=0D @@ -3534,11 +3741,20 @@ Returns: }=0D =0D if (AcmBuffer !=3D NULL) {=0D - if (CheckAcm ((ACM_FORMAT *)AcmBuffer, gFitTableContext.StartupA= cm[Index].Size)) {=0D - DumpAcm ((ACM_FORMAT *)AcmBuffer);=0D - } else {=0D - Status =3D STATUS_ERROR;=0D - goto exitFunc;=0D + if (CheckAcm((ACM_FORMAT *)AcmBuffer, gFitTableContext.StartupAc= m[Index].Size)) {=0D + DumpAcm((ACM_FORMAT *)AcmBuffer);=0D +=0D + if (gFitTableContext.StartupAcm[Index].Version >=3D 0x200) {=0D + GetAcmFms((ACM_FORMAT *)AcmBuffer, &gFitTableContext.Startup= Acm[Index].FMS, &gFitTableContext.StartupAcm[Index].FMSMask);=0D + printf("ACM FMS:%08x\n", gFitTableContext.StartupAcm[Index].= FMS);=0D + printf("ACM FMS Mask:%08x\n", gFitTableContext.StartupAcm[In= dex].FMSMask);=0D + }=0D + }=0D + else {=0D + if (Index =3D=3D 0) {=0D + Status =3D STATUS_ERROR;=0D + goto exitFunc;=0D + }=0D }=0D }=0D }=0D @@ -3592,32 +3808,31 @@ exitFunc: return Status;=0D }=0D =0D +/**=0D + View function for FitGen.=0D +=0D + @param argc Number of command line parameters.=0D + @param argv Array of pointers to parameter strings=0D +=0D + @retval STATUS_SUCCESS Utility exits successfully.=0D + @retval STATUS_ERROR Some error occurred during execution.=0D +**/=0D STATUS=0D FitView (=0D IN INTN argc,=0D IN CHAR8 **argv=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - View function for FitGen.=0D -=0D -Arguments:=0D -=0D - argc - Number of command line parameters.=0D - argv - Array of pointers to parameter strings.=0D -=0D -Returns:=0D - STATUS_SUCCESS - Utility exits successfully.=0D - STATUS_ERROR - Some error occurred during execution.=0D -=0D ---*/=0D {=0D - UINT32 FvRecoveryFileSize;=0D - UINT8 *FileBuffer;=0D - UINT8 *FileBufferRaw =3D NULL;=0D - STATUS Status;=0D + UINT32 FvRecoveryFileSize;=0D + UINT8 *FileBuffer;=0D + UINT8 *FileBufferRaw =3D NULL;=0D + STATUS Status;=0D + FILE *FpIn;=0D + UINT32 FlashValidSig =3D 0;=0D + UINT32 Frba;=0D + UINT32 BiosRegionBaseOffset;=0D + FLASH_MAP_0_REGISTER FlashMap0;=0D + FLASH_REGION_1_BIOS_REGISTER FlashRegion1;=0D =0D //=0D // Step 1: Read input file=0D @@ -3642,13 +3857,57 @@ Returns: gFitTableContext.FitTablePointerOffset =3D xtoi (argv[3 + 1]);=0D } else {=0D Error (NULL, 0, 0, "FIT offset not specified!", NULL);=0D + Status =3D STATUS_ERROR;=0D goto exitFunc;=0D }=0D } else {=0D Error (NULL, 0, 0, "Invalid view option: ", "%s", argv[3]);=0D + Status =3D STATUS_ERROR;=0D goto exitFunc;=0D }=0D =0D + //=0D + //Check the File Path=0D + //=0D + if (!CheckPath (argv[2])) {=0D + Error (NULL, 0, 0, "File path is invalid!", NULL);=0D + Status =3D STATUS_ERROR;=0D + goto exitFunc;=0D + }=0D + //=0D + // Open the Input file=0D + //=0D + if ((FpIn =3D fopen (argv[2], "rb")) =3D=3D NULL) {=0D + Error (NULL, 0, 0, "Unable open the file!", NULL);=0D + Status =3D STATUS_WARNING;=0D + goto exitFunc;=0D + }=0D + //=0D + //Seek and read the Flash Valid Signature;=0D + //=0D + fseek (FpIn, FLVALSIG_BASE_OFFSET, SEEK_SET);=0D + fread (&FlashValidSig, 4, 1, FpIn);=0D + if (FlashValidSig =3D=3D FLASH_VALID_SIGNATURE) {=0D + //=0D + //Seek and read the Flash Map 0 Register;=0D + //=0D + fseek (FpIn, FLMAP0_BASE_OFFSET, SEEK_SET);=0D + fread (&FlashMap0, 4, 1, FpIn);=0D + Frba =3D FlashMap0.Frba << 4 & 0xFF0; //FRBA identifies address bits = [11:4] for the region portion of the flashdescriptor, bits [26:12] and bits= [3:0] are 0=0D + //=0D + //Seek and read the Flash Region 1 (BIOS) Register;=0D + //=0D + BiosRegionBaseOffset =3D Frba + 0x4;=0D + fseek (FpIn, BiosRegionBaseOffset, SEEK_SET);=0D + fread (&FlashRegion1, 4, 1, FpIn);=0D + FileBuffer =3D (UINT8 *)(FileBuffer + (FlashRegion1.RegionBase << 12))= ; // RegionBase specifies address bits [26:12] for the Region Base.=0D + FvRecoveryFileSize =3D ((FlashRegion1.RegionLimit << 12 | 0xFFF) + 1) = - (FlashRegion1.RegionBase << 12); //RegionLimit specifies bits [26:12] of= the ending address for this region, bits [11:0] are assumed to be FFFh.=0D + }=0D + //=0D + // Close the Input file=0D + //=0D + fclose (FpIn);=0D +=0D //=0D // For debug=0D //=0D @@ -3661,27 +3920,20 @@ exitFunc: return Status;=0D }=0D =0D +/**=0D + Main function.=0D +=0D + @param argc Number of command line parameters.=0D + @param argv Array of pointers to parameter strings=0D +=0D + @retval STATUS_SUCCESS Utility exits successfully.=0D + @retval STATUS_ERROR Some error occurred during execution.=0D +**/=0D int=0D main (=0D int argc,=0D char **argv=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Main function.=0D -=0D -Arguments:=0D -=0D - argc - Number of command line parameters.=0D - argv - Array of pointers to parameter strings.=0D -=0D -Returns:=0D - STATUS_SUCCESS - Utility exits successfully.=0D - STATUS_ERROR - Some error occurred during execution.=0D -=0D ---*/=0D {=0D SetUtilityName (UTILITY_NAME);=0D =0D @@ -3703,24 +3955,18 @@ Returns: return STATUS_ERROR;=0D }=0D }=0D +/**=0D + Convert hex string to uint=0D +=0D + @param str The string=0D =0D + @retval Integer value=0D +=0D +**/=0D unsigned int=0D xtoi (=0D char *str=0D )=0D -/*++=0D -=0D -Routine Description:=0D -=0D - Convert hex string to uint=0D -=0D -Arguments:=0D -=0D - str - The string=0D -=0D -Returns:=0D -=0D ---*/=0D {=0D unsigned int u;=0D char c;=0D diff --git a/Silicon/Intel/Tools/FitGen/FitGen.h b/Silicon/Intel/Tools/FitG= en/FitGen.h index 511ab652ab..2d24ecb584 100644 --- a/Silicon/Intel/Tools/FitGen/FitGen.h +++ b/Silicon/Intel/Tools/FitGen/FitGen.h @@ -36,7 +36,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =0D #define FIT_SPEC_VERSION_MAJOR 1=0D #define FIT_SPEC_VERSION_MINOR 4=0D -=0D //=0D // The minimum number of arguments accepted from the command line.=0D //=0D @@ -50,4 +49,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =0D #define ROUNDUP(Size, Alignment) (((Size) + (Alignment) - 1) / (Alignment)= * (Alignment))=0D =0D +UINT32=0D +GetFvAcmSizeFromFd(=0D +IN UINT8 *FdBuffer,=0D +IN UINT32 FdFileSize=0D +);=0D +=0D #endif=0D --=20 2.30.1.windows.1