Commit 7054036f authored by Olaf Hering's avatar Olaf Hering Committed by Paul Mackerras

[PATCH] ppc64 boot: remove zlib

Switch ppc64 to the in-kernel zlib, it has less bugs than the current one.
The code in arch/ppc64/boot is compiled as 32bit, so it can not use the
includes from include/asm.

Copy all zlib related header files and convert them with sed.

Reduce the scratch size to 47k, check possible changes at runtime.
Signed-off-by: default avatarOlaf Hering <olh@suse.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Anton Blanchard <anton@samba.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent 8afe31c9
...@@ -27,10 +27,41 @@ BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc ...@@ -27,10 +27,41 @@ BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc
BOOTLFLAGS := -Ttext 0x00400000 -e _start -T $(srctree)/$(src)/zImage.lds BOOTLFLAGS := -Ttext 0x00400000 -e _start -T $(srctree)/$(src)/zImage.lds
OBJCOPYFLAGS := contents,alloc,load,readonly,data OBJCOPYFLAGS := contents,alloc,load,readonly,data
src-boot := crt0.S string.S prom.c main.c zlib.c imagesize.c div64.S zlib := infblock.c infcodes.c inffast.c inflate.c inftrees.c infutil.c
zlibheader := infblock.h infcodes.h inffast.h inftrees.h infutil.h
zliblinuxheader := zlib.h zconf.h zutil.h
$(addprefix $(obj)/,$(zlib) main.o): $(addprefix $(obj)/,$(zliblinuxheader)) $(addprefix $(obj)/,$(zlibheader))
#$(addprefix $(obj)/,main.o): $(addprefix $(obj)/,zlib.h)
src-boot := crt0.S string.S prom.c main.c imagesize.c div64.S
src-boot += $(zlib)
src-boot := $(addprefix $(obj)/, $(src-boot)) src-boot := $(addprefix $(obj)/, $(src-boot))
obj-boot := $(addsuffix .o, $(basename $(src-boot))) obj-boot := $(addsuffix .o, $(basename $(src-boot)))
BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj)
quiet_cmd_copy_zlib = COPY $@
cmd_copy_zlib = sed "s@__attribute_used__@@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
quiet_cmd_copy_zlibheader = COPY $@
cmd_copy_zlibheader = sed "s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
# stddef.h for NULL
quiet_cmd_copy_zliblinuxheader = COPY $@
cmd_copy_zliblinuxheader = sed "s@<linux/string.h>@\"string.h\"@;s@<linux/kernel.h>@<stddef.h>@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
$(addprefix $(obj)/,$(zlib)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
$(call cmd,copy_zlib)
$(addprefix $(obj)/,$(zlibheader)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
$(call cmd,copy_zlibheader)
$(addprefix $(obj)/,$(zliblinuxheader)): $(obj)/%: $(srctree)/include/linux/%
$(call cmd,copy_zliblinuxheader)
clean-files := $(zlib) $(zlibheader) $(zliblinuxheader)
quiet_cmd_bootcc = BOOTCC $@ quiet_cmd_bootcc = BOOTCC $@
cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $< cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
......
...@@ -26,12 +26,6 @@ extern void flush_cache(void *, unsigned long); ...@@ -26,12 +26,6 @@ extern void flush_cache(void *, unsigned long);
#define RAM_END (512<<20) // Fixme: use OF */ #define RAM_END (512<<20) // Fixme: use OF */
#define ONE_MB 0x100000 #define ONE_MB 0x100000
static char *avail_ram;
static char *begin_avail, *end_avail;
static char *avail_high;
static unsigned int heap_use;
static unsigned int heap_max;
extern char _start[]; extern char _start[];
extern char _end[]; extern char _end[];
extern char _vmlinux_start[]; extern char _vmlinux_start[];
...@@ -50,7 +44,8 @@ static struct addr_range vmlinux = {0, 0, 0}; ...@@ -50,7 +44,8 @@ static struct addr_range vmlinux = {0, 0, 0};
static struct addr_range vmlinuz = {0, 0, 0}; static struct addr_range vmlinuz = {0, 0, 0};
static struct addr_range initrd = {0, 0, 0}; static struct addr_range initrd = {0, 0, 0};
static char scratch[128<<10]; /* 128kB of scratch space for gunzip */ static char scratch[46912]; /* scratch space for gunzip, from zlib_inflate_workspacesize() */
typedef void (*kernel_entry_t)( unsigned long, typedef void (*kernel_entry_t)( unsigned long,
unsigned long, unsigned long,
...@@ -161,17 +156,12 @@ void start(unsigned long a1, unsigned long a2, void *promptr) ...@@ -161,17 +156,12 @@ void start(unsigned long a1, unsigned long a2, void *promptr)
/* Eventually gunzip the kernel */ /* Eventually gunzip the kernel */
if (*(unsigned short *)vmlinuz.addr == 0x1f8b) { if (*(unsigned short *)vmlinuz.addr == 0x1f8b) {
int len; int len;
avail_ram = scratch;
begin_avail = avail_high = avail_ram;
end_avail = scratch + sizeof(scratch);
printf("gunzipping (0x%lx <- 0x%lx:0x%0lx)...", printf("gunzipping (0x%lx <- 0x%lx:0x%0lx)...",
vmlinux.addr, vmlinuz.addr, vmlinuz.addr+vmlinuz.size); vmlinux.addr, vmlinuz.addr, vmlinuz.addr+vmlinuz.size);
len = vmlinuz.size; len = vmlinuz.size;
gunzip((void *)vmlinux.addr, vmlinux.size, gunzip((void *)vmlinux.addr, vmlinux.size,
(unsigned char *)vmlinuz.addr, &len); (unsigned char *)vmlinuz.addr, &len);
printf("done 0x%lx bytes\n\r", len); printf("done 0x%lx bytes\n\r", len);
printf("0x%x bytes of heap consumed, max in use 0x%x\n\r",
(unsigned)(avail_high - begin_avail), heap_max);
} else { } else {
memmove((void *)vmlinux.addr,(void *)vmlinuz.addr,vmlinuz.size); memmove((void *)vmlinux.addr,(void *)vmlinuz.addr,vmlinuz.size);
} }
...@@ -225,64 +215,12 @@ void start(unsigned long a1, unsigned long a2, void *promptr) ...@@ -225,64 +215,12 @@ void start(unsigned long a1, unsigned long a2, void *promptr)
exit(); exit();
} }
struct memchunk {
unsigned int size;
unsigned int pad;
struct memchunk *next;
};
static struct memchunk *freechunks;
void *zalloc(void *x, unsigned items, unsigned size)
{
void *p;
struct memchunk **mpp, *mp;
size *= items;
size = _ALIGN(size, sizeof(struct memchunk));
heap_use += size;
if (heap_use > heap_max)
heap_max = heap_use;
for (mpp = &freechunks; (mp = *mpp) != 0; mpp = &mp->next) {
if (mp->size == size) {
*mpp = mp->next;
return mp;
}
}
p = avail_ram;
avail_ram += size;
if (avail_ram > avail_high)
avail_high = avail_ram;
if (avail_ram > end_avail) {
printf("oops... out of memory\n\r");
pause();
}
return p;
}
void zfree(void *x, void *addr, unsigned nb)
{
struct memchunk *mp = addr;
nb = _ALIGN(nb, sizeof(struct memchunk));
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
static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
{ {
z_stream s; z_stream s;
...@@ -291,7 +229,7 @@ static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) ...@@ -291,7 +229,7 @@ static 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();
} }
...@@ -310,9 +248,13 @@ static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) ...@@ -310,9 +248,13 @@ static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
exit(); exit();
} }
s.zalloc = zalloc; if (zlib_inflate_workspacesize() > sizeof(scratch)) {
s.zfree = zfree; printf("gunzip needs more mem\n");
r = inflateInit2(&s, -MAX_WBITS); exit();
}
memset(&s, 0, sizeof(s));
s.workspace = scratch;
r = zlib_inflateInit2(&s, -MAX_WBITS);
if (r != Z_OK) { if (r != Z_OK) {
printf("inflateInit2 returned %d\n\r", r); printf("inflateInit2 returned %d\n\r", r);
exit(); exit();
...@@ -321,12 +263,12 @@ static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) ...@@ -321,12 +263,12 @@ static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
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);
} }
This diff is collapsed.
This diff is collapsed.
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