FreeCalypso > hg > freecalypso-tools
comparison loadtools/flerase.c @ 669:ba9523ca6ed8
fc-loadtool code: preparations for e-program-* addition
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 08 Mar 2020 01:32:08 +0000 |
parents | cd48bc4c5460 |
children | 185c9bf208d3 |
comparison
equal
deleted
inserted
replaced
668:cd48bc4c5460 | 669:ba9523ca6ed8 |
---|---|
8 #include <string.h> | 8 #include <string.h> |
9 #include <strings.h> | 9 #include <strings.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
11 #include <time.h> | 11 #include <time.h> |
12 #include "flash.h" | 12 #include "flash.h" |
13 #include "discontig.h" | |
13 | 14 |
14 extern struct flash_bank_info flash_bank_info[2]; | 15 extern struct flash_bank_info flash_bank_info[2]; |
15 | 16 |
16 flashcmd_erase(argc, argv, bank) | 17 flashcmd_erase(argc, argv, bank) |
17 char **argv; | 18 char **argv; |
53 if (!len) { | 54 if (!len) { |
54 printf("Zero length specified - nothing to do!\n"); | 55 printf("Zero length specified - nothing to do!\n"); |
55 return(0); | 56 return(0); |
56 } | 57 } |
57 /* now enforce sector alignment for both offset and length */ | 58 /* now enforce sector alignment for both offset and length */ |
58 if (get_flash_sector_table(bank) < 0) | 59 if (get_flash_sector_table(bi) < 0) |
59 return(-1); | 60 return(-1); |
60 if (get_flash_sector_range(bi, offset, len, &startsec, &endsec) < 0) | 61 if (get_flash_sector_range(bi, offset, len, &startsec, &endsec) < 0) |
61 return(-1); | 62 return(-1); |
62 printf("Erasing %d sector(s)\n", endsec - startsec); | 63 printf("Erasing %d sector(s)\n", endsec - startsec); |
63 time(&start_time); | 64 time(&start_time); |
74 mm = duration / 60; | 75 mm = duration / 60; |
75 ss = duration - mm * 60; | 76 ss = duration - mm * 60; |
76 printf("Operation completed in %um%us\n", mm, ss); | 77 printf("Operation completed in %um%us\n", mm, ss); |
77 return(0); | 78 return(0); |
78 } | 79 } |
80 | |
81 erase_sectors_for_prog(bi, regions, nregions) | |
82 struct flash_bank_info *bi; | |
83 struct discontig_prog *regions; | |
84 unsigned nregions; | |
85 { | |
86 struct sector_info *seclist[256], **seclp, **secendp, *sp; | |
87 struct discontig_prog *regp, *regendp; | |
88 uint32_t endaddr, secendaddr; | |
89 int flag, stat; | |
90 time_t start_time, finish_time; | |
91 unsigned duration, mm, ss; | |
92 | |
93 if (get_flash_sector_table(bi) < 0) | |
94 return(-1); | |
95 seclp = seclist; | |
96 endaddr = regions[nregions-1].end; | |
97 regendp = regions + nregions; | |
98 for (sp = bi->sectors; sp->size; sp++) { | |
99 if (sp->start >= endaddr) | |
100 break; | |
101 secendaddr = sp->start + sp->size; | |
102 flag = 0; | |
103 for (regp = regions; regp < regendp; regp++) { | |
104 if (regp->start >= secendaddr) | |
105 break; | |
106 if (sp->start >= regp->end) | |
107 continue; | |
108 flag = 1; | |
109 break; | |
110 } | |
111 if (flag) | |
112 *seclp++ = sp; | |
113 } | |
114 secendp = seclp; | |
115 printf("Erasing %d sector(s)\n", secendp - seclist); | |
116 time(&start_time); | |
117 for (seclp = seclist; seclp < secendp; seclp++) { | |
118 sp = *seclp; | |
119 stat = bi->ops->erase_sector(bi, sp); | |
120 if (stat) | |
121 return(stat); | |
122 putchar('.'); | |
123 fflush(stdout); | |
124 } | |
125 time(&finish_time); | |
126 putchar('\n'); | |
127 duration = finish_time - start_time; | |
128 mm = duration / 60; | |
129 ss = duration - mm * 60; | |
130 printf("Operation completed in %um%us\n", mm, ss); | |
131 return(0); | |
132 } |