1 /* inflate.c -- Not copyrighted 1992 by Mark Adler
2 version c10p1, 10 January 1993 */
5 * Adapted for booting Linux by Hannu Savolainen 1993
8 * Nicolas Pitre <nico@visuaide.com>, 1999/04/14 :
9 * Little mods for all variable to reside either into rodata or bss segments
10 * by marking constant variables with 'const' and initializing all the others
11 * at run-time only. This allows for the kernel uncompressor to run
12 * directly from Flash or ROM memory on embeded systems.
15 #include <linux/config.h>
17 #include "LzmaDecode.h"
19 /* Function prototypes */
20 unsigned char get_byte(void);
21 int tikernelunzip(int,char *[], char *[]);
22 static int tidecompress(uch
*, uch
*);
24 void kernel_entry(int, char *[], char *[]);
25 void (*ke
)(int, char *[], char *[]); /* Gen reference to kernel function */
26 void (*prnt
)(unsigned int, char *); /* Gen reference to Yamon print function */
27 void printf(char *ptr
); /* Generate our own printf */
29 int tikernelunzip(int argc
, char *argv
[], char *arge
[])
31 extern unsigned int _ftext
;
32 extern uch kernelimage
[];
36 printf("Launching kernel decompressor.\n");
38 out
= (unsigned char *) LOADADDR
;
39 in
= &(kernelimage
[0]);
41 status
= tidecompress(in
, out
);
44 printf("Kernel decompressor was successful ... launching kernel.\n");
46 ke
= ( void(*)(int, char *[],char*[]))kernel_entry
;
47 (*ke
)(argc
,argv
,arge
);
51 printf("Error in decompression.\n");
57 char hex
[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
67 for (j
= 0; j
< 8; j
++)
69 buf
[2 + 7 - j
] = hex
[i
& 0xf];
77 int tidecompress(uch
*indata
, uch
*outdata
)
79 extern unsigned int workspace
;
80 extern unsigned char kernelimage
[], kernelimage_end
[];
81 unsigned int i
; /* temp value */
82 unsigned int lc
; /* literal context bits */
83 unsigned int lp
; /* literal pos state bits */
84 unsigned int pb
; /* pos state bits */
85 unsigned int osize
; /* uncompressed size */
86 unsigned int wsize
; /* window size */
87 unsigned int insize
= kernelimage_end
- kernelimage
;
91 output_data
= outdata
;
96 lc
= i
% 9, i
= i
/ 9;
97 lp
= i
% 5, pb
= i
/ 5;
99 /* skip rest of the LZMA coder property */
100 for (i
= 0; i
< 4; i
++)
103 /* read the lower half of uncompressed size in the header */
104 osize
= ((unsigned int)get_byte()) +
105 ((unsigned int)get_byte() << 8) +
106 ((unsigned int)get_byte() << 16) +
107 ((unsigned int)get_byte() << 24);
109 /* skip rest of the header (upper half of uncompressed size) */
110 for (i
= 0; i
< 4; i
++)
114 wsize
= (LZMA_BASE_SIZE
+ (LZMA_LIT_SIZE
<< (lc
+ lp
))) * sizeof(CProb
);
116 if ((status
= LzmaDecode((unsigned char *) &workspace
, wsize
, lc
, lp
, pb
,
117 indata
+ 13, insize
- 13, (unsigned char *) output_data
, osize
, &i
)) == LZMA_RESULT_OK
)
124 void printf(char *ptr
)
126 unsigned int *tempptr
= (unsigned int *)0x90000534;
127 prnt
= ( void (*)(unsigned int, char *)) *tempptr
;
131 unsigned char get_byte()
This page took 0.057072 seconds and 5 git commands to generate.