annotate loadtools/flprogsrec.c @ 657:742c99c1ff52

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