]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/mcsdk-tools.git/blobdiff - writer/nand/src/nandwriter.c
writer: Update nand and nor writer to not do phy init
[keystone-rtos/mcsdk-tools.git] / writer / nand / src / nandwriter.c
index 83da16036a2546afc9b4fb0f4da758734f4899be..f1baba6c6d070100f12f40a873bad7a427af9963 100755 (executable)
@@ -47,7 +47,7 @@
 #include "types.h"
 
 /* NAND writer utility version */
-char version[] = "01.00.00.01";
+char version[] = "01.00.00.04";
 
 /* The input file name is hard coded */
 char *input_file = "nand_writer_input.txt";
@@ -58,6 +58,8 @@ volatile uint32_t nand_erase_flag = 0;
 /* Parameters defined in the input_file */
 #define FILE_NAME      "file_name"
 #define START_ADDR     "start_addr"
+#define RBL_ECC        "rbl_ecc"
+#define SKIP_BAD       "skip_bad"
 
 /* Memory address to store the write data */
 #define WRITE_DATA_ADDRESS     0x80000000
@@ -79,6 +81,8 @@ typedef struct NAND_WRITER_INFO_tag
     uint32_t    deviceTotalBytes;           /* Total number of bytes available in the device */
     uint32_t    startAddr;                  /* Start address to write */
     uint32_t    writeBytes;                 /* Number of bytes to be written into the device */
+    uint8_t     flags;                      /* Flag used for EVMK2H for multiple ECC formats */
+    uint8_t     skip_bad_blks;              /* Flag used to skip bad blocks */
     uint8_t     *writeData;                 /* Address to store the write data */
     uint8_t     *readData;                  /* Address to store the read data */
 
@@ -224,6 +228,8 @@ flash_nand
     uint32_t      wPos, wLen;
     uint32_t      block, start_block;
     uint8_t       *scrach_block;
+    uint32_t      num_blks;
+    uint32_t      bad_block_found;
 
     if (swap_byte)
     {
@@ -237,6 +243,30 @@ flash_nand
 
     start_block = nandWriterInfo.startAddr / nandWriterInfo.blockSizeBytes;
 
+    /* skip the bad blocks if the flag is set */
+    if (nandWriterInfo.skip_bad_blks)
+    {
+       num_blks = nandWriterInfo.writeBytes / nandWriterInfo.blockSizeBytes;
+       if ((nandWriterInfo.writeBytes - nandWriterInfo.blockSizeBytes * num_blks) > 0)
+               num_blks++;
+
+       while (TRUE)
+       {
+               bad_block_found = FALSE;
+               for (block = start_block; block < start_block + num_blks; block++)
+               {
+                       if (checkBadBlockMark(p_device, block))
+                       {
+                               start_block = block + 1;
+                               bad_block_found = TRUE;
+                               break;
+                       }
+               }
+               if (bad_block_found == FALSE)
+                       break;
+       }
+    }
+
     /* Program the NAND */
     for (block = start_block, wPos = 0; wPos < nandWriterInfo.writeBytes; block++, wPos += nandWriterInfo.blockSizeBytes)
     {
@@ -434,6 +464,33 @@ parse_input_file
     }
 
     nandWriterInfo.startAddr = (uint32_t)atoi(data);
+    
+    fgets(line, MAX_LINE_LENGTH, fp);
+    key = (char *)strtok(line, tokens);
+    data = (char *)strtok(NULL, tokens);
+    
+    if(strlen(data) != 0 && (strcmp(key, RBL_ECC) == 0))
+    {
+        nandWriterInfo.flags = (uint8_t)atoi(data);
+    }
+    else
+    {
+        nandWriterInfo.flags = 0;
+    }
+
+    /* Scan skip bad block input parameter */
+    fgets(line, MAX_LINE_LENGTH, fp);
+    key = (char *)strtok(line, tokens);
+    data = (char *)strtok(NULL, tokens);
+
+    if(strlen(data) != 0 && (strcmp(key, SKIP_BAD) == 0))
+    {
+        nandWriterInfo.skip_bad_blks = (uint8_t)atoi(data);
+    }
+    else
+    {
+        nandWriterInfo.skip_bad_blks = 0;
+    }
 
     return TRUE;
 }
@@ -544,16 +601,21 @@ void main ()
     memset(&init_flags, 1, sizeof(platform_init_flags));
     init_flags.pll = 0;
     init_flags.ddr = 0;
+    init_flags.phy =0;
     if (platform_init(&init_flags, &init_config) != Platform_EOK)
     {
         printf ("Platform init failed!\n");
         print_platform_errno();
         return;
     }
-#if !(defined(_EVMC6657L_))
-    p_device = platform_device_open(PLATFORM_DEVID_NAND512R3A2D, 0);
+#if (defined(_EVMC6657L_) || defined(DEVICE_K2H))
+     p_device = platform_device_open(PLATFORM_DEVID_MT29F1G08ABCHC, nandWriterInfo.flags);
+#elif defined(DEVICE_K2E)
+     p_device = platform_device_open(PLATFORM_DEVID_MT29F4G08ABADA, nandWriterInfo.flags);
+#elif defined(DEVICE_K2L)
+     p_device = platform_device_open(PLATFORM_DEVID_MT29F16G08ADBCAH4C, nandWriterInfo.flags);
 #else
-    p_device = platform_device_open(PLATFORM_DEVID_MT29F1G08ABCHC, 0);
+    p_device = platform_device_open(PLATFORM_DEVID_NAND512R3A2D, 0);
 #endif
     if (p_device == NULL) 
     {
@@ -607,7 +669,7 @@ void main ()
         platform_device_close(p_device->handle);
         return;
     }
-
+    
     /* Write the flash, verify the results. On read back failure mark
      * the block as bad and try rewriting again */
     rCount = 0;