继前一天移植的情况,运行后发现:
Flash: 2 MiB
NAND: 0 MiB
说明Nand flash没有移植成功,在文件drivers/mtd/nand/s3c2440_nand.c 中发现board_nand_init函数中:
nand->select_chip = NULL
选择芯片函数为NULL,我们在board_nand_init函数上面加上s3c2440_nand_select函数,代码如下:
static void s3c2440_nand_select(struct mtd_info *mtd, int chipnr) { struct s3c2440_nand *nand = s3c2440_get_base_nand(); switch(chipnr){ case -1: /* 取消选中 */ nand->nfcont |= (1<<1); break; case 0: /* 选中 */ nand->nfcont &= ~(1 << 1); break; default: BUG(); } return; }
再将board_nand_init函数中的select_chip改为:
nand->select_chip = s3c2440_nand_select;
重新编译运行:
Flash: 2 MiB NAND: 64 MiB
tq2440的nand flash的大小是为64M,说明nandflash被成功探测到了。
下面进行读写测试:
测试之前先将nand flash擦除一遍:
[TQ2440 #] nand erase 0 4000000
从服务器上下载test文件,放在0x31000000地址处。
[TQ2440 #] tftp 31000000 test
查看0x31000000地址处的内容:
[TQ2440 #] md 31000000 31000000: 34333231 38373635 0a0a3039 00000000 1234567890...... 31000010: 00000000 00000000 00000000 00000000 ................
将0x31000000地址处的内容写到nand flash的0地址处:
[TQ2440 #] nand write 31000000 0 ff NAND write: device 0 offset 0x0, size 0xff 255 bytes written: OK [TQ2440 #]
说明些是成功的。
再将其读到0x31000000地址处下面读操作:
[TQ2440 #] nand read 31000000 0 ff NAND read: device 0 offset 0x0, size 0xff 255 bytes read: OK
说明读也是OK的,比较前后读写的内容是否一样:
[TQ2440 #] md 31000000 31000000: 34333231 38373635 0a0a3039 00000000 1234567890......
说明Nand flash移植OK。
下图为tq2440开发板上的nand flash,页、块和设备之间的关系,以及oob区:
从图中可以看出一页的大小为512bytes,oob的大小为16字节,可以使用nand dump命令查看。
首先擦除一个块,因为nand flash只能0不能写1,所以擦除的操作就是讲页和oob区中的字节都置为1,如下
[TQ2440 #] nand erase 0 ff
[TQ2440 #] nand dump 0
Page 00000000 dump:
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
OOB:
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
绿色部分为一页大小,512bytes,红色部分为oob区,16bytes。擦除后的第一个页和oob区的字节都为ff。
在SDRAM中0x3100 0000起始位置后的10个字节为0~9的ASCII值,我们将其写入Nand flash的第一个页中去。
[TQ2440 #] md 31000000
31000000: 34333231 38373635 0a0a3039 00000000 1234567890......
31000010: 00000000 00000000 00000000 00000000 ................
写入16个字节:
[TQ2440 #] nand write 31000000 0 10
[TQ2440 #] nand dump 0
Page 00000000 dump:
31 32 33 34 35 36 37 38 39 30 0a 0a 00 00 00 00
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
OOB:
aa a5 ab ff ff ff ff ff
ff ff ff ff ff ff ff ff
可以看到第一个页中已经保存了0~9的ASCII值,多写了0a0a不用管。
明天继续。