nandwriter: add new input parameter to skip bad nand blocks DEV.MCSDK-03.01.00.02
authorHao Zhang <hzhang@ti.com>
Thu, 5 Jun 2014 20:36:50 +0000 (16:36 -0400)
committerHao Zhang <hzhang@ti.com>
Thu, 5 Jun 2014 20:36:50 +0000 (16:36 -0400)
The new parameter is introduced due to an RBL bug in k2l and k2e
devices that EMIF16 NAND boot can only boot an image burnt in
countinuous good nand blocks.

writer/nand/evmk2e/bin/nand_writer_input.txt [changed mode: 0644->0755]
writer/nand/evmk2h/bin/nand_writer_input.txt
writer/nand/evmk2l/bin/nand_writer_input.txt [changed mode: 0644->0755]
writer/nand/src/nandwriter.c

old mode 100644 (file)
new mode 100755 (executable)
index 340b140..2ea56cb
@@ -1,6 +1,6 @@
 file_name  = app.bin
 start_addr = 0
 rbl_ecc    = 0
-
+skip_bad   = 1
 
 
index 340b140cd137db7127562279d8ae48827f4d6f65..ec82083bc6e29d83e7d2253f28a71f80defe12fa 100755 (executable)
@@ -1,6 +1,6 @@
 file_name  = app.bin
 start_addr = 0
 rbl_ecc    = 0
-
+skip_bad   = 0
 
 
old mode 100644 (file)
new mode 100755 (executable)
index 340b140..2ea56cb
@@ -1,6 +1,6 @@
 file_name  = app.bin
 start_addr = 0
 rbl_ecc    = 0
-
+skip_bad   = 1
 
 
index 72dfc37c2d7a06e59badaf3cba781c9010a06364..f474d5aaaac46538329916c49c00064005e321fb 100755 (executable)
@@ -47,7 +47,7 @@
 #include "types.h"
 
 /* NAND writer utility version */
-char version[] = "01.00.00.03";
+char version[] = "01.00.00.04";
 
 /* The input file name is hard coded */
 char *input_file = "nand_writer_input.txt";
@@ -59,6 +59,7 @@ volatile uint32_t nand_erase_flag = 0;
 #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
@@ -81,6 +82,7 @@ typedef struct NAND_WRITER_INFO_tag
     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 */
 
@@ -226,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)
     {
@@ -239,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)
     {
@@ -450,6 +478,20 @@ parse_input_file
         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;
 }