Make mksyshdr safe for 64bits platforms (#1504)
[openwrt/svn-archive/archive.git] / tools / firmware-utils / src / mksyshdr.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <stdint.h>
4
5 int main(int argc, char* argv[])
6 {
7 FILE* fp;
8 uint32_t nImgSize;
9 char* pHeader1 = "CSYS";
10 uint32_t nHeader2 = 0x80500000;
11
12 if (argc != 3)
13 {
14 printf("Usage: mksyshdr <header file> <image file>\n");
15 return -1;
16 }
17
18 fp = fopen(argv[2], "rb");
19 if (fp != NULL)
20 {
21 fseek(fp, 0, SEEK_END);
22 nImgSize = ftell(fp);
23 fclose(fp);
24 fp = fopen(argv[1], "wb+");
25 if (fp != NULL)
26 {
27 fwrite(pHeader1, sizeof(char), 4, fp);
28 fwrite(&nHeader2, sizeof(nHeader2), 1, fp);
29 fwrite(&nImgSize, sizeof(nImgSize), 1, fp);
30 fclose(fp);
31 }
32 else
33 {
34 printf("Cannot create %s.\n", argv[1]);
35 return -1;
36 }
37 }
38 else
39 {
40 printf("Cannot open %s.\n", argv[2]);
41 return -1;
42 }
43
44 return 0;
45 }
46