comparison loadtools/romload.c @ 10:e2e80a09338e

fc-sertool actually works; output from loadagent is visible!
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 01 May 2013 03:41:42 +0000
parents fea204bc7674
children 24b88c119465
comparison
equal deleted inserted replaced
9:fea204bc7674 10:e2e80a09338e
118 int i, llen; 118 int i, llen;
119 119
120 sum = iramimage.datalen + 5; 120 sum = iramimage.datalen + 5;
121 llen = iramimage.datalen + 4; 121 llen = iramimage.datalen + 4;
122 for (i = 0; i < llen; i++) 122 for (i = 0; i < llen; i++)
123 sum = iramimage.record[i+1]; 123 sum += iramimage.record[i+1];
124 return sum; 124 return sum;
125 } 125 }
126 126
127 perform_romload() 127 perform_romload()
128 { 128 {
158 switch_baud_rate(B115200); 158 switch_baud_rate(B115200);
159 usleep(SERIAL_FLUSH_DELAY * 1000); 159 usleep(SERIAL_FLUSH_DELAY * 1000);
160 tcflush(target_fd, TCIFLUSH); 160 tcflush(target_fd, TCIFLUSH);
161 161
162 image_cksum = 0; 162 image_cksum = 0;
163 for (rec_count = 0; ; rec_count++) { 163 for (rec_count = 0; ; ) {
164 if (read_s_record(&iramimage) < 0) 164 if (read_s_record(&iramimage) < 0)
165 exit(1); 165 exit(1);
166 switch (iramimage.record_type) { 166 switch (iramimage.record_type) {
167 case '0': 167 case '0':
168 if (iramimage.lineno == 1) 168 if (iramimage.lineno == 1)
198 write_cmd[5] = iramimage.datalen; 198 write_cmd[5] = iramimage.datalen;
199 bcopy(iramimage.record + 1, write_cmd + 6, 4); 199 bcopy(iramimage.record + 1, write_cmd + 6, 4);
200 write(target_fd, write_cmd, sizeof write_cmd); 200 write(target_fd, write_cmd, sizeof write_cmd);
201 write(target_fd, iramimage.record + 5, iramimage.datalen); 201 write(target_fd, iramimage.record + 5, iramimage.datalen);
202 /* update our checksum accumulator */ 202 /* update our checksum accumulator */
203 image_cksum += ~(compute_block_cksum() & 0xFF); 203 image_cksum += ~compute_block_cksum() & 0xFF;
204 /* collect response */ 204 /* collect response */
205 resp = expect_response(INTERMEDIATE_TIMEOUT); 205 resp = expect_response(INTERMEDIATE_TIMEOUT);
206 if (resp != 'w') { 206 if (resp != 'w') {
207 fprintf(stderr, "Block #%lu: ", rec_count); 207 fprintf(stderr, "Block #%lu: ", rec_count);
208 if (resp < 0) 208 if (resp < 0)
215 fprintf(stderr, 215 fprintf(stderr,
216 "Got > %02X in response to <w command; expected >w\n", 216 "Got > %02X in response to <w command; expected >w\n",
217 resp); 217 resp);
218 exit(1); 218 exit(1);
219 } 219 }
220 /* on to the next record! */ 220 putchar('.');
221 fflush(stdout);
222 rec_count++;
221 } 223 }
222 /* got S7 */ 224 /* got S7 */
223 fclose(iramimage.openfile); 225 fclose(iramimage.openfile);
224 if (!rec_count) { 226 if (!rec_count) {
225 fprintf(stderr, 227 fprintf(stderr,
228 exit(1); 230 exit(1);
229 } 231 }
230 232
231 /* send <c */ 233 /* send <c */
232 printf("Sending checksum\n"); 234 printf("Sending checksum\n");
233 cksum_cmd[2] = ~(image_cksum & 0xFF); 235 cksum_cmd[2] = ~image_cksum & 0xFF;
234 write(target_fd, cksum_cmd, sizeof cksum_cmd); 236 write(target_fd, cksum_cmd, sizeof cksum_cmd);
235 resp = expect_response(INTERMEDIATE_TIMEOUT); 237 resp = expect_response(INTERMEDIATE_TIMEOUT);
236 if (resp != 'c') { 238 if (resp != 'c') {
237 if (resp < 0) 239 if (resp < 0)
238 fprintf(stderr, "No response to <c command\n"); 240 fprintf(stderr, "No response to <c command\n");