分享
 
 
 

The Linux MTD, YAFFS Howto

王朝system·作者佚名  2006-03-10
窄屏简体版  字體: |||超大  

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 ?? #define CONFIG_ARCH_EOS 1.

drivers/mtd/nand/Config.in

if [ "$CONFIG_ARCH_EOS" = "y" ]; then

dep_tristate 'NAND Flash device on EOS board' CONFIG_MTD_NAND_EOS $CONFIG_MTD_NAND

fi

Kernel Compile Selection.

Memory Technology Device (MTD) --->

[*] Memory Technology Device (MTD) support

[*] MTD partitioning support

[*] Direct char device access to MTD devices

[*] Caching block device access to MTD devices

NAND Flash Device Drivers --->

[*] NAND Device Support

[*] NAND Flash device on EOS board

File systems --->

[*] Yaffs filesystem on NAND

1.2 Including yaffs as a kernel fs.

NAND flash is cheap and has a fast erase time as compared with NOR flash. The NAND physical interface is very simple. The small size and low current requirements make it very suitable for embedded systems.

NAND flash mostly use mtd+yaffs than mtd+jffs2.

YAFFS Public Site is http://www.aleph1.co.uk/armlinux/projects/. After you download yaffs

source, do followning.

① Create [linux]/fs/yaffs directory in your kernel.

② Copy devextras.h, yaffs_fs.c, yaffs_guts.c, yaffs_guts.h, yaffs_mtdif.c, yaffs_mtdif.h, yaffsinterface.h, yportenv.h, yaffs_config.h, Makefile to that directory.

③ Modify Makefie

// Comment all line and add following.

O_TARGET := yaffs.o

obj-y := yaffs_fs.o yaffs_guts.o yaffs_mtdif.o yaffs_ecc.o

obj-m := $(O_TARGET)

include $(TOPDIR)/Rules.make

④ [linux]/fs/Config.in.

if [ "CONFIG_MTD_NAND" = "y" ]; then

tristate "Yaffs filesystem on NAND" CONFIG_YAFFS_FS

fi

⑤ [linux]/fs/Makefile

subdir-$(CONFIG_YAFFS_FS) += yaffs

⑥ Make menuconfig and select Yaffs.

Picture 1-2 Yaffs Setup of Menuconfig

⑦ make dep -> make and download kernel image.

/>cat /proc/filesystems

Picture 1-3 Yaffs Filesystem List

?? ote : If Error occur in the middle of kernel-compile, download the latest MTD version. N

MTD download : ftp://ftp.uk.linux.org/pub/people/dwmw2/mtd/cvs/

Source change howto :

- First, delete the old source.

# rm –rf linux/drivers/mtd

# rm –rf linux/fs/jffs

# rm –rf linux/fs/jffs2

- Copy the download mtd source

# cp –rf mtd/drivers/mtd linux/drivers/

# cp -rf mtd/include/* linux/include/

# cp -rf mtd/fs/jffs linux/fs/jffs

# cp -rf mtd/fs/jffs2 linux/fs/jffs2

# cp -rf mtd/fs/ffs2 linux/fs/ffs2

# cp -rf mtd/lib/zlib_deflate linux/lib/

# cp -rf mtd/lib/zlib_inflate linux/lib/

1.3 Yaffs FileSystem Test

?? Partition setup

Download kernel image on Eos board and boot, so you will see the below screen.

Picture 1-4 Yaffs Partition Setup Screen

/dev/mtd0, /dev/mtdblock0 : Root FileSystem Space

/dev/mtd1, /dev/mtdblock1 : User Space

?? Device file Creation

Note : If Character Device’s sub-number is odd, you can’t write the Device. So, If you need to read and write, create even.

/>mknod /dev/mtd0 c 90 0

/>mknod /dev/mtd1 c 90 2

/>mknod /dev/mtdblock0 c 31 0

/>mknod /dev/mtdblock1 c 31 1

Picture 1-5 MTD Device file

?? Mount, Umount and Delete

- Create folder to mount

/>mkdir /mnt/flash0

/>mkdir /mnt/flash1

- Mount Block-Device on folder

/>mount –t yaffs /dev/mtdblock0 /mnt/flash0

/>mount –t yaffs /dev/mtdblock1 /mnt/flash1

Picture 1-6 YAFFS Mount

- Deletion file in the flash.

#!/bin/sh

eraseall /dev/mtd0

umount /mnt/flash0

mount –t yaffs /dev/mtdblock0 /mnt/flash0

Picture 15-7 YAFFS File Dele

- Umount

/> umount /mnt/flash0

/> umount /mnt/flash1

1.4 HOWTO on incorporating yaffs as a root fs.

* Root File System correspond to mtdblock0(0x300000 ~ 0x500000).

?? Copy File-System into mtdblock0 area.

① Boot Eos-Board.(you should make use of Ramdisk)

② Erase the mtdblock0

/>eraseall /dev/mtd0

③ Create the mount directory and mount.

/>mkdir –p /mnt/flash0

/>mount –t yaffs /dev/mtdblock0 /mnt/flash0

④ Copy filesystem into /mnt/flash0.

/>cp –drf /bin /mnt/flash0 />cp –drf /home /mnt/flash0

/>cp –drf /tmp /mnt/flash0 />cp –drf /dev /mnt/flash0

/>cp –drf /lib /mnt/flash0 />cp –drf /root /mnt/flash0

/>cp –drf /usr /mnt/flash0 />cp –drf /etc /mnt/flash0

/>cp –drf /opt /mnt/flash0 />cp –drf /sbin /mnt/flash0

/>cp –drf /var /mnt/flash0 />cp linuxrc /mnt/flash0

/>mkdir –p /mnt/flash0/mnt/flash1

⑤ Modify /mnt/flash0/etc/rc.

Mount –t yaffs /dev/mtdblock0 /mnt/flash0. -> Make line comment(annotate)

⑥ Modify /mnt/flash0/etc/fstab

#/dev/root / ext2 rw,noauto 0 1 ?? Comment

/dev/mtdblock0 / yaffs defaults 1 1 ?? Add

proc /proc proc defaults 0 0

devpts /dev/pts devpts defaults 0 0

tmpfs /tmp tmpfs defaults 0 0

⑦ Create rc2 into /mnt/flash1.

// Modify according to your Ethernet enviroment.

ifconfig eth0 210.102.3.122 netmask 255.255.255.128

route add default gw 210.102.3.10

cat /etc/motd

⑧ Modify pathname.h into init-ae32000.

#define _PATH_RC2 "/mnt/flash0/rc2" // Before modify

??

#define _PATH_RC2 "/mnt/flash1/rc2" // After modify

?? Modify Kernel Source

① make menuconfig -> Block Devices

< > RAM disk support -> delete

<*> Loopback device support . -> select

② arch/ae32000bnommu/kernel/setup.c

#define CONFIG_CMDLINE "root=/dev/ram0"

->

#define CONFIG_CMDLINE "noinitrd root=/dev/mtdblock0"

③ make dep -> make

④ Download kernel and boot

⑤ If you see the below screen, done successfully.

Picture 1-8 Yaffs as a root filesystem

Reference download address : ftp://ftp.adc.co.kr/pub/uclinux/EOS-uClinux/user/

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有