2 * LZMA compressed kernel decompressor for bcm947xx boards
4 * Copyright (C) 2005 by Oleg I. Vdovikin <oleg@cs.msu.su>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Please note, this was code based on the bunzip2 decompressor code
22 * by Manuel Novoa III (mjn3@codepoet.org), although the only thing left
23 * is an idea and part of original vendor code
26 * 12-Mar-2005 Mineharu Takahara <mtakahar@yahoo.com>
27 * pass actual output size to decoder (stream mode
28 * compressed input is not a requirement anymore)
30 * 24-Apr-2005 Oleg I. Vdovikin
31 * reordered functions using lds script, removed forward decl
33 * ??-Nov-2005 Mike Baker
34 * reorder the script as an lzma wrapper; do not depend on flash access
37 #include "LzmaDecode.h"
40 #define KSEG0ADDR(addr) (0x80000000|addr)
42 register volatile gd_t
*gd
asm ("k0");
45 static __inline__
unsigned char get_byte()
47 unsigned char *buffer
;
55 /* This puts lzma workspace 128k below RAM end.
56 * That should be enough for both lzma and stack
58 static char *buffer
= (char *)(RAMSTART
+ RAMSIZE
- 0x00020000);
59 extern char _binary_vmlinux_lzma_start
[];
60 extern char _binary_vmlinux_lzma_end
[];
61 extern char lzma_start
[];
62 extern char lzma_end
[];
64 /* should be the first function */
65 void entry(unsigned int arg0
, unsigned int arg1
,
66 unsigned int arg2
, unsigned int arg3
)
68 unsigned int i
; /* temp value */
69 unsigned int isize
; /* compressed size */
70 unsigned int osize
; /* uncompressed size */
72 char **argv
= (char **)arg1
;
73 char **envp
= (char **)arg2
;
77 data
= (unsigned char *)_binary_vmlinux_lzma_start
;
78 isize
= _binary_vmlinux_lzma_end
- _binary_vmlinux_lzma_start
+ 1;
80 puts("\nLZMA kernel loader\n");
82 printf("lzma data @ %#x - %#x\n", _binary_vmlinux_lzma_start
, _binary_vmlinux_lzma_end
);
83 printf("load addr @ %#x\n\n", KERNEL_ENTRY
);
84 printf("jump table @ %#x\n", gd
->jt
[3]);
88 vs
.Properties
.lc
= i
% 9, i
= i
/ 9;
89 vs
.Properties
.lp
= i
% 5, vs
.Properties
.pb
= i
/ 5;
91 vs
.Probs
= (CProb
*)buffer
;
93 /* skip rest of the LZMA coder property */
96 /* read the lower half of uncompressed size in the header */
97 osize
= ((unsigned int)get_byte()) +
98 ((unsigned int)get_byte() << 8) +
99 ((unsigned int)get_byte() << 16) +
100 ((unsigned int)get_byte() << 24);
102 /* skip rest of the header (upper half of uncompressed size) */
105 /* decompress kernel */
106 puts("\nDecompressing kernel...");
107 if ((i
= LzmaDecode(&vs
,
108 (unsigned char*)data
, isize
, &isize
,
109 (unsigned char*)KERNEL_ENTRY
, osize
, &osize
)) == LZMA_RESULT_OK
)
113 /* Jump to load address */
114 // ((void (*)(int a0, int a1, int a2, int a3))KERNEL_ENTRY)(0,0,0,0);
115 ((void (*)(int a0
, int a1
, int a2
, int a3
))KERNEL_ENTRY
)(arg0
, arg1
, arg2
, arg3
);