Further simplify cbfs functions - don't pass iscomp to callers.
authorKevin O'Connor <kevin@koconnor.net>
Wed, 19 Aug 2009 02:21:10 +0000 (22:21 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Wed, 19 Aug 2009 02:21:10 +0000 (22:21 -0400)
The cbfs data copy function can determine if the file is compressed on
    its own - it doesn't need the iscomp parameter passed in.

src/coreboot.c
src/optionroms.c
src/ramdisk.c
src/util.h

index 4596ffdd2b79cbcd0f432ab19ef1dd881d4cb1e4..314d5c0d438c6a3d4ea49420ff1c2d1afa855524 100644 (file)
@@ -463,7 +463,7 @@ cbfs_findprefix(const char *prefix, struct cbfs_file *last)
 
 // Find a file with the given filename (possibly with ".lzma" extension).
 static struct cbfs_file *
-cbfs_finddatafile(const char *fname, int *iscomp)
+cbfs_finddatafile(const char *fname)
 {
     int fnlen = strlen(fname);
     struct cbfs_file *file = NULL;
@@ -471,28 +471,18 @@ cbfs_finddatafile(const char *fname, int *iscomp)
         file = cbfs_findprefix(fname, file);
         if (!file)
             return NULL;
-        if (file->filename[fnlen] == '\0') {
-            *iscomp = 0;
+        if (file->filename[fnlen] == '\0'
+            || strcmp(&file->filename[fnlen], ".lzma") == 0)
             return file;
-        }
-        if (strcmp(&file->filename[fnlen], ".lzma") == 0) {
-            *iscomp = 1;
-            return file;
-        }
     }
 }
 
-// Locate a datafile with the given prefix.
-struct cbfs_file *
-cbfs_finddataprefix(const char *prefix, struct cbfs_file *last, int *iscomp)
+// Determine whether the file has a ".lzma" extension.
+static int
+cbfs_iscomp(struct cbfs_file *file)
 {
-    struct cbfs_file *file = cbfs_findprefix(prefix, last);
-    if (!file)
-        return NULL;
     int fnamelen = strlen(file->filename);
-    *iscomp = (fnamelen > 5
-               && strcmp(&file->filename[fnamelen-5], ".lzma") == 0);
-    return file;
+    return fnamelen > 5 && strcmp(&file->filename[fnamelen-5], ".lzma") == 0;
 }
 
 // Return the filename of a given file.
@@ -504,24 +494,24 @@ cbfs_filename(struct cbfs_file *file)
 
 // Determine the uncompressed size of a datafile.
 u32
-cbfs_datasize(struct cbfs_file *file, int iscomp)
+cbfs_datasize(struct cbfs_file *file)
 {
     void *src = (void*)file + ntohl(file->offset);
-    if (iscomp)
+    if (cbfs_iscomp(file))
         return *(u32*)(src + LZMA_PROPERTIES_SIZE);
     return ntohl(file->len);
 }
 
 // Copy a file to memory (uncompressing if necessary)
 int
-cbfs_copyfile(struct cbfs_file *file, void *dst, u32 maxlen, int iscomp)
+cbfs_copyfile(struct cbfs_file *file, void *dst, u32 maxlen)
 {
     if (! CONFIG_COREBOOT_FLASH || !file)
         return -1;
 
     u32 size = ntohl(file->len);
     void *src = (void*)file + ntohl(file->offset);
-    if (iscomp)
+    if (cbfs_iscomp(file))
         // Compressed.
         return ulzma(dst, maxlen, src, size);
 
@@ -568,9 +558,7 @@ cbfs_copy_optionrom(void *dst, u32 maxlen, u32 vendev)
     *(u32*)&fname[12] = 0x6d6f722e; // ".rom"
     fname[16] = '\0';
 
-    int iscomp;
-    struct cbfs_file *file = cbfs_finddatafile(fname, &iscomp);
-    return cbfs_copyfile(file, dst, maxlen, iscomp);
+    return cbfs_copyfile(cbfs_finddatafile(fname), dst, maxlen);
 }
 
 struct cbfs_payload_segment {
index 15f67950b9f254e50b811b8f50e9f5a6eba5bfa7..0a5d85c1fc2609b4602bc6920a6431f65b4c1168 100644 (file)
@@ -227,12 +227,10 @@ run_cbfs_roms(const char *prefix, int isvga)
 {
     struct cbfs_file *file = NULL;
     for (;;) {
-        int iscomp = 0;
-        file = cbfs_finddataprefix(prefix, file, &iscomp);
+        file = cbfs_findprefix(prefix, file);
         if (!file)
             break;
-        int ret = cbfs_copyfile(file, (void*)RomEnd, BUILD_BIOS_ADDR - RomEnd
-                                , iscomp);
+        int ret = cbfs_copyfile(file, (void*)RomEnd, BUILD_BIOS_ADDR - RomEnd);
         if (ret > 0)
             init_optionrom((void*)RomEnd, 0, isvga);
     }
index cb78f4543ad67ed24df22bbc0bd27f9c8836693e..07f252300681752541bc624f9fb8bcfe349ede44 100644 (file)
@@ -19,11 +19,10 @@ ramdisk_setup()
         return;
 
     // Find image.
-    int iscomp;
-    struct cbfs_file *file = cbfs_finddataprefix("floppyimg/", NULL, &iscomp);
+    struct cbfs_file *file = cbfs_findprefix("floppyimg/", NULL);
     if (!file)
         return;
-    u32 size = cbfs_datasize(file, iscomp);
+    u32 size = cbfs_datasize(file);
     dprintf(3, "Found floppy file %s of size %d\n", cbfs_filename(file), size);
     int ftype = find_floppy_type(size);
     if (ftype < 0) {
@@ -41,7 +40,7 @@ ramdisk_setup()
     add_e820(loc, size, E820_RESERVED);
 
     // Copy image into ram.
-    cbfs_copyfile(file, (void*)loc, size, iscomp);
+    cbfs_copyfile(file, (void*)loc, size);
 
     // Setup driver.
     dprintf(1, "Mapping CBFS floppy %s to addr %x\n", cbfs_filename(file), loc);
index 0e4f84b3ae9534887c84ec4063250a75b8430466..b8d82332173d967dd2636c37ae0019f0f74350a0 100644 (file)
@@ -222,11 +222,9 @@ void smbios_init(void);
 // coreboot.c
 struct cbfs_file;
 struct cbfs_file *cbfs_findprefix(const char *prefix, struct cbfs_file *last);
-struct cbfs_file *cbfs_finddataprefix(const char *prefix, struct cbfs_file *last
-                                      , int *iscomp);
-u32 cbfs_datasize(struct cbfs_file *file, int iscomp);
+u32 cbfs_datasize(struct cbfs_file *file);
 const char *cbfs_filename(struct cbfs_file *file);
-int cbfs_copyfile(struct cbfs_file *file, void *dst, u32 maxlen, int iscomp);
+int cbfs_copyfile(struct cbfs_file *file, void *dst, u32 maxlen);
 int cbfs_copy_optionrom(void *dst, u32 maxlen, u32 vendev);
 void cbfs_run_payload(struct cbfs_file *file);