summaryrefslogtreecommitdiffstats
path: root/src/nolo.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2012-09-22 23:02:35 +0200
committerPali Rohár <pali.rohar@gmail.com>2012-09-22 23:02:35 +0200
commit6d69da6cd120fac092c92717bf37e7dcc3972b6b (patch)
tree3eb968569d29b3d5a959cfda70b57234ca14ed06 /src/nolo.c
parent3666e285dced0eff35757e3e82b3f78bd28503d2 (diff)
download0xFFFF-6d69da6cd120fac092c92717bf37e7dcc3972b6b.tar.bz2
nolo: Show progressbar and wait when flashing cmt
Diffstat (limited to 'src/nolo.c')
-rw-r--r--src/nolo.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/src/nolo.c b/src/nolo.c
index f6d7f97..713ae6e 100644
--- a/src/nolo.c
+++ b/src/nolo.c
@@ -348,6 +348,11 @@ int nolo_flash_image(struct usb_device_info * dev, struct image * image) {
int ret;
int flash;
int index;
+ unsigned long long int part;
+ unsigned long long int total;
+ unsigned long long int last_total;
+ char status[20];
+ char buf[128];
if ( image->type == IMAGE_ROOTFS )
flash = 1;
@@ -381,7 +386,67 @@ int nolo_flash_image(struct usb_device_info * dev, struct image * image) {
}
if ( image->type == IMAGE_CMT_MCUSW ) {
- /* TODO: show CMT progressbar and wait */
+
+ int state = 0;
+ last_total = 0;
+
+ printf("Erasing CMT...\n");
+
+ while ( state != 4 ) {
+
+ if ( nolo_get_string(dev, "cmt:status", buf, sizeof(buf)) < 0 )
+ ERROR_RETURN("cmt:status failed", -1);
+
+ if ( strncmp(buf, "finished", strlen("finished")) == 0 ) {
+
+ if ( state <= 0 ) {
+ printf_progressbar(last_total, last_total);
+ printf("Done\n");
+ }
+ if ( state <= 1 )
+ printf("Programming CMT...\n");
+ if ( state <= 2 ) {
+ printf_progressbar(last_total, last_total);
+ printf("Done\n");
+ }
+
+ state = 4;
+
+ } else {
+
+ if ( sscanf(buf, "%s:%llu/%llu", status, &part, &total) != 3 )
+ ERROR_RETURN("cmt:status unknown", -1);
+
+ if ( strcmp(status, "program") == 0 && state <= 0 ) {
+ printf_progressbar(last_total, last_total);
+ printf("Done\n");
+ state = 1;
+ }
+
+ if ( strcmp(status, "program") == 0 && state <= 1 ) {
+ printf("Programming CMT...\n");
+ state = 2;
+ }
+
+ printf_progressbar(part, total);
+ last_total = total;
+
+ if ( strcmp(status, "erase") == 0 && state <= 0 && part == total ) {
+ printf("Done\n");
+ state = 1;
+ }
+
+ if ( strcmp(status, "program") == 0 && state <= 2 && part == total ) {
+ printf("Done\n");
+ state = 3;
+ }
+
+ }
+
+ usleep(0xc350); // 0.5s
+
+ }
+
}
return 0;