summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Reinauer <stepan@coresystems.de>2010-06-24 13:37:59 +0000
committerStefan Reinauer <stepan@openbios.org>2010-06-24 13:37:59 +0000
commit9bb0438535d29329f6a01a136caa2f2ad79fdceb (patch)
treeed44ef0c6bd231abd1252487f04f66b1ff1079bf
parent980a69b8c20ad975553980ccb320bf25ff7c0b16 (diff)
downloadcoreboot-9bb0438535d29329f6a01a136caa2f2ad79fdceb.tar.xz
fix return value checks of cbfstool's writerom
Signed-off-by: Stefan Reinauer <stepan@coresystems.de> Acked-by: Stefan Reinauer <stepan@coresystems.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@5644 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
-rw-r--r--util/cbfstool/cbfstool.c9
-rw-r--r--util/cbfstool/common.c16
-rw-r--r--util/cbfstool/common.h2
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);