From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web10.3423.1654670768154504017 for ; Tue, 07 Jun 2022 23:46:09 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=gEuplO3d; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: wenyi.jiang@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654670768; x=1686206768; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4YgFUvSg1FflP0cjt8zgqizv6vSYsr//3J9pMdQdLRM=; b=gEuplO3dvX7hFuD9JNAJKooxKo7xaaVUIDu3HX6Z1i0E3JulLqSRAWLz AUeA+jOultK88mLyN4VRZqsLf72JVyTwL8Jra0VUmDQ/thjqCXEq7ZJcp +Ganx2ltedRBftB92Zi3Q87FqNyzvGjcX11MQRWRxpGHV5yl540rrw81W /ZRTiwBCUfdFiKTFGRtOgsX3kvMRg7oZRnVFP90noQWwbSDB/flkPojkE 6OSH81052d1y0aJFuabKD83KxQMsQUP6bLgrGFezCtPSXbh73f+4j93aV ixLvtqV/+X5p8xhuKsvfyeNw1++8ISclih4GAWPEXSXa4YdMRn0Hj8s+L g==; X-IronPort-AV: E=McAfee;i="6400,9594,10371"; a="256629134" X-IronPort-AV: E=Sophos;i="5.91,285,1647327600"; d="scan'208";a="256629134" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jun 2022 23:46:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,285,1647327600"; d="scan'208";a="670388081" Received: from shwdeopenlab703.ccr.corp.intel.com ([10.239.182.196]) by FMSMGA003.fm.intel.com with ESMTP; 07 Jun 2022 23:46:04 -0700 From: wenyijia To: devel@edk2.groups.io Cc: Chen Christine , Bob Feng Subject: [PATCH v1 1/1] Tools\FitGen: Add extra parameter fixed FIT address Date: Wed, 8 Jun 2022 14:46:02 +0800 Message-Id: <20220608064602.1693-1-wenyi.jiang@intel.com> X-Mailer: git-send-email 2.27.0.windows.1 In-Reply-To: <1> References: <1> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: fanwang2intel Add "-T " parameter to provide fixed FIT address on flash region. When this parameter is set to a valid address in the input FD/FV file, tool will directly generate FIT on this address. It's users' responsibilities to reserve enough size for FIT table and option modules on the target location, otherwise, FIT Gen process will fail. Cc: Chen Christine Cc: Bob Feng Signed-off-by: fanwang2intel --- Silicon/Intel/Tools/FitGen/FitGen.c | 163 ++++++++++++++------ 1 file changed, 120 insertions(+), 43 deletions(-) diff --git a/Silicon/Intel/Tools/FitGen/FitGen.c b/Silicon/Intel/Tools/FitG= en/FitGen.c index 290e688f6e4e..43f1cba25ec1 100644 --- a/Silicon/Intel/Tools/FitGen/FitGen.c +++ b/Silicon/Intel/Tools/FitGen/FitGen.c @@ -345,6 +345,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[-T ]\n"=0D , UTILITY_NAME);=0D printf (" Where:\n");=0D printf ("\t-D - It is FD file instead of FV file. (T= he tool will search FV file)\n");=0D @@ -392,6 +393,7 @@ Returns: printf (" Where:\n");=0D printf ("\tInputFile - Name of the input file.\n");=0D printf ("\tFitTablePointerOffset - FIT table pointer offset from end of= file. 0x%x as default.\n", DEFAULT_FIT_TABLE_POINTER_OFFSET);=0D + printf ("\tFixedFitLocation - Fixed FIT location in flash address.= FIT table will be generated at this location and Option Modules will be di= rectly put right before it.\n");=0D printf ("\nTool return values:\n");=0D printf ("\tSTATUS_SUCCESS=3D%d, STATUS_WARNING=3D%d, STATUS_ERROR=3D%d\n= ", STATUS_SUCCESS, STATUS_WARNING, STATUS_ERROR);=0D }=0D @@ -445,6 +447,46 @@ CheckPath ( return TRUE;=0D }=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 +=0D + FitLocation =3D 0;=0D +=0D + for (Index =3D 0; Index + 1 < argc; Index ++) {=0D +=0D + if ((strcmp (argv[Index], "-T") =3D=3D 0) ||=0D + (strcmp (argv[Index], "-t") =3D=3D 0) ) {=0D + FitLocation =3D xtoi (argv[Index + 1]);=0D + break;=0D + }=0D + }=0D +=0D + return FitLocation;=0D +}=0D +=0D STATUS=0D ReadInputFile (=0D IN CHAR8 *FileName,=0D @@ -1909,10 +1951,11 @@ Returns: }=0D =0D VOID *=0D -GetFreeSpaceFromFv (=0D +GetFreeSpaceForFit (=0D IN UINT8 *FvBuffer,=0D IN UINT32 FvSize,=0D - IN UINT32 FitEntryNumber=0D + IN UINT32 FitTableSize,=0D + IN UINT32 FixedFitLocation=0D )=0D /*++=0D =0D @@ -1922,9 +1965,10 @@ Routine Description: =0D Arguments:=0D =0D - FvBuffer - FvRecovery binary buffer=0D - FvSize - FvRecovery size=0D - FitEntryNumber - The FIT entry number=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 @@ -1939,7 +1983,6 @@ Returns: UINT8 *OptionalModuleAddress;=0D EFI_GUID VTFGuid =3D EFI_FFS_VOLUME_TOP_FILE_GUID;=0D UINT32 AlignedSize;=0D - UINT32 FitTableSize;=0D =0D EFI_FIRMWARE_VOLUME_HEADER *FvHeader;=0D EFI_FFS_FILE_HEADER *FileHeader;=0D @@ -1966,45 +2009,62 @@ Returns: }=0D }=0D =0D - //=0D - // Get EFI_FFS_VOLUME_TOP_FILE_GUID location=0D - //=0D - FitTableOffset =3D NULL;=0D + if (FixedFitLocation !=3D 0) {=0D + //=0D + // Get Free space from fixed location=0D + //=0D + FitTableOffset =3D (UINT8 *) FLASH_TO_MEMORY (FixedFitLocation, FvBuff= er, FvSize);=0D + } else {=0D + //=0D + // Get Free Space from FvRecovery=0D + //=0D + FitTableOffset =3D NULL;=0D =0D - FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)FvBuffer;=0D - FvLength =3D FvHeader->FvLength;=0D - FileHeader =3D (EFI_FFS_FILE_HEADER *)(FvBuffer + FvHeader->Header= Length);=0D - Offset =3D (UINTN)FileHeader - (UINTN)FvBuffer;=0D + FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)FvBuffer;=0D + FvLength =3D FvHeader->FvLength;=0D + FileHeader =3D (EFI_FFS_FILE_HEADER *)(FvBuffer + FvHeader->Head= erLength);=0D + Offset =3D (UINTN)FileHeader - (UINTN)FvBuffer;=0D =0D - while (Offset < FvLength) {=0D - FileLength =3D (*(UINT32 *)(FileHeader->Size)) & 0x00FFFFFF;=0D - FileOccupiedSize =3D GETOCCUPIEDSIZE(FileLength, 8);=0D - if ((CompareGuid (&(FileHeader->Name), &VTFGuid)) =3D=3D 0) {=0D - // find it=0D - FitTableOffset =3D (UINT8 *)FileHeader;=0D - break;=0D + //=0D + // Get EFI_FFS_VOLUME_TOP_FILE_GUID location=0D + //=0D + while (Offset < FvLength) {=0D + FileLength =3D (*(UINT32 *)(FileHeader->Size)) & 0x00FFFFFF;=0D + FileOccupiedSize =3D GETOCCUPIEDSIZE(FileLength, 8);=0D + if ((CompareGuid (&(FileHeader->Name), &VTFGuid)) =3D=3D 0) {=0D + // find it=0D + FitTableOffset =3D (UINT8 *)FileHeader;=0D + break;=0D + }=0D + FileHeader =3D (EFI_FFS_FILE_HEADER *)((UINTN)FileHeader + FileOccup= iedSize);=0D + Offset =3D (UINTN)FileHeader - (UINTN)FvBuffer;=0D }=0D - FileHeader =3D (EFI_FFS_FILE_HEADER *)((UINTN)FileHeader + FileOccupie= dSize);=0D - Offset =3D (UINTN)FileHeader - (UINTN)FvBuffer;=0D - }=0D -=0D - if (FitTableOffset =3D=3D NULL) {=0D - Error (NULL, 0, 0, "EFI_FFS_VOLUME_TOP_FILE_GUID not found!", NULL);=0D - return NULL;=0D - }=0D =0D - FitTableSize =3D FitEntryNumber * sizeof(FIRMWARE_INTERFACE_TABLE_ENTRY)= ;=0D - FitTableSize +=3D FIT_ALIGNMENT;=0D - FitTableSize &=3D ~FIT_ALIGNMENT;=0D + if (FitTableOffset =3D=3D NULL) {=0D + Error (NULL, 0, 0, "EFI_FFS_VOLUME_TOP_FILE_GUID not found!", NULL);= =0D + return NULL;=0D + }=0D =0D - FitTableOffset =3D (UINT8 *)((UINTN)FitTableOffset & ~FIT_ALIGNMENT);=0D - FitTableOffset =3D (UINT8 *)(FitTableOffset - FitTableSize);=0D + FitTableOffset =3D (UINT8 *)((UINTN)FitTableOffset & ~FIT_ALIGNMENT);= =0D + FitTableOffset =3D (UINT8 *)(FitTableOffset - FitTableSize);=0D + }=0D =0D //=0D - // Check it=0D + // Check the target space for FIT table=0D + //=0D + // 1. If FIT table has a fixed location, we assume users can provide an = empty space for FIT table=0D + // and Option Modules.=0D + // 2. If FIT table location is dynamicly calculated in FvRecovery, we gi= ve a last chance to skip=0D + // space for AP Vector.=0D //=0D for (Index =3D 0; Index < (INTN)(FitTableSize); Index ++) {=0D if (FitTableOffset[Index] !=3D 0xFF) {=0D +=0D + if (FixedFitLocation !=3D 0) {=0D + Error (NULL, 0, 0, "Reserved space for FIT table is not empty!", N= ULL);=0D + return NULL;=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 @@ -2054,6 +2114,12 @@ Returns: =0D for (SubIndex =3D 0; SubIndex < (INTN)(AlignedSize); SubIndex ++) {= =0D if (OptionalModuleAddress[SubIndex] !=3D 0xFF) {=0D +=0D + if (FixedFitLocation !=3D 0) {=0D + Error (NULL, 0, 0, "No enough space for Option Modules!", NULL= );=0D + return NULL;=0D + }=0D +=0D //=0D // No enough space - it might happen that it is occupied by AP w= ake vector.=0D // Last chance - skip this and search again.=0D @@ -3166,6 +3232,7 @@ Returns: UINT32 FdFileSize;=0D =0D UINT8 *AcmBuffer;=0D + UINT32 FixedFitLocation;=0D =0D FileBufferRaw =3D NULL;=0D //=0D @@ -3226,18 +3293,28 @@ Returns: // Add 1 more FitEntry as place holder, because we need exclude FIT ta= ble itself=0D //=0D FitEntryNumber++;=0D -=0D - //=0D - // Step 3: Get enough space in FvRecovery.fv=0D - //=0D - FitTableOffset =3D GetFreeSpaceFromFv (FileBuffer, FvRecoveryFileSize,= FitEntryNumber);=0D - if (FitTableOffset =3D=3D NULL) {=0D - return STATUS_ERROR;=0D - }=0D FitTableSize =3D FitEntryNumber * sizeof(FIRMWARE_INTERFACE_TABLE_ENTR= Y);=0D FitTableSize +=3D FIT_ALIGNMENT;=0D FitTableSize &=3D ~FIT_ALIGNMENT;=0D =0D + //=0D + // Step 3: Get enough space for FIT=0D + //=0D + FixedFitLocation =3D GetFixedFitLocation (argc, argv);=0D + if (FixedFitLocation !=3D 0 &&=0D + (FixedFitLocation < TOP_FLASH_ADDRESS - FdFileSize || FixedFitLocati= on + FitTableSize > TOP_FLASH_ADDRESS)) {=0D + //=0D + // FixedFitLocation is out of the input FD region, still find space = from FvRecovery=0D + //=0D + FixedFitLocation =3D 0;=0D + printf ("The fixed FIT location is not in valid flash region, find s= pace from FvRecovery ...\n");=0D + }=0D +=0D + FitTableOffset =3D GetFreeSpaceForFit (FileBuffer, FvRecoveryFileSize,= FitTableSize, FixedFitLocation);=0D + if (FitTableOffset =3D=3D NULL) {=0D + return STATUS_ERROR;=0D + }=0D +=0D CheckOverlap (=0D MEMORY_TO_FLASH (FitTableOffset, FdFileBuffer, FdFileSize),=0D FitTableSize=0D --=20 2.27.0.windows.1