Skip to content

Commit 6fb631e

Browse files
masahir0ytrini
authored andcommitted
scripts: import bin2c.c from Linux 4.10-rc6
Import scripts/basic/bin2c.c of Linux. In Linux Kernel, this file was moved to scripts/basic directory by commit 8370edea81e3 ("bin2c: move bin2c in scripts/basic"). In U-Boot, we do not need to follow that commit. Just put it in the original directory "scripts". Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Simon Glass <[email protected]>
1 parent 07a63c7 commit 6fb631e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

scripts/bin2c.c

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Unloved program to convert a binary on stdin to a C include on stdout
3+
*
4+
* Jan 1999 Matt Mackall <[email protected]>
5+
*
6+
* This software may be used and distributed according to the terms
7+
* of the GNU General Public License, incorporated herein by reference.
8+
*/
9+
10+
#include <stdio.h>
11+
12+
int main(int argc, char *argv[])
13+
{
14+
int ch, total = 0;
15+
16+
if (argc > 1)
17+
printf("const char %s[] %s=\n",
18+
argv[1], argc > 2 ? argv[2] : "");
19+
20+
do {
21+
printf("\t\"");
22+
while ((ch = getchar()) != EOF) {
23+
total++;
24+
printf("\\x%02x", ch);
25+
if (total % 16 == 0)
26+
break;
27+
}
28+
printf("\"\n");
29+
} while (ch != EOF);
30+
31+
if (argc > 1)
32+
printf("\t;\n\n#include <linux/types.h>\n\nconst size_t %s_size = %d;\n",
33+
argv[1], total);
34+
35+
return 0;
36+
}

0 commit comments

Comments
 (0)