1. 修改driver/mtd/nand/Kconfig:
在
--------------------------------------------------
config MTD_NAND_OMAP_HW
--------------------------------------------------
上一行添加
--------------------------------------------------
config MTD_NAND_OMAP_OSK
tristate "NAND Flash device on OSK5912 board"
depends on ARM && ARCH_OMAP1 && MTD_NAND && MACH_OMAP_OSK
help
Support for NAND flash on Texas Instruments OSK5912 platforms.
--------------------------------------------------
2. 修改driver/mtd/nand/Makefile:
在
--------------------------------------------------
obj-$(CONFIG_MTD_NAND_OMAP_HW) += omap-hw.o
--------------------------------------------------
上一行添加
--------------------------------------------------
obj-$(CONFIG_MTD_NAND_OMAP_OSK) += osk-nand-flash.o
--------------------------------------------------
3. 执行make menuconfig;
标记
--------------------------------------------------
[*] device driver->MTD->NAND->"NAND Flash support"
[M] device driver->MTD->NAND->"NAND Flash device on OSK5912 board"
--------------------------------------------------
4. 新建驱动文件osk-nand-flash.c在driver/mtd/nand下。
5. 修改文件arch/arm/mach-omap1/board-osk.c内容:
添加
--------------------------------------------------
#include <linux/mtd/nand.h>
......
......
#define OSK_NAND_BASEADDR 0x05000000 //Reading/writing to this address will issue a data access to NFMC
......
......
static struct nand_platform_data osk5912_nand_data = {
.options = NAND_ST_SP_OPTIONS,
};
static struct resource osk5912_nand_resource = {
.start = OSK_NAND_BASEADDR,
.end = OSK_NAND_BASEADDR+ SZ_4K - 1, //In fact it doesn't need SZ_4K so much space, SZ_4B is OK
.flags = IORESOURCE_MEM,
};
static struct platform_device osk5912_nand_device = {
.name = "osknand",
.id = 0,
.dev = {
.platform_data = &osk5912_nand_data,
},
.num_resources = 1,
.resource = &osk5912_nand_resource,
};
...... ......
static struct platform_device *osk5912_devices[] __initdata = {
&osk5912_flash_device,
&osk5912_nand_device, //add for NAND
&osk5912_smc91x_device,
&osk5912_cf_device,
&osk5912_mcbsp1_device,
};
--------------------------------------------------
6. 修改文件include/linux/mtd/nand.h内容:
--------------------------------------------------
/* Options valid for ST small page devices */
#define NAND_ST_SP_OPTIONS /
(NAND_NO_AUTOINCR | NAND_NO_PADDING | NAND_COPYBACK | NAND_NO_READRDY)
--------------------------------------------------
7. make menuconfig时候disable PCMCIA,因为我们的NAND FLASH占用CS1 bank,和PCMCIA冲突。
参考:
--------------------------------------------------
drivers/pcmcia/omap_cf.c: cf->phys_cf = OMAP_CS1_PHYS;
--------------------------------------------------
8. 重新编译,生成drivers/mtd/nand/osk-nand-flash.ko,复制到rootfs中。启动kernel后,运行
--------------------------------------------------
oskboard#insmod osk-nand-flash.ko
--------------------------------------------------
系统提示:
--------------------------------------------------
Using root/osk-nand-flash.ko
NAND device: Manufacturer ID: 0x20, Chip ID: 0x76 (ST Micro NAND 64MiB 3,3V 8-bit)
Scanning device for bad blocks
Bad eraseblock 1107 at 0x0114c000
--------------------------------------------------
9. 查看设备信息:
执行命令:
--------------------------------------------------
oskboard#cat /proc/mtd
--------------------------------------------------
得到如下信息:
--------------------------------------------------
dev: size erasesize name
mtd0: 00020000 00020000 "bootloader"
mtd1: 00020000 00020000 "params"
mtd2: 00200000 00020000 "kernel"
mtd3: 01dc0000 00020000 "filesystem"
mtd4: 04000000 00004000 "osknand.0"
--------------------------------------------------
执行命令:
--------------------------------------------------
oskboard#cat /proc/partitions
--------------------------------------------------
得到如下信息:
--------------------------------------------------
major minor #blocks name
31 0 128 mtdblock0
31 1 128 mtdblock1
31 2 2048 mtdblock2
31 3 30464 mtdblock3
31 4 65536 mtdblock4
--------------------------------------------------
10. 建立设备节点:
在/dev目录下执行命令
--------------------------------------------------
# mknod -m 666 mtd4 c 90 8
# mknod -m 666 mtdblock4 b 31 4
--------------------------------------------------
11. 下载mtd-utils-1.0.0.tar.gz工具包from http://www.linux-mtd.infradead.org/。修改Makefile:
--------------------------------------------------
#CC := $(CROSS)gcc
--------------------------------------------------
为
--------------------------------------------------
CC := $(CROSS)gcc
--------------------------------------------------
编译出来flash_erase,flash_eraseall,nandwrite工具。
12.在osk-linux下执行
./flash_eraseall -j /dev/mtd4
把nand按照jffs2格式erase;
至此,NAND flash已经可以以JFFS2格式被mount上去了。执行
# mount -t jffs2 /dev/mtdblock4 /mnt
然后在/mnt目录下建立文件testfile,umount该设备后再次mount,仍然能正常读出文件内容。
如果想把现成的目录结构直接做成JFFS2格式的image复制到NAND设备上(例如,制作rootfs时),参考下面方法:
方法一:
1. 使用工具制作jffs2格式的image:
#./mkfs.jffs2.x86 -l -p 0x200 -s 0x200 -e 0x4000 -d rootdir/ -o target.jffs2
执行#./mkfs.jffs2.x86 -h可以查看参数含义。
如果没有mkfs.jffs2工具,可以在上一步中生成,注意编译工具是gcc。
2. 在osk-linux下执行
./nandwrite -o /dev/mtd4 target.jffs2
把image写入flash。
这种方法可能需要调整参数设置才能OK。我使用的时候mount正常,读取文件内容就出错了。
方法二:
使用NFS时候,在PC端tar整个目录为target.tar.gz放到$(rootfs)下;
mount -t jffs2 /dev/mtdblock4 /mnt
cd /mnt
tar xvzf ../target.tar.gz
umount /mnt
附录I:
NAND驱动中option的解释:
NAND_NO_AUTOINCR
Most of the 1st generation chips (256/512 byte pagesize) have this
feature. It's important to be aware of this.
After reading a page, those chips are automatically transferring the
next page into the read buffer.
The 2nd generation chips (2K pagesize and a couple of the newer 512byte
pagesize chips) do not have this feature, so you must explicitely issue
a new page read command to get the next page data.
NAND_NO_PADDING
Device supports partial programming without padding(指partial program时候芯片是否自动把未写的地方填充0xFF)
附录II:
QUESTION:
============================================================================
nand_base.c L2290是否应该被修改?
/* Check if chip is a not a samsung device. Do not clear the
* options for chips which are not having an extended id.
*/
if (*maf_id != NAND_MFR_SAMSUNG && !type->pagesize)
chip->options &= ~NAND_SAMSUNG_LP_OPTIONS;
============================================================================
ecc由谁解释?
http://www.aoc.nrao.edu/~tjuerges/ALMA/Kernel/mtdnand/ch05s04.html
============================================================================
附录III:
make menuconfig时候部分macro含义:
============================================================================
.config中
#
# NAND Flash Device Drivers
#
# CONFIG_MTD_NAND is not set
编译omap-nand-flash.c的条件是CONFIG_MTD_NAND_OMAP
原来的Config.in在2.6中变成了Kconfig。
Verify NAND page writes (NEW)
其实就是在nand_base.c中nand_write()中每次写入后都重新read一遍做比较,相信性能一定下降的很快。
nandsim.c
Nokia开发的模拟NAND设备,默认是Toshiba NAND 8MiB 1,8V 8-bit(根据ManufactureID)
附录IV:
u-boot和linux kernel image中对osk5912 ID的匹配问题
http://linux.omap.com/pipermail/linux-omap-open-source/2004-October/001999.html
u-boot下的命令bdinfo可以show arch_number;
Linux下arch/arm/tools/mach-types中记录板子的number,二者需要匹配。