FreeCalypso > hg > freecalypso-sw
annotate loadtools/flmisc.c @ 955:d7830aee0d35
c139-lldbg hack concocted
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Wed, 04 Nov 2015 20:34:12 +0000 |
parents | 81d387690063 |
children |
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 } |
406
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
49 /* reset flash to read mode */ |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
50 if (bi->ops->reset_cmd(bi) < 0) |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
51 return(-1); |
60
048329d0888e
fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
58
diff
changeset
|
52 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
|
53 sprintf(targ_len, "%lx", len); |
048329d0888e
fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
58
diff
changeset
|
54 targv[0] = "blankchk"; |
048329d0888e
fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
58
diff
changeset
|
55 targv[1] = targ_start; |
048329d0888e
fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
58
diff
changeset
|
56 targv[2] = targ_len; |
048329d0888e
fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
58
diff
changeset
|
57 targv[3] = 0; |
048329d0888e
fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
58
diff
changeset
|
58 tpinterf_make_cmd(targv); |
048329d0888e
fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
58
diff
changeset
|
59 if (tpinterf_send_cmd() < 0) |
048329d0888e
fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
58
diff
changeset
|
60 return(-1); |
048329d0888e
fc-loadtool: flash blankchk implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
58
diff
changeset
|
61 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
|
62 } |
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 flashcmd_dump2file(argc, argv, bank) |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
65 char **argv; |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
66 { |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
67 struct flash_bank_info *bi; |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
68 u_long offset, dumplen, maxlen; |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
69 char *strtoul_endp; |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
70 int format; |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
71 |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
72 if (argc < 3 || argc > 5) { |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
73 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
|
74 argv[0], argv[1]); |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
75 return(-1); |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
76 } |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
77 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
|
78 return(-1); |
58
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
79 bi = flash_bank_info + bank; |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
80 if (argc >= 4) { |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
81 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
|
82 if (*strtoul_endp) |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
83 goto inv; |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
84 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
|
85 fprintf(stderr, |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
86 "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
|
87 (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
|
88 return(-1); |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
89 } |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
90 } else |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
91 offset = 0; |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
92 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
|
93 if (argc >= 5) { |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
94 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
|
95 if (*strtoul_endp) |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
96 goto inv; |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
97 if (dumplen > maxlen) { |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
98 fprintf(stderr, |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
99 "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
|
100 (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
|
101 return(-1); |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
102 } |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
103 } else |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
104 dumplen = maxlen; |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
105 switch (argv[1][5]) { |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
106 case 'b': |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
107 format = 0; |
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 case 's': |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
110 format = 1; |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
111 break; |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
112 default: |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
113 fprintf(stderr, |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
114 "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
|
115 return(-1); |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
116 } |
406
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
117 /* reset flash to read mode */ |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
118 if (bi->ops->reset_cmd(bi) < 0) |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
119 return(-1); |
58
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
120 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
|
121 format); |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
122 } |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
123 |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
124 flashcmd_erase(argc, argv, bank) |
58
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
125 char **argv; |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
126 { |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
127 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
|
128 u_long offset, len; |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
129 char *strtoul_endp; |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
130 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
|
131 int stat; |
58
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
132 |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
133 if (argc != 4) { |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
134 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
|
135 argv[0], argv[1]); |
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 } |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
138 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
|
139 if (*strtoul_endp) |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
140 goto inv; |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
141 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
|
142 return(-1); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
143 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
|
144 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
|
145 fprintf(stderr, |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
146 "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
|
147 (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
|
148 return(-1); |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
149 } |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
150 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
|
151 if (*strtoul_endp) |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
152 goto inv; |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
153 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
|
154 fprintf(stderr, |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
155 "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
|
156 (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
|
157 return(-1); |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
158 } |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
159 if (!len) { |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
160 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
|
161 return(0); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
162 } |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
163 /* 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
|
164 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
|
165 return(-1); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
166 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
|
167 return(-1); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
168 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
|
169 if (stat) |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
170 return(stat); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 if (stat) |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
175 return(stat); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
176 putchar('.'); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
177 fflush(stdout); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
178 } |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
179 putchar('\n'); |
58
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
180 return(0); |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
181 } |
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
182 |
64
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
183 flashcmd_quickprog(argc, argv, bank) |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
184 char **argv; |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
185 { |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
186 struct flash_bank_info *bi; |
64
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
187 char *targv[4], targ_base[10]; |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
188 int stat; |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
189 |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
190 if (argc != 4) { |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
191 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
|
192 argv[0], argv[1]); |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
193 return(-1); |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
194 } |
410
81d387690063
Intel flash: clear SR before programming
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
409
diff
changeset
|
195 if (flash_get_cfi(bank) < 0) |
81d387690063
Intel flash: clear SR before programming
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
409
diff
changeset
|
196 return(-1); |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
197 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
|
198 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
|
199 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
|
200 targv[1] = targ_base; |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
201 targv[2] = 0; |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
202 tpinterf_make_cmd(targv); |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
203 if (tpinterf_send_cmd() < 0) |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
204 return(-1); |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
205 stat = tpinterf_pass_output(1); |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
206 if (stat) |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
207 return(stat); |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
208 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
|
209 targv[1] = argv[2]; |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
210 targv[2] = argv[3]; |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
211 targv[3] = 0; |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
212 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
|
213 fprintf(stderr, |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
401
diff
changeset
|
214 "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
|
215 return(-1); |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
216 } |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
217 if (tpinterf_send_cmd() < 0) |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
218 return(-1); |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
219 return tpinterf_pass_output(1); |
a481d648278a
fc-loadtool: "quick program" command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
220 } |
406
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
221 |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
222 flashcmd_reset(argc, argv, bank) |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
223 char **argv; |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
224 { |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
225 struct flash_bank_info *bi; |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
226 |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
227 if (argc > 2) { |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
228 fprintf(stderr, "error: too many arguments\n"); |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
229 return(-1); |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
230 } |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
231 if (flash_get_cfi(bank) < 0) |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
232 return(-1); |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
233 bi = flash_bank_info + bank; |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
234 return bi->ops->reset_cmd(bi); |
0b8e5072abde
fc-loadtool flash: reset to read mode added where appropriate
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
235 } |
408
431023033c86
Intel flash: flash status command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
406
diff
changeset
|
236 |
431023033c86
Intel flash: flash status command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
406
diff
changeset
|
237 flashcmd_status(argc, argv, bank) |
431023033c86
Intel flash: flash status command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
406
diff
changeset
|
238 char **argv; |
431023033c86
Intel flash: flash status command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
406
diff
changeset
|
239 { |
431023033c86
Intel flash: flash status command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
406
diff
changeset
|
240 struct flash_bank_info *bi; |
431023033c86
Intel flash: flash status command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
406
diff
changeset
|
241 |
431023033c86
Intel flash: flash status command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
406
diff
changeset
|
242 if (argc > 2) { |
431023033c86
Intel flash: flash status command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
406
diff
changeset
|
243 fprintf(stderr, "error: too many arguments\n"); |
431023033c86
Intel flash: flash status command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
406
diff
changeset
|
244 return(-1); |
431023033c86
Intel flash: flash status command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
406
diff
changeset
|
245 } |
431023033c86
Intel flash: flash status command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
406
diff
changeset
|
246 if (flash_get_cfi(bank) < 0) |
431023033c86
Intel flash: flash status command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
406
diff
changeset
|
247 return(-1); |
431023033c86
Intel flash: flash status command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
406
diff
changeset
|
248 bi = flash_bank_info + bank; |
431023033c86
Intel flash: flash status command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
406
diff
changeset
|
249 return bi->ops->status_cmd(bi); |
431023033c86
Intel flash: flash status command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
406
diff
changeset
|
250 } |
409
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
251 |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
252 flashcmd_unlock(argc, argv, bank) |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
253 char **argv; |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
254 { |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
255 struct flash_bank_info *bi; |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
256 u_long offset, len; |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
257 char *strtoul_endp; |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
258 struct sector_info *startsec, *endsec, *sp; |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
259 int stat; |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
260 |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
261 if (flash_get_cfi(bank) < 0) |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
262 return(-1); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
263 bi = flash_bank_info + bank; |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
264 if (!bi->ops->needs_unlock) { |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
265 fprintf(stderr, |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
266 "This operation is not applicable to the selected flash type\n"); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
267 return(-1); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
268 } |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
269 if (argc != 4) { |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
270 inv: fprintf(stderr, "usage: %s %s hex-start-offset hex-length\n", |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
271 argv[0], argv[1]); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
272 return(-1); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
273 } |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
274 offset = strtoul(argv[2], &strtoul_endp, 16); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
275 if (*strtoul_endp) |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
276 goto inv; |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
277 if (offset >= bi->geom->total_size) { |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
278 fprintf(stderr, |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
279 "error: specified offset exceeds flash bank size (0x%lx)\n", |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
280 (u_long) bi->geom->total_size); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
281 return(-1); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
282 } |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
283 len = strtoul(argv[3], &strtoul_endp, 16); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
284 if (*strtoul_endp) |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
285 goto inv; |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
286 if (len > bi->geom->total_size - offset) { |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
287 fprintf(stderr, |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
288 "error: specified offset+length exceed flash bank size (0x%lx)\n", |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
289 (u_long) bi->geom->total_size); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
290 return(-1); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
291 } |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
292 if (!len) { |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
293 printf("Zero length specified - nothing to do!\n"); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
294 return(0); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
295 } |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
296 /* now enforce sector alignment for both offset and length */ |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
297 if (get_flash_sector_table(bank) < 0) |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
298 return(-1); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
299 if (get_flash_sector_range(bi, offset, len, &startsec, &endsec) < 0) |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
300 return(-1); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
301 printf("Unlocking %d sector(s)\n", endsec - startsec); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
302 for (sp = startsec; sp < endsec; sp++) { |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
303 stat = bi->ops->unlock_sector(bi, sp); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
304 if (stat) |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
305 return(stat); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
306 putchar('.'); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
307 fflush(stdout); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
308 } |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
309 putchar('\n'); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
310 return(0); |
23ab8fe81764
Intel flash: unlock command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
408
diff
changeset
|
311 } |