From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web12.2581.1575356475105116217 for ; Mon, 02 Dec 2019 23:01:15 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: liming.gao@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Dec 2019 23:01:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,272,1571727600"; d="scan'208";a="213308320" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga006.jf.intel.com with ESMTP; 02 Dec 2019 23:01:03 -0800 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 2 Dec 2019 23:01:03 -0800 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 2 Dec 2019 23:01:03 -0800 Received: from shsmsx154.ccr.corp.intel.com (10.239.6.54) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 2 Dec 2019 23:01:02 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.90]) by SHSMSX154.ccr.corp.intel.com ([169.254.7.71]) with mapi id 14.03.0439.000; Tue, 3 Dec 2019 15:01:01 +0800 From: "Liming Gao" To: "Chen, Chen A" , "devel@edk2.groups.io" CC: "Feng, Bob C" Subject: Re: [edk2-platform][PATCH] Silicon/Tools/FitGen: Add FitGen feature to support uCode Capsule Update Thread-Topic: [edk2-platform][PATCH] Silicon/Tools/FitGen: Add FitGen feature to support uCode Capsule Update Thread-Index: AQHVqNPRuhBTRypQgkiMeysYiUjsQ6emV16QgAGk+3A= Date: Tue, 3 Dec 2019 07:01:00 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E55AF35@SHSMSX104.ccr.corp.intel.com> References: <1575265560-383388-1-git-send-email-liming.gao@intel.com> <8CCE94730AD68946B3D28B43192D9D2D06F1B589@shsmsx102.ccr.corp.intel.com> In-Reply-To: <8CCE94730AD68946B3D28B43192D9D2D06F1B589@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: liming.gao@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Chen: Please correct the patch style. Some lines are not changed, but they are = in the patch.=20 Thanks Liming >-----Original Message----- >From: Chen, Chen A >Sent: Monday, December 02, 2019 1:52 PM >To: Gao, Liming ; devel@edk2.groups.io >Cc: Feng, Bob C >Subject: RE: [edk2-platform][PATCH] Silicon/Tools/FitGen: Add FitGen featu= re >to support uCode Capsule Update > >Bugzilla, https://bugzilla.tianocore.org/show_bug.cgi?id=3D2321 > >-----Original Message----- >From: Gao, Liming >Sent: Monday, December 2, 2019 1:46 PM >To: devel@edk2.groups.io >Cc: Chen, Chen A ; Feng, Bob C > >Subject: [edk2-platform][PATCH] Silicon/Tools/FitGen: Add FitGen feature t= o >support uCode Capsule Update > >From: Chen A Chen > >Add slot mode handling with a header array. > >Signed-off-by: Chen A Chen >Cc: Liming Gao >Cc: Bob Feng >--- > Silicon/Intel/Tools/FitGen/FitGen.c | 183 +++++++++++++++++++++++++---- >------- > 1 file changed, 129 insertions(+), 54 deletions(-) > >diff --git a/Silicon/Intel/Tools/FitGen/FitGen.c >b/Silicon/Intel/Tools/FitGen/FitGen.c >index faf9880060..ab236d0ab0 100644 >--- a/Silicon/Intel/Tools/FitGen/FitGen.c >+++ b/Silicon/Intel/Tools/FitGen/FitGen.c >@@ -312,12 +312,13 @@ Returns: > { > printf ("Usage (generate): %s [-D] InputFvRecoveryFile >OutputFvRecoveryFile\n" > "\t[-V ]\n" >- "\t[-F ] [-F ] [-= V >]\n" >- "\t[-NA]\n" >- "\t[-CLEAR]\n" >- "\t[-I ]\n" >- "\t[-S |] [-V >]\n" >- "\t[-B ] [-B ...] [-V >]\n" >+ "\t[-F ] [-F ] [-= V >]\n" >+ "\t[-NA]\n" >+ "\t[-CLEAR]\n" >+ "\t[-L ]\n" >+ "\t[-I ]\n" >+ "\t[-S |] [-V >]\n" >+ "\t[-B ] [-B ...] [-V >]\n" > "\t[-M ] [-M ...]|[-U MicrocodeBase>|MicrocodeRegionSize>|] [-V ]\n" > "\t[-O RecordType |RecordDataSize>|| [-V ]] >[-O ... [-V ...]]\n" > "\t[-P RecordType [-V >]] [-P ... [-V ...]]\n" >@@ -337,12 +338,14 @@ Returns: > printf ("\tMicrocodeSize - Size of Microcode.\n"); > printf ("\tMicrocodeFv - Name of Microcode.fv file.\n"); > printf ("\tMicrocodeBase - The base address of Microcode.fv in= final FD >image.\n"); >- printf ("\tMicrocodeRegionOffset - Offset of Microcode region in input= FD >image.\n"); >- printf ("\tMicrocodeRegionSize - Size of Microcode region in input F= D >image.\n"); >- printf ("\tMicrocodeGuid - Guid of Microcode Module.\n"); >- printf ("\t-NA - No 0x800 aligned Microcode requirem= ent. No -NA >means Microcode is 0x800 aligned.\n"); >- printf ("\tRecordType - FIT entry record type. User should = ensure it is >ordered.\n"); >- printf ("\tRecordDataAddress - FIT entry record data address.\n"); >+ printf ("\tMicrocodeRegionOffset - Offset of Microcode region in input= FD >image.\n"); >+ printf ("\tMicrocodeRegionSize - Size of Microcode region in input F= D >image.\n"); >+ printf ("\tMicrocodeGuid - Guid of Microcode Module.\n"); >+ printf ("\tMicrocodeSlotSize - Occupied region size of each Microc= ode >binary.\n"); >+ printf ("\tMicrocodeFfsGuid - Guid of FFS which is used to save >Microcode binary"); >+ printf ("\t-NA - No 0x800 aligned Microcode requirem= ent. No -NA >means Microcode is 0x800 aligned.\n"); >+ printf ("\tRecordType - FIT entry record type. User should = ensure it is >ordered.\n"); >+ printf ("\tRecordDataAddress - FIT entry record data address.\n"); > printf ("\tRecordDataSize - FIT entry record data size.\n"); > printf ("\tRecordDataGuid - FIT entry record data GUID.\n"); > printf ("\tRecordBinFile - FIT entry record data binary file.\= n"); >@@ -761,32 +764,39 @@ Returns: > FitEntryNumber - The FIT entry number > 0 - Argument parse fail > >-*/ >-{ >- EFI_GUID Guid; >- INTN Index; >- UINT8 *FileBuffer; >- UINT32 FileSize; >+*/ >+{ >+ EFI_GUID Guid; >+ EFI_GUID MicrocodeFfsGuid; >+ INTN Index; >+ UINT8 *FileBuffer; >+ UINT32 FileSize; > UINT32 Type; > UINT8 *MicrocodeFileBuffer; > UINT8 *MicrocodeFileBufferRaw; > UINT32 MicrocodeFileSize; >- UINT32 MicrocodeBase; >- UINT32 MicrocodeSize; >- UINT8 *MicrocodeBuffer; >- UINT32 MicrocodeRegionOffset; >- UINT32 MicrocodeRegionSize; >- STATUS Status; >- EFI_FIRMWARE_VOLUME_HEADER *FvHeader; >- UINTN FitEntryNumber; >- BOOLEAN BiosInfoExist; >- BIOS_INFO_HEADER *BiosInfo; >- BIOS_INFO_STRUCT *BiosInfoStruct; >- UINTN BiosInfoIndex; >- >- // >- // Init index >- // >+ UINT32 MicrocodeBase; >+ UINT32 MicrocodeSize; >+ UINT8 *MicrocodeBuffer; >+ UINT32 MicrocodeBufferSize; >+ UINT8 *Walker; >+ UINT32 MicrocodeRegionOffset; >+ UINT32 MicrocodeRegionSize; >+ UINT32 SlotSize; >+ STATUS Status; >+ EFI_FIRMWARE_VOLUME_HEADER *FvHeader; >+ UINTN FitEntryNumber; >+ BOOLEAN BiosInfoExist; >+ BOOLEAN SlotMode; >+ BIOS_INFO_HEADER *BiosInfo; >+ BIOS_INFO_STRUCT *BiosInfoStruct; >+ UINTN BiosInfoIndex; >+ >+ SlotMode =3D FALSE; >+ >+ // >+ // Init index >+ // > Index =3D 3; > if (((strcmp (argv[1], "-D") =3D=3D 0) || > (strcmp (argv[1], "-d") =3D=3D 0)) ) { @@ -897,13 +907,40 @@ Retur= ns: > // Do not parse any more > // > return 0; >- } >- >- // >- // 0.5 BiosInfo >- // >- if ((Index + 1 >=3D argc) || >- ((strcmp (argv[Index], "-I") !=3D 0) && >+ } >+ >+ // >+ // 0.5 SlotSize >+ // >+ if ((Index + 1 >=3D argc) || >+ ((strcmp (argv[Index], "-L") !=3D 0) && >+ (strcmp (argv[Index], "-l") !=3D 0)) ) { >+ // >+ // Bypass >+ // >+ SlotSize =3D 0; >+ } else { >+ SlotSize =3D xtoi (argv[Index + 1]); >+ >+ if (SlotSize =3D=3D 0) { >+ printf ("Invalid slotsize =3D %d\n", SlotSize); >+ return 0; >+ } >+ >+ SlotMode =3D IsGuidData(argv[Index + 2], &MicrocodeFfsGuid); >+ if (!SlotMode) { >+ printf ("Need a ffs GUID for search uCode ffs\n"); >+ return 0; >+ } >+ >+ Index +=3D 3; >+ } >+ >+ // >+ // 0.6 BiosInfo >+ // >+ if ((Index + 1 >=3D argc) || >+ ((strcmp (argv[Index], "-I") !=3D 0) && > (strcmp (argv[Index], "-i") !=3D 0)) ) { > // > // Bypass >@@ -1004,12 +1041,22 @@ Returns: > if (FvHeader->Signature =3D=3D EFI_FVH_SIGNATURE) { > // Skip FV header + FFS header > MicrocodeBuffer =3D MicrocodeFileBuffer + >sizeof(EFI_FIRMWARE_VOLUME_HEADER) + >sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(EFI_FFS_FILE_HEADER); >- } else { >- MicrocodeBuffer =3D MicrocodeFileBuffer; >- } >- while ((UINT32)(MicrocodeBuffer - MicrocodeFileBuffer) < >MicrocodeFileSize) { >- if (*(UINT32 *)(MicrocodeBuffer) !=3D 0x1) { // HeaderVersi= on >- break; >+ } else { >+ MicrocodeBuffer =3D MicrocodeFileBuffer; >+ } >+ >+ if (SlotMode) { >+ MicrocodeBuffer =3D FindFileFromFvByGuid(MicrocodeFileBuffe= r, >MicrocodeFileSize, &MicrocodeFfsGuid, &MicrocodeBufferSize); >+ if (MicrocodeBuffer =3D=3D NULL) { >+ printf ("-L Parameter incorrect, GUID not found\n"); >+ // not found >+ return 0; >+ } >+ } >+ >+ while ((UINT32)(MicrocodeBuffer - MicrocodeFileBuffer) < >MicrocodeFileSize) { >+ if (*(UINT32 *)(MicrocodeBuffer) !=3D 0x1) { // HeaderVersi= on >+ break; > } > if (*(UINT32 *)(MicrocodeBuffer + 20) !=3D 0x1) { // Loader= Version > break; >@@ -1037,13 +1084,41 @@ Returns: > >gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type =3D >FIT_TABLE_TYPE_MICROCODE; > >gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address =3D >MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) >MicrocodeFileBuffer); > >gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Size =3D >MicrocodeSize; >- gFitTableContext.MicrocodeNumber++; >- gFitTableContext.FitEntryNumber++; >- >- MicrocodeBuffer +=3D MicrocodeSize; >- } >- } >- break; >+ gFitTableContext.MicrocodeNumber++; >+ gFitTableContext.FitEntryNumber++; >+ >+ if (SlotSize !=3D 0) { >+ MicrocodeBuffer +=3D SlotSize; >+ } else { >+ MicrocodeBuffer +=3D MicrocodeSize; >+ } >+ } >+ >+ /// >+ /// Check the remaining buffer >+ /// >+ if (((UINT32)(MicrocodeBuffer - MicrocodeFileBuffer) < >MicrocodeFileSize) && SlotMode !=3D 0) { >+ for (Walker =3D MicrocodeBuffer; Walker < MicrocodeFileBuff= er + >MicrocodeFileSize; Walker++) { >+ if (*Walker !=3D 0xFF) { >+ printf ("Error: detect non-spare space after uCode arra= y, please >check uCode array!\n"); >+ return 0; >+ } >+ } >+ >+ /// >+ /// Split the spare space as empty buffer for save uCode pa= tch. >+ /// >+ while (MicrocodeBuffer + SlotSize <=3D MicrocodeFileBuffer = + >MicrocodeFileSize) { >+ >gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type =3D >FIT_TABLE_TYPE_MICROCODE; >+ >gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address =3D >MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) >MicrocodeFileBuffer); >+ gFitTableContext.MicrocodeNumber++; >+ gFitTableContext.FitEntryNumber++; >+ >+ MicrocodeBuffer +=3D SlotSize; >+ } >+ } >+ } >+ break; > case FIT_TABLE_TYPE_TPM_POLICY: > case FIT_TABLE_TYPE_BIOS_POLICY: > case FIT_TABLE_TYPE_TXT_POLICY: >-- >2.16.2.windows.1