aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/ppc64/boot/main.c115
1 files changed, 57 insertions, 58 deletions
diff --git a/arch/ppc64/boot/main.c b/arch/ppc64/boot/main.c
index 7485dcbf80bc..d039c47f8e5a 100644
--- a/arch/ppc64/boot/main.c
+++ b/arch/ppc64/boot/main.c
@@ -17,7 +17,6 @@
17#include "prom.h" 17#include "prom.h"
18#include "zlib.h" 18#include "zlib.h"
19 19
20static void gunzip(void *, int, unsigned char *, int *);
21extern void flush_cache(void *, unsigned long); 20extern void flush_cache(void *, unsigned long);
22 21
23 22
@@ -56,6 +55,63 @@ typedef void (*kernel_entry_t)( unsigned long,
56 55
57static unsigned long claim_base; 56static unsigned long claim_base;
58 57
58#define HEAD_CRC 2
59#define EXTRA_FIELD 4
60#define ORIG_NAME 8
61#define COMMENT 0x10
62#define RESERVED 0xe0
63
64static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
65{
66 z_stream s;
67 int r, i, flags;
68
69 /* skip header */
70 i = 10;
71 flags = src[3];
72 if (src[2] != Z_DEFLATED || (flags & RESERVED) != 0) {
73 printf("bad gzipped data\n\r");
74 exit();
75 }
76 if ((flags & EXTRA_FIELD) != 0)
77 i = 12 + src[10] + (src[11] << 8);
78 if ((flags & ORIG_NAME) != 0)
79 while (src[i++] != 0)
80 ;
81 if ((flags & COMMENT) != 0)
82 while (src[i++] != 0)
83 ;
84 if ((flags & HEAD_CRC) != 0)
85 i += 2;
86 if (i >= *lenp) {
87 printf("gunzip: ran out of data in header\n\r");
88 exit();
89 }
90
91 if (zlib_inflate_workspacesize() > sizeof(scratch)) {
92 printf("gunzip needs more mem\n");
93 exit();
94 }
95 memset(&s, 0, sizeof(s));
96 s.workspace = scratch;
97 r = zlib_inflateInit2(&s, -MAX_WBITS);
98 if (r != Z_OK) {
99 printf("inflateInit2 returned %d\n\r", r);
100 exit();
101 }
102 s.next_in = src + i;
103 s.avail_in = *lenp - i;
104 s.next_out = dst;
105 s.avail_out = dstlen;
106 r = zlib_inflate(&s, Z_FULL_FLUSH);
107 if (r != Z_OK && r != Z_STREAM_END) {
108 printf("inflate returned %d msg: %s\n\r", r, s.msg);
109 exit();
110 }
111 *lenp = s.next_out - (unsigned char *) dst;
112 zlib_inflateEnd(&s);
113}
114
59static unsigned long try_claim(unsigned long size) 115static unsigned long try_claim(unsigned long size)
60{ 116{
61 unsigned long addr = 0; 117 unsigned long addr = 0;
@@ -213,60 +269,3 @@ void start(unsigned long a1, unsigned long a2, void *promptr)
213 exit(); 269 exit();
214} 270}
215 271
216#define HEAD_CRC 2
217#define EXTRA_FIELD 4
218#define ORIG_NAME 8
219#define COMMENT 0x10
220#define RESERVED 0xe0
221
222static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
223{
224 z_stream s;
225 int r, i, flags;
226
227 /* skip header */
228 i = 10;
229 flags = src[3];
230 if (src[2] != Z_DEFLATED || (flags & RESERVED) != 0) {
231 printf("bad gzipped data\n\r");
232 exit();
233 }
234 if ((flags & EXTRA_FIELD) != 0)
235 i = 12 + src[10] + (src[11] << 8);
236 if ((flags & ORIG_NAME) != 0)
237 while (src[i++] != 0)
238 ;
239 if ((flags & COMMENT) != 0)
240 while (src[i++] != 0)
241 ;
242 if ((flags & HEAD_CRC) != 0)
243 i += 2;
244 if (i >= *lenp) {
245 printf("gunzip: ran out of data in header\n\r");
246 exit();
247 }
248
249 if (zlib_inflate_workspacesize() > sizeof(scratch)) {
250 printf("gunzip needs more mem\n");
251 exit();
252 }
253 memset(&s, 0, sizeof(s));
254 s.workspace = scratch;
255 r = zlib_inflateInit2(&s, -MAX_WBITS);
256 if (r != Z_OK) {
257 printf("inflateInit2 returned %d\n\r", r);
258 exit();
259 }
260 s.next_in = src + i;
261 s.avail_in = *lenp - i;
262 s.next_out = dst;
263 s.avail_out = dstlen;
264 r = zlib_inflate(&s, Z_FULL_FLUSH);
265 if (r != Z_OK && r != Z_STREAM_END) {
266 printf("inflate returned %d msg: %s\n\r", r, s.msg);
267 exit();
268 }
269 *lenp = s.next_out - (unsigned char *) dst;
270 zlib_inflateEnd(&s);
271}
272