Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <sys/types.h> |
| 3 | #include <sys/stat.h> |
| 4 | #include <fcntl.h> |
| 5 | #include <unistd.h> |
| 6 | |
| 7 | int main(int argc, char **argv) |
| 8 | { |
| 9 | unsigned char buf[8]; |
| 10 | unsigned int i, count, bytes = 0; |
| 11 | FILE *fd_in, *fd_out; |
| 12 | |
| 13 | if (argc != 4) { |
| 14 | fprintf(stderr, "\n\tusage: %s <ucode.bin> <array_name> <output_name>\n\n", argv[0]); |
| 15 | return -1; |
| 16 | } |
| 17 | |
| 18 | fd_in = fopen(argv[1], "rb"); |
| 19 | if (fd_in == NULL) { |
| 20 | fprintf(stderr, "firmware file '%s' not found\n", argv[1]); |
| 21 | return -1; |
| 22 | } |
| 23 | |
| 24 | fd_out = fopen(argv[3], "w+"); |
| 25 | if (fd_out == NULL) { |
| 26 | fprintf(stderr, "cannot create output file '%s'\n", argv[3]); |
| 27 | return -1; |
| 28 | } |
| 29 | |
| 30 | fprintf(fd_out, "\n#include <asm/types.h>\n\nu8 %s [] = {", argv[2]); |
| 31 | |
| 32 | while ((count = fread(buf, 1, 8, fd_in)) > 0) { |
| 33 | fprintf(fd_out, "\n\t"); |
| 34 | for (i = 0; i < count; i++, bytes++) |
| 35 | fprintf(fd_out, "0x%02x, ", buf[i]); |
| 36 | } |
| 37 | |
| 38 | fprintf(fd_out, "\n};\n\n"); |
| 39 | |
| 40 | fclose(fd_in); |
| 41 | fclose(fd_out); |
| 42 | |
| 43 | return 0; |
| 44 | } |