Commit 337214e8 authored by Hirokazu Takata's avatar Hirokazu Takata

m32r: bzip2/lzma kernel compression support

- Support bzip2 and lzma kernel compression for m32r.
- Clean up arch/m32r/boot/compressed/misc.c.
Signed-off-by: default avatarHirokazu Takata <takata@linux-m32r.org>
parent e968b8d4
...@@ -11,6 +11,9 @@ config M32R ...@@ -11,6 +11,9 @@ config M32R
select HAVE_IDE select HAVE_IDE
select HAVE_OPROFILE select HAVE_OPROFILE
select INIT_ALL_POSSIBLE select INIT_ALL_POSSIBLE
select HAVE_KERNEL_GZIP
select HAVE_KERNEL_BZIP2
select HAVE_KERNEL_LZMA
config SBUS config SBUS
bool bool
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
# create a compressed vmlinux image from the original vmlinux # create a compressed vmlinux image from the original vmlinux
# #
targets := vmlinux vmlinux.bin vmlinux.bin.gz head.o misc.o \ targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 \
piggy.o vmlinux.lds vmlinux.bin.lzma head.o misc.o piggy.o vmlinux.lds
OBJECTS = $(obj)/head.o $(obj)/misc.o OBJECTS = $(obj)/head.o $(obj)/misc.o
...@@ -27,6 +27,12 @@ $(obj)/vmlinux.bin: vmlinux FORCE ...@@ -27,6 +27,12 @@ $(obj)/vmlinux.bin: vmlinux FORCE
$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
$(call if_changed,gzip) $(call if_changed,gzip)
$(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE
$(call if_changed,bzip2)
$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
$(call if_changed,lzma)
CFLAGS_misc.o += -fpic CFLAGS_misc.o += -fpic
ifdef CONFIG_MMU ifdef CONFIG_MMU
...@@ -37,5 +43,9 @@ endif ...@@ -37,5 +43,9 @@ endif
OBJCOPYFLAGS += -R .empty_zero_page OBJCOPYFLAGS += -R .empty_zero_page
$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE suffix_$(CONFIG_KERNEL_GZIP) = gz
suffix_$(CONFIG_KERNEL_BZIP2) = bz2
suffix_$(CONFIG_KERNEL_LZMA) = lzma
$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.$(suffix_y) FORCE
$(call if_changed,ld) $(call if_changed,ld)
...@@ -9,140 +9,49 @@ ...@@ -9,140 +9,49 @@
* Adapted for SH by Stuart Menefy, Aug 1999 * Adapted for SH by Stuart Menefy, Aug 1999
* *
* 2003-02-12: Support M32R by Takeo Takahashi * 2003-02-12: Support M32R by Takeo Takahashi
* This is based on arch/sh/boot/compressed/misc.c.
*/ */
#include <linux/string.h>
/* /*
* gzip declarations * gzip declarations
*/ */
#define OF(args) args
#define STATIC static #define STATIC static
#undef memset #undef memset
#undef memcpy #undef memcpy
#define memzero(s, n) memset ((s), 0, (n)) #define memzero(s, n) memset ((s), 0, (n))
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */
static uch *inbuf; /* input buffer */
static uch window[WSIZE]; /* Sliding window buffer */
static unsigned insize = 0; /* valid bytes in inbuf */
static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
static unsigned outcnt = 0; /* bytes in output buffer */
/* gzip flag byte */
#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
#define COMMENT 0x10 /* bit 4 set: file comment present */
#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
#define RESERVED 0xC0 /* bit 6,7: reserved */
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
/* Diagnostic functions */
#ifdef DEBUG
# define Assert(cond,msg) {if(!(cond)) error(msg);}
# define Trace(x) fprintf x
# define Tracev(x) {if (verbose) fprintf x ;}
# define Tracevv(x) {if (verbose>1) fprintf x ;}
# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
#else
# define Assert(cond,msg)
# define Trace(x)
# define Tracev(x)
# define Tracevv(x)
# define Tracec(c,x)
# define Tracecv(c,x)
#endif
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m); static void error(char *m);
static unsigned char *input_data;
static int input_len;
static long bytes_out = 0;
static uch *output_data;
static unsigned long output_ptr = 0;
#include "m32r_sio.c" #include "m32r_sio.c"
static unsigned long free_mem_ptr; static unsigned long free_mem_ptr;
static unsigned long free_mem_end_ptr; static unsigned long free_mem_end_ptr;
#define HEAP_SIZE 0x10000 #ifdef CONFIG_KERNEL_BZIP2
static void *memset(void *s, int c, size_t n)
#include "../../../../lib/inflate.c"
void* memset(void* s, int c, size_t n)
{ {
int i; char *ss = s;
char *ss = (char*)s;
for (i=0;i<n;i++) ss[i] = c; while (n--)
*ss++ = c;
return s; return s;
} }
#endif
void* memcpy(void* __dest, __const void* __src, #ifdef CONFIG_KERNEL_GZIP
size_t __n) #define BOOT_HEAP_SIZE 0x10000
{ #include "../../../../lib/decompress_inflate.c"
int i; #endif
char *d = (char *)__dest, *s = (char *)__src;
for (i=0;i<__n;i++) d[i] = s[i];
return __dest;
}
/* ===========================================================================
* Fill the input buffer. This is called only when the buffer is empty
* and at least one byte is really needed.
*/
static int fill_inbuf(void)
{
if (insize != 0) {
error("ran out of input data");
}
inbuf = input_data;
insize = input_len;
inptr = 1;
return inbuf[0];
}
/* =========================================================================== #ifdef CONFIG_KERNEL_BZIP2
* Write the output window window[0..outcnt-1] and update crc and bytes_out. #define BOOT_HEAP_SIZE 0x400000
* (Used for the decompressed data only.) #include "../../../../lib/decompress_bunzip2.c"
*/ #endif
static void flush_window(void)
{
ulg c = crc; /* temporary variable */
unsigned n;
uch *in, *out, ch;
in = window; #ifdef CONFIG_KERNEL_LZMA
out = &output_data[output_ptr]; #define BOOT_HEAP_SIZE 0x10000
for (n = 0; n < outcnt; n++) { #include "../../../../lib/decompress_unlzma.c"
ch = *out++ = *in++; #endif
c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
}
crc = c;
bytes_out += (ulg)outcnt;
output_ptr += (ulg)outcnt;
outcnt = 0;
}
static void error(char *x) static void error(char *x)
{ {
...@@ -153,20 +62,20 @@ static void error(char *x) ...@@ -153,20 +62,20 @@ static void error(char *x)
while(1); /* Halt */ while(1); /* Halt */
} }
/* return decompressed size */
void void
decompress_kernel(int mmu_on, unsigned char *zimage_data, decompress_kernel(int mmu_on, unsigned char *zimage_data,
unsigned int zimage_len, unsigned long heap) unsigned int zimage_len, unsigned long heap)
{ {
unsigned char *input_data = zimage_data;
int input_len = zimage_len;
unsigned char *output_data;
output_data = (unsigned char *)CONFIG_MEMORY_START + 0x2000 output_data = (unsigned char *)CONFIG_MEMORY_START + 0x2000
+ (mmu_on ? 0x80000000 : 0); + (mmu_on ? 0x80000000 : 0);
free_mem_ptr = heap; free_mem_ptr = heap;
free_mem_end_ptr = free_mem_ptr + HEAP_SIZE; free_mem_end_ptr = free_mem_ptr + BOOT_HEAP_SIZE;
input_data = zimage_data;
input_len = zimage_len;
makecrc(); puts("\nDecompressing Linux... ");
puts("Uncompressing Linux... "); decompress(input_data, input_len, NULL, NULL, output_data, NULL, error);
gunzip(); puts("done.\nBooting the kernel.\n");
puts("Ok, booting the kernel.\n");
} }
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