[tuxdroid-svn] r1207 - firmware/tuxup/trunk
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2008-05-30 14:04:33
|
Author: Paul_R Date: 2008-05-30 16:04:36 +0200 (Fri, 30 May 2008) New Revision: 1207 Modified: firmware/tuxup/trunk/bootloader.c firmware/tuxup/trunk/main.c Log: * Changed the way to control the bootloading process with a counter. The counter is incremented in fuxusb and tuxup to keep the synchro. With HID, the driver is non-blockant. When we read the statuses, the driver return the content of a buffer, and don't request a read on the bus. That's the reason why a synchro is needed. * Added a 'true' progress bar. Modified: firmware/tuxup/trunk/bootloader.c =================================================================== --- firmware/tuxup/trunk/bootloader.c 2008-05-30 13:37:01 UTC (rev 1206) +++ firmware/tuxup/trunk/bootloader.c 2008-05-30 14:04:36 UTC (rev 1207) @@ -40,6 +40,9 @@ extern int verbose; bool HID; +static float line_nb; +static float step; +static float progress = 0; /* Debug commands */ //#define keybreak() {puts("Press return to read feedback"); getchar();} @@ -51,8 +54,8 @@ #define FALSE 0 #define USB_TIMEOUT 5 -#define BOOT_INIT_ACK 10 -#define BOOT_EXIT_ACK 2 +#define BOOT_INIT_ACK 255 +#define BOOT_EXIT_ACK 254 /* USB bootloader commands */ #define BOOT_INIT 1 @@ -60,6 +63,7 @@ #define BOOT_EXIT 3 static bool wait_status(uint8_t value, int timeout); +static void compute_progress_bar(float line_nb); typedef uint32_t FILE_Addr_t; typedef uint32_t FILE_SegmentLen_t; @@ -359,13 +363,13 @@ */ if (HID) { - ret = (wait_status(counter, USB_TIMEOUT)); + ret = (wait_status(++counter, USB_TIMEOUT)); tux_hid_read(5, data_buffer); - counter ++; } else { ret = usb_get_commands(parser->dev_handle, data_buffer, 5); + counter ++; } #if (PRINT_DATA) printf("Status of feedback from bootloader: %x\n", ret); @@ -374,14 +378,18 @@ { if ((ret) && (data_buffer[0] == 0xF0) && (data_buffer[1] == 0)) { - printf("."); + while ((counter >= progress)) + { + printf("#"); + progress += step; + } fflush (stdout); return TRUE; } else { fprintf(stderr, - "Bootloading failed, program aborted at dongle reply.\n"); + "\nBootloading failed, program aborted at dongle reply.\n"); exit(1); } } @@ -389,14 +397,18 @@ { if ((ret == 5) && (data_buffer[0] == 0xF0) && (data_buffer[1] == 0)) { - printf("."); + while ((counter >= progress)) + { + printf("#"); + progress += step; + } fflush (stdout); return TRUE; } else { fprintf(stderr, - "Bootloading failed, program aborted at dongle reply.\n"); + "\nBootloading failed, program aborted at dongle reply.\n"); exit(1); } } @@ -612,7 +624,6 @@ Parser_t parser; char line[100]; int rc = FALSE; - memset(&parser, 0, sizeof(parser)); /* clear all parser elements */ /* TODO get this value from either the file or the main program. @@ -634,7 +645,15 @@ goto cleanup; } + /* Nb of line */ + line_nb = 0; while (fgets(line, sizeof(line), fs) != NULL) + line_nb++; + + compute_progress_bar(line_nb); + fs = fopen(fileName, "rt"); + + while (fgets(line, sizeof(line), fs) != NULL) { parser.lineNum++; if (!parseIHexLine(&parser, line)) @@ -671,9 +690,14 @@ uint8_t packet_total = 2; /* XXX should depend on CPU type */ int ret; + /* Set global variable mem_type to the memory type */ mem_type = mem_t; + if (mem_type == EEPROM) + printf("EEPROM [\033[s\033[61C]\033[u\033[1B"); + else + printf("FLASH [\033[s\033[61C]\033[u\033[1B"); /* Bootloader initialization */ data_buffer[0] = LIBUSB_I2C_HEADER; data_buffer[1] = BOOT_INIT; @@ -682,9 +706,11 @@ data_buffer[4] = packet_total; counter = 0; - + progress = 0; + if (HID) { + sleep(0.5); ret = tux_hid_write(5, data_buffer); sleep(1); } @@ -697,7 +723,7 @@ { if (!wait_status(BOOT_INIT_ACK, USB_TIMEOUT) || !ret) { - fprintf(stderr, "Initialization failed\n"); + fprintf(stderr, "\nInitialization failed\n"); return FALSE; } } @@ -721,13 +747,15 @@ data_buffer[3] = 0; data_buffer[4] = 0; + progress = 0; + if (HID) - { + { tux_hid_write(5, data_buffer); tux_hid_read(5, data_buffer); if (!wait_status(BOOT_EXIT_ACK, USB_TIMEOUT)) { - fprintf(stderr, "Bootloader exit failed \n"); + fprintf(stderr, "\nBootloader exit failed \n"); return FALSE; } } @@ -762,3 +790,11 @@ } return 1; } + +static void compute_progress_bar(float line_nb) +{ + line_nb = (line_nb / 4); + if (line_nb<1) + line_nb = 1; + step = (line_nb / 60); +} Modified: firmware/tuxup/trunk/main.c =================================================================== --- firmware/tuxup/trunk/main.c 2008-05-30 13:37:01 UTC (rev 1206) +++ firmware/tuxup/trunk/main.c 2008-05-30 14:04:36 UTC (rev 1207) @@ -292,12 +292,12 @@ return 0; if (bootload(dev_h, cpu_i2c_addr, FLASH, filename)) - { - printf(" [OK]\n"); + { + printf("\033[2C[ \033[01;32mOK\033[00m ]\n"); return 0; } else - printf(" [FAIL]\n"); + printf("\033[2C[\033[01;31mFAIL\033[00m]\n"); return 1; } @@ -331,11 +331,11 @@ if (bootload(dev_h, cpu_i2c_addr, EEPROM, filename)) { - printf(" [OK]\n"); + printf("\033[2C[ \033[01;32mOK\033[00m ]\n"); return 0; } else - printf(" [FAIL]\n"); + printf("\033[2C[\033[01;31mFAIL\033[00m]\n"); return 1; } |