diff options
author | file <file@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2006-09-09 19:31:45 +0000 |
---|---|---|
committer | file <file@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2006-09-09 19:31:45 +0000 |
commit | 721dda88d1b4eb929ee867143aa963b31cfd8442 (patch) | |
tree | 2e0dc30ecbba36148497e1a60acde3cc78839860 /wct4xxp | |
parent | e3f1b9e15c2866a3ee71e010a7388263225fa264 (diff) |
Merged revisions 1458 via svnmerge from
https://origsvn.digium.com/svn/zaptel/branches/1.2
........
r1458 | file | 2006-09-09 15:29:31 -0400 (Sat, 09 Sep 2006) | 2 lines
Update firmware header generation tool to support paths being supplied with the filename (reported internally by Spiceland)
........
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@1459 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'wct4xxp')
-rw-r--r-- | wct4xxp/fw2h.c | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/wct4xxp/fw2h.c b/wct4xxp/fw2h.c index 5b6c73a..61ff53a 100644 --- a/wct4xxp/fw2h.c +++ b/wct4xxp/fw2h.c @@ -4,31 +4,46 @@ #include <unistd.h> #include <string.h> #include <errno.h> + int main(int argc, char *argv[]) { - char *c; - int fd; - FILE *f; - int res; - int x; + char *c = NULL, *fw_hdr_name = NULL; + int fd, res, x; + FILE *f = NULL; unsigned char buf[1024]; + + /* Make sure we have the right amount of arguments */ if (argc != 3) { - fprintf(stderr, "Usage: fw2h <infile> <outfile>"); + fprintf(stderr, "Usage: fw2h <infile> <outfile>\n"); exit(1); } - fd = open(argv[1], O_RDONLY); - if (fd < 0) { + + /* Make sure we can open the firmware in file */ + if ((fd = open(argv[1], O_RDONLY)) < 0) { fprintf(stderr, "Unable to open '%s': %s\n", argv[1], strerror(errno)); exit(1); } - f = fopen(argv[2], "w+"); - if (!f) { + + /* Make sure we can write out the firmware header file */ + if (!(f = fopen(argv[2], "w+"))) { fprintf(stderr, "Unable to open '%s' for writing: %s\n", argv[2], strerror(errno)); exit(1); } + + /* Strip file extension */ c = strrchr(argv[2], '.'); - if (c) *c = '\0'; - fprintf(f, "static unsigned char %s[] = {\t", argv[2]); + if (c) + *c = '\0'; + + /* Now determine the firmware header name */ + c = strrchr(argv[2], '/'); + if (c) + fw_hdr_name = ++c; + else + fw_hdr_name = argv[2]; + + /* Write out the firmware as a header file */ + fprintf(f, "static unsigned char %s[] = {\t", fw_hdr_name); while ((res = read(fd, buf, sizeof(buf))) > 0) { for (x = 0; x < res; x++) { if (!(x % 16)) @@ -37,10 +52,12 @@ int main(int argc, char *argv[]) } } fprintf(f, "\n};\n"); + if (res < 0) { fprintf(stderr, "Error reading file: %s\n", strerror(errno)); exit(1); } + fclose(f); close(fd); exit(0); |