@@ -637,6 +637,9 @@ static long get_file_size(FILE *f)
return size;
}
+#define HEADER_SIZE 0x200
+#define HEADER_SIGNATURE 0x53726448
+
static void load_linux(void *fw_cfg,
const char *kernel_filename,
const char *initrd_filename,
@@ -646,7 +649,7 @@ static void load_linux(void *fw_cfg,
uint16_t protocol;
int setup_size, kernel_size, initrd_size = 0, cmdline_size;
uint32_t initrd_max;
- uint8_t header[8192], *setup, *kernel, *initrd_data;
+ uint8_t header[HEADER_SIZE], *setup, *kernel, *initrd_data;
hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0;
FILE *f;
char *vmode;
@@ -667,8 +670,7 @@ static void load_linux(void *fw_cfg,
strerror(errno));
exit(1);
}
- if (fread(header, 1, MIN(ARRAY_SIZE(header), kernel_size), f) !=
- MIN(ARRAY_SIZE(header), kernel_size)) {
+ if (fread(header, 1, HEADER_SIZE, f) <= 0) {
fprintf(stderr, "qemu: could not load kernel '%s': %s\n",
kernel_filename, strerror(errno));
exit(1);
@@ -678,9 +680,9 @@ static void load_linux(void *fw_cfg,
#if 0
fprintf(stderr, "header magic: %#x\n", ldl_p(header+0x202));
#endif
- if (ldl_p(header+0x202) == 0x53726448)
- protocol = lduw_p(header+0x206);
- else {
+ if (ldl_p(header + 0x202) == HEADER_SIGNATURE) {
+ protocol = lduw_p(header + 0x206);
+ } else {
/* This looks like a multiboot kernel. If it is, let's stop
treating it like a Linux kernel. */
if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
it's not necessary to alloc 8K bytes for kernel header, 0.5K is enough. Signed-off-by: liguang <lig.fnst@cn.fujitsu.com> --- hw/pc.c | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-)