This fixes a rather silly bug in cbfs with filenames > 16 characters.

Tested to booting linux with qemu. 
Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Acked-by: Myles Watson<mylesgw@gmail.com>



git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4276 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Ronald G. Minnich 2009-05-12 15:06:54 +00:00
parent 67ee8f86fb
commit 1c7cf64f1e
1 changed files with 19 additions and 19 deletions

View File

@ -95,7 +95,7 @@ int nextfile(struct rom *rom, struct cbfs_file *c, int offset)
* @param size the size of the file needed * @param size the size of the file needed
* @returns pointer to a cbfs_file struct. * @returns pointer to a cbfs_file struct.
*/ */
struct cbfs_file * rom_alloc(struct rom *rom, unsigned long size) struct cbfs_file * rom_alloc(struct rom *rom, const char *name, unsigned long size, int type)
{ {
/* walk the rom and find an empty file with a base > base, and a large enough size */ /* walk the rom and find an empty file with a base > base, and a large enough size */
unsigned int offset = ntohl(rom->header->offset); unsigned int offset = ntohl(rom->header->offset);
@ -103,6 +103,7 @@ struct cbfs_file * rom_alloc(struct rom *rom, unsigned long size)
struct cbfs_file *c = NULL; struct cbfs_file *c = NULL;
unsigned long nextoffset, truncoffset; unsigned long nextoffset, truncoffset;
struct cbfs_file *newfile = NULL; struct cbfs_file *newfile = NULL;
unsigned int csize;
while (offset < rom->fssize) { while (offset < rom->fssize) {
@ -132,10 +133,10 @@ struct cbfs_file * rom_alloc(struct rom *rom, unsigned long size)
/* figure out the real end of this file, and hence the size */ /* figure out the real end of this file, and hence the size */
/* compute where the next file is */ /* compute where the next file is */
nextoffset = ALIGN(ret + ntohl(c->len) + headersize((char *)CBFS_NAME(c)), nextoffset = ALIGN(ret + ntohl(c->len) + headersize(name),
ntohl(rom->header->align)); ntohl(rom->header->align));
/* compute where the end of this new file might be */ /* compute where the end of this new file might be */
truncoffset = ALIGN(ret + size + headersize((char *)CBFS_NAME(c)), truncoffset = ALIGN(ret + size + headersize(name),
ntohl(rom->header->align)); ntohl(rom->header->align));
/* If there is more than align bytes difference, create a new empty file */ /* If there is more than align bytes difference, create a new empty file */
/* later, we can add code to merge all empty files. */ /* later, we can add code to merge all empty files. */
@ -149,6 +150,16 @@ struct cbfs_file * rom_alloc(struct rom *rom, unsigned long size)
c->len = htonl(size); c->len = htonl(size);
csize = headersize(name);
strcpy(c->magic, COMPONENT_MAGIC);
c->offset = htonl(csize);
c->type = htonl(type);
setname(c, name);
return ((struct cbfs_file *)ROM_PTR(rom, ret)); return ((struct cbfs_file *)ROM_PTR(rom, ret));
} }
@ -264,32 +275,21 @@ int rom_extract(struct rom *rom, const char *name, void** buf, int *size )
*/ */
int rom_add(struct rom *rom, const char *name, void *buffer, int size, int type) int rom_add(struct rom *rom, const char *name, void *buffer, int size, int type)
{ {
struct cbfs_file *c = rom_alloc(rom, size); struct cbfs_file *c;
int offset;
int csize;
if (rom_find_by_name(rom, name)) { if (rom_find_by_name(rom, name)) {
ERROR("Component %s already exists in this rom\n", name); ERROR("Component %s already exists in this rom\n", name);
return -1; return -1;
} }
c = rom_alloc(rom, name, size, type);
if (c == NULL) { if (c == NULL) {
ERROR("There is no more room in this ROM\n"); ERROR("There is no more room in this ROM\n");
return -1; return -1;
} }
csize = headersize(name); memcpy(((unsigned char *)c) + ntohl(c->offset), buffer, size);
offset = ROM_OFFSET(rom, c);
strcpy(c->magic, COMPONENT_MAGIC);
c->offset = htonl(csize);
c->type = htonl(type);
setname(c, name);
memcpy(((unsigned char *)c) + csize, buffer, size);
return 0; return 0;
} }