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 (
|
return LzmaUefiDecompressGetInfo (
|
||||||
(UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
|
(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,
|
OutputBufferSize,
|
||||||
ScratchBufferSize
|
ScratchBufferSize
|
||||||
);
|
);
|
||||||
|
@ -137,6 +137,7 @@ LzmaGuidedSectionExtraction (
|
||||||
|
|
||||||
return LzmaUefiDecompress (
|
return LzmaUefiDecompress (
|
||||||
(UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
|
(UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
|
||||||
|
SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
|
||||||
*OutputBuffer,
|
*OutputBuffer,
|
||||||
ScratchBuffer
|
ScratchBuffer
|
||||||
);
|
);
|
||||||
|
|
|
@ -17,18 +17,15 @@
|
||||||
#include "Sdk/C/7zVersion.h"
|
#include "Sdk/C/7zVersion.h"
|
||||||
#include "Sdk/C/LzmaDec.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
|
#define SCRATCH_BUFFER_REQUEST_SIZE SIZE_64KB
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ISzAlloc Functions;
|
||||||
|
VOID *Buffer;
|
||||||
|
UINTN BufferSize;
|
||||||
|
} ISzAllocWithData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Allocation routine used by LZMA decompression.
|
Allocation routine used by LZMA decompression.
|
||||||
|
|
||||||
|
@ -44,11 +41,12 @@ SzAlloc (
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
VOID *Addr;
|
VOID *Addr;
|
||||||
|
ISzAllocWithData *Private = (ISzAllocWithData*) P;
|
||||||
|
|
||||||
if (mScratchBufferSize >= Size) {
|
if (Private->BufferSize >= Size) {
|
||||||
Addr = mScratchBuffer;
|
Addr = Private->Buffer;
|
||||||
mScratchBuffer = (VOID*) ((UINT8*)Addr + Size);
|
Private->Buffer = (VOID*) ((UINT8*)Addr + Size);
|
||||||
mScratchBufferSize -= Size;
|
Private->BufferSize -= Size;
|
||||||
return Addr;
|
return Addr;
|
||||||
} else {
|
} else {
|
||||||
ASSERT (FALSE);
|
ASSERT (FALSE);
|
||||||
|
@ -75,8 +73,6 @@ SzFree (
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC ISzAlloc g_Alloc = { SzAlloc, SzFree };
|
|
||||||
|
|
||||||
#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8)
|
#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -151,15 +147,11 @@ LzmaUefiDecompressGetInfo (
|
||||||
|
|
||||||
DecodedSize = GetDecodedSizeOfBuf((UINT8*)Source);
|
DecodedSize = GetDecodedSizeOfBuf((UINT8*)Source);
|
||||||
|
|
||||||
mSourceLastUsedWithGetInfo = Source;
|
*DestinationSize = (UINT32)DecodedSize;
|
||||||
mSizeOfLastSource = SourceSize;
|
|
||||||
mDecompressedSizeForLastSource = (UInt32)DecodedSize;
|
|
||||||
*DestinationSize = mDecompressedSizeForLastSource;
|
|
||||||
*ScratchSize = SCRATCH_BUFFER_REQUEST_SIZE;
|
*ScratchSize = SCRATCH_BUFFER_REQUEST_SIZE;
|
||||||
return RETURN_SUCCESS;
|
return RETURN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Decompresses a Lzma compressed source buffer.
|
Decompresses a Lzma compressed source buffer.
|
||||||
|
|
||||||
|
@ -185,6 +177,7 @@ RETURN_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
LzmaUefiDecompress (
|
LzmaUefiDecompress (
|
||||||
IN CONST VOID *Source,
|
IN CONST VOID *Source,
|
||||||
|
IN UINTN SourceSize,
|
||||||
IN OUT VOID *Destination,
|
IN OUT VOID *Destination,
|
||||||
IN OUT VOID *Scratch
|
IN OUT VOID *Scratch
|
||||||
)
|
)
|
||||||
|
@ -193,16 +186,14 @@ LzmaUefiDecompress (
|
||||||
ELzmaStatus Status;
|
ELzmaStatus Status;
|
||||||
SizeT DecodedBufSize;
|
SizeT DecodedBufSize;
|
||||||
SizeT EncodedDataSize;
|
SizeT EncodedDataSize;
|
||||||
|
ISzAllocWithData AllocFuncs = {
|
||||||
|
{ SzAlloc, SzFree },
|
||||||
|
Scratch,
|
||||||
|
SCRATCH_BUFFER_REQUEST_SIZE
|
||||||
|
};
|
||||||
|
|
||||||
if (Source != mSourceLastUsedWithGetInfo) {
|
DecodedBufSize = GetDecodedSizeOfBuf((UINT8*)Source);
|
||||||
return RETURN_INVALID_PARAMETER;
|
EncodedDataSize = (SizeT) (SourceSize - LZMA_HEADER_SIZE);
|
||||||
}
|
|
||||||
|
|
||||||
DecodedBufSize = (SizeT)mDecompressedSizeForLastSource;
|
|
||||||
EncodedDataSize = (SizeT)(mSizeOfLastSource - LZMA_HEADER_SIZE);
|
|
||||||
|
|
||||||
mScratchBuffer = Scratch;
|
|
||||||
mScratchBufferSize = SCRATCH_BUFFER_REQUEST_SIZE;
|
|
||||||
|
|
||||||
LzmaResult = LzmaDecode(
|
LzmaResult = LzmaDecode(
|
||||||
Destination,
|
Destination,
|
||||||
|
@ -213,7 +204,7 @@ LzmaUefiDecompress (
|
||||||
LZMA_PROPS_SIZE,
|
LZMA_PROPS_SIZE,
|
||||||
LZMA_FINISH_END,
|
LZMA_FINISH_END,
|
||||||
&Status,
|
&Status,
|
||||||
&g_Alloc
|
(ISzAlloc*) &AllocFuncs
|
||||||
);
|
);
|
||||||
|
|
||||||
if (LzmaResult == SZ_OK) {
|
if (LzmaResult == SZ_OK) {
|
||||||
|
|
|
@ -86,6 +86,7 @@ RETURN_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
LzmaUefiDecompress (
|
LzmaUefiDecompress (
|
||||||
IN CONST VOID *Source,
|
IN CONST VOID *Source,
|
||||||
|
IN UINTN SourceSize,
|
||||||
IN OUT VOID *Destination,
|
IN OUT VOID *Destination,
|
||||||
IN OUT VOID *Scratch
|
IN OUT VOID *Scratch
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue