FreeCalypso > hg > freecalypso-tools
annotate miscutil/srec-regions.c @ 990:f34261bb3355
pln-ppb-test: implement PPB erase
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 03 Dec 2023 00:20:14 +0000 |
parents | 7ef3343161d6 |
children |
rev | line source |
---|---|
622
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program parses an S-record file (TI's *.m0 or otherwise), identifies |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * the set of discontiguous regions into which this SREC image deposits bits, |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * and lists these identified regions. |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/types.h> |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <ctype.h> |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <strings.h> |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdlib.h> |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 char *infname; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 FILE *inf; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char srecbuf[1024]; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 u_char srecbin[256]; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 int lineno, state; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 u_long region_start, region_end; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 decode_hex_byte(s) |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 char *s; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 register int u, l; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (!isxdigit(s[0]) || !isxdigit(s[1])) |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 return(-1); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 if (isdigit(s[0])) |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 u = s[0] - '0'; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 else if (isupper(s[0])) |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 u = s[0] - 'A' + 10; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 else |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 u = s[0] - 'a' + 10; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (isdigit(s[1])) |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 l = s[1] - '0'; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 else if (isupper(s[1])) |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 l = s[1] - 'A' + 10; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 else |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 l = s[1] - 'a' + 10; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 return((u << 4) | l); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 srec2bin() |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 register int i, l, b; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 l = decode_hex_byte(srecbuf + 2); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 if (l < 1) { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 fprintf(stderr, "%s line %d: S-record length octet is bad\n", |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 infname, lineno); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 exit(1); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 srecbin[0] = l; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 for (i = 1; i <= l; i++) { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 b = decode_hex_byte(srecbuf + i*2 + 2); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 if (b < 0) { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 fprintf(stderr, "%s line %d: hex decode error\n", |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 infname, lineno); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 exit(1); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 srecbin[i] = b; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 return(0); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 srec_cksum() |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 u_char accum; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 register int i, len; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 len = srecbin[0] + 1; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 accum = 0; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 for (i = 0; i < len; i++) |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 accum += srecbin[i]; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 if (accum != 0xFF) { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 fprintf(stderr, "%s line %d: bad checksum\n", infname, lineno); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 exit(1); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 return(0); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 main(argc, argv) |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 char **argv; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 register int i; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 u_long curaddr; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 int datalen; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 if (argc != 2) { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 fprintf(stderr, "usage: %s image.m0\n", argv[0]); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 exit(1); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 infname = argv[1]; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 inf = fopen(infname, "r"); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 if (!inf) { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 perror(infname); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 exit(1); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 state = 0; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 for (lineno = 1; ; lineno++) { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 if (!fgets(srecbuf, sizeof srecbuf, inf)) { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 fprintf(stderr, "%s: premature EOF\n", infname); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 exit(1); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 if (srecbuf[0] != 'S') { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 fprintf(stderr, "%s line %d: not an S-record\n", |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 infname, lineno); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 exit(1); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 switch (srecbuf[1]) { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 case '0': |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 if (state == 0) |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 break; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 else |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 goto badtype; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 case '3': |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 if (state == 0) |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 goto badtype; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 else |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 break; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 case '7': |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 if (state == 2) |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 break; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 else |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 goto badtype; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 default: |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 badtype: |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 fprintf(stderr, |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 "%s line %d: S-record type unexpected\n", |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 infname, lineno); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 exit(1); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 srec2bin(); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 srec_cksum(); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 switch (srecbuf[1]) { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 case '0': |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 state = 1; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 continue; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 case '3': |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 if (srecbin[0] < 6) { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 fprintf(stderr, |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 "%s line %d: S3 record is too short\n", |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 infname, lineno); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 exit(1); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 curaddr = (srecbin[1] << 24) | (srecbin[2] << 16) | |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 (srecbin[3] << 8) | srecbin[4]; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 datalen = srecbin[0] - 5; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 if (state < 2) { |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 region_start = curaddr; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 region_end = curaddr + datalen; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 state = 2; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 continue; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 } |
624
7485e75d9477
srec-regions: removed unnecessary prohibition against address going backward
Mychaela Falconia <falcon@freecalypso.org>
parents:
622
diff
changeset
|
156 if (curaddr != region_end) { |
622
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 printf("0x%08lX to 0x%08lX (%lu bytes)\n", |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 region_start, region_end, |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 region_end - region_start); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 region_start = curaddr; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 region_end = curaddr + datalen; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 continue; |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 case '7': |
625
7ef3343161d6
srec-regions: report the S7 address as well
Mychaela Falconia <falcon@freecalypso.org>
parents:
624
diff
changeset
|
165 if (srecbin[0] < 5) { |
7ef3343161d6
srec-regions: report the S7 address as well
Mychaela Falconia <falcon@freecalypso.org>
parents:
624
diff
changeset
|
166 fprintf(stderr, |
7ef3343161d6
srec-regions: report the S7 address as well
Mychaela Falconia <falcon@freecalypso.org>
parents:
624
diff
changeset
|
167 "%s line %d: S7 record is too short\n", |
7ef3343161d6
srec-regions: report the S7 address as well
Mychaela Falconia <falcon@freecalypso.org>
parents:
624
diff
changeset
|
168 infname, lineno); |
7ef3343161d6
srec-regions: report the S7 address as well
Mychaela Falconia <falcon@freecalypso.org>
parents:
624
diff
changeset
|
169 exit(1); |
7ef3343161d6
srec-regions: report the S7 address as well
Mychaela Falconia <falcon@freecalypso.org>
parents:
624
diff
changeset
|
170 } |
622
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 printf("0x%08lX to 0x%08lX (%lu bytes)\n", |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 region_start, region_end, |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 region_end - region_start); |
625
7ef3343161d6
srec-regions: report the S7 address as well
Mychaela Falconia <falcon@freecalypso.org>
parents:
624
diff
changeset
|
174 printf("S7 address 0x%02X%02X%02X%02X\n", srecbin[1], |
7ef3343161d6
srec-regions: report the S7 address as well
Mychaela Falconia <falcon@freecalypso.org>
parents:
624
diff
changeset
|
175 srecbin[2], srecbin[3], srecbin[4]); |
622
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 exit(0); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 default: |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 abort(); |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 } |
89e9e79a7f55
srec-regions utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 } |