changeset 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 1f035187e98f
children 57b8dbb029c2
files loadtools/flprogbin.c loadtools/flutil.c
diffstat 2 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/loadtools/flprogbin.c	Sun Sep 01 01:33:28 2013 +0000
+++ b/loadtools/flprogbin.c	Sun Sep 01 03:42:11 2013 +0000
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include <time.h>
 #include "flash.h"
 
 extern struct flash_bank_info flash_bank_info[2];
@@ -16,13 +17,14 @@
 	char **argv;
 {
 	struct flash_bank_info *bi;
-	u_long flashoff, fileoff, len;
+	u_long flashoff, fileoff, len, origlen, bytesdone;
 	char *strtoul_endp;
 	FILE *binf;
 	struct stat filestat;
 	char *targv[4], shortarg[10], longarg[513];
 	u_char databuf[256];
 	int reclen, cc;
+	time_t curtime, last_time;
 
 	if (argc < 4 || argc > 6) {
 inv:		fprintf(stderr,
@@ -122,7 +124,10 @@
 	targv[1] = shortarg;
 	targv[2] = longarg;
 	targv[3] = 0;
-	printf("Programming flash, each \'.\' = 256 bytes of data\n");
+	printf("Programming flash: %lu (0x%lx) bytes\n", len, len);
+	origlen = len;
+	bytesdone = 0;
+	last_time = 0;
 	while (len) {
 		if (len >= 256)
 			reclen = 256;
@@ -148,8 +153,15 @@
 		}
 		flashoff += reclen;
 		len -= reclen;
-		putchar('.');
-		fflush(stdout);
+		bytesdone += reclen;
+		cc = bytesdone * 100 / origlen;
+		time(&curtime);
+		if (curtime != last_time || cc == 100) {
+			printf("\r0x%lx bytes programmed (%i%%)",
+				bytesdone, cc);
+			fflush(stdout);
+		}
+		last_time = curtime;
 	}
 	putchar('\n');
 	fclose(binf);
--- a/loadtools/flutil.c	Sun Sep 01 01:33:28 2013 +0000
+++ b/loadtools/flutil.c	Sun Sep 01 03:42:11 2013 +0000
@@ -139,7 +139,7 @@
 	u_char *dp;
 	char *s;
 
-	for (dp = bin, s = strbuf, i =0; i < nwords; dp += 2, s += 4, i++) {
+	for (dp = bin, s = strbuf, i = 0; i < nwords; dp += 2, s += 4, i++) {
 		if (m0src) {
 			sprintf(s, "%02X", dp[0]);
 			sprintf(s + 2, "%02X", dp[1]);