|
楼主 |
发表于 2004-11-3 21:12:40
|
显示全部楼层
Linux MTD 源代码分析
by Jim Zeus
Version 0.1
2002/4/29
Copyright © 2002 Jim Zeus. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License,Version 1.1 or any later version published by the Free Software Foundation;with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".
If you got any Problem, Suggestion, Advice or Question ,
Please mail to: [email protected]
Any correction will be appreciated.
目录
专有名词:.... 7
Linux MTD介绍:... 8
设备层和原始设备层的函数调用关系(红色部分需要我们实现):... 9
NOR型Flash芯片驱动与MTD原始设备... 10
NAND和NOR的比较... 11
源码分析... 14
头文件分析... 14
mtd.h. 14
MTD_CHAR_MAJOR. 14
MTD_BLOCK_MAJOR. 14
MAX_MTD_DEVICES. 14
mtd_info. 14
mtd_info.type的取值... 16
mtd_info.flags的取值... 16
mtd_info.ecctype的取值... 17
erase_info. 17
erase_info.state的取值... 17
mtd_notifier 17
get_mtd_device. 18
put_mtd_device. 19
partitions.h. 19
mtd_partition. 19
MTDPART_OFS_APPEND.. 20
MTDPART_SIZ_FULL. 20
map.h. 20
map_info. 20
mtd_chip_driver 21
gen_probe.h. 21
chip_probe. 22
cfi.h. 22
cfi_private. 22
cfi_private.cfi_mode的取值... 22
cfi_ident 23
cfi_ident.P_ID的取值... 23
flashchip.h. 24
flchip. 24
/drivers/mtd/子目录... 24
mtdcore.c. 25
mtd_table. 25
mtd_notifiers. 25
add_mtd_device. 25
del_mtd_device. 26
register_mtd_user 28
unregister_mtd_user 29
__get_mtd_device. 30
mtdpart.c. 31
mtd_partitions. 32
mtd_part 32
PART(x) 32
add_mtd_partitions. 32
del_mtd_partitions. 36
part_read. 37
part_write. 37
part_readv. 37
part_writev. 37
part_erase. 37
part_lock. 37
part_unlock. 37
part_sync. 37
part_suspend. 37
part_resume. 37
mtdblock.c. 38
notifier 38
mtdblk_dev. 38
mtdblks. 39
erase_callback. 39
erase_write. 39
write_cached_data. 41
do_cached_write. 42
do_cached_read. 45
mtdblock_open. 46
mtdblock_release. 49
handle_mtdblock_request 50
leaving. 52
mtdblock_thread. 52
mtdblock_ioctl 54
mtd_fops. 55
init_mtdblock. 55
cleanup_mtdblock. 57
mtdchar.c. 58
notifier 58
mtd_lseek. 58
mtd_open. 59
mtd_close. 61
MAX_KMALLOC_SIZE. 61
mtd_read. 62
mtd_write. 63
mtd_erase_callback. 65
mtd_ioctl 66
mtd_fops. 71
init_mtdchar 72
cleanup_mtdchar 73
/drivers/mtd/chips子目录... 74
chipreg.c. 74
chip_drvs_list 74
register_mtd_chip_driver 74
unregister_mtd_chip_driver 75
get_mtd_chip_driver 76
do_map_probe. 77
cfi_probe.c. 78
cfi_chipdrv. 78
cfi_probe_init 78
cfi_probe_exit 79
cfi_probe. 80
cfi_chip_probe. 80
cfi_probe_chip. 80
qry_present 81
cfi_chip_setup. 82
jedec_probe.c. 84
amd_flash_info. 84
jedec_table. 84
jedec_chipdrv. 85
jedec_probe_init 85
jedec_probe_exit 85
jedec_probe. 86
jedec_probe_chip. 87
jedec_probe_chip. 87
cfi_jedec_setup. 87
gen_probe.c. 88
mtd_do_chip_probe. 88
genprobe_ident_chips. 89
genprobe_new_chip. 90
check_cmd_set 91
cfi_cmdset_unkown. 92
cfi_cmdset_0002.c. 93
cfi_amdstd_chipdrv. 93
cfi_cmdset_0002. 93
cfi_amdstd_setup. 96
cfi_amdstd_erase_onesize. 99
do_erase_oneblock. 101
cfi_amdstd_read. 103
do_read_onechip. 105
cfi_amdstd_write. 106
do_write_oneword. 111
cfi_amdstd_sync. 113
cfi_amdstd_suspend. 113
cfi_amdstd_resume. 113
cfi_amdstd_destroy. 113
cfi_amdstd_erase_varsize. 113
cfi_amdstd_init 114
cfi_amdstd_exit 114
cfi_cmdset_0001.c. 115
/drivers/mtd/maps子目录... 115
your-flash.c. 115
WINDOW_ADDR. 115
WINDOW_SIZE. 115
BUSWIDTH. 115
mymtd. 116
your_read8. 116
your_read16. 117
your_read32. 117
your_copy_from.. 117
your_write8. 117
your_write16. 117
your_write32. 117
your_copy_to. 117
your_set_vpp. 117
your_partition. 118
NUM_PARTITIONS. 119
your_map. 119
init_yourflash. 119
cleanup_yourflash. 120
专有名词:
1. MTD:Memory Technology Device,内存技术设备,
2. JEDEC:Joint Electron Device Engineering Council,电子电器设备联合会
3. CFI:Common Flash Interface,通用Flash接口,Intel发起的一个Flash的接口标准
4. OOB: out of band,某些内存技术支持out-of-band数据——例如,NAND flash每512字节的块有16个字节的extra data,用于纠错或元数据。
5. ECC: error correction,某些硬件不仅允许对flash的访问,也有ecc功能,所有flash器件都受位交换现象的困扰。在某些情况下,一个比特位会发生反转或被报告反转了,如果此位真的反转了,就要采用ECC算法。
6. erasesize: 一个erase命令可以擦除的最小块的尺寸
7. buswidth:MTD设备的接口总线宽度
8. interleave:交错数,几块芯片平行连接成一块芯片,使buswidth变大
9. devicetype:芯片类型,x8、x16或者x32
10. NAND:一种Flash技术,参看NAND和NOR的比较
11. NOR:一种Flash技术,参看NAND和NOR的比较
Linux MTD介绍:
MTD(memory technology device内存技术设备)是用于访问memory设备(ROM、flash)的Linux的子系统。MTD的主要目的是为了使新的memory设备的驱动更加简单,为此它在硬件和上层之间提供了一个抽象的接口。MTD的所有源代码在/drivers/mtd子目录下。我将CFI接口的MTD设备分为四层(从设备节点直到底层硬件驱动),这四层从上到下依次是:设备节点、MTD设备层、MTD原始设备层和硬件驱动层。
根文件系统
文件系统
字符设备节点
MTD字符设备
MTD块设备
MTD原始设备
FLASH硬件驱动
块设备节点
一、Flash硬件驱动层:硬件驱动层负责在init时驱动Flash硬件,Linux MTD设备的NOR Flash芯片驱动遵循CFI接口标准,其驱动程序位于drivers/mtd/chips子目录下。NAND型Flash的驱动程序则位于/drivers/mtd/nand子目录下
二、MTD原始设备:原始设备层有两部分组成,一部分是MTD原始设备的通用代码,另一部分是各个特定的Flash的数据,例如分区。
用于描述MTD原始设备的数据结构是mtd_info,这其中定义了大量的关于MTD的数据和操作函数。mtd_table(mtdcore.c)则是所有MTD原始设备的列表,mtd_part(mtd_part.c)是用于表示MTD原始设备分区的结构,其中包含了mtd_info,因 |
|