comparison loadtools/ltdump.c @ 94:1f035187e98f

fc-loadtool dump2{bin,srec}: smarter progress indication
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 01 Sep 2013 01:33:28 +0000
parents 65111e6eee9e
children b3ed63722eb5
comparison
equal deleted inserted replaced
93:45911ad957fd 94:1f035187e98f
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string.h> 9 #include <string.h>
10 #include <strings.h> 10 #include <strings.h>
11 #include <stdlib.h> 11 #include <stdlib.h>
12 #include <time.h>
12 13
13 extern uint32_t crc32_table[]; 14 extern uint32_t crc32_table[];
14 extern char target_response_line[]; 15 extern char target_response_line[];
15 16
16 crc32_on_target(area_base, area_len, retptr) 17 crc32_on_target(area_base, area_len, retptr)
67 /* the actual dump facility */ 68 /* the actual dump facility */
68 69
69 static FILE *dump_outfile; 70 static FILE *dump_outfile;
70 static int dump_save_srec; 71 static int dump_save_srec;
71 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;
72 static u_char dump_binrec[0x86]; 74 static u_char dump_binrec[0x86];
75 static time_t dump_last_time;
73 76
74 static 77 static
75 dump_receiver(line) 78 dump_receiver(line)
76 char *line; 79 char *line;
77 { 80 {
78 int i, b; 81 int i, b;
79 u_char sr_cksum; 82 u_char sr_cksum;
80 uint32_t addr_from_srec; 83 uint32_t addr_from_srec;
84 time_t curtime;
81 85
82 if (strncmp(line, "S385", 4)) { 86 if (strncmp(line, "S385", 4)) {
83 fprintf(stderr, 87 fprintf(stderr,
84 "error: target response is not the expected S385...\n"); 88 "error: target response is not the expected S385...\n");
85 return(-1); 89 return(-1);
119 for (i = 0; i < 0x80; i++) 123 for (i = 0; i < 0x80; i++)
120 dump_crcaccum = crc32_table[dump_crcaccum & 0xFF ^ 124 dump_crcaccum = crc32_table[dump_crcaccum & 0xFF ^
121 dump_binrec[i+5]] ^ 125 dump_binrec[i+5]] ^
122 (dump_crcaccum >> 8); 126 (dump_crcaccum >> 8);
123 /* progress indication */ 127 /* progress indication */
124 putchar('.'); 128 dump_progress_len += 0x80;
125 fflush(stdout); 129 i = dump_progress_len * 100 / dump_total_len;
130 time(&curtime);
131 if (curtime != dump_last_time || i == 100) {
132 printf("\rRx %lu out of %lu bytes (%i%%)",
133 (u_long) dump_progress_len, (u_long) dump_total_len, i);
134 fflush(stdout);
135 }
126 dump_nextaddr += 0x80; 136 dump_nextaddr += 0x80;
137 dump_last_time = curtime;
127 return(1); 138 return(1);
128 } 139 }
129 140
130 loadtool_memdump(start_addr, area_len, filename, fmt_srec) 141 loadtool_memdump(start_addr, area_len, filename, fmt_srec)
131 u_long start_addr, area_len; 142 u_long start_addr, area_len;
151 return(-1); 162 return(-1);
152 } 163 }
153 dump_save_srec = fmt_srec; 164 dump_save_srec = fmt_srec;
154 dump_nextaddr = start_addr; 165 dump_nextaddr = start_addr;
155 dump_crcaccum = 0xFFFFFFFF; 166 dump_crcaccum = 0xFFFFFFFF;
167 dump_total_len = area_len;
168 dump_progress_len = 0;
156 169
157 printf("Requesting memory dump...\n"); 170 printf("Requesting memory dump...\n");
158 sprintf(target_arg1, "%lx", start_addr); 171 sprintf(target_arg1, "%lx", start_addr);
159 sprintf(target_arg2, "%lx", area_len); 172 sprintf(target_arg2, "%lx", area_len);
160 target_argv[0] = "DUMP"; 173 target_argv[0] = "DUMP";