annotate loadtools/flmisc.c @ 405:a212b4968b29

fc-loadtool flash: another refactoring: geometry vs. command set
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 17 Jun 2014 00:33:05 +0000
parents loadtools/ltflash.c@7ceeec049be4
children 0b8e5072abde
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
55
278052b6afda loadtools: started laying the foundation for flash support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
2 * Miscellaneous flash commands (fc-loadtool) are implemented here
55
278052b6afda loadtools: started laying the foundation for flash support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
278052b6afda loadtools: started laying the foundation for flash support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
278052b6afda loadtools: started laying the foundation for flash support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
278052b6afda loadtools: started laying the foundation for flash support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
278052b6afda loadtools: started laying the foundation for flash support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdint.h>
278052b6afda loadtools: started laying the foundation for flash support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
278052b6afda loadtools: started laying the foundation for flash support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
278052b6afda loadtools: started laying the foundation for flash support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <stdlib.h>
278052b6afda loadtools: started laying the foundation for flash support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "flash.h"
278052b6afda loadtools: started laying the foundation for flash support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
13 extern struct flash_bank_info flash_bank_info[2];
58
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
14
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
15 flashcmd_blankchk(argc, argv, bank)
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
16 char **argv;
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
17 {
60
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
18 struct flash_bank_info *bi;
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
19 u_long offset, len;
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
20 char *strtoul_endp;
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
21 char *targv[4], targ_start[10], targ_len[10];
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
22
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
23 if (argc != 4) {
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
24 inv: fprintf(stderr, "usage: %s %s hex-start-offset hex-length\n",
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
25 argv[0], argv[1]);
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
26 return(-1);
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
27 }
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
28 offset = strtoul(argv[2], &strtoul_endp, 16);
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
29 if (*strtoul_endp)
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
30 goto inv;
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
31 if (flash_get_cfi(bank) < 0)
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
32 return(-1);
60
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
33 bi = flash_bank_info + bank;
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
34 if (offset >= bi->geom->total_size) {
60
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
35 fprintf(stderr,
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
36 "error: specified offset exceeds flash bank size (0x%lx)\n",
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
37 (u_long) bi->geom->total_size);
60
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
38 return(-1);
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
39 }
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
40 len = strtoul(argv[3], &strtoul_endp, 16);
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
41 if (*strtoul_endp)
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
42 goto inv;
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
43 if (len > bi->geom->total_size - offset) {
60
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
44 fprintf(stderr,
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
45 "error: specified offset+length exceed flash bank size (0x%lx)\n",
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
46 (u_long) bi->geom->total_size);
60
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
47 return(-1);
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
48 }
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
49 sprintf(targ_start, "%lx", (u_long) bi->base_addr + offset);
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
50 sprintf(targ_len, "%lx", len);
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
51 targv[0] = "blankchk";
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
52 targv[1] = targ_start;
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
53 targv[2] = targ_len;
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
54 targv[3] = 0;
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
55 tpinterf_make_cmd(targv);
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
56 if (tpinterf_send_cmd() < 0)
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
57 return(-1);
048329d0888e fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 58
diff changeset
58 return tpinterf_pass_output(10); /* 10 s timeout */
58
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
59 }
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
60
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
61 flashcmd_dump2file(argc, argv, bank)
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
62 char **argv;
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
63 {
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
64 struct flash_bank_info *bi;
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
65 u_long offset, dumplen, maxlen;
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
66 char *strtoul_endp;
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
67 int format;
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
68
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
69 if (argc < 3 || argc > 5) {
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
70 inv: fprintf(stderr, "usage: %s %s outfile [offset [length]]\n",
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
71 argv[0], argv[1]);
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
72 return(-1);
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
73 }
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
74 if (flash_get_cfi(bank) < 0)
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
75 return(-1);
58
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
76 bi = flash_bank_info + bank;
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
77 if (argc >= 4) {
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
78 offset = strtoul(argv[3], &strtoul_endp, 16);
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
79 if (*strtoul_endp)
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
80 goto inv;
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
81 if (offset >= bi->geom->total_size) {
58
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
82 fprintf(stderr,
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
83 "error: specified offset exceeds flash bank size (0x%lx)\n",
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
84 (u_long) bi->geom->total_size);
58
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
85 return(-1);
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
86 }
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
87 } else
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
88 offset = 0;
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
89 maxlen = bi->geom->total_size - offset;
58
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
90 if (argc >= 5) {
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
91 dumplen = strtoul(argv[4], &strtoul_endp, 16);
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
92 if (*strtoul_endp)
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
93 goto inv;
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
94 if (dumplen > maxlen) {
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
95 fprintf(stderr,
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
96 "error: specified offset+length exceed flash bank size (0x%lx)\n",
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
97 (u_long) bi->geom->total_size);
58
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
98 return(-1);
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
99 }
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
100 } else
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
101 dumplen = maxlen;
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
102 switch (argv[1][5]) {
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
103 case 'b':
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
104 format = 0;
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
105 break;
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
106 case 's':
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
107 format = 1;
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
108 break;
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
109 default:
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
110 fprintf(stderr,
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
111 "internal bug: bad format in flashcmd_dump2file()\n");
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
112 return(-1);
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
113 }
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
114 return loadtool_memdump(bi->base_addr + offset, dumplen, argv[2],
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
115 format);
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
116 }
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
117
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
118 flashcmd_erase(argc, argv, bank)
58
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
119 char **argv;
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
120 {
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
121 struct flash_bank_info *bi;
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
122 u_long offset, len;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
123 char *strtoul_endp;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
124 struct sector_info *startsec, *endsec, *sp;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
125 int stat;
58
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
126
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
127 if (argc != 4) {
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
128 inv: fprintf(stderr, "usage: %s %s hex-start-offset hex-length\n",
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
129 argv[0], argv[1]);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
130 return(-1);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
131 }
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
132 offset = strtoul(argv[2], &strtoul_endp, 16);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
133 if (*strtoul_endp)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
134 goto inv;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
135 if (flash_get_cfi(bank) < 0)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
136 return(-1);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
137 bi = flash_bank_info + bank;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
138 if (offset >= bi->geom->total_size) {
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
139 fprintf(stderr,
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
140 "error: specified offset exceeds flash bank size (0x%lx)\n",
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
141 (u_long) bi->geom->total_size);
58
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
142 return(-1);
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
143 }
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
144 len = strtoul(argv[3], &strtoul_endp, 16);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
145 if (*strtoul_endp)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
146 goto inv;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
147 if (len > bi->geom->total_size - offset) {
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
148 fprintf(stderr,
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
149 "error: specified offset+length exceed flash bank size (0x%lx)\n",
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
150 (u_long) bi->geom->total_size);
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
151 return(-1);
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
152 }
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
153 if (!len) {
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
154 printf("Zero length specified - nothing to do!\n");
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
155 return(0);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
156 }
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
157 /* now enforce sector alignment for both offset and length */
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
158 if (get_flash_sector_table(bank) < 0)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
159 return(-1);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
160 if (get_flash_sector_range(bi, offset, len, &startsec, &endsec) < 0)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
161 return(-1);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
162 stat = flash_id_check(bank, 0);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
163 if (stat)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
164 return(stat);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
165 printf("Erasing %d sector(s)\n", endsec - startsec);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
166 for (sp = startsec; sp < endsec; sp++) {
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
167 stat = bi->ops->erase_sector(bi, sp);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
168 if (stat)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
169 return(stat);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
170 putchar('.');
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
171 fflush(stdout);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
172 }
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
173 putchar('\n');
58
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
174 return(0);
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
175 }
1f9302b6f342 fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
176
64
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
177 flashcmd_quickprog(argc, argv, bank)
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
178 char **argv;
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
179 {
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
180 struct flash_bank_info *bi;
64
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
181 char *targv[4], targ_base[10];
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
182 int stat;
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
183
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
184 if (flash_get_cfi(bank) < 0)
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
185 return(-1);
64
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
186 if (argc != 4) {
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
187 fprintf(stderr, "usage: %s %s hex-offset hex-data-string\n",
64
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
188 argv[0], argv[1]);
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
189 return(-1);
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
190 }
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
191 bi = flash_bank_info + bank;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
192 sprintf(targ_base, "%lx", (u_long) bi->base_addr);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
193 targv[0] = bi->ops->loadagent_setbase_cmd;
64
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
194 targv[1] = targ_base;
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
195 targv[2] = 0;
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
196 tpinterf_make_cmd(targv);
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
197 if (tpinterf_send_cmd() < 0)
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
198 return(-1);
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
199 stat = tpinterf_pass_output(1);
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
200 if (stat)
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
201 return(stat);
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
202 targv[0] = bi->ops->loadagent_program_cmd;
64
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
203 targv[1] = argv[2];
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
204 targv[2] = argv[3];
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
205 targv[3] = 0;
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
206 if (tpinterf_make_cmd(targv) < 0) {
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
207 fprintf(stderr,
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 401
diff changeset
208 "error: unable to form AMFW/INFW target command\n");
64
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
209 return(-1);
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
210 }
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
211 if (tpinterf_send_cmd() < 0)
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
212 return(-1);
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
213 return tpinterf_pass_output(1);
a481d648278a fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
214 }