comparison loadtools/flutil.c @ 204:61c7480b3c50

fc-loadtool: flash idcheck standalone command implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 23 Dec 2013 08:49:38 +0000
parents 96f56e875862
children cd12d1049f91
comparison
equal deleted inserted replaced
203:99c234bf6a9b 204:61c7480b3c50
145 else 145 else
146 sprintf(s, "%02X%02X", dp[1], dp[0]); 146 sprintf(s, "%02X%02X", dp[1], dp[0]);
147 } 147 }
148 *s = '\0'; 148 *s = '\0';
149 } 149 }
150
151 flash_id_check(bank, repeat)
152 {
153 struct flash_bank_info *bi;
154 struct flash_bank_desc *bd;
155 struct flash_idcheck *id;
156 int stat, fail;
157 uint16_t rdval;
158 unsigned cnt;
159
160 bi = flash_bank_info + bank;
161 if (bi->idcheck_done && !repeat)
162 return(0);
163 printf("Performing flash ID check\n");
164 stat = do_w16(bi->base_addr + 0xAAA, 0xAA);
165 if (stat) {
166 bad_w16: fprintf(stderr,
167 "unexpected response to w16 in read ID cmd sequence - aborting\n");
168 return(-1);
169 }
170 stat = do_w16(bi->base_addr + 0x554, 0x55);
171 if (stat)
172 goto bad_w16;
173 stat = do_w16(bi->base_addr + 0xAAA, 0x90);
174 if (stat)
175 goto bad_w16;
176 bd = bi->bank_desc;
177 id = bd->idcheck_table;
178 fail = 0;
179 for (cnt = 0; cnt < bd->idcheck_num; cnt++) {
180 stat = do_r16(bi->base_addr + id->offset, &rdval);
181 if (stat)
182 return(stat); /* error msg already printed */
183 printf("offset %02X: %04X -- ", (int)id->offset, (int)rdval);
184 if (rdval == id->expect_val)
185 printf("PASS\n");
186 else {
187 printf("FAIL: expected %04X\n", (int)id->expect_val);
188 fail = 1;
189 break;
190 }
191 id++;
192 }
193 /* reset flash to read mode */
194 stat = do_w16(bi->base_addr + 0xAAA, 0xF0);
195 if (stat) {
196 fprintf(stderr,
197 "unexpected response to w16 when resetting flash to read mode!\n");
198 return(-1);
199 }
200 if (fail)
201 return(-1);
202 bi->idcheck_done = 1;
203 return(0);
204 }
205
206 flashcmd_idcheck(argc, argv, bank)
207 char **argv;
208 {
209 struct flash_bank_info *bi;
210
211 if (argc > 2) {
212 fprintf(stderr, "error: too many arguments\n");
213 return(-1);
214 }
215 return flash_id_check(bank, 1);
216 }