From 12f081ab2778e3ed9212a4f3c8205f04f6f7f038 Mon Sep 17 00:00:00 2001 From: Michael Traxler Date: Wed, 23 Apr 2014 10:43:08 +0200 Subject: [PATCH] trbflash: support for new hardware id (0x9300) of cbmtof --- libtrbnet/trbflash.c | 127 +++++++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 54 deletions(-) diff --git a/libtrbnet/trbflash.c b/libtrbnet/trbflash.c index 972368c..4cdb356 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] = { @@ -89,7 +90,8 @@ typedef enum FLASH_TRB3_FPGA_3 = 17, FLASH_TRB3_FPGA_4 = 18, - CBM_RICH_1 = 19 + CBM_RICH_1 = 19, + CBM_TOF_1 = 20 } FlashType; static const char FlashTypeStr[][32] = { @@ -112,7 +114,8 @@ static const char FlashTypeStr[][32] = { "TRB3 FPGA 2", "TRB3 FPGA 3", "TRB3 FPGA 4", - "CBM RICH V1" + "CBM RICH V1", + "CBM TOF V1" }; typedef struct { @@ -328,6 +331,13 @@ static int setFlashParam(FlashParam* flashParam, uint16_t hardwareId) strcpy(flashParam->allowedStringId[1], "cbmtof"); flashParam->numPages = 32768; break; + + case 0x9300: + flashParam->flashType = CBM_TOF_1; + flashParam->manId = 0x1720c2; + strcpy(flashParam->allowedStringId[0], "cbmtof"); + flashParam->numPages = 32768; + break; default: return -1; @@ -643,7 +653,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 +667,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 +729,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 +1066,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 +1087,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 +1104,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 +1170,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 +1228,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 +1257,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 +1325,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 +1355,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 +1386,7 @@ int main(int argc, char **argv) if (prepareImageBuffer() == -1) { exit(EXIT_FAILURE); } - + /* Create InfoPage */ createInfoPage(imageFileName, userInfoStr); @@ -1402,7 +1421,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 +1478,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 +1531,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 +1551,7 @@ int main(int argc, char **argv) /*********************************************************/ uint16_t trb_address; - char *imageFileName; + char* imageFileName; int size; if (argc - optind != 3) { @@ -1625,9 +1644,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; -- 2.43.0