comparison loadtools/ltdump.c @ 98:b3ed63722eb5

fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 01 Sep 2013 17:20:58 +0000
parents 1f035187e98f
children
comparison
equal deleted inserted replaced
97:a2e793f6b8c4 98:b3ed63722eb5
72 static uint32_t dump_nextaddr, dump_crcaccum; 72 static uint32_t dump_nextaddr, dump_crcaccum;
73 static uint32_t dump_total_len, dump_progress_len; 73 static uint32_t dump_total_len, dump_progress_len;
74 static u_char dump_binrec[0x86]; 74 static u_char dump_binrec[0x86];
75 static time_t dump_last_time; 75 static time_t dump_last_time;
76 76
77 static char dumpsrec_s0_line[] = "S007000044554D50C2\n";
78 static char dumpsrec_s7_line[] = "S70500000000FA\n";
79
77 static 80 static
78 dump_receiver(line) 81 dump_receiver(line)
79 char *line; 82 char *line;
80 { 83 {
81 int i, b; 84 int i, b;
113 fprintf(stderr, 116 fprintf(stderr,
114 "error: S3 record from target has the wrong address\n"); 117 "error: S3 record from target has the wrong address\n");
115 return(-1); 118 return(-1);
116 } 119 }
117 /* all checks passed - save it */ 120 /* all checks passed - save it */
118 if (dump_save_srec) 121 if (dump_save_srec) {
122 if (!dump_progress_len)
123 fputs(dumpsrec_s0_line, dump_outfile);
119 fprintf(dump_outfile, "%s\n", line); 124 fprintf(dump_outfile, "%s\n", line);
120 else 125 } else
121 fwrite(dump_binrec + 5, 1, 0x80, dump_outfile); 126 fwrite(dump_binrec + 5, 1, 0x80, dump_outfile);
122 /* update running CRC */ 127 /* update running CRC */
123 for (i = 0; i < 0x80; i++) 128 for (i = 0; i < 0x80; i++)
124 dump_crcaccum = crc32_table[dump_crcaccum & 0xFF ^ 129 dump_crcaccum = crc32_table[dump_crcaccum & 0xFF ^
125 dump_binrec[i+5]] ^ 130 dump_binrec[i+5]] ^
179 if (stat < 0) { 184 if (stat < 0) {
180 fclose(dump_outfile); 185 fclose(dump_outfile);
181 return(stat); 186 return(stat);
182 } 187 }
183 stat = tpinterf_capture_output(2, dump_receiver); 188 stat = tpinterf_capture_output(2, dump_receiver);
184 fclose(dump_outfile); 189 if (stat < 0) {
185 if (stat < 0) 190 fclose(dump_outfile);
186 return(stat); 191 return(stat);
187 putchar('\n'); /* after lots of dots */ 192 }
193 putchar('\n'); /* after last progress line */
188 194
189 /* sanity checks */ 195 /* sanity checks */
190 if (dump_nextaddr != start_addr + area_len) { 196 if (dump_nextaddr != start_addr + area_len) {
197 fclose(dump_outfile);
191 fprintf(stderr, 198 fprintf(stderr,
192 "error: received dump length does not match expected\n"); 199 "error: received dump length does not match expected\n");
193 return(-1); 200 return(-1);
194 } 201 }
195 if (dump_crcaccum != (uint32_t) target_crc_init) { 202 if (dump_crcaccum != (uint32_t) target_crc_init) {
203 fclose(dump_outfile);
196 fprintf(stderr, "error: CRC mismatch (computed %lX)\n", 204 fprintf(stderr, "error: CRC mismatch (computed %lX)\n",
197 (u_long) dump_crcaccum); 205 (u_long) dump_crcaccum);
198 return(-1); 206 return(-1);
199 } 207 }
208 if (fmt_srec)
209 fputs(dumpsrec_s7_line, dump_outfile);
210 fclose(dump_outfile);
200 printf("Requesting another CRC-32 of the area from target...\n"); 211 printf("Requesting another CRC-32 of the area from target...\n");
201 stat = crc32_on_target(start_addr, area_len, &target_crc_fin); 212 stat = crc32_on_target(start_addr, area_len, &target_crc_fin);
202 if (stat) 213 if (stat)
203 return(stat); 214 return(stat);
204 if (target_crc_fin == target_crc_init) { 215 if (target_crc_fin == target_crc_init) {