]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 LT |
2 | #include <stdio.h> |
3 | #include <string.h> | |
4 | #include <stdlib.h> | |
5 | ||
6 | int main( int argc, const char * argv [] ) | |
7 | { | |
8 | const char * varname; | |
9 | int i = 0; | |
10 | int c; | |
11 | int id = 0; | |
12 | ||
13 | if(argv[1] && strcmp(argv[1],"-i")==0) | |
14 | { | |
15 | argv++; | |
16 | argc--; | |
17 | id=1; | |
18 | } | |
19 | ||
20 | if(argc==1) | |
21 | { | |
22 | fprintf(stderr, "bin2hex: [-i] firmware\n"); | |
23 | exit(1); | |
24 | } | |
25 | ||
26 | varname = argv[1]; | |
27 | printf( "/* automatically generated by bin2hex */\n" ); | |
28 | printf( "static unsigned char %s [] %s =\n{\n", varname , id?"__initdata":""); | |
29 | ||
30 | while ( ( c = getchar( ) ) != EOF ) | |
31 | { | |
32 | if ( i != 0 && i % 10 == 0 ) | |
33 | printf( "\n" ); | |
34 | printf( "0x%02lx,", c & 0xFFl ); | |
35 | i++; | |
36 | } | |
37 | ||
38 | printf( "};\nstatic int %sLen = %d;\n", varname, i ); | |
39 | return 0; | |
40 | } |