]> git.ipfire.org Git - people/ms/u-boot.git/blame - tools/bin2header.c
usb: add support for generic EHCI devices
[people/ms/u-boot.git] / tools / bin2header.c
CommitLineData
0a823aa2
HW
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 *
1a459660 6 * SPDX-License-Identifier: GPL-2.0+
0a823aa2
HW
7 */
8
9#include <stdlib.h>
10#include <stdio.h>
11
12int main(int argc, char **argv)
13{
14 if (argc < 2) {
15 fprintf(stderr, "%s needs one argument: the structure name\n",
16 argv[0]);
17 exit(1);
18 }
19
20 printf("/* bin2header output - automatically generated */\n");
21 printf("unsigned char %s[] = {\n", argv[1]);
22
23 while (1) {
24 int i, nread;
25 unsigned char buf[10];
26 nread = read(0, buf, sizeof(buf));
27 if (nread <= 0)
28 break;
29
30 printf("\t");
31 for (i = 0; i < nread - 1; i++)
32 printf("0x%02x, ", buf[i]);
33
34 printf("0x%02x,\n", buf[nread-1]);
35 }
36
37 printf("};\n");
38
39 exit(0);
40}