qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 5/5] target-arm: Adjust kernel load address for Imag


From: Greg Bellows
Subject: [Qemu-devel] [PATCH 5/5] target-arm: Adjust kernel load address for Image
Date: Mon, 19 Jan 2015 16:30:21 -0600

Adjust the kernel load offset by 0x8000 if not a zImage.

Signed-off-by: Pranavkumar Sawargaonkar <address@hidden>
Signed-off-by: Greg Bellows <address@hidden>
---
 hw/arm/boot.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 52ebd8b..b581cea 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -537,6 +537,32 @@ static void load_image_to_fw_cfg(FWCfgState *fw_cfg, 
uint16_t size_key,
     fw_cfg_add_bytes(fw_cfg, data_key, data, size);
 }
 
+static int check_load_zimage(const char *filename)
+{
+    int fd;
+    uint8_t buf[40];
+    uint32_t *p = (uint32_t *) &buf[36];
+
+    fd = open(filename, O_RDONLY | O_BINARY);
+    if (fd < 0) {
+        perror(filename);
+        return -1;
+    }
+
+    memset(buf, 0, sizeof(buf));
+    if (read(fd, buf, sizeof(buf)) != sizeof(buf)) {
+        close(fd);
+        return -1;
+    }
+
+    /* Check for zImage magic number */
+    if (*p == 0x016F2818) {
+        return 1;
+    }
+
+   return 0;
+}
+
 void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)
 {
     CPUState *cs;
@@ -613,7 +639,12 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info 
*info)
         primary_loader = bootloader;
         kernel_load_offset = KERNEL_LOAD_ADDR;
         elf_machine = EM_ARM;
-    }
+
+        if (!check_load_zimage(info->kernel_filename)) {
+            /* Assuming we are loading Image hence aligning it to 0x8000 */
+            kernel_load_offset -= 0x8000;
+        }
+   }
 
     info->dtb_filename = qemu_opt_get(qemu_get_machine_opts(), "dtb");
 
-- 
1.8.3.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]