summaryrefslogtreecommitdiff
path: root/hw/core
diff options
context:
space:
mode:
authorMax Filippov <jcmvbkbc@gmail.com>2014-10-19 07:42:22 +0400
committerMax Filippov <jcmvbkbc@gmail.com>2014-11-03 00:59:10 +0300
commit25bda50a0c7241dcb247483af2b7f961632020cc (patch)
tree513752bed41420a65b2bf8b46b7d6cfe60745f59 /hw/core
parentc9e9521fcb840b14ec0ae9117b224ff8a71418da (diff)
downloadqemu-25bda50a0c7241dcb247483af2b7f961632020cc.tar.gz
hw/core/loader: implement address translation in uimage loader
Such address translation is needed when load address recorded in uImage is a virtual address. When the actual load address is requested, return untranslated address: user that needs the translated address can always apply translation function to it and those that need it untranslated don't need to do the inverse translation. Add translation function pointer and its parameter to uimage_load prototype. Update all existing users. No user-visible functional changes. Cc: qemu-stable@nongnu.org Signed-off-by: Max Filippov <jcmvbkbc@gmail.com> Reviewed-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'hw/core')
-rw-r--r--hw/core/loader.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 5f3a8598c5..bbe6eb3d82 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -477,7 +477,9 @@ static ssize_t gunzip(void *dst, size_t dstlen, uint8_t *src,
/* Load a U-Boot image. */
static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr,
- int *is_linux, uint8_t image_type)
+ int *is_linux, uint8_t image_type,
+ uint64_t (*translate_fn)(void *, uint64_t),
+ void *translate_opaque)
{
int fd;
int size;
@@ -511,6 +513,9 @@ static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr,
switch (hdr->ih_type) {
case IH_TYPE_KERNEL:
address = hdr->ih_load;
+ if (translate_fn) {
+ address = translate_fn(translate_opaque, address);
+ }
if (loadaddr) {
*loadaddr = hdr->ih_load;
}
@@ -587,15 +592,19 @@ out:
}
int load_uimage(const char *filename, hwaddr *ep, hwaddr *loadaddr,
- int *is_linux)
+ int *is_linux,
+ uint64_t (*translate_fn)(void *, uint64_t),
+ void *translate_opaque)
{
- return load_uboot_image(filename, ep, loadaddr, is_linux, IH_TYPE_KERNEL);
+ return load_uboot_image(filename, ep, loadaddr, is_linux, IH_TYPE_KERNEL,
+ translate_fn, translate_opaque);
}
/* Load a ramdisk. */
int load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz)
{
- return load_uboot_image(filename, NULL, &addr, NULL, IH_TYPE_RAMDISK);
+ return load_uboot_image(filename, NULL, &addr, NULL, IH_TYPE_RAMDISK,
+ NULL, NULL);
}
/* This simply prevents g_malloc in the function below from allocating