FreeCalypso > hg > freecalypso-sw
annotate loadtools/flutil.c @ 726:105ac33aa5a1
mm_regf.c compiles
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sat, 04 Oct 2014 21:45:54 +0000 |
parents | f2cc551e597f |
children |
rev | line source |
---|---|
56
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * Miscellaneous utility functions for flash support |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdint.h> |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <stdlib.h> |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include "flash.h" |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 extern struct flash_bank_info flash_bank_info[2]; |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
12 extern struct flash_cmdset flash_cmdset_amd; |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
13 extern struct flash_cmdset flash_cmdset_intel; |
56
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
15 static int |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
16 cfi_read_byte(bi, off, ret16p) |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
17 struct flash_bank_info *bi; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
18 int off; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
19 uint16_t *ret16p; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
20 { |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
21 return do_r16(bi->base_addr + (off << 1), ret16p); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
22 } |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
23 |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
24 static int |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
25 cfi_read_twobyte(bi, off, retptr) |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
26 struct flash_bank_info *bi; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
27 int off; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
28 uint16_t *retptr; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
29 { |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
30 uint16_t lo, hi; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
31 |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
32 if (cfi_read_byte(bi, off, &lo) < 0) |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
33 return(-1); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
34 lo &= 0xFF; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
35 if (cfi_read_byte(bi, off + 1, &hi) < 0) |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
36 return(-1); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
37 hi &= 0xFF; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
38 *retptr = (hi << 8) | lo; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
39 return(0); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
40 } |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
41 |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
42 flash_get_cfi(bank) |
56
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 { |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 struct flash_bank_info *bi; |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
45 struct flash_geom *geom; |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
46 struct flash_region_desc *reg; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
47 int nr; |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
48 uint16_t rdval, cmdset_id; |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
49 uint32_t size_check; |
56
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 bi = flash_bank_info + bank; |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
52 if (bi->geom) |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
53 return(0); |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
54 printf("Performing CFI query\n"); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
55 if (do_w16(bi->base_addr + 0xAA, 0x98)) { |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
56 fprintf(stderr, "unexpected response to w16 - aborting\n"); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
57 return(-1); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
58 } |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
59 /* if do_r16() returns -1, error msg has already been printed */ |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
60 if (cfi_read_byte(bi, 0x10, &rdval) < 0) |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
61 return(-1); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
62 if (rdval != 'Q') { |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
63 noqry: fprintf(stderr, "error: no QRY response from flash\n"); |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
64 amd_reset_cmd(bi); |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
65 return(-1); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
66 } |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
67 if (cfi_read_byte(bi, 0x11, &rdval) < 0) |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
68 return(-1); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
69 if (rdval != 'R') |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
70 goto noqry; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
71 if (cfi_read_byte(bi, 0x12, &rdval) < 0) |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
72 return(-1); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
73 if (rdval != 'Y') |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
74 goto noqry; |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
75 if (cfi_read_twobyte(bi, 0x13, &cmdset_id) < 0) |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
76 return(-1); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
77 if (!bi->ops) { |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
78 switch (cmdset_id) { |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
79 case 2: |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
80 bi->ops = &flash_cmdset_amd; |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
81 break; |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
82 case 3: |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
83 bi->ops = &flash_cmdset_intel; |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
84 break; |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
85 default: |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
86 fprintf(stderr, "error: command set %04X unsupported\n", |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
87 cmdset_id); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
88 amd_reset_cmd(bi); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
89 return(-1); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
90 } |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
91 } |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
92 geom = malloc(sizeof(struct flash_geom)); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
93 if (!geom) { |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
94 fprintf(stderr, |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
95 "unable to malloc buffer for flash bank %d CFI geometry structure\n", |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
96 bank); |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
97 bi->ops->reset_cmd(bi); |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
98 return(-1); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
99 } |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
100 /* total device size */ |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
101 if (cfi_read_byte(bi, 0x27, &rdval) < 0) { |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
102 free_and_immed_out: |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
103 free(geom); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
104 return(-1); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
105 } |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
106 if (rdval < 20 || rdval > 24) { |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
107 fprintf(stderr, |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
108 "error: CFI reports unreasonable device size\n"); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
109 free_and_clean_out: |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
110 free(geom); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
111 bi->ops->reset_cmd(bi); |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
112 return(-1); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
113 } |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
114 geom->total_size = 1 << rdval; |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
115 if (geom->total_size > bi->bank_desc->align_size) { |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
116 fprintf(stderr, |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
117 "error: CFI device size 0x%lx exceeds configured maximum 0x%lx\n", |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
118 (u_long) geom->total_size, bi->bank_desc->align_size); |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
119 goto free_and_clean_out; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
120 } |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
121 if (cfi_read_byte(bi, 0x2C, &rdval) < 0) |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
122 goto free_and_immed_out; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
123 if (rdval < 1 || rdval > CFI_MAX_REGIONS) { |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
124 fprintf(stderr, |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
125 "error: CFI reports unreasonable # of erase regions\n"); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
126 goto free_and_clean_out; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
127 } |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
128 geom->nregions = rdval; |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
129 geom->total_sectors = 0; |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
130 size_check = 0; |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
131 for (nr = 0; nr < geom->nregions; nr++) { |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
132 reg = geom->regions + nr; |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
133 if (cfi_read_twobyte(bi, 0x2D + nr*4, &rdval) < 0) |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
134 goto free_and_immed_out; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
135 if (rdval > 255) { |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
136 fprintf(stderr, |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
137 "error: CFI reports unreasonable # of sectors in region %d\n", |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
138 nr); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
139 goto free_and_clean_out; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
140 } |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
141 reg->nsectors = rdval + 1; |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
142 geom->total_sectors += reg->nsectors; |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
143 if (cfi_read_twobyte(bi, 0x2F + nr*4, &rdval) < 0) |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
144 goto free_and_immed_out; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
145 if (rdval < 0x20 || rdval > 0x400) { |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
146 fprintf(stderr, |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
147 "error: CFI reports unreasonable sector size in region %d\n", |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
148 nr); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
149 goto free_and_clean_out; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
150 } |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
151 reg->sector_size = rdval << 8; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
152 size_check += reg->sector_size * reg->nsectors; |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
153 } |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
154 if (bi->ops->reset_cmd(bi) < 0) { |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
155 /* error msg already printed */ |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
156 free(geom); |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
157 return(-1); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
158 } |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
159 if (size_check != geom->total_size) { |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
160 fprintf(stderr, |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
161 "CFI error: added size of erase regions (%lx) != reported devive size (%lx)\n", |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
162 (u_long) size_check, (u_long) geom->total_size); |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
163 free(geom); |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
164 return(-1); |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
165 } |
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
166 /* all checks passed */ |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
167 bi->geom = geom; |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
168 printf( |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
169 "CFI query successful: total size %lx, %u sectors, command set style %04X\n", |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
170 (u_long) geom->total_size, geom->total_sectors, cmdset_id); |
403
7602443edf0d
fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
171 return(1); |
56
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
172 } |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
173 |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
174 get_flash_sector_table(bank) |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
175 { |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
176 struct flash_bank_info *bi; |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
177 struct flash_geom *geom; |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
178 struct flash_region_desc *reg; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
179 struct sector_info *sp; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
180 uint32_t offset; |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
181 int nr, i; |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
182 |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
183 bi = flash_bank_info + bank; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
184 if (bi->sectors) |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
185 return(0); |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
186 i = flash_get_cfi(bank); |
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
187 if (i < 0) |
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
188 return(i); |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
189 geom = bi->geom; |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
190 sp = (struct sector_info *) malloc(sizeof(struct sector_info) |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
191 * (geom->total_sectors + 1)); |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
192 if (!sp) { |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
193 fprintf(stderr, |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
194 "unable to malloc buffer for flash bank %d sector table\n", |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
195 bank); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
196 return(-1); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
197 } |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
198 bi->sectors = sp; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
199 /* now fill it */ |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
200 offset = 0; |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
201 for (nr = 0; nr < geom->nregions; nr++) { |
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
202 reg = geom->regions + nr; |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
203 for (i = 0; i < reg->nsectors; i++) { |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
204 sp->start = offset; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
205 sp->size = reg->sector_size; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
206 sp++; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
207 offset += reg->sector_size; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
208 } |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
209 } |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
210 /* sanity checks */ |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
211 if (sp - bi->sectors != geom->total_sectors) { |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
212 fprintf(stderr, |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
213 "BUG in get_flash_sector_table(): wrong # of sectors at the end\n"); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
214 abort(); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
215 } |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
216 if (offset != geom->total_size) { |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
217 fprintf(stderr, |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
218 "BUG in get_flash_sector_table(): wrong offset at the end\n"); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
219 abort(); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
220 } |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
221 /* finish */ |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
222 sp->start = 0; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
223 sp->size = 0; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
224 return(0); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
225 } |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
226 |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
227 flashcmd_sectors(argc, argv, bank) |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
228 char **argv; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
229 { |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
230 struct flash_bank_info *bi; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
231 struct sector_info *sp; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
232 |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
233 if (argc > 2) { |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
234 fprintf(stderr, "error: too many arguments\n"); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
235 return(-1); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
236 } |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
237 if (get_flash_sector_table(bank) < 0) |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
238 return(-1); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
239 bi = flash_bank_info + bank; |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
403
diff
changeset
|
240 printf("%u sectors in flash bank %d:\n", bi->geom->total_sectors, bank); |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
241 printf("Offset Size\n"); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
242 for (sp = bi->sectors; sp->size; sp++) |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
243 printf("%08lX %lx\n", (u_long) sp->start, (u_long) sp->size); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
244 return(0); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
245 } |
62
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
246 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
247 get_flash_sector_range(bi, useroff, userlen, startp, endp) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
248 struct flash_bank_info *bi; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
249 u_long useroff, userlen; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
250 struct sector_info **startp, **endp; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
251 { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
252 struct sector_info *sp; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
253 uint32_t remlen; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
254 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
255 for (sp = bi->sectors; sp->size; sp++) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
256 if (sp->start == useroff) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
257 break; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
258 if (!sp->size) { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
259 fprintf(stderr, |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
260 "error: specified offset not aligned to a flash sector boundary\n"); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
261 return(-1); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
262 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
263 *startp = sp; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
264 for (remlen = userlen; remlen; ) { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
265 if (remlen < sp->size) { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
266 fprintf(stderr, |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
267 "error: specified length not aligned to a flash sector boundary\n"); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
268 return(-1); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
269 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
270 remlen -= sp->size; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
271 sp++; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
272 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
273 *endp = sp; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
274 return(0); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
275 } |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
276 |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
277 build_flashw_hex_string(bin, strbuf, nwords, m0src) |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
278 u_char *bin; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
279 char *strbuf; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
280 int nwords, m0src; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
281 { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
282 int i; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
283 u_char *dp; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
284 char *s; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
285 |
95
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
65
diff
changeset
|
286 for (dp = bin, s = strbuf, i = 0; i < nwords; dp += 2, s += 4, i++) { |
199
96f56e875862
fc-loadtool: minor polish in build_flashw_hex_string()
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
95
diff
changeset
|
287 if (m0src) |
96f56e875862
fc-loadtool: minor polish in build_flashw_hex_string()
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
95
diff
changeset
|
288 sprintf(s, "%02X%02X", dp[0], dp[1]); |
96f56e875862
fc-loadtool: minor polish in build_flashw_hex_string()
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
95
diff
changeset
|
289 else |
96f56e875862
fc-loadtool: minor polish in build_flashw_hex_string()
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
95
diff
changeset
|
290 sprintf(s, "%02X%02X", dp[1], dp[0]); |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
291 } |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
292 *s = '\0'; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
293 } |
204
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
294 |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
295 flash_id_check(bank, repeat) |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
296 { |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
297 struct flash_bank_info *bi; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
298 struct flash_bank_desc *bd; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
299 struct flash_idcheck *id; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
300 int stat, fail; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
301 uint16_t rdval; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
302 unsigned cnt; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
303 |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
304 bi = flash_bank_info + bank; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
305 if (bi->idcheck_done && !repeat) |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
306 return(0); |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
307 bd = bi->bank_desc; |
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
308 if (!bd->idcheck_table || !bd->idcheck_num) |
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
309 return(0); |
204
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
310 printf("Performing flash ID check\n"); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
311 stat = do_w16(bi->base_addr + 0xAAA, 0xAA); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
312 if (stat) { |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
313 bad_w16: fprintf(stderr, |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
314 "unexpected response to w16 in read ID cmd sequence - aborting\n"); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
315 return(-1); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
316 } |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
317 stat = do_w16(bi->base_addr + 0x554, 0x55); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
318 if (stat) |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
319 goto bad_w16; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
320 stat = do_w16(bi->base_addr + 0xAAA, 0x90); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
321 if (stat) |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
322 goto bad_w16; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
323 id = bd->idcheck_table; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
324 fail = 0; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
325 for (cnt = 0; cnt < bd->idcheck_num; cnt++) { |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
326 stat = do_r16(bi->base_addr + id->offset, &rdval); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
327 if (stat) |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
328 return(stat); /* error msg already printed */ |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
329 printf("offset %02X: %04X -- ", (int)id->offset, (int)rdval); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
330 if (rdval == id->expect_val) |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
331 printf("PASS\n"); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
332 else { |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
333 printf("FAIL: expected %04X\n", (int)id->expect_val); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
334 fail = 1; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
335 break; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
336 } |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
337 id++; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
338 } |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
339 /* reset flash to read mode */ |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
340 stat = do_w16(bi->base_addr + 0xAAA, 0xF0); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
341 if (stat) { |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
342 fprintf(stderr, |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
343 "unexpected response to w16 when resetting flash to read mode!\n"); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
344 return(-1); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
345 } |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
346 if (fail) |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
347 return(-1); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
348 bi->idcheck_done = 1; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
349 return(0); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
350 } |