Skip to content

Commit

Permalink
bzip2/lzma: library support for gzip, bzip2 and lzma decompression
Browse files Browse the repository at this point in the history
Impact: Replaces inflate.c with a wrapper around zlib_inflate; new library code

This is the first part of the bzip2/lzma patch

The bzip patch is based on an idea by Christian Ludwig, includes support for
compressing the kernel with bzip2 or lzma rather than gzip. Both
compressors give smaller sizes than gzip.  Lzma's decompresses faster
than bzip2.

It also supports ramdisks and initramfs' compressed using these two
compressors.

The functionality has been successfully used for a couple of years by
the udpcast project

This version applies to "tip" kernel 2.6.28

This part contains:
- changed inflate.c to accomodate rest of patch
- implementation of bzip2 compression (not used at this stage yet)
- implementation of lzma compression (not used at this stage yet)
- Makefile routines to support bzip2 and lzma kernel compression

Signed-off-by: Alain Knaff <[email protected]>
Signed-off-by: H. Peter Anvin <[email protected]>
  • Loading branch information
Alain Knaff authored and H. Peter Anvin committed Jan 4, 2009
1 parent 7d3b56b commit bc22c17
Show file tree
Hide file tree
Showing 12 changed files with 1,733 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/linux/decompress/bunzip2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef DECOMPRESS_BUNZIP2_H
#define DECOMPRESS_BUNZIP2_H

int bunzip2(unsigned char *inbuf, int len,
int(*fill)(void*, unsigned int),
int(*flush)(void*, unsigned int),
unsigned char *output,
int *pos,
void(*error)(char *x));
#endif
30 changes: 30 additions & 0 deletions include/linux/decompress/generic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef DECOMPRESS_GENERIC_H
#define DECOMPRESS_GENERIC_H

/* Minimal chunksize to be read.
*Bzip2 prefers at least 4096
*Lzma prefers 0x10000 */
#define COMPR_IOBUF_SIZE 4096

typedef int (*decompress_fn) (unsigned char *inbuf, int len,
int(*fill)(void*, unsigned int),
int(*writebb)(void*, unsigned int),
unsigned char *output,
int *posp,
void(*error)(char *x));

/* inbuf - input buffer
*len - len of pre-read data in inbuf
*fill - function to fill inbuf if empty
*writebb - function to write out outbug
*posp - if non-null, input position (number of bytes read) will be
* returned here
*
*If len != 0, the inbuf is initialized (with as much data), and fill
*should not be called
*If len = 0, the inbuf is allocated, but empty. Its size is IOBUF_SIZE
*fill should be called (repeatedly...) to read data, at most IOBUF_SIZE
*/


#endif
13 changes: 13 additions & 0 deletions include/linux/decompress/inflate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef INFLATE_H
#define INFLATE_H

/* Other housekeeping constants */
#define INBUFSIZ 4096

int gunzip(unsigned char *inbuf, int len,
int(*fill)(void*, unsigned int),
int(*flush)(void*, unsigned int),
unsigned char *output,
int *pos,
void(*error_fn)(char *x));
#endif
87 changes: 87 additions & 0 deletions include/linux/decompress/mm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* linux/compr_mm.h
*
* Memory management for pre-boot and ramdisk uncompressors
*
* Authors: Alain Knaff <[email protected]>
*
*/

#ifndef DECOMPR_MM_H
#define DECOMPR_MM_H

#ifdef STATIC

/* Code active when included from pre-boot environment: */

/* A trivial malloc implementation, adapted from
* malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
*/
static unsigned long malloc_ptr;
static int malloc_count;

static void *malloc(int size)
{
void *p;

if (size < 0)
error("Malloc error");
if (!malloc_ptr)
malloc_ptr = free_mem_ptr;

malloc_ptr = (malloc_ptr + 3) & ~3; /* Align */

p = (void *)malloc_ptr;
malloc_ptr += size;

if (free_mem_end_ptr && malloc_ptr >= free_mem_end_ptr)
error("Out of memory");

malloc_count++;
return p;
}

static void free(void *where)
{
malloc_count--;
if (!malloc_count)
malloc_ptr = free_mem_ptr;
}

#define large_malloc(a) malloc(a)
#define large_free(a) free(a)

#define set_error_fn(x)

#define INIT

#else /* STATIC */

/* Code active when compiled standalone for use when loading ramdisk: */

#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/string.h>
#include <linux/vmalloc.h>

/* Use defines rather than static inline in order to avoid spurious
* warnings when not needed (indeed large_malloc / large_free are not
* needed by inflate */

#define malloc(a) kmalloc(a, GFP_KERNEL)
#define free(a) kfree(a)

#define large_malloc(a) vmalloc(a)
#define large_free(a) vfree(a)

static void(*error)(char *m);
#define set_error_fn(x) error = x;

#define INIT __init
#define STATIC

#include <linux/init.h>

#endif /* STATIC */

#endif /* DECOMPR_MM_H */
12 changes: 12 additions & 0 deletions include/linux/decompress/unlzma.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef DECOMPRESS_UNLZMA_H
#define DECOMPRESS_UNLZMA_H

int unlzma(unsigned char *, int,
int(*fill)(void*, unsigned int),
int(*flush)(void*, unsigned int),
unsigned char *output,
int *posp,
void(*error)(char *x)
);

#endif
Loading

0 comments on commit bc22c17

Please sign in to comment.