FreeCalypso > hg > freecalypso-tools
annotate loadtools/flprogsrec.c @ 639:963d15a808eb
loadagent BINDUMP actually works
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 01 Mar 2020 18:28:10 +0000 |
parents | 0f70fe9395c4 |
children | d42534e5ac02 |
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 flash program-srec and flash program-m0 commands: |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * programming flash using S-record files as the data source. |
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 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.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 <stdint.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
617
97fe41e9242a
fc-loadtool: added operation time reporting to flash program-m0
Mychaela Falconia <falcon@freecalypso.org>
parents:
506
diff
changeset
|
10 #include <time.h> |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "flash.h" |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "srecreader.h" |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern struct flash_bank_info flash_bank_info[2]; |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
15 extern uint32_t crc32_table[]; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
17 #define MAX_SREC_REGIONS 256 |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
19 read_srec_img_for_flash(imgfile, is_m0, bank_size, reglistp, regcountp, |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
20 totalp, tmpfilep) |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
21 char *imgfile; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
22 uint32_t bank_size, *totalp; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
23 struct discontig_prog *reglistp; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
24 unsigned *regcountp; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
25 FILE **tmpfilep; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
26 { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
27 struct srecreader srr; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
28 struct discontig_prog *regp; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
29 unsigned regcount; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
30 uint32_t total_len; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
31 char tmpfilename[] = "/tmp/fc-loadtoolXXXXXX"; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
32 int rc, tmpfd, i, c; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
33 FILE *tmpfile; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
34 |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
35 printf("Reading S-record image from %s\n", imgfile); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 srr.filename = imgfile; |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
37 rc = open_srec_file(&srr); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
38 if (rc < 0) |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
39 return(rc); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
40 tmpfd = mkstemp(tmpfilename); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
41 if (tmpfd < 0) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
42 fprintf(stderr, "unable to get temp file via mkstemp()\n"); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 fclose(srr.openfile); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
46 unlink(tmpfilename); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
47 tmpfile = fdopen(tmpfd, "w+"); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
48 if (!tmpfile) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
49 perror("fdopen"); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
50 close(tmpfd); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 fclose(srr.openfile); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 } |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
54 regp = reglistp; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
55 regcount = 0; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
56 total_len = 0; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
57 for (;;) { |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 if (read_s_record(&srr) < 0) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 /* error msg already printed */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 fclose(srr.openfile); |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
61 fclose(tmpfile); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (srr.record_type == '0') { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 if (srr.lineno == 1) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 continue; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 fprintf(stderr, |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
68 "error: S0 record found in line %d of %s (expected in line 1 only)\n", |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 srr.lineno, srr.filename); |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
70 fclose(srr.openfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
71 fclose(tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
72 return(-1); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
73 } else if (srr.record_type == '7') |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 break; |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
75 else if (srr.record_type != '3') { |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 fprintf(stderr, |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
77 "error: unsupported S%c record type in line %d of %s\n", |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 srr.record_type, srr.lineno, srr.filename); |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
79 fclose(srr.openfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
80 fclose(tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
81 return(-1); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 /* must be S3 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 if (s3s7_get_addr_data(&srr) < 0) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 /* error msg already printed */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 fclose(srr.openfile); |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
87 fclose(tmpfile); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (srr.datalen < 1) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 "%s line %d: S3 record of zero data length ignored\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 srr.filename, srr.lineno); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 continue; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 if (srr.addr & 1 || srr.datalen & 1) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 "%s line %d: violates word alignment requirement\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 srr.filename, srr.lineno); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 fclose(srr.openfile); |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
101 fclose(tmpfile); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 } |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
104 srr.addr &= bank_size - 1; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
105 if (srr.addr + srr.datalen > bank_size) { |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 "%s line %d: goes past the end of the flash bank\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 srr.filename, srr.lineno); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 fclose(srr.openfile); |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
110 fclose(tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
111 return(-1); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
112 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
113 /* is this the first record of the first region? */ |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
114 if (!regcount) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
115 regp->start = srr.addr; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
116 regp->end = srr.addr; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
117 regp->crc = 0xFFFFFFFF; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
118 regcount = 1; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
119 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
120 if (srr.addr < regp->end) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
121 fprintf(stderr, "%s line %d: address going backwards\n", |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
122 srr.filename, srr.lineno); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
123 fclose(srr.openfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
124 fclose(tmpfile); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 } |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
127 if (srr.addr != regp->end) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
128 if (regcount >= MAX_SREC_REGIONS) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
129 fprintf(stderr, |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
130 "error: %s has too many discontiguous regions\n", |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
131 imgfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
132 fclose(srr.openfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
133 fclose(tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
134 return(-1); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
135 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
136 regp++; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
137 regcount++; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
138 regp->start = srr.addr; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
139 regp->end = srr.addr; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
140 regp->crc = 0xFFFFFFFF; |
617
97fe41e9242a
fc-loadtool: added operation time reporting to flash program-m0
Mychaela Falconia <falcon@freecalypso.org>
parents:
506
diff
changeset
|
141 } |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
142 /* take in the payload */ |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
143 if (is_m0) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
144 for (i = 0; i < srr.datalen; i += 2) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
145 c = srr.record[i+6]; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
146 regp->crc = crc32_table[regp->crc & 0xFF ^ c] |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
147 ^ (regp->crc >> 8); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
148 putc(c, tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
149 c = srr.record[i+5]; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
150 regp->crc = crc32_table[regp->crc & 0xFF ^ c] |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
151 ^ (regp->crc >> 8); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
152 putc(c, tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
153 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
154 } else { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
155 for (i = 0; i < srr.datalen; i++) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
156 c = srr.record[i+5]; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
157 regp->crc = crc32_table[regp->crc & 0xFF ^ c] |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
158 ^ (regp->crc >> 8); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
159 putc(c, tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
160 } |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 } |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
162 regp->end += srr.datalen; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
163 total_len += srr.datalen; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 /* got S7 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 fclose(srr.openfile); |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
167 if (!regcount) { |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 "%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
|
170 srr.filename, srr.lineno); |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
171 fclose(tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
172 return(-1); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
173 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
174 /* good read */ |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
175 if (regcount == 1) |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
176 printf("Got %lu (0x%lx) bytes in one contiguous region\n", |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
177 (u_long) total_len, (u_long) total_len); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
178 else |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
179 printf("Got %lu (0x%lx) bytes in %u discontiguous regions\n", |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
180 (u_long) total_len, (u_long) total_len, regcount); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
181 *regcountp = regcount; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
182 *totalp = total_len; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
183 *tmpfilep = tmpfile; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
184 return(0); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
185 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
186 |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
187 flashcmd_progsrec_gen(bank, imgfile, is_m0) |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
188 char *imgfile; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
189 { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
190 struct flash_bank_info *bi; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
191 struct discontig_prog regions[MAX_SREC_REGIONS], *regp; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
192 unsigned nregions, reg; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
193 uint32_t total_len, bytesdone, addr, len; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
194 FILE *tmpfile; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
195 char *targv[4], shortarg[10], longarg[513]; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
196 u_char databuf[256]; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
197 int reclen, cc, rc; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
198 time_t initial_time, curtime, last_time; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
199 unsigned duration, mm, ss; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
200 u_long crc_from_target; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
201 |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
202 if (flash_detect(bank, 0) < 0) |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
203 return(-1); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
204 bi = flash_bank_info + bank; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
205 rc = read_srec_img_for_flash(imgfile, is_m0, bi->geom->total_size, |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
206 regions, &nregions, &total_len, &tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
207 if (rc < 0) |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
208 return(rc); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
209 sprintf(shortarg, "%lx", (u_long) bi->base_addr); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
210 targv[0] = bi->ops->loadagent_setbase_cmd; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
211 targv[1] = shortarg; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
212 targv[2] = 0; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
213 printf("Setting flash base address: %s %s\n", targv[0], targv[1]); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
214 tpinterf_make_cmd(targv); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
215 if (tpinterf_send_cmd() < 0) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
216 fclose(tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
217 return(-1); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
218 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
219 rc = tpinterf_pass_output(1); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
220 if (rc) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
221 fclose(tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
222 return(rc); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
223 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
224 if (bi->ops->prep_for_program(bi) < 0) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
225 fclose(tmpfile); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 } |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
228 rewind(tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
229 targv[0] = bi->ops->loadagent_program_cmd; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
230 targv[1] = shortarg; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
231 targv[2] = longarg; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
232 targv[3] = 0; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
233 printf("Programming flash\n"); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
234 bytesdone = 0; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
235 last_time = 0; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
236 time(&initial_time); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
237 for (reg = 0, regp = regions; reg < nregions; reg++, regp++) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
238 addr = regp->start; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
239 len = regp->end - addr; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
240 while (len) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
241 if (len >= 256) |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
242 reclen = 256; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
243 else |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
244 reclen = len; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
245 cc = fread(databuf, 1, reclen, tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
246 if (cc != reclen) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
247 fclose(tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
248 fprintf(stderr, |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
249 "error reading from temp file!\n"); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
250 return(-1); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
251 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
252 sprintf(shortarg, "%lx", addr); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
253 build_flashw_hex_string(databuf, longarg, reclen >> 1, |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
254 0); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
255 tpinterf_make_cmd(targv); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
256 if (tpinterf_send_cmd() < 0) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
257 fclose(tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
258 return(-1); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
259 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
260 rc = tpinterf_pass_output(8); /* 8 s timeout */ |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
261 if (rc) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
262 fclose(tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
263 return(rc); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
264 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
265 addr += reclen; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
266 len -= reclen; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
267 bytesdone += reclen; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
268 cc = bytesdone * 100 / total_len; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
269 time(&curtime); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
270 if (curtime != last_time || cc == 100) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
271 printf("\r0x%lx bytes programmed (%i%%)", |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
272 bytesdone, cc); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
273 fflush(stdout); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
274 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
275 last_time = curtime; |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
276 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
277 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
278 putchar('\n'); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
279 fclose(tmpfile); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
280 duration = last_time - initial_time; |
617
97fe41e9242a
fc-loadtool: added operation time reporting to flash program-m0
Mychaela Falconia <falcon@freecalypso.org>
parents:
506
diff
changeset
|
281 mm = duration / 60; |
97fe41e9242a
fc-loadtool: added operation time reporting to flash program-m0
Mychaela Falconia <falcon@freecalypso.org>
parents:
506
diff
changeset
|
282 ss = duration - mm * 60; |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
283 printf("Operation completed in %um%us\n", mm, ss); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
284 |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
285 /* reset flash to read mode */ |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
286 if (bi->ops->reset_cmd(bi) < 0) |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
287 return(-1); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
288 printf("Verifying CRC-32 of %u programmed region(s)\n", nregions); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
289 for (reg = 0, regp = regions; reg < nregions; reg++, regp++) { |
629
0f70fe9395c4
fc-loadtool: bug in the new program-m0 CRC-32 verification
Mychaela Falconia <falcon@freecalypso.org>
parents:
628
diff
changeset
|
290 rc = crc32_on_target((u_long) (bi->base_addr + regp->start), |
628
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
291 (u_long) (regp->end - regp->start), |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
292 &crc_from_target); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
293 if (rc < 0) |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
294 return(rc); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
295 if (crc_from_target != regp->crc) { |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
296 fprintf(stderr, "error: CRC mismatch!\n"); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
297 return(-1); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
298 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
299 putchar('.'); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
300 fflush(stdout); |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
301 } |
9c5b0629e346
fc-loadtool SREC programming revamp implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
617
diff
changeset
|
302 putchar('\n'); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
303 return(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
304 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
305 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
306 flashcmd_program_srec(argc, argv, bank) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
307 char **argv; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
308 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
309 if (argc != 3) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 fprintf(stderr, "usage: %s %s image.srec\n", argv[0], argv[1]); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 return flashcmd_progsrec_gen(bank, argv[2], 0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
315 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
316 flashcmd_program_m0(argc, argv, bank) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
317 char **argv; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
318 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
319 if (argc != 3) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
320 fprintf(stderr, "usage: %s %s image.m0\n", argv[0], argv[1]); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
321 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
322 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
323 return flashcmd_progsrec_gen(bank, argv[2], 1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
324 } |