From 6d69da6cd120fac092c92717bf37e7dcc3972b6b Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Sat, 22 Sep 2012 23:02:35 +0200 Subject: nolo: Show progressbar and wait when flashing cmt --- src/nolo.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) 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; -- cgit v1.2.3