From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: shenglei.zhang@intel.com) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by groups.io with SMTP; Thu, 19 Sep 2019 19:29:13 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Sep 2019 19:29:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,527,1559545200"; d="scan'208";a="192239660" Received: from shenglei-dev.ccr.corp.intel.com ([10.239.158.52]) by orsmga006.jf.intel.com with ESMTP; 19 Sep 2019 19:29:10 -0700 From: "Zhang, Shenglei" To: devel@edk2.groups.io Cc: "Zhang, Shenglei" , Bob Feng , Liming Gao Subject: [PATCH v4] BaseTools/LzmaCompress: Add two switches Date: Fri, 20 Sep 2019 10:29:02 +0800 Message-Id: <20190920022902.42808-1-shenglei.zhang@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 From: "Zhang, Shenglei" As is requested in the BZ 2077, add two switches to support setting compression mode and dictionary size. (https://bugzilla.tianocore.org/show_bug.cgi?id=2077) Cc: Bob Feng Cc: Liming Gao Signed-off-by: Shenglei Zhang --- v2: 1.Update DictionarySize to mDictionarySize. 2.Update CompressionMode to mCompressionMode. 3.Use CLzmaEncProps *props as the input parameter of the function Encode. v3: Remove the component "mDictionarySize >= 0" in the if judgement.line 303 This is to fix the build failure under Mac OS. Beacuse the type of mDictionarySize is UINT64, which is always >= 0. v4: Update type of "props" when declaring and the consequent usage. The encoding functionality has been tested under Windows OS, Linux OS and Mac OS. .../Source/C/LzmaCompress/LzmaCompress.c | 41 +++++++++++++++---- BaseTools/Source/C/LzmaCompress/GNUmakefile | 4 +- BaseTools/Source/C/LzmaCompress/Makefile | 4 +- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/BaseTools/Source/C/LzmaCompress/LzmaCompress.c b/BaseTools/Source/C/LzmaCompress/LzmaCompress.c index a3607f9b2084..856fcf9ffb17 100644 --- a/BaseTools/Source/C/LzmaCompress/LzmaCompress.c +++ b/BaseTools/Source/C/LzmaCompress/LzmaCompress.c @@ -5,7 +5,7 @@ LzmaUtil.c -- Test application for LZMA compression 2018-04-30 : Igor Pavlov : Public domain - Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -23,6 +23,7 @@ #include "Sdk/C/LzmaEnc.h" #include "Sdk/C/Bra.h" #include "CommonLib.h" +#include "ParseInf.h" #define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8) @@ -36,10 +37,14 @@ const char *kCantReadMessage = "Can not read input file"; const char *kCantWriteMessage = "Can not write output file"; const char *kCantAllocateMessage = "Can not allocate memory"; const char *kDataErrorMessage = "Data error"; +const char *kInvalidParamValMessage = "Invalid parameter value"; static Bool mQuietMode = False; static CONVERTER_TYPE mConType = NoConverter; +UINT64 mDictionarySize = 31; +UINT64 mCompressionMode = 2; + #define UTILITY_NAME "LzmaCompress" #define UTILITY_MAJOR_VERSION 0 #define UTILITY_MINOR_VERSION 2 @@ -58,6 +63,8 @@ void PrintHelp(char *buffer) " -v, --verbose: increase output messages\n" " -q, --quiet: reduce output messages\n" " --debug [0-9]: set debug level\n" + " -a: set compression mode 0 = fast, 1 = normal, default: 1 (normal)\n" + " d: sets Dictionary size - [0, 30], default: 23 (8MB)\n" " --version: display the program version and exit\n" " -h, --help: display this help text\n" ); @@ -87,7 +94,7 @@ void PrintVersion(char *buffer) sprintf (buffer, "%s Version %d.%d %s ", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION); } -static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize) +static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize, CLzmaEncProps *props) { SRes res; size_t inSize = (size_t)fileSize; @@ -95,10 +102,6 @@ static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 file Byte *outBuffer = 0; Byte *filteredStream = 0; size_t outSize; - CLzmaEncProps props; - - LzmaEncProps_Init(&props); - LzmaEncProps_Normalize(&props); if (inSize != 0) { inBuffer = (Byte *)MyAlloc(inSize); @@ -151,7 +154,7 @@ static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 file res = LzmaEncode(outBuffer + LZMA_HEADER_SIZE, &outSizeProcessed, mConType != NoConverter ? filteredStream : inBuffer, inSize, - &props, outBuffer, &outPropsSize, 0, + props, outBuffer, &outPropsSize, 0, NULL, &g_Alloc, &g_Alloc); if (res != SZ_OK) @@ -246,6 +249,10 @@ int main2(int numArgs, const char *args[], char *rs) const char *outputFile = "file.tmp"; int param; UInt64 fileSize; + CLzmaEncProps props; + + LzmaEncProps_Init(&props); + LzmaEncProps_Normalize(&props); FileSeqInStream_CreateVTable(&inStream); File_Construct(&inStream.file); @@ -280,6 +287,24 @@ int main2(int numArgs, const char *args[], char *rs) // parameter compatibility with other build tools. // param++; + } else if (strcmp(args[param], "-a") == 0) { + AsciiStringToUint64(args[param + 1],FALSE,&mCompressionMode); + if ((mCompressionMode == 0)||(mCompressionMode == 1)){ + props.algo = (int)mCompressionMode; + param++; + continue; + } else { + return PrintError(rs, kInvalidParamValMessage); + } + } else if (strcmp(args[param], "d") == 0) { + AsciiStringToUint64(args[param + 1],FALSE,&mDictionarySize); + if (mDictionarySize <= 30){ + props.dictSize = (UINT32)mDictionarySize; + param++; + continue; + } else { + return PrintError(rs, kInvalidParamValMessage); + } } else if ( strcmp(args[param], "-h") == 0 || strcmp(args[param], "--help") == 0 @@ -335,7 +360,7 @@ int main2(int numArgs, const char *args[], char *rs) if (!mQuietMode) { printf("Encoding\n"); } - res = Encode(&outStream.vt, &inStream.vt, fileSize); + res = Encode(&outStream.vt, &inStream.vt, fileSize, &props); } else { diff --git a/BaseTools/Source/C/LzmaCompress/GNUmakefile b/BaseTools/Source/C/LzmaCompress/GNUmakefile index 533f0a59a0af..c837e7782373 100644 --- a/BaseTools/Source/C/LzmaCompress/GNUmakefile +++ b/BaseTools/Source/C/LzmaCompress/GNUmakefile @@ -1,13 +1,15 @@ ## @file # GNU/Linux makefile for 'LzmaCompress' module build. # -# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # MAKEROOT ?= .. APPNAME = LzmaCompress +LIBS = -lCommon + SDK_C = Sdk/C OBJECTS = \ diff --git a/BaseTools/Source/C/LzmaCompress/Makefile b/BaseTools/Source/C/LzmaCompress/Makefile index 12be48de2940..055f5d3ac3ca 100644 --- a/BaseTools/Source/C/LzmaCompress/Makefile +++ b/BaseTools/Source/C/LzmaCompress/Makefile @@ -1,14 +1,14 @@ ## @file # Windows makefile for 'LzmaCompress' module build. # -# Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # !INCLUDE ..\Makefiles\ms.common APPNAME = LzmaCompress -#LIBS = $(LIB_PATH)\Common.lib +LIBS = $(LIB_PATH)\Common.lib SDK_C = Sdk\C -- 2.18.0.windows.1