]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
new program procedure: first program the hole chip, then verify
authorhadaq <hadaq>
Fri, 23 Jul 2010 21:22:44 +0000 (21:22 +0000)
committerhadaq <hadaq>
Fri, 23 Jul 2010 21:22:44 +0000 (21:22 +0000)
trbrich/trbflash.c

index 28cf6d74b2753994ae6b68ec00c648ced3b032e5..9e9661414e05962170231fcfcbf2a11c09fa1c19 100644 (file)
@@ -97,7 +97,7 @@ static const char FlashTypeStr[16][32] =
 
 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;
 
@@ -467,8 +467,7 @@ static int initTransfer(uint16_t trb_address)
   default:
     abort();
   }
-  
-    
+      
   NUM_BLOCKS = (NUM_PAGES * PAGE_SIZE) / BLOCK_SIZE;
   
   /* Buffer holding the entire rom-image */
@@ -610,9 +609,12 @@ typedef enum {
   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;
@@ -627,12 +629,14 @@ static int programImageBuffer(uint16_t trb_address, unsigned int size,
     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]);
     }
     
@@ -644,19 +648,21 @@ static int programImageBuffer(uint16_t trb_address, unsigned int size,
   }
   
   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"
@@ -677,9 +683,8 @@ static int programImageBuffer(uint16_t trb_address, unsigned int size,
     
   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); 
     }
@@ -741,6 +746,8 @@ static int programImageBuffer(uint16_t trb_address, unsigned int size,
            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) {
@@ -763,6 +770,7 @@ static int programImageBuffer(uint16_t trb_address, unsigned int size,
           return -1;
         }
       }
+      
       if ((manId == 0x01461f) || 
           (manId == 0x00471f)) {
         /* Enable writing */
@@ -774,75 +782,74 @@ static int programImageBuffer(uint16_t trb_address, unsigned int size,
         /* 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]);
+            }
           }
         }
       }
@@ -1237,10 +1244,14 @@ int main(int argc, char ** argv)
     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) {
     
     /*********************************************************/
@@ -1296,7 +1307,7 @@ int main(int argc, char ** argv)
     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);
     }
     
@@ -1423,7 +1434,7 @@ int main(int argc, char ** argv)
     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);
     }