From: hadaq Date: Wed, 9 Feb 2011 12:54:49 +0000 (+0000) Subject: output now stdout, fflush X-Git-Tag: v6.0~160 X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=1e581746f03b193ec0c7bca82d05e817c19254ac;p=trbnettools.git output now stdout, fflush --- diff --git a/libtrbnet/trbflash.c b/libtrbnet/trbflash.c index 5917452..fab3c05 100644 --- a/libtrbnet/trbflash.c +++ b/libtrbnet/trbflash.c @@ -96,7 +96,7 @@ static const char FlashTypeStr[16][32] = { static FlashType flashType = FLASH_INVALID; static uint32_t manId = 0; -static const char trbflash_version[] = "$Revision: 2.28 $"; +static const char trbflash_version[] = "$Revision: 2.29 $"; static uint32_t mdcFlashSelect = 1; @@ -611,7 +611,6 @@ typedef enum static int programImageBuffer(uint16_t trb_address, unsigned int size, PMode mode, int infoPage) { - int bla = 0; unsigned int block; int status; int errorCtr = 0; @@ -625,41 +624,44 @@ static int programImageBuffer(uint16_t trb_address, char c; if ((flashType == FLASH_MDC_OEP_V2) || (flashType == FLASH_MDC_OEP_V3)) { if (mdcFlashSelect == 0) { - fprintf(stderr, + fprintf(stdout, "You decided to reprogram the FlashRom(s) #0 of " "MDC_OEP, the so called 'GoldenImage'. " "Do you really know what you're about to do [N,y]: "); } } else { - fprintf(stderr, + fprintf(stdout, "You decided to reprogram the FlashRom(s) of " "%s, are you sure [N,y]: ", FlashTypeStr[flashType]); } + fflush(stdout); c = getc(stdin); if (!((c == 'Y') || (c == 'y'))) { - fprintf(stderr, "\nAborting on user request\n"); + fprintf(stdout, "\nAborting on user request\n"); + fflush(stdout); return -1; } } if (mode != PMODE_VERIFY) { - fprintf(stderr, + fprintf(stdout, "Programming Endpoint(s) @ Address 0x%04x\n", trb_address); - fprintf(stderr, + fprintf(stdout, "Symbols:\n" " E: Erasing\n" " P: Programming\n" " @: Success\n" " .: Skipped\n\n"); } else { - fprintf(stderr, "Verifying Endpoint(s) @ Address 0x%04x\n", trb_address); - fprintf(stderr, + fprintf(stdout, "Verifying Endpoint(s) @ Address 0x%04x\n", trb_address); + fprintf(stdout, "Symbols:\n" " V: Verifying\n" " X: Failed (see logfile 'trbflash.log' for details)\n" " @: Success\n" " .: Skipped\n\n"); } - fprintf(stderr, "Block: 0 1 2 3 4 5 6 7 8 9 A B C D E F"); - + fprintf(stdout, "Block: 0 1 2 3 4 5 6 7 8 9 A B C D E F"); + fflush(stdout); + errorCtr = 0; if ((mode != PMODE_VERIFY) && (manId == 0x1520c2)) { @@ -674,12 +676,14 @@ static int programImageBuffer(uint16_t trb_address, int error = 0; int writeInfoPage = (block == NUM_BLOCKS - 1) && (infoPage == 1) ? 1 : 0; if (block % 16 == 0) { - fprintf(stderr, "\n%x ", block / 16); + fprintf(stdout, "\n%x ", block / 16); } - fprintf(stderr, ".\b"); - + fprintf(stdout, ".\b"); + fflush(stdout); + if (!(bytesWritten > 0) && (writeInfoPage == 0)) { - fprintf(stderr, ". "); + fprintf(stdout, ". "); + fflush(stdout); continue; } @@ -709,7 +713,8 @@ static int programImageBuffer(uint16_t trb_address, } /* Erase block */ - fprintf(stderr, "E\b"); + fprintf(stdout, "E\b"); + fflush(stdout); if (sendCommand(trb_address, 0xd8 << 24 | (BLOCK_SIZE * block), 3) == -1) { fprintf(stderr, "\nError > program: erase block #%d, aborting\n", @@ -727,7 +732,8 @@ static int programImageBuffer(uint16_t trb_address, } /* Now write pages */ - fprintf(stderr, "P\b"); + fprintf(stdout, "P\b"); + fflush(stdout); tmp = bytesWritten; for (i = 0, page = (block * BLOCK_SIZE) / PAGE_SIZE; (i < (BLOCK_SIZE / PAGE_SIZE)) && (tmp > 0); i++, page++) { @@ -775,9 +781,9 @@ static int programImageBuffer(uint16_t trb_address, } } else { /* Verify pages */ - fprintf(stderr, "V\b"); + fprintf(stdout, "V\b"); + fflush(stdout); tmp = bytesWritten; - bla++; for (i = 0, page = (block * BLOCK_SIZE) / PAGE_SIZE; (i < (BLOCK_SIZE / PAGE_SIZE)) && (tmp > 0); i++, page++) { unsigned int endPoint; @@ -839,10 +845,11 @@ static int programImageBuffer(uint16_t trb_address, } if (error == 0) { - fprintf(stderr, "@ "); + fprintf(stdout, "@ "); } else { - fprintf(stderr, "X "); + fprintf(stdout, "X "); } + fflush(stdout); } if ((mode != PMODE_VERIFY) && (manId == 0x1520c2)) { @@ -854,12 +861,13 @@ static int programImageBuffer(uint16_t trb_address, } if (errorCtr == 0) { - fprintf(stderr, "\n\nSuccess\n\n"); + fprintf(stdout, "\n\nSuccess\n\n"); } else { - fprintf(stderr, + fprintf(stdout, "\n\n%d Errors have occured, see logFile %s for details\n\n", errorCtr, logFileName); } + fflush(stdout); return errorCtr == 0 ? 0 : -1; }