comparison loadtools/flashops.c @ 407:f2cc551e597f

fc-loadtool flash: beginning of Intel command set support
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 17 Jun 2014 01:39:59 +0000
parents a212b4968b29
children 431023033c86
comparison
equal deleted inserted replaced
406:0b8e5072abde 407:f2cc551e597f
91 .erase_sector = amd_sector_erase, 91 .erase_sector = amd_sector_erase,
92 .prep_for_program = noop, 92 .prep_for_program = noop,
93 .loadagent_setbase_cmd = "AMFB", 93 .loadagent_setbase_cmd = "AMFB",
94 .loadagent_program_cmd = "AMFW", 94 .loadagent_program_cmd = "AMFW",
95 }; 95 };
96
97 /* Intel flash functions */
98
99 intel_reset_cmd(bi)
100 struct flash_bank_info *bi;
101 {
102 if (do_w16(bi->base_addr, 0xFF)) {
103 fprintf(stderr,
104 "unexpected response to w16 when resetting flash to read mode!\n");
105 return(-1);
106 }
107 return(0);
108 }
109
110 intel_sector_unlock(bi, sp)
111 struct flash_bank_info *bi;
112 struct sector_info *sp;
113 {
114 int stat;
115
116 stat = do_w16(bi->base_addr + sp->start, 0x60);
117 if (stat) {
118 bad_w16: fprintf(stderr,
119 "unexpected response to w16 in block unlock cmd sequence - aborting\n");
120 return(-1);
121 }
122 stat = do_w16(bi->base_addr + sp->start, 0xD0);
123 if (stat)
124 goto bad_w16;
125 return(0);
126 }
127
128 intel_sector_erase(bi, sp)
129 struct flash_bank_info *bi;
130 struct sector_info *sp;
131 {
132 int stat;
133 uint16_t flstat;
134 time_t start_time, curtime;
135
136 stat = intel_sector_unlock(bi, sp);
137 if (stat)
138 return(stat); /* error msg already printed */
139 /* clear SR */
140 stat = do_w16(bi->base_addr + sp->start, 0x50);
141 if (stat) {
142 bad_w16: fprintf(stderr,
143 "unexpected response to w16 in erase cmd sequence - aborting\n");
144 return(-1);
145 }
146 /* send the actual block erase command */
147 stat = do_w16(bi->base_addr + sp->start, 0x20);
148 if (stat)
149 goto bad_w16;
150 stat = do_w16(bi->base_addr + sp->start, 0xD0);
151 if (stat)
152 goto bad_w16;
153 /* wait for completion */
154 start_time = time(0);
155 for (;;) {
156 stat = do_r16(bi->base_addr + sp->start, &flstat);
157 if (stat)
158 return(stat); /* error msg already printed */
159 if (flstat & 0x80)
160 break;
161 curtime = time(0);
162 if (curtime >= start_time + 20) {
163 fprintf(stderr, "erase timeout, aborting\n");
164 return(-1);
165 }
166 }
167 if (flstat & 0x20) {
168 fprintf(stderr, "block erase failed!\n");
169 return(-1);
170 } else
171 return(0);
172 }
173
174 struct flash_cmdset flash_cmdset_intel = {
175 .cmdset_name = "Intel",
176 .reset_cmd = intel_reset_cmd,
177 .status_cmd = invalid,
178 .unlock_sector = intel_sector_unlock,
179 .erase_sector = intel_sector_erase,
180 .loadagent_setbase_cmd = "INFB",
181 .loadagent_program_cmd = "INFW",
182 };