注:粗体字后面表示加入的代码!
XC2440开发板使用的Nandflash容量为256M,大页(2K)Nand
内核中NandFlash驱动的位置为:drivers/mtd/nand/目录,该目录下的s3c2410_nand.c文件为s3c2440的NAND控制器的驱动,我们无需修改驱动,只需要让内核支持nand驱动,并创建nandflash分区表。
188B在mach-xc2440.c文件中加入nand驱动支持:
189B加入必备的头文件:
- #include
- #include
- #include
- #include
- #include
195B在平台设备结构体数组xc2440_devices[ ]中加入:
s3c_device_nand是在arch/arm/plat-samsung/dev-nand.c文件中定义:
- struct platform_device s3c_device_nand = {
-
.name = "s3c2410-nand",
-
.id = -1,
-
.num_resources = ARRAY_SIZE(s3c_nand_resource),
-
.resource = s3c_nand_resource,
-
};
在这个文件中还定义了s3c_nand_set_platdata函数,用于设置nand设备的platdata
结构体s3c2410_platform_nand是在arch/arm/plat-samsung/include/plat.h中定义
在xc2440_machine_init函数中加入设置nand平台数据函数:
- s3c_nand_set_platdata(&xc2440_nand_info);
构建一个s3c2410_platform_nand类型的xc2440_nand_info结构体:
- static struct s3c2410_platform_nand xc2440_nand_info __initdata = {
-
.tacls = 0,
-
.twrph0 = 25,
-
.twrph1 = 15,
-
.nr_sets = ARRAY_SIZE(xc2440_nand_sets),
-
.sets = xc2440_nand_sets,
-
.ignore_unset_ecc = 1,
-
};
参数说明:
tacls --> time for active CLE/ALE
to nWE/nOE
twrph0 --> active time for nWE/nOE
twrph1 --> time for release
CLE/ALE from nWE/nOE inactive
以上三个值是从nandflash的手册中获得
ignore_unset_ecc = 1 表示忽略ecc
set是s3c_nand_set_platdata类型的函数函数指针,其中定义了mtd_partition类型的partitions成员,用于设置mtd分区表
实现s3c2410_nand_set:
- static struct s3c2410_nand_set xc2440_nand_sets[] __initdata = {
-
[0] = {
-
.name = "nand",
-
.nr_chips = 1,
-
.nr_partitions = ARRAY_SIZE(xc2440_default_nand_part),
-
.partitions = xc2440_default_nand_part,
-
.flash_bbt = 1, /* we use u-boot to create a BBT */
-
},
-
};
创建MTD分区表:
- /* NAND Flash */
-
static struct mtd_partition xc2440_default_nand_part[] __initdata = {
-
[0] = {
-
.name = "bootloader",
-
.size = SZ_1M,
-
.offset = 0,
-
},
-
[1] = {
-
.name = "boot env",
-
.size = SZ_128K,
-
.offset = SZ_1M,
-
},
-
[2] = {
-
.name = "kernel",
-
.size = SZ_4M,
-
.offset = SZ_1M + SZ_128K,
-
},
-
[3] = {
-
.name = "root",
-
.offset = SZ_1M+ SZ_128K + SZ_4M,
-
.size = MTDPART_SIZ_FULL,
-
},
-
};
参数说明:
name --> identifier
string 用于识别分区的字符串
size --> partition
size 分区的大小
offset --> offset
within the master MTD space 分区的偏移量
查看drivers/mtd/nand/目录下的Kconfig文件,定义了s3c2410 nand设备的配置:
- config MTD_NAND_S3C2410
- tristate "NAND Flash support for Samsung S3C SoCs"
- depends on ARCH_S3C2410 || ARCH_S3C64XX
239B配置内核,支持NandFlash
- Device Drivers --->
- <*> Memory Technology Device (MTD) support --->
- [*] MTD partitioning support
- <*> NAND Device Support --->
- <*> NAND Flash support for Samsung S3C SoCs
- [ ] Samsung S3C NAND driver debug
- [ ] Samsung S3C NAND Hardware ECC
- [ ] Samsung S3C NAND IDLE clock stop
启动时输出的信息会打印出nand控制器和nand芯片类型和MTD分区表:
- S3C24XX NAND Driver, (c) 2004 Simtec Electronics
-
s3c24xx-nand s3c2440-nand: Tacls=1, 10ns Twrph0=3 30ns, Twrph1=2 20ns
-
s3c24xx-nand s3c2440-nand: NAND soft ECC
-
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung )
-
Creating 4 MTD partitions on "nand":
-
0x000000000000-0x000000100000 : "bootloader"
-
0x000000100000-0x000000120000 : "boot env"
-
0x000000120000-0x000000520000 : "kernel"
-
0x000000520000-0x000010000000 : "root"
小超嵌入式工作室出品, 转载请注明出处,谢谢合作!
阅读(593) | 评论(0) | 转发(0) |