Chinaunix首页 | 论坛 | 博客
  • 博客访问: 815641
  • 博文数量: 321
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 936
  • 用 户 组: 普通用户
  • 注册时间: 2013-02-23 11:25
文章分类

全部博文(321)

文章存档

2017年(1)

2016年(10)

2015年(61)

2014年(187)

2013年(62)

分类: 嵌入式

2015-06-10 22:03:44

原文地址:移植内核之nandflash驱动 作者:linux_cjok

移植内核之nandflash驱动

     这只是作者本人的学习笔迹,所以没有什么格式规范可言,时间紧迫,尽请谅解。
移植步骤如下:

  1 机器码

     为自己的开发板设定一个机器码,添加在/arch/arm/tools/mach_types文件中

ut6410          MACH_UT6410         UT6410          1626

可以说随便设为什么数字,但是一定要和你uboot include/asm-arm/mach-types.h设定

的机器码匹配

   2 复制 mach-s3c6410.c

      Cp mach-s3c6410.c mach-ut6410.c

  Mach-ut6410.c要修改的地方很多,会在后面详细讲解。

  

修改arch/arm/mach-s3c6410/下的KconfigMakefile

Vim Kconfig 加入配置选项:

config MACH_UT6410

    bool "UT6410"

    select CPU_S3C6410

    select S3C_DEV_HSMMC

    select S3C_DEV_HSMMC1

    select S3C_DEV_I2C1

    select S3C_DEV_FB

    select S3C_DEV_USB_HOST

    select S3C_DEV_USB_HSOTG

    select S3C6410_SETUP_SDHCI

    select S3C64XX_SETUP_I2C1

    select S3C64XX_SETUP_FB_24BPP

    help

      Machine support for the UT6410, Modified by CJOK

 

Vim Makefile 加入:

 obj-$(CONFIG_MACH_UT6410)   += mach-ut6410.o

 

4 复制配置文件

   Cp arch/arm/config/s3c6400_defconfig .config

   如果找不到本芯片的配置文件,就找与本芯片型号相近的配置文件

   *****配置文件不对,在编译的时候可能会出现error

5 修改mach-ut6410.c

  Vim mach-ut6410.c

  vim命令行输入:

    %s/smdk6410/ut6410/g

    作用是把smdk6410全部替换为ut6410

 

6 mach-ut6410.c加入nandflash分区信息以及驱动

 

加入必要的头文件

> #include

> #include

> #include

> #include

> #include

 

加入分区信息

> /* modified by CJOK */

> static struct mtd_partition ut6410_default_nand_part[] __initdata = {

>   [0] = {

>          .name    = "u-boot",

>          .size       = 0x40000,

>          .offset    = 0,

>   },

>   [1] = {

>          .name    = "kernel",

>          .size       = 0x3c0000,

>          .offset    = 0x40000,

>   },

>   [2] = {

>          .name    = "rootfs",

>          .size       = 0x5000000,

>          .offset    = 0x400000,

>   },

>   [3] = {

>          .name    = "file system",

>          .size       = 0xac00000,

>          .offset    = 0x5400000,

>   },

> };

>

> static struct s3c2410_nand_set ut6410_nand_sets[] __initdata = {

>   [0] = {

>          .name           = "nand",

>          .nr_chips       = 1,

>          .nr_partitions       = ARRAY_SIZE(ut6410_default_nand_part),

>          .partitions     = ut6410_default_nand_part,

>          .flash_bbt     = 1, /* we use u-boot to create a BBT */

>   },

> };

>

> static struct s3c2410_platform_nand ut6410_nand_info __initdata = {

>   .tacls             = 25,         

>   .twrph0         = 55,

>   .twrph1         = 40,

>   .nr_sets = ARRAY_SIZE(ut6410_nand_sets),

>   .sets             = ut6410_nand_sets,

>   .ignore_unset_ecc = 1,

> };

 

Tacls,twrph0,twrph1是根据S3C6410资料得到,具体怎么得来的,还望高手能指点,

上面的数据是参考网友的。

 

在结构体static struct platform_device *ut6410_devices[] __initdata 中加入

&s3c_device_nand,

 

在函数static void __init ut6410_map_io(void)中加入

s3c_device_nand.dev.platform_data = &ut6410_nand_info;

 

在函数static void __init ut6410_machine_init(void)中加入

s3c_fb_set_platdata(&ut6410_nand_info);

 

修改:> MACHINE_START(UT6410, "UT6410 modified by CJOK")

 

基本上nandflash就只要添加这么多信息

 

