annotate helpers/srec4ram.c @ 192:4f40ae165be4

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