]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
added feature to write binary data to flash, beginning with arbitrary page
authorMaps <maps@ikf>
Thu, 9 Jul 2015 15:48:26 +0000 (17:48 +0200)
committerMaps <maps@ikf>
Thu, 9 Jul 2015 15:48:26 +0000 (17:48 +0200)
libtrbnet/trbflash.c

index 6e9239397e0f8f111c111716ca0f45b240062756..3f40b825a86b90a50032e93c6d58704d5eaa7e91 100644 (file)
@@ -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 <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)
@@ -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);
       }
     }