mirror of https://github.com/acidanthera/audk.git
IntelFrameworkModulePkg LZMA: Support running LZMA from flash/rom
Previously the code relied upon global variables which could not be modified if the code was running from ROM (or similarly a flash memory which is not easily modified). git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9667 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
807765a034
commit
090d308851
|
@ -73,7 +73,7 @@ LzmaGuidedSectionGetInfo (
|
|||
|
||||
return LzmaUefiDecompressGetInfo (
|
||||
(UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
|
||||
(*(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
|
||||
SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
|
||||
OutputBufferSize,
|
||||
ScratchBufferSize
|
||||
);
|
||||
|
@ -137,6 +137,7 @@ LzmaGuidedSectionExtraction (
|
|||
|
||||
return LzmaUefiDecompress (
|
||||
(UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
|
||||
SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
|
||||
*OutputBuffer,
|
||||
ScratchBuffer
|
||||
);
|
||||
|
|
|
@ -17,18 +17,15 @@
|
|||
#include "Sdk/C/7zVersion.h"
|
||||
#include "Sdk/C/LzmaDec.h"
|
||||
|
||||
//
|
||||
// Global data
|
||||
//
|
||||
|
||||
CONST VOID *mSourceLastUsedWithGetInfo;
|
||||
UINT32 mSizeOfLastSource;
|
||||
UINT32 mDecompressedSizeForLastSource;
|
||||
VOID *mScratchBuffer;
|
||||
UINTN mScratchBufferSize;
|
||||
|
||||
#define SCRATCH_BUFFER_REQUEST_SIZE SIZE_64KB
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISzAlloc Functions;
|
||||
VOID *Buffer;
|
||||
UINTN BufferSize;
|
||||
} ISzAllocWithData;
|
||||
|
||||
/**
|
||||
Allocation routine used by LZMA decompression.
|
||||
|
||||
|
@ -44,11 +41,12 @@ SzAlloc (
|
|||
)
|
||||
{
|
||||
VOID *Addr;
|
||||
ISzAllocWithData *Private = (ISzAllocWithData*) P;
|
||||
|
||||
if (mScratchBufferSize >= Size) {
|
||||
Addr = mScratchBuffer;
|
||||
mScratchBuffer = (VOID*) ((UINT8*)Addr + Size);
|
||||
mScratchBufferSize -= Size;
|
||||
if (Private->BufferSize >= Size) {
|
||||
Addr = Private->Buffer;
|
||||
Private->Buffer = (VOID*) ((UINT8*)Addr + Size);
|
||||
Private->BufferSize -= Size;
|
||||
return Addr;
|
||||
} else {
|
||||
ASSERT (FALSE);
|
||||
|
@ -75,8 +73,6 @@ SzFree (
|
|||
//
|
||||
}
|
||||
|
||||
STATIC ISzAlloc g_Alloc = { SzAlloc, SzFree };
|
||||
|
||||
#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8)
|
||||
|
||||
/**
|
||||
|
@ -151,15 +147,11 @@ LzmaUefiDecompressGetInfo (
|
|||
|
||||
DecodedSize = GetDecodedSizeOfBuf((UINT8*)Source);
|
||||
|
||||
mSourceLastUsedWithGetInfo = Source;
|
||||
mSizeOfLastSource = SourceSize;
|
||||
mDecompressedSizeForLastSource = (UInt32)DecodedSize;
|
||||
*DestinationSize = mDecompressedSizeForLastSource;
|
||||
*DestinationSize = (UINT32)DecodedSize;
|
||||
*ScratchSize = SCRATCH_BUFFER_REQUEST_SIZE;
|
||||
return RETURN_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Decompresses a Lzma compressed source buffer.
|
||||
|
||||
|
@ -185,6 +177,7 @@ RETURN_STATUS
|
|||
EFIAPI
|
||||
LzmaUefiDecompress (
|
||||
IN CONST VOID *Source,
|
||||
IN UINTN SourceSize,
|
||||
IN OUT VOID *Destination,
|
||||
IN OUT VOID *Scratch
|
||||
)
|
||||
|
@ -193,16 +186,14 @@ LzmaUefiDecompress (
|
|||
ELzmaStatus Status;
|
||||
SizeT DecodedBufSize;
|
||||
SizeT EncodedDataSize;
|
||||
ISzAllocWithData AllocFuncs = {
|
||||
{ SzAlloc, SzFree },
|
||||
Scratch,
|
||||
SCRATCH_BUFFER_REQUEST_SIZE
|
||||
};
|
||||
|
||||
if (Source != mSourceLastUsedWithGetInfo) {
|
||||
return RETURN_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
DecodedBufSize = (SizeT)mDecompressedSizeForLastSource;
|
||||
EncodedDataSize = (SizeT)(mSizeOfLastSource - LZMA_HEADER_SIZE);
|
||||
|
||||
mScratchBuffer = Scratch;
|
||||
mScratchBufferSize = SCRATCH_BUFFER_REQUEST_SIZE;
|
||||
DecodedBufSize = GetDecodedSizeOfBuf((UINT8*)Source);
|
||||
EncodedDataSize = (SizeT) (SourceSize - LZMA_HEADER_SIZE);
|
||||
|
||||
LzmaResult = LzmaDecode(
|
||||
Destination,
|
||||
|
@ -213,7 +204,7 @@ LzmaUefiDecompress (
|
|||
LZMA_PROPS_SIZE,
|
||||
LZMA_FINISH_END,
|
||||
&Status,
|
||||
&g_Alloc
|
||||
(ISzAlloc*) &AllocFuncs
|
||||
);
|
||||
|
||||
if (LzmaResult == SZ_OK) {
|
||||
|
|
|
@ -86,6 +86,7 @@ RETURN_STATUS
|
|||
EFIAPI
|
||||
LzmaUefiDecompress (
|
||||
IN CONST VOID *Source,
|
||||
IN UINTN SourceSize,
|
||||
IN OUT VOID *Destination,
|
||||
IN OUT VOID *Scratch
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue