annotate loadtools/chainload.c @ 839:b053e4141a16

CHANGES: refer to doc/Audio-mode-config for AEC support changes
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 30 Jul 2021 05:42:21 +0000
parents 185c9bf208d3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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>
666
51bcfb251b23 fc-loadtool flash program-m0 changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 656
diff changeset
12 #include <unistd.h>
651
6bb41b4d39ed fc-xram number of records per batch made baudrate-dependent
Mychaela Falconia <falcon@freecalypso.org>
parents: 650
diff changeset
13 #include "../libserial/baudrate.h"
656
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
14 #include "discontig.h"
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "srecreader.h"
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
650
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
17 extern int target_fd;
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
18
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 struct srecreader xramimage;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 extern struct baudrate *current_baud_rate;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern struct baudrate *xram_run_baudrate;
536
dc05170ab113 fc-xram JTAG mode (-j) implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 535
diff changeset
23 extern int xram_jtag_mode;
656
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
24 extern uint32_t crc32_table[];
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 perform_chain_load()
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 {
656
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
28 int rc, reclen, too_many_regions;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 unsigned long rec_count;
656
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
30 struct discontig_prog regions[MAX_SREC_REGIONS], *regp;
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
31 unsigned regcount, reg;
650
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
32 char *argv[3], jumparg[10];
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
33 u_char scratch[3], expect_conf[3];
614
02bdb2f366bc fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents: 536
diff changeset
34 time_t start_time, finish_time;
02bdb2f366bc fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents: 536
diff changeset
35 unsigned duration, mm, ss;
656
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
36 u_long crc_from_target;
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
37 int i, c;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (open_srec_file(&xramimage) < 0)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 exit(1);
650
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
41 /* enter binary RAM download mode */
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
42 argv[0] = "BINML";
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
43 argv[1] = 0;
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
44 tpinterf_make_cmd(argv);
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
45 if (tpinterf_send_cmd())
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
46 exit(1);
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
47 /* 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
48 expect_conf[0] = 0x06;
656
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
49 regp = regions;
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
50 regcount = 0;
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
51 too_many_regions = 0;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 for (rec_count = 0; ; ) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 if (read_s_record(&xramimage) < 0)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 switch (xramimage.record_type) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 case '0':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (xramimage.lineno == 1)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 "%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
61 xramimage.filename, xramimage.lineno);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 case '3':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 case '7':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (s3s7_get_addr_data(&xramimage) < 0)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 break;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 default:
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 "%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
71 xramimage.filename, xramimage.lineno,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 xramimage.record_type);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
650
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
75 if (xramimage.record_type == '7')
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 break;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 /* must be S3 */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if (xramimage.datalen < 1) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 "%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
81 xramimage.filename, xramimage.lineno);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 }
614
02bdb2f366bc fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents: 536
diff changeset
84 if (!rec_count) {
651
6bb41b4d39ed fc-xram number of records per batch made baudrate-dependent
Mychaela Falconia <falcon@freecalypso.org>
parents: 650
diff changeset
85 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
86 current_baud_rate->xram_records);
614
02bdb2f366bc fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents: 536
diff changeset
87 time(&start_time);
02bdb2f366bc fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents: 536
diff changeset
88 }
650
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
89 reclen = xramimage.datalen + 6;
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
90 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
91 perror("binary write to target");
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 exit(1);
650
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
93 }
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 rec_count++;
656
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
95 /* discontiguous regions and CRC-32 accumulation */
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
96 if (!regcount) {
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
97 regp->start = xramimage.addr;
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
98 regp->end = xramimage.addr;
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
99 regp->crc = 0xFFFFFFFF;
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
100 regcount = 1;
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
101 }
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
102 if (xramimage.addr != regp->end) {
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
103 if (regcount >= MAX_SREC_REGIONS)
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
104 too_many_regions = 1;
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
105 else {
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
106 regp++;
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
107 regcount++;
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
108 regp->start = xramimage.addr;
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
109 regp->end = xramimage.addr;
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
110 regp->crc = 0xFFFFFFFF;
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 }
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
113 if (!too_many_regions) {
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
114 for (i = 0; i < xramimage.datalen; i++) {
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
115 c = xramimage.record[i+5];
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
116 regp->crc = crc32_table[regp->crc & 0xFF ^ c]
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
117 ^ (regp->crc >> 8);
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
118 }
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
119 regp->end += xramimage.datalen;
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
120 }
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
121 /* 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
122 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
123 scratch[0] = 0x05; /* ENQ */
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
124 write(target_fd, scratch, 1);
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
125 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
126 exit(1);
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
127 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
128 expect_conf[2] = rec_count;
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
129 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
130 fprintf(stderr,
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
131 "error: expected sync mismatch\n");
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
132 exit(1);
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
133 }
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 putchar('.');
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 fflush(stdout);
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 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 /* got S7 */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 fclose(xramimage.openfile);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 if (!rec_count) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 "%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
143 xramimage.filename, xramimage.lineno);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 }
535
88962b111edc fc-xram: print a newline after the dots
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
146 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
147 scratch[0] = 0x04; /* EOT */
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
148 write(target_fd, scratch, 1);
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
149 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
150 exit(1);
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
151 time(&finish_time);
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
152 if (scratch[0] != '=') {
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
153 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
154 exit(1);
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
155 }
614
02bdb2f366bc fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents: 536
diff changeset
156 duration = finish_time - start_time;
02bdb2f366bc fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents: 536
diff changeset
157 mm = duration / 60;
02bdb2f366bc fc-xram: added transfer time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents: 536
diff changeset
158 ss = duration - mm * 60;
692
185c9bf208d3 loadtools operation time reporting: two digits for seconds
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
159 printf("XRAM image transferred in %um%02us\n", mm, ss);
656
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
160 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
161 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
162 rc = crc32_on_target((u_long) regp->start,
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
163 (u_long) (regp->end - regp->start),
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
164 &crc_from_target);
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
165 if (rc < 0)
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
166 exit(1);
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
167 if (crc_from_target != regp->crc) {
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
168 fprintf(stderr, "error: CRC mismatch!\n");
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
169 exit(1);
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
170 }
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
171 putchar('.');
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
172 fflush(stdout);
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
173 }
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
174 putchar('\n');
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 if (xram_run_baudrate != current_baud_rate) {
656
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
176 rc = loadagent_switch_baud(xram_run_baudrate);
9f5a3e9e6294 fc-xram: implemented CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents: 651
diff changeset
177 if (rc)
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 }
536
dc05170ab113 fc-xram JTAG mode (-j) implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 535
diff changeset
180 if (xram_jtag_mode) {
dc05170ab113 fc-xram JTAG mode (-j) implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 535
diff changeset
181 printf(
dc05170ab113 fc-xram JTAG mode (-j) implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 535
diff changeset
182 "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
183 (u_long) xramimage.addr);
dc05170ab113 fc-xram JTAG mode (-j) implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 535
diff changeset
184 exit(0);
dc05170ab113 fc-xram JTAG mode (-j) implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 535
diff changeset
185 }
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 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
187 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
188 argv[0] = "jump";
650
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
189 argv[1] = jumparg;
bf840c984113 fc-xram reworked to use the new binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 614
diff changeset
190 argv[2] = 0;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 tpinterf_make_cmd(argv);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 if (tpinterf_send_cmd())
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 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
195 argv[0], argv[1]);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 return(0);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 }