Xconv_raw_to_c.c Source File
Back to the index.
src
devices
fonts
Xconv_raw_to_c.c
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2003-2009 Anders Gavare. All rights reserved.
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
6
*
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
12
*
13
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23
* SUCH DAMAGE.
24
*
25
*
26
* Convert a raw binary file into an unsigned char array, usable from C.
27
* Example:
28
*
29
* ./Xconv_raw_to_c somefile.raw hello
30
*
31
* gives the following output:
32
*
33
* unsigned char hello[] = {
34
* 35,10,35,32,32,77,97,107,101,102,
35
* 105,108,101,32,105,115,32,103,101,110,
36
* 101,114,97,116,101,100,32,102,114,111,
37
* 109,32,77,97,107,101,102,105,108,101,
38
* 46,115,107,101,108,46,32,68,111,110,
39
* ...
40
* }
41
*
42
* This is useful to include things such as trampoline code, which needs
43
* to be copied to some specific address at runtime, into a kernel image.
44
*/
45
46
#include <stdio.h>
47
#include <stdlib.h>
48
49
50
int
main
(
int
argc,
char
*argv[])
51
{
52
FILE *
f
;
53
unsigned
char
buf[50000];
54
int
len, i;
55
56
if
(argc < 3) {
57
fprintf(stderr,
"syntax: %s input_binary symbol_name\n"
,
58
argv[0]);
59
fprintf(stderr,
"Output is written to stdout.\n"
);
60
exit(1);
61
}
62
63
f
= fopen(argv[1],
"r"
);
64
printf(
"unsigned char %s[] = {"
, argv[2]);
65
len = fread(&buf, 1,
sizeof
(buf),
f
);
66
67
for
(i=0; i<len; i++) {
68
if
((i%10)==0)
69
printf(
"\n\t"
);
70
printf(
"%u"
, buf[i]);
71
if
(i < len-1)
72
printf(
","
);
73
}
74
printf(
"\n};\n"
);
75
76
return
0;
77
}
78
f
void f(int s, int func, int only_name)
Definition:
generate_arm_r.c:45
main
int main(int argc, char *argv[])
Definition:
Xconv_raw_to_c.c:50
Generated on Tue Mar 24 2020 14:04:48 for GXemul by
1.8.17