From: Daan De Meyer Date: Mon, 24 Nov 2025 12:35:21 +0000 (+0100) Subject: hw/loader: Add support for zboot images compressed with zstd X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a18e8a25992d1643707e2cebdd6e9bb2bd7d3b9;p=thirdparty%2Fqemu.git hw/loader: Add support for zboot images compressed with zstd Reviewed-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Signed-off-by: Daan De Meyer Message-ID: <20251124123521.1058183-5-daan.j.demeyer@gmail.com> Signed-off-by: Philippe Mathieu-Daudé --- diff --git a/hw/core/loader.c b/hw/core/loader.c index 4952443fe5..5cbfba0a86 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -68,6 +68,11 @@ #include +#ifdef CONFIG_ZSTD +#include +#include +#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;