FreeCalypso > hg > freecalypso-sw
annotate loadtools/flerase.c @ 301:8dd522a8d60e
fc-fsio: set-imeisv and set-pcm-string added from fc-tmsh
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 02 Mar 2014 02:04:51 +0000 |
parents | cd12d1049f91 |
children | f027c6fbe37e |
rev | line source |
---|---|
62
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This module implements the flash erase operation |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdint.h> |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <stdlib.h> |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <time.h> |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include "flash.h" |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 extern struct flash_bank_info flash_bank_info[2]; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 do_sector_erase(bi, sp) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 struct flash_bank_info *bi; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 struct sector_info *sp; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 int stat; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 uint16_t flstat; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 time_t start_time, curtime; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 stat = do_w16(bi->base_addr + sp->start + 0xAAA, 0xAA); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 if (stat) { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 bad_w16: fprintf(stderr, |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 "unexpected response to w16 in erase cmd sequence - aborting\n"); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 return(-1); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 stat = do_w16(bi->base_addr + sp->start + 0x554, 0x55); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 if (stat) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 goto bad_w16; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 stat = do_w16(bi->base_addr + sp->start + 0xAAA, 0x80); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 if (stat) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 goto bad_w16; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 stat = do_w16(bi->base_addr + sp->start + 0xAAA, 0xAA); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 if (stat) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 goto bad_w16; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 stat = do_w16(bi->base_addr + sp->start + 0x554, 0x55); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 if (stat) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 goto bad_w16; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 stat = do_w16(bi->base_addr + sp->start + 0xAAA, 0x30); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 if (stat) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 goto bad_w16; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 start_time = time(0); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 for (;;) { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 stat = do_r16(bi->base_addr + sp->start, &flstat); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 if (stat) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 return(stat); /* error msg already printed */ |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 if (flstat == 0xFFFF) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 return(0); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 curtime = time(0); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 if (curtime >= start_time + 20) { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 fprintf(stderr, "erase timeout, aborting\n"); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 return(-1); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 flashcmd_erase(argc, argv, bank) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 char **argv; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 struct flash_bank_info *bi; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 u_long offset, len; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 char *strtoul_endp; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 struct sector_info *startsec, *endsec, *sp; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 int stat; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 if (argc != 4) { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 inv: fprintf(stderr, "usage: %s %s hex-start-offset hex-length\n", |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 argv[0], argv[1]); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 return(-1); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 offset = strtoul(argv[2], &strtoul_endp, 16); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 if (*strtoul_endp) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 goto inv; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 bi = flash_bank_info + bank; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 if (offset >= bi->total_size) { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 fprintf(stderr, |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 "error: specified offset exceeds flash bank size (0x%lx)\n", |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 (u_long) bi->total_size); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 return(-1); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 len = strtoul(argv[3], &strtoul_endp, 16); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 if (*strtoul_endp) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 goto inv; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 if (len > bi->total_size - offset) { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 fprintf(stderr, |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 "error: specified offset+length exceed flash bank size (0x%lx)\n", |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 (u_long) bi->total_size); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 return(-1); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 if (!len) { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 printf("Zero length specified - nothing to do!\n"); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 return(0); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 /* now enforce sector alignment for both offset and length */ |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 if (get_flash_sector_table(bank) < 0) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 return(-1); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 if (get_flash_sector_range(bi, offset, len, &startsec, &endsec) < 0) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 return(-1); |
205
cd12d1049f91
fc-loadtool: flash ID check moved into flash info, added to erase and program
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
100 stat = flash_id_check(bank, 0); |
cd12d1049f91
fc-loadtool: flash ID check moved into flash info, added to erase and program
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
101 if (stat) |
cd12d1049f91
fc-loadtool: flash ID check moved into flash info, added to erase and program
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
62
diff
changeset
|
102 return(stat); |
62
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 printf("Erasing %d sector(s)\n", endsec - startsec); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 for (sp = startsec; sp < endsec; sp++) { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 stat = do_sector_erase(bi, sp); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
106 if (stat) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
107 return(stat); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
108 putchar('.'); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
109 fflush(stdout); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
110 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
111 putchar('\n'); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
112 return(0); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
113 } |