hw/loader: split out load_image_gzipped_buffer()
In the next patch we'd like to reuse the image decompression facility without installing the output as a ROM at a specific guest-phys address. In addition, expose LOAD_IMAGE_MAX_GUNZIP_BYTES, because that's a straightforward "max_sz" argument for the new load_image_gzipped_buffer(). Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 1419250305-31062-10-git-send-email-pbonzini@redhat.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
578f3c7b08
commit
7d48a0f721
@ -614,14 +614,9 @@ int load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz)
|
|||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This simply prevents g_malloc in the function below from allocating
|
/* Load a gzip-compressed kernel to a dynamically allocated buffer. */
|
||||||
* a huge amount of memory, by placing a limit on the maximum
|
int load_image_gzipped_buffer(const char *filename, uint64_t max_sz,
|
||||||
* uncompressed image size that load_image_gzipped will read.
|
uint8_t **buffer)
|
||||||
*/
|
|
||||||
#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 *compressed_data = NULL;
|
||||||
uint8_t *data = NULL;
|
uint8_t *data = NULL;
|
||||||
@ -653,8 +648,11 @@ int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
rom_add_blob_fixed(filename, data, bytes, addr);
|
/* trim to actual size and return to caller */
|
||||||
|
*buffer = g_realloc(data, bytes);
|
||||||
ret = bytes;
|
ret = bytes;
|
||||||
|
/* ownership has been transferred to caller */
|
||||||
|
data = NULL;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
g_free(compressed_data);
|
g_free(compressed_data);
|
||||||
@ -662,6 +660,20 @@ int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Load a gzip-compressed kernel. */
|
||||||
|
int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz)
|
||||||
|
{
|
||||||
|
int bytes;
|
||||||
|
uint8_t *data;
|
||||||
|
|
||||||
|
bytes = load_image_gzipped_buffer(filename, max_sz, &data);
|
||||||
|
if (bytes != -1) {
|
||||||
|
rom_add_blob_fixed(filename, data, bytes, addr);
|
||||||
|
g_free(data);
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Functions for reboot-persistent memory regions.
|
* Functions for reboot-persistent memory regions.
|
||||||
* - used for vga bios and option roms.
|
* - used for vga bios and option roms.
|
||||||
|
@ -16,6 +16,15 @@ int load_image(const char *filename, uint8_t *addr); /* deprecated */
|
|||||||
ssize_t load_image_size(const char *filename, void *addr, size_t size);
|
ssize_t load_image_size(const char *filename, void *addr, size_t size);
|
||||||
int load_image_targphys(const char *filename, hwaddr,
|
int load_image_targphys(const char *filename, hwaddr,
|
||||||
uint64_t max_sz);
|
uint64_t max_sz);
|
||||||
|
|
||||||
|
/* This is the limit on the maximum uncompressed image size that
|
||||||
|
* load_image_gzipped_buffer() and load_image_gzipped() will read. It prevents
|
||||||
|
* g_malloc() in those functions from allocating a huge amount of memory.
|
||||||
|
*/
|
||||||
|
#define LOAD_IMAGE_MAX_GUNZIP_BYTES (256 << 20)
|
||||||
|
|
||||||
|
int load_image_gzipped_buffer(const char *filename, uint64_t max_sz,
|
||||||
|
uint8_t **buffer);
|
||||||
int load_image_gzipped(const char *filename, hwaddr addr, 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_FAILED -1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user