]> git.sur5r.net Git - u-boot/blob - tools/bin2header.c
Prepare v2016.09.01
[u-boot] / tools / bin2header.c
1 /* bin2header.c - program to convert binary file into a C structure
2  * definition to be included in a header file.
3  *
4  * (C) Copyright 2008 by Harald Welte <laforge@openmoko.org>
5  *
6  * SPDX-License-Identifier:     GPL-2.0+
7  */
8
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <unistd.h>
12
13 int main(int argc, char **argv)
14 {
15         if (argc < 2) {
16                 fprintf(stderr, "%s needs one argument: the structure name\n",
17                         argv[0]);
18                 exit(1);
19         }
20
21         printf("/* bin2header output - automatically generated */\n");
22         printf("unsigned char %s[] = {\n", argv[1]);
23
24         while (1) {
25                 int i, nread;
26                 unsigned char buf[10];
27                 nread = read(0, buf, sizeof(buf));
28                 if (nread <= 0)
29                         break;
30
31                 printf("\t");
32                 for (i = 0; i < nread - 1; i++)
33                         printf("0x%02x, ", buf[i]);
34
35                 printf("0x%02x,\n", buf[nread-1]);
36         }
37
38         printf("};\n");
39
40         exit(0);
41 }