FreeCalypso > hg > freecalypso-tools
annotate loadtools/chainload.c @ 662:0a6184443821
libserial-posix/baudtab.c: cosmetic bugfix
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 05 Mar 2020 20:07:42 +0000 |
parents | 9f5a3e9e6294 |
children | 51bcfb251b23 |
rev | line source |
---|---|
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the chain-loading of XRAM images via loadagent. |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdint.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
614
02bdb2f366bc
fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
536
diff
changeset
|
11 #include <time.h> |
651
6bb41b4d39ed
fc-xram number of records per batch made baudrate-dependent
Mychaela Falconia <falcon@freecalypso.org>
parents:
650
diff
changeset
|
12 #include "../libserial/baudrate.h" |
656
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
13 #include "discontig.h" |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "srecreader.h" |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
650
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
16 extern int target_fd; |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
17 |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 struct srecreader xramimage; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 extern struct baudrate *current_baud_rate; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 extern struct baudrate *xram_run_baudrate; |
536
dc05170ab113
fc-xram JTAG mode (-j) implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
535
diff
changeset
|
22 extern int xram_jtag_mode; |
656
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
23 extern uint32_t crc32_table[]; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 perform_chain_load() |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 { |
656
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
27 int rc, reclen, too_many_regions; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 unsigned long rec_count; |
656
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
29 struct discontig_prog regions[MAX_SREC_REGIONS], *regp; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
30 unsigned regcount, reg; |
650
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
31 char *argv[3], jumparg[10]; |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
32 u_char scratch[3], expect_conf[3]; |
614
02bdb2f366bc
fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
536
diff
changeset
|
33 time_t start_time, finish_time; |
02bdb2f366bc
fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
536
diff
changeset
|
34 unsigned duration, mm, ss; |
656
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
35 u_long crc_from_target; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
36 int i, c; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (open_srec_file(&xramimage) < 0) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 exit(1); |
650
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
40 /* enter binary RAM download mode */ |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
41 argv[0] = "BINML"; |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
42 argv[1] = 0; |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
43 tpinterf_make_cmd(argv); |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
44 if (tpinterf_send_cmd()) |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
45 exit(1); |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
46 /* read and send S-record image */ |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
47 expect_conf[0] = 0x06; |
656
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
48 regp = regions; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
49 regcount = 0; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
50 too_many_regions = 0; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 for (rec_count = 0; ; ) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (read_s_record(&xramimage) < 0) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 switch (xramimage.record_type) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 case '0': |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 if (xramimage.lineno == 1) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 continue; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 "%s: S0 record found in line %d (expected in line 1 only)\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 xramimage.filename, xramimage.lineno); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 case '3': |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 case '7': |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (s3s7_get_addr_data(&xramimage) < 0) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 break; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 default: |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 "%s line %d: S%c record type not supported\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 xramimage.filename, xramimage.lineno, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 xramimage.record_type); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |
650
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
74 if (xramimage.record_type == '7') |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 break; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 /* must be S3 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (xramimage.datalen < 1) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 "%s line %d: S3 record has zero data length\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 xramimage.filename, xramimage.lineno); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
614
02bdb2f366bc
fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
536
diff
changeset
|
83 if (!rec_count) { |
651
6bb41b4d39ed
fc-xram number of records per batch made baudrate-dependent
Mychaela Falconia <falcon@freecalypso.org>
parents:
650
diff
changeset
|
84 printf("Each \'.\' is %d S-records\n", |
6bb41b4d39ed
fc-xram number of records per batch made baudrate-dependent
Mychaela Falconia <falcon@freecalypso.org>
parents:
650
diff
changeset
|
85 current_baud_rate->xram_records); |
614
02bdb2f366bc
fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
536
diff
changeset
|
86 time(&start_time); |
02bdb2f366bc
fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
536
diff
changeset
|
87 } |
650
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
88 reclen = xramimage.datalen + 6; |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
89 if (write(target_fd, xramimage.record, reclen) != reclen) { |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
90 perror("binary write to target"); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 exit(1); |
650
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
92 } |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 rec_count++; |
656
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
94 /* discontiguous regions and CRC-32 accumulation */ |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
95 if (!regcount) { |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
96 regp->start = xramimage.addr; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
97 regp->end = xramimage.addr; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
98 regp->crc = 0xFFFFFFFF; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
99 regcount = 1; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
100 } |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
101 if (xramimage.addr != regp->end) { |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
102 if (regcount >= MAX_SREC_REGIONS) |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
103 too_many_regions = 1; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
104 else { |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
105 regp++; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
106 regcount++; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
107 regp->start = xramimage.addr; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
108 regp->end = xramimage.addr; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
109 regp->crc = 0xFFFFFFFF; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
110 } |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
111 } |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
112 if (!too_many_regions) { |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
113 for (i = 0; i < xramimage.datalen; i++) { |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
114 c = xramimage.record[i+5]; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
115 regp->crc = crc32_table[regp->crc & 0xFF ^ c] |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
116 ^ (regp->crc >> 8); |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
117 } |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
118 regp->end += xramimage.datalen; |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
119 } |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
120 /* target sync and progress indication */ |
651
6bb41b4d39ed
fc-xram number of records per batch made baudrate-dependent
Mychaela Falconia <falcon@freecalypso.org>
parents:
650
diff
changeset
|
121 if (rec_count % current_baud_rate->xram_records == 0) { |
650
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
122 scratch[0] = 0x05; /* ENQ */ |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
123 write(target_fd, scratch, 1); |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
124 if (collect_binblock_from_target(scratch, 3, 1)) |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
125 exit(1); |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
126 expect_conf[1] = rec_count >> 8; |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
127 expect_conf[2] = rec_count; |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
128 if (bcmp(scratch, expect_conf, 3)) { |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
129 fprintf(stderr, |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
130 "error: expected sync mismatch\n"); |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
131 exit(1); |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
132 } |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 putchar('.'); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 fflush(stdout); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 /* got S7 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 fclose(xramimage.openfile); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 if (!rec_count) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 "%s line %d: S7 without any preceding S3 data records\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 xramimage.filename, xramimage.lineno); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 } |
535
88962b111edc
fc-xram: print a newline after the dots
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
145 putchar('\n'); /* newline after the dots */ |
650
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
146 scratch[0] = 0x04; /* EOT */ |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
147 write(target_fd, scratch, 1); |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
148 if (collect_binblock_from_target(scratch, 1, 1)) |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
149 exit(1); |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
150 time(&finish_time); |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
151 if (scratch[0] != '=') { |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
152 fprintf(stderr, "error: \'=\' not received as expected\n"); |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
153 exit(1); |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
154 } |
614
02bdb2f366bc
fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
536
diff
changeset
|
155 duration = finish_time - start_time; |
02bdb2f366bc
fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
536
diff
changeset
|
156 mm = duration / 60; |
02bdb2f366bc
fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
536
diff
changeset
|
157 ss = duration - mm * 60; |
02bdb2f366bc
fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
536
diff
changeset
|
158 printf("XRAM image transferred in %um%us\n", mm, ss); |
656
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
159 printf("Verifying CRC-32 of %u downloaded region(s)\n", regcount); |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
160 for (reg = 0, regp = regions; reg < regcount; reg++, regp++) { |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
161 rc = crc32_on_target((u_long) regp->start, |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
162 (u_long) (regp->end - regp->start), |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
163 &crc_from_target); |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
164 if (rc < 0) |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
165 exit(1); |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
166 if (crc_from_target != regp->crc) { |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
167 fprintf(stderr, "error: CRC mismatch!\n"); |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
168 exit(1); |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
169 } |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
170 putchar('.'); |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
171 fflush(stdout); |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
172 } |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
173 putchar('\n'); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 if (xram_run_baudrate != current_baud_rate) { |
656
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
175 rc = loadagent_switch_baud(xram_run_baudrate); |
9f5a3e9e6294
fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
651
diff
changeset
|
176 if (rc) |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 } |
536
dc05170ab113
fc-xram JTAG mode (-j) implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
535
diff
changeset
|
179 if (xram_jtag_mode) { |
dc05170ab113
fc-xram JTAG mode (-j) implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
535
diff
changeset
|
180 printf( |
dc05170ab113
fc-xram JTAG mode (-j) implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
535
diff
changeset
|
181 "Leaving target in loadagent for JTAG; image start address is 0x%08lX\n", |
dc05170ab113
fc-xram JTAG mode (-j) implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
535
diff
changeset
|
182 (u_long) xramimage.addr); |
dc05170ab113
fc-xram JTAG mode (-j) implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
535
diff
changeset
|
183 exit(0); |
dc05170ab113
fc-xram JTAG mode (-j) implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
535
diff
changeset
|
184 } |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 printf("Sending jump command\n"); |
650
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
186 sprintf(jumparg, "%lX", (u_long) xramimage.addr); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 argv[0] = "jump"; |
650
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
188 argv[1] = jumparg; |
bf840c984113
fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents:
614
diff
changeset
|
189 argv[2] = 0; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 tpinterf_make_cmd(argv); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 if (tpinterf_send_cmd()) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 printf("Sent \"%s %s\": XRAM image should now be running!\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 argv[0], argv[1]); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 return(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 } |