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.web11.2635.1591690623019810754 for ; Tue, 09 Jun 2020 01:17:03 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: liming.gao@intel.com) IronPort-SDR: DuRZKMuo4XDujIj1ZhS8LI4Ty3ddipurjpYpDWQNK+omtU1S1CTvMYtKMCrrAJKhxKtPsIhC+V eVzrIDh1TUQQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2020 01:17:01 -0700 IronPort-SDR: c6k0ykk3qLMjd0rqniXk8rxNrHoBgZm6hjaMSgKsTum+jH71IpyHV5yVuKgG9dix0BCzI+UoPN iI3d46YNYvsA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,491,1583222400"; d="scan'208";a="472994382" Received: from shwde7172.ccr.corp.intel.com ([10.239.158.67]) by fmsmga005.fm.intel.com with ESMTP; 09 Jun 2020 01:17:01 -0700 From: "Liming Gao" To: devel@edk2.groups.io Cc: Bob Feng Subject: [Patch] BaseTools GenFv: Report the correct spare FV image size Date: Tue, 9 Jun 2020 16:16:48 +0800 Message-Id: <20200609081648.1527-1-liming.gao@intel.com> X-Mailer: git-send-email 2.24.1.windows.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2790 If the top FFS is placed in FV image, current FV will show there is no space. In fact, the pad ffs in FV image can be regarded as the spare space. This change reports the max pad ffs size as the spare space for use. Signed-off-by: Liming Gao Cc: Bob Feng --- BaseTools/Source/C/GenFv/GenFvInternalLib.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c b/BaseTools/Source/C/GenFv/GenFvInternalLib.c index d29a891c9c..b5ffed93a9 100644 --- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c +++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c @@ -3140,6 +3140,7 @@ Returns: --*/ { UINTN CurrentOffset; + UINTN OrigOffset; UINTN Index; FILE *fpin; UINTN FfsFileSize; @@ -3148,8 +3149,10 @@ Returns: UINT32 FfsHeaderSize; EFI_FFS_FILE_HEADER FfsHeader; UINTN VtfFileSize; + UINTN MaxPadFileSize; FvExtendHeaderSize = 0; + MaxPadFileSize = 0; VtfFileSize = 0; fpin = NULL; Index = 0; @@ -3258,8 +3261,12 @@ Returns: // // Only EFI_FFS_FILE_HEADER is needed for a pad section. // + OrigOffset = CurrentOffset; CurrentOffset = (CurrentOffset + FfsHeaderSize + sizeof(EFI_FFS_FILE_HEADER) + FfsAlignment - 1) & ~(FfsAlignment - 1); CurrentOffset -= FfsHeaderSize; + if ((CurrentOffset - OrigOffset) > MaxPadFileSize) { + MaxPadFileSize = CurrentOffset - OrigOffset; + } } } @@ -3303,6 +3310,12 @@ Returns: // mFvTotalSize = FvInfoPtr->Size; mFvTakenSize = CurrentOffset; + if ((mFvTakenSize == mFvTotalSize) && (MaxPadFileSize > 0)) { + // + // This FV means TOP FFS has been taken. Then, check whether there is padding data for use. + // + mFvTakenSize = mFvTakenSize - MaxPadFileSize; + } return EFI_SUCCESS; } -- 2.13.0.windows.1