Skip to content

Commit

Permalink
kexec: Enable zstd in kexec decompression paths
Browse files Browse the repository at this point in the history
The kexec decompression routines support detecting zlib or lzma
compressed images. Lets add the ability to automatically decompress
zstd ones as well. The zstd attempt is made after gzip because its
fairly inexpensive relative lzma, and gzip remains a popular option.

Signed-off-by: Jeremy Linton <[email protected]>
Acked-by: Pingfan Liu <[email protected]>
Signed-off-by: Simon Horman <[email protected]>
  • Loading branch information
jlintonarm authored and horms committed Dec 13, 2024
1 parent 60ce9bd commit a7fcd42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion kexec/kexec-pe-zboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ int pez_prepare(const char *crude_buf, off_t buf_sz, int *kernel_fd,
* algorithms than are supported here, error out if we detect that.
*/
if (memcmp(&z->compress_type, "gzip", 4) &&
memcmp(&z->compress_type, "zstd", 4) &&
memcmp(&z->compress_type, "lzma", 4)) {
dbgprintf("%s: kexec can only decompress gziped and lzma images.\n", __func__);
dbgprintf("%s: kexec can only decompress gziped, lzma and zstd images\n", __func__);
return -1;
}

Expand Down
10 changes: 7 additions & 3 deletions kexec/kexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "kexec-sha256.h"
#include "kexec-zlib.h"
#include "kexec-lzma.h"
#include "kexec-zstd.h"
#include <arch/options.h>

#define KEXEC_LOADED_PATH "/sys/kernel/kexec_loaded"
Expand Down Expand Up @@ -639,9 +640,12 @@ char *slurp_decompress_file(const char *filename, off_t *r_size)

kernel_buf = zlib_decompress_file(filename, r_size);
if (!kernel_buf) {
kernel_buf = lzma_decompress_file(filename, r_size);
if (!kernel_buf)
return slurp_file(filename, r_size);
kernel_buf = zstd_decompress_file(filename, r_size);
if (!kernel_buf) {
kernel_buf = lzma_decompress_file(filename, r_size);
if (!kernel_buf)
return slurp_file(filename, r_size);
}
}
return kernel_buf;
}
Expand Down

0 comments on commit a7fcd42

Please sign in to comment.