annotate loadtools/flprogbin.c @ 681:0815661d6e3e

doc/Loadtools-performance: typo fix
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 09 Mar 2020 07:24:28 +0000
parents f67e5ad30324
children 185c9bf208d3
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-bin command:
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * programming flash using a binary file 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 <sys/stat.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdint.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <time.h>
666
51bcfb251b23 fc-loadtool flash program-m0 changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 665
diff changeset
12 #include <unistd.h>
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "flash.h"
673
f67e5ad30324 fc-loadtool: flash e-program-bin implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 672
diff changeset
14 #include "discontig.h"
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
665
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
16 extern int target_fd;
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
17
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 extern struct flash_bank_info flash_bank_info[2];
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern uint32_t crc32_table[];
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
672
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
21 flashcmd_progbin_int(bank, with_erase, flashoff, imgfile, fileoff, len,
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
22 len_given)
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
23 u_long flashoff, fileoff, len;
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
24 char *imgfile;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 struct flash_bank_info *bi;
673
f67e5ad30324 fc-loadtool: flash e-program-bin implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 672
diff changeset
27 struct discontig_prog erase_region;
672
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
28 u_long origlen, bytesdone;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 u_long crc_base_addr, crc_from_target;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 uint32_t crcaccum;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 FILE *binf;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 struct stat filestat;
665
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
33 char *targv[3], shortarg[10];
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
34 u_char databuf[2048 + 7], ackbyte;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 int reclen, cc, i;
612
52980e3a51c7 fc-loadtool: added operation time reporting to flash program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 506
diff changeset
36 time_t initial_time, curtime, last_time;
52980e3a51c7 fc-loadtool: added operation time reporting to flash program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 506
diff changeset
37 unsigned duration, mm, ss;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
506
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
39 if (flash_detect(bank, 0) < 0)
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 bi = flash_bank_info + bank;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (flashoff >= bi->geom->total_size) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 "error: specified flash offset exceeds bank size (0x%lx)\n",
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 (u_long) bi->geom->total_size);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (flashoff & 1) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fprintf(stderr, "error: flash offset must be even\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
672
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
52 binf = fopen(imgfile, "r");
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 if (!binf) {
672
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
54 perror(imgfile);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 fstat(fileno(binf), &filestat);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (!S_ISREG(filestat.st_mode)) {
672
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
59 fprintf(stderr, "error: %s is not a regular file\n", imgfile);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 fclose(binf);
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 }
672
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
63 if (fileoff > filestat.st_size) {
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
64 fprintf(stderr,
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 "error: specified file offset exceeds file length\n");
672
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
66 fclose(binf);
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
67 return(-1);
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
68 }
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
69 if (len_given) {
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (len > filestat.st_size - fileoff) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 "error: specified file offset+length exceed file length\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 fclose(binf);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 } else
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 len = filestat.st_size - fileoff;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if (!len) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 printf("Length is zero - nothing to do!\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 fclose(binf);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 return(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 if (len > bi->geom->total_size - flashoff) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 "error: specified flash offset+length exceed bank size (0x%lx)\n",
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 (u_long) bi->geom->total_size);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 fclose(binf);
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 (len & 1) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 fprintf(stderr, "error: program length must be even\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 fclose(binf);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 return(-1);
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
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 /* finally done with the arg parsing etc, can get to work now */
673
f67e5ad30324 fc-loadtool: flash e-program-bin implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 672
diff changeset
97 if (with_erase) {
f67e5ad30324 fc-loadtool: flash e-program-bin implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 672
diff changeset
98 erase_region.start = flashoff;
f67e5ad30324 fc-loadtool: flash e-program-bin implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 672
diff changeset
99 erase_region.end = flashoff + len;
f67e5ad30324 fc-loadtool: flash e-program-bin implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 672
diff changeset
100 i = erase_sectors_for_prog(bi, &erase_region, 1);
f67e5ad30324 fc-loadtool: flash e-program-bin implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 672
diff changeset
101 if (i < 0) {
f67e5ad30324 fc-loadtool: flash e-program-bin implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 672
diff changeset
102 fclose(binf);
f67e5ad30324 fc-loadtool: flash e-program-bin implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 672
diff changeset
103 return(i);
f67e5ad30324 fc-loadtool: flash e-program-bin implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 672
diff changeset
104 }
f67e5ad30324 fc-loadtool: flash e-program-bin implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 672
diff changeset
105 }
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 crc_base_addr = bi->base_addr + flashoff;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 sprintf(shortarg, "%lx", (u_long) bi->base_addr);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 targv[0] = bi->ops->loadagent_setbase_cmd;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 targv[1] = shortarg;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 targv[2] = 0;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 printf("Setting flash base address: %s %s\n", targv[0], targv[1]);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 tpinterf_make_cmd(targv);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 if (tpinterf_send_cmd() < 0) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 fclose(binf);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 cc = tpinterf_pass_output(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 if (cc) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 fclose(binf);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 return(cc);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 if (bi->ops->prep_for_program(bi) < 0) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 fclose(binf);
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 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 fseek(binf, fileoff, SEEK_SET);
665
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
127 targv[0] = bi->ops->loadagent_binmode_cmd;
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
128 targv[1] = 0;
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
129 tpinterf_make_cmd(targv);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
130 if (tpinterf_send_cmd() < 0) {
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
131 fclose(binf);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
132 return(-1);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
133 }
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 printf("Programming flash: %lu (0x%lx) bytes\n", len, len);
665
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
135 databuf[0] = 0x01;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 origlen = len;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 bytesdone = 0;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 last_time = 0;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 crcaccum = 0xFFFFFFFF;
612
52980e3a51c7 fc-loadtool: added operation time reporting to flash program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 506
diff changeset
140 time(&initial_time);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 while (len) {
665
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
142 if (len >= 2048)
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
143 reclen = 2048;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 else
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 reclen = len;
665
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
146 cc = fread(databuf + 7, 1, reclen, binf);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 if (cc != reclen) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 fclose(binf);
672
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
149 fprintf(stderr, "error reading from %s\n", imgfile);
665
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
150 /* don't leave loadagent in binary flash mode */
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
151 databuf[0] = 0x04;
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
152 write(target_fd, databuf, 1);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
153 tpinterf_pass_output(1);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 for (i = 0; i < reclen; i++) /* update running CRC */
665
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
157 crcaccum = crc32_table[crcaccum & 0xFF ^ databuf[i+7]]
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 ^ (crcaccum >> 8);
665
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
159 /* binary flash write command to loadagent */
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
160 databuf[1] = flashoff >> 24;
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
161 databuf[2] = flashoff >> 16;
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
162 databuf[3] = flashoff >> 8;
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
163 databuf[4] = flashoff;
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
164 databuf[5] = reclen >> 8;
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
165 databuf[6] = reclen;
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
166 cc = write(target_fd, databuf, reclen + 7);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
167 if (cc != reclen + 7) {
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 fclose(binf);
665
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
169 perror("binary write to target");
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 }
665
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
172 i = collect_binblock_from_target(&ackbyte, 1, 8);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 if (i) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 fclose(binf);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 return(i);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 }
665
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
177 if (ackbyte == 0x15) { /* NAK */
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
178 fclose(binf);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
179 tpinterf_pass_output(1);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
180 return(-1);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
181 }
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
182 if (ackbyte != 0x06) { /* ACK */
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
183 fclose(binf);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
184 fprintf(stderr,
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
185 "binary protocol error: bad ack 0x%02X\n",
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
186 ackbyte);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
187 return(-1);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
188 }
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 flashoff += reclen;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 len -= reclen;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 bytesdone += reclen;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 cc = bytesdone * 100 / origlen;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 time(&curtime);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 if (curtime != last_time || cc == 100) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 printf("\r0x%lx bytes programmed (%i%%)",
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 bytesdone, cc);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 fflush(stdout);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 last_time = curtime;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 putchar('\n');
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 fclose(binf);
665
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
203 databuf[0] = 0x04; /* EOT */
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
204 write(target_fd, databuf, 1);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
205 i = collect_binblock_from_target(&ackbyte, 1, 1);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
206 if (i)
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
207 return(i);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
208 time(&last_time);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
209 if (ackbyte != '=') {
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
210 fprintf(stderr, "error: \'=\' not received as expected\n");
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
211 return(-1);
b43d8c2725b9 fc-loadtool flash program-bin changed to use binary protocol
Mychaela Falconia <falcon@freecalypso.org>
parents: 612
diff changeset
212 }
612
52980e3a51c7 fc-loadtool: added operation time reporting to flash program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 506
diff changeset
213 duration = last_time - initial_time;
52980e3a51c7 fc-loadtool: added operation time reporting to flash program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 506
diff changeset
214 mm = duration / 60;
52980e3a51c7 fc-loadtool: added operation time reporting to flash program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 506
diff changeset
215 ss = duration - mm * 60;
52980e3a51c7 fc-loadtool: added operation time reporting to flash program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 506
diff changeset
216 printf("Operation completed in %um%us\n", mm, ss);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 /* reset flash to read mode */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 if (bi->ops->reset_cmd(bi) < 0)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 printf("Verifying CRC-32 of programmed flash area\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 if (crc32_on_target(crc_base_addr, origlen, &crc_from_target) < 0)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 if (crc_from_target == crcaccum) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 printf("match (%08lX)\n", crc_from_target);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 return(0);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 } else {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 fprintf(stderr, "error: CRC mismatch!\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 }
672
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
232
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
233 flashcmd_progbin_wrap(argc, argv, bank)
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
234 char **argv;
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
235 {
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
236 u_long flashoff, fileoff, len;
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
237 int len_given;
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
238 char *strtoul_endp;
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
239
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
240 if (argc < 4 || argc > 6) {
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
241 inv: fprintf(stderr,
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
242 "usage: %s %s flash-offset binfile [file-offset [length]]\n",
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
243 argv[0], argv[1]);
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
244 return(-1);
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
245 }
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
246 flashoff = strtoul(argv[2], &strtoul_endp, 16);
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
247 if (*strtoul_endp)
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
248 goto inv;
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
249 if (argc > 4) {
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
250 fileoff = strtoul(argv[4], &strtoul_endp, 16);
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
251 if (*strtoul_endp)
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
252 goto inv;
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
253 } else
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
254 fileoff = 0;
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
255 if (argc > 5) {
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
256 len = strtoul(argv[5], &strtoul_endp, 16);
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
257 if (*strtoul_endp)
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
258 goto inv;
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
259 len_given = 1;
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
260 } else {
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
261 len = 0; /* dummy */
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
262 len_given = 0;
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
263 }
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
264 return flashcmd_progbin_int(bank, argv[1][0] == 'e', flashoff, argv[3],
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
265 fileoff, len, len_given);
57cb825b505a fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
Mychaela Falconia <falcon@freecalypso.org>
parents: 666
diff changeset
266 }