Chinaunix首页 | 论坛 | 博客
  • 博客访问: 119942
  • 博文数量: 35
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 165
  • 用 户 组: 普通用户
  • 注册时间: 2016-10-24 15:06
文章分类

全部博文(35)

文章存档

2017年(5)

2016年(30)

我的朋友

分类: 嵌入式

2016-12-14 09:44:41

原文地址:S3C6410下移植NAND驱动 作者:embeded-linux

S3C6410下移植NAND驱动
2010-09-25 21:01

在之前的hi.baidu.com/qiuqi830/blog/item/c00d69c5375159109c163dcb.html一文中提到了一些NAND的信息。下面具体说说NAND的驱动移植。

由于我在ANDROID官网GIT下来的2.6.29内核与海泰克6410开发版中提供的2.6.24内核的出入比较大,因此我在29的内核的/include/asm中添加了一些头文件,在此先做个提醒。

下载的NAND驱动放在/drivers/mtd/nand/该文件夹中。
在该文件夹下的KCONFIG文件中添加下面信息:
config MTD_NAND_S3C
tristate "NAND Flash support for S3C SoC"
depends on ARCH_S3C64XX && MTD_NAND
help
This enables the NAND flash controller on the S3C.

No board specfic support is done by this driver, each board
must advertise a platform_device for the driver to attach.

config MTD_NAND_S3C_DEBUG
bool "S3C NAND driver debug"
depends on MTD_NAND_S3C
help
Enable debugging of the S3C NAND driver

config MTD_NO_ECC_WARNING
bool "S3C MTD NO ECC warning"
depends on MTD_NAND_S3C
default y
help
Disable warnings when reading or writing on NO ECC Mode.

config MTD_NAND_S3C_HWECC
bool "S3C NAND Hardware ECC"
depends on MTD_NAND_S3C
help
Enable the use of the S3C's internal ECC generator when
using NAND. Early versions of the chip have had problems with
incorrect ECC generation, and if using these, the default of
software ECC is preferable.

If you lay down a device with the hardware ECC, then you will
currently not be able to switch to software, as there is no
implementation for ECC method used by the S3C

config S3C_LARGEPAGE_NAND
bool "Large (2K) page nand Support Enable"
depends on MTD_NAND_S3C
default n
help
S3C Large Page nand support.


在makefile文件中添加:
obj-$(CONFIG_MTD_NAND_S3C)        += s3c_nand.o

s3c_nand.c中,s3c_nand_probe函数里面做一些修改:
        //nand->ecc.mode = NAND_ECC_SOFT;       //- chachi
        nand->ecc.mode = NAND_ECC_NONE;        //+ chachi


为什么这么改,网上是这么说的:
    假设你把NAND_ECC_SOFT改成NAND_ECC_NONE,那[*] Lets Yaffs do its own ECC 这一步是必需的。
最后,如果你把NAND_ECC_SOFT改成NAND_ECC_NONE的话,那你下载yaffs文件系统的时候就不应该加上-e的参数了。
这个东西我可是经历了无数次的"mount_devfs_fs(): unable to mount devfs, err: -2"才悟出来的,本来想不讲出来的,但实在太多人问这个问题了,实在不忍^_^
最后给点建议:先让内核挂载cramfs试试看(记得把NAND_ECC_SOFT改成NAND_ECC_NONE哦),因为这个文件系统只要用下载内核的命令下载就行,成功挂载cramfs的话将会是你最大的鼓舞

先这么理解,开发版不支持硬件的ECC校验,menuconfig中不配置硬件ECC校验,驱动中也会执行软件的ECC校验,而且貌似ECC校验会占用大量的系统资源,因此将参数设置为NAND_ECC_NONE

附:如何编写linux下nand flash驱动-2

green-waste.blog.163.com/blog/static/326776782009622112913547/


NAND FLASH ECC校验的原理

http://blog.ednchina.com/lieal/17736/message.aspx

驱动设置好以后,进行参数配置。
比较了一下2.6.24和2.6.29内核以后,发现2.6.29内核中6410(其他类似)中的所有platform_device都定义在了 /arch/arm/mach-s3c6410/mach-smdk6410.c 以及 /arch/arm/plat-s3c64xx/dev-xxx.c(比如:dev-fb.c)中。

因此,在mach-smdk6410.c中添加注册信息:
/*
* NAND分区
* 一共分为4个区,其中第3个分区存放ANDROID的文件系统

* 第4个分区存放ANDROID文件系统data文件夹的内容
* 因此在UBOOT的参数设置为root=/dev/mtdblock2
*/
struct mtd_partition s3c_partition_info[] = {
{
.name        = "Bootloader",
.offset        = 0,
.size        = (256*SZ_1K),
.mask_flags    = MTD_CAP_NANDFLASH,
},
{
.name        = "Kernel",
.offset        = (256*SZ_1K),    /* Block number is 0x10 */
.size        = (5*SZ_1M) - (256*SZ_1K),
// .mask_flags    = MTD_CAP_NANDFLASH,        //- chachi
},
{
.name        = "File System",
.offset        = (5*SZ_1M),    /* Block number is 0x10 */
.size        = (90*SZ_1M),            //gzy
// .mask_flags    = MTD_CAP_NANDFLASH,    //- chachi
},       
{
.name        = "Data",
.offset        = MTDPART_OFS_APPEND,
.size        = MTDPART_SIZ_FULL,
}  
};

struct s3c_nand_mtd_info s3c_nand_mtd_part_info = {
.chip_nr = 1,
.mtd_part_nr = ARRAY_SIZE(s3c_partition_info),
.partition = s3c_partition_info,
};

static struct resource s3c_nand_resource[] = {
[0] = {
.start = S3C24XX_PA_NAND,
.end   = S3C24XX_PA_NAND + S3C24XX_SZ_NAND - 1,
.flags = IORESOURCE_MEM,
}
};

struct platform_device s3c_device_nand = {
.name        = "s3c-nand",
.id        = -1,
.num_resources    = ARRAY_SIZE(s3c_nand_resource),
.resource    = s3c_nand_resource,
.dev = {
.platform_data = &s3c_nand_mtd_part_info
}
};
/* end change by chachi */


static struct platform_device *smdk6410_devices[] __initdata = {
......
&s3c_device_nand, //+ chachi
......
};

NAND的PHY地址定义为:
#define S3C24XX_PA_NAND (0x70200000)
#define S3C24XX_SZ_NAND SZ_1M


最后配置menuconfig(我更喜欢用xconfig ^_^):
<*> Memory Technology Device (MTD) support --->
[*]   MTD partitioning support
<*>   RedBoot partition table parsing                            │ │
│ │    (-1)    Location of RedBoot partition table                      │ │
│ │    [*]     Include unallocated flash regions                        │ │
│ │    [ ]     Force read-only for RedBoot system images                │ │
│ │    [*]   Command line partition table parsing                       │
<*>   Direct char device access to MTD devices                   │ │
│ │    -*-   Common interface to block layer for MTD 'translation layers│ │
│ │    <*>   Caching block device access to MTD devices  

│ │          RAM/ROM/Flash chip drivers --->
<*> Detect flash chips by Common Flash Interface (CFI) probe     │ │
│ │    <*> Detect non-CFI AMD/JEDEC-compatible flash chips              │ │
│ │    [ ] Flash chip driver advanced configuration options             │ │
│ │    <*> Support for Intel/Sharp flash chips                          │ │
│ │    <*> Support for AMD/Fujitsu/Spansion flash chips                 │ │
│ │    < > Support for ST (Advanced Architecture) flash chips           │ │
│ │    < > Support for RAM chips in bus mapping                         │ │
│ │    <*> Support for ROM chips in bus mapping                         │ │
│ │    < > Support for absent chips in bus mapping                      │ │
│ │                                                                     │ │
│ └——————————————————————————————————————————————————

<*>   NAND Device Support --->
--- NAND Device Support                                          │ │
│ │    [*]   Verify NAND page writes                                    │ │
│ │    [ ]   NAND ECC Smart Media byte order                            │ │
│ │    [ ]   Enable chip ids for obsolete ancient NAND devices          │ │
│ │    < >   GPIO NAND Flash driver                                     │ │
│ │    <*>   NAND Flash support for S3C SoC                             │ │
│ │    [ ]     S3C NAND driver debug                                    │ │
│ │    [*]     S3C MTD NO ECC warning                                   │ │
│ │    [ ]     S3C NAND Hardware ECC                                    │ │
│ │    [*]     Large (2K) page nand Support Enable                      │ │
│ │
│ │    < >   Support for generic platform NAND driver                   │ │
│ └———————————————————————————————————————————————————————————————

在uboot中配置bootargs参数:

root=/dev/mtdblock2 rootfstype=jffs2

启动内核后显示:

S3C NAND Driver, (c) 2007 Samsung Electronics

<6>NAND device: Manufacturer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-bit)

<4>NAND_ECC_NONE selected by board driver. This is not recommended !!

<5>Creating 4 MTD partitions on "NAND 128MiB 3,3V 8-bit":

<5>0x000000000000-0x000000040000 : "Bootloader"

<5>0x000000040000-0x000000500000 : "Kernel"

<5>0x000000500000-0x000005f00000 : "File System"

<5>0x000005f00000-0x000008000000 : "data"

install NAND DRIVE = 0

......

VFS: Mounted root (jffs2 filesystem) on device 31:2.

<6>Freeing init memory: 88K

<4>Warning: unable to open an initial console.

<0>Kernel panic - not syncing: Attempted to kill init!

表示NAND驱动移植成功

JFFS2文件系统等,在之后的文章中写

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