blob: a7a8717c6ac6eaa992d4e1ee42fe181ec8b1ebf0 [file] [log] [blame]
Uwe Hermann7eb845e2008-11-02 17:01:06 +00001/*
2
3Coreboot interface to memory-saving variant of LZMA decoder
4
5(C)opyright 2006 Carl-Daniel Hailfinger
6Released under the GNU GPL v2 or later
7
8Parts of this file are based on C/7zip/Compress/LZMA_C/LzmaTest.c from the LZMA
9SDK 4.42, which is written and distributed to public domain by Igor Pavlov.
10
11*/
12
13#include <libpayload.h>
14#include "lzmadecode.c"
15
16unsigned long ulzma(u8 *src, u8 *dst)
17{
18 unsigned char properties[LZMA_PROPERTIES_SIZE];
19 UInt32 outSize;
20 SizeT inProcessed;
21 SizeT outProcessed;
22 int res;
23 CLzmaDecoderState state;
24 SizeT mallocneeds;
25 unsigned char scratchpad[15980];
26
27 memcpy(properties, src, LZMA_PROPERTIES_SIZE);
28 outSize = *(UInt32 *)(src + LZMA_PROPERTIES_SIZE);
29 if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK) {
30 printf("Incorrect stream properties\n");
31 }
32 mallocneeds = (LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
33 if (mallocneeds > 15980) {
34 printf("Decoder scratchpad too small!\n");
35 }
36 state.Probs = (CProb *)scratchpad;
37 res = LzmaDecode(&state, src + LZMA_PROPERTIES_SIZE + 8, (SizeT)0xffffffff, &inProcessed,
38 dst, outSize, &outProcessed);
39 if (res != 0) {
40 printf("Decoding error = %d\n", res);
41 }
42 return outSize;
43}