Commit 34e5a7cd authored by topjohnwu's avatar topjohnwu

Zopfli is not always smaller

parent 7343c195
...@@ -541,6 +541,14 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) { ...@@ -541,6 +541,14 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
} else { } else {
hdr->kernel_size() = xwrite(fd, raw_buf, raw_size); hdr->kernel_size() = xwrite(fd, raw_buf, raw_size);
} }
if (boot.flags[ZIMAGE_KERNEL] &&
boot.k_fmt == GZIP && hdr->kernel_size() > boot.hdr->kernel_size()) {
// Revert and try zipfoli
ftruncate(fd, lseek(fd, -hdr->kernel_size(), SEEK_CUR));
hdr->kernel_size() = compress(ZOPFLI, fd, raw_buf, raw_size);
}
munmap(raw_buf, raw_size); munmap(raw_buf, raw_size);
} }
if (boot.flags[ZIMAGE_KERNEL]) { if (boot.flags[ZIMAGE_KERNEL]) {
......
...@@ -624,8 +624,9 @@ stream_ptr get_encoder(format_t type, stream_ptr &&base) { ...@@ -624,8 +624,9 @@ stream_ptr get_encoder(format_t type, stream_ptr &&base) {
return make_unique<LZ4_encoder>(std::move(base), false); return make_unique<LZ4_encoder>(std::move(base), false);
case LZ4_LG: case LZ4_LG:
return make_unique<LZ4_encoder>(std::move(base), true); return make_unique<LZ4_encoder>(std::move(base), true);
case GZIP: case ZOPFLI:
return make_unique<zopfli_encoder>(std::move(base)); return make_unique<zopfli_encoder>(std::move(base));
case GZIP:
default: default:
return make_unique<gz_encoder>(std::move(base)); return make_unique<gz_encoder>(std::move(base));
} }
...@@ -643,6 +644,7 @@ stream_ptr get_decoder(format_t type, stream_ptr &&base) { ...@@ -643,6 +644,7 @@ stream_ptr get_decoder(format_t type, stream_ptr &&base) {
case LZ4_LEGACY: case LZ4_LEGACY:
case LZ4_LG: case LZ4_LG:
return make_unique<LZ4_decoder>(std::move(base)); return make_unique<LZ4_decoder>(std::move(base));
case ZOPFLI:
case GZIP: case GZIP:
default: default:
return make_unique<gz_decoder>(std::move(base)); return make_unique<gz_decoder>(std::move(base));
......
...@@ -47,6 +47,8 @@ const char *Fmt2Name::operator[](format_t fmt) { ...@@ -47,6 +47,8 @@ const char *Fmt2Name::operator[](format_t fmt) {
switch (fmt) { switch (fmt) {
case GZIP: case GZIP:
return "gzip"; return "gzip";
case ZOPFLI:
return "zopfli";
case LZOP: case LZOP:
return "lzop"; return "lzop";
case XZ: case XZ:
...@@ -73,6 +75,7 @@ const char *Fmt2Name::operator[](format_t fmt) { ...@@ -73,6 +75,7 @@ const char *Fmt2Name::operator[](format_t fmt) {
const char *Fmt2Ext::operator[](format_t fmt) { const char *Fmt2Ext::operator[](format_t fmt) {
switch (fmt) { switch (fmt) {
case GZIP: case GZIP:
case ZOPFLI:
return ".gz"; return ".gz";
case LZOP: case LZOP:
return ".lzo"; return ".lzo";
...@@ -96,6 +99,7 @@ const char *Fmt2Ext::operator[](format_t fmt) { ...@@ -96,6 +99,7 @@ const char *Fmt2Ext::operator[](format_t fmt) {
format_t Name2Fmt::operator[](std::string_view name) { format_t Name2Fmt::operator[](std::string_view name) {
if (0) {} if (0) {}
CHECK("gzip", GZIP) CHECK("gzip", GZIP)
CHECK("zopfli", ZOPFLI)
CHECK("xz", XZ) CHECK("xz", XZ)
CHECK("lzma", LZMA) CHECK("lzma", LZMA)
CHECK("bzip2", BZIP2) CHECK("bzip2", BZIP2)
......
...@@ -12,6 +12,7 @@ typedef enum { ...@@ -12,6 +12,7 @@ typedef enum {
BLOB, BLOB,
/* Compression formats */ /* Compression formats */
GZIP, GZIP,
ZOPFLI,
XZ, XZ,
LZMA, LZMA,
BZIP2, BZIP2,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment