diff options
Diffstat (limited to 'meta/packages/x-load/files/signGP.c')
-rw-r--r-- | meta/packages/x-load/files/signGP.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/meta/packages/x-load/files/signGP.c b/meta/packages/x-load/files/signGP.c new file mode 100644 index 0000000000..0e8ed07f52 --- /dev/null +++ b/meta/packages/x-load/files/signGP.c | |||
@@ -0,0 +1,73 @@ | |||
1 | // | ||
2 | // signGP.c | ||
3 | // Read the x-load.bin file and write out the x-load.bin.ift file. | ||
4 | // The signed image is the original pre-pended with the size of the image | ||
5 | // and the load address. If not entered on command line, file name is | ||
6 | // assumed to be x-load.bin in current directory and load address is | ||
7 | // 0x40200800. | ||
8 | |||
9 | #include <stdio.h> | ||
10 | #include <stdlib.h> | ||
11 | #include <fcntl.h> | ||
12 | #include <sys/stat.h> | ||
13 | #include <string.h> | ||
14 | #include <malloc.h> | ||
15 | |||
16 | |||
17 | main(int argc, char *argv[]) | ||
18 | { | ||
19 | int i; | ||
20 | char ifname[FILENAME_MAX], ofname[FILENAME_MAX], ch; | ||
21 | FILE *ifile, *ofile; | ||
22 | unsigned long loadaddr, len; | ||
23 | struct stat sinfo; | ||
24 | |||
25 | |||
26 | // Default to x-load.bin and 0x40200800. | ||
27 | strcpy(ifname, "x-load.bin"); | ||
28 | loadaddr = 0x40200800; | ||
29 | |||
30 | if ((argc == 2) || (argc == 3)) | ||
31 | strcpy(ifname, argv[1]); | ||
32 | |||
33 | if (argc == 3) | ||
34 | loadaddr = strtol(argv[2], NULL, 16); | ||
35 | |||
36 | // Form the output file name. | ||
37 | strcpy(ofname, ifname); | ||
38 | strcat(ofname, ".ift"); | ||
39 | |||
40 | // Open the input file. | ||
41 | ifile = fopen(ifname, "rb"); | ||
42 | if (ifile == NULL) { | ||
43 | printf("Cannot open %s\n", ifname); | ||
44 | exit(0); | ||
45 | } | ||
46 | |||
47 | // Get file length. | ||
48 | stat(ifname, &sinfo); | ||
49 | len = sinfo.st_size; | ||
50 | |||
51 | // Open the output file and write it. | ||
52 | ofile = fopen(ofname, "wb"); | ||
53 | if (ofile == NULL) { | ||
54 | printf("Cannot open %s\n", ofname); | ||
55 | fclose(ifile); | ||
56 | exit(0); | ||
57 | } | ||
58 | |||
59 | // Pad 1 sector of zeroes. | ||
60 | //ch = 0x00; | ||
61 | //for (i=0; i<0x200; i++) | ||
62 | // fwrite(&ch, 1, 1, ofile); | ||
63 | |||
64 | fwrite(&len, 1, 4, ofile); | ||
65 | fwrite(&loadaddr, 1, 4, ofile); | ||
66 | for (i=0; i<len; i++) { | ||
67 | fread(&ch, 1, 1, ifile); | ||
68 | fwrite(&ch, 1, 1, ofile); | ||
69 | } | ||
70 | |||
71 | fclose(ifile); | ||
72 | fclose(ofile); | ||
73 | } | ||