From 0088259ac0db04921dcc8e1ead5a51525eff116d Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 18 Aug 2009 22:21:10 -0400 Subject: [PATCH] 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. --- src/coreboot.c | 36 ++++++++++++------------------------ src/optionroms.c | 6 ++---- src/ramdisk.c | 7 +++---- src/util.h | 6 ++---- 4 files changed, 19 insertions(+), 36 deletions(-) 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 @@ 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 { 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 @@ 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); } 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 @@ 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); 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 @@ 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); -- 2.25.1