The Linux MTD, YAFFS Howto

本文深入解析了Linux MTD NAND Flash驱动的实现细节,包括eosnand_init()函数中设备I/O设置的过程,eosnand_hwcontrol()函数如何控制NAND Flash的使能与禁用及忙碌状态检查,以及nand_scan()函数中如何读取制造商标识和设备标识等关键步骤。此外还展示了如何进行NAND Flash分区配置。
1 The Linux MTD, YAFFS Howto
User ProgramSystem Call InterfaceBlock Device InterfaceFIle System(jffs,yaffs)Virtual File SystemMTD Driver ModuleNAND FLASH MEMORYMTD ModuleUser ModuleDriver Module
Picture 1-1 MTD System Organization
1.1 MTD Nand Device Driver
Modify drivers/mtd/nand/nand.c and eos_nand.c(Copy spia.c).
int __init eosnand_init (void)
{
struct nand_chip *this;
*(volatile unsigned char *) 0x1ff00010 = 0x82; // Pin Mux Control Register set
eos_writel(0x33002, NFMCON); // Nand Flash Memory Control Register set

this = (struct nand_chip *) (&eosnand_mtd[1]);

this->hwcontrol = eosnand_hwcontrol; // Device I/O Set
this->chip_delay = 15; // delay set
this->eccmode = NAND_ECC_SOFT; // ECC Use Set.
// target nand flash ID search
if (nand_scan (eosnand_mtd)) {
kfree (eosnand_mtd);
return -ENXIO;
}
// initialized eosnand_mtd registration
add_mtd_partitions(eosnand_mtd, partition_info, NUM_PARTITIONS);
return 0;
}
Code 1-1 eosnand_init()
EOS Nand Flash Device I/O Setup Function
Void eosnand_hwcontrol(int cmd)
{
switch(cmd){
case NAND_CTL_CLRNCE: // Nand Flash Enable
eos_writel(eos_readl(NFMCON) & ~0x02, NFMCON);
case NAND_CTL_SETNCE: // Nand Flash Disable
eos_writel(eos_readl(NFMCON) | 0x02, NFMCON);
case NAND_CTL_CHKRB: // Nand Flash busy check
{
int temp;
while(1) {
temp = eos_readb(NFMSTAT);
temp &= 0x01;
if (temp) break;
}
}
}
}
#define nand_select() this->hwcontrol(NAND_CTL_SETNCE);
#define nand_deselect() this->hwcontrol(NAND_CTL_CLRNCE);
#define nand_busy() this->hwcontrol(NAND_CTL_CHKRB);
Code 1-2 eosnand_hwcontrol()
Next, Manufacture ID read and additional hardware initializing function.
int nand_scan (struct mtd_info *mtd)
{
int i, nand_maf_id, nand_dev_id;
struct nand_chip *this = mtd->priv;
// check for proper chip_delay setup, set 20us if not
if (!this->chip_delay) this->chip_delay = 20;
// check, if a user supplied command function given
if (this->cmdfunc == NULL)
this->cmdfunc = nand_command;

nand_select(); // Nand Chip Enable
// Function to read Device ID.
this->cmdfunc (mtd, NAND_CMD_READID, 0x00, -1);
// Manufacture ID and Device ID read.
nand_maf_id = eos_readb (NFMDATA);
nand_dev_id = eos_readb (NFMDATA);
// Save Device information.
for (i = 0; nand_flash_ids[i].name != NULL; i++) {
if (nand_dev_id == nand_flash_ids[i].id && !mtd->size) { … }
}

nand_deselect (); // Nand Chip Disable

mtd->erase = nand_erase;
mtd->read = nand_read;
mtd->write = nand_write;
return 0;
}
Code 1-3 nand_scan()
Raw level functions of nand_erase, nand_read, nand_write are already implemented in nand.c. So, Eos only modify writeb and readb.
For example,
writeb (command, NAND_IO_ADDR); -> eos_writeb (command, NFMCMD);
readb (this->IO_ADDR_R); -> eos_readb(NFMDATA);
Next code is NAND Flash Partition setup.
// 0M ~ 3M : nand code + bootloader + ramdisk + kernel
// 3M ~ 5M : Root FileSystem(YAFFS)
// 5M ~ 8M : User Space
const static struct mtd_partition partition_info[] = {
{
.name = "Root FileSystem(YAFFS)",
.offset = 3*1024*1024,
.size = 2*1024*1024
},
{
.name = "User Space",
.offset = 5*1024*1024,
.size = 3*1024*1024
}
};
#define NUM_PARTITIONS 2
Code 1-4 Nand Flash Partition Setup.
Add eos_nand.c in Makefile.
obj-$(CONFIG_MTD_NAND_EOS) += eos_nand.o
include/config/arch/eos.h
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值