aarch64: Allow -kernel option to take a gzip-compressed kernel
v8 cover aarch64: Allow -kernel option to take a gzip-compressed kernel
Changes since v7:
- Rebase against current head & retest.
- Don't use `allow_compressed_kernel' boolean, but use arm_feature test at point of use instead.
- Added Reviewed-by tags (thanks Peter Crosthwaite).
Rich.
PATCH v8 1/2 loader: Add load_image_gzipped function.
As the name suggests this lets you load a ROM/disk image that is gzipped. It is uncompressed before storing it in guest memory.
--- hw/core/loader.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/loader.h | 1 + 2 files changed, 49 insertions(+)
hw/core/loader.c +48 -0
@@ -577,6 +577,54 @@ int load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz)return load_uboot_image (filename,NULL , &addr,NULL ,IH_TYPE_RAMDISK ); } +/* This simply prevents g_malloc in the function below from allocating +* a huge amount of memory, by placing a limit on the maximum +* uncompressed image size that load_image_gzipped will read. +*/ +#define LOAD_IMAGE_MAX_GUNZIP_BYTES (256 << 20) + +/* Load a gzip-compressed kernel. */ +int load_image_gzipped (const char *filename,hwaddr addr,uint64_t max_sz) +{ +uint8_t *compressed_data =NULL ; +uint8_t *data =NULL ; +gsize len; +ssize_t bytes; +int ret =-1 ; + +if (!g_file_get_contents (filename, (char **) &compressed_data, &len, +NULL )) { + goto out; + } + +/* Is it a gzip-compressed file? */ +if (len <2 || + compressed_data[0 ] !=0x1f || + compressed_data[1 ] !=0x8b ) { + goto out; + } + +if (max_sz >LOAD_IMAGE_MAX_GUNZIP_BYTES ) { + max_sz =LOAD_IMAGE_MAX_GUNZIP_BYTES ; + } + + data =g_malloc (max_sz); + bytes =gunzip (data, max_sz, compressed_data, len); +if (bytes <0 ) { +fprintf (stderr,"%s: unable to decompress gzipped kernel file\n" , + filename); + goto out; + } + +rom_add_blob_fixed (filename, data, bytes, addr); + ret = bytes; + + out: +g_free (compressed_data); +g_free (data); +return ret; +} +/* * Functions for reboot-persistent memory regions. * - used for vga bios and option roms.
include/hw/loader.h +1 -0
@@ -15,6 +15,7 @@ int get_image_size(const char *filename);int load_image (const char *filename,uint8_t *addr);/* deprecated */ int load_image_targphys (const char *filename,hwaddr ,uint64_t max_sz); +int load_image_gzipped (const char *filename,hwaddr addr,uint64_t max_sz);#define ELF_LOAD_FAILED -1#define ELF_LOAD_NOT_ELF -2
Signature · 1 line
2.0.4
PATCH v8 2/2 aarch64: Allow -kernel option to take a gzip-compressed kernel.
In reply to Richard W.M. JonesOn aarch64 it is the bootloader's job to uncompress the kernel. UEFI and u-boot bootloaders do this automatically when the kernel is gzip-compressed.
However the qemu -kernel option does not do this. The following command does not work:
qemu-system-aarch64 [...] -kernel /boot/vmlinuz
because it tries to execute the gzip-compressed data.
This commit lets gzip-compressed kernels be uncompressed transparently.
Currently this is only done when emulating aarch64.
--- hw/arm/boot.c | 7 +++++++ 1 file changed, 7 insertions(+)
hw/arm/boot.c +7 -0
@@ -514,6 +514,13 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) kernel_size =load_uimage (info->kernel_filename, &entry,NULL , &is_linux); } +/* On aarch64, it's the bootloader's job to uncompress the kernel. */ +if (arm_feature (&cpu->env,ARM_FEATURE_AARCH64 ) && kernel_size <0 ) { + entry = info->loader_start + kernel_load_offset; + kernel_size =load_image_gzipped (info->kernel_filename, entry, + info->ram_size - kernel_load_offset); + is_linux =1 ; + }if (kernel_size <0 ) { entry = info->loader_start + kernel_load_offset; kernel_size = load_image_targphys(info->kernel_filename, entry,
Signature · 1 line
2.0.4
Quoted 8 lines · Richard W.M. Jones
Changes since v7:
- Rebase against current head & retest.
- Don't use `allow_compressed_kernel' boolean, but use
arm_featuretest at point of use instead.- Added Reviewed-by tags (thanks Peter Crosthwaite).
Thanks; applied to target-arm.next.
-- PMM