2004-02-15 20:46:45 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
|
|
|
|
#include "console.h"
|
|
|
|
#include "uncompress.h"
|
|
|
|
#include "misc.h"
|
|
|
|
|
2004-06-01 22:00:21 +00:00
|
|
|
unsigned long kernel_image_start;
|
|
|
|
unsigned long kernel_image_size;
|
|
|
|
|
2004-02-15 20:46:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* gzip declarations
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define OF(args) args
|
|
|
|
|
|
|
|
typedef unsigned char uch;
|
|
|
|
typedef unsigned short ush;
|
|
|
|
typedef unsigned long ulg;
|
|
|
|
|
|
|
|
#define WSIZE 0x8000 /* Window size must be at least 32k, */
|
|
|
|
/* and a power of two */
|
|
|
|
|
|
|
|
static long bytes_out = 0;
|
|
|
|
|
2004-05-25 23:30:31 +00:00
|
|
|
static uch *inbuf; /* input buffer */
|
|
|
|
static uch window[WSIZE]; /* Sliding window buffer */
|
2004-02-15 20:46:45 +00:00
|
|
|
|
2004-05-25 23:30:31 +00:00
|
|
|
static unsigned insize; /* valid bytes in inbuf */
|
|
|
|
static unsigned inptr; /* index of next byte to be processed in inbuf */
|
2004-02-15 20:46:45 +00:00
|
|
|
static unsigned outcnt = 0; /* bytes in output buffer */
|
|
|
|
|
|
|
|
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
|
|
|
|
|
2004-05-25 23:30:31 +00:00
|
|
|
static uch *output_data;
|
2004-02-15 20:46:45 +00:00
|
|
|
static unsigned long output_ptr = 0;
|
|
|
|
|
|
|
|
#define Assert(cond,msg)
|
|
|
|
#define Trace(x)
|
|
|
|
#define Tracev(x)
|
|
|
|
#define Tracevv(x)
|
|
|
|
#define Tracec(c,x)
|
|
|
|
#define Tracecv(c,x)
|
|
|
|
|
|
|
|
#define memzero(s, n) memset ((s), 0, (n))
|
|
|
|
|
|
|
|
static int fill_inbuf(void)
|
|
|
|
{
|
2004-06-01 22:00:21 +00:00
|
|
|
inbuf = (uch*)kernel_image_start;
|
|
|
|
insize = kernel_image_size;
|
2004-02-15 20:46:45 +00:00
|
|
|
inptr = 1;
|
|
|
|
return inbuf[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gzip_mark(void **ptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gzip_release(void **ptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flush_window(void);
|
|
|
|
|
|
|
|
#define STATIC
|
|
|
|
#include "inflate.c"
|
|
|
|
|
|
|
|
static void flush_window(void)
|
|
|
|
{
|
|
|
|
ulg c = crc; /* temporary variable */
|
|
|
|
unsigned n;
|
|
|
|
uch *in, *out, ch;
|
|
|
|
|
|
|
|
in = window;
|
|
|
|
out = output_data + output_ptr;
|
|
|
|
for (n = 0; n < outcnt; n++) {
|
|
|
|
ch = *out++ = *in++;
|
|
|
|
c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
|
|
|
|
}
|
|
|
|
crc = c;
|
|
|
|
bytes_out += (ulg)outcnt;
|
|
|
|
output_ptr += (ulg)outcnt;
|
|
|
|
outcnt = 0;
|
|
|
|
|
|
|
|
console_put('.');
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long uncompress(char* buf)
|
|
|
|
{
|
|
|
|
output_data = buf;
|
2004-06-01 22:00:21 +00:00
|
|
|
|
2004-02-15 20:46:45 +00:00
|
|
|
makecrc();
|
|
|
|
printf("Uncompressing kernel to %p", buf);
|
|
|
|
gunzip();
|
|
|
|
|
|
|
|
return (unsigned long)output_data - (unsigned long)buf;
|
|
|
|
}
|