Re: [edk2] [PATCH] BaseTools: Add --uefi option to enable UefiCompress method

2018-10-12 Thread Zhu, Yonghong
Reviewed-by: Yonghong Zhu  

Best Regards,
Zhu Yonghong


-Original Message-
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Yonghong 
Zhu
Sent: Friday, October 12, 2018 12:42 PM
To: edk2-devel@lists.01.org
Cc: Gao, Liming 
Subject: [edk2] [PATCH] BaseTools: Add --uefi option to enable UefiCompress 
method

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, );
   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, 
);
+  if (UEFIMODE) {
+Status = EfiCompress ((UINT8 *)FileBuffer, InputLength, OutBuffer, 
+ );  } else {
+Status = TianoCompress ((UINT8 *)FileBuffer, InputLength, 
+ OutBuffer, );  }
 
   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, 
);
+  if (UEFIMODE) {
+Status = EfiCompress ((UINT8 *)FileBuffer, InputLength, OutBuffer, 
+ );  } else {
+Status = TianoCompress ((UINT8 *)FileBuffer, InputLength, 
+ OutBuffer, );  }
   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 *), 
, 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

[edk2] [PATCH] BaseTools: Add --uefi option to enable UefiCompress method

2018-10-11 Thread Yonghong Zhu
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, );
   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, 
);
+  if (UEFIMODE) {
+Status = EfiCompress ((UINT8 *)FileBuffer, InputLength, OutBuffer, 
);
+  } else {
+Status = TianoCompress ((UINT8 *)FileBuffer, InputLength, OutBuffer, 
);
+  }
 
   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, 
);
+  if (UEFIMODE) {
+Status = EfiCompress ((UINT8 *)FileBuffer, InputLength, OutBuffer, 
);
+  } else {
+Status = TianoCompress ((UINT8 *)FileBuffer, InputLength, OutBuffer, 
);
+  }
   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 *), 
, 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);
-