diff options
author | Olaf Hering <olh@suse.de> | 2005-10-28 20:46:38 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2005-10-29 01:04:43 -0400 |
commit | 7054036fc526b741ba90ff1d077ac900362f30ed (patch) | |
tree | 90d4edc10a81861219eb3d37e2fd93814935c315 /arch/ppc64/boot/main.c | |
parent | 8afe31c9eb92389f091a40def9650278ca66befd (diff) |
[PATCH] ppc64 boot: remove zlib
Switch ppc64 to the in-kernel zlib, it has less bugs than the current one.
The code in arch/ppc64/boot is compiled as 32bit, so it can not use the
includes from include/asm.
Copy all zlib related header files and convert them with sed.
Reduce the scratch size to 47k, check possible changes at runtime.
Signed-off-by: Olaf Hering <olh@suse.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Anton Blanchard <anton@samba.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/ppc64/boot/main.c')
-rw-r--r-- | arch/ppc64/boot/main.c | 82 |
1 files changed, 12 insertions, 70 deletions
diff --git a/arch/ppc64/boot/main.c b/arch/ppc64/boot/main.c index f7ec19a2d0b0..0b95ccfb143c 100644 --- a/arch/ppc64/boot/main.c +++ b/arch/ppc64/boot/main.c | |||
@@ -26,12 +26,6 @@ extern void flush_cache(void *, unsigned long); | |||
26 | #define RAM_END (512<<20) // Fixme: use OF */ | 26 | #define RAM_END (512<<20) // Fixme: use OF */ |
27 | #define ONE_MB 0x100000 | 27 | #define ONE_MB 0x100000 |
28 | 28 | ||
29 | static char *avail_ram; | ||
30 | static char *begin_avail, *end_avail; | ||
31 | static char *avail_high; | ||
32 | static unsigned int heap_use; | ||
33 | static unsigned int heap_max; | ||
34 | |||
35 | extern char _start[]; | 29 | extern char _start[]; |
36 | extern char _end[]; | 30 | extern char _end[]; |
37 | extern char _vmlinux_start[]; | 31 | extern char _vmlinux_start[]; |
@@ -50,7 +44,8 @@ static struct addr_range vmlinux = {0, 0, 0}; | |||
50 | static struct addr_range vmlinuz = {0, 0, 0}; | 44 | static struct addr_range vmlinuz = {0, 0, 0}; |
51 | static struct addr_range initrd = {0, 0, 0}; | 45 | static struct addr_range initrd = {0, 0, 0}; |
52 | 46 | ||
53 | static char scratch[128<<10]; /* 128kB of scratch space for gunzip */ | 47 | static char scratch[46912]; /* scratch space for gunzip, from zlib_inflate_workspacesize() */ |
48 | |||
54 | 49 | ||
55 | typedef void (*kernel_entry_t)( unsigned long, | 50 | typedef void (*kernel_entry_t)( unsigned long, |
56 | unsigned long, | 51 | unsigned long, |
@@ -161,17 +156,12 @@ void start(unsigned long a1, unsigned long a2, void *promptr) | |||
161 | /* Eventually gunzip the kernel */ | 156 | /* Eventually gunzip the kernel */ |
162 | if (*(unsigned short *)vmlinuz.addr == 0x1f8b) { | 157 | if (*(unsigned short *)vmlinuz.addr == 0x1f8b) { |
163 | int len; | 158 | int len; |
164 | avail_ram = scratch; | ||
165 | begin_avail = avail_high = avail_ram; | ||
166 | end_avail = scratch + sizeof(scratch); | ||
167 | printf("gunzipping (0x%lx <- 0x%lx:0x%0lx)...", | 159 | printf("gunzipping (0x%lx <- 0x%lx:0x%0lx)...", |
168 | vmlinux.addr, vmlinuz.addr, vmlinuz.addr+vmlinuz.size); | 160 | vmlinux.addr, vmlinuz.addr, vmlinuz.addr+vmlinuz.size); |
169 | len = vmlinuz.size; | 161 | len = vmlinuz.size; |
170 | gunzip((void *)vmlinux.addr, vmlinux.size, | 162 | gunzip((void *)vmlinux.addr, vmlinux.size, |
171 | (unsigned char *)vmlinuz.addr, &len); | 163 | (unsigned char *)vmlinuz.addr, &len); |
172 | printf("done 0x%lx bytes\n\r", len); | 164 | printf("done 0x%lx bytes\n\r", len); |
173 | printf("0x%x bytes of heap consumed, max in use 0x%x\n\r", | ||
174 | (unsigned)(avail_high - begin_avail), heap_max); | ||
175 | } else { | 165 | } else { |
176 | memmove((void *)vmlinux.addr,(void *)vmlinuz.addr,vmlinuz.size); | 166 | memmove((void *)vmlinux.addr,(void *)vmlinuz.addr,vmlinuz.size); |
177 | } | 167 | } |
@@ -225,64 +215,12 @@ void start(unsigned long a1, unsigned long a2, void *promptr) | |||
225 | exit(); | 215 | exit(); |
226 | } | 216 | } |
227 | 217 | ||
228 | struct memchunk { | ||
229 | unsigned int size; | ||
230 | unsigned int pad; | ||
231 | struct memchunk *next; | ||
232 | }; | ||
233 | |||
234 | static struct memchunk *freechunks; | ||
235 | |||
236 | void *zalloc(void *x, unsigned items, unsigned size) | ||
237 | { | ||
238 | void *p; | ||
239 | struct memchunk **mpp, *mp; | ||
240 | |||
241 | size *= items; | ||
242 | size = _ALIGN(size, sizeof(struct memchunk)); | ||
243 | heap_use += size; | ||
244 | if (heap_use > heap_max) | ||
245 | heap_max = heap_use; | ||
246 | for (mpp = &freechunks; (mp = *mpp) != 0; mpp = &mp->next) { | ||
247 | if (mp->size == size) { | ||
248 | *mpp = mp->next; | ||
249 | return mp; | ||
250 | } | ||
251 | } | ||
252 | p = avail_ram; | ||
253 | avail_ram += size; | ||
254 | if (avail_ram > avail_high) | ||
255 | avail_high = avail_ram; | ||
256 | if (avail_ram > end_avail) { | ||
257 | printf("oops... out of memory\n\r"); | ||
258 | pause(); | ||
259 | } | ||
260 | return p; | ||
261 | } | ||
262 | |||
263 | void zfree(void *x, void *addr, unsigned nb) | ||
264 | { | ||
265 | struct memchunk *mp = addr; | ||
266 | |||
267 | nb = _ALIGN(nb, sizeof(struct memchunk)); | ||
268 | heap_use -= nb; | ||
269 | if (avail_ram == addr + nb) { | ||
270 | avail_ram = addr; | ||
271 | return; | ||
272 | } | ||
273 | mp->size = nb; | ||
274 | mp->next = freechunks; | ||
275 | freechunks = mp; | ||
276 | } | ||
277 | |||
278 | #define HEAD_CRC 2 | 218 | #define HEAD_CRC 2 |
279 | #define EXTRA_FIELD 4 | 219 | #define EXTRA_FIELD 4 |
280 | #define ORIG_NAME 8 | 220 | #define ORIG_NAME 8 |
281 | #define COMMENT 0x10 | 221 | #define COMMENT 0x10 |
282 | #define RESERVED 0xe0 | 222 | #define RESERVED 0xe0 |
283 | 223 | ||
284 | #define DEFLATED 8 | ||
285 | |||
286 | static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) | 224 | static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) |
287 | { | 225 | { |
288 | z_stream s; | 226 | z_stream s; |
@@ -291,7 +229,7 @@ static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) | |||
291 | /* skip header */ | 229 | /* skip header */ |
292 | i = 10; | 230 | i = 10; |
293 | flags = src[3]; | 231 | flags = src[3]; |
294 | if (src[2] != DEFLATED || (flags & RESERVED) != 0) { | 232 | if (src[2] != Z_DEFLATED || (flags & RESERVED) != 0) { |
295 | printf("bad gzipped data\n\r"); | 233 | printf("bad gzipped data\n\r"); |
296 | exit(); | 234 | exit(); |
297 | } | 235 | } |
@@ -310,9 +248,13 @@ static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) | |||
310 | exit(); | 248 | exit(); |
311 | } | 249 | } |
312 | 250 | ||
313 | s.zalloc = zalloc; | 251 | if (zlib_inflate_workspacesize() > sizeof(scratch)) { |
314 | s.zfree = zfree; | 252 | printf("gunzip needs more mem\n"); |
315 | r = inflateInit2(&s, -MAX_WBITS); | 253 | exit(); |
254 | } | ||
255 | memset(&s, 0, sizeof(s)); | ||
256 | s.workspace = scratch; | ||
257 | r = zlib_inflateInit2(&s, -MAX_WBITS); | ||
316 | if (r != Z_OK) { | 258 | if (r != Z_OK) { |
317 | printf("inflateInit2 returned %d\n\r", r); | 259 | printf("inflateInit2 returned %d\n\r", r); |
318 | exit(); | 260 | exit(); |
@@ -321,12 +263,12 @@ static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) | |||
321 | s.avail_in = *lenp - i; | 263 | s.avail_in = *lenp - i; |
322 | s.next_out = dst; | 264 | s.next_out = dst; |
323 | s.avail_out = dstlen; | 265 | s.avail_out = dstlen; |
324 | r = inflate(&s, Z_FINISH); | 266 | r = zlib_inflate(&s, Z_FINISH); |
325 | if (r != Z_OK && r != Z_STREAM_END) { | 267 | if (r != Z_OK && r != Z_STREAM_END) { |
326 | printf("inflate returned %d msg: %s\n\r", r, s.msg); | 268 | printf("inflate returned %d msg: %s\n\r", r, s.msg); |
327 | exit(); | 269 | exit(); |
328 | } | 270 | } |
329 | *lenp = s.next_out - (unsigned char *) dst; | 271 | *lenp = s.next_out - (unsigned char *) dst; |
330 | inflateEnd(&s); | 272 | zlib_inflateEnd(&s); |
331 | } | 273 | } |
332 | 274 | ||