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.web11.6589.1654746927034454631 for ; Wed, 08 Jun 2022 20:55:27 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=TQkFYLF8; spf=pass (domain: intel.com, ip: 192.55.52.43, 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=1654746927; x=1686282927; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jKVqlcj5Amf4fEXhAcO0rkyvKa3CQe45jG19Fx6Yjb0=; b=TQkFYLF83NAIebUIKJtmCaPXZ9VkD2kus7YOQTF0eyWclEn6UfJw6je9 b7vyGxYM6jpJEvj7YyxqookT0HC5eiqOok6S416Wkxo3vuZuv6LzqJhC7 YXVHTSV9Kwmz1CfQIdyHVQoSmPY0uCAaDifETQe3f1rAoiPFcTLkdl0I9 gDMcGETCOm75aOaP7v3SIZ2FWhc2NriErh7/eWzksC5aqFcGaM0ksHzh+ LSRcx6RNCOLbAbr9nGvuJ2ekDrJbp2tGntaUN94zHqBW89NavFh3cbDKA DBRHEOxVXEY103l/WMhls8yoOByTarb39adNlqzUV7HjFtU7qySD1Y0ev g==; X-IronPort-AV: E=McAfee;i="6400,9594,10372"; a="363465012" X-IronPort-AV: E=Sophos;i="5.91,287,1647327600"; d="scan'208";a="363465012" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2022 20:55:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,287,1647327600"; d="scan'208";a="670945729" Received: from shwdeopenlab703.ccr.corp.intel.com ([10.239.182.196]) by FMSMGA003.fm.intel.com with ESMTP; 08 Jun 2022 20:55:24 -0700 From: wenyijia To: devel@edk2.groups.io Cc: Chen Christine , Bob Feng Subject: [PATCH v2 1/1] Tools\FitGen: Add extra parameter fixed FIT address Date: Thu, 9 Jun 2022 11:55:18 +0800 Message-Id: <20220609035518.1311-1-wenyi.jiang@intel.com> X-Mailer: git-send-email 2.27.0.windows.1 In-Reply-To: References: 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..4de72ea4225e 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 @@ -388,6 +389,7 @@ Returns: printf ("\tWidth - The Width of the port.\n");=0D printf ("\tBit - The Bit Number of the port.\n");=0D printf ("\tIndex - The Index Number of the port.\n");=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 ("\nUsage (view): %s [-view] InputFile -F = \n", UTILITY_NAME);=0D printf (" Where:\n");=0D printf ("\tInputFile - Name of the input file.\n");=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