Compressor part
This commit is contained in:
parent
758194b076
commit
2c44e493c7
3 changed files with 68 additions and 18 deletions
|
@ -113,6 +113,7 @@ program = {
|
||||||
extra_dist = util/grub-mkimagexx.c;
|
extra_dist = util/grub-mkimagexx.c;
|
||||||
|
|
||||||
ldadd = libgrub.a;
|
ldadd = libgrub.a;
|
||||||
|
ldadd = '$(LIBLZMA)';
|
||||||
ldadd = '$(LIBINTL) $(LIBDEVMAPPER)';
|
ldadd = '$(LIBINTL) $(LIBDEVMAPPER)';
|
||||||
cppflags = '-DGRUB_PKGLIBROOTDIR=\"$(pkglibrootdir)\"';
|
cppflags = '-DGRUB_PKGLIBROOTDIR=\"$(pkglibrootdir)\"';
|
||||||
};
|
};
|
||||||
|
|
|
@ -849,6 +849,12 @@ fi
|
||||||
|
|
||||||
AC_SUBST([LIBDEVMAPPER])
|
AC_SUBST([LIBDEVMAPPER])
|
||||||
|
|
||||||
|
AC_CHECK_LIB([lzma], [lzma_code],
|
||||||
|
[LIBLZMA="-llzma"
|
||||||
|
AC_DEFINE([HAVE_LIBLZMA], [1],
|
||||||
|
[Define to 1 if you have the LZMA library.])],)
|
||||||
|
AC_SUBST([LIBLZMA])
|
||||||
|
|
||||||
AC_CHECK_LIB([zfs], [libzfs_init],
|
AC_CHECK_LIB([zfs], [libzfs_init],
|
||||||
[LIBZFS="-lzfs"
|
[LIBZFS="-lzfs"
|
||||||
AC_DEFINE([HAVE_LIBZFS], [1],
|
AC_DEFINE([HAVE_LIBZFS], [1],
|
||||||
|
|
|
@ -45,6 +45,10 @@
|
||||||
|
|
||||||
#define ALIGN_ADDR(x) (ALIGN_UP((x), image_target->voidp_sizeof))
|
#define ALIGN_ADDR(x) (ALIGN_UP((x), image_target->voidp_sizeof))
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBLZMA
|
||||||
|
#include <lzma.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TARGET_NO_FIELD 0xffffffff
|
#define TARGET_NO_FIELD 0xffffffff
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -269,7 +273,11 @@ struct image_target_desc image_targets[] =
|
||||||
.link_addr = GRUB_KERNEL_MIPS_YEELOONG_LINK_ADDR,
|
.link_addr = GRUB_KERNEL_MIPS_YEELOONG_LINK_ADDR,
|
||||||
.elf_target = EM_MIPS,
|
.elf_target = EM_MIPS,
|
||||||
.link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN,
|
.link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN,
|
||||||
|
#ifdef HAVE_LIBLZMA
|
||||||
.default_compression = COMPRESSION_XZ
|
.default_compression = COMPRESSION_XZ
|
||||||
|
#else
|
||||||
|
.default_compression = COMPRESSION_NONE
|
||||||
|
#endif
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.name = "mipsel-yeeloong-elf",
|
.name = "mipsel-yeeloong-elf",
|
||||||
|
@ -492,7 +500,7 @@ compress_kernel_lzma (char *kernel_img, size_t kernel_size,
|
||||||
memcpy (*core_img, kernel_img, raw_size);
|
memcpy (*core_img, kernel_img, raw_size);
|
||||||
|
|
||||||
*core_size = kernel_size - raw_size;
|
*core_size = kernel_size - raw_size;
|
||||||
if (LzmaEncode ((unsigned char *) *core_img + raw_size, core_size - raw_size,
|
if (LzmaEncode ((unsigned char *) *core_img + raw_size, core_size,
|
||||||
(unsigned char *) kernel_img + raw_size,
|
(unsigned char *) kernel_img + raw_size,
|
||||||
kernel_size - raw_size,
|
kernel_size - raw_size,
|
||||||
&props, out_props, &out_props_size,
|
&props, out_props, &out_props_size,
|
||||||
|
@ -506,30 +514,52 @@ static void
|
||||||
compress_kernel_xz (char *kernel_img, size_t kernel_size,
|
compress_kernel_xz (char *kernel_img, size_t kernel_size,
|
||||||
char **core_img, size_t *core_size, size_t raw_size)
|
char **core_img, size_t *core_size, size_t raw_size)
|
||||||
{
|
{
|
||||||
CLzmaEncProps props;
|
lzma_stream strm = LZMA_STREAM_INIT;
|
||||||
unsigned char out_props[5];
|
lzma_ret xzret;
|
||||||
size_t out_props_size = 5;
|
lzma_options_lzma lzopts = {
|
||||||
|
.dict_size = 1 << 16,
|
||||||
LzmaEncProps_Init(&props);
|
.preset_dict = NULL,
|
||||||
props.dictSize = 1 << 16;
|
.preset_dict_size = 0,
|
||||||
props.lc = 3;
|
.lc = 3,
|
||||||
props.lp = 0;
|
.lp = 0,
|
||||||
props.pb = 2;
|
.pb = 2,
|
||||||
props.numThreads = 1;
|
.mode = LZMA_MODE_NORMAL,
|
||||||
|
.nice_len = 64,
|
||||||
|
.mf = LZMA_MF_BT4,
|
||||||
|
.depth = 0,
|
||||||
|
};
|
||||||
|
lzma_filter fltrs[] = {
|
||||||
|
{ .id = LZMA_FILTER_LZMA2, .options = &lzopts},
|
||||||
|
{ .id = LZMA_VLI_UNKNOWN, .options = NULL}
|
||||||
|
};
|
||||||
|
|
||||||
if (kernel_size < raw_size)
|
if (kernel_size < raw_size)
|
||||||
grub_util_error (_("the core image is too small"));
|
grub_util_error (_("the core image is too small"));
|
||||||
|
|
||||||
|
xzret = lzma_stream_encoder (&strm, fltrs, LZMA_CHECK_NONE);
|
||||||
|
if (xzret != LZMA_OK)
|
||||||
|
grub_util_error (_("cannot compress the kernel image"));
|
||||||
|
|
||||||
*core_img = xmalloc (kernel_size);
|
*core_img = xmalloc (kernel_size);
|
||||||
memcpy (*core_img, kernel_img, raw_size);
|
memcpy (*core_img, kernel_img, raw_size);
|
||||||
|
|
||||||
*core_size = kernel_size - raw_size;
|
*core_size = kernel_size - raw_size;
|
||||||
if (LzmaEncode ((unsigned char *) *core_img + raw_size, core_size - raw_size,
|
strm.next_in = (unsigned char *) kernel_img + raw_size;
|
||||||
(unsigned char *) kernel_img + raw_size,
|
strm.avail_in = kernel_size - raw_size;
|
||||||
kernel_size - raw_size,
|
strm.next_out = (unsigned char *) *core_img + raw_size;
|
||||||
&props, out_props, &out_props_size,
|
strm.avail_out = *core_size;
|
||||||
0, NULL, &g_Alloc, &g_Alloc) != SZ_OK)
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
xzret = lzma_code (&strm, LZMA_FINISH);
|
||||||
|
if (xzret == LZMA_OK)
|
||||||
|
continue;
|
||||||
|
if (xzret == LZMA_STREAM_END)
|
||||||
|
break;
|
||||||
grub_util_error (_("cannot compress the kernel image"));
|
grub_util_error (_("cannot compress the kernel image"));
|
||||||
|
}
|
||||||
|
|
||||||
|
*core_size -= strm.avail_out;
|
||||||
|
|
||||||
*core_size += raw_size;
|
*core_size += raw_size;
|
||||||
}
|
}
|
||||||
|
@ -546,6 +576,7 @@ compress_kernel (struct image_target_desc *image_target, char *kernel_img,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBLZMA
|
||||||
if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS
|
if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS
|
||||||
&& (comp == COMPRESSION_XZ))
|
&& (comp == COMPRESSION_XZ))
|
||||||
{
|
{
|
||||||
|
@ -553,6 +584,11 @@ compress_kernel (struct image_target_desc *image_target, char *kernel_img,
|
||||||
core_size, image_target->raw_size);
|
core_size, image_target->raw_size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS
|
||||||
|
&& (comp != COMPRESSION_NONE))
|
||||||
|
grub_util_error ("unknown compression %d\n", comp);
|
||||||
|
|
||||||
*core_img = xmalloc (kernel_size);
|
*core_img = xmalloc (kernel_size);
|
||||||
memcpy (*core_img, kernel_img, kernel_size);
|
memcpy (*core_img, kernel_img, kernel_size);
|
||||||
|
@ -1457,7 +1493,14 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
case 'C':
|
case 'C':
|
||||||
if (grub_strcmp (optarg, "xz") == 0)
|
if (grub_strcmp (optarg, "xz") == 0)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_LIBLZMA
|
||||||
comp = COMPRESSION_XZ;
|
comp = COMPRESSION_XZ;
|
||||||
|
#else
|
||||||
|
grub_util_error ("grub-mkimage is compiled without XZ support",
|
||||||
|
optarg);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
else if (grub_strcmp (optarg, "none") == 0)
|
else if (grub_strcmp (optarg, "none") == 0)
|
||||||
comp = COMPRESSION_NONE;
|
comp = COMPRESSION_NONE;
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue