* [PATCH v4 0/4] Add support for zboot images compressed with zstd
@ 2025-11-24 12:35 Daan De Meyer
2025-11-24 12:35 ` [PATCH v4 1/4] Rename LOAD_IMAGE_MAX_GUNZIP_BYTES to LOAD_IMAGE_MAX_DECOMPRESSED_BYTES Daan De Meyer
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Daan De Meyer @ 2025-11-24 12:35 UTC (permalink / raw)
To: qemu-devel
Cc: Aleksandar Rikalo, Paul Burton, qemu-arm, Gerd Hoffmann,
Peter Maydell, Philippe Mathieu-Daudé, Daan De Meyer
Fedora arm64 has an EFI_ZBOOT kernel image compressed
with zstd. Let's make sure we can use it for direct kernel
boot with qemu.
Daan De Meyer (4):
Rename LOAD_IMAGE_MAX_GUNZIP_BYTES to
LOAD_IMAGE_MAX_DECOMPRESSED_BYTES
Rename UBOOT_MAX_GUNZIP_BYTES to UBOOT_MAX_DECOMPRESSED_BYTES
Use g_autofree in unpack_efi_zboot_image()
Add support for zboot images compressed with zstd
hw/arm/boot.c | 4 ++--
hw/core/loader-fit.c | 2 +-
hw/core/loader.c | 44 ++++++++++++++++++++++++++++----------------
hw/nvram/fw_cfg.c | 2 +-
include/hw/loader.h | 4 ++--
5 files changed, 34 insertions(+), 22 deletions(-)
--
2.51.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v4 1/4] Rename LOAD_IMAGE_MAX_GUNZIP_BYTES to LOAD_IMAGE_MAX_DECOMPRESSED_BYTES
2025-11-24 12:35 [PATCH v4 0/4] Add support for zboot images compressed with zstd Daan De Meyer
@ 2025-11-24 12:35 ` Daan De Meyer
2025-11-24 12:35 ` [PATCH v4 2/4] Rename UBOOT_MAX_GUNZIP_BYTES to UBOOT_MAX_DECOMPRESSED_BYTES Daan De Meyer
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Daan De Meyer @ 2025-11-24 12:35 UTC (permalink / raw)
To: qemu-devel
Cc: Aleksandar Rikalo, Paul Burton, qemu-arm, Gerd Hoffmann,
Peter Maydell, Philippe Mathieu-Daudé, Daan De Meyer,
Daniel P. Berrangé
Preparation for adding support for zstd compressed efi zboot kernel
images.
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>
---
hw/arm/boot.c | 4 ++--
hw/core/loader.c | 9 +++++----
hw/nvram/fw_cfg.c | 2 +-
include/hw/loader.h | 2 +-
4 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index b91660208f..6cf8a4b7fd 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -823,11 +823,11 @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
hwaddr kernel_load_offset = KERNEL64_LOAD_ADDR;
uint64_t kernel_size = 0;
uint8_t *buffer;
+ size_t max_size = LOAD_IMAGE_MAX_DECOMPRESSED_BYTES;
ssize_t size;
/* On aarch64, it's the bootloader's job to uncompress the kernel. */
- size = load_image_gzipped_buffer(filename, LOAD_IMAGE_MAX_GUNZIP_BYTES,
- &buffer);
+ size = load_image_gzipped_buffer(filename, max_size, &buffer);
if (size < 0) {
gsize len;
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 590c5b02aa..f940b6a227 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -814,8 +814,8 @@ ssize_t load_image_gzipped_buffer(const char *filename, uint64_t max_sz,
goto out;
}
- if (max_sz > LOAD_IMAGE_MAX_GUNZIP_BYTES) {
- max_sz = LOAD_IMAGE_MAX_GUNZIP_BYTES;
+ if (max_sz > LOAD_IMAGE_MAX_DECOMPRESSED_BYTES) {
+ max_sz = LOAD_IMAGE_MAX_DECOMPRESSED_BYTES;
}
data = g_malloc(max_sz);
@@ -885,6 +885,7 @@ ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size)
uint8_t *data = NULL;
ssize_t ploff, plsize;
ssize_t bytes;
+ size_t max_bytes = LOAD_IMAGE_MAX_DECOMPRESSED_BYTES;
/* ignore if this is too small to be a EFI zboot image */
if (*size < sizeof(*header)) {
@@ -916,8 +917,8 @@ ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size)
return -1;
}
- data = g_malloc(LOAD_IMAGE_MAX_GUNZIP_BYTES);
- bytes = gunzip(data, LOAD_IMAGE_MAX_GUNZIP_BYTES, *buffer + ploff, plsize);
+ data = g_malloc(max_bytes);
+ bytes = gunzip(data, max_bytes, *buffer + ploff, plsize);
if (bytes < 0) {
fprintf(stderr, "failed to decompress EFI zboot image\n");
g_free(data);
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index aa24050493..af3b112524 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -1115,7 +1115,7 @@ void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key,
if (try_decompress) {
size = load_image_gzipped_buffer(image_name,
- LOAD_IMAGE_MAX_GUNZIP_BYTES, &data);
+ LOAD_IMAGE_MAX_DECOMPRESSED_BYTES, &data);
}
if (size == (size_t)-1) {
diff --git a/include/hw/loader.h b/include/hw/loader.h
index d035e72748..3371de506f 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -82,7 +82,7 @@ ssize_t load_image_mr(const char *filename, MemoryRegion *mr);
* load_image_gzipped_buffer() will read. It prevents
* g_malloc() in those functions from allocating a huge amount of memory.
*/
-#define LOAD_IMAGE_MAX_GUNZIP_BYTES (256 << 20)
+#define LOAD_IMAGE_MAX_DECOMPRESSED_BYTES (256 << 20)
ssize_t load_image_gzipped_buffer(const char *filename, uint64_t max_sz,
uint8_t **buffer);
--
2.51.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4 2/4] Rename UBOOT_MAX_GUNZIP_BYTES to UBOOT_MAX_DECOMPRESSED_BYTES
2025-11-24 12:35 [PATCH v4 0/4] Add support for zboot images compressed with zstd Daan De Meyer
2025-11-24 12:35 ` [PATCH v4 1/4] Rename LOAD_IMAGE_MAX_GUNZIP_BYTES to LOAD_IMAGE_MAX_DECOMPRESSED_BYTES Daan De Meyer
@ 2025-11-24 12:35 ` Daan De Meyer
2025-11-24 12:39 ` Philippe Mathieu-Daudé
2025-11-24 12:35 ` [PATCH v4 3/4] Use g_autofree in unpack_efi_zboot_image() Daan De Meyer
` (2 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Daan De Meyer @ 2025-11-24 12:35 UTC (permalink / raw)
To: qemu-devel
Cc: Aleksandar Rikalo, Paul Burton, qemu-arm, Gerd Hoffmann,
Peter Maydell, Philippe Mathieu-Daudé, Daan De Meyer
For consistency with LOAD_IMAGE_MAX_DECOMPRESSED_BYTES.
Signed-off-by: Daan De Meyer <daan.j.demeyer@gmail.com>
---
hw/core/loader-fit.c | 2 +-
hw/core/loader.c | 2 +-
include/hw/loader.h | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/hw/core/loader-fit.c b/hw/core/loader-fit.c
index 2dea485ae0..5895e89f22 100644
--- a/hw/core/loader-fit.c
+++ b/hw/core/loader-fit.c
@@ -70,7 +70,7 @@ static void *fit_load_image_alloc(const void *itb, const char *name,
}
if (!strcmp(comp, "gzip")) {
- uncomp_len = UBOOT_MAX_GUNZIP_BYTES;
+ uncomp_len = UBOOT_MAX_DECOMPRESSED_BYTES;
uncomp_data = g_malloc(uncomp_len);
uncomp_len = gunzip(uncomp_data, uncomp_len, (void *) data, sz);
diff --git a/hw/core/loader.c b/hw/core/loader.c
index f940b6a227..090af59df2 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -739,7 +739,7 @@ static ssize_t load_uboot_image(const char *filename, hwaddr *ep,
ssize_t bytes;
compressed_data = data;
- max_bytes = UBOOT_MAX_GUNZIP_BYTES;
+ max_bytes = UBOOT_MAX_DECOMPRESSED_BYTES;
data = g_malloc(max_bytes);
bytes = gunzip(data, max_bytes, compressed_data, hdr->ih_size);
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 3371de506f..cbcb274fce 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -343,7 +343,7 @@ ssize_t rom_add_option(const char *file, int32_t bootindex);
/* This is the usual maximum in uboot, so if a uImage overflows this, it would
* overflow on real hardware too. */
-#define UBOOT_MAX_GUNZIP_BYTES (64 << 20)
+#define UBOOT_MAX_DECOMPRESSED_BYTES (64 << 20)
typedef struct RomGap {
hwaddr base;
--
2.51.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4 3/4] Use g_autofree in unpack_efi_zboot_image()
2025-11-24 12:35 [PATCH v4 0/4] Add support for zboot images compressed with zstd Daan De Meyer
2025-11-24 12:35 ` [PATCH v4 1/4] Rename LOAD_IMAGE_MAX_GUNZIP_BYTES to LOAD_IMAGE_MAX_DECOMPRESSED_BYTES Daan De Meyer
2025-11-24 12:35 ` [PATCH v4 2/4] Rename UBOOT_MAX_GUNZIP_BYTES to UBOOT_MAX_DECOMPRESSED_BYTES Daan De Meyer
@ 2025-11-24 12:35 ` Daan De Meyer
2025-11-24 12:35 ` [PATCH v4 4/4] Add support for zboot images compressed with zstd Daan De Meyer
2025-11-24 12:41 ` [PATCH v4 0/4] " Philippe Mathieu-Daudé
4 siblings, 0 replies; 7+ messages in thread
From: Daan De Meyer @ 2025-11-24 12:35 UTC (permalink / raw)
To: qemu-devel
Cc: Aleksandar Rikalo, Paul Burton, qemu-arm, Gerd Hoffmann,
Peter Maydell, Philippe Mathieu-Daudé, Daan De Meyer,
Daniel P. Berrangé
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>
---
hw/core/loader.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 090af59df2..d74e33ceb6 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -882,7 +882,7 @@ struct linux_efi_zboot_header {
ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size)
{
const struct linux_efi_zboot_header *header;
- uint8_t *data = NULL;
+ g_autofree uint8_t *data = NULL;
ssize_t ploff, plsize;
ssize_t bytes;
size_t max_bytes = LOAD_IMAGE_MAX_DECOMPRESSED_BYTES;
@@ -921,12 +921,11 @@ ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size)
bytes = gunzip(data, max_bytes, *buffer + ploff, plsize);
if (bytes < 0) {
fprintf(stderr, "failed to decompress EFI zboot image\n");
- g_free(data);
return -1;
}
g_free(*buffer);
- *buffer = g_realloc(data, bytes);
+ *buffer = g_realloc(g_steal_pointer(&data), bytes);
*size = bytes;
return bytes;
}
--
2.51.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4 4/4] Add support for zboot images compressed with zstd
2025-11-24 12:35 [PATCH v4 0/4] Add support for zboot images compressed with zstd Daan De Meyer
` (2 preceding siblings ...)
2025-11-24 12:35 ` [PATCH v4 3/4] Use g_autofree in unpack_efi_zboot_image() Daan De Meyer
@ 2025-11-24 12:35 ` Daan De Meyer
2025-11-24 12:41 ` [PATCH v4 0/4] " Philippe Mathieu-Daudé
4 siblings, 0 replies; 7+ messages in thread
From: Daan De Meyer @ 2025-11-24 12:35 UTC (permalink / raw)
To: qemu-devel
Cc: Aleksandar Rikalo, Paul Burton, qemu-arm, Gerd Hoffmann,
Peter Maydell, Philippe Mathieu-Daudé, Daan De Meyer,
Daniel P. Berrangé
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>
---
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 d74e33ceb6..8924767e7d 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -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 */
@@ -901,14 +906,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);
@@ -918,7 +915,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;
--
2.51.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v4 2/4] Rename UBOOT_MAX_GUNZIP_BYTES to UBOOT_MAX_DECOMPRESSED_BYTES
2025-11-24 12:35 ` [PATCH v4 2/4] Rename UBOOT_MAX_GUNZIP_BYTES to UBOOT_MAX_DECOMPRESSED_BYTES Daan De Meyer
@ 2025-11-24 12:39 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 7+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-11-24 12:39 UTC (permalink / raw)
To: Daan De Meyer, qemu-devel
Cc: Aleksandar Rikalo, Paul Burton, qemu-arm, Gerd Hoffmann,
Peter Maydell
On 24/11/25 13:35, Daan De Meyer wrote:
> For consistency with LOAD_IMAGE_MAX_DECOMPRESSED_BYTES.
>
> Signed-off-by: Daan De Meyer <daan.j.demeyer@gmail.com>
> ---
> hw/core/loader-fit.c | 2 +-
> hw/core/loader.c | 2 +-
> include/hw/loader.h | 2 +-
> 3 files changed, 3 insertions(+), 3 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v4 0/4] Add support for zboot images compressed with zstd
2025-11-24 12:35 [PATCH v4 0/4] Add support for zboot images compressed with zstd Daan De Meyer
` (3 preceding siblings ...)
2025-11-24 12:35 ` [PATCH v4 4/4] Add support for zboot images compressed with zstd Daan De Meyer
@ 2025-11-24 12:41 ` Philippe Mathieu-Daudé
4 siblings, 0 replies; 7+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-11-24 12:41 UTC (permalink / raw)
To: Daan De Meyer, qemu-devel
Cc: Aleksandar Rikalo, Paul Burton, qemu-arm, Gerd Hoffmann,
Peter Maydell
On 24/11/25 13:35, Daan De Meyer wrote:
> Fedora arm64 has an EFI_ZBOOT kernel image compressed
> with zstd. Let's make sure we can use it for direct kernel
> boot with qemu.
>
> Daan De Meyer (4):
> Rename LOAD_IMAGE_MAX_GUNZIP_BYTES to
> LOAD_IMAGE_MAX_DECOMPRESSED_BYTES
> Rename UBOOT_MAX_GUNZIP_BYTES to UBOOT_MAX_DECOMPRESSED_BYTES
> Use g_autofree in unpack_efi_zboot_image()
> Add support for zboot images compressed with zstd
Thanks, queued for 11.0.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-11-24 12:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-24 12:35 [PATCH v4 0/4] Add support for zboot images compressed with zstd Daan De Meyer
2025-11-24 12:35 ` [PATCH v4 1/4] Rename LOAD_IMAGE_MAX_GUNZIP_BYTES to LOAD_IMAGE_MAX_DECOMPRESSED_BYTES Daan De Meyer
2025-11-24 12:35 ` [PATCH v4 2/4] Rename UBOOT_MAX_GUNZIP_BYTES to UBOOT_MAX_DECOMPRESSED_BYTES Daan De Meyer
2025-11-24 12:39 ` Philippe Mathieu-Daudé
2025-11-24 12:35 ` [PATCH v4 3/4] Use g_autofree in unpack_efi_zboot_image() Daan De Meyer
2025-11-24 12:35 ` [PATCH v4 4/4] Add support for zboot images compressed with zstd Daan De Meyer
2025-11-24 12:41 ` [PATCH v4 0/4] " Philippe Mathieu-Daudé
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).