[edk2-devel] [PATCH] BaseTools/LzmaCompress: Add two switches

Zhang, Shenglei posted 1 patch 1 week ago
Failed in applying to current master (apply log)
.../Source/C/LzmaCompress/LzmaCompress.c      | 39 +++++++++++++++----
BaseTools/Source/C/LzmaCompress/Makefile      |  4 +-
2 files changed, 34 insertions(+), 9 deletions(-)

[edk2-devel] [PATCH] BaseTools/LzmaCompress: Add two switches

Posted by Zhang, Shenglei 1 week ago
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 <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
---
 .../Source/C/LzmaCompress/LzmaCompress.c      | 39 +++++++++++++++----
 BaseTools/Source/C/LzmaCompress/Makefile      |  4 +-
 2 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/BaseTools/Source/C/LzmaCompress/LzmaCompress.c b/BaseTools/Source/C/LzmaCompress/LzmaCompress.c
index a3607f9b2084..e18a1e0365f6 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.<BR>
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
   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 DictionarySize = 31;
+UINT64 CompressionMode = 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);
@@ -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,&CompressionMode);
+      if ((CompressionMode == 0)||(CompressionMode == 1)){
+        props.algo = (int)CompressionMode;
+		param++;
+        continue;
+      } else {
+        return PrintError(rs, kInvalidParamValMessage);
+      }
+    } else if (strcmp(args[param], "d") == 0) {
+      AsciiStringToUint64(args[param + 1],FALSE,&DictionarySize);
+      if ((DictionarySize >= 0)&&(DictionarySize <= 30)){
+        props.dictSize = (UINT32)DictionarySize;
+		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/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.<BR>
+# Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>
 # 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


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47152): https://edk2.groups.io/g/devel/message/47152
Mute This Topic: https://groups.io/mt/34111304/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH] BaseTools/LzmaCompress: Add two switches

Posted by Liming Gao 4 days ago
Shenglei:
  I add my comments. 

Thanks
Liming
>-----Original Message-----
>From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
>Zhang, Shenglei
>Sent: Thursday, September 12, 2019 10:40 AM
>To: devel@edk2.groups.io
>Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
>Subject: [edk2-devel] [PATCH] BaseTools/LzmaCompress: Add two switches
>
>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 <bob.c.feng@intel.com>
>Cc: Liming Gao <liming.gao@intel.com>
>Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
>---
> .../Source/C/LzmaCompress/LzmaCompress.c      | 39 +++++++++++++++----
> BaseTools/Source/C/LzmaCompress/Makefile      |  4 +-
> 2 files changed, 34 insertions(+), 9 deletions(-)
>
>diff --git a/BaseTools/Source/C/LzmaCompress/LzmaCompress.c
>b/BaseTools/Source/C/LzmaCompress/LzmaCompress.c
>index a3607f9b2084..e18a1e0365f6 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.<BR>
>+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
>   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 DictionarySize = 31;
>+UINT64 CompressionMode = 2;

Module level global variable is with "m" as the prefix name. 

>+
> #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)

Please use CLzmaEncProps  *props as the function input parameter. 

Thanks
Liming
> {
>   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);
>@@ -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,&CompressionMode);
>+      if ((CompressionMode == 0)||(CompressionMode == 1)){
>+        props.algo = (int)CompressionMode;
>+		param++;
>+        continue;
>+      } else {
>+        return PrintError(rs, kInvalidParamValMessage);
>+      }
>+    } else if (strcmp(args[param], "d") == 0) {
>+      AsciiStringToUint64(args[param + 1],FALSE,&DictionarySize);
>+      if ((DictionarySize >= 0)&&(DictionarySize <= 30)){
>+        props.dictSize = (UINT32)DictionarySize;
>+		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/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.<BR>
>+# Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>
> # 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
>
>
>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47260): https://edk2.groups.io/g/devel/message/47260
Mute This Topic: https://groups.io/mt/34111304/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-