From: Maps Date: Thu, 9 Jul 2015 15:48:26 +0000 (+0200) Subject: added feature to write binary data to flash, beginning with arbitrary page X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=f4f7669eb24228e041411212ae341180936a1306;p=trbnettools.git added feature to write binary data to flash, beginning with arbitrary page --- diff --git a/libtrbnet/trbflash.c b/libtrbnet/trbflash.c index 6e92393..3f40b82 100644 --- a/libtrbnet/trbflash.c +++ b/libtrbnet/trbflash.c @@ -806,7 +806,7 @@ typedef enum } 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; @@ -880,7 +880,7 @@ static int programImageBuffer(uint16_t trb_address, 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; @@ -942,7 +942,7 @@ static int programImageBuffer(uint16_t trb_address, 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", @@ -1253,18 +1253,23 @@ void usage(const char* progName) printf(" -h give this help\n"); printf(" -V Version number\n"); printf("\nCommands:\n"); - printf(" program -> " + printf(" program -> " "program bit-file to flash-memory\n"); - printf(" verify -> " + printf(" verify -> " "compare bit-file with flash-memory\n"); - printf(" backup -> " + printf(" backup -> " "write entire flash-memory to raw-file\n"); - printf(" restore -> " + printf(" restore -> " "write backuped raw-file to flash-memory\n"); - printf(" info -> " + printf(" info -> " "dump content of info-page to stdout\n"); - printf(" dumppage pagenumber -> " + printf(" dumppage pagenumber -> " "dump one flash-memory page to stdout\n"); + printf(" flash_at_page -> " + "program a binary file to flash-memory,\n" + " " + "beginning at page \n" + ); } int main(int argc, char** argv) @@ -1414,16 +1419,75 @@ 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) { /*********************************************************/ @@ -1477,7 +1541,7 @@ int main(int argc, char** argv) 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); } @@ -1603,12 +1667,12 @@ int main(int argc, char** argv) 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); } }