FreeCalypso > hg > freecalypso-sw
comparison 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 |
comparison
equal
deleted
inserted
replaced
399:d26a9e3de626 | 400:f027c6fbe37e |
---|---|
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include "flash.h" | 9 #include "flash.h" |
10 | 10 |
11 extern struct flash_bank_info flash_bank_info[2]; | 11 extern struct flash_bank_info flash_bank_info[2]; |
12 | 12 |
13 compute_flash_totsize_nsecs(bank) | 13 flash_get_cfi(bank) |
14 { | 14 { |
15 struct flash_bank_info *bi; | 15 struct flash_bank_info *bi; |
16 struct flash_region_desc *reg; | 16 |
17 | 17 bi = flash_bank_info + bank; |
18 bi = flash_bank_info + bank; | 18 if (bi->cfi) |
19 for (reg = bi->bank_desc->regions; reg->nsectors; reg++) { | 19 return(0); |
20 bi->nsectors += reg->nsectors; | 20 printf("Error: CFI info retrieval not implemented yet\n"); |
21 bi->total_size += reg->sector_size * reg->nsectors; | 21 return(-1); |
22 } | |
23 } | |
24 | |
25 /* the following function is used to verify that total_size is a power of 2 */ | |
26 count_ones(word) | |
27 uint32_t word; | |
28 { | |
29 int count; | |
30 | |
31 for (count = 0; word; word >>= 1) | |
32 count += word & 1; | |
33 return count; | |
34 } | 22 } |
35 | 23 |
36 get_flash_sector_table(bank) | 24 get_flash_sector_table(bank) |
37 { | 25 { |
38 struct flash_bank_info *bi; | 26 struct flash_bank_info *bi; |
27 struct cfi_info *cfi; | |
39 struct flash_region_desc *reg; | 28 struct flash_region_desc *reg; |
40 struct sector_info *sp; | 29 struct sector_info *sp; |
41 uint32_t offset; | 30 uint32_t offset; |
42 int i; | 31 int nr, i; |
43 | 32 |
44 bi = flash_bank_info + bank; | 33 bi = flash_bank_info + bank; |
45 if (bi->sectors) | 34 if (bi->sectors) |
46 return(0); | 35 return(0); |
36 i = flash_get_cfi(bank); | |
37 if (i < 0) | |
38 return(i); | |
39 cfi = bi->cfi; | |
47 sp = (struct sector_info *) malloc(sizeof(struct sector_info) | 40 sp = (struct sector_info *) malloc(sizeof(struct sector_info) |
48 * (bi->nsectors + 1)); | 41 * (cfi->total_sectors + 1)); |
49 if (!sp) { | 42 if (!sp) { |
50 fprintf(stderr, | 43 fprintf(stderr, |
51 "unable to malloc buffer for flash bank %d sector table\n", | 44 "unable to malloc buffer for flash bank %d sector table\n", |
52 bank); | 45 bank); |
53 return(-1); | 46 return(-1); |
54 } | 47 } |
55 bi->sectors = sp; | 48 bi->sectors = sp; |
56 /* now fill it */ | 49 /* now fill it */ |
57 offset = 0; | 50 offset = 0; |
58 for (reg = bi->bank_desc->regions; reg->nsectors; reg++) { | 51 for (nr = 0; nr < cfi->nregions; nr++) { |
52 reg = cfi->regions + nr; | |
59 for (i = 0; i < reg->nsectors; i++) { | 53 for (i = 0; i < reg->nsectors; i++) { |
60 sp->start = offset; | 54 sp->start = offset; |
61 sp->size = reg->sector_size; | 55 sp->size = reg->sector_size; |
62 sp++; | 56 sp++; |
63 offset += reg->sector_size; | 57 offset += reg->sector_size; |
64 } | 58 } |
65 } | 59 } |
66 /* sanity checks */ | 60 /* sanity checks */ |
67 if (sp - bi->sectors != bi->nsectors) { | 61 if (sp - bi->sectors != cfi->total_sectors) { |
68 fprintf(stderr, | 62 fprintf(stderr, |
69 "BUG in get_flash_sector_table(): wrong # of sectors at the end\n"); | 63 "BUG in get_flash_sector_table(): wrong # of sectors at the end\n"); |
70 abort(); | 64 abort(); |
71 } | 65 } |
72 if (offset != bi->total_size) { | 66 if (offset != cfi->total_size) { |
73 fprintf(stderr, | 67 fprintf(stderr, |
74 "BUG in get_flash_sector_table(): wrong offset at the end\n"); | 68 "BUG in get_flash_sector_table(): wrong offset at the end\n"); |
75 abort(); | 69 abort(); |
76 } | 70 } |
77 /* finish */ | 71 /* finish */ |
91 return(-1); | 85 return(-1); |
92 } | 86 } |
93 if (get_flash_sector_table(bank) < 0) | 87 if (get_flash_sector_table(bank) < 0) |
94 return(-1); | 88 return(-1); |
95 bi = flash_bank_info + bank; | 89 bi = flash_bank_info + bank; |
96 printf("%u sectors in flash bank %d:\n", bi->nsectors, bank); | 90 printf("%u sectors in flash bank %d:\n", bi->cfi->total_sectors, bank); |
97 printf("Offset Size\n"); | 91 printf("Offset Size\n"); |
98 for (sp = bi->sectors; sp->size; sp++) | 92 for (sp = bi->sectors; sp->size; sp++) |
99 printf("%08lX %lx\n", (u_long) sp->start, (u_long) sp->size); | 93 printf("%08lX %lx\n", (u_long) sp->start, (u_long) sp->size); |
100 return(0); | 94 return(0); |
101 } | 95 } |
158 unsigned cnt; | 152 unsigned cnt; |
159 | 153 |
160 bi = flash_bank_info + bank; | 154 bi = flash_bank_info + bank; |
161 if (bi->idcheck_done && !repeat) | 155 if (bi->idcheck_done && !repeat) |
162 return(0); | 156 return(0); |
157 bd = bi->bank_desc; | |
158 if (!bd->idcheck_table || !bd->idcheck_num) | |
159 return(0); | |
163 printf("Performing flash ID check\n"); | 160 printf("Performing flash ID check\n"); |
164 stat = do_w16(bi->base_addr + 0xAAA, 0xAA); | 161 stat = do_w16(bi->base_addr + 0xAAA, 0xAA); |
165 if (stat) { | 162 if (stat) { |
166 bad_w16: fprintf(stderr, | 163 bad_w16: fprintf(stderr, |
167 "unexpected response to w16 in read ID cmd sequence - aborting\n"); | 164 "unexpected response to w16 in read ID cmd sequence - aborting\n"); |
171 if (stat) | 168 if (stat) |
172 goto bad_w16; | 169 goto bad_w16; |
173 stat = do_w16(bi->base_addr + 0xAAA, 0x90); | 170 stat = do_w16(bi->base_addr + 0xAAA, 0x90); |
174 if (stat) | 171 if (stat) |
175 goto bad_w16; | 172 goto bad_w16; |
176 bd = bi->bank_desc; | |
177 id = bd->idcheck_table; | 173 id = bd->idcheck_table; |
178 fail = 0; | 174 fail = 0; |
179 for (cnt = 0; cnt < bd->idcheck_num; cnt++) { | 175 for (cnt = 0; cnt < bd->idcheck_num; cnt++) { |
180 stat = do_r16(bi->base_addr + id->offset, &rdval); | 176 stat = do_r16(bi->base_addr + id->offset, &rdval); |
181 if (stat) | 177 if (stat) |