2009-01-09 02:14:17 +03:00
/*
* decompress . c
*
* Detect the decompression method based on magic number
*/
# include <linux/decompress/generic.h>
# include <linux/decompress/bunzip2.h>
# include <linux/decompress/unlzma.h>
decompressors: add boot-time XZ support
This implements the API defined in <linux/decompress/generic.h> which is
used for kernel, initramfs, and initrd decompression. This patch together
with the first patch is enough for XZ-compressed initramfs and initrd;
XZ-compressed kernel will need arch-specific changes.
The buffering requirements described in decompress_unxz.c are stricter
than with gzip, so the relevant changes should be done to the
arch-specific code when adding support for XZ-compressed kernel.
Similarly, the heap size in arch-specific pre-boot code may need to be
increased (30 KiB is enough).
The XZ decompressor needs memmove(), memeq() (memcmp() == 0), and
memzero() (memset(ptr, 0, size)), which aren't available in all
arch-specific pre-boot environments. I'm including simple versions in
decompress_unxz.c, but a cleaner solution would naturally be nicer.
Signed-off-by: Lasse Collin <lasse.collin@tukaani.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Alain Knaff <alain@knaff.lu>
Cc: Albin Tonnerre <albin.tonnerre@free-electrons.com>
Cc: Phillip Lougher <phillip@lougher.demon.co.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-01-13 04:01:23 +03:00
# include <linux/decompress/unxz.h>
2009-01-09 02:14:17 +03:00
# include <linux/decompress/inflate.h>
2010-01-09 01:42:46 +03:00
# include <linux/decompress/unlzo.h>
2013-07-09 03:01:46 +04:00
# include <linux/decompress/unlz4.h>
2009-01-09 02:14:17 +03:00
# include <linux/types.h>
# include <linux/string.h>
2012-10-05 04:16:58 +04:00
# include <linux/init.h>
2014-04-08 02:39:16 +04:00
# include <linux/printk.h>
2009-01-09 02:14:17 +03:00
2009-01-13 01:24:04 +03:00
# ifndef CONFIG_DECOMPRESS_GZIP
# define gunzip NULL
# endif
# ifndef CONFIG_DECOMPRESS_BZIP2
# define bunzip2 NULL
# endif
# ifndef CONFIG_DECOMPRESS_LZMA
# define unlzma NULL
# endif
decompressors: add boot-time XZ support
This implements the API defined in <linux/decompress/generic.h> which is
used for kernel, initramfs, and initrd decompression. This patch together
with the first patch is enough for XZ-compressed initramfs and initrd;
XZ-compressed kernel will need arch-specific changes.
The buffering requirements described in decompress_unxz.c are stricter
than with gzip, so the relevant changes should be done to the
arch-specific code when adding support for XZ-compressed kernel.
Similarly, the heap size in arch-specific pre-boot code may need to be
increased (30 KiB is enough).
The XZ decompressor needs memmove(), memeq() (memcmp() == 0), and
memzero() (memset(ptr, 0, size)), which aren't available in all
arch-specific pre-boot environments. I'm including simple versions in
decompress_unxz.c, but a cleaner solution would naturally be nicer.
Signed-off-by: Lasse Collin <lasse.collin@tukaani.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Alain Knaff <alain@knaff.lu>
Cc: Albin Tonnerre <albin.tonnerre@free-electrons.com>
Cc: Phillip Lougher <phillip@lougher.demon.co.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-01-13 04:01:23 +03:00
# ifndef CONFIG_DECOMPRESS_XZ
# define unxz NULL
# endif
2010-01-09 01:42:46 +03:00
# ifndef CONFIG_DECOMPRESS_LZO
# define unlzo NULL
# endif
2013-07-09 03:01:46 +04:00
# ifndef CONFIG_DECOMPRESS_LZ4
# define unlz4 NULL
# endif
2009-01-13 01:24:04 +03:00
2012-10-05 04:16:58 +04:00
struct compress_format {
2009-01-09 02:14:17 +03:00
unsigned char magic [ 2 ] ;
const char * name ;
decompress_fn decompressor ;
2012-10-05 04:16:58 +04:00
} ;
2013-05-01 02:28:50 +04:00
static const struct compress_format compressed_formats [ ] __initconst = {
2009-01-09 02:14:17 +03:00
{ { 037 , 0213 } , " gzip " , gunzip } ,
{ { 037 , 0236 } , " gzip " , gunzip } ,
{ { 0x42 , 0x5a } , " bzip2 " , bunzip2 } ,
{ { 0x5d , 0x00 } , " lzma " , unlzma } ,
decompressors: add boot-time XZ support
This implements the API defined in <linux/decompress/generic.h> which is
used for kernel, initramfs, and initrd decompression. This patch together
with the first patch is enough for XZ-compressed initramfs and initrd;
XZ-compressed kernel will need arch-specific changes.
The buffering requirements described in decompress_unxz.c are stricter
than with gzip, so the relevant changes should be done to the
arch-specific code when adding support for XZ-compressed kernel.
Similarly, the heap size in arch-specific pre-boot code may need to be
increased (30 KiB is enough).
The XZ decompressor needs memmove(), memeq() (memcmp() == 0), and
memzero() (memset(ptr, 0, size)), which aren't available in all
arch-specific pre-boot environments. I'm including simple versions in
decompress_unxz.c, but a cleaner solution would naturally be nicer.
Signed-off-by: Lasse Collin <lasse.collin@tukaani.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Alain Knaff <alain@knaff.lu>
Cc: Albin Tonnerre <albin.tonnerre@free-electrons.com>
Cc: Phillip Lougher <phillip@lougher.demon.co.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-01-13 04:01:23 +03:00
{ { 0xfd , 0x37 } , " xz " , unxz } ,
2010-01-09 01:42:46 +03:00
{ { 0x89 , 0x4c } , " lzo " , unlzo } ,
2013-07-09 03:01:46 +04:00
{ { 0x02 , 0x21 } , " lz4 " , unlz4 } ,
2009-01-09 02:14:17 +03:00
{ { 0 , 0 } , NULL , NULL }
} ;
2012-10-05 04:16:58 +04:00
decompress_fn __init decompress_method ( const unsigned char * inbuf , int len ,
2009-01-09 02:14:17 +03:00
const char * * name )
{
const struct compress_format * cf ;
if ( len < 2 )
return NULL ; /* Need at least this much... */
2014-04-08 02:39:16 +04:00
pr_debug ( " Compressed data magic: %#.2x %#.2x \n " , inbuf [ 0 ] , inbuf [ 1 ] ) ;
2009-02-20 00:36:55 +03:00
for ( cf = compressed_formats ; cf - > name ; cf + + ) {
2009-01-09 02:14:17 +03:00
if ( ! memcmp ( inbuf , cf - > magic , 2 ) )
break ;
}
if ( name )
* name = cf - > name ;
return cf - > decompressor ;
}