comparison loadtools/flmisc.c @ 409:23ab8fe81764

Intel flash: unlock command implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 17 Jun 2014 03:18:02 +0000
parents 431023033c86
children 81d387690063
comparison
equal deleted inserted replaced
408:431023033c86 409:23ab8fe81764
246 if (flash_get_cfi(bank) < 0) 246 if (flash_get_cfi(bank) < 0)
247 return(-1); 247 return(-1);
248 bi = flash_bank_info + bank; 248 bi = flash_bank_info + bank;
249 return bi->ops->status_cmd(bi); 249 return bi->ops->status_cmd(bi);
250 } 250 }
251
252 flashcmd_unlock(argc, argv, bank)
253 char **argv;
254 {
255 struct flash_bank_info *bi;
256 u_long offset, len;
257 char *strtoul_endp;
258 struct sector_info *startsec, *endsec, *sp;
259 int stat;
260
261 if (flash_get_cfi(bank) < 0)
262 return(-1);
263 bi = flash_bank_info + bank;
264 if (!bi->ops->needs_unlock) {
265 fprintf(stderr,
266 "This operation is not applicable to the selected flash type\n");
267 return(-1);
268 }
269 if (argc != 4) {
270 inv: fprintf(stderr, "usage: %s %s hex-start-offset hex-length\n",
271 argv[0], argv[1]);
272 return(-1);
273 }
274 offset = strtoul(argv[2], &strtoul_endp, 16);
275 if (*strtoul_endp)
276 goto inv;
277 if (offset >= bi->geom->total_size) {
278 fprintf(stderr,
279 "error: specified offset exceeds flash bank size (0x%lx)\n",
280 (u_long) bi->geom->total_size);
281 return(-1);
282 }
283 len = strtoul(argv[3], &strtoul_endp, 16);
284 if (*strtoul_endp)
285 goto inv;
286 if (len > bi->geom->total_size - offset) {
287 fprintf(stderr,
288 "error: specified offset+length exceed flash bank size (0x%lx)\n",
289 (u_long) bi->geom->total_size);
290 return(-1);
291 }
292 if (!len) {
293 printf("Zero length specified - nothing to do!\n");
294 return(0);
295 }
296 /* now enforce sector alignment for both offset and length */
297 if (get_flash_sector_table(bank) < 0)
298 return(-1);
299 if (get_flash_sector_range(bi, offset, len, &startsec, &endsec) < 0)
300 return(-1);
301 printf("Unlocking %d sector(s)\n", endsec - startsec);
302 for (sp = startsec; sp < endsec; sp++) {
303 stat = bi->ops->unlock_sector(bi, sp);
304 if (stat)
305 return(stat);
306 putchar('.');
307 fflush(stdout);
308 }
309 putchar('\n');
310 return(0);
311 }