hw/loader: Add support for zboot images compressed with zstd

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Daan De Meyer <daan.j.demeyer@gmail.com>
Message-ID: <20251124123521.1058183-5-daan.j.demeyer@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
Daan De Meyer
2025-11-24 13:35:21 +01:00
committed by Philippe Mathieu-Daudé
parent 3fd0734cb3
commit 3a18e8a259

View File

@@ -68,6 +68,11 @@
#include <zlib.h>
#ifdef CONFIG_ZSTD
#include <zstd.h>
#include <zstd_errors.h>
#endif
static int roms_loaded;
/* return the size or -1 if error */
@@ -916,14 +921,6 @@ ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size)
return 0;
}
if (strcmp(header->compression_type, "gzip") != 0) {
fprintf(stderr,
"unable to handle EFI zboot image with \"%.*s\" compression\n",
(int)sizeof(header->compression_type) - 1,
header->compression_type);
return -1;
}
ploff = ldl_le_p(&header->payload_offset);
plsize = ldl_le_p(&header->payload_size);
@@ -933,7 +930,22 @@ ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size)
}
data = g_malloc(max_bytes);
bytes = gunzip(data, max_bytes, *buffer + ploff, plsize);
if (strcmp(header->compression_type, "gzip") == 0) {
bytes = gunzip(data, max_bytes, *buffer + ploff, plsize);
#ifdef CONFIG_ZSTD
} else if (strcmp(header->compression_type, "zstd") == 0) {
size_t ret = ZSTD_decompress(data, max_bytes, *buffer + ploff, plsize);
bytes = ZSTD_isError(ret) ? -1 : (ssize_t) ret;
#endif
} else {
fprintf(stderr,
"unable to handle EFI zboot image with \"%.*s\" compression\n",
(int)sizeof(header->compression_type) - 1,
header->compression_type);
return -1;
}
if (bytes < 0) {
fprintf(stderr, "failed to decompress EFI zboot image\n");
return -1;