comparison loadtools/romload.c @ 633:4dca8542f569

loadtools/romload.c: collect additional response bytes after >p and >c
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 01 Mar 2020 00:57:12 +0000
parents aba969153d20
children 3172e3111ab7
comparison
equal deleted inserted replaced
632:ae4330d86029 633:4dca8542f569
148 write(target_fd, beacon_cmd, sizeof beacon_cmd); 148 write(target_fd, beacon_cmd, sizeof beacon_cmd);
149 while (expect_response(beacon_interval) != 'i'); 149 while (expect_response(beacon_interval) != 'i');
150 return 0; 150 return 0;
151 } 151 }
152 152
153 static int
154 expect_add_response(buf, expect_bytes, timeout)
155 u_char *buf;
156 {
157 fd_set fds;
158 struct timeval tv;
159 int pass, cc;
160
161 for (pass = 0; pass < expect_bytes; ) {
162 FD_ZERO(&fds);
163 FD_SET(target_fd, &fds);
164 tv.tv_sec = 0;
165 tv.tv_usec = timeout * 1000;
166 cc = select(target_fd+1, &fds, NULL, NULL, &tv);
167 if (cc < 0) {
168 if (errno == EINTR)
169 continue;
170 perror("select");
171 exit(1);
172 }
173 if (cc < 1)
174 return(-1);
175 cc = read(target_fd, buf + pass, expect_bytes - pass);
176 if (cc <= 0) {
177 perror("read after successful select");
178 exit(1);
179 }
180 pass += cc;
181 }
182 return(0);
183 }
184
153 static uint32_t 185 static uint32_t
154 compute_block_cksum() 186 compute_block_cksum()
155 { 187 {
156 uint32_t sum; 188 uint32_t sum;
157 int i, llen; 189 int i, llen;
166 perform_romload() 198 perform_romload()
167 { 199 {
168 int resp; 200 int resp;
169 uint16_t image_cksum; 201 uint16_t image_cksum;
170 unsigned long rec_count; 202 unsigned long rec_count;
203 u_char addresp[2];
171 static int zero = 0; 204 static int zero = 0;
172 205
173 if (open_srec_file(&iramimage) < 0) 206 if (open_srec_file(&iramimage) < 0)
174 exit(1); 207 exit(1);
175 set_fixed_baudrate("19200"); 208 set_fixed_baudrate("19200");
191 resp); 224 resp);
192 else 225 else
193 fprintf(stderr, 226 fprintf(stderr,
194 "Got > %02X in response to <p command; expected >p\n", 227 "Got > %02X in response to <p command; expected >p\n",
195 resp); 228 resp);
229 exit(1);
230 }
231 resp = expect_add_response(addresp, 2, INTERMEDIATE_TIMEOUT);
232 if (resp < 0 || addresp[0] != 0x00 || addresp[1] != 0x04) {
233 fprintf(stderr,
234 "error: extra bytes after >p not received as expected\n");
196 exit(1); 235 exit(1);
197 } 236 }
198 printf("<p command successful, switching to %s baud\n", 237 printf("<p command successful, switching to %s baud\n",
199 romload_baud_rate->name); 238 romload_baud_rate->name);
200 set_serial_baudrate(romload_baud_rate); 239 set_serial_baudrate(romload_baud_rate);
288 fprintf(stderr, 327 fprintf(stderr,
289 "Got > %02X in response to <c command; expected >c\n", 328 "Got > %02X in response to <c command; expected >c\n",
290 resp); 329 resp);
291 exit(1); 330 exit(1);
292 } 331 }
332 resp = expect_add_response(addresp, 1, INTERMEDIATE_TIMEOUT);
333 if (resp < 0) {
334 fprintf(stderr,
335 "error: extra byte after >c not received as expected\n");
336 exit(1);
337 }
293 printf("<c command successful, sending <b\n"); 338 printf("<c command successful, sending <b\n");
294 339
295 bcopy(iramimage.record + 1, branch_cmd + 2, 4); 340 bcopy(iramimage.record + 1, branch_cmd + 2, 4);
296 write(target_fd, branch_cmd, sizeof branch_cmd); 341 write(target_fd, branch_cmd, sizeof branch_cmd);
297 resp = expect_response(INTERMEDIATE_TIMEOUT); 342 resp = expect_response(INTERMEDIATE_TIMEOUT);