Commit 69597547 authored by Tom Rini's avatar Tom Rini Committed by Linus Torvalds

[PATCH] ppc32: Switch arch/ppc/boot to lib/zlib_inflate

The following patch switches arch/ppc/boot over from using its own version
of zlib to the code found under lib/zlib_inflate.  In conjunction with the
previous two patches, the size of the resulting images isn't noticably
different.  But this does have the advantage of removing another copy of
zlib from the kernel, and I believe this allows for lib/inflate.c to go
away (as that's basically what ppc used to use).
Signed-off-by: default avatarTom Rini <trini@kernel.crashing.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent f65296a0
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <stdarg.h> /* for va_ bits */ #include <stdarg.h> /* for va_ bits */
#include <linux/config.h> #include <linux/config.h>
#include <linux/string.h> #include <linux/string.h>
#include "zlib.h" #include <linux/zlib.h>
#include "nonstdio.h" #include "nonstdio.h"
/* If we're on a PReP, assume we have a keyboard controller /* If we're on a PReP, assume we have a keyboard controller
...@@ -202,11 +202,10 @@ void error(char *x) ...@@ -202,11 +202,10 @@ void error(char *x)
while(1); /* Halt */ while(1); /* Halt */
} }
void *zalloc(void *x, unsigned items, unsigned size) static void *zalloc(unsigned size)
{ {
void *p = avail_ram; void *p = avail_ram;
size *= items;
size = (size + 7) & -8; size = (size + 7) & -8;
avail_ram += size; avail_ram += size;
if (avail_ram > end_avail) { if (avail_ram > end_avail) {
...@@ -216,18 +215,12 @@ void *zalloc(void *x, unsigned items, unsigned size) ...@@ -216,18 +215,12 @@ void *zalloc(void *x, unsigned items, unsigned size)
return p; return p;
} }
void zfree(void *x, void *addr, unsigned nb)
{
}
#define HEAD_CRC 2 #define HEAD_CRC 2
#define EXTRA_FIELD 4 #define EXTRA_FIELD 4
#define ORIG_NAME 8 #define ORIG_NAME 8
#define COMMENT 0x10 #define COMMENT 0x10
#define RESERVED 0xe0 #define RESERVED 0xe0
#define DEFLATED 8
void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
{ {
z_stream s; z_stream s;
...@@ -236,7 +229,7 @@ void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) ...@@ -236,7 +229,7 @@ void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
/* skip header */ /* skip header */
i = 10; i = 10;
flags = src[3]; flags = src[3];
if (src[2] != DEFLATED || (flags & RESERVED) != 0) { if (src[2] != Z_DEFLATED || (flags & RESERVED) != 0) {
puts("bad gzipped data\n"); puts("bad gzipped data\n");
exit(); exit();
} }
...@@ -255,24 +248,24 @@ void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) ...@@ -255,24 +248,24 @@ void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
exit(); exit();
} }
s.zalloc = zalloc; /* Initialize ourself. */
s.zfree = zfree; s.workspace = zalloc(zlib_inflate_workspacesize());
r = inflateInit2(&s, -MAX_WBITS); r = zlib_inflateInit2(&s, -MAX_WBITS);
if (r != Z_OK) { if (r != Z_OK) {
puts("inflateInit2 returned "); puthex(r); puts("\n"); puts("zlib_inflateInit2 returned "); puthex(r); puts("\n");
exit(); exit();
} }
s.next_in = src + i; s.next_in = src + i;
s.avail_in = *lenp - i; s.avail_in = *lenp - i;
s.next_out = dst; s.next_out = dst;
s.avail_out = dstlen; s.avail_out = dstlen;
r = inflate(&s, Z_FINISH); r = zlib_inflate(&s, Z_FINISH);
if (r != Z_OK && r != Z_STREAM_END) { if (r != Z_OK && r != Z_STREAM_END) {
puts("inflate returned "); puthex(r); puts("\n"); puts("inflate returned "); puthex(r); puts("\n");
exit(); exit();
} }
*lenp = s.next_out - (unsigned char *) dst; *lenp = s.next_out - (unsigned char *) dst;
inflateEnd(&s); zlib_inflateEnd(&s);
} }
void void
......
This diff is collapsed.
...@@ -4,5 +4,18 @@ ...@@ -4,5 +4,18 @@
CFLAGS_kbd.o += -Idrivers/char CFLAGS_kbd.o += -Idrivers/char
lib-y := zlib.o div64.o $(obj)/infblock.o: lib/zlib_inflate/infblock.c
$(call cmd,cc_o_c)
$(obj)/infcodes.o: lib/zlib_inflate/infcodes.c
$(call cmd,cc_o_c)
$(obj)/inffast.o: lib/zlib_inflate/inffast.c
$(call cmd,cc_o_c)
$(obj)/inflate.o: lib/zlib_inflate/inflate.c
$(call cmd,cc_o_c)
$(obj)/inftrees.o: lib/zlib_inflate/inftrees.c
$(call cmd,cc_o_c)
$(obj)/infutil.o: lib/zlib_inflate/infutil.c
$(call cmd,cc_o_c)
lib-y := infblock.o infcodes.o inffast.o inflate.o inftrees.o infutil.o div64.o
lib-$(CONFIG_VGA_CONSOLE) += vreset.o kbd.o lib-$(CONFIG_VGA_CONSOLE) += vreset.o kbd.o
This diff is collapsed.
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "nonstdio.h" #include "nonstdio.h"
#include "of1275.h" #include "of1275.h"
#include "zlib.h"
/* Passed from the linker */ /* Passed from the linker */
extern char __image_begin, __image_end; extern char __image_begin, __image_end;
......
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
* 2 of the License, or (at your option) any later version. * 2 of the License, or (at your option) any later version.
*/ */
#include "zlib.h"
#include "nonstdio.h" #include "nonstdio.h"
#include "of1275.h" #include "of1275.h"
#include <linux/string.h> #include <linux/string.h>
#include <linux/zlib.h>
#include <asm/bootinfo.h> #include <asm/bootinfo.h>
#include <asm/page.h> #include <asm/page.h>
...@@ -30,12 +30,11 @@ struct memchunk { ...@@ -30,12 +30,11 @@ struct memchunk {
static struct memchunk *freechunks; static struct memchunk *freechunks;
static void *zalloc(void *x, unsigned items, unsigned size) static void *zalloc(unsigned size)
{ {
void *p; void *p;
struct memchunk **mpp, *mp; struct memchunk **mpp, *mp;
size *= items;
size = (size + 7) & -8; size = (size + 7) & -8;
heap_use += size; heap_use += size;
if (heap_use > heap_max) if (heap_use > heap_max)
...@@ -57,29 +56,12 @@ static void *zalloc(void *x, unsigned items, unsigned size) ...@@ -57,29 +56,12 @@ static void *zalloc(void *x, unsigned items, unsigned size)
return p; return p;
} }
static void zfree(void *x, void *addr, unsigned nb)
{
struct memchunk *mp = addr;
nb = (nb + 7) & -8;
heap_use -= nb;
if (avail_ram == addr + nb) {
avail_ram = addr;
return;
}
mp->size = nb;
mp->next = freechunks;
freechunks = mp;
}
#define HEAD_CRC 2 #define HEAD_CRC 2
#define EXTRA_FIELD 4 #define EXTRA_FIELD 4
#define ORIG_NAME 8 #define ORIG_NAME 8
#define COMMENT 0x10 #define COMMENT 0x10
#define RESERVED 0xe0 #define RESERVED 0xe0
#define DEFLATED 8
void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
{ {
z_stream s; z_stream s;
...@@ -88,7 +70,7 @@ void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) ...@@ -88,7 +70,7 @@ void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
/* skip header */ /* skip header */
i = 10; i = 10;
flags = src[3]; flags = src[3];
if (src[2] != DEFLATED || (flags & RESERVED) != 0) { if (src[2] != Z_DEFLATED || (flags & RESERVED) != 0) {
printf("bad gzipped data\n\r"); printf("bad gzipped data\n\r");
exit(); exit();
} }
...@@ -107,24 +89,24 @@ void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) ...@@ -107,24 +89,24 @@ void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
exit(); exit();
} }
s.zalloc = zalloc; /* Initialize ourself. */
s.zfree = zfree; s.workspace = zalloc(zlib_inflate_workspacesize());
r = inflateInit2(&s, -MAX_WBITS); r = zlib_inflateInit2(&s, -MAX_WBITS);
if (r != Z_OK) { if (r != Z_OK) {
printf("inflateInit2 returned %d\n\r", r); printf("zlib_inflateInit2 returned %d\n\r", r);
exit(); exit();
} }
s.next_in = src + i; s.next_in = src + i;
s.avail_in = *lenp - i; s.avail_in = *lenp - i;
s.next_out = dst; s.next_out = dst;
s.avail_out = dstlen; s.avail_out = dstlen;
r = inflate(&s, Z_FINISH); r = zlib_inflate(&s, Z_FINISH);
if (r != Z_OK && r != Z_STREAM_END) { if (r != Z_OK && r != Z_STREAM_END) {
printf("inflate returned %d msg: %s\n\r", r, s.msg); printf("inflate returned %d msg: %s\n\r", r, s.msg);
exit(); exit();
} }
*lenp = s.next_out - (unsigned char *) dst; *lenp = s.next_out - (unsigned char *) dst;
inflateEnd(&s); zlib_inflateEnd(&s);
} }
/* Make a bi_rec in OF. We need to be passed a name for BI_BOOTLOADER_ID, /* Make a bi_rec in OF. We need to be passed a name for BI_BOOTLOADER_ID,
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#endif #endif
#include "nonstdio.h" #include "nonstdio.h"
#include "zlib.h"
/* The linker tells us where the image is. */ /* The linker tells us where the image is. */
extern char __image_begin, __image_end; extern char __image_begin, __image_end;
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include <asm/reg.h> #include <asm/reg.h>
#include "nonstdio.h" #include "nonstdio.h"
#include "zlib.h"
/* Default cmdline */ /* Default cmdline */
#ifdef CONFIG_CMDLINE #ifdef CONFIG_CMDLINE
...@@ -220,7 +219,7 @@ decompress_kernel(unsigned long load_addr, int num_words, unsigned long cksum) ...@@ -220,7 +219,7 @@ decompress_kernel(unsigned long load_addr, int num_words, unsigned long cksum)
puts("\n"); puts("\n");
puts("Uncompressing Linux..."); puts("Uncompressing Linux...");
gunzip(NULL, 0x400000, zimage_start, &zimage_size); gunzip(0x0, 0x400000, zimage_start, &zimage_size);
puts("done.\n"); puts("done.\n");
/* get the bi_rec address */ /* get the bi_rec address */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment