1 Index: linux-2.6.24.7/arch/x86/boot/compressed/LzmaDecode.c
2 ===================================================================
4 +++ linux-2.6.24.7/arch/x86/boot/compressed/LzmaDecode.c
8 + LZMA Decoder (optimized for Speed version)
10 + LZMA SDK 4.17 Copyright (c) 1999-2005 Igor Pavlov (2005-04-05)
11 + http://www.7-zip.org/
13 + LZMA SDK is licensed under two licenses:
14 + 1) GNU Lesser General Public License (GNU LGPL)
15 + 2) Common Public License (CPL)
16 + It means that you can select one of these two licenses and
17 + follow rules of that license.
20 + Igor Pavlov, as the author of this Code, expressly permits you to
21 + statically or dynamically link your Code (or bind by name) to the
22 + interfaces of this file without subjecting your linked Code to the
23 + terms of the CPL or GNU LGPL. Any modifications or additions
24 + to this file, however, are subject to the LGPL or CPL terms.
27 +#include "LzmaDecode.h"
30 +#define Byte unsigned char
33 +#define kNumTopBits 24
34 +#define kTopValue ((UInt32)1 << kNumTopBits)
36 +#define kNumBitModelTotalBits 11
37 +#define kBitModelTotal (1 << kNumBitModelTotalBits)
38 +#define kNumMoveBits 5
40 +#define RC_READ_BYTE (*Buffer++)
42 +#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \
43 + { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}
47 +#define RC_TEST { if (Buffer == BufferLim) \
48 + { UInt32 size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \
49 + BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}
51 +#define RC_INIT Buffer = BufferLim = 0; RC_INIT2
55 +#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }
57 +#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2
61 +#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
63 +#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)
64 +#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;
65 +#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;
67 +#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \
68 + { UpdateBit0(p); mi <<= 1; A0; } else \
69 + { UpdateBit1(p); mi = (mi + mi) + 1; A1; }
71 +#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)
73 +#define RangeDecoderBitTreeDecode(probs, numLevels, res) \
74 + { int i = numLevels; res = 1; \
75 + do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \
76 + res -= (1 << numLevels); }
79 +#define kNumPosBitsMax 4
80 +#define kNumPosStatesMax (1 << kNumPosBitsMax)
82 +#define kLenNumLowBits 3
83 +#define kLenNumLowSymbols (1 << kLenNumLowBits)
84 +#define kLenNumMidBits 3
85 +#define kLenNumMidSymbols (1 << kLenNumMidBits)
86 +#define kLenNumHighBits 8
87 +#define kLenNumHighSymbols (1 << kLenNumHighBits)
90 +#define LenChoice2 (LenChoice + 1)
91 +#define LenLow (LenChoice2 + 1)
92 +#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
93 +#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
94 +#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
97 +#define kNumStates 12
98 +#define kNumLitStates 7
100 +#define kStartPosModelIndex 4
101 +#define kEndPosModelIndex 14
102 +#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
104 +#define kNumPosSlotBits 6
105 +#define kNumLenToPosStates 4
107 +#define kNumAlignBits 4
108 +#define kAlignTableSize (1 << kNumAlignBits)
110 +#define kMatchMinLen 2
113 +#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
114 +#define IsRepG0 (IsRep + kNumStates)
115 +#define IsRepG1 (IsRepG0 + kNumStates)
116 +#define IsRepG2 (IsRepG1 + kNumStates)
117 +#define IsRep0Long (IsRepG2 + kNumStates)
118 +#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
119 +#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
120 +#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
121 +#define LenCoder (Align + kAlignTableSize)
122 +#define RepLenCoder (LenCoder + kNumLenProbs)
123 +#define Literal (RepLenCoder + kNumLenProbs)
125 +#if Literal != LZMA_BASE_SIZE
129 +#ifdef _LZMA_OUT_READ
131 +typedef struct _LzmaVarState
138 + ILzmaInCallback *InCallback;
141 + UInt32 DictionarySize;
142 + UInt32 DictionaryPos;
150 + Byte TempDictionary[4];
153 +int LzmaDecoderInit(
154 + unsigned char *buffer, UInt32 bufferSize,
155 + int lc, int lp, int pb,
156 + unsigned char *dictionary, UInt32 dictionarySize,
158 + ILzmaInCallback *InCallback
160 + unsigned char *inStream, UInt32 inSize
168 + LzmaVarState *vs = (LzmaVarState *)buffer;
169 + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
170 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
172 + if (bufferSize < numProbs * sizeof(CProb) + sizeof(LzmaVarState))
173 + return LZMA_RESULT_NOT_ENOUGH_MEM;
174 + vs->Dictionary = dictionary;
175 + vs->DictionarySize = dictionarySize;
176 + vs->DictionaryPos = 0;
178 + vs->Reps[0] = vs->Reps[1] = vs->Reps[2] = vs->Reps[3] = 1;
184 + dictionary[dictionarySize - 1] = 0;
185 + for (i = 0; i < numProbs; i++)
186 + p[i] = kBitModelTotal >> 1;
191 + RC_INIT(inStream, inSize);
193 + vs->Buffer = Buffer;
194 + vs->BufferLim = BufferLim;
198 + vs->InCallback = InCallback;
201 + return LZMA_RESULT_OK;
204 +int LzmaDecode(unsigned char *buffer,
205 + unsigned char *outStream, UInt32 outSize,
206 + UInt32 *outSizeProcessed)
208 + LzmaVarState *vs = (LzmaVarState *)buffer;
209 + Byte *Buffer = vs->Buffer;
210 + Byte *BufferLim = vs->BufferLim;
211 + UInt32 Range = vs->Range;
212 + UInt32 Code = vs->Code;
214 + ILzmaInCallback *InCallback = vs->InCallback;
216 + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
217 + int state = vs->State;
219 + UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
221 + UInt32 posStateMask = (1 << (vs->pb)) - 1;
222 + UInt32 literalPosMask = (1 << (vs->lp)) - 1;
224 + int len = vs->RemainLen;
225 + UInt32 globalPos = vs->GlobalPos;
227 + Byte *dictionary = vs->Dictionary;
228 + UInt32 dictionarySize = vs->DictionarySize;
229 + UInt32 dictionaryPos = vs->DictionaryPos;
231 + Byte tempDictionary[4];
232 + if (dictionarySize == 0)
234 + dictionary = tempDictionary;
235 + dictionarySize = 1;
236 + tempDictionary[0] = vs->TempDictionary[0];
241 + *outSizeProcessed = 0;
242 + return LZMA_RESULT_OK;
245 + while(len != 0 && nowPos < outSize)
247 + UInt32 pos = dictionaryPos - rep0;
248 + if (pos >= dictionarySize)
249 + pos += dictionarySize;
250 + outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];
251 + if (++dictionaryPos == dictionarySize)
255 + if (dictionaryPos == 0)
256 + previousByte = dictionary[dictionarySize - 1];
258 + previousByte = dictionary[dictionaryPos - 1];
262 + Byte *buffer, UInt32 bufferSize,
263 + int lc, int lp, int pb,
265 + ILzmaInCallback *InCallback,
267 + unsigned char *inStream, UInt32 inSize,
269 + unsigned char *outStream, UInt32 outSize,
270 + UInt32 *outSizeProcessed)
272 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
273 + CProb *p = (CProb *)buffer;
277 + Byte previousByte = 0;
278 + UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
280 + UInt32 posStateMask = (1 << pb) - 1;
281 + UInt32 literalPosMask = (1 << lp) - 1;
289 + if (bufferSize < numProbs * sizeof(CProb))
290 + return LZMA_RESULT_NOT_ENOUGH_MEM;
291 + for (i = 0; i < numProbs; i++)
292 + p[i] = kBitModelTotal >> 1;
298 + RC_INIT(inStream, inSize);
302 + *outSizeProcessed = 0;
303 + while(nowPos < outSize)
307 + int posState = (int)(
309 + #ifdef _LZMA_OUT_READ
315 + prob = p + IsMatch + (state << kNumPosBitsMax) + posState;
320 + prob = p + Literal + (LZMA_LIT_SIZE *
323 + #ifdef _LZMA_OUT_READ
327 + & literalPosMask) << lc) + (previousByte >> (8 - lc))));
329 + if (state >= kNumLitStates)
332 + #ifdef _LZMA_OUT_READ
333 + UInt32 pos = dictionaryPos - rep0;
334 + if (pos >= dictionarySize)
335 + pos += dictionarySize;
336 + matchByte = dictionary[pos];
338 + matchByte = outStream[nowPos - rep0];
345 + bit = (matchByte & 0x100);
346 + probLit = prob + 0x100 + bit + symbol;
347 + RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)
349 + while (symbol < 0x100);
351 + while (symbol < 0x100)
353 + CProb *probLit = prob + symbol;
354 + RC_GET_BIT(probLit, symbol)
356 + previousByte = (Byte)symbol;
358 + outStream[nowPos++] = previousByte;
359 + #ifdef _LZMA_OUT_READ
360 + dictionary[dictionaryPos] = previousByte;
361 + if (++dictionaryPos == dictionarySize)
364 + if (state < 4) state = 0;
365 + else if (state < 10) state -= 3;
371 + prob = p + IsRep + state;
378 + state = state < kNumLitStates ? 0 : 3;
379 + prob = p + LenCoder;
384 + prob = p + IsRepG0 + state;
388 + prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;
391 + #ifdef _LZMA_OUT_READ
396 + #ifdef _LZMA_OUT_READ
400 + return LZMA_RESULT_DATA_ERROR;
401 + state = state < kNumLitStates ? 9 : 11;
402 + #ifdef _LZMA_OUT_READ
403 + pos = dictionaryPos - rep0;
404 + if (pos >= dictionarySize)
405 + pos += dictionarySize;
406 + previousByte = dictionary[pos];
407 + dictionary[dictionaryPos] = previousByte;
408 + if (++dictionaryPos == dictionarySize)
411 + previousByte = outStream[nowPos - rep0];
413 + outStream[nowPos++] = previousByte;
425 + prob = p + IsRepG1 + state;
434 + prob = p + IsRepG2 + state;
451 + state = state < kNumLitStates ? 8 : 11;
452 + prob = p + RepLenCoder;
455 + int numBits, offset;
456 + CProb *probLen = prob + LenChoice;
459 + UpdateBit0(probLen);
460 + probLen = prob + LenLow + (posState << kLenNumLowBits);
462 + numBits = kLenNumLowBits;
466 + UpdateBit1(probLen);
467 + probLen = prob + LenChoice2;
470 + UpdateBit0(probLen);
471 + probLen = prob + LenMid + (posState << kLenNumMidBits);
472 + offset = kLenNumLowSymbols;
473 + numBits = kLenNumMidBits;
477 + UpdateBit1(probLen);
478 + probLen = prob + LenHigh;
479 + offset = kLenNumLowSymbols + kLenNumMidSymbols;
480 + numBits = kLenNumHighBits;
483 + RangeDecoderBitTreeDecode(probLen, numBits, len);
490 + state += kNumLitStates;
491 + prob = p + PosSlot +
492 + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
494 + RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);
495 + if (posSlot >= kStartPosModelIndex)
497 + int numDirectBits = ((posSlot >> 1) - 1);
498 + rep0 = (2 | ((UInt32)posSlot & 1));
499 + if (posSlot < kEndPosModelIndex)
501 + rep0 <<= numDirectBits;
502 + prob = p + SpecPos + rep0 - posSlot - 1;
506 + numDirectBits -= kNumAlignBits;
518 + while (--numDirectBits != 0);
520 + rep0 <<= kNumAlignBits;
521 + numDirectBits = kNumAlignBits;
528 + CProb *prob3 = prob + mi;
529 + RC_GET_BIT2(prob3, mi, ; , rep0 |= i);
532 + while(--numDirectBits != 0);
537 + if (++rep0 == (UInt32)(0))
539 + /* it's for stream version */
545 + len += kMatchMinLen;
547 + #ifdef _LZMA_OUT_READ
548 + + globalPos || rep0 > dictionarySize
551 + return LZMA_RESULT_DATA_ERROR;
554 + #ifdef _LZMA_OUT_READ
555 + UInt32 pos = dictionaryPos - rep0;
556 + if (pos >= dictionarySize)
557 + pos += dictionarySize;
558 + previousByte = dictionary[pos];
559 + dictionary[dictionaryPos] = previousByte;
560 + if (++dictionaryPos == dictionarySize)
563 + previousByte = outStream[nowPos - rep0];
566 + outStream[nowPos++] = previousByte;
568 + while(len != 0 && nowPos < outSize);
573 + #ifdef _LZMA_OUT_READ
574 + vs->Buffer = Buffer;
575 + vs->BufferLim = BufferLim;
578 + vs->DictionaryPos = dictionaryPos;
579 + vs->GlobalPos = globalPos + nowPos;
580 + vs->Reps[0] = rep0;
581 + vs->Reps[1] = rep1;
582 + vs->Reps[2] = rep2;
583 + vs->Reps[3] = rep3;
585 + vs->RemainLen = len;
586 + vs->TempDictionary[0] = tempDictionary[0];
589 + *outSizeProcessed = nowPos;
590 + return LZMA_RESULT_OK;
592 Index: linux-2.6.24.7/arch/x86/boot/compressed/LzmaDecode.h
593 ===================================================================
595 +++ linux-2.6.24.7/arch/x86/boot/compressed/LzmaDecode.h
599 + LZMA Decoder interface
601 + LZMA SDK 4.16 Copyright (c) 1999-2005 Igor Pavlov (2005-03-18)
602 + http://www.7-zip.org/
604 + LZMA SDK is licensed under two licenses:
605 + 1) GNU Lesser General Public License (GNU LGPL)
606 + 2) Common Public License (CPL)
607 + It means that you can select one of these two licenses and
608 + follow rules of that license.
611 + Igor Pavlov, as the author of this code, expressly permits you to
612 + statically or dynamically link your code (or bind by name) to the
613 + interfaces of this file without subjecting your linked code to the
614 + terms of the CPL or GNU LGPL. Any modifications or additions
615 + to this file, however, are subject to the LGPL or CPL terms.
618 +#ifndef __LZMADECODE_H
619 +#define __LZMADECODE_H
621 +/* #define _LZMA_IN_CB */
622 +/* Use callback for input data */
624 +/* #define _LZMA_OUT_READ */
625 +/* Use read function for output data */
627 +/* #define _LZMA_PROB32 */
628 +/* It can increase speed on some 32-bit CPUs,
629 + but memory usage will be doubled in that case */
631 +/* #define _LZMA_LOC_OPT */
632 +/* Enable local speed optimizations inside code */
635 +#ifdef _LZMA_UINT32_IS_ULONG
636 +#define UInt32 unsigned long
638 +#define UInt32 unsigned int
643 +#define CProb UInt32
645 +#define CProb unsigned short
648 +#define LZMA_RESULT_OK 0
649 +#define LZMA_RESULT_DATA_ERROR 1
650 +#define LZMA_RESULT_NOT_ENOUGH_MEM 2
653 +typedef struct _ILzmaInCallback
655 + int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize);
659 +#define LZMA_BASE_SIZE 1846
660 +#define LZMA_LIT_SIZE 768
663 +bufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb)
664 +bufferSize += 100 in case of _LZMA_OUT_READ
665 +by default CProb is unsigned short,
666 +but if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int)
669 +#ifdef _LZMA_OUT_READ
670 +int LzmaDecoderInit(
671 + unsigned char *buffer, UInt32 bufferSize,
672 + int lc, int lp, int pb,
673 + unsigned char *dictionary, UInt32 dictionarySize,
675 + ILzmaInCallback *inCallback
677 + unsigned char *inStream, UInt32 inSize
683 + unsigned char *buffer,
684 + #ifndef _LZMA_OUT_READ
686 + int lc, int lp, int pb,
688 + ILzmaInCallback *inCallback,
690 + unsigned char *inStream, UInt32 inSize,
693 + unsigned char *outStream, UInt32 outSize,
694 + UInt32 *outSizeProcessed);
697 Index: linux-2.6.24.7/arch/x86/boot/compressed/lzma_misc.c
698 ===================================================================
700 +++ linux-2.6.24.7/arch/x86/boot/compressed/lzma_misc.c
705 + * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
706 + * puts by Nick Holloway 1993, better puts by Martin Mares 1995
707 + * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
709 + * Decompress LZMA compressed vmlinuz
710 + * Version 0.9 Copyright (c) Ming-Ching Tiew mctiew@yahoo.com
711 + * Program adapted from misc.c for 2.6 kernel
712 + * Forward ported to latest 2.6 version of misc.c by
713 + * Felix Fietkau <nbd@openwrt.org>
716 +#undef CONFIG_PARAVIRT
717 +#include <linux/linkage.h>
718 +#include <linux/vmalloc.h>
719 +#include <linux/screen_info.h>
721 +#include <asm/page.h>
722 +#include <asm/boot.h>
725 + * This code is compiled with -fPIC and it is relocated dynamically
726 + * at run time, but no relocation processing is performed.
727 + * This means that it is not safe to place pointers in static structures.
731 + * Getting to provable safe in place decompression is hard.
732 + * Worst case behaviours need to be analized.
733 + * Background information:
735 + * The file layout is:
742 + * compressed data blocks[N]
743 + * crc[4] orig_len[4]
745 + * resulting in 18 bytes of non compressed data overhead.
747 + * Files divided into blocks
748 + * 1 bit (last block flag)
749 + * 2 bits (block type)
751 + * 1 block occurs every 32K -1 bytes or when there 50% compression has been achieved.
752 + * The smallest block type encoding is always used.
755 + * 32 bits length in bytes.
758 + * magic fixed tree.
762 + * dynamic tree encoding.
766 + * The buffer for decompression in place is the length of the
767 + * uncompressed data, plus a small amount extra to keep the algorithm safe.
768 + * The compressed data is placed at the end of the buffer. The output
769 + * pointer is placed at the start of the buffer and the input pointer
770 + * is placed where the compressed data starts. Problems will occur
771 + * when the output pointer overruns the input pointer.
773 + * The output pointer can only overrun the input pointer if the input
774 + * pointer is moving faster than the output pointer. A condition only
775 + * triggered by data whose compressed form is larger than the uncompressed
778 + * The worst case at the block level is a growth of the compressed data
779 + * of 5 bytes per 32767 bytes.
781 + * The worst case internal to a compressed block is very hard to figure.
782 + * The worst case can at least be boundined by having one bit that represents
783 + * 32764 bytes and then all of the rest of the bytes representing the very
786 + * All of which is enough to compute an amount of extra data that is required
787 + * to be safe. To avoid problems at the block level allocating 5 extra bytes
788 + * per 32767 bytes of data is sufficient. To avoind problems internal to a block
789 + * adding an extra 32767 bytes (the worst case uncompressed block size) is
790 + * sufficient, to ensure that in the worst case the decompressed data for
791 + * block will stop the byte before the compressed data for a block begins.
792 + * To avoid problems with the compressed data's meta information an extra 18
793 + * bytes are needed. Leading to the formula:
795 + * extra_bytes = (uncompressed_size >> 12) + 32768 + 18 + decompressor_size.
797 + * Adding 8 bytes per 32K is a bit excessive but much easier to calculate.
798 + * Adding 32768 instead of 32767 just makes for round numbers.
799 + * Adding the decompressor_size is necessary as it musht live after all
800 + * of the data as well. Last I measured the decompressor is about 14K.
801 + * 10K of actuall data and 4K of bss.
806 + * gzip declarations
809 +#define OF(args) args
810 +#define STATIC static
814 +typedef unsigned char uch;
815 +typedef unsigned short ush;
816 +typedef unsigned long ulg;
818 +#define WSIZE 0x80000000 /* Window size must be at least 32k,
819 + * and a power of two
820 + * We don't actually have a window just
821 + * a huge output buffer so I report
822 + * a 2G windows size, as that should
823 + * always be larger than our output buffer.
826 +static uch *inbuf; /* input buffer */
827 +static uch *window; /* Sliding window buffer, (and final output buffer) */
829 +static unsigned insize; /* valid bytes in inbuf */
830 +static unsigned inptr; /* index of next byte to be processed in inbuf */
831 +static unsigned long workspace;
833 +#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
835 +/* Diagnostic functions */
837 +# define Assert(cond,msg) {if(!(cond)) error(msg);}
838 +# define Trace(x) fprintf x
839 +# define Tracev(x) {if (verbose) fprintf x ;}
840 +# define Tracevv(x) {if (verbose>1) fprintf x ;}
841 +# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
842 +# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
844 +# define Assert(cond,msg)
848 +# define Tracec(c,x)
849 +# define Tracecv(c,x)
852 +static int fill_inbuf(void);
855 + * This is set up by the setup-routine at boot-time
857 +static unsigned char *real_mode; /* Pointer to real-mode data */
858 +extern unsigned char input_data[];
859 +extern int input_len;
861 +static void error(char *x);
862 +static void *memcpy(void *dest, const void *src, unsigned n);
864 +#ifdef CONFIG_X86_NUMAQ
868 +static void* memcpy(void* dest, const void* src, unsigned n)
871 + char *d = (char *)dest, *s = (char *)src;
873 + for (i=0;i<n;i++) d[i] = s[i];
877 +/* ===========================================================================
878 + * Fill the input buffer. This is called only when the buffer is empty
879 + * and at least one byte is really needed.
881 +static int fill_inbuf(void)
883 + error("ran out of input data");
888 +// When using LZMA in callback, the compressed length is not needed.
889 +// Otherwise you need a special version of lzma compression program
890 +// which will pad the compressed length in the header.
892 +#include "LzmaDecode.h"
893 +#include "LzmaDecode.c"
895 +static int read_byte(void *object, unsigned char **buffer, UInt32 *bufferSize);
899 + * Do the lzma decompression
900 + * When using LZMA in callback, the end of input stream is automatically determined
902 +static int lzma_unzip(void)
905 + unsigned int i; /* temp value */
906 + unsigned int lc; /* literal context bits */
907 + unsigned int lp; /* literal pos state bits */
908 + unsigned int pb; /* pos state bits */
909 + unsigned int uncompressedSize = 0;
912 + ILzmaInCallback callback;
913 + callback.Read = read_byte;
917 + lc = i % 9, i = i / 9;
918 + lp = i % 5, pb = i / 5;
920 + /* skip dictionary size */
921 + for (i = 0; i < 4; i++)
923 + // get uncompressedSize
924 + p= (char*)&uncompressedSize;
925 + for (i = 0; i < 4; i++)
928 + //get compressedSize
929 + for (i = 0; i < 4; i++)
932 + // point it beyond uncompresedSize
933 + //workspace = window + uncompressedSize;
935 + /* decompress kernel */
936 + if (LzmaDecode((unsigned char*)workspace, ~0, lc, lp, pb, &callback,
937 + (unsigned char*)window, uncompressedSize, &i) == LZMA_RESULT_OK)
945 +static int read_byte(void *object, unsigned char **buffer, UInt32 *bufferSize)
947 + static unsigned int i = 0;
948 + static unsigned char val;
952 + return LZMA_RESULT_OK;
956 +static void error(char *x)
958 + while(1); /* Halt */
961 +asmlinkage void decompress_kernel(void *rmode, unsigned long end,
962 + uch *input_data, unsigned long input_len, uch *output)
967 + inbuf = input_data; /* Input buffer */
968 + insize = input_len;
971 + if ((u32)output & (CONFIG_PHYSICAL_ALIGN -1))
972 + error("Destination address not CONFIG_PHYSICAL_ALIGN aligned");
973 + if ((workspace = end) > ((-__PAGE_OFFSET-(512 <<20)-1) & 0x7fffffff))
974 + error("Destination address too large");
975 +#ifndef CONFIG_RELOCATABLE
976 + if ((u32)output != LOAD_PHYSICAL_ADDR)
977 + error("Wrong destination address");
983 Index: linux-2.6.24.7/scripts/Makefile.lib
984 ===================================================================
985 --- linux-2.6.24.7.orig/scripts/Makefile.lib
986 +++ linux-2.6.24.7/scripts/Makefile.lib
987 @@ -166,4 +166,9 @@ cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS)
988 quiet_cmd_gzip = GZIP $@
989 cmd_gzip = gzip -f -9 < $< > $@
994 +quiet_cmd_lzma = LZMA $@
995 +cmd_lzma = bash -e scripts/lzma_kern $< $@ -lc7 -lp0 -pb0
997 +# cmd_lzma = lzmacomp $< 700 > $@
998 Index: linux-2.6.24.7/scripts/lzma_kern
999 ===================================================================
1001 +++ linux-2.6.24.7/scripts/lzma_kern
1003 +get-size() { echo "$5" ;}
1004 +printf -v len '%.8x' "$(get-size $(ls -l "$1"))"
1006 +echo -ne "\x$(echo $len | cut -c 7,8)\x$(echo $len | cut -c 5,6)\x$(echo $len | cut -c 3,4)\x$(echo $len | cut -c 1,2)" >> "$2"
1007 Index: linux-2.6.24.7/arch/x86/boot/compressed/Makefile_32
1008 ===================================================================
1009 --- linux-2.6.24.7.orig/arch/x86/boot/compressed/Makefile_32
1010 +++ linux-2.6.24.7/arch/x86/boot/compressed/Makefile_32
1012 # create a compressed vmlinux image from the original vmlinux
1015 -targets := vmlinux vmlinux.bin vmlinux.bin.gz head_32.o misc_32.o piggy.o \
1016 - vmlinux.bin.all vmlinux.relocs
1017 +targets := vmlinux vmlinux.bin vmlinux.bin.lzma head_32.o piggy.o \
1018 + vmlinux.bin.all vmlinux.relocs lzma_misc.o
1019 EXTRA_AFLAGS := -traditional
1021 LDFLAGS_vmlinux := -T
1022 @@ -17,7 +17,7 @@ KBUILD_CFLAGS := -m32 -D__KERNEL__ $(LI
1023 $(call cc-option,-fno-stack-protector)
1024 LDFLAGS := -m elf_i386
1026 -$(obj)/vmlinux: $(src)/vmlinux_32.lds $(obj)/head_32.o $(obj)/misc_32.o $(obj)/piggy.o FORCE
1027 +$(obj)/vmlinux: $(src)/vmlinux_32.lds $(obj)/head_32.o $(obj)/lzma_misc.o $(obj)/piggy.o FORCE
1028 $(call if_changed,ld)
1031 @@ -37,14 +37,14 @@ $(obj)/vmlinux.bin.all: $(vmlinux.bin.al
1032 $(call if_changed,relocbin)
1034 ifdef CONFIG_RELOCATABLE
1035 -$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin.all FORCE
1036 - $(call if_changed,gzip)
1037 +$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin.all FORCE
1038 + $(call if_changed,lzma)
1040 -$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
1041 - $(call if_changed,gzip)
1042 +$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
1043 + $(call if_changed,lzma)
1046 LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T
1048 -$(obj)/piggy.o: $(src)/vmlinux_32.scr $(obj)/vmlinux.bin.gz FORCE
1049 +$(obj)/piggy.o: $(src)/vmlinux_32.scr $(obj)/vmlinux.bin.lzma FORCE
1050 $(call if_changed,ld)