Skip to content

Commit df8ce25

Browse files
committed
sh: Tidy up gzip-based zImage decompression.
This brings the zImage handling in to the current century, in preparation for handling the other compression types. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent f686d8c commit df8ce25

3 files changed

Lines changed: 19 additions & 215 deletions

File tree

‎arch/sh/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ config SUPERH
1717
select HAVE_ARCH_TRACEHOOK
1818
select HAVE_DMA_API_DEBUG
1919
select HAVE_PERF_COUNTERS
20+
select HAVE_KERNEL_GZIP
2021
select RTC_LIB
2122
select GENERIC_ATOMIC64
2223
help

‎arch/sh/boot/compressed/misc_32.c‎

Lines changed: 11 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -14,73 +14,23 @@
1414
#include <asm/uaccess.h>
1515
#include <asm/addrspace.h>
1616
#include <asm/page.h>
17-
#ifdef CONFIG_SH_STANDARD_BIOS
1817
#include <asm/sh_bios.h>
19-
#endif
2018

2119
/*
2220
* gzip declarations
2321
*/
2422

25-
#define OF(args) args
2623
#define STATIC static
2724

2825
#undef memset
2926
#undef memcpy
3027
#define memzero(s, n) memset ((s), 0, (n))
3128

32-
typedef unsigned char uch;
33-
typedef unsigned short ush;
34-
typedef unsigned long ulg;
35-
36-
#define WSIZE 0x8000 /* Window size must be at least 32k, */
37-
/* and a power of two */
38-
39-
static uch *inbuf; /* input buffer */
40-
static uch window[WSIZE]; /* Sliding window buffer */
41-
42-
static unsigned insize = 0; /* valid bytes in inbuf */
43-
static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
44-
static unsigned outcnt = 0; /* bytes in output buffer */
45-
46-
/* gzip flag byte */
47-
#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
48-
#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
49-
#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
50-
#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
51-
#define COMMENT 0x10 /* bit 4 set: file comment present */
52-
#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
53-
#define RESERVED 0xC0 /* bit 6,7: reserved */
54-
55-
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
56-
57-
/* Diagnostic functions */
58-
#ifdef DEBUG
59-
# define Assert(cond,msg) {if(!(cond)) error(msg);}
60-
# define Trace(x) fprintf x
61-
# define Tracev(x) {if (verbose) fprintf x ;}
62-
# define Tracevv(x) {if (verbose>1) fprintf x ;}
63-
# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
64-
# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
65-
#else
66-
# define Assert(cond,msg)
67-
# define Trace(x)
68-
# define Tracev(x)
69-
# define Tracevv(x)
70-
# define Tracec(c,x)
71-
# define Tracecv(c,x)
72-
#endif
73-
74-
static int fill_inbuf(void);
75-
static void flush_window(void);
7629
static void error(char *m);
7730

7831
extern char input_data[];
7932
extern int input_len;
80-
81-
static long bytes_out = 0;
82-
static uch *output_data;
83-
static unsigned long output_ptr = 0;
33+
static unsigned char *output;
8434

8535
static void error(char *m);
8636

@@ -93,7 +43,9 @@ static unsigned long free_mem_end_ptr;
9343

9444
#define HEAP_SIZE 0x10000
9545

96-
#include "../../../../lib/inflate.c"
46+
#ifdef CONFIG_KERNEL_GZIP
47+
#include "../../../../lib/decompress_inflate.c"
48+
#endif
9749

9850
#ifdef CONFIG_SH_STANDARD_BIOS
9951
size_t strlen(const char *s)
@@ -138,44 +90,6 @@ void* memcpy(void* __dest, __const void* __src,
13890
return __dest;
13991
}
14092

