[lkrn] Add support for EFI zboot compressed kernel images

Current RISC-V and AArch64 kernels found in the wild tend not to be in
the documented kernel format, but are instead "EFI zboot" kernels
comprising a small EFI executable that decompresses and executes the
inner payload (which is a kernel in the expected format).

The EFI zboot header includes a recognisable magic value "zimg" along
with two fields describing the offset and length of the compressed
payload.  We can therefore treat this as an archive image format,
extracting the payload as-is and then relying on our existing ability
to execute compressed images.

This is sufficient to allow iPXE to execute the Fedora 42 RISC-V
kernel binary as currently published.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-05-20 14:14:26 +01:00
parent ecac4a34c7
commit e2f4dba2b7
2 changed files with 136 additions and 0 deletions

View File

@@ -56,6 +56,40 @@ struct lkrn_context {
physaddr_t fdt;
};
/** Compressed kernel image header */
struct zimg_header {
/** Reserved */
uint8_t reserved_a[4];
/** Magic */
uint32_t magic;
/** Offset to payload */
uint32_t offset;
/** Length of payload */
uint32_t len;
/** Reserved */
uint8_t reserved_b[8];
/** Compression type */
uint32_t type;
} __attribute__ (( packed ));
/** Compressed kernel image magic value */
#define ZIMG_MAGIC LKRN_MAGIC ( 'z', 'i', 'm', 'g' )
/** Compressed kernel image context */
struct zimg_context {
/** Offset to compressed data */
size_t offset;
/** Length of compressed data */
size_t len;
/** Compression type */
union {
/** Raw type */
uint32_t raw;
/** Printable string */
char string[5];
} type;
};
#include <bits/lkrn.h>
/**