comparison loadtools/flprogbin.c @ 95:336f5cc96810

fc-loadtool flash program-bin: smarter progress indication
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 01 Sep 2013 03:42:11 +0000
parents 98f855e58c9f
children cd12d1049f91
comparison
equal deleted inserted replaced
94:1f035187e98f 95:336f5cc96810
6 #include <sys/types.h> 6 #include <sys/types.h>
7 #include <sys/stat.h> 7 #include <sys/stat.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <stdlib.h> 10 #include <stdlib.h>
11 #include <time.h>
11 #include "flash.h" 12 #include "flash.h"
12 13
13 extern struct flash_bank_info flash_bank_info[2]; 14 extern struct flash_bank_info flash_bank_info[2];
14 15
15 flashcmd_progbin(argc, argv, bank) 16 flashcmd_progbin(argc, argv, bank)
16 char **argv; 17 char **argv;
17 { 18 {
18 struct flash_bank_info *bi; 19 struct flash_bank_info *bi;
19 u_long flashoff, fileoff, len; 20 u_long flashoff, fileoff, len, origlen, bytesdone;
20 char *strtoul_endp; 21 char *strtoul_endp;
21 FILE *binf; 22 FILE *binf;
22 struct stat filestat; 23 struct stat filestat;
23 char *targv[4], shortarg[10], longarg[513]; 24 char *targv[4], shortarg[10], longarg[513];
24 u_char databuf[256]; 25 u_char databuf[256];
25 int reclen, cc; 26 int reclen, cc;
27 time_t curtime, last_time;
26 28
27 if (argc < 4 || argc > 6) { 29 if (argc < 4 || argc > 6) {
28 inv: fprintf(stderr, 30 inv: fprintf(stderr,
29 "usage: %s %s flash-offset binfile [file-offset [length]]\n", 31 "usage: %s %s flash-offset binfile [file-offset [length]]\n",
30 argv[0], argv[1]); 32 argv[0], argv[1]);
120 fseek(binf, fileoff, SEEK_SET); 122 fseek(binf, fileoff, SEEK_SET);
121 targv[0] = "AMFW"; 123 targv[0] = "AMFW";
122 targv[1] = shortarg; 124 targv[1] = shortarg;
123 targv[2] = longarg; 125 targv[2] = longarg;
124 targv[3] = 0; 126 targv[3] = 0;
125 printf("Programming flash, each \'.\' = 256 bytes of data\n"); 127 printf("Programming flash: %lu (0x%lx) bytes\n", len, len);
128 origlen = len;
129 bytesdone = 0;
130 last_time = 0;
126 while (len) { 131 while (len) {
127 if (len >= 256) 132 if (len >= 256)
128 reclen = 256; 133 reclen = 256;
129 else 134 else
130 reclen = len; 135 reclen = len;
146 fclose(binf); 151 fclose(binf);
147 return(cc); 152 return(cc);
148 } 153 }
149 flashoff += reclen; 154 flashoff += reclen;
150 len -= reclen; 155 len -= reclen;
151 putchar('.'); 156 bytesdone += reclen;
152 fflush(stdout); 157 cc = bytesdone * 100 / origlen;
158 time(&curtime);
159 if (curtime != last_time || cc == 100) {
160 printf("\r0x%lx bytes programmed (%i%%)",
161 bytesdone, cc);
162 fflush(stdout);
163 }
164 last_time = curtime;
153 } 165 }
154 putchar('\n'); 166 putchar('\n');
155 fclose(binf); 167 fclose(binf);
156 return(0); 168 return(0);
157 } 169 }