From 4ced99fb020fb37335399a1fa52b2a7414321db9 Mon Sep 17 00:00:00 2001 From: Richard W.M. Jones Date: Aug 20 2014 21:28:16 +0000 Subject: Add patch for aarch64 which uncompresses -kernel parameter (in arm.next). --- diff --git a/0001-loader-Add-load_image_gzipped-function.patch b/0001-loader-Add-load_image_gzipped-function.patch new file mode 100644 index 0000000..5be7cd9 --- /dev/null +++ b/0001-loader-Add-load_image_gzipped-function.patch @@ -0,0 +1,92 @@ +From ddf2a3a69486376897ae654c8f1f0aa8cbae6c24 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Mon, 4 Aug 2014 12:25:08 +0100 +Subject: [PATCH 1/2] loader: Add load_image_gzipped function. +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +As the name suggests this lets you load a ROM/disk image that is +gzipped. It is uncompressed before storing it in guest memory. + +Signed-off-by: Richard W.M. Jones +Reviewed-by: Alex Bennée +--- + hw/core/loader.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ + include/hw/loader.h | 1 + + 2 files changed, 49 insertions(+) + +diff --git a/hw/core/loader.c b/hw/core/loader.c +index 2bf6b8f..83136e8 100644 +--- a/hw/core/loader.c ++++ b/hw/core/loader.c +@@ -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. +diff --git a/include/hw/loader.h b/include/hw/loader.h +index 796cbf9..00c9117 100644 +--- a/include/hw/loader.h ++++ b/include/hw/loader.h +@@ -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 +-- +2.0.4 + diff --git a/0002-aarch64-Allow-kernel-option-to-take-a-gzip-compresse.patch b/0002-aarch64-Allow-kernel-option-to-take-a-gzip-compresse.patch new file mode 100644 index 0000000..d2521c1 --- /dev/null +++ b/0002-aarch64-Allow-kernel-option-to-take-a-gzip-compresse.patch @@ -0,0 +1,68 @@ +From fc77c3116f7e4b3400e576c51e73ade2edee350a Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Tue, 29 Jul 2014 23:32:31 +0100 +Subject: [PATCH 2/2] aarch64: Allow -kernel option to take a gzip-compressed + kernel. +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +On 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. + +Signed-off-by: Richard W.M. Jones +Reviewed-by: Alex Bennée +--- + hw/arm/boot.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/hw/arm/boot.c b/hw/arm/boot.c +index 1241761..c71c4d5 100644 +--- a/hw/arm/boot.c ++++ b/hw/arm/boot.c +@@ -448,6 +448,7 @@ static void do_cpu_reset(void *opaque) + void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) + { + CPUState *cs = CPU(cpu); ++ int allow_compressed_kernels = 0; + int kernel_size; + int initrd_size; + int is_linux = 0; +@@ -469,6 +470,7 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) + primary_loader = bootloader_aarch64; + kernel_load_offset = KERNEL64_LOAD_ADDR; + elf_machine = EM_AARCH64; ++ allow_compressed_kernels = 1; + } else { + primary_loader = bootloader; + kernel_load_offset = KERNEL_LOAD_ADDR; +@@ -514,6 +516,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 (allow_compressed_kernels && 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, +-- +2.0.4 + diff --git a/qemu.spec b/qemu.spec index 2650295..028edfb 100644 --- a/qemu.spec +++ b/qemu.spec @@ -192,6 +192,9 @@ Source12: bridge.conf # qemu-kvm back compat wrapper Source13: qemu-kvm.sh +Patch1: 0001-loader-Add-load_image_gzipped-function.patch +Patch2: 0002-aarch64-Allow-kernel-option-to-take-a-gzip-compresse.patch + BuildRequires: SDL2-devel BuildRequires: zlib-devel BuildRequires: which @@ -716,6 +719,9 @@ CAC emulation development files. %prep %setup -q +%patch1 -p1 +%patch2 -p1 + %build %if %{with kvmonly} @@ -1494,13 +1500,16 @@ getent passwd qemu >/dev/null || \ %endif %changelog +* Wed Aug 20 2014 Richard W.M. Jones 2:2.1.0-5 +- Add patch for aarch64 which uncompresses -kernel parameter (in arm.next). + * Mon Aug 18 2014 Dan Horák - 2:2.1.0-4 - Don't fail build due failing tests on s390 (#1100971) * Sun Aug 17 2014 Fedora Release Engineering - 2:2.1.0-3 - Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild -* Sun Aug 3 2014 Richard W.M. Jones 2:2.1.0-2 +* Sun Aug 03 2014 Richard W.M. Jones 2:2.1.0-2 - Update to qemu 2.1.0 final released version. - Drop optimization flags when compiling on aarch64 (see RHBZ#1126199).