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 uint32_t* trbBuffer = NULL;
static uint8_t** pageBuffer = NULL;
static uint16_t* pageBufferAddress = NULL;
static FlashType flashType = FLASH_INVALID;
-static const char trbflash_version[] = "$Revision: 2.02 $";
+static const char trbflash_version[] = "$Revision: 2.03 $";
+
+static uint32_t mdcFlashSelect = 1;
/* ------ Local Functions ----------------------------------------------- */
int bytesWritten = size;
int tmp;
+ if (verifyOnly == 0) {
+ /* Be nice and ask before start flashing the roms */
+ char c;
+ fprintf(stdout, "You decided to reprogram the FlashRom(s), "
+ "are you sure [N,y]: ");
+ c = getc(stdin);
+ if (!((c == 'Y') || (c == 'y'))) {
+ fprintf(stderr, "\nAborting on user request\n");
+ return -1;
+ }
+
+ if (flashType == FLASH_MDC) {
+ if (mdcFlashSelect == 0) {
+ fprintf(stdout, "\nFlashRom(s) #0 of MDC (i.e. the GoldenImage(s)), "
+ "do you know what you're about to do [N,y]: ");
+ c = getc(stdin);
+ if (!((c == 'Y') || (c == 'y'))) {
+ fprintf(stderr, "\nAborting on user request\n");
+ return -1;
+ }
+ }
+ }
+ }
+
if (verifyOnly == 0) {
fprintf(stderr, "Programming Endpoint(s) @ Address 0x%04x\n",
trb_address);
errorCtr = 0;
- if ((verifyOnly == 0) && (flashType == FLASH_MDC)) {
+ if ((flashType == FLASH_MDC) && (verifyOnly == 0)) {
/* Unprotect all Sectors */
if (writeStatusRegister(trb_address, 0) == -1) {
- fprintf(stderr, "\nError > program: unprotect all sectors, aborting\n");
+ fprintf(stderr,
+ "\nError > program: unprotect all sectors, aborting\n");
return -1;
}
}
/* Unprotect sector */
if (sendCommand(trb_address, 0x39 << 24 | (BLOCK_SIZE * block), 3)
== -1) {
- fprintf(stderr, "\nError > program: unprotect sector #%d, aborting\n",
+ fprintf(stderr,
+ "\nError > program: unprotect sector #%d, aborting\n",
block);
return -1;
}
status = writePage(trb_address, page,
imageBuffer + page * PAGE_SIZE, bytes);
if (status == -1) {
- fprintf(stderr, "\nError > program: pageProgram page #%d, aborting\n",
+ fprintf(stderr,
+ "\nError > program: pageProgram page #%d, aborting\n",
page);
return -1;
}
/* Protect sector */
if (sendCommand(trb_address, 0x36 << 24 | (BLOCK_SIZE * block), 3)
== -1) {
- fprintf(stderr, "\nError > program: unprotect sector #%d, aborting\n",
+ fprintf(stderr,
+ "\nError > program: unprotect sector #%d, aborting\n",
block);
return -1;
}
return 0;
}
+static int selectMdcFlashRom(uint16_t trb_address, uint8_t number) {
+ /* Select MDC-FlashRom */
+ if (trb_register_write(trb_address, MDCFlashRomSelect,
+ (uint32_t)number) == -1) {
+ fprintf(logFile, "\nError > selcetMdcFlashRom: TRBNet %s\n",
+ trb_strerror(trb_errno));
+ return -1;
+ }
+}
+
/* ------ MAIN ---------------------------------------------------------- */
void usage(const char *progName)
printf("Usage: %s [-h] <COMMAND>\n",
progName);
printf("Options:\n");
+ printf(" -g select 'FlashRom #0 (the 'Golden Image') "
+ "(MDC only, default = no)\n");
printf(" -h give this help\n");
printf(" -V Version number\n");
printf("\nCommands:\n");
trb_debug = 0;
logFile = stderr;
-
+ mdcFlashSelect = 1;
+
/* Parse Arguments */
- while ((i = getopt(argc, argv, "+hd:V")) != -1) {
+ while ((i = getopt(argc, argv, "+hd:gV")) != -1) {
switch (i) {
case '?':
usage(basename(argv[0]));
case 'h':
usage(basename(argv[0]));
exit(EXIT_SUCCESS);
+ case 'g':
+ mdcFlashSelect = 0;
+ break;
case 'd':
trb_debug = strtoul(optarg, NULL, 0);
break;
if (prepareImageBuffer() == -1) {
exit(EXIT_FAILURE);
}
+
+ /* In case of MDC: select FlashRom */
+ if (flashType == FLASH_MDC) {
+ if (selectMdcFlashRom(trb_address, mdcFlashSelect) == -1) {
+ exit(EXIT_FAILURE);
+ }
+ }
/* Open LogFile */
if (openLog() == -1) {
exit(EXIT_FAILURE);
}
+ /* In case of MDC: select FlashRom */
+ if (flashType == FLASH_MDC) {
+ if (selectMdcFlashRom(trb_address, mdcFlashSelect) == -1) {
+ exit(EXIT_FAILURE);
+ }
+ }
+
/* Open LogFile */
if (openLog() == -1) {
exit(EXIT_FAILURE);
"Broadcast addresses are not supported by this command\n");
exit(EXIT_FAILURE);
}
-
+
+ /* In case of MDC: select FlashRom */
+ if (flashType == FLASH_MDC) {
+ if (selectMdcFlashRom(trb_address, mdcFlashSelect) == -1) {
+ exit(EXIT_FAILURE);
+ }
+ }
+
if (initTransfer(trb_address) == -1) {
exit(EXIT_FAILURE);
}
}
/* Write Pages to file */
- fprintf(stderr, "Writing entire flashrom of EndPoint 0x%04x to file '%s' ",
+ fprintf(stderr,
+ "Dumping entire flashrom of EndPoint 0x%04x to file '%s' ",
trb_address, imageFileName);
imageFile = fopen(imageFileName, "w+");
/* Check ImageBuffer ??? */
+ /* In case of MDC: select FlashRom */
+ if (flashType == FLASH_MDC) {
+ if (selectMdcFlashRom(trb_address, mdcFlashSelect) == -1) {
+ exit(EXIT_FAILURE);
+ }
+ }
+
/* Open LogFile */
if (openLog() == -1) {
exit(EXIT_FAILURE);
fprintf(stderr, "Invalid ManId(s), aborting\n");
exit(EXIT_FAILURE);
}
-
+
+ /* In case of MDC: select FlashRom */
+ if (flashType == FLASH_MDC) {
+ if (selectMdcFlashRom(trb_address, mdcFlashSelect) == -1) {
+ exit(EXIT_FAILURE);
+ }
+ }
+
if ((status = readPage(trb_address, pageNumber, 256)) == -1) {
fprintf(stderr, "Error reading Page, aborting\n");
exit(EXIT_FAILURE);
fprintf(stdout, "\n");
} else {
+
/* Invalid command */
usage(basename(argv[0]));
exit(EXIT_FAILURE);