annotate helpers/srec4ram.c @ 554:28ed4002131a

configs/* except classic and hybrid-gpf: all parts of TCS211 GPF for which we found exact corresponding sources are now rebuilt from those sources; only OSL and OSX remain as blobs, plus CCD for non-hybrid configs
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 19 Nov 2018 00:12:20 +0000
parents 40b08f6cb2b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
92
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This ad hoc utility is used as part of building RAM-loadable
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * firmware images for targets with large RAM. It reads the ramimage.m0
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * S-record file produced by TI's hex470 post-linker and re-emits it
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * in another SREC form that is suitable for feeding to fc-xram.
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 */
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/types.h>
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <ctype.h>
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <string.h>
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <strings.h>
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 char *infname;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 FILE *inf, *outf;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 char srecbuf[80];
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 u_char srecbin[40], srecout[40];
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 int lineno;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 decode_hex_byte(s)
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 char *s;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 register int u, l;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (!isxdigit(s[0]) || !isxdigit(s[1]))
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return(-1);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (isdigit(s[0]))
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 u = s[0] - '0';
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 else if (isupper(s[0]))
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 u = s[0] - 'A' + 10;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 else
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 u = s[0] - 'a' + 10;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (isdigit(s[1]))
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 l = s[1] - '0';
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 else if (isupper(s[1]))
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 l = s[1] - 'A' + 10;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 else
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 l = s[1] - 'a' + 10;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return((u << 4) | l);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 srec2bin()
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 register int i, l, b;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 l = decode_hex_byte(srecbuf + 2);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (l < 1) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fprintf(stderr, "%s line %d: S-record length octet is bad\n",
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 infname, lineno);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 exit(1);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 srecbin[0] = l;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (l > 35) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 fprintf(stderr,
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 "%s line %d: S-record is longer than expected\n",
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 infname, lineno);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 exit(1);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 for (i = 1; i <= l; i++) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 b = decode_hex_byte(srecbuf + i*2 + 2);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 if (b < 0) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 fprintf(stderr, "%s line %d: hex decode error\n",
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 infname, lineno);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 exit(1);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 srecbin[i] = b;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return(0);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 srec_cksum()
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 u_char accum;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 register int i, len;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 len = srecbin[0] + 1;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 accum = 0;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 for (i = 0; i < len; i++)
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 accum += srecbin[i];
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (accum != 0xFF) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 fprintf(stderr, "%s line %d: bad checksum\n", infname, lineno);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 exit(1);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 return(0);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 emit_output_srec(type, buf)
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 u_char *buf;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 int i;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 u_char accum = 0;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 putc('S', outf);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 putc(type, outf);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 for (i = 0; i < buf[0]; i++) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 fprintf(outf, "%02X", buf[i]);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 accum += buf[i];
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 fprintf(outf, "%02X\n", ~accum & 0xFF);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 return 0;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 transform_s3()
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 int datalen;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 u_char *sp, *dp;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 int i;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 if (srecbin[0] < 6) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 fprintf(stderr,
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 "%s line %d: S3 record is too short\n",
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 infname, lineno);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 exit(1);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 datalen = srecbin[0] - 5;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 if (datalen & 1) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 fprintf(stderr, "%s line %d: odd data length\n",
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 infname, lineno);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 exit(1);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 sp = srecbin;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 dp = srecout;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 for (i = 0; i < 5; i++)
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 *dp++ = *sp++;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 for (i = 0; i < datalen; i += 2) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 dp[0] = sp[1];
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 dp[1] = sp[0];
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 sp += 2;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 dp += 2;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 return 0;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 generate_vectors_record()
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 u_char *dp;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 u_long addr;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 int i;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 srecout[0] = 28 + 5;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 srecout[1] = 0x00;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 srecout[2] = 0x80;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 srecout[3] = 0x00;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 srecout[4] = 0x00;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 dp = srecout + 5;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 for (i = 0; i < 7; i++) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 addr = 0x01004000 + i * 4;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 *dp++ = addr;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 *dp++ = addr >> 8;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 *dp++ = addr >> 16;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 *dp++ = addr >> 24;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 emit_output_srec('3', srecout);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 return 0;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 generate_jump_record()
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 srecout[0] = 5;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 srecout[1] = 0x01;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 srecout[2] = 0x00;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 srecout[3] = 0x40;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 srecout[4] = 0x58;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 emit_output_srec('7', srecout);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 return 0;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 main(argc, argv)
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 char **argv;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 if (argc < 2 || argc > 3) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 fprintf(stderr, "usage: %s input.m0 [output.srec]\n", argv[0]);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 exit(1);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 infname = argv[1];
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 inf = fopen(infname, "r");
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 if (!inf) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 perror(infname);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 exit(1);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 if (argc > 2) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 outf = fopen(argv[2], "w");
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 if (!outf) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 perror(argv[2]);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 exit(1);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 } else
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 outf = stdout;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 for (lineno = 1; ; lineno++) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 if (!fgets(srecbuf, sizeof srecbuf, inf)) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 fprintf(stderr, "%s: premature EOF\n", infname);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 exit(1);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 if (srecbuf[0] != 'S') {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 fprintf(stderr, "%s line %d: not an S-record\n",
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 infname, lineno);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 exit(1);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 srec2bin();
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 srec_cksum();
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 switch (srecbuf[1]) {
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 case '0':
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 emit_output_srec('0', srecbin);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 continue;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 case '3':
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 transform_s3();
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 emit_output_srec('3', srecout);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 continue;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 case '7':
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 break;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 default:
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 fprintf(stderr, "%s line %d: unexpected S%c record\n",
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 infname, lineno, srecbuf[1]);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 exit(1);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 break;
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 }
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 generate_vectors_record();
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 generate_jump_record();
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 exit(0);
40b08f6cb2b8 srec4ram helper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 }