From: Yonghong Zhu <yonghong.zhu@intel.com>
To: edk2-devel@lists.01.org
Cc: Yunhua Feng <yunhuax.feng@intel.com>, Liming Gao <liming.gao@intel.com>
Subject: [PATCH] BaseTools: Add --uefi option to enable UefiCompress method
Date: Fri, 12 Oct 2018 12:41:58 +0800 [thread overview]
Message-ID: <1539319318-1888-1-git-send-email-yonghong.zhu@intel.com> (raw)
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
next reply other threads:[~2018-10-12 4:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-12 4:41 Yonghong Zhu [this message]
2018-10-13 2:03 ` [PATCH] BaseTools: Add --uefi option to enable UefiCompress method Zhu, Yonghong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1539319318-1888-1-git-send-email-yonghong.zhu@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox