Hi,

attached patch makes 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)


Signed-off-by: Patrick Georgi <[email protected]>

Index: src/lib/cbfs.c
===================================================================
--- src/lib/cbfs.c	(Revision 4206)
+++ src/lib/cbfs.c	(Arbeitskopie)
@@ -96,6 +96,8 @@
 		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));
@@ -103,8 +105,14 @@
 		    !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);
 
+		offset += foffset + flen;
+		offset = (offset + align-1) & ~(align-1);
+		printk_spew("%p\n", offset);
+
 		if (offset < 0xFFFFFFFF - ntohl(header->romsize))
 			return NULL;
 	}
-- 
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to