diff options
author | Myles Watson <mylesgw@gmail.com> | 2009-04-20 21:38:11 +0000 |
---|---|---|
committer | Myles Watson <mylesgw@gmail.com> | 2009-04-20 21:38:11 +0000 |
commit | feaaedc1cf99c12b8d1ab4bb233a311044d7f8b0 (patch) | |
tree | 0cfe0d7189dbc3351ac08daae8422246a1bf7012 /util/cbfstool/fs.c | |
parent | 2cecce5740a23327a1095c6cba6e295e4b4d2963 (diff) |
This patch adds
cbfstool extract [FILE] [NAME]
It also factors out the csize calculation in rom_add, and fixes rom_delete so
that it can handle deleting the last entry.
Signed-off-by: Myles Watson <mylesgw@gmail.com>
Acked-by: Ronald G. Minnich <rminnich@gmail.com>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4144 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/cbfstool/fs.c')
-rw-r--r-- | util/cbfstool/fs.c | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/util/cbfstool/fs.c b/util/cbfstool/fs.c index c5e9892a8e..ff5741e37e 100644 --- a/util/cbfstool/fs.c +++ b/util/cbfstool/fs.c @@ -110,17 +110,43 @@ int rom_remove(struct rom *rom, const char *name) return -1; } - /* Get the next component - and copy it into the current - space */ + /* Get the next component - and copy it into the current space if it + * exists. If there is no next component, just delete c. */ n = rom_find_next(rom, c); + + if (n != NULL) { + memcpy(c, n, rom->fssize - ROM_OFFSET(rom, n)); + clear = ROM_OFFSET(rom, n) - ROM_OFFSET(rom, c); + } + else { /* No component after this one. */ + unsigned int csize; + csize = sizeof(struct cbfs_file) + ALIGN(strlen(name) + 1, 16); + clear = ntohl(c->len) + csize; + memcpy(c, ((void*)c) + clear, + rom->fssize - (ROM_OFFSET(rom, c)+clear)); + } - memcpy(c, n, rom->fssize - ROM_OFFSET(rom, n)); + /* Zero the new space, which is always at the end. */ + memset(ROM_PTR(rom, rom->fssize - clear), 0, clear); + + return 0; +} - clear = ROM_OFFSET(rom, n) - ROM_OFFSET(rom, c); +int rom_extract(struct rom *rom, const char *name, void** buf, unsigned long *size ) +{ + struct cbfs_file *c = rom_find_by_name(rom, name); + unsigned int csize; - /* Zero the new space */ - memset(ROM_PTR(rom, rom->fssize - clear), 0, clear); + if (c == NULL) { + ERROR("Component %s does not exist\n", name); + return -1; + } + + *size = ntohl(c->len); + + csize = sizeof(struct cbfs_file) + ALIGN(strlen(name) + 1, 16); + *buf = ((unsigned char *)c) + csize; return 0; } @@ -140,22 +166,20 @@ int rom_add(struct rom *rom, const char *name, void *buffer, int size, int type) return -1; } - csize = sizeof(struct cbfs_file) + ALIGN(strlen(name), 16) + size; + csize = sizeof(struct cbfs_file) + ALIGN(strlen(name) + 1, 16); offset = ROM_OFFSET(rom, c); - if (offset + csize >= rom->fssize) { + if (offset + csize + size > rom->fssize) { ERROR("There is not enough room in this ROM for this\n"); ERROR("component. I need %d bytes, only have %d bytes avail\n", - csize, rom->fssize - offset); + csize + size, rom->fssize - offset); return -1; } strcpy(c->magic, COMPONENT_MAGIC); - csize = sizeof(struct cbfs_file) + ALIGN(strlen(name) + 1, 16); - c->len = htonl(size); c->offset = htonl(csize); c->type = htonl(type); |