From: Ludwig Maier Date: Wed, 12 Feb 2014 20:23:56 +0000 (+0100) Subject: updated trb_flash, when calling 'info' DATE field now shows CompileTime take from... X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=fd01efcc8c1fd24d9601887a4b12a488cb58d501;p=trbnettools.git updated trb_flash, when calling 'info' DATE field now shows CompileTime take from information stored in *.bit file --- diff --git a/libtrbnet/trbflash.c b/libtrbnet/trbflash.c index 972368c..32da420 100644 --- a/libtrbnet/trbflash.c +++ b/libtrbnet/trbflash.c @@ -15,7 +15,7 @@ #include #include -extern char *optarg; +extern char* optarg; extern int optind, opterr, optopt; #include @@ -26,12 +26,13 @@ static const uint16_t CtrlReg = 0xd000; static const uint16_t SetupReg = 0xd001; static const uint16_t BlockRam = 0xd100; static const uint16_t MDCFlashRomSelect = 0xd200; +static char compileTime[64] = "----------"; -static uint32_t *trbBuffer = NULL; -static uint8_t **pageBuffer = NULL; -static uint16_t *pageBufferAddress = NULL; +static uint32_t* trbBuffer = NULL; +static uint8_t** pageBuffer = NULL; +static uint16_t* pageBufferAddress = NULL; -static uint8_t *imageBuffer = NULL; +static uint8_t* imageBuffer = NULL; /* Maximum number of endpoints */ #define NUM_ENDPOINTS 1024 @@ -49,7 +50,7 @@ static unsigned int NUM_BLOCKS = 0; #define PAGE_BUFFER_SIZE (PAGE_SIZE * NUM_ENDPOINTS) -static FILE *logFile = NULL; +static FILE* logFile = NULL; static const char logFileName[256] = "trbflash.log"; static const char busy[4][5] = { @@ -643,7 +644,7 @@ static int initTransfer(uint16_t trb_address) /* Buffer holding the entire rom-image */ imageBuffer = - (uint8_t *) malloc(sizeof(uint8_t) * (PAGE_SIZE * (NUM_PAGES + 2))); + (uint8_t* ) malloc(sizeof(uint8_t) * (PAGE_SIZE * (NUM_PAGES + 2))); if (imageBuffer == NULL) { abort(); } @@ -657,8 +658,8 @@ static int initTransfer(uint16_t trb_address) static int readPage(uint16_t trb_address, uint32_t pageNumber, uint32_t numBytes) { - uint32_t *temp = NULL; - uint32_t *end = NULL; + uint32_t* temp = NULL; + uint32_t* end = NULL; unsigned int endPoint; uint16_t size = 0; uint32_t trbcmd; @@ -719,9 +720,9 @@ static int readPage(uint16_t trb_address, uint32_t pageNumber, static int writePage(uint16_t trb_address, uint32_t pageNumber, - const uint8_t * pageBuffer, uint32_t numBytes) + const uint8_t* pageBuffer, uint32_t numBytes) { - uint32_t *temp = NULL; + uint32_t* temp = NULL; uint16_t size = 0; uint32_t trbcmd; unsigned int c; @@ -1056,9 +1057,9 @@ static int programImageBuffer(uint16_t trb_address, } -static int readImageFile(const char *imageFileName) +static int readImageFile(const char* imageFileName) { - FILE *imageFile = NULL; + FILE* imageFile = NULL; int imageSize; unsigned int i; @@ -1077,7 +1078,7 @@ static int readImageFile(const char *imageFileName) imageSize = 0; do { - imageSize += fread((void *)(imageBuffer + imageSize), sizeof(uint8_t), + imageSize += fread((void* )(imageBuffer + imageSize), sizeof(uint8_t), PAGE_SIZE, imageFile); } while ((feof(imageFile) == 0) && (imageSize <= PAGE_SIZE * NUM_PAGES)); @@ -1094,25 +1095,41 @@ static int readImageFile(const char *imageFileName) return imageSize; } + static int prepareImageBuffer() { int match; + int compileTimeFound; unsigned int end; unsigned int i = 0; /* Verify imageFile Id */ i = 0; match = 0; - for (i = 0; (i < 2 * PAGE_SIZE) && (match == 0); i++) { - unsigned int j = 0; - while (strlen(flashParamRef.allowedStringId[j]) > 0) { - if (memcmp(imageBuffer + i, - flashParamRef.allowedStringId[j], - strlen(flashParamRef.allowedStringId[j])) == 0) { - match = 1; - break; + compileTimeFound = 0; + for (i = 0; + (i < (2 * PAGE_SIZE) - 64) && (match == 0 || compileTimeFound == 0); + i++) { + + /* Look forg allowedStringId */ + if (match == 0) { + unsigned int j = 0; + while (strlen(flashParamRef.allowedStringId[j]) > 0) { + if (memcmp(imageBuffer + i, + flashParamRef.allowedStringId[j], + strlen(flashParamRef.allowedStringId[j])) == 0) { + match = 1; + break; + } + j++; } - j++; + } + + /* Look for Compile Time */ + if ((compileTimeFound == 0) && + (memcmp(imageBuffer + i, "Date:", 5) == 0 )) { + memcpy(compileTime, imageBuffer + i + 6, 24); + compileTimeFound = 1; } } @@ -1144,30 +1161,23 @@ static int prepareImageBuffer() return 0; } -static int createInfoPage(const char *fileName, const char *userString) +static int createInfoPage(const char* fileName, const char* userString) { - char *buffer = (char *)(imageBuffer + (NUM_PAGES - 1) * PAGE_SIZE); - struct stat statBuf; + char* buffer = (char* )(imageBuffer + (NUM_PAGES - 1) * PAGE_SIZE); unsigned int i; for (i = 0; i < PAGE_SIZE; i++) { buffer[i] = '\0'; } - if (stat(fileName, &statBuf) == -1) { - fprintf(logFile, - "Error line %d > prepareInfoPage: statCall failed: %s\n", - __LINE__, strerror(errno)); - return -1; - } - snprintf(buffer + 0, 63, "NAME: %s", basename((char *)fileName)); - snprintf(buffer + 64, 31, "DATE: %s", ctime(&statBuf.st_mtime)); + snprintf(buffer + 0, 63, "NAME: %s", basename((char* )fileName)); + snprintf(buffer + 64, 31, "DATE: %s", compileTime); snprintf(buffer + 96, 159, "USER: %s", userString); fprintf(stderr, "%s\n", buffer); fprintf(stderr, "%s\n", buffer + 64); fprintf(stderr, "%s\n", buffer + 96); - + return 0; } @@ -1209,7 +1219,7 @@ static int selectMdcFlashRom(uint16_t trb_address, uint8_t number) /* ------ MAIN ---------------------------------------------------------- */ -void usage(const char *progName) +void usage(const char* progName) { printf("Usage: %s [-s str] [-g] [-y] [-f] [-v] [-h] [-V] \n", progName); @@ -1238,10 +1248,10 @@ void usage(const char *progName) "dump one flash-memory page to stdout\n"); } -int main(int argc, char **argv) +int main(int argc, char** argv) { unsigned int i; - char userInfoStr[256] = ""; + char userInfoStr[256] = "----------"; trb_debug = 0; logFile = stderr; mdcFlashSelect = 1; @@ -1306,24 +1316,24 @@ int main(int argc, char **argv) /* Allocate memory for buffers */ /* Buffer holding the TRBNet packages, e.g. use by trb_read_register */ - trbBuffer = (uint32_t *) malloc(sizeof(uint32_t) * TRB_BUFFER_SIZE); + trbBuffer = (uint32_t* ) malloc(sizeof(uint32_t) * TRB_BUFFER_SIZE); if (trbBuffer == NULL) { abort(); } /* Buffer holding the pages of the endpoints */ - pageBuffer = (uint8_t **) malloc(sizeof(uint8_t *) * NUM_ENDPOINTS); + pageBuffer = (uint8_t**) malloc(sizeof(uint8_t* ) * NUM_ENDPOINTS); if (pageBuffer == NULL) { abort(); } for (i = 0; i < NUM_ENDPOINTS; i++) { - pageBuffer[i] = (uint8_t *) malloc(sizeof(uint8_t) * PAGE_SIZE); + pageBuffer[i] = (uint8_t* ) malloc(sizeof(uint8_t) * PAGE_SIZE); if (pageBuffer[i] == NULL) abort(); } /* Buffer holding the corresponding TRBAddresses */ - pageBufferAddress = (uint16_t *) malloc(sizeof(uint16_t) * NUM_ENDPOINTS); + pageBufferAddress = (uint16_t* ) malloc(sizeof(uint16_t) * NUM_ENDPOINTS); if (pageBufferAddress == NULL) { abort(); } @@ -1336,7 +1346,7 @@ int main(int argc, char **argv) /*********************************************************/ uint16_t trb_address; - char *imageFileName = NULL; + char* imageFileName = NULL; int size; if (argc - optind != 3) { @@ -1367,7 +1377,7 @@ int main(int argc, char **argv) if (prepareImageBuffer() == -1) { exit(EXIT_FAILURE); } - + /* Create InfoPage */ createInfoPage(imageFileName, userInfoStr); @@ -1402,7 +1412,7 @@ int main(int argc, char **argv) /*********************************************************/ uint16_t trb_address; - char *imageFileName = NULL; + char* imageFileName = NULL; int size; if (argc - optind != 3) { @@ -1459,8 +1469,8 @@ int main(int argc, char **argv) /*********************************************************/ uint16_t trb_address; - char *imageFileName; - FILE *imageFile = NULL; + char* imageFileName; + FILE* imageFile = NULL; unsigned int page; int status = 0; @@ -1512,7 +1522,7 @@ int main(int argc, char **argv) fclose(imageFile); exit(EXIT_FAILURE); } - if (fwrite((void *)pageBuffer[0], PAGE_SIZE, 1, imageFile) != 1) { + if (fwrite((void* )pageBuffer[0], PAGE_SIZE, 1, imageFile) != 1) { fprintf(stderr, "\nError writing Page #%d to file, aborting..\n", page); fclose(imageFile); @@ -1532,7 +1542,7 @@ int main(int argc, char **argv) /*********************************************************/ uint16_t trb_address; - char *imageFileName; + char* imageFileName; int size; if (argc - optind != 3) { @@ -1625,9 +1635,9 @@ int main(int argc, char **argv) pageBuffer[i][255] = '\0'; fprintf(stdout, "\nEndPoint: 0x%04x InfoPage\n", pageBufferAddress[i]); - if ((strncmp((char *)(pageBuffer[i] + 0), "NAME:", 5) != 0) || - (strncmp((char *)(pageBuffer[i] + 64), "DATE:", 5) != 0) || - (strncmp((char *)(pageBuffer[i] + 96), "USER:", 5) != 0) + if ((strncmp((char* )(pageBuffer[i] + 0), "NAME:", 5) != 0) || + (strncmp((char* )(pageBuffer[i] + 64), "DATE:", 5) != 0) || + (strncmp((char* )(pageBuffer[i] + 96), "USER:", 5) != 0) ) { fprintf(stdout, "INVALID CONTENT\n"); continue;