]> git.sur5r.net Git - openocd/commitdiff
Made BI-swap optional in mxc.
authorErik Ahlén <erik.ahlen@avalonenterprise.com>
Tue, 13 Dec 2011 10:39:52 +0000 (11:39 +0100)
committerSpencer Oliver <spen@spen-soft.co.uk>
Fri, 23 Dec 2011 09:39:48 +0000 (09:39 +0000)
Change-Id: Ibdf3b1e415adcf1fdb38de25fe05da726ef58ca4
Signed-off-by: Erik Ahlén <erik.ahlen@avalonenterprise.com>
Reviewed-on: http://openocd.zylin.com/269
Tested-by: jenkins
Reviewed-by: Mathias Küster <kesmtp@freenet.de>
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
src/flash/nand/mx2.c
src/flash/nand/mx2.h
tcl/board/tx27_stk5.cfg

index ef1942216ed582bca6879b2e5bbdec66b05e3ead..e3647385cebb784dd12481a00d76bc4b39238fca 100644 (file)
@@ -87,7 +87,7 @@ NAND_DEVICE_COMMAND_HANDLER(mxc_nand_device_command)
        nand->controller_priv = mxc_nf_info;
 
        if (CMD_ARGC < 4) {
-               LOG_ERROR("use \"nand device mxc target mx27|mx31|mx35 noecc|hwecc\"");
+               LOG_ERROR("use \"nand device mxc target mx27|mx31|mx35 noecc|hwecc [biswap]\"");
                return ERROR_FAIL;
        }
 
@@ -115,6 +115,15 @@ NAND_DEVICE_COMMAND_HANDLER(mxc_nand_device_command)
        mxc_nf_info->flags.target_little_endian =
        (nand->target->endianness == TARGET_LITTLE_ENDIAN);
 
+       /*
+        * should factory bad block indicator be swaped
+        * as a workaround for how the nfc handles pages.
+        */
+       if (CMD_ARGC > 4 && strcmp(CMD_ARGV[4], "biswap") == 0) {
+               LOG_DEBUG("BI-swap enabled");
+               mxc_nf_info->flags.biswap_enabled = 1;
+       }
+
        /*
         * testing host endianness
         */
@@ -414,18 +423,21 @@ static int mxc_write_page(struct nand_device *nand, uint32_t page,
                }
                target_write_buffer(target, MXC_NF_SPARE_BUFFER0, oob_size,     oob);
        }
-       /* BI-swap -  work-around of mxc NFC for NAND device with page == 2kb */
-       target_read_u16(target, MXC_NF_MAIN_BUFFER3 + 464, &swap1);
-       if (oob) {
-               LOG_ERROR("Due to NFC Bug, oob is not correctly implemented in mxc driver");
-               return ERROR_NAND_OPERATION_FAILED;
+
+       if (nand->page_size > 512 && mxc_nf_info->flags.biswap_enabled) {
+               /* BI-swap - work-around of i.MX NFC for NAND device with page == 2kb*/
+               target_read_u16(target, MXC_NF_MAIN_BUFFER3 + 464, &swap1);
+               if (oob) {
+                       LOG_ERROR("Due to NFC Bug, oob is not correctly implemented in mxc driver");
+                       return ERROR_NAND_OPERATION_FAILED;
+               }
+               swap2 = 0xffff;  /* Spare buffer unused forced to 0xffff */
+               new_swap1 = (swap1 & 0xFF00) | (swap2 >> 8);
+               swap2 = (swap1 << 8) | (swap2 & 0xFF);
+               target_write_u16(target, MXC_NF_MAIN_BUFFER3 + 464, new_swap1);
+               target_write_u16(target, MXC_NF_SPARE_BUFFER3 + 4, swap2);
        }
-       swap2 = 0xffff;  /* Spare buffer unused forced to 0xffff */
-       new_swap1 = (swap1 & 0xFF00) | (swap2 >> 8);
-       swap2 = (swap1 << 8) | (swap2 & 0xFF);
 
-       target_write_u16(target, MXC_NF_MAIN_BUFFER3 + 464, new_swap1);
-       target_write_u16(target, MXC_NF_SPARE_BUFFER3 + 4, swap2);
        /*
         * start data input operation (set MXC_NF_BIT_OP_DONE==0)
         */
@@ -553,13 +565,16 @@ static int mxc_read_page(struct nand_device *nand, uint32_t page,
                LOG_ERROR("MXC_NF : Error reading page 3");
                return retval;
        }
-       /* BI-swap -  work-around of mxc NFC for NAND device with page == 2k */
-       target_read_u16(target, MXC_NF_MAIN_BUFFER3 + 464, &swap1);
-       target_read_u16(target, MXC_NF_SPARE_BUFFER3 + 4, &swap2);
-       new_swap1 = (swap1 & 0xFF00) | (swap2 >> 8);
-       swap2 = (swap1 << 8) | (swap2 & 0xFF);
-       target_write_u16(target, MXC_NF_MAIN_BUFFER3 + 464, new_swap1);
-       target_write_u16(target, MXC_NF_SPARE_BUFFER3 + 4, swap2);
+
+       if (nand->page_size > 512 && mxc_nf_info->flags.biswap_enabled) {
+               /* BI-swap -  work-around of mxc NFC for NAND device with page == 2k */
+               target_read_u16(target, MXC_NF_MAIN_BUFFER3 + 464, &swap1);
+               target_read_u16(target, MXC_NF_SPARE_BUFFER3 + 4, &swap2);
+               new_swap1 = (swap1 & 0xFF00) | (swap2 >> 8);
+               swap2 = (swap1 << 8) | (swap2 & 0xFF);
+               target_write_u16(target, MXC_NF_MAIN_BUFFER3 + 464, new_swap1);
+               target_write_u16(target, MXC_NF_SPARE_BUFFER3 + 4, swap2);
+       }
 
        if (data)
                target_read_buffer(target, MXC_NF_MAIN_BUFFER0, data_size, data);
index c0e7d6b28ba0a89558f4665e8b3127620d40c299..77854b953b7b8973878f09fb5604ce7e2b427d6b 100644 (file)
@@ -107,6 +107,7 @@ struct mxc_nf_flags {
        unsigned nand_readonly:1;
        unsigned one_kb_sram:1;
        unsigned hw_ecc_enabled:1;
+       unsigned biswap_enabled:1;
 };
 
 struct mxc_nf_controller {
index 5887ac694c824d66a1f494604036f74ee0654344..bb933e149d39f7e6be83e17d0ae1bddb29f459e9 100644 (file)
@@ -61,4 +61,4 @@ proc tx27_init { } {
        nand probe 0
 }
 
-nand device tx27.nand mxc $_TARGETNAME mx27 hwecc
+nand device tx27.nand mxc $_TARGETNAME mx27 hwecc biswap