FreeCalypso > hg > freecalypso-sw
annotate loadtools/flutil.c @ 400:f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 15 Jun 2014 20:05:54 +0000 |
parents | cd12d1049f91 |
children | 7602443edf0d |
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]; |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
13 flash_get_cfi(bank) |
56
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 { |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 struct flash_bank_info *bi; |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 |
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 bi = flash_bank_info + bank; |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
18 if (bi->cfi) |
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
19 return(0); |
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
20 printf("Error: CFI info retrieval not implemented yet\n"); |
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
21 return(-1); |
56
d98137625c0d
fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 } |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
23 |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
24 get_flash_sector_table(bank) |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
25 { |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
26 struct flash_bank_info *bi; |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
27 struct cfi_info *cfi; |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
28 struct flash_region_desc *reg; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
29 struct sector_info *sp; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
30 uint32_t offset; |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
31 int nr, i; |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
32 |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
33 bi = flash_bank_info + bank; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
34 if (bi->sectors) |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
35 return(0); |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
36 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
|
37 if (i < 0) |
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
38 return(i); |
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
39 cfi = bi->cfi; |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
40 sp = (struct sector_info *) malloc(sizeof(struct sector_info) |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
41 * (cfi->total_sectors + 1)); |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
42 if (!sp) { |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
43 fprintf(stderr, |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
44 "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
|
45 bank); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
46 return(-1); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
47 } |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
48 bi->sectors = sp; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
49 /* now fill it */ |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
50 offset = 0; |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
51 for (nr = 0; nr < cfi->nregions; nr++) { |
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
52 reg = cfi->regions + nr; |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
53 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
|
54 sp->start = offset; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
55 sp->size = reg->sector_size; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
56 sp++; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
57 offset += reg->sector_size; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
58 } |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
59 } |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
60 /* sanity checks */ |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
61 if (sp - bi->sectors != cfi->total_sectors) { |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
62 fprintf(stderr, |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
63 "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
|
64 abort(); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
65 } |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
66 if (offset != cfi->total_size) { |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
67 fprintf(stderr, |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
68 "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
|
69 abort(); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
70 } |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
71 /* finish */ |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
72 sp->start = 0; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
73 sp->size = 0; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
74 return(0); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
75 } |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
76 |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
77 flashcmd_sectors(argc, argv, bank) |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
78 char **argv; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
79 { |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
80 struct flash_bank_info *bi; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
81 struct sector_info *sp; |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
82 |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
83 if (argc > 2) { |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
84 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
|
85 return(-1); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
86 } |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
87 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
|
88 return(-1); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
89 bi = flash_bank_info + bank; |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
90 printf("%u sectors in flash bank %d:\n", bi->cfi->total_sectors, bank); |
61
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
91 printf("Offset Size\n"); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
92 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
|
93 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
|
94 return(0); |
a10491da8c3a
fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
56
diff
changeset
|
95 } |
62
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
96 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
97 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
|
98 struct flash_bank_info *bi; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
99 u_long useroff, userlen; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
100 struct sector_info **startp, **endp; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
101 { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
102 struct sector_info *sp; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
103 uint32_t remlen; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
104 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
105 for (sp = bi->sectors; sp->size; sp++) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
106 if (sp->start == useroff) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
107 break; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
108 if (!sp->size) { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
109 fprintf(stderr, |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
110 "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
|
111 return(-1); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
112 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
113 *startp = sp; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
114 for (remlen = userlen; remlen; ) { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
115 if (remlen < sp->size) { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
116 fprintf(stderr, |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
117 "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
|
118 return(-1); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
119 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
120 remlen -= sp->size; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
121 sp++; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
122 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
123 *endp = sp; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
124 return(0); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
61
diff
changeset
|
125 } |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
126 |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
127 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
|
128 u_char *bin; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
129 char *strbuf; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
130 int nwords, m0src; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
131 { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
132 int i; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
133 u_char *dp; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
134 char *s; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
135 |
95
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
65
diff
changeset
|
136 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
|
137 if (m0src) |
96f56e875862
fc-loadtool: minor polish in build_flashw_hex_string()
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
95
diff
changeset
|
138 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
|
139 else |
96f56e875862
fc-loadtool: minor polish in build_flashw_hex_string()
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
95
diff
changeset
|
140 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
|
141 } |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
142 *s = '\0'; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
143 } |
204
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
144 |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
145 flash_id_check(bank, repeat) |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
146 { |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
147 struct flash_bank_info *bi; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
148 struct flash_bank_desc *bd; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
149 struct flash_idcheck *id; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
150 int stat, fail; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
151 uint16_t rdval; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
152 unsigned cnt; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
153 |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
154 bi = flash_bank_info + bank; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
155 if (bi->idcheck_done && !repeat) |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
156 return(0); |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
157 bd = bi->bank_desc; |
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
158 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
|
159 return(0); |
204
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
160 printf("Performing flash ID check\n"); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
161 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
|
162 if (stat) { |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
163 bad_w16: fprintf(stderr, |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
164 "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
|
165 return(-1); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
166 } |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
167 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
|
168 if (stat) |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
169 goto bad_w16; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
170 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
|
171 if (stat) |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
172 goto bad_w16; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
173 id = bd->idcheck_table; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
174 fail = 0; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
175 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
|
176 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
|
177 if (stat) |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
178 return(stat); /* error msg already printed */ |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
179 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
|
180 if (rdval == id->expect_val) |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
181 printf("PASS\n"); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
182 else { |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
183 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
|
184 fail = 1; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
185 break; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
186 } |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
187 id++; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
188 } |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
189 /* reset flash to read mode */ |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
190 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
|
191 if (stat) { |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
192 fprintf(stderr, |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
193 "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
|
194 return(-1); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
195 } |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
196 if (fail) |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
197 return(-1); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
198 bi->idcheck_done = 1; |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
199 return(0); |
61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
199
diff
changeset
|
200 } |