Further simplify cbfs functions - don't pass iscomp to callers.
The cbfs data copy function can determine if the file is compressed on
its own - it doesn't need the iscomp parameter passed in.
diff --git a/src/coreboot.c b/src/coreboot.c
index 4596ffd..314d5c0 100644
--- a/src/coreboot.c
+++ b/src/coreboot.c
@@ -463,7 +463,7 @@
// 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 @@
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 @@
// 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 @@
*(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 {
diff --git a/src/optionroms.c b/src/optionroms.c
index 15f6795..0a5d85c 100644
--- a/src/optionroms.c
+++ b/src/optionroms.c
@@ -227,12 +227,10 @@
{
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);
}
diff --git a/src/ramdisk.c b/src/ramdisk.c
index cb78f45..07f2523 100644
--- a/src/ramdisk.c
+++ b/src/ramdisk.c
@@ -19,11 +19,10 @@
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 @@
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);
diff --git a/src/util.h b/src/util.h
index 0e4f84b..b8d8233 100644
--- a/src/util.h
+++ b/src/util.h
@@ -222,11 +222,9 @@
// 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);