7 配置内核

  Make menuconfig ARCH=arm CROSS_COMPILE=arm-linux-

  添加对nandflash的支持:

  Device Drivers  ---> 

     <*> Memory Technology Device (MTD) support  --->

           [*]   MTD partitioning support

           <*>   NAND Device Support  ---> 

                    <*>   NAND Flash support for Samsung S3C SoCs   

           <*>   Caching block device access to MTD devices                

  添加对NFS支持

  [*] Networking support  --->   

        Networking options  --->    

            [*] TCP/IP networking 

            [*]   IP: kernel level autoconfiguration

  选上自己配置的芯片类型

   System Type  ---> 

        [*] UT6410    

   是不是觉得很眼熟,对,就是我们刚刚第3步修改Kconfig得到的

 

8编译烧写到开发板上

  Make zImage CROSS_COMPILE=arm-linux- ARCH=arm

  启动信息:

   ………………………………………………………………………………………….

   Creating 4 MTD partitions on "NAND 256MiB 3,3V 8-bit":

0x000000000000-0x000000040000 : "u-boot"

0x000000040000-0x000000400000 : "kernel"

0x000000400000-0x000005400000 : "rootfs"

0x000005400000-0x000010000000 : "file system"

mice: PS/2 mouse device common for all mice

i2c /dev entries driver

sdhci: Secure Digital Host Controller Interface driver

sdhci: Copyright(c) Pierre Ossman

TCP cubic registered

VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5

VFS: Cannot open root device "mtdblock2" or unknown-block(31,2)

Please append a correct "root=" boot option; here are the available partitions:

1f00             256 mtdblock0 (driver?)

1f01            3840 mtdblock1 (driver?)

1f02           81920 mtdblock2 (driver?)

1f03          176128 mtdblock3 (driver?)

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,2)

[] (unwind_backtrace+0x0/0xd8) from [] (panic+0x40/0x10c)

[] (panic+0x40/0x10c) from [] (mount_block_root+0x1cc/0x20c)

[] (mount_block_root+0x1cc/0x20c) from [] (prepare_namespace+0x160/0x1b8)

[] (prepare_namespace+0x160/0x1b8) from [] (kernel_init+0xd8/0x10c)

[] (kernel_init+0xd8/0x10c) from [] (kernel_thread_exit+0x0/0x8)

 

额,出现了KERNEL PANIC,不要紧张

有三种情况:

a   MTD分区与bootloader不匹配

b   没有devfs文件系统支持

c   ECC校验没有关闭

 

 

终于看到了分区信息,nandflash驱动OK

 

可能遇到的问题:

问题一:

下载到板子上,发现如下问题,此问题郁闷我最久,

…………………………………..

CPU: Testing write buffer coherency: ok

s3c6400-nand: failed to claim resource 0

WARNING: at drivers/base/core.c:130 device_release+0x70/0x84()

…………………………………………………….

------------[ cut here ]------------

WARNING: at drivers/base/core.c:130 device_release+0x70/0x84()

Device 's3c64xx-rtc' does not have a release() function, it is broken and must be fixed.

Modules linked in:

……………………………………………………….

 

 

解决方法就是修改arch./arm/plat-samsung/dev-nand.c 中的

static struct resource s3c_nand_resource[] = {

    [0] = {

              .start = S3C_PA_NAND,

              .end  = S3C_PA_NAND + SZ_1M -1,

              .flags = IORESOURCE_MEM,

      }

};

.end  = S3C_PA_NAND + SZ_1M-1,  减去一就行了

 

问题二:

……………………………………………………..

end_request: I/O error, dev mtdblock2, sector 16

Buffer I/O error on device mtdblock2, logical block 2

uncorrectable error :

uncorrectable error :

end_request: I/O error, dev mtdblock2, sector 24

Buffer I/O error on device mtdblock2, logical block 3

uncorrectable error :

uncorrectable error :

end_request: I/O error, dev mtdblock2, sector 24

Buffer I/O error on device mtdblock2, logical block 3

List of all partitions:

1f00             256 mtdblock0 (driver?)

1f01            3840 mtdblock1 (driver?)

1f02           81920 mtdblock2 (driver?)

1f03          176128 mtdblock3 (driver?)

No filesystem could mount root, tried:  cramfs

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,2)

[] (unwind_backtrace+0x0/0xd8) from [] (panic+0x40/0x10c)

[] (panic+0x40/0x10c) from [] (mount_block_root+0x1cc/0x20c

 

解决办法:

1drivers/mtd/nand/s3c2410.c的函数s3c2410_nand_init_chip中的

NAND_ECC_SOFT修改为NAND_ECC_NONE

2、配置内核时,不要选上NAND ECC

 

 





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