#include <sys/stat.h>
#include <unistd.h>
-extern char *optarg;
+extern char* optarg;
extern int optind, opterr, optopt;
#include <trbnet.h>
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
#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] = {
/* 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();
}
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;
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;
}
-static int readImageFile(const char *imageFileName)
+static int readImageFile(const char* imageFileName)
{
- FILE *imageFile = NULL;
+ FILE* imageFile = NULL;
int imageSize;
unsigned int i;
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));
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;
}
}
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;
}
/* ------ MAIN ---------------------------------------------------------- */
-void usage(const char *progName)
+void usage(const char* progName)
{
printf("Usage: %s [-s str] [-g] [-y] [-f] [-v] [-h] [-V] <COMMAND>\n",
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;
/* 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();
}
/*********************************************************/
uint16_t trb_address;
- char *imageFileName = NULL;
+ char* imageFileName = NULL;
int size;
if (argc - optind != 3) {
if (prepareImageBuffer() == -1) {
exit(EXIT_FAILURE);
}
-
+
/* Create InfoPage */
createInfoPage(imageFileName, userInfoStr);
/*********************************************************/
uint16_t trb_address;
- char *imageFileName = NULL;
+ char* imageFileName = NULL;
int size;
if (argc - optind != 3) {
/*********************************************************/
uint16_t trb_address;
- char *imageFileName;
- FILE *imageFile = NULL;
+ char* imageFileName;
+ FILE* imageFile = NULL;
unsigned int page;
int status = 0;
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);
/*********************************************************/
uint16_t trb_address;
- char *imageFileName;
+ char* imageFileName;
int size;
if (argc - optind != 3) {
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;