From: Daan De Meyer <daan.j.demeyer@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Gerd Hoffmann" <kraxel@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
qemu-arm@nongnu.org, "Daan De Meyer" <daan.j.demeyer@gmail.com>
Subject: [PATCH v3 3/3] Add support for zboot images compressed with zstd
Date: Sat, 11 Oct 2025 10:15:53 +0200 [thread overview]
Message-ID: <20251011081553.4065883-4-daan.j.demeyer@gmail.com> (raw)
In-Reply-To: <20251011081553.4065883-1-daan.j.demeyer@gmail.com>
Signed-off-by: Daan De Meyer <daan.j.demeyer@gmail.com>
---
hw/core/loader.c | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index a511888aa3..c1611cc960 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -67,6 +67,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 */
@@ -882,14 +887,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);
@@ -899,7 +896,22 @@ ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size)
}
data = g_malloc(LOAD_IMAGE_MAX_DECOMPRESSED_BYTES);
- bytes = gunzip(data, LOAD_IMAGE_MAX_DECOMPRESSED_BYTES, *buffer + ploff, plsize);
+
+ if (strcmp(header->compression_type, "gzip") == 0) {
+ bytes = gunzip(data, LOAD_IMAGE_MAX_DECOMPRESSED_BYTES, *buffer + ploff, plsize);
+#ifdef CONFIG_ZSTD
+ } else if (strcmp(header->compression_type, "zstd") == 0) {
+ size_t ret = ZSTD_decompress(data, LOAD_IMAGE_MAX_DECOMPRESSED_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;
--
2.51.0
next prev parent reply other threads:[~2025-10-11 8:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-11 8:15 [PATCH v3 0/3] Add support for zboot images compressed with zstd Daan De Meyer
2025-10-11 8:15 ` [PATCH v3 1/3] Rename LOAD_IMAGE_MAX_GUNZIP_BYTES to LOAD_IMAGE_MAX_DECOMPRESSED_BYTES Daan De Meyer
2025-10-13 7:10 ` Daniel P. Berrangé
2025-10-11 8:15 ` [PATCH v3 2/3] Use g_autofree in unpack_efi_zboot_image() Daan De Meyer
2025-10-13 7:10 ` Daniel P. Berrangé
2025-10-11 8:15 ` Daan De Meyer [this message]
2025-10-13 7:12 ` [PATCH v3 3/3] Add support for zboot images compressed with zstd Daniel P. Berrangé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251011081553.4065883-4-daan.j.demeyer@gmail.com \
--to=daan.j.demeyer@gmail.com \
--cc=kraxel@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).