FreeCalypso > hg > freecalypso-tools
comparison loadtools/flmisc.c @ 506:0dd2c87c1b63
fc-loadtool flash support overhaul
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 28 May 2019 05:12:47 +0000 |
parents | e7502631a0f9 |
children | 4be92bcd1535 |
comparison
equal
deleted
inserted
replaced
505:7bf0d909c87e | 506:0dd2c87c1b63 |
---|---|
26 return(-1); | 26 return(-1); |
27 } | 27 } |
28 offset = strtoul(argv[2], &strtoul_endp, 16); | 28 offset = strtoul(argv[2], &strtoul_endp, 16); |
29 if (*strtoul_endp) | 29 if (*strtoul_endp) |
30 goto inv; | 30 goto inv; |
31 if (flash_get_cfi(bank) < 0) | 31 if (flash_detect(bank, 0) < 0) |
32 return(-1); | 32 return(-1); |
33 bi = flash_bank_info + bank; | 33 bi = flash_bank_info + bank; |
34 if (offset >= bi->geom->total_size) { | 34 if (offset >= bi->geom->total_size) { |
35 fprintf(stderr, | 35 fprintf(stderr, |
36 "error: specified offset exceeds flash bank size (0x%lx)\n", | 36 "error: specified offset exceeds flash bank size (0x%lx)\n", |
72 if (argc < 3 || argc > 5) { | 72 if (argc < 3 || argc > 5) { |
73 inv: fprintf(stderr, "usage: %s %s outfile [offset [length]]\n", | 73 inv: fprintf(stderr, "usage: %s %s outfile [offset [length]]\n", |
74 argv[0], argv[1]); | 74 argv[0], argv[1]); |
75 return(-1); | 75 return(-1); |
76 } | 76 } |
77 if (flash_get_cfi(bank) < 0) | 77 if (flash_detect(bank, 0) < 0) |
78 return(-1); | 78 return(-1); |
79 bi = flash_bank_info + bank; | 79 bi = flash_bank_info + bank; |
80 if (argc >= 4) { | 80 if (argc >= 4) { |
81 offset = strtoul(argv[3], &strtoul_endp, 16); | 81 offset = strtoul(argv[3], &strtoul_endp, 16); |
82 if (*strtoul_endp) | 82 if (*strtoul_endp) |
136 return(-1); | 136 return(-1); |
137 } | 137 } |
138 offset = strtoul(argv[2], &strtoul_endp, 16); | 138 offset = strtoul(argv[2], &strtoul_endp, 16); |
139 if (*strtoul_endp) | 139 if (*strtoul_endp) |
140 goto inv; | 140 goto inv; |
141 if (flash_get_cfi(bank) < 0) | 141 if (flash_detect(bank, 0) < 0) |
142 return(-1); | 142 return(-1); |
143 bi = flash_bank_info + bank; | 143 bi = flash_bank_info + bank; |
144 if (offset >= bi->geom->total_size) { | 144 if (offset >= bi->geom->total_size) { |
145 fprintf(stderr, | 145 fprintf(stderr, |
146 "error: specified offset exceeds flash bank size (0x%lx)\n", | 146 "error: specified offset exceeds flash bank size (0x%lx)\n", |
163 /* now enforce sector alignment for both offset and length */ | 163 /* now enforce sector alignment for both offset and length */ |
164 if (get_flash_sector_table(bank) < 0) | 164 if (get_flash_sector_table(bank) < 0) |
165 return(-1); | 165 return(-1); |
166 if (get_flash_sector_range(bi, offset, len, &startsec, &endsec) < 0) | 166 if (get_flash_sector_range(bi, offset, len, &startsec, &endsec) < 0) |
167 return(-1); | 167 return(-1); |
168 stat = flash_id_check(bank, 0); | |
169 if (stat) | |
170 return(stat); | |
171 printf("Erasing %d sector(s)\n", endsec - startsec); | 168 printf("Erasing %d sector(s)\n", endsec - startsec); |
172 for (sp = startsec; sp < endsec; sp++) { | 169 for (sp = startsec; sp < endsec; sp++) { |
173 stat = bi->ops->erase_sector(bi, sp); | 170 stat = bi->ops->erase_sector(bi, sp); |
174 if (stat) | 171 if (stat) |
175 return(stat); | 172 return(stat); |
190 if (argc != 4) { | 187 if (argc != 4) { |
191 fprintf(stderr, "usage: %s %s hex-offset hex-data-string\n", | 188 fprintf(stderr, "usage: %s %s hex-offset hex-data-string\n", |
192 argv[0], argv[1]); | 189 argv[0], argv[1]); |
193 return(-1); | 190 return(-1); |
194 } | 191 } |
195 if (flash_get_cfi(bank) < 0) | 192 if (flash_detect(bank, 0) < 0) |
196 return(-1); | 193 return(-1); |
197 bi = flash_bank_info + bank; | 194 bi = flash_bank_info + bank; |
198 sprintf(targ_base, "%lx", (u_long) bi->base_addr); | 195 sprintf(targ_base, "%lx", (u_long) bi->base_addr); |
199 targv[0] = bi->ops->loadagent_setbase_cmd; | 196 targv[0] = bi->ops->loadagent_setbase_cmd; |
200 targv[1] = targ_base; | 197 targv[1] = targ_base; |
226 | 223 |
227 if (argc > 2) { | 224 if (argc > 2) { |
228 fprintf(stderr, "error: too many arguments\n"); | 225 fprintf(stderr, "error: too many arguments\n"); |
229 return(-1); | 226 return(-1); |
230 } | 227 } |
231 if (flash_get_cfi(bank) < 0) | 228 if (flash_detect(bank, 0) < 0) |
232 return(-1); | 229 return(-1); |
233 bi = flash_bank_info + bank; | 230 bi = flash_bank_info + bank; |
234 return bi->ops->reset_cmd(bi); | 231 return bi->ops->reset_cmd(bi); |
235 } | 232 } |
236 | 233 |
241 | 238 |
242 if (argc > 2) { | 239 if (argc > 2) { |
243 fprintf(stderr, "error: too many arguments\n"); | 240 fprintf(stderr, "error: too many arguments\n"); |
244 return(-1); | 241 return(-1); |
245 } | 242 } |
246 if (flash_get_cfi(bank) < 0) | 243 if (flash_detect(bank, 0) < 0) |
247 return(-1); | 244 return(-1); |
248 bi = flash_bank_info + bank; | 245 bi = flash_bank_info + bank; |
249 return bi->ops->status_cmd(bi); | 246 return bi->ops->status_cmd(bi); |
250 } | 247 } |
251 | 248 |
256 u_long offset, len; | 253 u_long offset, len; |
257 char *strtoul_endp; | 254 char *strtoul_endp; |
258 struct sector_info *startsec, *endsec, *sp; | 255 struct sector_info *startsec, *endsec, *sp; |
259 int stat; | 256 int stat; |
260 | 257 |
261 if (flash_get_cfi(bank) < 0) | 258 if (flash_detect(bank, 0) < 0) |
262 return(-1); | 259 return(-1); |
263 bi = flash_bank_info + bank; | 260 bi = flash_bank_info + bank; |
264 if (!bi->ops->needs_unlock) { | 261 if (!bi->ops->needs_unlock) { |
265 fprintf(stderr, | 262 fprintf(stderr, |
266 "This operation is not applicable to the selected flash type\n"); | 263 "This operation is not applicable to AMD-style flash\n"); |
267 return(-1); | 264 return(-1); |
268 } | 265 } |
269 if (argc != 4) { | 266 if (argc != 4) { |
270 inv: fprintf(stderr, "usage: %s %s hex-start-offset hex-length\n", | 267 inv: fprintf(stderr, "usage: %s %s hex-start-offset hex-length\n", |
271 argv[0], argv[1]); | 268 argv[0], argv[1]); |