qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 6/6] load_linux: change kernel header size allocatio


From: liguang
Subject: [Qemu-devel] [PATCH 6/6] load_linux: change kernel header size allocation
Date: Mon, 4 Feb 2013 10:27:58 +0800

it's not necessary to alloc 8K bytes for kernel
header, 0.5K is enough.

Signed-off-by: liguang <address@hidden>
---
 hw/pc.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index 0ccd775..b6b236f 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -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;
@@ -665,8 +668,7 @@ static void load_linux(void *fw_cfg,
         fprintf(stderr, "can't get size of kernel image file\n");
         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);
@@ -676,7 +678,7 @@ 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)
+    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
-- 
1.7.2.5




reply via email to

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