SOURCES (LINUX_2_6): kernel-bzip2-lzma.patch (NEW) - support for b...

zbyniu zbyniu at pld-linux.org
Thu Mar 13 01:25:00 CET 2008


Author: zbyniu                       Date: Thu Mar 13 00:25:00 2008 GMT
Module: SOURCES                       Tag: LINUX_2_6
---- Log message:
- support for bzip2/lzma packed kernel/initrd (for rescuecd)
- raw http://www.udpcast.linux.lu/download/bzip2-lzma-kernel-2.6.23.12.patch.gz

---- Files affected:
SOURCES:
   kernel-bzip2-lzma.patch (NONE -> 1.1.2.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/kernel-bzip2-lzma.patch
diff -u /dev/null SOURCES/kernel-bzip2-lzma.patch:1.1.2.1
--- /dev/null	Thu Mar 13 01:25:00 2008
+++ SOURCES/kernel-bzip2-lzma.patch	Thu Mar 13 01:24:55 2008
@@ -0,0 +1,2110 @@
+diff -urN linux-2.6.23.12/arch/i386/boot/compressed/Makefile linux-2.6.23.12udpcast/arch/i386/boot/compressed/Makefile
+--- linux-2.6.23.12/arch/i386/boot/compressed/Makefile	2007-12-18 21:55:57.000000000 +0000
++++ linux-2.6.23.12udpcast/arch/i386/boot/compressed/Makefile	2007-12-27 09:13:47.000000000 +0000
+@@ -4,7 +4,7 @@
+ # create a compressed vmlinux image from the original vmlinux
+ #
+ 
+-targets		:= vmlinux vmlinux.bin vmlinux.bin.gz head.o misc.o piggy.o \
++targets		:= vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma head.o misc.o piggy.o \
+ 			vmlinux.bin.all vmlinux.relocs
+ EXTRA_AFLAGS	:= -traditional
+ 
+@@ -44,7 +44,27 @@
+ 	$(call if_changed,gzip)
+ endif
+ 
++ifdef CONFIG_RELOCATABLE
++$(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin.all FORCE
++	$(call if_changed,bzip2)
++else
++$(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE
++	$(call if_changed,bzip2)
++endif
++
++ifdef CONFIG_RELOCATABLE
++$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin.all FORCE
++	$(call if_changed,lzma)
++else
++$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
++	$(call if_changed,lzma)
++endif
++
+ LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T
+ 
+-$(obj)/piggy.o: $(src)/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: $(src)/vmlinux.scr $(obj)/vmlinux.bin.$(suffix_y) FORCE
+ 	$(call if_changed,ld)
+diff -urN linux-2.6.23.12/arch/i386/boot/compressed/misc.c linux-2.6.23.12udpcast/arch/i386/boot/compressed/misc.c
+--- linux-2.6.23.12/arch/i386/boot/compressed/misc.c	2007-12-27 10:02:06.000000000 +0000
++++ linux-2.6.23.12udpcast/arch/i386/boot/compressed/misc.c	2007-12-27 11:58:57.000000000 +0000
+@@ -104,6 +104,7 @@
+ 
+ #define OF(args)  args
+ #define STATIC static
++#define MYSTATIC static
+ 
+ #undef memset
+ #undef memcpy
+@@ -121,9 +122,12 @@
+ 				 * always be larger than our output buffer.
+ 				 */
+ 
++#ifdef CONFIG_KERNEL_GZIP
+ static uch *inbuf;	/* input buffer */
++#endif
+ static uch *window;	/* Sliding window buffer, (and final output buffer) */
+ 
++#ifdef CONFIG_KERNEL_GZIP
+ static unsigned insize;  /* valid bytes in inbuf */
+ static unsigned inptr;   /* index of next byte to be processed in inbuf */
+ static unsigned outcnt;  /* bytes in output buffer */
+@@ -158,9 +162,14 @@
+ 
+ static int  fill_inbuf(void);
+ static void flush_window(void);
++#endif
++
+ static void error(char *m);
++
++#ifdef CONFIG_KERNEL_GZIP
+ static void gzip_mark(void **);
+ static void gzip_release(void **);
++#endif
+   
+ /*
+  * This is set up by the setup-routine at boot-time
+@@ -181,7 +190,9 @@
+ static void *malloc(int size);
+ static void free(void *where);
+ 
++#if (defined CONFIG_KERNEL_GZIP || defined CONFIG_KERNEL_BZIP2)
+ static void *memset(void *s, int c, unsigned n);
++#endif
+ static void *memcpy(void *dest, const void *src, unsigned n);
+ 
+ static void putstr(const char *);
+@@ -189,7 +200,11 @@
+ static unsigned long free_mem_ptr;
+ static unsigned long free_mem_end_ptr;
+ 
++#if (defined CONFIG_KERNEL_BZIP2 || defined CONFIG_KERNEL_LZMA)
++#define HEAP_SIZE             0x400000
++#else
+ #define HEAP_SIZE             0x4000
++#endif
+ 
+ static char *vidmem = (char *)0xb8000;
+ static int vidport;
+@@ -199,7 +214,29 @@
+ void *xquad_portio;
+ #endif
+ 
++#if (defined CONFIG_KERNEL_BZIP2 || defined CONFIG_KERNEL_LZMA)
++
++#define large_malloc malloc
++#define large_free free
++
++#ifdef current
++#undef current
++#endif
++
++#define INCLUDED
++#endif
++
++#ifdef CONFIG_KERNEL_GZIP
+ #include "../../../../lib/inflate.c"
++#endif
++
++#ifdef CONFIG_KERNEL_BZIP2
++#include "../../../../lib/decompress_bunzip2.c"
++#endif
++
++#ifdef CONFIG_KERNEL_LZMA
++#include "../../../../lib/decompress_unlzma.c"
++#endif
+ 
+ static void *malloc(int size)
+ {
+@@ -223,6 +260,7 @@
+ {	/* Don't care */
+ }
+ 
++#ifdef CONFIG_KERNEL_GZIP
+ static void gzip_mark(void **ptr)
+ {
+ 	*ptr = (void *) free_mem_ptr;
+@@ -232,6 +270,7 @@
+ {
+ 	free_mem_ptr = (unsigned long) *ptr;
+ }
++#endif
+  
+ static void scroll(void)
+ {
+@@ -279,6 +318,7 @@
+ 	outb_p(0xff & (pos >> 1), vidport+1);
+ }
+ 
++#if (defined CONFIG_KERNEL_GZIP || defined CONFIG_KERNEL_BZIP2)
+ static void* memset(void* s, int c, unsigned n)
+ {
+ 	int i;
+@@ -287,6 +327,7 @@
+ 	for (i=0;i<n;i++) ss[i] = c;
+ 	return s;
+ }
++#endif
+ 
+ static void* memcpy(void* dest, const void* src, unsigned n)
+ {
+@@ -297,6 +338,27 @@
+ 	return dest;
+ }
+ 
++#ifndef CONFIG_KERNEL_GZIP
++/* ===========================================================================
++ * Write the output window window[0..outcnt-1] and update bytes_out.
++ * (Used for the decompressed data only.)
++ */
++static int compr_flush(void *datav, unsigned int len)
++{
++    char *data = (char *) datav;
++    unsigned n;
++    uch *out;
++    
++    out = window; 
++    for (n = 0; n < len; n++) {
++	    *out++ = *data++;
++    }
++    bytes_out += (ulg)len;
++    window += (ulg)len;
++    return len;
++}
++
++#else
+ /* ===========================================================================
+  * Fill the input buffer. This is called only when the buffer is empty
+  * and at least one byte is really needed.
+@@ -329,6 +391,7 @@
+ 	bytes_out += (ulg)outcnt;
+ 	outcnt = 0;
+ }
++#endif
+ 
+ static void error(char *x)
+ {
+@@ -358,9 +421,11 @@
+ 	window = output;  	/* Output buffer (Normally at 1M) */
+ 	free_mem_ptr     = end;	/* Heap  */
+ 	free_mem_end_ptr = end + HEAP_SIZE;
++#ifdef CONFIG_KERNEL_GZIP
+ 	inbuf  = input_data;	/* Input buffer */
+ 	insize = input_len;
+ 	inptr  = 0;
++#endif
+ 
+ 	if ((u32)output & (CONFIG_PHYSICAL_ALIGN -1))
+ 		error("Destination address not CONFIG_PHYSICAL_ALIGN aligned");
+@@ -371,9 +436,21 @@
+ 		error("Wrong destination address");
+ #endif
+ 
++#ifdef CONFIG_KERNEL_BZIP2
++	putstr("Bunzipping Linux... ");
++	bunzip2(input_data, input_len-4, NULL, compr_flush, NULL);
++#endif
++
++#ifdef CONFIG_KERNEL_LZMA
++	putstr("Unlzmaing Linux... ");
++	unlzma(input_data, input_len-4, NULL, compr_flush, NULL);
++#endif
++
++#ifdef CONFIG_KERNEL_GZIP
+ 	makecrc();
+ 	putstr("Uncompressing Linux... ");
+ 	gunzip();
++#endif
+ 	putstr("Ok, booting the kernel.\n");
+ 	return;
+ }
+diff -urN linux-2.6.23.12/drivers/block/Kconfig linux-2.6.23.12udpcast/drivers/block/Kconfig
+--- linux-2.6.23.12/drivers/block/Kconfig	2007-12-18 21:55:57.000000000 +0000
++++ linux-2.6.23.12udpcast/drivers/block/Kconfig	2007-12-27 09:13:47.000000000 +0000
+@@ -374,6 +374,30 @@
+ 	  setups function - apparently needed by the rd_load_image routine
+ 	  that supposes the filesystem in the image uses a 1024 blocksize.
+ 
++config RD_BZIP2
++	bool "Initial ramdisk compressed using bzip2"
++	default n
++	depends on BLK_DEV_INITRD=y
++	help
++	  Support loading of a bzip2 encoded initial ramdisk or cpio buffer
++	  If unsure, say N.
++
++config RD_LZMA
++	bool "Initial ramdisk compressed using lzma"
++	default n
++	depends on BLK_DEV_INITRD=y
++	help
++	  Support loading of a lzma encoded initial ramdisk or cpio buffer
++	  If unsure, say N.
++
++config RD_GZIP
++	bool "Initial ramdisk compressed using gzip"
++	default y
++	depends on BLK_DEV_INITRD=y
++	help
++	  Support loading of a gzip encoded initial ramdisk or cpio buffer.
++	  If unsure, say Y.
++
+ config CDROM_PKTCDVD
+ 	tristate "Packet writing on CD/DVD media"
+ 	depends on !UML
+diff -urN linux-2.6.23.12/include/linux/decompress_bunzip2.h linux-2.6.23.12udpcast/include/linux/decompress_bunzip2.h
+--- linux-2.6.23.12/include/linux/decompress_bunzip2.h	1970-01-01 00:00:00.000000000 +0000
++++ linux-2.6.23.12udpcast/include/linux/decompress_bunzip2.h	2007-12-27 11:59:44.000000000 +0000
+@@ -0,0 +1,20 @@
++#ifndef DECOMPRESS_BUNZIP2_H
++#define DECOMPRESS_BUNZIP2_H
++
++/* Other housekeeping constants */
++#define BZIP2_IOBUF_SIZE		4096
++
++#ifndef MYSTATIC
++#define MYSTATIC
++#endif
++
++#ifndef INIT
++#define INIT
++#endif
++
++MYSTATIC int INIT bunzip2(char *inbuf, int len, 
++			  int(*fill)(void*,unsigned int),
++			  int(*flush)(void*,unsigned int),
++			  int *pos);
++
++#endif
+diff -urN linux-2.6.23.12/include/linux/decompress_generic.h linux-2.6.23.12udpcast/include/linux/decompress_generic.h
+--- linux-2.6.23.12/include/linux/decompress_generic.h	1970-01-01 00:00:00.000000000 +0000
++++ linux-2.6.23.12udpcast/include/linux/decompress_generic.h	2007-12-27 09:13:47.000000000 +0000
+@@ -0,0 +1,28 @@
++#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 (*uncompress_fn) (char *inbuf, int len, 
++			      int(*fill)(char*,unsigned int),
++			      int(*writebb)(char*,unsigned int),
++			      int *posp);
++
++/* 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
+diff -urN linux-2.6.23.12/include/linux/decompress_unlzma.h linux-2.6.23.12udpcast/include/linux/decompress_unlzma.h
+--- linux-2.6.23.12/include/linux/decompress_unlzma.h	1970-01-01 00:00:00.000000000 +0000
++++ linux-2.6.23.12udpcast/include/linux/decompress_unlzma.h	2007-12-27 11:59:39.000000000 +0000
+@@ -0,0 +1,19 @@
++#ifndef DECOMPRESS_UNLZMA_H
++#define DECOMPRESS_UNLZMA_H
++
++#define LZMA_IOBUF_SIZE	0x10000
++
++#ifndef MYSTATIC
++#define MYSTATIC
++#endif
++
++#ifndef INIT
++#define INIT
++#endif
++
++MYSTATIC int INIT unlzma(char *,int,
++			 int(*fill)(void*,unsigned int),
++			 int(*flush)(void*,unsigned int),
++			 int *);
++
++#endif
+diff -urN linux-2.6.23.12/init/Kconfig linux-2.6.23.12udpcast/init/Kconfig
+--- linux-2.6.23.12/init/Kconfig	2007-12-18 21:55:57.000000000 +0000
++++ linux-2.6.23.12udpcast/init/Kconfig	2007-12-27 09:13:47.000000000 +0000
+@@ -92,6 +92,56 @@
+ 
+ 	  which is done within the script "scripts/setlocalversion".)
+ 
++choice
++        prompt "Kernel compression mode"
++        default KERNEL_GZIP
++        help
++	  The linux kernel is a kind of self-extracting executable.
++	  Several compression algorithms are available, which differ
++	  in efficiency, compression and decompression speed.
++	  Compression speed is only relevant when building a kernel.
++	  Decompression speed is relevant at each boot.
++
++	  If you have any problems with bzip2 or lzma compressed
++	  kernels, mail me (Alain Knaff) <alain at knaff.lu>. (An older
++	  version of this functionality (bzip2 only), for 2.4, was
++	  supplied by Christian Ludwig)
++
++	  High compression options are mostly useful for users, who
++	  are low on disk space (embedded systems), but for whom ram
++	  size matters less.
++
++	  If in doubt, select 'gzip'
++
++config KERNEL_GZIP
++       bool "Gzip"
++       help
++         The old and tries gzip compression. Its compression ratio is
++	 the poorest among the 3 choices; however its speed (both
++	 compression and decompression) is the fastest.
++
++config KERNEL_BZIP2
++	bool "Bzip2"
++	help
++	  Its compression ratio and speed is intermediate.
++	  Decompression speed is slowest among the 3.
++	  The kernel size is about 10 per cent smaller with bzip2,
++	  in comparison to gzip.
++	  Bzip2 uses a large amount of memory. For modern kernels
++	  you will need at least 8MB RAM or more for booting.
++
++config KERNEL_LZMA
++       bool "LZMA"
++       help
++         The most recent compression algorithm.
++	 Its ratio is best, decompression speed is between the other
++	 2. Compression is slowest.
++	 The kernel size is about 33 per cent smaller with lzma,
++	 in comparison to gzip.
++
++endchoice
++
++
+ config SWAP
+ 	bool "Support for paging of anonymous memory (swap)"
+ 	depends on MMU && BLOCK
+diff -urN linux-2.6.23.12/init/do_mounts_rd.c linux-2.6.23.12udpcast/init/do_mounts_rd.c
+--- linux-2.6.23.12/init/do_mounts_rd.c	2007-12-18 21:55:57.000000000 +0000
++++ linux-2.6.23.12udpcast/init/do_mounts_rd.c	2007-12-27 10:58:08.000000000 +0000
+@@ -30,7 +30,15 @@
+ }
+ __setup("ramdisk_start=", ramdisk_start_setup);
+ 
++#ifdef CONFIG_RD_GZIP
+ static int __init crd_load(int in_fd, int out_fd);
++#endif
++#ifdef CONFIG_RD_BZIP2
++static int __init crd_load_bzip2(int in_fd, int out_fd);
++#endif
++#ifdef CONFIG_RD_LZMA
++static int __init crd_load_lzma(int in_fd, int out_fd);
++#endif
+ 
+ /*
+  * This routine tries to find a RAM disk image to load, and returns the
+@@ -46,7 +54,7 @@
+  * 	gzip
+  */
+ static int __init 
+-identify_ramdisk_image(int fd, int start_block)
++identify_ramdisk_image(int fd, int start_block, int *ztype)
+ {
+ 	const int size = 512;
+ 	struct minix_super_block *minixsb;
+@@ -72,6 +80,7 @@
+ 	sys_lseek(fd, start_block * BLOCK_SIZE, 0);
+ 	sys_read(fd, buf, size);
+ 
++#ifdef CONFIG_RD_GZIP
+ 	/*
+ 	 * If it matches the gzip magic numbers, return -1
+ 	 */
+@@ -79,9 +88,40 @@
+ 		printk(KERN_NOTICE
+ 		       "RAMDISK: Compressed image found at block %d\n",
+ 		       start_block);
++		*ztype = 0;
++		nblocks = 0;
++		goto done;
++	}
++#endif
++
++#ifdef CONFIG_RD_BZIP2
++	/*
++	 * If it matches the bzip magic numbers, return -1
++	 */
++	if (buf[0] == 0x42 && (buf[1] == 0x5a)) {
++		printk(KERN_NOTICE
++		       "RAMDISK: Bzipped image found at block %d\n",
++		       start_block);
++		*ztype = 1;
+ 		nblocks = 0;
+ 		goto done;
+ 	}
++#endif
++
++#ifdef CONFIG_RD_LZMA
++	/*
++	 * If it matches the bzip magic numbers, return -1
++	 */
++	if (buf[0] == 0x5d && (buf[1] == 0x00)) {
++		printk(KERN_NOTICE
++		       "RAMDISK: Lzma image found at block %d\n",
++		       start_block);
++		*ztype = 2;
++		nblocks = 0;
++		goto done;
++	}
++#endif
++
+ 
+ 	/* romfs is at block zero too */
+ 	if (romfsb->word0 == ROMSB_WORD0 &&
+@@ -145,6 +185,7 @@
+ 	int nblocks, i, disk;
+ 	char *buf = NULL;
+ 	unsigned short rotate = 0;
++	int ztype=-1;
+ #if !defined(CONFIG_S390) && !defined(CONFIG_PPC_ISERIES)
+ 	char rotator[4] = { '|' , '/' , '-' , '\\' };
+ #endif
+@@ -157,14 +198,38 @@
+ 	if (in_fd < 0)
+ 		goto noclose_input;
+ 
+-	nblocks = identify_ramdisk_image(in_fd, rd_image_start);
++	nblocks = identify_ramdisk_image(in_fd, rd_image_start, &ztype);
+ 	if (nblocks < 0)
+ 		goto done;
+ 
+ 	if (nblocks == 0) {
+ #ifdef BUILD_CRAMDISK
+-		if (crd_load(in_fd, out_fd) == 0)
+-			goto successful_load;
++		switch(ztype) {
++
++#ifdef CONFIG_RD_GZIP
++			case 0:
++				if (crd_load(in_fd, out_fd) == 0)
++					goto successful_load;
++				break;
++#endif
++
++#ifdef CONFIG_RD_BZIP2
++			case 1:
++				if (crd_load_bzip2(in_fd, out_fd) == 0)
++					goto successful_load;
++				break;
++#endif
++
++#ifdef CONFIG_RD_LZMA
++			case 2:
++				if (crd_load_lzma(in_fd, out_fd) == 0)
++					goto successful_load;
++				break;
++#endif
++
++			default:
++				break;
++		}
+ #else
+ 		printk(KERN_NOTICE
+ 		       "RAMDISK: Kernel does not support compressed "
+@@ -269,6 +334,7 @@
+ 
+ #ifdef BUILD_CRAMDISK
+ 
++#ifdef CONFIG_RD_GZIP
+ /*
+  * gzip declarations
+  */
+@@ -296,8 +362,11 @@
+ static int exit_code;
+ static int unzip_error;
+ static long bytes_out;
++#endif
++
+ static int crd_infd, crd_outfd;
+ 
++#ifdef CONFIG_RD_GZIP
+ #define get_byte()  (inptr < insize ? inbuf[inptr++] : fill_inbuf())
+ 		
+ /* Diagnostic functions (stubbed out) */
+@@ -321,6 +390,16 @@
+ 
+ #include "../lib/inflate.c"
+ 
++#ifdef CONFIG_RD_BZIP2
++#include <linux/decompress_bunzip2.h>
++#undef STATIC
++#endif
++
++#ifdef CONFIG_RD_LZMA
++#include <linux/decompress_unlzma.h>
++#undef STATIC
++#endif
++
+ static void __init *malloc(size_t size)
+ {
+ 	return kmalloc(size, GFP_KERNEL);
+@@ -359,7 +438,22 @@
+ 
+ 	return inbuf[0];
+ }
++#endif
+ 
++#if (defined CONFIG_RD_BZIP2 || defined CONFIG_RD_LZMA)
++static int __init compr_fill(void *buf, unsigned int len)
++{
++	int r = sys_read(crd_infd, buf, len);
++	if(r < 0) {
++		printk(KERN_ERR "RAMDISK: error while reading compressed data");
++	} else if(r == 0) {
++		printk(KERN_ERR "RAMDISK: EOF while reading compressed data");
++	}
++	return r;
++}
++#endif
++
++#ifdef CONFIG_RD_GZIP
<<Diff was trimmed, longer than 597 lines>>


More information about the pld-cvs-commit mailing list