Patchwork pc_sysfw: old_pc_system_rom_init(): improve error messages

login
register
mail settings
Submitter Luiz Capitulino
Date June 28, 2012, 4:58 p.m.
Message ID <20120628135809.56bb87d3@doriath.home>
Download mbox | patch
Permalink /patch/167929/
State New
Headers show

Comments

Luiz Capitulino - June 28, 2012, 4:58 p.m.
Also say why loading the bios has failed.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hw/pc_sysfw.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

Patch

diff --git a/hw/pc_sysfw.c b/hw/pc_sysfw.c
index b45f0ac..5670651 100644
--- a/hw/pc_sysfw.c
+++ b/hw/pc_sysfw.c
@@ -144,23 +144,28 @@  static void old_pc_system_rom_init(MemoryRegion *rom_memory)
         bios_name = BIOS_FILENAME;
     }
     filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
-    if (filename) {
-        bios_size = get_image_size(filename);
-    } else {
-        bios_size = -1;
+    if (!filename) {
+        goto exit_err;
+    }
+
+    bios_size = get_image_size(filename);
+    if (bios_size < 0) {
+        goto exit_err;
     }
-    if (bios_size <= 0 ||
+
+    if (bios_size == 0 ||
         (bios_size % 65536) != 0) {
-        goto bios_error;
+        fprintf(stderr, "qemu: PC BIOS '%s' has bad size (%d bytes)\n",
+                bios_name, bios_size);
+        exit(1);
     }
+
     bios = g_malloc(sizeof(*bios));
     memory_region_init_ram(bios, "pc.bios", bios_size);
     vmstate_register_ram_global(bios);
     memory_region_set_readonly(bios, true);
     ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1);
     if (ret != 0) {
-    bios_error:
-        fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name);
         exit(1);
     }
     if (filename) {
@@ -185,6 +190,12 @@  static void old_pc_system_rom_init(MemoryRegion *rom_memory)
     memory_region_add_subregion(rom_memory,
                                 (uint32_t)(-bios_size),
                                 bios);
+    return;
+
+exit_err:
+    fprintf(stderr, "qemu: could not load PC BIOS '%s' (%s)\n", bios_name,
+            strerror(errno));
+    exit(1);
 }
 
 void pc_system_firmware_init(MemoryRegion *rom_memory)