關於linux nand 驅動調試的一些注意點

關於linux nand 驅動調試的一些注意點

作者: zjujoe 轉載請註明出處

Email:[email protected]

BLOG:http://blog.csdn.net/zjujoe

 

最近在開發 nand驅動, 不可避免的, 用到了 nand tools. 這裏將一些細節記錄下來。網上google 的內容好像也不是很多。Nand tools(mtdutils1.2)似乎也有些難用。

注意我目前使用的是linux2.6.25內核, mtdutils 1.2

 

燒錄普通image(沒有使用到oob數據)

flash_eraseall /dev/mtd1

nandwrite /dev/mtd1 ./zImage

注意這裏的 image 必須 block 對齊, 否則, nandwrite 會抱怨:

Input file is not page aligned

Data was only partially written due to error

 

燒錄 jffs2 image

先製作好jffs2 image, 比如:(這裏暫不使用 sumtool)

sudo ./mkjffs2   -n -s 2048 -p 2048 -e 0x20000 -r rootfs_initramfs  -o rootfs_initramfs.jffs2

 

然後通過某種方式, 比如 T  卡或者 cifs, 放入嵌入式環境。目標板上執行:

flash_eraseall  -j /dev/mtd3

nandwrite  /dev/mtd3 ./rootfs_initramfs.jffs2

 

注意這裏 nandwrite 不要使用 –j 參數,從help 上看, 該參數已經過時。(至於爲什麼不需要了, 還沒有研究。)

 

另外,就是 flash_eraseall 要求第一個 free 的 oob 數據區其大小要超過8(jffs2 的 cleanmarker 大小爲8),像我原來的驅動裏:

static struct nand_ecclayout comip_lb_nand_oob ={

       .eccbytes = 12,

       .eccpos = {

                  8, 9, 10, 24, 25, 26,

                  40, 41, 42, 56, 57, 58},

       .oobfree = {{1, 7},{11, 13}, {27, 13}, {43, 13}, {59, 5} }

};

 

用 nanddump 抓出數據,會發現 BIT 8 被 cleanmarker 最後一個字節 overwrite 了。

需要改爲:

static struct nand_ecclayout comip_lb_nand_oob ={

       .eccbytes = 12,

       .eccpos = {

                  8, 9, 10, 24, 25, 26,

                  40, 41, 42, 56, 57, 58},

       .oobfree = {{11, 13}, {27, 13}, {43, 13}, {59, 5}, {1, 7}}

};

 

當然, 如果修改 flash_eraseall.c 也可以解決問題。

 

燒錄 yaffs2image

 

PC 上先製作一個 yaffs2 image:

./mkyaffs2image ./rootfs_initramfsrootfs_initramfs.yaffs2

 

然後燒錄到目標板上:

flash_eraseall /dev/mtd3

nandwrite   -a -o/dev/mtd3 rootfs_initramfs.yaffs2

 

mount 不能成功!

而如果只是擦除,然後直接mount,讀寫文件時沒有問題的。

使用nanddump 取出二進制數據, 發現 oob 數據有問題!

分析nandwrite的代碼, 原來寫oob數據的代碼不正確:(或

許是因爲開發nandwrite後底層代碼發生了變動。)

#if 0

for (i = 0; old_oobinfo.oobfree[i][1];i++) {

       /* Set the reserved bytes to 0xff */

       start = old_oobinfo.oobfree[i][0];

       len = old_oobinfo.oobfree[i][1];

       memcpy(oobbuf + start, oobreadbuf + start, len);

}

#else

{

       int totallen = 28;

       int offset = 0;

       memset(oobbuf, 0xFF, 64);

       for (i = 0; old_oobinfo.oobfree[i][1]; i++) {

                /* Set the reserved bytes to0xff */

                start = old_oobinfo.oobfree[i][0];

                len =old_oobinfo.oobfree[i][1];

 

                if (len >= totallen)

                        len = totallen;

                totallen -= len;

                memcpy(oobbuf + start,oobreadbuf + offset, len);

               if (totallen == 0)

                        break;

                offset += len;

       }

}

#endif

 

修改以後, 用 nandwrite 寫入 yaffs2 image, 就可以正常mount了!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章