summaryrefslogtreecommitdiff
path: root/util/cbfstool
diff options
context:
space:
mode:
authorPatrick Georgi <patrick.georgi@coresystems.de>2009-09-30 11:21:18 +0000
committerPatrick Georgi <patrick.georgi@coresystems.de>2009-09-30 11:21:18 +0000
commit56f5fb734bb92efd147912794071ff57c35cab04 (patch)
tree8f5c053087594166fb260c92e3bbd7d177518f50 /util/cbfstool
parent53ad9f585ddc3f40671adcd92a6341eadd229a06 (diff)
downloadcoreboot-56f5fb734bb92efd147912794071ff57c35cab04.tar.xz
Fix endless loop when trying to add a too large file to CBFS,
and report the correct error code, and a hopefully helpful error message. Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de> Acked-by: Stefan Reinauer <stepan@coresystems.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4692 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/cbfstool')
-rw-r--r--util/cbfstool/cbfstool.c9
-rw-r--r--util/cbfstool/common.c60
2 files changed, 37 insertions, 32 deletions
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index 7fa7a8510a..bf8b3812b8 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -80,7 +80,8 @@ static int cbfs_add(int argc, char **argv)
}
cbfsfile =
create_cbfs_file(cbfsname, filedata, &filesize, type, &base);
- add_file_to_cbfs(cbfsfile, filesize, base);
+ if (add_file_to_cbfs(cbfsfile, filesize, base))
+ return 1;
writerom(romname, rom, romsize);
return 0;
}
@@ -127,7 +128,8 @@ static int cbfs_add_payload(int argc, char **argv)
cbfsfile =
create_cbfs_file(cbfsname, payload, &filesize,
CBFS_COMPONENT_PAYLOAD, &base);
- add_file_to_cbfs(cbfsfile, filesize, base);
+ if (add_file_to_cbfs(cbfsfile, filesize, base))
+ return 1;
writerom(romname, rom, romsize);
return 0;
}
@@ -175,7 +177,8 @@ static int cbfs_add_stage(int argc, char **argv)
create_cbfs_file(cbfsname, stage, &filesize,
CBFS_COMPONENT_STAGE, &base);
- add_file_to_cbfs(cbfsfile, filesize, base);
+ if (add_file_to_cbfs(cbfsfile, filesize, base))
+ return 1;
writerom(romname, rom, romsize);
return 0;
}
diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
index 7a9e6f1e4b..4c453995ed 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -40,7 +40,7 @@ void *loadfile(const char *filename, uint32_t * romsize_p, void *content,
content = malloc(*romsize_p);
if (!content) {
printf("Could not get %d bytes for file %s\n",
- *romsize_p, filename);
+ *romsize_p, filename);
exit(1);
}
} else if (place == SEEK_END)
@@ -205,40 +205,42 @@ int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location)
dprintf("copying data\n");
memcpy(phys_to_virt(current), content,
contentsize);
- break;
- }
- if (location == 0)
- continue;
-
- /* CBFS has the constraint that the chain always moves up in memory. so once
- we're past the place we seek, we don't need to look any further */
- if (current > location) {
- printf
- ("the requested space is not available\n");
- return 1;
+ return 0;
}
+ if (location != 0) {
+ /* CBFS has the constraint that the chain always moves up in memory. so once
+ we're past the place we seek, we don't need to look any further */
+ if (current > location) {
+ printf
+ ("the requested space is not available\n");
+ return 1;
+ }
- /* Is the requested location inside the current chunk? */
- if ((current < location)
- && ((location + contentsize) <= (current + length))) {
- /* Split it up. In the next iteration the code will be at the right place. */
- dprintf("split up. new length: %x\n",
- location - current -
- ntohl(thisfile->offset));
- thisfile->len =
- htonl(location - current -
- ntohl(thisfile->offset));
- struct cbfs_file *nextfile =
- cbfs_create_empty_file(location,
- length - (location -
- current));
+ /* Is the requested location inside the current chunk? */
+ if ((current < location)
+ && ((location + contentsize) <=
+ (current + length))) {
+ /* Split it up. In the next iteration the code will be at the right place. */
+ dprintf("split up. new length: %x\n",
+ location - current -
+ ntohl(thisfile->offset));
+ thisfile->len =
+ htonl(location - current -
+ ntohl(thisfile->offset));
+ struct cbfs_file *nextfile =
+ cbfs_create_empty_file(location,
+ length -
+ (location -
+ current));
+ }
}
}
current =
ALIGN(current + ntohl(thisfile->len) +
ntohl(thisfile->offset), align);
}
- return 0;
+ printf("Could not add the file to CBFS, it's probably too big.\n");
+ return 1;
}
/* returns new data block with cbfs_file header, suitable to dump into the ROM. location returns
@@ -263,7 +265,7 @@ void *create_cbfs_file(const char *filename, void *data, uint32_t * datasize,
void *newdata = malloc(*datasize + headersize);
if (!newdata) {
printf("Could not get %d bytes for CBFS file.\n", *datasize +
- headersize);
+ headersize);
exit(1);
}
struct cbfs_file *nextfile = (struct cbfs_file *)newdata;
@@ -285,7 +287,7 @@ int create_cbfs_image(const char *romfile, uint32_t _romsize,
unsigned char *romarea = malloc(romsize);
if (!romarea) {
printf("Could not get %d bytes of memory for CBFS image.\n",
- romsize);
+ romsize);
exit(1);
}
memset(romarea, 0xff, romsize);