Linux Audio

Check our new training course

Loading...
v4.6
 
  1/*
  2 * misc.c
  3 * 
  4 * This is a collection of several routines from gzip-1.0.3 
  5 * adapted for Linux.
  6 *
  7 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
  8 *
  9 * Modified for ARM Linux by Russell King
 10 *
 11 * Nicolas Pitre <nico@visuaide.com>  1999/04/14 :
 12 *  For this code to run directly from Flash, all constant variables must
 13 *  be marked with 'const' and all other variables initialized at run-time 
 14 *  only.  This way all non constant variables will end up in the bss segment,
 15 *  which should point to addresses in RAM and cleared to 0 on start.
 16 *  This allows for a much quicker boot time.
 17 *
 18 * Modified for Alpha, from the ARM version, by Jay Estabrook 2003.
 19 */
 20
 21#include <linux/kernel.h>
 22#include <linux/slab.h>
 23
 24#include <asm/uaccess.h>
 25
 26#define memzero(s,n)	memset ((s),0,(n))
 27#define puts		srm_printk
 28extern long srm_printk(const char *, ...)
 29     __attribute__ ((format (printf, 1, 2)));
 30
 31/*
 32 * gzip delarations
 33 */
 34#define OF(args)  args
 35#define STATIC static
 36
 37typedef unsigned char  uch;
 38typedef unsigned short ush;
 39typedef unsigned long  ulg;
 40
 41#define WSIZE 0x8000		/* Window size must be at least 32k, */
 42				/* and a power of two */
 43
 44static uch *inbuf;		/* input buffer */
 45static uch *window;		/* Sliding window buffer */
 46
 47static unsigned insize;		/* valid bytes in inbuf */
 48static unsigned inptr;		/* index of next byte to be processed in inbuf */
 49static unsigned outcnt;		/* bytes in output buffer */
 50
 51/* gzip flag byte */
 52#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
 53#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
 54#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
 55#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
 56#define COMMENT      0x10 /* bit 4 set: file comment present */
 57#define ENCRYPTED    0x20 /* bit 5 set: file is encrypted */
 58#define RESERVED     0xC0 /* bit 6,7:   reserved */
 59
 60#define get_byte()  (inptr < insize ? inbuf[inptr++] : fill_inbuf())
 61
 62/* Diagnostic functions */
 63#ifdef DEBUG
 64#  define Assert(cond,msg) {if(!(cond)) error(msg);}
 65#  define Trace(x) fprintf x
 66#  define Tracev(x) {if (verbose) fprintf x ;}
 67#  define Tracevv(x) {if (verbose>1) fprintf x ;}
 68#  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
 69#  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
 70#else
 71#  define Assert(cond,msg)
 72#  define Trace(x)
 73#  define Tracev(x)
 74#  define Tracevv(x)
 75#  define Tracec(c,x)
 76#  define Tracecv(c,x)
 77#endif
 78
 79static int  fill_inbuf(void);
 80static void flush_window(void);
 81static void error(char *m);
 82
 83static char *input_data;
 84static int  input_data_size;
 85
 86static uch *output_data;
 87static ulg output_ptr;
 88static ulg bytes_out;
 89
 90static void error(char *m);
 91static void gzip_mark(void **);
 92static void gzip_release(void **);
 93
 94extern int end;
 95static ulg free_mem_ptr;
 96static ulg free_mem_end_ptr;
 97
 98#define HEAP_SIZE 0x3000
 99
