From dcce5210c7c9b1f81cb1a968a9f9d91e2f719bb5 Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Sat, 25 Apr 2009 14:39:12 +0000 Subject: [PATCH] Make the CBFS file lookup skip file data instead of brute-forcing its way through it, looking for magic numbers. For one, it should speed up file access, esp. with many entries, but it also helps against false positives (eg. seabios, which contains the magic number for its own CBFS support, which _might_ just be aligned properly) Also avoid infinite loops and give up searching for new files for invalid magic numbers. Signed-off-by: Patrick Georgi Acked-by: Stefan Reinauer git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4210 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- src/lib/cbfs.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index 11098b6b86..3a79502fbb 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -96,14 +96,23 @@ struct cbfs_file *cbfs_find(const char *name) return NULL; offset = 0 - ntohl(header->romsize) + ntohl(header->offset); + int align= ntohl(header->align); + while(1) { struct cbfs_file *file = (struct cbfs_file *) offset; - if (cbfs_check_magic(file)) printk_info("Check %s\n", CBFS_NAME(file)); - if (cbfs_check_magic(file) && - !strcmp(CBFS_NAME(file), name)) + if (!cbfs_check_magic(file)) return NULL; + printk_info("Check %s\n", CBFS_NAME(file)); + if (!strcmp(CBFS_NAME(file), name)) return file; - offset += ntohl(header->align); + int flen = ntohl(file->len); + int foffset = ntohl(file->offset); + printk_spew("CBFS: follow chain: %p + %x + %x + align -> ", offset, foffset, flen); + + unsigned long oldoffset = offset; + offset = ALIGN(offset + foffset + flen, align); + printk_spew("%p\n", offset); + if (offset <= oldoffset) return NULL; if (offset < 0xFFFFFFFF - ntohl(header->romsize)) return NULL;