} PMode;
static int programImageBuffer(uint16_t trb_address,
- unsigned int size, PMode mode, int infoPage)
+ unsigned int start_page, unsigned int size, PMode mode, int infoPage)
{
unsigned int block;
int status;
fprintf(stdout, ".\b");
fflush(stdout);
- if (!(bytesWritten > 0) && (writeInfoPage == 0)) {
+ if ( (!(bytesWritten > 0) && (writeInfoPage == 0)) || ((block * BLOCK_SIZE)/PAGE_SIZE < start_page ) ) {
fprintf(stdout, ". ");
fflush(stdout);
continue;
bytesWritten = tmp;
status = writePage(trb_address, page,
- imageBuffer + page * PAGE_SIZE, bytes);
+ imageBuffer + (page - start_page) * PAGE_SIZE, bytes);
if (status == -1) {
fprintf(stderr,
"\nError > program: pageProgram page #%d, aborting\n",
printf(" -h give this help\n");
printf(" -V Version number\n");
printf("\nCommands:\n");
- printf(" program <trbaddress> <bit-file> -> "
+ printf(" program <trbaddress> <bit-file> -> "
"program bit-file to flash-memory\n");
- printf(" verify <trbaddress> <bit-file> -> "
+ printf(" verify <trbaddress> <bit-file> -> "
"compare bit-file with flash-memory\n");
- printf(" backup <trbaddress> <raw-file> -> "
+ printf(" backup <trbaddress> <raw-file> -> "
"write entire flash-memory to raw-file\n");
- printf(" restore <trbaddress> <raw-file> -> "
+ printf(" restore <trbaddress> <raw-file> -> "
"write backuped raw-file to flash-memory\n");
- printf(" info <trbaddress> -> "
+ printf(" info <trbaddress> -> "
"dump content of info-page to stdout\n");
- printf(" dumppage <trbaddress> pagenumber -> "
+ printf(" dumppage <trbaddress> pagenumber -> "
"dump one flash-memory page to stdout\n");
+ printf(" flash_at_page <trbaddress> <page> <binary file> -> "
+ "program a binary file to flash-memory,\n"
+ " "
+ "beginning at page <page>\n"
+ );
}
int main(int argc, char** argv)
fprintf(stderr, "Start programming ImageFile '%s'\n", imageFileName);
- if (programImageBuffer(trb_address, size, PMODE_PROGRAM, 1) == -1) {
+ if (programImageBuffer(trb_address, 0, size, PMODE_PROGRAM, 1) == -1) {
exit(EXIT_FAILURE);
}
if (skipVerify == 0) {
- if (programImageBuffer(trb_address, size, PMODE_VERIFY, 1) == -1) {
+ if (programImageBuffer(trb_address, 0, size, PMODE_VERIFY, 1) == -1) {
exit(EXIT_FAILURE);
}
}
+ } else if (strcmp(argv[optind], "flash_at_page") == 0) {
+
+ /*********************************************************/
+ /* Program Image */
+ /*********************************************************/
+
+ uint16_t trb_address;
+ char* imageFileName = NULL;
+ int size;
+ uint16_t start_page;
+
+ if (argc - optind != 4) {
+ usage(basename(argv[0]));
+ exit(EXIT_FAILURE);
+ }
+
+ trb_address = strtoul(argv[optind + 1], NULL, 0);
+ start_page = strtoul(argv[optind + 2], NULL, 0);
+ imageFileName = argv[optind + 3];
+
+ /* Check for correct ManId */
+ if (initTransfer(trb_address) == -1) {
+ fprintf(stderr, "InitTransfer failed, aborting\n");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Read imageFile to imageBuffer */
+ if ((size = readImageFile(imageFileName)) == -1) {
+ exit(EXIT_FAILURE);
+ }
+ if (size > (PAGE_SIZE * (NUM_PAGES - 1))) {
+ fprintf(stderr, "ImageFile to large (%d bytes, maximum is %d bytes)\n",
+ size, PAGE_SIZE * (NUM_PAGES - 1));
+ exit(EXIT_FAILURE);
+ }
+
+// /* Validate Id and prepare imageBuffer */
+// if (prepareImageBuffer() == -1) {
+// exit(EXIT_FAILURE);
+// }
+
+ /* In case of MDC: select FlashRom */
+ if ((flashParamRef.flashType == FLASH_MDC_OEP_V2) || (flashParamRef.flashType == FLASH_MDC_OEP_V3)) {
+ if (selectMdcFlashRom(trb_address, mdcFlashSelect) == -1) {
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ /* Open LogFile */
+ if (openLog() == -1) {
+ exit(EXIT_FAILURE);
+ }
+
+ fprintf(stderr, "Start programming ImageFile '%s'\n", imageFileName);
+
+ if (programImageBuffer(trb_address, start_page, size, PMODE_PROGRAM, 0) == -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, 0) == -1) {
+ if (programImageBuffer(trb_address, 0, size, PMODE_VERIFY, 0) == -1) {
exit(EXIT_FAILURE);
}
fprintf(stderr, "Start restoring ImageFile '%s'\n", imageFileName);
- if (programImageBuffer(trb_address, size, PMODE_PROGRAM_FULL, 0) == -1) {
+ if (programImageBuffer(trb_address, 0, size, PMODE_PROGRAM_FULL, 0) == -1) {
exit(EXIT_FAILURE);
}
if (skipVerify == 0) {
- if (programImageBuffer(trb_address, size, PMODE_VERIFY, 0) == -1) {
+ if (programImageBuffer(trb_address, 0, size, PMODE_VERIFY, 0) == -1) {
exit(EXIT_FAILURE);
}
}