2 * (C) Copyright 2000-2006
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #include <u-boot/zlib.h>
31 #define ZALLOC_ALIGNMENT 16
39 void *zalloc(void *, unsigned, unsigned);
40 void zfree(void *, void *, unsigned);
42 void *zalloc(void *x, unsigned items, unsigned size)
47 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
54 void zfree(void *x, void *addr, unsigned nb)
59 int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
66 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
67 puts ("Error: Bad gzipped data\n");
70 if ((flags & EXTRA_FIELD) != 0)
71 i = 12 + src[10] + (src[11] << 8);
72 if ((flags & ORIG_NAME) != 0)
75 if ((flags & COMMENT) != 0)
78 if ((flags & HEAD_CRC) != 0)
81 puts ("Error: gunzip out of data in header\n");
85 return zunzip(dst, dstlen, src, lenp, 1, i);
89 * Uncompress blocks compressed with zlib without headers
91 int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
92 int stoponerr, int offset)
99 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
100 s.outcb = (cb_func)WATCHDOG_RESET;
103 #endif /* CONFIG_HW_WATCHDOG */
105 r = inflateInit2(&s, -MAX_WBITS);
107 printf ("Error: inflateInit2() returned %d\n", r);
110 s.next_in = src + offset;
111 s.avail_in = *lenp - offset;
113 s.avail_out = dstlen;
114 r = inflate(&s, Z_FINISH);
115 if ((r != Z_STREAM_END) && (stoponerr==1)) {
116 printf ("Error: inflate() returned %d\n", r);
120 *lenp = s.next_out - (unsigned char *) dst;