141-
/* ===========================================================================
142-
* Fill the input buffer. This is called only when the buffer is empty
143-
* and at least one byte is really needed.
144-
*/
145-
static int fill_inbuf(void)
146-
{
147-
if (insize != 0) {
148-
error("ran out of input data");
149-
}
150-
151-
inbuf = input_data;
152-
insize = input_len;
153-
inptr = 1;
154-
return inbuf[0];
155-
}
156-
157-
/* ===========================================================================
158-
* Write the output window window[0..outcnt-1] and update crc and bytes_out.
159-
* (Used for the decompressed data only.)
160-
*/
161-
static void flush_window(void)
162-
{
163-
ulg c = crc; /* temporary variable */
164-
unsigned n;
165-
uch *in, *out, ch;
166-
167-
in = window;
168-
out = &output_data[output_ptr];
169-
for (n = 0; n < outcnt; n++) {
170-
ch = *out++ = *in++;
171-
c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
172-
}
173-
crc = c;
174-
bytes_out += (ulg)outcnt;
175-
output_ptr += (ulg)outcnt;
176-
outcnt = 0;
177-
}
178-
17993
static void error(char *x)
18094
{
18195
puts("\n\n");
@@ -191,16 +105,18 @@ long* stack_start = &user_stack[STACK_SIZE];
191105

192106
void decompress_kernel(void)
193107
{
194-
output_data = NULL;
195-
output_ptr = PHYSADDR((unsigned long)&_text+PAGE_SIZE);
108+
unsigned long output_addr;
109+
110+
output_addr = PHYSADDR((unsigned long)&_text+PAGE_SIZE);
196111
#ifdef CONFIG_29BIT
197-
output_ptr |= P2SEG;
112+
output_addr |= P2SEG;
198113
#endif
114+
115+
output = (unsigned char *)output_addr;
199116
free_mem_ptr = (unsigned long)&_end;
200117
free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
201118

202-
makecrc();
203119
puts("Uncompressing Linux... ");
204-
gunzip();
120+
decompress(input_data, input_len, NULL, NULL, output, NULL, error);
205121
puts("Ok, booting the kernel.\n");
206122
}

‎arch/sh/boot/compressed/misc_64.c‎

Lines changed: 7 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -20,67 +20,18 @@ int cache_control(unsigned int command);
2020
* gzip declarations
2121
*/
2222

23-
#define OF(args) args
2423
#define STATIC static
2524

2625
#undef memset
2726
#undef memcpy
2827
#define memzero(s, n) memset ((s), 0, (n))
2928

30-
typedef unsigned char uch;
31-
typedef unsigned short ush;
32-
typedef unsigned long ulg;
33-
34-
#define WSIZE 0x8000 /* Window size must be at least 32k, */
35-
/* and a power of two */
36-
37-
static uch *inbuf; /* input buffer */
38-
static uch window[WSIZE]; /* Sliding window buffer */
39-
40-
static unsigned insize = 0; /* valid bytes in inbuf */
41-
static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
42-
static unsigned outcnt = 0; /* bytes in output buffer */
43-
44-
/* gzip flag byte */
45-
#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
46-
#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
47-
#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
48-
#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
49-
#define COMMENT 0x10 /* bit 4 set: file comment present */
50-
#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
51-
#define RESERVED 0xC0 /* bit 6,7: reserved */
52-
53-
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
54-
55-
/* Diagnostic functions */
56-
#ifdef DEBUG
57-
# define Assert(cond,msg) {if(!(cond)) error(msg);}
58-
# define Trace(x) fprintf x
59-
# define Tracev(x) {if (verbose) fprintf x ;}
60-
# define Tracevv(x) {if (verbose>1) fprintf x ;}
61-
# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
62-
# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
63-
#else
64-
# define Assert(cond,msg)
65-
# define Trace(x)
66-
# define Tracev(x)
67-
# define Tracevv(x)
68-
# define Tracec(c,x)
69-
# define Tracecv(c,x)
70-
#endif
71-
72-
static int fill_inbuf(void);
73-
static void flush_window(void);
7429
static void error(char *m);
7530

7631
extern char input_data[];
7732
extern int input_len;
7833

79-
static long bytes_out = 0;
80-
static uch *output_data;
81-
static unsigned long output_ptr = 0;
82-
83-
static void error(char *m);
34+
static unsigned char *output_data;
8435

8536
static void puts(const char *);
8637

@@ -91,7 +42,9 @@ static unsigned long free_mem_end_ptr;
9142

9243
#define HEAP_SIZE 0x10000
9344

94-
#include "../../../../lib/inflate.c"
45+
#ifdef CONFIG_KERNEL_GZIP
46+
#include "../../../../lib/decompress_inflate.c"
47+
#endif
9548

9649
void puts(const char *s)
9750
{
@@ -117,45 +70,6 @@ void *memcpy(void *__dest, __const void *__src, size_t __n)
11770
return __dest;
11871
}
11972

120-
/* ===========================================================================
121-
* Fill the input buffer. This is called only when the buffer is empty
122-
* and at least one byte is really needed.
123-
*/
124-
static int fill_inbuf(void)
125-
{
126-
if (insize != 0) {
127-
error("ran out of input data\n");
128-
}
129-
130-
inbuf = input_data;
131-
insize = input_len;
132-
inptr = 1;
133-
return inbuf[0];
134-
}
135-
136-
/* ===========================================================================
137-
* Write the output window window[0..outcnt-1] and update crc and bytes_out.
138-
* (Used for the decompressed data only.)
139-
*/
140-
static void flush_window(void)
141-
{
142-
ulg c = crc; /* temporary variable */
143-
unsigned n;
144-
uch *in, *out, ch;
145-
146-
in = window;
147-
out = &output_data[output_ptr];
148-
for (n = 0; n < outcnt; n++) {
149-
ch = *out++ = *in++;
150-
c = crc_32_tab[((int) c ^ ch) & 0xff] ^ (c >> 8);
151-
}
152-
crc = c;
153-
bytes_out += (ulg) outcnt;
154-
output_ptr += (ulg) outcnt;
155-
outcnt = 0;
156-
puts(".");
157-
}
158-
15973
static void error(char *x)
16074
{
16175
puts("\n\n");
@@ -171,40 +85,13 @@ long *stack_start = &user_stack[STACK_SIZE];
17185

17286
void decompress_kernel(void)
17387
{
174-
output_data = (uch *) (CONFIG_MEMORY_START + 0x2000);
88+
output_data = (unsigned char *) (CONFIG_MEMORY_START + 0x2000);
17589
free_mem_ptr = (unsigned long) &_end;
17690
free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
17791

178-
makecrc();
17992
puts("Uncompressing Linux... ");
18093
cache_control(CACHE_ENABLE);
181-
gunzip();
182-
puts("\n");
183-
184-
#if 0
185-
/* When booting from ROM may want to do something like this if the
186-
* boot loader doesn't.
187-
*/
188-
189-
/* Set up the parameters and command line */
190-
{
191-
volatile unsigned int *parambase =
192-
(int *) (CONFIG_MEMORY_START + 0x1000);
193-
194-
parambase[0] = 0x1; /* MOUNT_ROOT_RDONLY */
195-
parambase[1] = 0x0; /* RAMDISK_FLAGS */
196-
parambase[2] = 0x0200; /* ORIG_ROOT_DEV */
197-
parambase[3] = 0x0; /* LOADER_TYPE */
198-
parambase[4] = 0x0; /* INITRD_START */
199-
parambase[5] = 0x0; /* INITRD_SIZE */
200-
parambase[6] = 0;
201-
202-
strcpy((char *) ((int) parambase + 0x100),
203-
"console=ttySC0,38400");
204-
}
205-
#endif
206-
207-
puts("Ok, booting the kernel.\n");
208-
94+
decompress(input_data, input_len, NULL, NULL, output_data, NULL, error);
20995
cache_control(CACHE_DISABLE);
96+
puts("Ok, booting the kernel.\n");
21097
}

0 commit comments

Comments
 (0)