Add romfile_loadfile() helper function.
authorKevin O'Connor <kevin@koconnor.net>
Fri, 24 Dec 2010 16:15:26 +0000 (11:15 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Fri, 24 Dec 2010 16:15:26 +0000 (11:15 -0500)
Add function to find, malloc, and copy a romfile.  Use it in the
bootsplash and bootorder code.

src/boot.c
src/bootsplash.c
src/paravirt.c
src/paravirt.h

index 9c370237301dd422508dbe864bfe57f57ba9197c..4fb73ac9261dbf6bfb70e07527ed6645631fcb8b 100644 (file)
@@ -68,24 +68,10 @@ boot_setup(void)
             IPL.checkfloppysig = 1;
     }
 
-    u32 file = romfile_find("bootorder");
-    if (!file)
+    char *f = romfile_loadfile("bootorder", NULL);
+    if (!f)
         return;
 
-    int filesize = romfile_size(file);
-    dprintf(3, "bootorder file found (len %d)\n", filesize);
-
-    if (filesize == 0)
-        return;
-
-    char *f = malloc_tmphigh(filesize);
-
-    if (!f) {
-        warn_noalloc();
-        return;
-    }
-
-    romfile_copy(file, f, filesize);
     int i;
     IPL.fw_bootorder_count = 1;
     while(f[i]) {
index 8f42dfde209af4cf6616ce48fdbbe39a95e6b131..cf1a603e790fabdb9a1aba15c377c4151e8294c3 100644 (file)
@@ -149,17 +149,16 @@ enable_bootsplash(void)
     if (!CONFIG_BOOTSPLASH)
         return;
     dprintf(3, "Checking for bootsplash\n");
-    u32 file = romfile_find("bootsplash.jpg");
-    if (!file)
+    int filesize;
+    u8 *filedata = romfile_loadfile("bootsplash.jpg", &filesize);
+    if (!filedata)
         return;
-    int filesize = romfile_size(file);
 
     u8 *picture = NULL;
-    u8 *filedata = malloc_tmphigh(filesize);
     struct vesa_info *vesa_info = malloc_tmplow(sizeof(*vesa_info));
     struct vesa_mode_info *mode_info = malloc_tmplow(sizeof(*mode_info));
     struct jpeg_decdata *jpeg = jpeg_alloc();
-    if (!filedata || !jpeg || !vesa_info || !mode_info) {
+    if (!jpeg || !vesa_info || !mode_info) {
         warn_noalloc();
         goto done;
     }
@@ -186,8 +185,6 @@ enable_bootsplash(void)
             vendor, product);
 
     // Parse jpeg and get image size.
-    dprintf(5, "Copying bootsplash.jpg\n");
-    romfile_copy(file, filedata, filesize);
     dprintf(5, "Decoding bootsplash.jpg\n");
     int ret = jpeg_decode(jpeg, filedata);
     if (ret) {
index 308c809c3841bcbff3d9477ceba5bec0ba4fc845..74d3743e9df5ab418216704b413a177a5ba46929 100644 (file)
@@ -365,3 +365,30 @@ int qemu_cfg_read_file(u32 select, void *dst, u32 maxlen)
     qemu_cfg_read_entry(dst, select, len);
     return len;
 }
+
+// Helper function to find, malloc_tmphigh, and copy a romfile.  This
+// function adds a trailing zero to the malloc'd copy.
+void *
+romfile_loadfile(const char *name, int *psize)
+{
+    u32 file = romfile_find(name);
+    if (!file)
+        return NULL;
+
+    int filesize = romfile_size(file);
+    if (!filesize)
+        return NULL;
+
+    char *data = malloc_tmphigh(filesize+1);
+    if (!data) {
+        warn_noalloc();
+        return NULL;
+    }
+
+    dprintf(5, "Copying romfile '%s' (len %d)\n", name, filesize);
+    romfile_copy(file, data, filesize);
+    if (psize)
+        *psize = filesize;
+    data[filesize] = '\0';
+    return data;
+}
index 99c473b49b5af8f5d8f9abe96c6c5bc9bcbc85d0..7bf34b1465b344c19fd3f9ca8c18fc263f503621 100644 (file)
@@ -100,6 +100,7 @@ static inline const char* romfile_name(u32 fileid) {
         return cbfs_filename((void*)fileid);
     return qemu_cfg_name_file(fileid);
 }
+void *romfile_loadfile(const char *name, int *psize);
 
 u32 qemu_cfg_e820_entries(void);
 void* qemu_cfg_e820_load_next(void *addr);