100#include "../../../lib/inflate.c"
101
102/* ===========================================================================
103 * Fill the input buffer. This is called only when the buffer is empty
104 * and at least one byte is really needed.
105 */
106int fill_inbuf(void)
107{
108	if (insize != 0)
109		error("ran out of input data");
110
111	inbuf = input_data;
112	insize = input_data_size;
113
114	inptr = 1;
115	return inbuf[0];
116}
117
118/* ===========================================================================
119 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
120 * (Used for the decompressed data only.)
121 */
122void flush_window(void)
123{
124	ulg c = crc;
125	unsigned n;
126	uch *in, *out, ch;
127
128	in = window;
129	out = &output_data[output_ptr];
130	for (n = 0; n < outcnt; n++) {
131		ch = *out++ = *in++;
132		c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
133	}
134	crc = c;
135	bytes_out += (ulg)outcnt;
136	output_ptr += (ulg)outcnt;
137	outcnt = 0;
138/*	puts("."); */
139}
140
141static void error(char *x)
142{
143	puts("\n\n");
144	puts(x);
145	puts("\n\n -- System halted");
146
147	while(1);	/* Halt */
148}
149
150unsigned int
151decompress_kernel(void *output_start,
152		  void *input_start,
153		  size_t ksize,
154		  size_t kzsize)
155{
156	output_data		= (uch *)output_start;
157	input_data		= (uch *)input_start;
158	input_data_size		= kzsize; /* use compressed size */
159
160	/* FIXME FIXME FIXME */
161	free_mem_ptr		= (ulg)output_start + ksize;
162	free_mem_end_ptr	= (ulg)output_start + ksize + 0x200000;
163	/* FIXME FIXME FIXME */
164
165	/* put in temp area to reduce initial footprint */
166	window = malloc(WSIZE);
167
168	makecrc();
169/*	puts("Uncompressing Linux..."); */
170	gunzip();
171/*	puts(" done, booting the kernel.\n"); */
172	return output_ptr;
173}
v6.2
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * misc.c
  4 * 
  5 * This is a collection of several routines from gzip-1.0.3 
  6 * adapted for Linux.
  7 *
  8 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
  9 *
 10 * Modified for ARM Linux by Russell King
 11 *
 12 * Nicolas Pitre <nico@visuaide.com>  1999/04/14 :
 13 *  For this code to run directly from Flash, all constant variables must
 14 *  be marked with 'const' and all other variables initialized at run-time 
 15 *  only.  This way all non constant variables will end up in the bss segment,
 16 *  which should point to addresses in RAM and cleared to 0 on start.
 17 *  This allows for a much quicker boot time.
 18 *
 19 * Modified for Alpha, from the ARM version, by Jay Estabrook 2003.
 20 */
 21
 22#include <linux/kernel.h>
 23#include <linux/slab.h>
 24
 25#include <linux/uaccess.h>
 26
 27#define memzero(s,n)	memset ((s),0,(n))
 28#define puts		srm_printk
 29extern long srm_printk(const char *, ...)
 30     __attribute__ ((format (printf, 1, 2)));
 31
 32/*
 33 * gzip declarations
 34 */
 35#define OF(args)  args
 36#define STATIC static
 37
 38typedef unsigned char  uch;
 39typedef unsigned short ush;
 40typedef unsigned long  ulg;
 41
 42#define WSIZE 0x8000		/* Window size must be at least 32k, */
 43				/* and a power of two */
 44
 45static uch *inbuf;		/* input buffer */
 46static uch *window;		/* Sliding window buffer */
 47
 48static unsigned insize;		/* valid bytes in inbuf */
 49static unsigned inptr;		/* index of next byte to be processed in inbuf */
 50static unsigned outcnt;		/* bytes in output buffer */
 51
 52/* gzip flag byte */
 53#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
 54#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
 55#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
 56#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
 57#define COMMENT      0x10 /* bit 4 set: file comment present */
 58#define ENCRYPTED    0x20 /* bit 5 set: file is encrypted */
 59#define RESERVED     0xC0 /* bit 6,7:   reserved */
 60
 61#define get_byte()  (inptr < insize ? inbuf[inptr++] : fill_inbuf())
 62
 63/* Diagnostic functions */
 64#ifdef DEBUG
 65#  define Assert(cond,msg) {if(!(cond)) error(msg);}
 66#  define Trace(x) fprintf x
 67#  define Tracev(x) {if (verbose) fprintf x ;}
 68#  define Tracevv(x) {if (verbose>1) fprintf x ;}
 69#  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
 70#  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
 71#else
 72#  define Assert(cond,msg)
 73#  define Trace(x)
 74#  define Tracev(x)
 75#  define Tracevv(x)
 76#  define Tracec(c,x)
 77#  define Tracecv(c,x)
 78#endif
 79
 80static int  fill_inbuf(void);
 81static void flush_window(void);
 82static void error(char *m);
 83
 84static char *input_data;
 85static int  input_data_size;
 86
 87static uch *output_data;
 88static ulg output_ptr;
 89static ulg bytes_out;
 90
 91static void error(char *m);
 92static void gzip_mark(void **);
 93static void gzip_release(void **);
 94
 95extern int end;
 96static ulg free_mem_ptr;
 97static ulg free_mem_end_ptr;
 98
 99#define HEAP_SIZE 0x3000
100
101#include "../../../lib/inflate.c"
102
103/* ===========================================================================
104 * Fill the input buffer. This is called only when the buffer is empty
105 * and at least one byte is really needed.
106 */
107int fill_inbuf(void)
108{
109	if (insize != 0)
110		error("ran out of input data");
111
112	inbuf = input_data;
113	insize = input_data_size;
114
115	inptr = 1;
116	return inbuf[0];
117}
118
119/* ===========================================================================
120 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
121 * (Used for the decompressed data only.)
122 */
123void flush_window(void)
124{
125	ulg c = crc;
126	unsigned n;
127	uch *in, *out, ch;
128
129	in = window;
130	out = &output_data[output_ptr];
131	for (n = 0; n < outcnt; n++) {
132		ch = *out++ = *in++;
133		c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
134	}
135	crc = c;
136	bytes_out += (ulg)outcnt;
137	output_ptr += (ulg)outcnt;
138	outcnt = 0;
139/*	puts("."); */
140}
141
142static void error(char *x)
143{
144	puts("\n\n");
145	puts(x);
146	puts("\n\n -- System halted");
147
148	while(1);	/* Halt */
149}
150
151unsigned int
152decompress_kernel(void *output_start,
153		  void *input_start,
154		  size_t ksize,
155		  size_t kzsize)
156{
157	output_data		= (uch *)output_start;
158	input_data		= (uch *)input_start;
159	input_data_size		= kzsize; /* use compressed size */
160
161	/* FIXME FIXME FIXME */
162	free_mem_ptr		= (ulg)output_start + ksize;
163	free_mem_end_ptr	= (ulg)output_start + ksize + 0x200000;
164	/* FIXME FIXME FIXME */
165
166	/* put in temp area to reduce initial footprint */
167	window = malloc(WSIZE);
168
169	makecrc();
170/*	puts("Uncompressing Linux..."); */
171	gunzip();
172/*	puts(" done, booting the kernel.\n"); */
173	return output_ptr;
174}