关于linux nand 驱动调试的一些注意点

来源:互联网 发布:ubuntu中的火狐浏览器 编辑:程序博客网 时间:2024/06/05 10:27

关于linux nand 驱动调试的一些注意点

点击打开链接

 

最近在开发 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 也可以解决问题。

 

烧录 yaffs2 image

 

PC 上先制作一个 yaffs2 image:

./mkyaffs2image ./rootfs_initramfs rootfs_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 to 0xff */

                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了!

0 0
原创粉丝点击