[PATCH] add support for loading lzma compressed kernels

Eric W. Biederman ebiederm at xmission.com
Wed Nov 18 19:03:27 EST 2009


Florian Fainelli <florian at openwrt.org> writes:

> Please find below a version which should address your comments.
> Thanks for reviewing the patch.
> --
> From: Florian Fainelli <florian at openwrt.org>
> Subject: [PATCH] add support for loading lzma compressed kernels
>
> This patch allows one to load a lzma compressed kernel using kexec -l.
> As I wanted the lzma code to be very similar to the existing
> zlib slurp_decompress I took lzread and associated routines
> from the cpio lzma support. Tested on my x86 laptop using the
> following commands:
>
> lzma e bzImage bzImage.lzma
> kexec -l bzImage.lzma
>
> Having lzma support is particularly useful on some embedded
> systems on which we have the kernel already lzma compressed
> and available on a mtd partition.

Yes.  I don't think it is particularly useful on x86 (as we have
a decompressor built into the kernel) but on other arches
it makes a lot of sense.

A few minor comments inline.

> diff -urN kexec-tools-2.0.1/kexec/kexec-lzma.h kexec-tools-2.0.1.lzma/kexec/kexec-lzma.h
> --- kexec-tools-2.0.1/kexec/kexec-lzma.h	1970-01-01 01:00:00.000000000 +0100
> +++ kexec-tools-2.0.1.lzma/kexec/kexec-lzma.h	2009-11-19 00:06:24.000000000 +0100
> @@ -0,0 +1,29 @@
> +#ifndef __KEXEC_LZMA_H
> +#define __KEXEC_LZMA_H
> +
> +#include <stdio.h>
> +#include <sys/types.h>
> +#include <unistd.h>
> +#include <inttypes.h>
> +#include <lzma.h>
> +
> +#include "config.h"
> +
> +#ifdef HAVE_LIBLZMA
> +#define kBufferSize (1 << 15)
> +
> +typedef struct lzfile {
> +	uint8_t buf[kBufferSize];
> +	lzma_stream strm;
> +	FILE *file;
> +	int encoding;
> +	int eof;
> +} LZFILE;
> +
> +LZFILE *lzopen(const char *path, const char *mode);
> +int lzclose(LZFILE *lzfile);
> +ssize_t lzread(LZFILE *lzfile, void *buf, size_t len);

I don't think we need any of these definitions in the header file.

> +#endif /* HAVE_LIBLZMA */
> +
> +char *lzma_decompress_file(const char *filename, off_t *r_size);

Ideally the lzma_decompress_file stub would live here and would not
even compile kexec/lzma.c if we don't have lzma.

> +#endif /* __KEXEC_LZMA_H */


Eric



More information about the kexec mailing list