Carl-Daniel Hailfinger | cba07dd | 2006-09-14 15:12:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 3 | Coreboot interface to memory-saving variant of LZMA decoder |
Carl-Daniel Hailfinger | fa510c7 | 2008-03-17 01:37:27 +0000 | [diff] [blame] | 4 | |
Carl-Daniel Hailfinger | cba07dd | 2006-09-14 15:12:36 +0000 | [diff] [blame] | 5 | (C)opyright 2006 Carl-Daniel Hailfinger |
Carl-Daniel Hailfinger | fa510c7 | 2008-03-17 01:37:27 +0000 | [diff] [blame] | 6 | Released under the GNU GPL v2 or later |
| 7 | |
| 8 | Parts of this file are based on C/7zip/Compress/LZMA_C/LzmaTest.c from the LZMA |
| 9 | SDK 4.42, which is written and distributed to public domain by Igor Pavlov. |
Carl-Daniel Hailfinger | cba07dd | 2006-09-14 15:12:36 +0000 | [diff] [blame] | 10 | |
| 11 | */ |
| 12 | |
| 13 | #include "lzmadecode.c" |
Patrick Georgi | 7994164 | 2009-04-24 16:44:34 +0000 | [diff] [blame] | 14 | #include <console/console.h> |
| 15 | #include <string.h> |
Myles Watson | 5817078 | 2009-10-28 16:13:28 +0000 | [diff] [blame] | 16 | #include <lib.h> |
Carl-Daniel Hailfinger | cba07dd | 2006-09-14 15:12:36 +0000 | [diff] [blame] | 17 | |
Patrick Georgi | 7994164 | 2009-04-24 16:44:34 +0000 | [diff] [blame] | 18 | unsigned long ulzma(unsigned char * src, unsigned char * dst) |
Carl-Daniel Hailfinger | cba07dd | 2006-09-14 15:12:36 +0000 | [diff] [blame] | 19 | { |
| 20 | unsigned char properties[LZMA_PROPERTIES_SIZE]; |
| 21 | UInt32 outSize; |
| 22 | SizeT inProcessed; |
| 23 | SizeT outProcessed; |
| 24 | int res; |
| 25 | CLzmaDecoderState state; |
| 26 | SizeT mallocneeds; |
| 27 | unsigned char scratchpad[15980]; |
| 28 | |
| 29 | memcpy(properties, src, LZMA_PROPERTIES_SIZE); |
| 30 | outSize = *(UInt32 *)(src + LZMA_PROPERTIES_SIZE); |
| 31 | if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 32 | printk(BIOS_WARNING, "lzma: Incorrect stream properties.\n"); |
Ward Vandewege | ec2bd53 | 2008-08-27 21:53:11 +0000 | [diff] [blame] | 33 | return 0; |
Carl-Daniel Hailfinger | cba07dd | 2006-09-14 15:12:36 +0000 | [diff] [blame] | 34 | } |
| 35 | mallocneeds = (LzmaGetNumProbs(&state.Properties) * sizeof(CProb)); |
| 36 | if (mallocneeds > 15980) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 37 | printk(BIOS_WARNING, "lzma: Decoder scratchpad too small!\n"); |
Ward Vandewege | ec2bd53 | 2008-08-27 21:53:11 +0000 | [diff] [blame] | 38 | return 0; |
Carl-Daniel Hailfinger | cba07dd | 2006-09-14 15:12:36 +0000 | [diff] [blame] | 39 | } |
| 40 | state.Probs = (CProb *)scratchpad; |
| 41 | res = LzmaDecode(&state, src + LZMA_PROPERTIES_SIZE + 8, (SizeT)0xffffffff, &inProcessed, |
| 42 | dst, outSize, &outProcessed); |
| 43 | if (res != 0) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 44 | printk(BIOS_WARNING, "lzma: Decoding error = %d\n", res); |
Ward Vandewege | ec2bd53 | 2008-08-27 21:53:11 +0000 | [diff] [blame] | 45 | return 0; |
Carl-Daniel Hailfinger | cba07dd | 2006-09-14 15:12:36 +0000 | [diff] [blame] | 46 | } |
| 47 | return outSize; |
| 48 | } |