diff options
Diffstat (limited to 'util/cbfstool')
-rw-r--r-- | util/cbfstool/cbfstool.c | 9 | ||||
-rw-r--r-- | util/cbfstool/common.c | 16 | ||||
-rw-r--r-- | util/cbfstool/common.h | 2 |
3 files changed, 21 insertions, 6 deletions
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index 1d8b7c6b74..4c3a8c925e 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -83,7 +83,8 @@ static int cbfs_add(int argc, char **argv) cbfsfile = create_cbfs_file(cbfsname, filedata, &filesize, type, &base); if (add_file_to_cbfs(cbfsfile, filesize, base)) return 1; - writerom(romname, rom, romsize); + if (writerom(romname, rom, romsize)) + return 1; return 0; } @@ -131,7 +132,8 @@ static int cbfs_add_payload(int argc, char **argv) CBFS_COMPONENT_PAYLOAD, &base); if (add_file_to_cbfs(cbfsfile, filesize, base)) return 1; - writerom(romname, rom, romsize); + if (writerom(romname, rom, romsize)) + return 1; return 0; } @@ -180,7 +182,8 @@ static int cbfs_add_stage(int argc, char **argv) if (add_file_to_cbfs(cbfsfile, filesize, base)) return 1; - writerom(romname, rom, romsize); + if (writerom(romname, rom, romsize)) + return 1; return 0; } diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c index b071864b5c..8478c5a492 100644 --- a/util/cbfstool/common.c +++ b/util/cbfstool/common.c @@ -90,11 +90,23 @@ void *loadrom(const char *filename) return romarea; } -void writerom(const char *filename, void *start, uint32_t size) +int writerom(const char *filename, void *start, uint32_t size) { FILE *file = fopen(filename, "wb"); - fwrite(start, size, 1, file); + if (!file) { + fprintf(stderr, "Could not open '%s' for writing: ", filename); + perror(""); + return 1; + } + + if (fwrite(start, size, 1, file) != 1) { + fprintf(stderr, "Could not write to '%s': ", filename); + perror(""); + return 1; + } + fclose(file); + return 0; } int cbfs_file_header(uint32_t physaddr) diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h index eaf5e71f60..8d1b4d845d 100644 --- a/util/cbfstool/common.h +++ b/util/cbfstool/common.h @@ -44,7 +44,7 @@ uint32_t getfilesize(const char *filename); void *loadfile(const char *filename, uint32_t * romsize_p, void *content, int place); void *loadrom(const char *filename); -void writerom(const char *filename, void *start, uint32_t size); +int writerom(const char *filename, void *start, uint32_t size); int iself(unsigned char *input); |