From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 529E621B02822 for ; Thu, 11 Oct 2018 21:42:13 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2018 21:42:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,371,1534834800"; d="scan'208";a="240704092" Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.127]) by orsmga004.jf.intel.com with ESMTP; 11 Oct 2018 21:42:07 -0700 From: Yonghong Zhu To: edk2-devel@lists.01.org Cc: Yunhua Feng , Liming Gao Date: Fri, 12 Oct 2018 12:41:58 +0800 Message-Id: <1539319318-1888-1-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 Subject: [PATCH] BaseTools: Add --uefi option to enable UefiCompress method X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Oct 2018 04:42:13 -0000 From: Yunhua Feng Add one new option --uefi to enable UefiCompress. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng --- BaseTools/Source/C/TianoCompress/TianoCompress.c | 81 +++++++++++++++++------- BaseTools/Source/C/TianoCompress/TianoCompress.h | 2 +- 2 files changed, 58 insertions(+), 25 deletions(-) diff --git a/BaseTools/Source/C/TianoCompress/TianoCompress.c b/BaseTools/Source/C/TianoCompress/TianoCompress.c index 9a548fae1e..b88d7da2ed 100644 --- a/BaseTools/Source/C/TianoCompress/TianoCompress.c +++ b/BaseTools/Source/C/TianoCompress/TianoCompress.c @@ -15,10 +15,11 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #include "Compress.h" +#include "Decompress.h" #include "TianoCompress.h" #include "EfiUtilityMsgs.h" #include "ParseInf.h" #include #include "assert.h" @@ -63,10 +64,11 @@ static BOOLEAN QuietMode = FALSE; // // Global Variables // STATIC BOOLEAN ENCODE = FALSE; STATIC BOOLEAN DECODE = FALSE; +STATIC BOOLEAN UEFIMODE = FALSE; STATIC UINT8 *mSrc, *mDst, *mSrcUpperLimit, *mDstUpperLimit; STATIC UINT8 *mLevel, *mText, *mChildCount, *mBuf, mCLen[NC], mPTLen[NPT], *mLen; STATIC INT16 mHeap[NC + 1]; STATIC INT32 mRemainder, mMatchLen, mBitCount, mHeapSize, mN; STATIC UINT32 mBufSiz = 0, mOutputPos, mOutputMask, mSubBitBuf, mCrc; @@ -1701,10 +1703,12 @@ Returns: // // Details Option // fprintf (stdout, "Options:\n"); + fprintf (stdout, " --uefi\n\ + Enable UefiCompress, use TianoCompress when without this option\n"); fprintf (stdout, " -o FileName, --output FileName\n\ File will be created to store the ouput content.\n"); fprintf (stdout, " -v, --verbose\n\ Turn on verbose output with informational messages.\n"); fprintf (stdout, " -q, --quiet\n\ @@ -1820,10 +1824,17 @@ Returns: argc--; argv++; continue; } + if (stricmp(argv[0], "--uefi") == 0) { + UEFIMODE = TRUE; + argc--; + argv++; + continue; + } + if (stricmp (argv[0], "--debug") == 0) { argc-=2; argv++; Status = AsciiStringToUint64(argv[0], FALSE, &DebugLevel); if (DebugLevel > 9) { @@ -1937,21 +1948,29 @@ Returns: // First call TianoCompress to get DstSize // if (DebugMode) { DebugMsg(UTILITY_NAME, 0, DebugLevel, "Encoding", NULL); } - Status = TianoCompress ((UINT8 *)FileBuffer, InputLength, OutBuffer, &DstSize); + if (UEFIMODE) { + Status = EfiCompress ((UINT8 *)FileBuffer, InputLength, OutBuffer, &DstSize); + } else { + Status = TianoCompress ((UINT8 *)FileBuffer, InputLength, OutBuffer, &DstSize); + } if (Status == EFI_BUFFER_TOO_SMALL) { OutBuffer = (UINT8 *) malloc (DstSize); if (OutBuffer == NULL) { Error (NULL, 0, 4001, "Resource:", "Memory cannot be allocated!"); goto ERROR; } } - Status = TianoCompress ((UINT8 *)FileBuffer, InputLength, OutBuffer, &DstSize); + if (UEFIMODE) { + Status = EfiCompress ((UINT8 *)FileBuffer, InputLength, OutBuffer, &DstSize); + } else { + Status = TianoCompress ((UINT8 *)FileBuffer, InputLength, OutBuffer, &DstSize); + } if (Status != EFI_SUCCESS) { Error (NULL, 0, 0007, "Error compressing file", NULL); goto ERROR; } @@ -1977,36 +1996,50 @@ Returns: } else if (DECODE) { if (DebugMode) { DebugMsg(UTILITY_NAME, 0, DebugLevel, "Decoding\n", NULL); } - // - // Get Compressed file original size - // - Src = (UINT8 *)FileBuffer; - OrigSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24); - // - // Allocate OutputBuffer - // - OutBuffer = (UINT8 *)malloc(OrigSize); - if (OutBuffer == NULL) { - Error (NULL, 0, 4001, "Resource:", "Memory cannot be allocated!"); - goto ERROR; - } + if (UEFIMODE) { + Status = Extract((VOID *)FileBuffer, InputLength, (VOID *)&OutBuffer, &DstSize, 1); + if (Status != EFI_SUCCESS) { + goto ERROR; + } + fwrite(OutBuffer, (size_t)(DstSize), 1, OutputFile); + } else { + // + // Get Compressed file original size + // + Src = (UINT8 *)FileBuffer; + OrigSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24); - Status = Decompress((VOID *)FileBuffer, (VOID *)OutBuffer, (VOID *)Scratch, 2); - if (Status != EFI_SUCCESS) { - goto ERROR; - } + // + // Allocate OutputBuffer + // + OutBuffer = (UINT8 *)malloc(OrigSize); + if (OutBuffer == NULL) { + Error (NULL, 0, 4001, "Resource:", "Memory cannot be allocated!"); + goto ERROR; + } - fwrite(OutBuffer, (size_t)(Scratch->mOrigSize), 1, OutputFile); + Status = TDecompress((VOID *)FileBuffer, (VOID *)OutBuffer, (VOID *)Scratch, 2); + if (Status != EFI_SUCCESS) { + goto ERROR; + } + fwrite(OutBuffer, (size_t)(Scratch->mOrigSize), 1, OutputFile); + } fclose(OutputFile); fclose(InputFile); - free(Scratch); - free(FileBuffer); - free(OutBuffer); + if (Scratch != NULL) { + free(Scratch); + } + if (FileBuffer != NULL) { + free(FileBuffer); + } + if (OutBuffer != NULL) { + free(OutBuffer); + } if (DebugMode) { DebugMsg(UTILITY_NAME, 0, DebugLevel, "Encoding successful!\n", NULL); } @@ -2632,11 +2665,11 @@ Done: return ; } RETURN_STATUS EFIAPI -Decompress ( +TDecompress ( IN VOID *Source, IN OUT VOID *Destination, IN OUT VOID *Scratch, IN UINT32 Version ) diff --git a/BaseTools/Source/C/TianoCompress/TianoCompress.h b/BaseTools/Source/C/TianoCompress/TianoCompress.h index d75c00d26f..1297982e27 100644 --- a/BaseTools/Source/C/TianoCompress/TianoCompress.h +++ b/BaseTools/Source/C/TianoCompress/TianoCompress.h @@ -425,11 +425,11 @@ Decode ( SCRATCH_DATA *Sd ); RETURN_STATUS EFIAPI -Decompress ( +TDecompress ( IN VOID *Source, IN OUT VOID *Destination, IN OUT VOID *Scratch, IN UINT32 Version ); -- 2.12.2.windows.2