From nobody Sat Apr 20 15:17:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+51517+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51517+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1575265571; cv=none; d=zohomail.com; s=zohoarc; b=EOjQH0ivAfbt4BKlYZCQQ2Gp7BbAJ8EWfTVRcC35Iw0vWeh29ATX0b7Vh8iz2so2RH4D+sxko2hROUptwaOMZpatAlY4dLvQetlhcBb3EN0MJYVawujle4gGraZCKZR62egRtE/u6Fwtd7OBMkoluXwaPhXBH70XIcL3N5GXKCU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575265571; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=a8ROdqB9NKX5wbFSB3l9lWzM7ka53SLGqdOXiVVOAbo=; b=XXZaek/g+Ip1dbOSp51t/OLeBSPasqfT27fgTBqpdq7Wb1Ljl6whu2VCVu/JEZqBN6Bas2pXa7bWZeBduZg4wSJFkwRbrGDf48LfnZDoSt1gW0ZbMDS0Pk/7T2VOVSVgya3I4moADPWym6TMELvUBMizsx9b+nhNA9yeeA10pcQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51517+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1575265571078924.0644985574763; Sun, 1 Dec 2019 21:46:11 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id JFveYY1788612xZcsBHnLYZ5; Sun, 01 Dec 2019 21:46:10 -0800 X-Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web11.56.1575265569625827148 for ; Sun, 01 Dec 2019 21:46:09 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Dec 2019 21:46:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,268,1571727600"; d="scan'208";a="200486164" X-Received: from shwde7172.ccr.corp.intel.com ([10.239.158.22]) by orsmga007.jf.intel.com with ESMTP; 01 Dec 2019 21:46:07 -0800 From: "Liming Gao" To: devel@edk2.groups.io Cc: Chen A Chen , Bob Feng Subject: [edk2-devel] [edk2-platform][PATCH] Silicon/Tools/FitGen: Add FitGen feature to support uCode Capsule Update Date: Mon, 2 Dec 2019 13:46:00 +0800 Message-Id: <1575265560-383388-1-git-send-email-liming.gao@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,liming.gao@intel.com X-Gm-Message-State: y6URroxeAUsnbPTL9Jzl7jyAx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1575265570; bh=tbYrMciZL4N5OPz2t+pHgWphVBxErAKmk7dS66i1E+o=; h=Cc:Date:From:Reply-To:Subject:To; b=H9N5xskE3MunWnsrJ5Ph0Se/IkekjxhWT8jgOnCt8QJU4OSJ1gfvUcVfkkYZURlzDTy sqKI1vEKCVWF46RIqSHMW1RL7qEYAumUwyPgsdHPTMZjQS4+Uu6Qor7BBSvPM/5269Ks6 OFTgBl4zXz3x0U+mlVHrCPXaB04Ln3+ErMA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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/FitG= en/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 OutputFvRecoveryF= ile\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 ||] [-V ]\n" "\t[-O RecordType ||| [-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 FD= image.\n"); - printf ("\tMicrocodeGuid - Guid of Microcode Module.\n"); - printf ("\t-NA - No 0x800 aligned Microcode requireme= nt. No -NA means Microcode is 0x800 aligned.\n"); - printf ("\tRecordType - FIT entry record type. User should e= nsure 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 FD= image.\n"); + printf ("\tMicrocodeGuid - Guid of Microcode Module.\n"); + printf ("\tMicrocodeSlotSize - Occupied region size of each Microco= de binary.\n"); + printf ("\tMicrocodeFfsGuid - Guid of FFS which is used to save Mi= crocode binary"); + printf ("\t-NA - No 0x800 aligned Microcode requireme= nt. No -NA means Microcode is 0x800 aligned.\n"); + printf ("\tRecordType - FIT entry record type. User should e= nsure 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 =20 -*/ -{ - 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 @@ Returns: // 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_FIRMWAR= E_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(EFI_FFS_FILE_HEA= DER); - } else { - MicrocodeBuffer =3D MicrocodeFileBuffer; - } - while ((UINT32)(MicrocodeBuffer - MicrocodeFileBuffer) < Micro= codeFileSize) { - if (*(UINT32 *)(MicrocodeBuffer) !=3D 0x1) { // HeaderVersion - break; + } else { + MicrocodeBuffer =3D MicrocodeFileBuffer; + } + + if (SlotMode) { + MicrocodeBuffer =3D FindFileFromFvByGuid(MicrocodeFileBuffer= , MicrocodeFileSize, &MicrocodeFfsGuid, &MicrocodeBufferSize); + if (MicrocodeBuffer =3D=3D NULL) { + printf ("-L Parameter incorrect, GUID not found\n"); + // not found + return 0; + } + } + + while ((UINT32)(MicrocodeBuffer - MicrocodeFileBuffer) < Micro= codeFileSize) { + if (*(UINT32 *)(MicrocodeBuffer) !=3D 0x1) { // HeaderVersion + break; } if (*(UINT32 *)(MicrocodeBuffer + 20) !=3D 0x1) { // LoaderV= ersion 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) < Microco= deFileSize) && SlotMode !=3D 0) { + for (Walker =3D MicrocodeBuffer; Walker < MicrocodeFileBuffe= r + MicrocodeFileSize; Walker++) { + if (*Walker !=3D 0xFF) { + printf ("Error: detect non-spare space after uCode array= , please check uCode array!\n"); + return 0; + } + } + + /// + /// Split the spare space as empty buffer for save uCode pat= ch. + /// + while (MicrocodeBuffer + SlotSize <=3D MicrocodeFileBuffer += MicrocodeFileSize) { + gFitTableContext.Microcode[gFitTableContext.MicrocodeNumbe= r].Type =3D FIT_TABLE_TYPE_MICROCODE; + gFitTableContext.Microcode[gFitTableContext.MicrocodeNumbe= r].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: --=20 2.16.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#51517): https://edk2.groups.io/g/devel/message/51517 Mute This Topic: https://groups.io/mt/64551980/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-