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
35 #include "LzmaDecode.h"
37 #define BCM4710_FLASH 0x1fc00000 /* Flash */
39 #define KSEG0 0x80000000
40 #define KSEG1 0xa0000000
42 #define KSEG1ADDR(a) ((((unsigned)(a)) & 0x1fffffffU) | KSEG1)
44 #define Index_Invalidate_I 0x00
45 #define Index_Writeback_Inv_D 0x01
47 #define cache_unroll(base,op) \
48 __asm__ __volatile__( \
58 static __inline__
void blast_icache(unsigned long size
, unsigned long lsize
)
60 unsigned long start
= KSEG0
;
61 unsigned long end
= (start
+ size
);
64 cache_unroll(start
,Index_Invalidate_I
);
69 static __inline__
void blast_dcache(unsigned long size
, unsigned long lsize
)
71 unsigned long start
= KSEG0
;
72 unsigned long end
= (start
+ size
);
75 cache_unroll(start
,Index_Writeback_Inv_D
);
80 #define TRX_MAGIC 0x30524448 /* "HDR0" */
83 unsigned int magic
; /* "HDR0" */
84 unsigned int len
; /* Length of file including header */
85 unsigned int crc32
; /* 32-bit CRC from flag_version to end of file */
86 unsigned int flag_version
; /* 0:15 flags, 16:31 version */
87 unsigned int offsets
[3]; /* Offsets of partitions from start of header */
90 #define EDIMAX_PS_HEADER_MAGIC 0x36315350 /* "PS16" */
91 #define EDIMAX_PS_HEADER_LEN 0xc /* 12 bytes long for edimax header */
93 /* beyound the image end, size not known in advance */
94 extern unsigned char workspace
[];
99 /* flash access should be aligned, so wrapper is used */
100 /* read byte from the flash, all accesses are 32-bit aligned */
101 static int read_byte(void *object
, unsigned char **buffer
, UInt32
*bufferSize
)
103 static unsigned int val
;
105 if (((unsigned int)offset
% 4) == 0) {
106 val
= *(unsigned int *)data
;
111 *buffer
= ((unsigned char *)&val
) + (offset
++ & 3);
113 return LZMA_RESULT_OK
;
116 static __inline__
unsigned char get_byte(void)
118 unsigned char *buffer
;
121 return read_byte(0, &buffer
, &fake
), *buffer
;
124 /* should be the first function */
125 void entry(unsigned long icache_size
, unsigned long icache_lsize
,
126 unsigned long dcache_size
, unsigned long dcache_lsize
,
127 unsigned long fw_arg0
, unsigned long fw_arg1
,
128 unsigned long fw_arg2
, unsigned long fw_arg3
)
130 unsigned int i
; /* temp value */
131 unsigned int lc
; /* literal context bits */
132 unsigned int lp
; /* literal pos state bits */
133 unsigned int pb
; /* pos state bits */
134 unsigned int osize
; /* uncompressed size */
136 ILzmaInCallback callback
;
137 callback
.Read
= read_byte
;
139 /* look for trx header, 32-bit data access */
140 for (data
= ((unsigned char *) KSEG1ADDR(BCM4710_FLASH
));
141 ((struct trx_header
*)data
)->magic
!= TRX_MAGIC
&&
142 ((struct trx_header
*)data
)->magic
!= EDIMAX_PS_HEADER_MAGIC
;
145 if (((struct trx_header
*)data
)->magic
== EDIMAX_PS_HEADER_MAGIC
)
146 data
+= EDIMAX_PS_HEADER_LEN
;
147 /* compressed kernel is in the partition 0 or 1 */
148 if (((struct trx_header
*)data
)->offsets
[1] > 65536)
149 data
+= ((struct trx_header
*)data
)->offsets
[0];
151 data
+= ((struct trx_header
*)data
)->offsets
[1];
157 lc
= i
% 9, i
= i
/ 9;
158 lp
= i
% 5, pb
= i
/ 5;
160 /* skip rest of the LZMA coder property */
161 for (i
= 0; i
< 4; i
++)
164 /* read the lower half of uncompressed size in the header */
165 osize
= ((unsigned int)get_byte()) +
166 ((unsigned int)get_byte() << 8) +
167 ((unsigned int)get_byte() << 16) +
168 ((unsigned int)get_byte() << 24);
170 /* skip rest of the header (upper half of uncompressed size) */
171 for (i
= 0; i
< 4; i
++)
174 /* decompress kernel */
175 if (LzmaDecode(workspace
, ~0, lc
, lp
, pb
, &callback
,
176 (unsigned char*)LOADADDR
, osize
, &i
) == LZMA_RESULT_OK
)
178 blast_dcache(dcache_size
, dcache_lsize
);
179 blast_icache(icache_size
, icache_lsize
);
181 /* Jump to load address */
182 ((void (*)(unsigned long, unsigned long, unsigned long,
183 unsigned long)) LOADADDR
)(fw_arg0
, fw_arg1
, fw_arg2
,
This page took 0.049836 seconds and 5 git commands to generate.