* [PATCH] BaseTools: Add --uefi option to enable UefiCompress method
@ 2018-10-12 4:41 Yonghong Zhu
2018-10-13 2:03 ` Zhu, Yonghong
0 siblings, 1 reply; 2+ messages in thread
From: Yonghong Zhu @ 2018-10-12 4:41 UTC (permalink / raw)
To: edk2-devel; +Cc: Yunhua Feng, Liming Gao
From: Yunhua Feng <yunhuax.feng@intel.com>
Add one new option --uefi to enable UefiCompress.
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
---
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 <stdio.h>
#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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] BaseTools: Add --uefi option to enable UefiCompress method
2018-10-12 4:41 [PATCH] BaseTools: Add --uefi option to enable UefiCompress method Yonghong Zhu
@ 2018-10-13 2:03 ` Zhu, Yonghong
0 siblings, 0 replies; 2+ messages in thread
From: Zhu, Yonghong @ 2018-10-13 2:03 UTC (permalink / raw)
To: Zhu, Yonghong, edk2-devel@lists.01.org; +Cc: Gao, Liming, Zhu, Yonghong
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Best Regards,
Zhu Yonghong
-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@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 <liming.gao@intel.com>
Subject: [edk2] [PATCH] BaseTools: Add --uefi option to enable UefiCompress method
From: Yunhua Feng <yunhuax.feng@intel.com>
Add one new option --uefi to enable UefiCompress.
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
---
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 <stdio.h>
#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
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-10-13 2:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-12 4:41 [PATCH] BaseTools: Add --uefi option to enable UefiCompress method Yonghong Zhu
2018-10-13 2:03 ` Zhu, Yonghong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox