Chinaunix首页 | 论坛 | 博客
  • 博客访问: 932993
  • 博文数量: 70
  • 博客积分: 1741
  • 博客等级: 上尉
  • 技术积分: 2476
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-05 14:46
个人简介

全志全系列芯片产品方案开发 A20/A33/A64/A40/A60/A83/A63/H3/H5/H6/H8

文章存档

2018年(1)

2012年(20)

2011年(49)

分类: LINUX

2011-11-17 21:03:57

注:粗体字后面表示加入的代码!

XC2440开发板使用的Nandflash容量为256M,大页(2K)Nand

内核中NandFlash驱动的位置为:drivers/mtd/nand/目录,该目录下的s3c2410_nand.c文件为s3c2440NAND控制器的驱动,我们无需修改驱动,只需要让内核支持nand驱动,并创建nandflash分区表。

 

188Bmach-xc2440.c文件中加入nand驱动支持

189B加入必备的头文件:

  1. #include
  2. #include
  3. #include
  4. #include
  5. #include


195B在平台设备结构体数组xc2440_devices[ ]中加入:

  1. &s3c_device_nand,

s3c_device_nand是在arch/arm/plat-samsung/dev-nand.c文件中定义:

  1. struct platform_device s3c_device_nand = {
  2.     .name         = "s3c2410-nand",
  3.     .id         = -1,
  4.     .num_resources     = ARRAY_SIZE(s3c_nand_resource),
  5.     .resource     = s3c_nand_resource,
  6. };

在这个文件中还定义了s3c_nand_set_platdata函数,用于设置nand设备的platdata

结构体s3c2410_platform_nand是在arch/arm/plat-samsung/include/plat.h中定义


xc2440_machine_init函数中加入设置nand平台数据函数:

  1. s3c_nand_set_platdata(&xc2440_nand_info);


构建一个s3c2410_platform_nand类型的xc2440_nand_info结构体:

  1. static struct s3c2410_platform_nand xc2440_nand_info __initdata = {
  2.     .tacls = 0,
  3.     .twrph0 = 25,
  4.     .twrph1 = 15,
  5.     .nr_sets = ARRAY_SIZE(xc2440_nand_sets),
  6.     .sets = xc2440_nand_sets,
  7.     .ignore_unset_ecc = 1,
  8. };

参数说明:

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

sets3c_nand_set_platdata类型的函数函数指针,其中定义了mtd_partition类型的partitions成员,用于设置mtd分区表


实现s3c2410_nand_set

  1. static struct s3c2410_nand_set xc2440_nand_sets[] __initdata = {
  2.     [0] = {
  3.         .name = "nand",
  4.         .nr_chips = 1,
  5.         .nr_partitions = ARRAY_SIZE(xc2440_default_nand_part),
  6.         .partitions = xc2440_default_nand_part,
  7.         .flash_bbt = 1, /* we use u-boot to create a BBT */
  8.     },
  9. };

创建MTD分区表

  1. /* NAND Flash */
  2. static struct mtd_partition xc2440_default_nand_part[] __initdata = {
  3.     [0] = {
  4.         .name    = "bootloader",
  5.         .size    = SZ_1M,
  6.         .offset    = 0,
  7.     },
  8.     [1] = {
  9.         .name    = "boot env",
  10.         .size    = SZ_128K,
  11.         .offset    = SZ_1M,
  12.     },
  13.     [2] = {
  14.         .name    = "kernel",
  15.         .size    = SZ_4M,
  16.         .offset    = SZ_1M + SZ_128K,
  17.     },
  18.     [3] = {
  19.         .name    = "root",
  20.         .offset    = SZ_1M+ SZ_128K + SZ_4M,
  21.         .size    = MTDPART_SIZ_FULL,
  22.     },
  23. };

参数说明:

name --> identifier string    用于识别分区的字符串

size --> partition size       分区的大小

offset --> offset within the master MTD space    分区的偏移量


查看drivers/mtd/nand/目录下的Kconfig文件,定义了s3c2410 nand设备的配置:

  1. config MTD_NAND_S3C2410
  2. tristate "NAND Flash support for Samsung S3C SoCs"
  3. depends on ARCH_S3C2410 || ARCH_S3C64XX


239B配置内核,支持NandFlash

  1. Device Drivers --->
  2.      <*> Memory Technology Device (MTD) support --->
  3.            [*]   MTD partitioning support
  4.            <*> NAND Device Support --->
  5. <*>   NAND Flash support for Samsung S3C SoCs
  6. [ ]     Samsung S3C NAND driver debug
  7. [ ]     Samsung S3C NAND Hardware ECC
  8. [ ]   Samsung S3C NAND IDLE clock stop


启动时输出的信息会打印出nand控制器和nand芯片类型和MTD分区表:

  1. S3C24XX NAND Driver, (c) 2004 Simtec Electronics
  2. s3c24xx-nand s3c2440-nand: Tacls=1, 10ns Twrph0=3 30ns, Twrph1=2 20ns
  3. s3c24xx-nand s3c2440-nand: NAND soft ECC
  4. NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung )
  5. Creating 4 MTD partitions on "nand":
  6. 0x000000000000-0x000000100000 : "bootloader"
  7. 0x000000100000-0x000000120000 : "boot env"
  8. 0x000000120000-0x000000520000 : "kernel"
  9. 0x000000520000-0x000010000000 : "root"


小超嵌入式工作室出品,  转载请注明出处,谢谢合作!

阅读(4002) | 评论(0) | 转发(8) |
给主人留下些什么吧!~~