@@ -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");