summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHao Zhang2011-06-03 16:00:07 -0500
committerHao Zhang2011-06-03 16:00:07 -0500
commitcacac223050597dffd7154eb8fe496a48d9c59cc (patch)
tree92458cfb3fe0db5a52a0743b888b51750aad3942 /hfile2array/hfile2array.c
parent7d259efa17050018b7565f0b098564567cdd3120 (diff)
downloadmcsdk-tools-cacac223050597dffd7154eb8fe496a48d9c59cc.tar.gz
mcsdk-tools-cacac223050597dffd7154eb8fe496a48d9c59cc.tar.xz
mcsdk-tools-cacac223050597dffd7154eb8fe496a48d9c59cc.zip
Added SRIO boot example, added binary support for writers
Diffstat (limited to 'hfile2array/hfile2array.c')
-rw-r--r--hfile2array/hfile2array.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/hfile2array/hfile2array.c b/hfile2array/hfile2array.c
new file mode 100644
index 0000000..19e658d
--- /dev/null
+++ b/hfile2array/hfile2array.c
@@ -0,0 +1,113 @@
1/******************************************************************************
2 * Copyright (c) 2011 Texas Instruments Incorporated - http://www.ti.com
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 *****************************************************************************/
33
34/***************************************************************************************
35 * FILE NAME: hex2h.c
36 *
37 * DESCRIPTION: A simple utility to convert an ASCII hex file to a header file .
38 *
39 ***************************************************************************************/
40#include <stdlib.h>
41#include <stdio.h>
42#include <string.h>
43
44int main(int argc, char **argv)
45{
46 FILE *out, *in;
47 char line[200] = "uint8_t ";
48
49 if (argc != 4)
50 {
51 printf ("Usage: hfile2array.exe <in_file> <out_file> <array_name>\n");
52 return (-1);
53 }
54
55 argv++;
56
57 in = fopen((const char *)(*argv++), "rt");
58
59 if (in == NULL)
60 {
61 printf ("Can not open %s\n", *argv[0]);
62 return (-1);
63 }
64
65 out = fopen((const char *)(*argv++), "wt");
66 if (out == NULL)
67 {
68 printf ("Can not open %s\n", *argv[1]);
69 return (-1);
70 }
71 strcat (line, (const char *)(*argv++));
72 strcat (line, "[] = {\n");
73
74 if (fputs(line, out) != 0)
75 {
76 printf ("fputs %s error\n", fputs);
77 goto error;
78 }
79
80 while (1)
81 {
82 if (fgets(line, 200, in) != NULL)
83 {
84 if (fputs(line, out) != 0)
85 {
86 printf ("fputs %s error\n", fputs);
87 goto error;
88 }
89 }
90 else
91 {
92 /* EOF reached */
93 break;
94 }
95 }
96
97 if (fputs("};\n", out) != 0)
98 {
99 printf ("fputs %s error\n", fputs);
100 goto error;
101 }
102
103 fclose(in);
104 fclose(out);
105
106 return 0;
107
108error:
109 fclose(in);
110 fclose(out);
111
112 return (-1);
113} \ No newline at end of file