blob: dbaa805afad1b08cc6fb4fd6462ede91f76219b5 [file] [log] [blame]
Carl-Daniel Hailfingercba07dd2006-09-14 15:12:36 +00001/*
2
Stefan Reinauerf8ee1802008-01-18 15:08:58 +00003Coreboot interface to memory-saving variant of LZMA decoder
Carl-Daniel Hailfingerfa510c72008-03-17 01:37:27 +00004
Carl-Daniel Hailfingercba07dd2006-09-14 15:12:36 +00005(C)opyright 2006 Carl-Daniel Hailfinger
Carl-Daniel Hailfingerfa510c72008-03-17 01:37:27 +00006Released 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.
Carl-Daniel Hailfingercba07dd2006-09-14 15:12:36 +000010
11*/
12
13#include "lzmadecode.c"
14
15
16static unsigned long ulzma(unsigned char * src, unsigned char * 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 printk_warning("Incorrect stream properties\n");
Ward Vandewegeec2bd532008-08-27 21:53:11 +000031 return 0;
Carl-Daniel Hailfingercba07dd2006-09-14 15:12:36 +000032 }
33 mallocneeds = (LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
34 if (mallocneeds > 15980) {
35 printk_warning("Decoder scratchpad too small!\n");
Ward Vandewegeec2bd532008-08-27 21:53:11 +000036 return 0;
Carl-Daniel Hailfingercba07dd2006-09-14 15:12:36 +000037 }
38 state.Probs = (CProb *)scratchpad;
39 res = LzmaDecode(&state, src + LZMA_PROPERTIES_SIZE + 8, (SizeT)0xffffffff, &inProcessed,
40 dst, outSize, &outProcessed);
41 if (res != 0) {
42 printk_warning("Decoding error = %d\n", res);
Ward Vandewegeec2bd532008-08-27 21:53:11 +000043 return 0;
Carl-Daniel Hailfingercba07dd2006-09-14 15:12:36 +000044 }
45 return outSize;
46}