From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEbQz-00042C-O0 for qemu-devel@nongnu.org; Tue, 05 Aug 2014 05:53:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XEbQu-0007u4-Tw for qemu-devel@nongnu.org; Tue, 05 Aug 2014 05:53:33 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:47399 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEbQu-0007u0-NV for qemu-devel@nongnu.org; Tue, 05 Aug 2014 05:53:28 -0400 References: <1407152873-16772-1-git-send-email-rjones@redhat.com> <1407152873-16772-2-git-send-email-rjones@redhat.com> From: Alex =?utf-8?Q?Benn=C3=A9e?= Date: Tue, 05 Aug 2014 10:52:17 +0100 In-reply-to: <1407152873-16772-2-git-send-email-rjones@redhat.com> Message-ID: <8761i7l0tj.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH v5 1/2] loader: Add load_image_gzipped function. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Richard W.M. Jones" Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, qemu-devel@nongnu.org Richard W.M. Jones writes: > As the name suggests this lets you load a ROM/disk image that is > gzipped. It is uncompressed before storing it in guest memory. > > + > + /* Is it a gzip-compressed file? */ > + if (len < 2 || > + compressed_data[0] != '\x1f' || > + compressed_data[1] != '\x8b') { > + goto out; > + } I was looking to see if the zlib library provided the magic numbers or a verification routine here but I couldn't find it. > + > + 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 Reviewed-by: Alex Bennée -- Alex Bennée