static FlashType flashType = FLASH_INVALID;
static uint32_t manId = 0;
-static const char trbflash_version[] = "$Revision: 2.20 $";
+static const char trbflash_version[] = "$Revision: 2.21 $";
static uint32_t mdcFlashSelect = 1;
default:
abort();
}
-
-
+
NUM_BLOCKS = (NUM_PAGES * PAGE_SIZE) / BLOCK_SIZE;
/* Buffer holding the entire rom-image */
PMODE_VERIFY
} PMode;
-static int programImageBuffer(uint16_t trb_address, unsigned int size,
- PMode mode)
+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;
if ((flashType == FLASH_MDC_OEP_V2) ||
(flashType == FLASH_MDC_OEP_V3)) {
if (mdcFlashSelect == 0) {
- fprintf(stdout, "You decided to reprogram the FlashRom(s) #0 of "
+ 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(stdout, "You decided to reprogram the FlashRom(s) of "
+ fprintf(stdout,
+ "You decided to reprogram the FlashRom(s) of "
"%s, are you sure [N,y]: ", FlashTypeStr[flashType]);
}
}
if (mode != PMODE_VERIFY) {
- fprintf(stderr, "Programming Endpoint(s) @ Address 0x%04x\n",
+ fprintf(stderr,
+ "Programming Endpoint(s) @ Address 0x%04x\n",
trb_address);
- fprintf(stderr, "Symbols:\n"
+ fprintf(stderr,
+ "Symbols:\n"
" E: Erasing\n"
" P: Programming\n"
- " V: Verifying\n"
- " X: Failed (see logfile 'trbflash.log' for details)\n"
" @: Success\n"
" .: Skipped\n\n");
} else {
- fprintf(stderr, "Verifying Endpoint(s) @ Address 0x%04x\n",
+ fprintf(stderr,
+ "Verifying Endpoint(s) @ Address 0x%04x\n",
trb_address);
- fprintf(stderr, "Symbols:\n"
+ fprintf(stderr,
+ "Symbols:\n"
" V: Verifying\n"
" X: Failed (see logfile 'trbflash.log' for details)\n"
" @: Success\n"
for (block = 0; (block < NUM_BLOCKS); block++) {
int error = 0;
- int writeInfoPage = (block == NUM_BLOCKS - 1) && (mode == PMODE_PROGRAM)
- ? 1 : 0;
-
+ int writeInfoPage =
+ (block == NUM_BLOCKS - 1) && (infoPage == 1) ? 1 : 0;
if (block % 16 == 0) {
fprintf(stderr, "\n%x ", block / 16);
}
i++, page++) {
int bytes = tmp < PAGE_SIZE ? tmp : PAGE_SIZE;
tmp -= bytes;
+ bytesWritten = tmp;
+
status = writePage(trb_address, page,
imageBuffer + page * PAGE_SIZE, bytes);
if (status == -1) {
return -1;
}
}
+
if ((manId == 0x01461f) ||
(manId == 0x00471f)) {
/* Enable writing */
/* 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: protect sector #%d, aborting\n",
block);
return -1;
}
}
- }
-
- /* Verify pages */
- fprintf(stderr, "V\b");
- tmp = bytesWritten;
- for (i = 0, page = (block * BLOCK_SIZE) / PAGE_SIZE;
- (i < (BLOCK_SIZE / PAGE_SIZE)) && (tmp > 0);
- i++, page++) {
- unsigned int endPoint;
- unsigned int c;
- int bytes = tmp < PAGE_SIZE ? tmp : PAGE_SIZE;
- tmp -= bytes;
-
- if ((status = readPage(trb_address, page, bytes)) == -1) {
- fprintf(stderr, "\nError > program: reading Page #%d, aborting\n",
- page);
- return -1;
- }
-
- for (endPoint = 0; endPoint < status; endPoint++) {
- for (c = 0; c < bytes; c++) {
- if (pageBuffer[endPoint][c] != imageBuffer[page * PAGE_SIZE + c]) {
- error = -1;
- errorCtr++;
- fprintf(logFile,
- "verify failed page #%d, byte #%d "
- "(exp: 0x%02x rec: 0x%02x), EndPoint: 0x%04x\n",
- page, c,
- imageBuffer[page * PAGE_SIZE + c],
- pageBuffer[endPoint][c],
- pageBufferAddress[endPoint]);
+ } else {
+ /* Verify pages */
+ fprintf(stderr, "V\b");
+ tmp = bytesWritten;
+ bla++;
+ for (i = 0, page = (block * BLOCK_SIZE) / PAGE_SIZE;
+ (i < (BLOCK_SIZE / PAGE_SIZE)) && (tmp > 0);
+ i++, page++) {
+ unsigned int endPoint;
+ unsigned int c;
+ int bytes = tmp < PAGE_SIZE ? tmp : PAGE_SIZE;
+ tmp -= bytes;
+ bytesWritten = tmp;
+
+ if ((status = readPage(trb_address, page, bytes)) == -1) {
+ fprintf(stderr, "\nError > program: reading Page #%d, aborting\n",
+ page);
+ return -1;
+ }
+
+ for (endPoint = 0; endPoint < status; endPoint++) {
+ for (c = 0; c < bytes; c++) {
+ if (pageBuffer[endPoint][c] != imageBuffer[page * PAGE_SIZE + c]) {
+ error = -1;
+ errorCtr++;
+ fprintf(logFile,
+ "verify failed page #%d, byte #%d "
+ "(exp: 0x%02x rec: 0x%02x), EndPoint: 0x%04x\n",
+ page, c,
+ imageBuffer[page * PAGE_SIZE + c],
+ pageBuffer[endPoint][c],
+ pageBufferAddress[endPoint]);
+ }
}
}
}
- bytesWritten = tmp;
- }
-
- if (writeInfoPage == 1) {
/* Verify Info-Page */
- unsigned int endPoint;
- unsigned int c;
- int bytes = tmp < PAGE_SIZE ? tmp : PAGE_SIZE;
- tmp -= bytes;
-
- if ((status = readPage(trb_address, NUM_PAGES - 1, PAGE_SIZE)) == -1) {
- fprintf(stderr, "\nError > program: reading InfoPage, aborting\n");
- return -1;
- }
-
- for (endPoint = 0; endPoint < status; endPoint++) {
- for (c = 0; c < PAGE_SIZE; c++) {
- if (pageBuffer[endPoint][c] !=
- imageBuffer[(NUM_PAGES - 1) * PAGE_SIZE + c]) {
- error = -1;
- errorCtr++;
- fprintf(logFile,
- "verify failed InfoPage, byte #%d "
- "(exp: 0x%02x rec: 0x%02x), EndPoint: 0x%04x\n",
- c,
- imageBuffer[(NUM_PAGES - 1) * PAGE_SIZE + c],
- pageBuffer[endPoint][c],
- pageBufferAddress[endPoint]);
+ if (writeInfoPage == 1) {
+ unsigned int endPoint;
+ unsigned int c;
+ int bytes = tmp < PAGE_SIZE ? tmp : PAGE_SIZE;
+ tmp -= bytes;
+
+ if ((status = readPage(trb_address, NUM_PAGES - 1, PAGE_SIZE)) == -1) {
+ fprintf(stderr, "\nError > program: reading InfoPage, aborting\n");
+ return -1;
+ }
+
+ for (endPoint = 0; endPoint < status; endPoint++) {
+ for (c = 0; c < PAGE_SIZE; c++) {
+ if (pageBuffer[endPoint][c] !=
+ imageBuffer[(NUM_PAGES - 1) * PAGE_SIZE + c]) {
+ error = -1;
+ errorCtr++;
+ fprintf(logFile,
+ "verify failed InfoPage, byte #%d "
+ "(exp: 0x%02x rec: 0x%02x), EndPoint: 0x%04x\n",
+ c,
+ imageBuffer[(NUM_PAGES - 1) * PAGE_SIZE + c],
+ pageBuffer[endPoint][c],
+ pageBufferAddress[endPoint]);
+ }
}
}
}
fprintf(stderr, "Start programming ImageFile '%s'\n",
imageFileName);
- if (programImageBuffer(trb_address, size, PMODE_PROGRAM) == -1) {
+ if (programImageBuffer(trb_address, size, PMODE_PROGRAM, 1) == -1) {
exit(EXIT_FAILURE);
}
+ if (programImageBuffer(trb_address, size, PMODE_VERIFY, 1) == -1) {
+ exit(EXIT_FAILURE);
+ }
+
} else if (strcmp(argv[optind], "verify") == 0) {
/*********************************************************/
fprintf(stderr, "Start verifying ImageFile '%s'\n",
imageFileName);
- if (programImageBuffer(trb_address, size, PMODE_VERIFY) == -1) {
+ if (programImageBuffer(trb_address, size, PMODE_VERIFY, 0) == -1) {
exit(EXIT_FAILURE);
}
fprintf(stderr, "Start restoring ImageFile '%s'\n",
imageFileName);
- if (programImageBuffer(trb_address, size, PMODE_PROGRAM_FULL) == -1) {
+ if (programImageBuffer(trb_address, size, PMODE_PROGRAM_FULL, 0) == -1) {
exit(EXIT_FAILURE);
}